Fix layer hoisting image filter corner cases
This CL fixes 5 bugs related to hoisting image filters:
For image filters the src layer (the one prior to filtering) often needs to be
smaller then the final layer. This requires the saveLayer's optional bounds
to be stored (in SkLayerInfo.h and SkRecordDraw.cpp) and then used in
compute_source_rect and carried around in GrCachedLayer.
The image filters can add an extra offset to the final draw operation.
This is now computed in GrLayerHoister::FilterLayer and carried around in
GrCachedLayer.
Filtered layers must use exact matches. This is now done in GrLayerCache::lock.
The filter cache requires a valid matrix so it can compute the correct offset.
This is now done in GrLayerHoister::FilterLayer.
Filtered layers need to be drawn with drawSprite while unfiltered (and therefore
hopefully atlased) layers can be drawn with drawBitmap. This is now done in
draw_replacement_bitmap.
Committed: https://skia.googlesource.com/skia/+/702eb9622102599d94ab6798e6227cf29f48c2d3
Review URL: https://codereview.chromium.org/803183003
diff --git a/src/gpu/GrLayerCache.h b/src/gpu/GrLayerCache.h
index 0ea23b3..cdbd080 100644
--- a/src/gpu/GrLayerCache.h
+++ b/src/gpu/GrLayerCache.h
@@ -144,13 +144,16 @@
// GrCachedLayer proper
GrCachedLayer(uint32_t pictureID, unsigned start, unsigned stop,
- const SkIRect& bounds, const SkMatrix& ctm,
+ const SkIRect& srcIR, const SkIRect& dstIR,
+ const SkMatrix& ctm,
const unsigned* key, int keySize,
const SkPaint* paint)
: fKey(pictureID, ctm, key, keySize, true)
, fStart(start)
, fStop(stop)
- , fBounds(bounds)
+ , fSrcIR(srcIR)
+ , fDstIR(dstIR)
+ , fOffset(SkIPoint::Make(0, 0))
, fPaint(paint ? SkNEW_ARGS(SkPaint, (*paint)) : NULL)
, fFilter(NULL)
, fTexture(NULL)
@@ -161,8 +164,10 @@
SkASSERT(SK_InvalidGenID != pictureID);
if (fPaint) {
- fFilter = SkSafeRef(fPaint->getImageFilter());
- fPaint->setImageFilter(NULL);
+ if (fPaint->getImageFilter() && fPaint->getImageFilter()->canFilterImageGPU()) {
+ fFilter = SkSafeRef(fPaint->getImageFilter());
+ fPaint->setImageFilter(NULL);
+ }
}
}
@@ -179,7 +184,8 @@
unsigned start() const { return fStart; }
// TODO: make bound debug only
- const SkIRect& bound() const { return fBounds; }
+ const SkIRect& srcIR() const { return fSrcIR; }
+ const SkIRect& dstIR() const { return fDstIR; }
unsigned stop() const { return fStop; }
void setTexture(GrTexture* texture, const SkIRect& rect) {
SkRefCnt_SafeAssign(fTexture, texture);
@@ -190,6 +196,9 @@
const SkImageFilter* filter() const { return fFilter; }
const SkIRect& rect() const { return fRect; }
+ void setOffset(const SkIPoint& offset) { fOffset = offset; }
+ const SkIPoint& offset() const { return fOffset; }
+
void setPlot(GrPlot* plot) {
SkASSERT(NULL == plot || NULL == fPlot);
fPlot = plot;
@@ -212,7 +221,13 @@
// The final "restore" operation index of the cached layer
const unsigned fStop;
- const SkIRect fBounds;
+ // The layer's src rect (i.e., the portion of the source scene required
+ // for filtering).
+ const SkIRect fSrcIR;
+ // The layer's dest rect (i.e., where it will land in device space)
+ const SkIRect fDstIR;
+ // Offset sometimes required by image filters
+ SkIPoint fOffset;
// The paint used when dropping the layer down into the owning canvas.
// Can be NULL. This class makes a copy for itself.
@@ -276,7 +291,8 @@
const unsigned* key, int keySize);
GrCachedLayer* findLayerOrCreate(uint32_t pictureID,
int start, int stop,
- const SkIRect& bounds,
+ const SkIRect& srcIR,
+ const SkIRect& dstIR,
const SkMatrix& initialMat,
const unsigned* key, int keySize,
const SkPaint* paint);
@@ -360,7 +376,8 @@
void initAtlas();
GrCachedLayer* createLayer(uint32_t pictureID, int start, int stop,
- const SkIRect& bounds, const SkMatrix& initialMat,
+ const SkIRect& srcIR, const SkIRect& dstIR,
+ const SkMatrix& initialMat,
const unsigned* key, int keySize,
const SkPaint* paint);