diff options
-rw-r--r-- | expectations/gm/ignored-tests.txt | 3 | ||||
-rw-r--r-- | gm/displacement.cpp | 53 | ||||
-rw-r--r-- | src/effects/SkDisplacementMapEffect.cpp | 16 |
3 files changed, 62 insertions, 10 deletions
diff --git a/expectations/gm/ignored-tests.txt b/expectations/gm/ignored-tests.txt index ac67f631e4..87384dbda4 100644 --- a/expectations/gm/ignored-tests.txt +++ b/expectations/gm/ignored-tests.txt @@ -77,3 +77,6 @@ clipped-bitmap-shaders-tile-hq_angle # Added by senorblanco to accomodate bounds fixes for SkXfermodeImageFilter in https://codereview.chromium.org/112683004. xfermodeimagefilter + +# Added by sugoi in https://codereview.chromium.org/101623007 +displacement diff --git a/gm/displacement.cpp b/gm/displacement.cpp index 350b8e30f3..5a20f8187b 100644 --- a/gm/displacement.cpp +++ b/gm/displacement.cpp @@ -22,6 +22,15 @@ protected: return SkString("displacement"); } + void make_bitmaps() { + make_bitmap(); + make_checkerboard(&fCheckerboard, 80, 80); + make_checkerboard(&fSmall, 64, 64); + make_checkerboard(&fLarge, 96, 96); + make_checkerboard(&fLargeW, 96, 64); + make_checkerboard(&fLargeH, 64, 96); + } + void make_bitmap() { fBitmap.setConfig(SkBitmap::kARGB_8888_Config, 80, 80); fBitmap.allocPixels(); @@ -36,18 +45,18 @@ protected: canvas.drawText(str, strlen(str), SkIntToScalar(15), SkIntToScalar(55), paint); } - void make_checkerboard() { - fCheckerboard.setConfig(SkBitmap::kARGB_8888_Config, 80, 80); - fCheckerboard.allocPixels(); - SkBitmapDevice device(fCheckerboard); + void make_checkerboard(SkBitmap* bitmap, int w, int h) { + bitmap->setConfig(SkBitmap::kARGB_8888_Config, w, h); + bitmap->allocPixels(); + SkBitmapDevice device(*bitmap); SkCanvas canvas(&device); canvas.clear(0x00000000); SkPaint darkPaint; darkPaint.setColor(0xFF804020); SkPaint lightPaint; lightPaint.setColor(0xFF244484); - for (int y = 0; y < 80; y += 16) { - for (int x = 0; x < 80; x += 16) { + for (int y = 0; y < h; y += 16) { + for (int x = 0; x < w; x += 16) { canvas.save(); canvas.translate(SkIntToScalar(x), SkIntToScalar(y)); canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint); @@ -60,7 +69,7 @@ protected: } virtual SkISize onISize() { - return make_isize(500, 400); + return make_isize(500, 500); } void drawClippedBitmap(SkCanvas* canvas, int x, int y, const SkPaint& paint) { @@ -73,8 +82,7 @@ protected: virtual void onDraw(SkCanvas* canvas) { if (!fInitialized) { - make_bitmap(); - make_checkerboard(); + make_bitmaps(); fInitialized = true; } canvas->clear(0x00000000); @@ -174,11 +182,36 @@ protected: SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ, NULL, &cropRect)))->unref(); drawClippedBitmap(canvas, 400, 300, paint); + + displ.reset(SkNEW_ARGS(SkBitmapSource, (fSmall))); + paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, + (SkDisplacementMapEffect::kR_ChannelSelectorType, + SkDisplacementMapEffect::kG_ChannelSelectorType, + 40.0f, displ)))->unref(); + drawClippedBitmap(canvas, 0, 400, paint); + displ.reset(SkNEW_ARGS(SkBitmapSource, (fLarge))); + paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, + (SkDisplacementMapEffect::kB_ChannelSelectorType, + SkDisplacementMapEffect::kA_ChannelSelectorType, + 40.0f, displ)))->unref(); + drawClippedBitmap(canvas, 100, 400, paint); + displ.reset(SkNEW_ARGS(SkBitmapSource, (fLargeW))); + paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, + (SkDisplacementMapEffect::kR_ChannelSelectorType, + SkDisplacementMapEffect::kB_ChannelSelectorType, + 40.0f, displ)))->unref(); + drawClippedBitmap(canvas, 200, 400, paint); + displ.reset(SkNEW_ARGS(SkBitmapSource, (fLargeH))); + paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, + (SkDisplacementMapEffect::kG_ChannelSelectorType, + SkDisplacementMapEffect::kA_ChannelSelectorType, + 40.0f, displ)))->unref(); + drawClippedBitmap(canvas, 300, 400, paint); } private: typedef GM INHERITED; - SkBitmap fBitmap, fCheckerboard; + SkBitmap fBitmap, fCheckerboard, fSmall, fLarge, fLargeW, fLargeH; bool fInitialized; }; diff --git a/src/effects/SkDisplacementMapEffect.cpp b/src/effects/SkDisplacementMapEffect.cpp index 6e5c910edf..f43287c4d7 100644 --- a/src/effects/SkDisplacementMapEffect.cpp +++ b/src/effects/SkDisplacementMapEffect.cpp @@ -205,6 +205,14 @@ bool SkDisplacementMapEffect::onFilterImage(Proxy* proxy, if (!this->applyCropRect(&bounds, ctm)) { return false; } + SkIRect displBounds; + displ.getBounds(&displBounds); + if (!this->applyCropRect(&displBounds, ctm)) { + return false; + } + if (!bounds.intersect(displBounds)) { + return false; + } dst->setConfig(color.config(), bounds.width(), bounds.height()); dst->allocPixels(); @@ -338,6 +346,14 @@ bool SkDisplacementMapEffect::filterImageGPU(Proxy* proxy, const SkBitmap& src, if (!this->applyCropRect(&bounds, ctm)) { return false; } + SkIRect displBounds; + displacementBM.getBounds(&displBounds); + if (!this->applyCropRect(&displBounds, ctm)) { + return false; + } + if (!bounds.intersect(displBounds)) { + return false; + } SkRect srcRect = SkRect::Make(bounds); SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); context->drawRectToRect(paint, dstRect, srcRect); |