Added cache to gpu AA clipping

http://codereview.appspot.com/6160046/



git-svn-id: http://skia.googlecode.com/svn/trunk@3828 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
robertphillips@google.com 2012-05-02 19:32:32 +00:00
Родитель 7ff2e37185
Коммит fd6daf5ed7
2 изменённых файлов: 69 добавлений и 4 удалений

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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