aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-12-13 21:39:56 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-12-13 21:39:56 +0000
commit1adcf8859cc9414591038e440e3f22382c8e4aa0 (patch)
tree9a7326ace2054faecd8ca907e90188b412be7b54 /include
parent9f13174da5295e88d447f29740318003b9cec9c3 (diff)
Goal: ensure we always balance lock/unlock pixels calls.
A big caller of lockPixels is setContext in the bitmapshader. This change replaces beginSession/endSession with adding endContext(), and adds debugging code to ensure that 1. setContext calls are never nested 2. endContext is always called after each setContext call. Review URL: https://codereview.appspot.com/6937046 git-svn-id: http://skia.googlecode.com/svn/trunk@6798 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include')
-rw-r--r--include/core/SkComposeShader.h9
-rw-r--r--include/core/SkShader.h29
2 files changed, 23 insertions, 15 deletions
diff --git a/include/core/SkComposeShader.h b/include/core/SkComposeShader.h
index a8a8e0bb60..b0790bf393 100644
--- a/include/core/SkComposeShader.h
+++ b/include/core/SkComposeShader.h
@@ -34,11 +34,10 @@ public:
SkComposeShader(SkShader* sA, SkShader* sB, SkXfermode* mode = NULL);
virtual ~SkComposeShader();
- // override
- virtual bool setContext(const SkBitmap& device, const SkPaint& paint, const SkMatrix& matrix);
- virtual void shadeSpan(int x, int y, SkPMColor result[], int count);
- virtual void beginSession();
- virtual void endSession();
+ virtual bool setContext(const SkBitmap&, const SkPaint&,
+ const SkMatrix&) SK_OVERRIDE;
+ virtual void endContext() SK_OVERRIDE;
+ virtual void shadeSpan(int x, int y, SkPMColor[], int count) SK_OVERRIDE;
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkComposeShader)
diff --git a/include/core/SkShader.h b/include/core/SkShader.h
index 1286177271..7edbe6fd4b 100644
--- a/include/core/SkShader.h
+++ b/include/core/SkShader.h
@@ -139,12 +139,29 @@ public:
/**
* Called once before drawing, with the current paint and device matrix.
* Return true if your shader supports these parameters, or false if not.
- * If false is returned, nothing will be drawn.
+ * If false is returned, nothing will be drawn. If true is returned, then
+ * a balancing call to endContext() will be made before the next call to
+ * setContext.
+ *
+ * Subclasses should be sure to call their INHERITED::setContext() if they
+ * override this method.
*/
virtual bool setContext(const SkBitmap& device, const SkPaint& paint,
const SkMatrix& matrix);
/**
+ * Assuming setContext returned true, endContext() will be called when
+ * the draw using the shader has completed. It is an error for setContext
+ * to be called twice w/o an intervening call to endContext().
+ *
+ * Subclasses should be sure to call their INHERITED::endContext() if they
+ * override this method.
+ */
+ virtual void endContext();
+
+ SkDEBUGCODE(bool setContextHasBeenCalled() const { return fInSetContext; })
+
+ /**
* Called for each span of the object being drawn. Your subclass should
* set the appropriate colors (with premultiplied alpha) that correspond
* to the specified device coordinates.
@@ -183,14 +200,6 @@ public:
}
/**
- * Called before a session using the shader begins. Some shaders override
- * this to defer some of their work (like calling bitmap.lockPixels()).
- * Must be balanced by a call to endSession.
- */
- virtual void beginSession();
- virtual void endSession();
-
- /**
Gives method bitmap should be read to implement a shader.
Also determines number and interpretation of "extra" parameters returned
by asABitmap
@@ -355,7 +364,7 @@ private:
uint8_t fPaintAlpha;
uint8_t fDeviceConfig;
uint8_t fTotalInverseClass;
- SkDEBUGCODE(SkBool8 fInSession;)
+ SkDEBUGCODE(SkBool8 fInSetContext;)
static SkShader* CreateBitmapShader(const SkBitmap& src,
TileMode, TileMode,