aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu
diff options
context:
space:
mode:
authorGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-05-02 19:32:32 +0000
committerGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-05-02 19:32:32 +0000
commitfd6daf5ed7f730ee0fb437c5fd17561ce8c20b6c (patch)
tree8489223b1a1d8ffedc018205f2162e14a606f9e9 /src/gpu
parent7ff2e371859982cad995f9d2a8cbdbb8601fc780 (diff)
Added cache to gpu AA clipping
Diffstat (limited to 'src/gpu')
-rw-r--r--src/gpu/GrClipMaskManager.cpp14
-rw-r--r--src/gpu/GrClipMaskManager.h59
2 files changed, 69 insertions, 4 deletions
diff --git a/src/gpu/GrClipMaskManager.cpp b/src/gpu/GrClipMaskManager.cpp
index a1ac0ab9b1..ce0f620f29 100644
--- a/src/gpu/GrClipMaskManager.cpp
+++ b/src/gpu/GrClipMaskManager.cpp
@@ -15,7 +15,6 @@
//#define GR_AA_CLIP 1
-
////////////////////////////////////////////////////////////////////////////////
void ScissoringSettings::setupScissoring(GrGpu* gpu) {
if (!fEnableScissoring) {
@@ -366,10 +365,17 @@ bool GrClipMaskManager::createAlphaClipMask(GrGpu* gpu,
GrRenderTarget* rt = origDrawState->getRenderTarget();
GrAssert(NULL != rt);
+ if (fAACache.canReuse(clipIn, rt->width(), rt->height())) {
+ *result = fAACache.getLastMask();
+ *resultBounds = fAACache.getLastBound();
+ return true;
+ }
+
GrRect rtRect;
rtRect.setLTRB(0, 0,
GrIntToScalar(rt->width()), GrIntToScalar(rt->height()));
+
// unlike the stencil path the alpha path is not bound to the size of the
// render target - determine the minimum size required for the mask
GrRect bounds;
@@ -411,8 +417,9 @@ bool GrClipMaskManager::createAlphaClipMask(GrGpu* gpu,
GrTexture* accum = gpu->createTexture(desc, NULL, 0);
GrTexture* temp = gpu->createTexture(desc, NULL, 0);
if (NULL == accum || NULL == temp) {
- // TODO: free up accum & temp here!
fClipMaskInAlpha = false;
+ SkSafeUnref(accum);
+ SkSafeUnref(temp);
return false;
}
@@ -505,8 +512,11 @@ bool GrClipMaskManager::createAlphaClipMask(GrGpu* gpu,
}
}
+ fAACache.set(clipIn, rt->width(), rt->height(), accum, bounds);
*result = accum;
*resultBounds = bounds;
+ SkSafeUnref(accum); // fAACache still has a ref to accum
+ SkSafeUnref(temp);
return true;
}
diff --git a/src/gpu/GrClipMaskManager.h b/src/gpu/GrClipMaskManager.h
index be6873edd9..516ec95e30 100644
--- a/src/gpu/GrClipMaskManager.h
+++ b/src/gpu/GrClipMaskManager.h
@@ -11,9 +11,11 @@
#include "GrRect.h"
#include "SkPath.h"
+#include "GrNoncopyable.h"
+#include "GrClip.h"
+#include "SkRefCnt.h"
class GrGpu;
-class GrClip;
class GrPathRenderer;
class GrPathRendererChain;
class SkPath;
@@ -33,6 +35,57 @@ struct ScissoringSettings {
void setupScissoring(GrGpu* gpu);
};
+/**
+ * The stencil buffer stores the last clip path - providing a single entry
+ * "cache". This class provides similar functionality for AA clip paths
+ */
+class GrClipMaskCache : public GrNoncopyable {
+public:
+ GrClipMaskCache()
+ : fLastWidth(-1)
+ , fLastHeight(-1) {
+ fLastBound.MakeEmpty();
+ }
+
+ bool canReuse(const GrClip& clip, int width, int height) {
+ if (fLastWidth >= width &&
+ fLastHeight >= height &&
+ clip == fLastClip) {
+ return true;
+ }
+
+ return false;
+ }
+
+ void set(const GrClip& clip, int width, int height,
+ GrTexture* mask, const GrRect& bound) {
+
+ fLastWidth = width;
+ fLastHeight = height;
+ fLastClip = clip;
+ SkSafeRef(mask);
+ fLastMask.reset(mask);
+ fLastBound = bound;
+ }
+
+ GrTexture* getLastMask() {
+ return fLastMask.get();
+ }
+
+ const GrRect& getLastBound() const {
+ return fLastBound;
+ }
+
+protected:
+private:
+ int fLastWidth;
+ int fLastHeight;
+ GrClip fLastClip;
+ SkAutoTUnref<GrTexture> fLastMask;
+ GrRect fLastBound;
+
+ typedef GrNoncopyable INHERITED;
+};
/**
* The clip mask creator handles the generation of the clip mask. If anti
@@ -42,7 +95,7 @@ struct ScissoringSettings {
* mask can be represented as a rectangle then scissoring is used. In all
* cases scissoring is used to bound the range of the clip mask.
*/
-class GrClipMaskManager {
+class GrClipMaskManager : public GrNoncopyable {
public:
GrClipMaskManager()
: fClipMaskInStencil(false)
@@ -67,6 +120,7 @@ protected:
private:
bool fClipMaskInStencil; // is the clip mask in the stencil buffer?
bool fClipMaskInAlpha; // is the clip mask in an alpha texture?
+ GrClipMaskCache fAACache; // cache for the AA path
// must be instantiated after GrGpu object has been given its owning
// GrContext ptr. (GrGpu is constructed first then handed off to GrContext).
@@ -102,6 +156,7 @@ private:
GrPathFill fill,
bool antiAlias);
+ typedef GrNoncopyable INHERITED;
};
#endif // GrClipMaskManager_DEFINED