senorblanco | afc7cce | 2016-02-02 18:44:15 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "gm.h" |
| 9 | #include "SkBlurImageFilter.h" |
| 10 | #include "SkRRect.h" |
| 11 | #include "SkSurface.h" |
Mike Reed | ebfce6d | 2016-12-12 10:02:12 -0500 | [diff] [blame^] | 12 | #include "SkClipOpPriv.h" |
senorblanco | afc7cce | 2016-02-02 18:44:15 -0800 | [diff] [blame] | 13 | |
| 14 | #define WIDTH 512 |
| 15 | #define HEIGHT 512 |
| 16 | |
| 17 | namespace skiagm { |
| 18 | |
| 19 | class ComplexClipBlurTiledGM : public GM { |
| 20 | public: |
| 21 | ComplexClipBlurTiledGM() { |
| 22 | } |
| 23 | |
| 24 | protected: |
| 25 | SkString onShortName() override { |
| 26 | return SkString("complexclip_blur_tiled"); |
| 27 | } |
| 28 | |
| 29 | SkISize onISize() override { |
| 30 | return SkISize::Make(WIDTH, HEIGHT); |
| 31 | } |
| 32 | |
| 33 | void onDraw(SkCanvas* canvas) override { |
| 34 | SkPaint blurPaint; |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 35 | blurPaint.setImageFilter(SkBlurImageFilter::Make(5.0f, 5.0f, nullptr)); |
| 36 | const SkScalar tileSize = SkIntToScalar(128); |
senorblanco | afc7cce | 2016-02-02 18:44:15 -0800 | [diff] [blame] | 37 | SkRect bounds; |
| 38 | if (!canvas->getClipBounds(&bounds)) { |
| 39 | bounds.setEmpty(); |
| 40 | } |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 41 | int ts = SkScalarCeilToInt(tileSize); |
senorblanco | afc7cce | 2016-02-02 18:44:15 -0800 | [diff] [blame] | 42 | SkImageInfo info = SkImageInfo::MakeN32Premul(ts, ts); |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 43 | auto tileSurface(canvas->makeSurface(info)); |
| 44 | if (!tileSurface) { |
| 45 | tileSurface = SkSurface::MakeRaster(info); |
senorblanco | afc7cce | 2016-02-02 18:44:15 -0800 | [diff] [blame] | 46 | } |
| 47 | SkCanvas* tileCanvas = tileSurface->getCanvas(); |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 48 | for (SkScalar y = bounds.top(); y < bounds.bottom(); y += tileSize) { |
| 49 | for (SkScalar x = bounds.left(); x < bounds.right(); x += tileSize) { |
senorblanco | afc7cce | 2016-02-02 18:44:15 -0800 | [diff] [blame] | 50 | tileCanvas->save(); |
| 51 | tileCanvas->clear(0); |
| 52 | tileCanvas->translate(-x, -y); |
| 53 | SkRect rect = SkRect::MakeWH(WIDTH, HEIGHT); |
| 54 | tileCanvas->saveLayer(&rect, &blurPaint); |
| 55 | SkRRect rrect = SkRRect::MakeRectXY(rect.makeInset(20, 20), 25, 25); |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 56 | tileCanvas->clipRRect(rrect, kDifference_SkClipOp, true); |
senorblanco | afc7cce | 2016-02-02 18:44:15 -0800 | [diff] [blame] | 57 | SkPaint paint; |
| 58 | tileCanvas->drawRect(rect, paint); |
| 59 | tileCanvas->restore(); |
| 60 | tileCanvas->restore(); |
reed | 9ce9d67 | 2016-03-17 10:51:11 -0700 | [diff] [blame] | 61 | canvas->drawImage(tileSurface->makeImageSnapshot().get(), x, y); |
senorblanco | afc7cce | 2016-02-02 18:44:15 -0800 | [diff] [blame] | 62 | } |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | private: |
| 67 | typedef GM INHERITED; |
| 68 | }; |
| 69 | |
| 70 | ////////////////////////////////////////////////////////////////////////////// |
| 71 | |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 72 | DEF_GM(return new ComplexClipBlurTiledGM;) |
senorblanco | afc7cce | 2016-02-02 18:44:15 -0800 | [diff] [blame] | 73 | |
| 74 | } |