GrRenderTarget* rt = origDrawState->getRenderTarget();
GrAssert(NULL != rt);
- if (fAACache.canReuse(clipIn, rt->width(), rt->height())) {
- *result = fAACache.getLastMask();
- fAACache.getLastBound(resultBounds);
- return true;
- }
-
GrRect rtRect;
rtRect.setLTRB(0, 0,
GrIntToScalar(rt->width()), GrIntToScalar(rt->height()));
GrAssert(SkScalarIsInt(bounds.width()));
GrAssert(SkScalarIsInt(bounds.height()));
+ if (fAACache.canReuse(clipIn,
+ SkScalarCeilToInt(bounds.width()),
+ SkScalarCeilToInt(bounds.height()))) {
+ *result = fAACache.getLastMask();
+ fAACache.getLastBound(resultBounds);
+ return true;
+ }
+
const GrTextureDesc desc = {
kRenderTarget_GrTextureFlagBit|kNoStencil_GrTextureFlagBit,
SkScalarCeilToInt(bounds.width()),
}
}
- fAACache.set(clipIn, rt->width(), rt->height(), accum, bounds);
+ fAACache.set(clipIn, accum, bounds);
*result = accum;
*resultBounds = bounds;
SkSafeUnref(accum); // fAACache still has a ref to accum
GrClipStackFrame* back = (GrClipStackFrame*) fStack.back();
- if (back->fLastWidth >= width &&
- back->fLastHeight >= height &&
+ if (back->fLastMask &&
+ back->fLastMask->width() >= width &&
+ back->fLastMask->height() >= height &&
clip == back->fLastClip) {
return true;
}
return false;
}
- void set(const GrClip& clip, int width, int height,
- GrTexture* mask, const GrRect& bound) {
+ void set(const GrClip& clip, GrTexture* mask, const GrRect& bound) {
if (fStack.empty()) {
GrAssert(false);
GrClipStackFrame* back = (GrClipStackFrame*) fStack.back();
- back->fLastWidth = width;
- back->fLastHeight = height;
back->fLastClip = clip;
SkSafeRef(mask);
back->fLastMask.reset(mask);
}
}
- int getLastWidth() const {
-
- if (fStack.empty()) {
- GrAssert(false);
- return -1;
- }
-
- GrClipStackFrame* back = (GrClipStackFrame*) fStack.back();
-
- return back->fLastWidth;
- }
-
- int getLastHeight() const {
-
- if (fStack.empty()) {
- GrAssert(false);
- return -1;
- }
-
- GrClipStackFrame* back = (GrClipStackFrame*) fStack.back();
-
- return back->fLastHeight;
- }
-
void getLastClip(GrClip* clip) const {
if (fStack.empty()) {
}
void reset () {
- fLastWidth = -1;
- fLastHeight = -1;
fLastClip.setEmpty();
fLastMask.reset(NULL);
fLastBound.setEmpty();
}
- // fLastWidth & fLastHeight store the render target size used when
- // creating the mask. They factor into the reuse decision (in canReuse)
- // TODO: We should probably use the mask's width & height rather than
- // the render target's width & height for reuse decisions
- int fLastWidth;
- int fLastHeight;
GrClip fLastClip;
// The mask's width & height values are used in setupDrawStateAAClip to
// correctly scale the uvs for geometry drawn with this mask
// verify that the top state of the stack matches the passed in state
static void check_state(skiatest::Reporter* reporter,
const GrClipMaskCache& cache,
- int width,
- int height,
const GrClip& clip,
GrTexture* mask,
const GrRect& bound) {
- REPORTER_ASSERT(reporter, width == cache.getLastWidth());
- REPORTER_ASSERT(reporter, height == cache.getLastHeight());
-
GrClip cacheClip;
cache.getLastClip(&cacheClip);
REPORTER_ASSERT(reporter, clip == cacheClip);
emptyBound.setEmpty();
// check initial state
- check_state(reporter, cache, -1, -1, emptyClip, NULL, emptyBound);
+ check_state(reporter, cache, emptyClip, NULL, emptyBound);
// set the current state
GrRect bound1;
return;
}
- cache.set(clip1, 128, 128, texture.get(), bound1);
+ cache.set(clip1, texture.get(), bound1);
// check that the set took
- check_state(reporter, cache, 128, 128, clip1, texture.get(), bound1);
+ check_state(reporter, cache, clip1, texture.get(), bound1);
REPORTER_ASSERT(reporter, 2 == texture.get()->getRefCnt());
// push the state
cache.push();
// verify that the pushed state is initially empty
- check_state(reporter, cache, -1, -1, emptyClip, NULL, emptyBound);
+ check_state(reporter, cache, emptyClip, NULL, emptyBound);
REPORTER_ASSERT(reporter, 2 == texture.get()->getRefCnt());
// modify the new state
clip2.setEmpty();
clip2.setFromRect(bound2);
- cache.set(clip2, 10, 10, texture.get(), bound2);
+ cache.set(clip2, texture.get(), bound2);
// check that the changes took
- check_state(reporter, cache, 10, 10, clip2, texture.get(), bound2);
+ check_state(reporter, cache, clip2, texture.get(), bound2);
REPORTER_ASSERT(reporter, 3 == texture.get()->getRefCnt());
// check to make sure canReuse works
cache.pop();
// verify that the old state is restored
- check_state(reporter, cache, 128, 128, clip1, texture.get(), bound1);
+ check_state(reporter, cache, clip1, texture.get(), bound1);
REPORTER_ASSERT(reporter, 2 == texture.get()->getRefCnt());
// manually clear the state
cache.reset();
// verify it is now empty
- check_state(reporter, cache, -1, -1, emptyClip, NULL, emptyBound);
+ check_state(reporter, cache, emptyClip, NULL, emptyBound);
REPORTER_ASSERT(reporter, 1 == texture.get()->getRefCnt());
// pop again - so there is no state