blob: 979c7e7423fa81cfb6bcc62beea99d81b9adfe29 [file] [log] [blame]
senorblancoafc7cce2016-02-02 18:44:15 -08001/*
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
13#define WIDTH 512
14#define HEIGHT 512
15
16namespace skiagm {
17
18class ComplexClipBlurTiledGM : public GM {
19public:
20 ComplexClipBlurTiledGM() {
21 }
22
23protected:
24 SkString onShortName() override {
25 return SkString("complexclip_blur_tiled");
26 }
27
28 SkISize onISize() override {
29 return SkISize::Make(WIDTH, HEIGHT);
30 }
31
32 void onDraw(SkCanvas* canvas) override {
33 SkPaint blurPaint;
robertphillips6e7025a2016-04-04 04:31:25 -070034 blurPaint.setImageFilter(SkBlurImageFilter::Make(5.0f, 5.0f, nullptr));
35 const SkScalar tileSize = SkIntToScalar(128);
senorblancoafc7cce2016-02-02 18:44:15 -080036 SkRect bounds;
37 if (!canvas->getClipBounds(&bounds)) {
38 bounds.setEmpty();
39 }
robertphillips6e7025a2016-04-04 04:31:25 -070040 int ts = SkScalarCeilToInt(tileSize);
senorblancoafc7cce2016-02-02 18:44:15 -080041 SkImageInfo info = SkImageInfo::MakeN32Premul(ts, ts);
reede8f30622016-03-23 18:59:25 -070042 auto tileSurface(canvas->makeSurface(info));
43 if (!tileSurface) {
44 tileSurface = SkSurface::MakeRaster(info);
senorblancoafc7cce2016-02-02 18:44:15 -080045 }
46 SkCanvas* tileCanvas = tileSurface->getCanvas();
robertphillips6e7025a2016-04-04 04:31:25 -070047 for (SkScalar y = bounds.top(); y < bounds.bottom(); y += tileSize) {
48 for (SkScalar x = bounds.left(); x < bounds.right(); x += tileSize) {
senorblancoafc7cce2016-02-02 18:44:15 -080049 tileCanvas->save();
50 tileCanvas->clear(0);
51 tileCanvas->translate(-x, -y);
52 SkRect rect = SkRect::MakeWH(WIDTH, HEIGHT);
53 tileCanvas->saveLayer(&rect, &blurPaint);
54 SkRRect rrect = SkRRect::MakeRectXY(rect.makeInset(20, 20), 25, 25);
55 tileCanvas->clipRRect(rrect, SkRegion::kDifference_Op, true);
56 SkPaint paint;
57 tileCanvas->drawRect(rect, paint);
58 tileCanvas->restore();
59 tileCanvas->restore();
reed9ce9d672016-03-17 10:51:11 -070060 canvas->drawImage(tileSurface->makeImageSnapshot().get(), x, y);
senorblancoafc7cce2016-02-02 18:44:15 -080061 }
62 }
63 }
64
65private:
66 typedef GM INHERITED;
67};
68
69//////////////////////////////////////////////////////////////////////////////
70
robertphillips6e7025a2016-04-04 04:31:25 -070071DEF_GM(return new ComplexClipBlurTiledGM;)
senorblancoafc7cce2016-02-02 18:44:15 -080072
73}