blob: 611212d4509baa1c3fe9f3b89e92b956acaab259 [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"
Mike Reedebfce6d2016-12-12 10:02:12 -050012#include "SkClipOpPriv.h"
senorblancoafc7cce2016-02-02 18:44:15 -080013
14#define WIDTH 512
15#define HEIGHT 512
16
17namespace skiagm {
18
19class ComplexClipBlurTiledGM : public GM {
20public:
21 ComplexClipBlurTiledGM() {
22 }
23
24protected:
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;
robertphillips6e7025a2016-04-04 04:31:25 -070035 blurPaint.setImageFilter(SkBlurImageFilter::Make(5.0f, 5.0f, nullptr));
36 const SkScalar tileSize = SkIntToScalar(128);
senorblancoafc7cce2016-02-02 18:44:15 -080037 SkRect bounds;
38 if (!canvas->getClipBounds(&bounds)) {
39 bounds.setEmpty();
40 }
robertphillips6e7025a2016-04-04 04:31:25 -070041 int ts = SkScalarCeilToInt(tileSize);
senorblancoafc7cce2016-02-02 18:44:15 -080042 SkImageInfo info = SkImageInfo::MakeN32Premul(ts, ts);
reede8f30622016-03-23 18:59:25 -070043 auto tileSurface(canvas->makeSurface(info));
44 if (!tileSurface) {
45 tileSurface = SkSurface::MakeRaster(info);
senorblancoafc7cce2016-02-02 18:44:15 -080046 }
47 SkCanvas* tileCanvas = tileSurface->getCanvas();
robertphillips6e7025a2016-04-04 04:31:25 -070048 for (SkScalar y = bounds.top(); y < bounds.bottom(); y += tileSize) {
49 for (SkScalar x = bounds.left(); x < bounds.right(); x += tileSize) {
senorblancoafc7cce2016-02-02 18:44:15 -080050 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 Reedc1f77742016-12-09 09:00:50 -050056 tileCanvas->clipRRect(rrect, kDifference_SkClipOp, true);
senorblancoafc7cce2016-02-02 18:44:15 -080057 SkPaint paint;
58 tileCanvas->drawRect(rect, paint);
59 tileCanvas->restore();
60 tileCanvas->restore();
reed9ce9d672016-03-17 10:51:11 -070061 canvas->drawImage(tileSurface->makeImageSnapshot().get(), x, y);
senorblancoafc7cce2016-02-02 18:44:15 -080062 }
63 }
64 }
65
66private:
67 typedef GM INHERITED;
68};
69
70//////////////////////////////////////////////////////////////////////////////
71
robertphillips6e7025a2016-04-04 04:31:25 -070072DEF_GM(return new ComplexClipBlurTiledGM;)
senorblancoafc7cce2016-02-02 18:44:15 -080073
74}