Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1222)

Side by Side Diff: gm/complexclip_blur_tiled.cpp

Issue 1852743002: Update SkBlurImageFilter to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Update to ToT & address code review comments Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gm/colorfilterimagefilter.cpp ('k') | gm/filterfastbounds.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "gm.h" 8 #include "gm.h"
9 #include "SkBlurImageFilter.h" 9 #include "SkBlurImageFilter.h"
10 #include "SkRRect.h" 10 #include "SkRRect.h"
(...skipping 13 matching lines...) Expand all
24 SkString onShortName() override { 24 SkString onShortName() override {
25 return SkString("complexclip_blur_tiled"); 25 return SkString("complexclip_blur_tiled");
26 } 26 }
27 27
28 SkISize onISize() override { 28 SkISize onISize() override {
29 return SkISize::Make(WIDTH, HEIGHT); 29 return SkISize::Make(WIDTH, HEIGHT);
30 } 30 }
31 31
32 void onDraw(SkCanvas* canvas) override { 32 void onDraw(SkCanvas* canvas) override {
33 SkPaint blurPaint; 33 SkPaint blurPaint;
34 SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(5.0f, 5.0f)); 34 blurPaint.setImageFilter(SkBlurImageFilter::Make(5.0f, 5.0f, nullptr));
35 blurPaint.setImageFilter(blur); 35 const SkScalar tileSize = SkIntToScalar(128);
36 const SkScalar tile_size = SkIntToScalar(128);
37 SkRect bounds; 36 SkRect bounds;
38 if (!canvas->getClipBounds(&bounds)) { 37 if (!canvas->getClipBounds(&bounds)) {
39 bounds.setEmpty(); 38 bounds.setEmpty();
40 } 39 }
41 int ts = SkScalarCeilToInt(tile_size); 40 int ts = SkScalarCeilToInt(tileSize);
42 SkImageInfo info = SkImageInfo::MakeN32Premul(ts, ts); 41 SkImageInfo info = SkImageInfo::MakeN32Premul(ts, ts);
43 auto tileSurface(canvas->makeSurface(info)); 42 auto tileSurface(canvas->makeSurface(info));
44 if (!tileSurface) { 43 if (!tileSurface) {
45 tileSurface = SkSurface::MakeRaster(info); 44 tileSurface = SkSurface::MakeRaster(info);
46 } 45 }
47 SkCanvas* tileCanvas = tileSurface->getCanvas(); 46 SkCanvas* tileCanvas = tileSurface->getCanvas();
48 for (SkScalar y = bounds.top(); y < bounds.bottom(); y += tile_size) { 47 for (SkScalar y = bounds.top(); y < bounds.bottom(); y += tileSize) {
49 for (SkScalar x = bounds.left(); x < bounds.right(); x += tile_size) { 48 for (SkScalar x = bounds.left(); x < bounds.right(); x += tileSize) {
50 tileCanvas->save(); 49 tileCanvas->save();
51 tileCanvas->clear(0); 50 tileCanvas->clear(0);
52 tileCanvas->translate(-x, -y); 51 tileCanvas->translate(-x, -y);
53 SkRect rect = SkRect::MakeWH(WIDTH, HEIGHT); 52 SkRect rect = SkRect::MakeWH(WIDTH, HEIGHT);
54 tileCanvas->saveLayer(&rect, &blurPaint); 53 tileCanvas->saveLayer(&rect, &blurPaint);
55 SkRRect rrect = SkRRect::MakeRectXY(rect.makeInset(20, 20), 25, 25); 54 SkRRect rrect = SkRRect::MakeRectXY(rect.makeInset(20, 20), 25, 25);
56 tileCanvas->clipRRect(rrect, SkRegion::kDifference_Op, true); 55 tileCanvas->clipRRect(rrect, SkRegion::kDifference_Op, true);
57 SkPaint paint; 56 SkPaint paint;
58 tileCanvas->drawRect(rect, paint); 57 tileCanvas->drawRect(rect, paint);
59 tileCanvas->restore(); 58 tileCanvas->restore();
60 tileCanvas->restore(); 59 tileCanvas->restore();
61 canvas->drawImage(tileSurface->makeImageSnapshot().get(), x, y); 60 canvas->drawImage(tileSurface->makeImageSnapshot().get(), x, y);
62 } 61 }
63 } 62 }
64 } 63 }
65 64
66 private: 65 private:
67 typedef GM INHERITED; 66 typedef GM INHERITED;
68 }; 67 };
69 68
70 ////////////////////////////////////////////////////////////////////////////// 69 //////////////////////////////////////////////////////////////////////////////
71 70
72 static GM* MyFactory1(void*) { return new ComplexClipBlurTiledGM(); } 71 DEF_GM(return new ComplexClipBlurTiledGM;)
73 static GMRegistry reg1(MyFactory1);
74 72
75 } 73 }
OLDNEW
« no previous file with comments | « gm/colorfilterimagefilter.cpp ('k') | gm/filterfastbounds.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698