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

Side by Side Diff: gm/imagefiltersclipped.cpp

Issue 1320673011: Minor code cleanup (left over from prior CL) (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 3 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/displacement.cpp ('k') | gm/imagefiltersgraph.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 "SkBitmapSource.h" 9 #include "SkBitmapSource.h"
10 #include "SkBlurImageFilter.h" 10 #include "SkBlurImageFilter.h"
(...skipping 10 matching lines...) Expand all
21 #include "SkScalar.h" 21 #include "SkScalar.h"
22 #include "gm.h" 22 #include "gm.h"
23 23
24 #define RESIZE_FACTOR_X SkIntToScalar(2) 24 #define RESIZE_FACTOR_X SkIntToScalar(2)
25 #define RESIZE_FACTOR_Y SkIntToScalar(5) 25 #define RESIZE_FACTOR_Y SkIntToScalar(5)
26 26
27 namespace skiagm { 27 namespace skiagm {
28 28
29 class ImageFiltersClippedGM : public GM { 29 class ImageFiltersClippedGM : public GM {
30 public: 30 public:
31 ImageFiltersClippedGM() : fInitialized(false) { 31 ImageFiltersClippedGM() {
32 this->setBGColor(0x00000000); 32 this->setBGColor(0x00000000);
33 } 33 }
34 34
35 protected: 35 protected:
36
37 SkString onShortName() override { 36 SkString onShortName() override {
38 return SkString("imagefiltersclipped"); 37 return SkString("imagefiltersclipped");
39 } 38 }
40 39
41 SkISize onISize() override { 40 SkISize onISize() override {
42 return SkISize::Make(860, 500); 41 return SkISize::Make(860, 500);
43 } 42 }
44 43
45 void make_gradient_circle(int width, int height) { 44 void makeGradientCircle(int width, int height) {
46 SkScalar x = SkIntToScalar(width / 2); 45 SkScalar x = SkIntToScalar(width / 2);
47 SkScalar y = SkIntToScalar(height / 2); 46 SkScalar y = SkIntToScalar(height / 2);
48 SkScalar radius = SkMinScalar(x, y) * 0.8f; 47 SkScalar radius = SkMinScalar(x, y) * 0.8f;
49 fGradientCircle.allocN32Pixels(width, height); 48 fGradientCircle.allocN32Pixels(width, height);
50 SkCanvas canvas(fGradientCircle); 49 SkCanvas canvas(fGradientCircle);
51 canvas.clear(0x00000000); 50 canvas.clear(0x00000000);
52 SkColor colors[2]; 51 SkColor colors[2];
53 colors[0] = SK_ColorWHITE; 52 colors[0] = SK_ColorWHITE;
54 colors[1] = SK_ColorBLACK; 53 colors[1] = SK_ColorBLACK;
55 SkAutoTUnref<SkShader> shader( 54 SkAutoTUnref<SkShader> shader(
(...skipping 17 matching lines...) Expand all
73 canvas->translate(SkIntToScalar(16), SkIntToScalar(-32)); 72 canvas->translate(SkIntToScalar(16), SkIntToScalar(-32));
74 } else if (6 == i) { 73 } else if (6 == i) {
75 canvas->scale(SkScalarInvert(RESIZE_FACTOR_X), 74 canvas->scale(SkScalarInvert(RESIZE_FACTOR_X),
76 SkScalarInvert(RESIZE_FACTOR_Y)); 75 SkScalarInvert(RESIZE_FACTOR_Y));
77 } 76 }
78 canvas->drawCircle(primBounds.centerX(), primBounds.centerY(), 77 canvas->drawCircle(primBounds.centerX(), primBounds.centerY(),
79 primBounds.width() * 2 / 5, paint); 78 primBounds.width() * 2 / 5, paint);
80 canvas->restore(); 79 canvas->restore();
81 } 80 }
82 81
82 void onOnceBeforeDraw() override {
83 fCheckerboard = sk_tool_utils::create_checkerboard_bitmap(64, 64,
84 0xFFA0A0A0, 0x FF404040, 8);
85 this->makeGradientCircle(64, 64);
86 }
87
83 void onDraw(SkCanvas* canvas) override { 88 void onDraw(SkCanvas* canvas) override {
84 if (!fInitialized) {
85 fCheckerboard.allocN32Pixels(64, 64);
86 SkCanvas checkerboardCanvas(fCheckerboard);
87 sk_tool_utils::draw_checkerboard(&checkerboardCanvas, 0xFFA0A0A0, 0x FF404040, 8);
88
89 this->make_gradient_circle(64, 64);
90 fInitialized = true;
91 }
92 canvas->clear(SK_ColorBLACK); 89 canvas->clear(SK_ColorBLACK);
93 90
94 SkAutoTUnref<SkImageFilter> gradient(SkBitmapSource::Create(fGradientCir cle)); 91 SkAutoTUnref<SkImageFilter> gradient(SkBitmapSource::Create(fGradientCir cle));
95 SkAutoTUnref<SkImageFilter> checkerboard(SkBitmapSource::Create(fChecker board)); 92 SkAutoTUnref<SkImageFilter> checkerboard(SkBitmapSource::Create(fChecker board));
96 SkAutoTUnref<SkShader> noise(SkPerlinNoiseShader::CreateFractalNoise( 93 SkAutoTUnref<SkShader> noise(SkPerlinNoiseShader::CreateFractalNoise(
97 SkDoubleToScalar(0.1), SkDoubleToScalar(0.05), 1, 0)); 94 SkDoubleToScalar(0.1), SkDoubleToScalar(0.05), 1, 0));
98 SkMatrix resizeMatrix; 95 SkMatrix resizeMatrix;
99 resizeMatrix.setScale(RESIZE_FACTOR_X, RESIZE_FACTOR_Y); 96 resizeMatrix.setScale(RESIZE_FACTOR_X, RESIZE_FACTOR_Y);
100 SkPoint3 pointLocation = SkPoint3::Make(32, 32, SkIntToScalar(10)); 97 SkPoint3 pointLocation = SkPoint3::Make(32, 32, SkIntToScalar(10));
101 98
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 canvas->translate(SK_ARRAY_COUNT(filters)*(r.width() + margin), 0); 140 canvas->translate(SK_ARRAY_COUNT(filters)*(r.width() + margin), 0);
144 for (int xOffset = 0; xOffset < 80; xOffset += 16) { 141 for (int xOffset = 0; xOffset < 80; xOffset += 16) {
145 bounds.fLeft = SkIntToScalar(xOffset); 142 bounds.fLeft = SkIntToScalar(xOffset);
146 draw_clipped_filter(canvas, rectFilter, 0, r, bounds); 143 draw_clipped_filter(canvas, rectFilter, 0, r, bounds);
147 canvas->translate(0, r.height() + margin); 144 canvas->translate(0, r.height() + margin);
148 } 145 }
149 SkSafeUnref(rectFilter); 146 SkSafeUnref(rectFilter);
150 } 147 }
151 148
152 private: 149 private:
153 bool fInitialized;
154 SkBitmap fCheckerboard; 150 SkBitmap fCheckerboard;
155 SkBitmap fGradientCircle; 151 SkBitmap fGradientCircle;
152
156 typedef GM INHERITED; 153 typedef GM INHERITED;
157 }; 154 };
158 155
159 ////////////////////////////////////////////////////////////////////////////// 156 //////////////////////////////////////////////////////////////////////////////
160 157
161 static GM* MyFactory(void*) { return new ImageFiltersClippedGM; } 158 DEF_GM(return new ImageFiltersClippedGM;)
162 static GMRegistry reg(MyFactory);
163
164 } 159 }
OLDNEW
« no previous file with comments | « gm/displacement.cpp ('k') | gm/imagefiltersgraph.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698