blob: 5b684af3b1008d0f64d0c894939512534470db89 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -04009#include "include/core/SkCanvas.h"
10#include "include/core/SkImageFilter.h"
11#include "include/core/SkImageInfo.h"
12#include "include/core/SkPaint.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "include/core/SkRRect.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040014#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"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050019#include "include/core/SkSurface.h"
20#include "include/effects/SkBlurImageFilter.h"
21#include "src/core/SkClipOpPriv.h"
22#include "tools/ToolUtils.h"
senorblancoafc7cce2016-02-02 18:44:15 -080023
24#define WIDTH 512
25#define HEIGHT 512
26
27namespace skiagm {
28
29class ComplexClipBlurTiledGM : public GM {
30public:
31 ComplexClipBlurTiledGM() {
32 }
33
34protected:
35 SkString onShortName() override {
36 return SkString("complexclip_blur_tiled");
37 }
38
39 SkISize onISize() override {
40 return SkISize::Make(WIDTH, HEIGHT);
41 }
42
43 void onDraw(SkCanvas* canvas) override {
44 SkPaint blurPaint;
robertphillips6e7025a2016-04-04 04:31:25 -070045 blurPaint.setImageFilter(SkBlurImageFilter::Make(5.0f, 5.0f, nullptr));
46 const SkScalar tileSize = SkIntToScalar(128);
Mike Reed918e1442017-01-23 11:39:45 -050047 SkRect bounds = canvas->getLocalClipBounds();
robertphillips6e7025a2016-04-04 04:31:25 -070048 int ts = SkScalarCeilToInt(tileSize);
senorblancoafc7cce2016-02-02 18:44:15 -080049 SkImageInfo info = SkImageInfo::MakeN32Premul(ts, ts);
Mike Kleinea3f0142019-03-20 11:12:10 -050050 auto tileSurface(ToolUtils::makeSurface(canvas, info));
senorblancoafc7cce2016-02-02 18:44:15 -080051 SkCanvas* tileCanvas = tileSurface->getCanvas();
robertphillips6e7025a2016-04-04 04:31:25 -070052 for (SkScalar y = bounds.top(); y < bounds.bottom(); y += tileSize) {
53 for (SkScalar x = bounds.left(); x < bounds.right(); x += tileSize) {
senorblancoafc7cce2016-02-02 18:44:15 -080054 tileCanvas->save();
55 tileCanvas->clear(0);
56 tileCanvas->translate(-x, -y);
57 SkRect rect = SkRect::MakeWH(WIDTH, HEIGHT);
58 tileCanvas->saveLayer(&rect, &blurPaint);
59 SkRRect rrect = SkRRect::MakeRectXY(rect.makeInset(20, 20), 25, 25);
Mike Reedc1f77742016-12-09 09:00:50 -050060 tileCanvas->clipRRect(rrect, kDifference_SkClipOp, true);
senorblancoafc7cce2016-02-02 18:44:15 -080061 SkPaint paint;
62 tileCanvas->drawRect(rect, paint);
63 tileCanvas->restore();
64 tileCanvas->restore();
reed9ce9d672016-03-17 10:51:11 -070065 canvas->drawImage(tileSurface->makeImageSnapshot().get(), x, y);
senorblancoafc7cce2016-02-02 18:44:15 -080066 }
67 }
68 }
69
70private:
71 typedef GM INHERITED;
72};
73
74//////////////////////////////////////////////////////////////////////////////
75
robertphillips6e7025a2016-04-04 04:31:25 -070076DEF_GM(return new ComplexClipBlurTiledGM;)
senorblancoafc7cce2016-02-02 18:44:15 -080077
78}