diff options
author | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-10-24 01:46:11 +0000 |
---|---|---|
committer | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-10-24 01:46:11 +0000 |
commit | bbfe4541ef154696313374de2130b1ac90e28482 (patch) | |
tree | 566838274cb53abb834309b11109b29c344a855d /gm | |
parent | e9821871ecebbeed06aaef54741a71607ccc9720 (diff) |
Apply matrix early in draw bitmap
Committed: http://code.google.com/p/skia/source/detail?r=11930
Reverted: https://code.google.com/p/skia/source/detail?r=11932
R=robertphillips@google.com, senorblanco@chromium.org
Author: bsalomon@google.com
Review URL: https://codereview.chromium.org/30593003
git-svn-id: http://skia.googlecode.com/svn/trunk@11933 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gm')
-rw-r--r-- | gm/imagefiltersgraph.cpp | 86 |
1 files changed, 84 insertions, 2 deletions
diff --git a/gm/imagefiltersgraph.cpp b/gm/imagefiltersgraph.cpp index 363a4147e9..98f82f5340 100644 --- a/gm/imagefiltersgraph.cpp +++ b/gm/imagefiltersgraph.cpp @@ -7,22 +7,88 @@ #include "gm.h" +#include "SkArithmeticMode.h" #include "SkBitmapSource.h" #include "SkBlurImageFilter.h" #include "SkColorFilter.h" #include "SkColorMatrixFilter.h" #include "SkColorFilterImageFilter.h" +#include "SkFlattenableBuffers.h" #include "SkMergeImageFilter.h" #include "SkMorphologyImageFilter.h" +#include "SkOnce.h" #include "SkXfermodeImageFilter.h" #include "SkTestImageFilters.h" /////////////////////////////////////////////////////////////////////////////// +namespace { +// More closely models how Blink's OffsetFilter works as of 10/23/13. SkOffsetImageFilter doesn't +// perform a draw and this one does. +class SimpleOffsetFilter : public SkImageFilter { +public: + SimpleOffsetFilter(SkScalar dx, SkScalar dy, SkImageFilter* input) + : SkImageFilter(input), fDX(dx), fDY(dy) {} + + virtual bool onFilterImage(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm, + SkBitmap* dst, SkIPoint* offset) SK_OVERRIDE { + SkBitmap source = src; + SkImageFilter* input = getInput(0); + SkIPoint srcOffset = SkIPoint::Make(0, 0); + if (NULL != input && !input->filterImage(proxy, src, ctm, &source, &srcOffset)) { + return false; + } + + SkIRect bounds; + source.getBounds(&bounds); + + if (!this->applyCropRect(&bounds, ctm)) { + return false; + } + + SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds.height())); + SkCanvas canvas(device); + SkPaint paint; + paint.setXfermodeMode(SkXfermode::kSrc_Mode); + canvas.drawBitmap(source, fDX - bounds.left(), fDY - bounds.top(), &paint); + *dst = device->accessBitmap(false); + offset->fX += bounds.left(); + offset->fY += bounds.top(); + return true; + } + + SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SimpleOffsetFilter); + +protected: + explicit SimpleOffsetFilter(SkFlattenableReadBuffer& buffer) + : SkImageFilter(buffer) { + fDX = buffer.readScalar(); + fDY = buffer.readScalar(); + } + + virtual void flatten(SkFlattenableWriteBuffer& buffer) const SK_OVERRIDE { + this->SkImageFilter::flatten(buffer); + buffer.writeScalar(fDX); + buffer.writeScalar(fDY); + } + +private: + SkScalar fDX, fDY; +}; +} + +static void init_flattenable(int*) { + SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SimpleOffsetFilter) +} + class ImageFiltersGraphGM : public skiagm::GM { public: - ImageFiltersGraphGM() : fInitialized(false) {} + ImageFiltersGraphGM() : fInitialized(false) { + int dummy; + SK_DECLARE_STATIC_ONCE(once); + SkOnce(&once, init_flattenable, &dummy); + } protected: virtual SkString onShortName() { @@ -43,7 +109,7 @@ protected: canvas.drawText(str, strlen(str), SkIntToScalar(20), SkIntToScalar(70), paint); } - virtual SkISize onISize() { return SkISize::Make(200, 100); } + virtual SkISize onISize() { return SkISize::Make(500, 150); } virtual void onDraw(SkCanvas* canvas) { if (!fInitialized) { @@ -81,6 +147,22 @@ protected: paint.setImageFilter(blendColor); canvas->drawBitmap(fBitmap, 100, 0, &paint); } + { + SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0, + 0, SK_Scalar1, 0, 0, 0, + 0, 0, SK_Scalar1, 0, 0, + 0, 0, 0, SkFloatToScalar(0.5f), 0 }; + SkColorMatrixFilter matrixCF(matrix); + SkAutoTUnref<SkImageFilter> matrixFilter(SkColorFilterImageFilter::Create(&matrixCF)); + SimpleOffsetFilter offsetFilter(SkIntToScalar(10), SkIntToScalar(10), matrixFilter); + + SkAutoTUnref<SkXfermode> arith(SkArithmeticMode::Create(0, SK_Scalar1, SK_Scalar1, 0)); + SkXfermodeImageFilter arithFilter(arith, matrixFilter, &offsetFilter); + + SkPaint paint; + paint.setImageFilter(&arithFilter); + canvas->drawSprite(fBitmap, 200, 0, &paint); + } } private: |