blob: 47234da55f7502d98f789d2e32e608fcedafdc6e [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"
Mike Reed46596ae2018-01-02 15:40:29 -050013#include "sk_tool_utils.h"
senorblancoafc7cce2016-02-02 18:44:15 -080014
15#define WIDTH 512
16#define HEIGHT 512
17
18namespace skiagm {
19
20class ComplexClipBlurTiledGM : public GM {
21public:
22 ComplexClipBlurTiledGM() {
23 }
24
25protected:
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;
robertphillips6e7025a2016-04-04 04:31:25 -070036 blurPaint.setImageFilter(SkBlurImageFilter::Make(5.0f, 5.0f, nullptr));
37 const SkScalar tileSize = SkIntToScalar(128);
Mike Reed918e1442017-01-23 11:39:45 -050038 SkRect bounds = canvas->getLocalClipBounds();
robertphillips6e7025a2016-04-04 04:31:25 -070039 int ts = SkScalarCeilToInt(tileSize);
senorblancoafc7cce2016-02-02 18:44:15 -080040 SkImageInfo info = SkImageInfo::MakeN32Premul(ts, ts);
Mike Reed46596ae2018-01-02 15:40:29 -050041 auto tileSurface(sk_tool_utils::makeSurface(canvas, info));
senorblancoafc7cce2016-02-02 18:44:15 -080042 SkCanvas* tileCanvas = tileSurface->getCanvas();
robertphillips6e7025a2016-04-04 04:31:25 -070043 for (SkScalar y = bounds.top(); y < bounds.bottom(); y += tileSize) {
44 for (SkScalar x = bounds.left(); x < bounds.right(); x += tileSize) {
senorblancoafc7cce2016-02-02 18:44:15 -080045 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);
Mike Reedc1f77742016-12-09 09:00:50 -050051 tileCanvas->clipRRect(rrect, kDifference_SkClipOp, true);
senorblancoafc7cce2016-02-02 18:44:15 -080052 SkPaint paint;
53 tileCanvas->drawRect(rect, paint);
54 tileCanvas->restore();
55 tileCanvas->restore();
reed9ce9d672016-03-17 10:51:11 -070056 canvas->drawImage(tileSurface->makeImageSnapshot().get(), x, y);
senorblancoafc7cce2016-02-02 18:44:15 -080057 }
58 }
59 }
60
61private:
62 typedef GM INHERITED;
63};
64
65//////////////////////////////////////////////////////////////////////////////
66
robertphillips6e7025a2016-04-04 04:31:25 -070067DEF_GM(return new ComplexClipBlurTiledGM;)
senorblancoafc7cce2016-02-02 18:44:15 -080068
69}