diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-29 22:08:44 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-29 22:08:44 +0000 |
commit | bd026803b2a3db66f2003f83c4b7e627c71828a2 (patch) | |
tree | e45b18ae05095ffae9201fe8ec905bf1fef25e50 /gfx | |
parent | 6a649b71db4df80493abfb125e0a71738d4d9d8a (diff) | |
download | chromium_src-bd026803b2a3db66f2003f83c4b7e627c71828a2.zip chromium_src-bd026803b2a3db66f2003f83c4b7e627c71828a2.tar.gz chromium_src-bd026803b2a3db66f2003f83c4b7e627c71828a2.tar.bz2 |
Canvas refactoring Phase 4a:
Move Save, SaveLayerAlpha and Restore onto gfx::Canvas.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/2846035
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51179 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gfx')
-rw-r--r-- | gfx/canvas.h | 15 | ||||
-rw-r--r-- | gfx/canvas_skia.cc | 25 | ||||
-rw-r--r-- | gfx/canvas_skia.h | 4 |
3 files changed, 44 insertions, 0 deletions
diff --git a/gfx/canvas.h b/gfx/canvas.h index d66db03..90495cd 100644 --- a/gfx/canvas.h +++ b/gfx/canvas.h @@ -66,6 +66,21 @@ class Canvas { // Creates a canvas with the specified size. static Canvas* CreateCanvas(int width, int height, bool is_opaque); + // Saves a copy of the drawing state onto a stack, operating on this copy + // until a balanced call to Restore() is made. + virtual void Save() = 0; + + // As with Save(), except draws to a layer that is blended with the canvas + // at the specified alpha once Restore() is called. + // |layer_bounds| are the bounds of the layer relative to the current + // transform. + virtual void SaveLayerAlpha(U8CPU alpha) = 0; + virtual void SaveLayerAlpha(U8CPU alpha, const gfx::Rect& layer_bounds) = 0; + + // Restores the drawing state after a call to Save*(). It is an error to + // call Restore() more times than Save*(). + virtual void Restore() = 0; + // Retrieves the clip rectangle and sets it in the specified rectangle if any. // Returns true if the clip rect is non-empty. virtual bool GetClipRect(gfx::Rect* clip_rect) = 0; diff --git a/gfx/canvas_skia.cc b/gfx/canvas_skia.cc index 8fb752de..28a3596 100644 --- a/gfx/canvas_skia.cc +++ b/gfx/canvas_skia.cc @@ -29,6 +29,31 @@ SkBitmap CanvasSkia::ExtractBitmap() const { return result; } +//////////////////////////////////////////////////////////////////////////////// +// CanvasSkia, Canvas implementation: + +void CanvasSkia::Save() { + save(); +} + +void CanvasSkia::SaveLayerAlpha(U8CPU alpha) { + saveLayerAlpha(NULL, alpha); +} + + +void CanvasSkia::SaveLayerAlpha(U8CPU alpha, const gfx::Rect& layer_bounds) { + SkRect bounds; + bounds.set(SkIntToScalar(layer_bounds.x()), + SkIntToScalar(layer_bounds.y()), + SkIntToScalar(layer_bounds.right()), + SkIntToScalar(layer_bounds.bottom())); + saveLayerAlpha(&bounds, alpha); +} + +void CanvasSkia::Restore() { + restore(); +} + bool CanvasSkia::GetClipRect(gfx::Rect* r) { SkRect clip; if (!getClipBounds(&clip)) { diff --git a/gfx/canvas_skia.h b/gfx/canvas_skia.h index cae4ac1..1648cbe 100644 --- a/gfx/canvas_skia.h +++ b/gfx/canvas_skia.h @@ -80,6 +80,10 @@ class CanvasSkia : public skia::PlatformCanvas, SkBitmap ExtractBitmap() const; // Overridden from Canvas2: + virtual void Save(); + virtual void SaveLayerAlpha(U8CPU alpha); + virtual void SaveLayerAlpha(U8CPU alpha, const gfx::Rect& layer_bounds); + virtual void Restore(); virtual bool GetClipRect(gfx::Rect* clip_rect); virtual bool ClipRectInt(int x, int y, int w, int h); virtual bool IntersectsClipRectInt(int x, int y, int w, int h); |