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

Side by Side Diff: gm/imagefiltersclipped.cpp

Issue 1810813003: update callsites for Make image factories (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: start to take advantage of sk_sp drawImage Created 4 years, 9 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/imagefilters.cpp ('k') | gm/imagefilterscropexpand.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 2014 Google Inc. 2 * Copyright 2014 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 "sk_tool_utils.h" 8 #include "sk_tool_utils.h"
9 #include "SkBlurImageFilter.h" 9 #include "SkBlurImageFilter.h"
10 #include "SkColor.h" 10 #include "SkColor.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(width, hei ght)); 50 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(width, hei ght));
51 SkCanvas* canvas = surface->getCanvas(); 51 SkCanvas* canvas = surface->getCanvas();
52 canvas->clear(0x00000000); 52 canvas->clear(0x00000000);
53 SkColor colors[2]; 53 SkColor colors[2];
54 colors[0] = SK_ColorWHITE; 54 colors[0] = SK_ColorWHITE;
55 colors[1] = SK_ColorBLACK; 55 colors[1] = SK_ColorBLACK;
56 SkPaint paint; 56 SkPaint paint;
57 paint.setShader(SkGradientShader::MakeRadial(SkPoint::Make(x, y), radius , colors, nullptr, 57 paint.setShader(SkGradientShader::MakeRadial(SkPoint::Make(x, y), radius , colors, nullptr,
58 2, SkShader::kClamp_TileMod e)); 58 2, SkShader::kClamp_TileMod e));
59 canvas->drawCircle(x, y, radius, paint); 59 canvas->drawCircle(x, y, radius, paint);
60 fGradientCircle.reset(surface->newImageSnapshot()); 60 fGradientCircle = surface->makeImageSnapshot();
61 } 61 }
62 62
63 static void draw_clipped_filter(SkCanvas* canvas, SkImageFilter* filter, siz e_t i, 63 static void draw_clipped_filter(SkCanvas* canvas, SkImageFilter* filter, siz e_t i,
64 const SkRect& primBounds, const SkRect& clip Bounds) { 64 const SkRect& primBounds, const SkRect& clip Bounds) {
65 SkPaint paint; 65 SkPaint paint;
66 paint.setColor(SK_ColorWHITE); 66 paint.setColor(SK_ColorWHITE);
67 paint.setImageFilter(filter); 67 paint.setImageFilter(filter);
68 paint.setAntiAlias(true); 68 paint.setAntiAlias(true);
69 canvas->save(); 69 canvas->save();
70 canvas->clipRect(clipBounds); 70 canvas->clipRect(clipBounds);
71 if (5 == i) { 71 if (5 == i) {
72 canvas->translate(SkIntToScalar(16), SkIntToScalar(-32)); 72 canvas->translate(SkIntToScalar(16), SkIntToScalar(-32));
73 } else if (6 == i) { 73 } else if (6 == i) {
74 canvas->scale(SkScalarInvert(RESIZE_FACTOR_X), 74 canvas->scale(SkScalarInvert(RESIZE_FACTOR_X),
75 SkScalarInvert(RESIZE_FACTOR_Y)); 75 SkScalarInvert(RESIZE_FACTOR_Y));
76 } 76 }
77 canvas->drawCircle(primBounds.centerX(), primBounds.centerY(), 77 canvas->drawCircle(primBounds.centerX(), primBounds.centerY(),
78 primBounds.width() * 2 / 5, paint); 78 primBounds.width() * 2 / 5, paint);
79 canvas->restore(); 79 canvas->restore();
80 } 80 }
81 81
82 void onOnceBeforeDraw() override { 82 void onOnceBeforeDraw() override {
83 fCheckerboard.reset(SkImage::NewFromBitmap 83 fCheckerboard = SkImage::MakeFromBitmap
84 (sk_tool_utils::create_checkerboard_bitmap(64, 64, 0xFFA0A0A0, 0xFF4 04040, 8))); 84 (sk_tool_utils::create_checkerboard_bitmap(64, 64, 0xFFA0A0A0, 0xFF4 04040, 8));
85 this->makeGradientCircle(64, 64); 85 this->makeGradientCircle(64, 64);
86 } 86 }
87 87
88 void onDraw(SkCanvas* canvas) override { 88 void onDraw(SkCanvas* canvas) override {
89 canvas->clear(SK_ColorBLACK); 89 canvas->clear(SK_ColorBLACK);
90 90
91 SkAutoTUnref<SkImageFilter> gradient(SkImageSource::Create(fGradientCirc le)); 91 SkAutoTUnref<SkImageFilter> gradient(SkImageSource::Create(fGradientCirc le.get()));
92 SkAutoTUnref<SkImageFilter> checkerboard(SkImageSource::Create(fCheckerb oard)); 92 SkAutoTUnref<SkImageFilter> checkerboard(SkImageSource::Create(fCheckerb oard.get()));
93 SkAutoTUnref<SkShader> noise(SkPerlinNoiseShader::CreateFractalNoise( 93 SkAutoTUnref<SkShader> noise(SkPerlinNoiseShader::CreateFractalNoise(
94 SkDoubleToScalar(0.1), SkDoubleToScalar(0.05), 1, 0)); 94 SkDoubleToScalar(0.1), SkDoubleToScalar(0.05), 1, 0));
95 SkMatrix resizeMatrix; 95 SkMatrix resizeMatrix;
96 resizeMatrix.setScale(RESIZE_FACTOR_X, RESIZE_FACTOR_Y); 96 resizeMatrix.setScale(RESIZE_FACTOR_X, RESIZE_FACTOR_Y);
97 SkPoint3 pointLocation = SkPoint3::Make(32, 32, SkIntToScalar(10)); 97 SkPoint3 pointLocation = SkPoint3::Make(32, 32, SkIntToScalar(10));
98 98
99 SkImageFilter* filters[] = { 99 SkImageFilter* filters[] = {
100 SkBlurImageFilter::Create(SkIntToScalar(12), SkIntToScalar(12)), 100 SkBlurImageFilter::Create(SkIntToScalar(12), SkIntToScalar(12)),
101 SkDropShadowImageFilter::Create(SkIntToScalar(10), SkIntToScalar(10) , 101 SkDropShadowImageFilter::Create(SkIntToScalar(10), SkIntToScalar(10) ,
102 SkIntToScalar(3), SkIntToScalar(3), SK_ColorGREEN, 102 SkIntToScalar(3), SkIntToScalar(3), SK_ColorGREEN,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 SkAutoTUnref<SkImageFilter> rectFilter(SkPaintImageFilter::Create(noiseP aint)); 141 SkAutoTUnref<SkImageFilter> rectFilter(SkPaintImageFilter::Create(noiseP aint));
142 canvas->translate(SK_ARRAY_COUNT(filters)*(r.width() + margin), 0); 142 canvas->translate(SK_ARRAY_COUNT(filters)*(r.width() + margin), 0);
143 for (int xOffset = 0; xOffset < 80; xOffset += 16) { 143 for (int xOffset = 0; xOffset < 80; xOffset += 16) {
144 bounds.fLeft = SkIntToScalar(xOffset); 144 bounds.fLeft = SkIntToScalar(xOffset);
145 draw_clipped_filter(canvas, rectFilter, 0, r, bounds); 145 draw_clipped_filter(canvas, rectFilter, 0, r, bounds);
146 canvas->translate(0, r.height() + margin); 146 canvas->translate(0, r.height() + margin);
147 } 147 }
148 } 148 }
149 149
150 private: 150 private:
151 SkAutoTUnref<SkImage> fCheckerboard, fGradientCircle; 151 sk_sp<SkImage> fCheckerboard, fGradientCircle;
152 152
153 typedef GM INHERITED; 153 typedef GM INHERITED;
154 }; 154 };
155 155
156 ////////////////////////////////////////////////////////////////////////////// 156 //////////////////////////////////////////////////////////////////////////////
157 157
158 DEF_GM(return new ImageFiltersClippedGM;) 158 DEF_GM(return new ImageFiltersClippedGM;)
159 } 159 }
OLDNEW
« no previous file with comments | « gm/imagefilters.cpp ('k') | gm/imagefilterscropexpand.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698