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" 12 #include "SkClipOpPriv.h" 13 #include "sk_tool_utils.h" 14 15 #define WIDTH 512 16 #define HEIGHT 512 17 18 namespace skiagm { 19 20 class ComplexClipBlurTiledGM : public GM { 21 public: 22 ComplexClipBlurTiledGM() { 23 } 24 25 protected: 26 SkString onShortName() override { 27 return SkString("complexclip_blur_tiled"); 28 } 29 30 SkISize onISize() override { 31 return SkISize::Make(WIDTH, HEIGHT); 32 } 33 34 void onDraw(SkCanvas* canvas) override { 35 SkPaint blurPaint; 36 blurPaint.setImageFilter(SkBlurImageFilter::Make(5.0f, 5.0f, nullptr)); 37 const SkScalar tileSize = SkIntToScalar(128); 38 SkRect bounds = canvas->getLocalClipBounds(); 39 int ts = SkScalarCeilToInt(tileSize); 40 SkImageInfo info = SkImageInfo::MakeN32Premul(ts, ts); 41 auto tileSurface(sk_tool_utils::makeSurface(canvas, info)); 42 SkCanvas* tileCanvas = tileSurface->getCanvas(); 43 for (SkScalar y = bounds.top(); y < bounds.bottom(); y += tileSize) { 44 for (SkScalar x = bounds.left(); x < bounds.right(); x += tileSize) { 45 tileCanvas->save(); 46 tileCanvas->clear(0); 47 tileCanvas->translate(-x, -y); 48 SkRect rect = SkRect::MakeWH(WIDTH, HEIGHT); 49 tileCanvas->saveLayer(&rect, &blurPaint); 50 SkRRect rrect = SkRRect::MakeRectXY(rect.makeInset(20, 20), 25, 25); 51 tileCanvas->clipRRect(rrect, kDifference_SkClipOp, true); 52 SkPaint paint; 53 tileCanvas->drawRect(rect, paint); 54 tileCanvas->restore(); 55 tileCanvas->restore(); 56 canvas->drawImage(tileSurface->makeImageSnapshot().get(), x, y); 57 } 58 } 59 } 60 61 private: 62 typedef GM INHERITED; 63 }; 64 65 ////////////////////////////////////////////////////////////////////////////// 66 67 DEF_GM(return new ComplexClipBlurTiledGM;) 68 69 } 70