summaryrefslogtreecommitdiffstats
path: root/skia/ext/platform_canvas.h
diff options
context:
space:
mode:
authortwiz@chromium.org <twiz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-26 14:28:35 +0000
committertwiz@chromium.org <twiz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-26 14:28:35 +0000
commit62f2e80c79f7d660d7871b14287cef9082fcc32f (patch)
tree310edb9b2c0aa8409defc654979719cb4d8a4059 /skia/ext/platform_canvas.h
parentc89b244483969aa8859a1d4bb3396f6ceb54f875 (diff)
downloadchromium_src-62f2e80c79f7d660d7871b14287cef9082fcc32f.zip
chromium_src-62f2e80c79f7d660d7871b14287cef9082fcc32f.tar.gz
chromium_src-62f2e80c79f7d660d7871b14287cef9082fcc32f.tar.bz2
This change implements a first pass in the effort to remove the dependency of PlatformDevice within Chrome. The Skia library now provides multiple back-ends for the SkDevice class, so PlatformDevice's inheritance of SkDevice, and the assumption of instances of PlatformDevice limits the use of these new back-ends.
A new set of helper functions is provided for the PlatformDevice entry points. Upon construction of a PlatformDevice, a pointer to the interface is cached in the parent SkDevice's SkMetaData. The new helper functions forward calls to the interface cached in the metadata. BUG=NONE TEST=NONE Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=86625 Reverted: http://src.chromium.org/viewvc/chrome?view=rev&revision=86625 Review URL: http://codereview.chromium.org/7019013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86823 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia/ext/platform_canvas.h')
-rw-r--r--skia/ext/platform_canvas.h76
1 files changed, 47 insertions, 29 deletions
diff --git a/skia/ext/platform_canvas.h b/skia/ext/platform_canvas.h
index 24f613a..d9afb77 100644
--- a/skia/ext/platform_canvas.h
+++ b/skia/ext/platform_canvas.h
@@ -63,30 +63,6 @@ class SK_API PlatformCanvas : public SkCanvas {
// Shared --------------------------------------------------------------------
- // These calls should surround calls to platform drawing routines, the
- // surface returned here can be used with the native platform routines
- //
- // Call endPlatformPaint when you are done and want to use Skia operations
- // after calling the platform-specific beginPlatformPaint; this will
- // synchronize the bitmap to OS if necessary.
- PlatformDevice::PlatformSurface beginPlatformPaint() const;
- void endPlatformPaint() const;
-
- // Returns the platform device pointer of the topmost rect with a non-empty
- // clip. In practice, this is usually either the top layer or nothing, since
- // we usually set the clip to new layers when we make them.
- //
- // If there is no layer that is not all clipped out, this will return a
- // dummy device so callers do not have to check. If you are concerned about
- // performance, check the clip before doing any painting.
- //
- // This is different than SkCanvas' getDevice, because that returns the
- // bottommost device.
- //
- // Danger: the resulting device should not be saved. It will be invalidated
- // by the next call to save() or restore().
- PlatformDevice& getTopPlatformDevice() const;
-
// Return the stride (length of a line in bytes) for the given width. Because
// we use 32-bits per pixel, this will be roughly 4*width. However, for
// alignment reasons we may wish to increase that.
@@ -109,11 +85,26 @@ class SK_API PlatformCanvas : public SkCanvas {
// CoreGraphics.
virtual SkDevice* setBitmapDevice(const SkBitmap& bitmap);
- // Disallow copy and assign.
+ // Disallow copy and assign
PlatformCanvas(const PlatformCanvas&);
PlatformCanvas& operator=(const PlatformCanvas&);
};
+// Returns the SkDevice pointer of the topmost rect with a non-empty
+// clip. In practice, this is usually either the top layer or nothing, since
+// we usually set the clip to new layers when we make them.
+//
+// If there is no layer that is not all clipped out, this will return a
+// dummy device so callers do not have to check. If you are concerned about
+// performance, check the clip before doing any painting.
+//
+// This is different than SkCanvas' getDevice, because that returns the
+// bottommost device.
+//
+// Danger: the resulting device should not be saved. It will be invalidated
+// by the next call to save() or restore().
+SK_API SkDevice* GetTopDevice(const SkCanvas& canvas);
+
// Creates a canvas with raster bitmap backing.
// Set is_opaque if you are going to erase the bitmap and not use
// transparency: this will enable some optimizations.
@@ -124,18 +115,45 @@ SK_API SkCanvas* CreateBitmapCanvas(int width, int height, bool is_opaque);
// return NULL PlatformSurface.
SK_API bool SupportsPlatformPaint(const SkCanvas* canvas);
+// Draws into the a native platform surface, |context|. Forwards to
+// DrawToNativeContext on a PlatformDevice instance bound to the top device.
+// If no PlatformDevice instance is bound, is a no-operation.
+SK_API void DrawToNativeContext(SkCanvas* canvas, PlatformSurface context,
+ int x, int y, const PlatformRect* src_rect);
+
+// Sets the opacity of each pixel in the specified region to be opaque.
+SK_API void MakeOpaque(SkCanvas* canvas, int x, int y, int width, int height);
+
// These calls should surround calls to platform drawing routines, the
// surface returned here can be used with the native platform routines.
//
// Call EndPlatformPaint when you are done and want to use skia operations
// after calling the platform-specific BeginPlatformPaint; this will
// synchronize the bitmap to OS if necessary.
-//
-// Note: These functions will eventually replace
-// PlatformCanvas::beginPlatformPaint and PlatformCanvas::endPlatformPaint.
-SK_API PlatformDevice::PlatformSurface BeginPlatformPaint(SkCanvas* canvas);
+SK_API PlatformSurface BeginPlatformPaint(SkCanvas* canvas);
SK_API void EndPlatformPaint(SkCanvas* canvas);
+// Helper class for pairing calls to BeginPlatformPaint and EndPlatformPaint.
+// Upon construction invokes BeginPlatformPaint, and upon destruction invokes
+// EndPlatformPaint.
+class SK_API ScopedPlatformPaint {
+ public:
+ explicit ScopedPlatformPaint(SkCanvas* canvas) : canvas_(canvas) {
+ platform_surface_ = BeginPlatformPaint(canvas);
+ }
+ ~ScopedPlatformPaint() { EndPlatformPaint(canvas_); }
+
+ // Returns the PlatformSurface to use for native platform drawing calls.
+ PlatformSurface GetPlatformSurface() { return platform_surface_; }
+ private:
+ SkCanvas* canvas_;
+ PlatformSurface platform_surface_;
+
+ // Disallow copy and assign
+ ScopedPlatformPaint(const ScopedPlatformPaint&);
+ ScopedPlatformPaint& operator=(const ScopedPlatformPaint&);
+};
+
} // namespace skia
#endif // SKIA_EXT_PLATFORM_CANVAS_H_