Switch to a more complete method of filtering hoisted layers
Committed: https://skia.googlesource.com/skia/+/74668a8e818fd891a08c4966cc5973b04c1ad992 Review URL: https://codereview.chromium.org/842323003
This commit is contained in:
parent
38cd055215
commit
95145a9d3e
@ -164,7 +164,7 @@ public:
|
||||
SkASSERT(SK_InvalidGenID != pictureID);
|
||||
|
||||
if (fPaint) {
|
||||
if (fPaint->getImageFilter() && fPaint->getImageFilter()->canFilterImageGPU()) {
|
||||
if (fPaint->getImageFilter()) {
|
||||
fFilter = SkSafeRef(fPaint->getImageFilter());
|
||||
fPaint->setImageFilter(NULL);
|
||||
}
|
||||
@ -190,6 +190,9 @@ public:
|
||||
void setTexture(GrTexture* texture, const SkIRect& rect) {
|
||||
SkRefCnt_SafeAssign(fTexture, texture);
|
||||
fRect = rect;
|
||||
if (!fTexture) {
|
||||
fLocked = false;
|
||||
}
|
||||
}
|
||||
GrTexture* texture() { return fTexture; }
|
||||
const SkPaint* paint() const { return fPaint; }
|
||||
|
@ -10,6 +10,8 @@
|
||||
#include "GrRecordReplaceDraw.h"
|
||||
|
||||
#include "SkCanvas.h"
|
||||
#include "SkDeviceImageFilterProxy.h"
|
||||
#include "SkDeviceProperties.h"
|
||||
#include "SkGpuDevice.h"
|
||||
#include "SkGrPixelRef.h"
|
||||
#include "SkLayerInfo.h"
|
||||
@ -274,13 +276,21 @@ void GrLayerHoister::DrawLayersToAtlas(GrContext* context,
|
||||
}
|
||||
}
|
||||
|
||||
SkBitmap wrap_texture(GrTexture* texture) {
|
||||
SkASSERT(texture);
|
||||
|
||||
SkBitmap result;
|
||||
result.setInfo(texture->surfacePriv().info());
|
||||
result.setPixelRef(SkNEW_ARGS(SkGrPixelRef, (result.info(), texture)))->unref();
|
||||
return result;
|
||||
}
|
||||
|
||||
void GrLayerHoister::FilterLayer(GrContext* context,
|
||||
SkGpuDevice* device,
|
||||
const GrHoistedLayer& info) {
|
||||
GrCachedLayer* layer = info.fLayer;
|
||||
|
||||
SkASSERT(layer->filter());
|
||||
SkASSERT(layer->filter()->canFilterImageGPU());
|
||||
|
||||
static const int kDefaultCacheSize = 32 * 1024 * 1024;
|
||||
|
||||
@ -294,7 +304,6 @@ void GrLayerHoister::FilterLayer(GrContext* context,
|
||||
totMat.preConcat(info.fLocalMat);
|
||||
totMat.postTranslate(-SkIntToScalar(filterOffset.fX), -SkIntToScalar(filterOffset.fY));
|
||||
|
||||
|
||||
SkASSERT(0 == layer->rect().fLeft && 0 == layer->rect().fTop);
|
||||
SkIRect clipBounds = layer->rect();
|
||||
|
||||
@ -303,9 +312,11 @@ void GrLayerHoister::FilterLayer(GrContext* context,
|
||||
SkAutoTUnref<SkImageFilter::Cache> cache(SkImageFilter::Cache::Create(kDefaultCacheSize));
|
||||
SkImageFilter::Context filterContext(totMat, clipBounds, cache);
|
||||
|
||||
if (!device->filterTexture(context, layer->texture(), layer->filter(),
|
||||
filterContext, &filteredBitmap, &offset)) {
|
||||
// Filtering failed. Press on with the unfiltered version
|
||||
SkDeviceImageFilterProxy proxy(device, SkSurfaceProps(0, kUnknown_SkPixelGeometry));
|
||||
const SkBitmap src = wrap_texture(layer->texture());
|
||||
|
||||
if (!layer->filter()->filterImage(&proxy, src, filterContext, &filteredBitmap, &offset)) {
|
||||
// Filtering failed. Press on with the unfiltered version.
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,12 @@ static inline void wrap_texture(GrTexture* texture, int width, int height, SkBit
|
||||
|
||||
static inline void draw_replacement_bitmap(GrCachedLayer* layer, SkCanvas* canvas) {
|
||||
|
||||
// Some image filter can totally filter away a layer (e.g., SkPictureImageFilter's with
|
||||
// no picture).
|
||||
if (!layer->texture()) {
|
||||
return;
|
||||
}
|
||||
|
||||
SkBitmap bm;
|
||||
wrap_texture(layer->texture(),
|
||||
!layer->isAtlased() ? layer->rect().width() : layer->texture()->width(),
|
||||
|
Loading…
Reference in New Issue
Block a user