2 * Copyright 2016 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
9 #include "include/core/SkCanvas.h"
10 #include "include/core/SkImageFilter.h"
11 #include "include/core/SkImageInfo.h"
12 #include "include/core/SkPaint.h"
13 #include "include/core/SkRRect.h"
14 #include "include/core/SkRect.h"
15 #include "include/core/SkRefCnt.h"
16 #include "include/core/SkScalar.h"
17 #include "include/core/SkSize.h"
18 #include "include/core/SkString.h"
19 #include "include/core/SkSurface.h"
20 #include "include/effects/SkImageFilters.h"
21 #include "tools/ToolUtils.h"
28 class ComplexClipBlurTiledGM : public GM {
30 ComplexClipBlurTiledGM() {
34 SkString onShortName() override {
35 return SkString("complexclip_blur_tiled");
38 SkISize onISize() override {
39 return SkISize::Make(WIDTH, HEIGHT);
42 void onDraw(SkCanvas* canvas) override {
44 blurPaint.setImageFilter(SkImageFilters::Blur(5.0f, 5.0f, nullptr));
45 const SkScalar tileSize = SkIntToScalar(128);
46 SkRect bounds = canvas->getLocalClipBounds();
47 int ts = SkScalarCeilToInt(tileSize);
48 SkImageInfo info = SkImageInfo::MakeN32Premul(ts, ts);
49 auto tileSurface(ToolUtils::makeSurface(canvas, info));
50 SkCanvas* tileCanvas = tileSurface->getCanvas();
51 for (SkScalar y = bounds.top(); y < bounds.bottom(); y += tileSize) {
52 for (SkScalar x = bounds.left(); x < bounds.right(); x += tileSize) {
55 tileCanvas->translate(-x, -y);
56 SkRect rect = SkRect::MakeWH(WIDTH, HEIGHT);
57 tileCanvas->saveLayer(&rect, &blurPaint);
58 SkRRect rrect = SkRRect::MakeRectXY(rect.makeInset(20, 20), 25, 25);
59 tileCanvas->clipRRect(rrect, SkClipOp::kDifference, true);
61 tileCanvas->drawRect(rect, paint);
62 tileCanvas->restore();
63 tileCanvas->restore();
64 canvas->drawImage(tileSurface->makeImageSnapshot().get(), x, y);
73 //////////////////////////////////////////////////////////////////////////////
75 DEF_GM(return new ComplexClipBlurTiledGM;)