// We could reuse the mask if bounds is a subset of last bounds. We'd have to communicate
// an offset to the caller.
- if (back->fLastMask.texture() &&
+ if (back->fLastMask &&
+ !back->fLastMask->wasDestroyed() &&
back->fLastBound == bounds &&
back->fLastClipGenID == clipGenID) {
return true;
GrClipStackFrame* back = (GrClipStackFrame*) fStack.back();
- return back->fLastMask.texture();
+ return back->fLastMask;
}
const GrTexture* getLastMask() const {
GrClipStackFrame* back = (GrClipStackFrame*) fStack.back();
- return back->fLastMask.texture();
+ return back->fLastMask;
}
void acquireMask(int32_t clipGenID,
- const GrTextureDesc& desc,
+ const GrSurfaceDesc& desc,
const SkIRect& bound) {
if (fStack.empty()) {
GrClipStackFrame* back = (GrClipStackFrame*) fStack.back();
- if (NULL == back->fLastMask.texture()) {
+ if (NULL == back->fLastMask) {
return -1;
}
- return back->fLastMask.texture()->width();
+ return back->fLastMask->width();
}
int getLastMaskHeight() const {
GrClipStackFrame* back = (GrClipStackFrame*) fStack.back();
- if (NULL == back->fLastMask.texture()) {
+ if (NULL == back->fLastMask) {
return -1;
}
- return back->fLastMask.texture()->height();
+ return back->fLastMask->height();
}
void getLastBound(SkIRect* bound) const {
return fContext;
}
- void releaseResources() {
-
+ // TODO: Remove this when we hold cache keys instead of refs to textures.
+ void purgeResources() {
SkDeque::F2BIter iter(fStack);
for (GrClipStackFrame* frame = (GrClipStackFrame*) iter.next();
frame != NULL;
void acquireMask(GrContext* context,
int32_t clipGenID,
- const GrTextureDesc& desc,
+ const GrSurfaceDesc& desc,
const SkIRect& bound) {
fLastClipGenID = clipGenID;
- fLastMask.set(context, desc);
+ // HACK: set the last param to true to indicate that this request is at
+ // flush time and therefore we require a scratch texture with no pending IO operations.
+ fLastMask.reset(context->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch,
+ /*flushing=*/true));
fLastBound = bound;
}
void reset () {
fLastClipGenID = SkClipStack::kInvalidGenID;
- GrTextureDesc desc;
+ GrSurfaceDesc desc;
- fLastMask.set(NULL, desc);
+ fLastMask.reset(NULL);
fLastBound.setEmpty();
}
int32_t fLastClipGenID;
// The mask's width & height values are used by GrClipMaskManager to correctly scale the
- // texture coords for the geometry drawn with this mask.
- GrAutoScratchTexture fLastMask;
+ // texture coords for the geometry drawn with this mask. TODO: This should be a cache key
+ // and not a hard ref to a texture.
+ SkAutoTUnref<GrTexture> fLastMask;
// fLastBound stores the bounding box of the clip mask in clip-stack space. This rect is
// used by GrClipMaskManager to position a rect and compute texture coords for the mask.
SkIRect fLastBound;