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

Side by Side Diff: gm/imagefiltersclipped.cpp

Issue 834303005: Factor out checkerboard function in gm and sampleapp into tools. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rename to sk_tools::DrawCheckerboard Created 5 years, 11 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/imagefiltersscaled.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 "gm.h" 8 #include "Checkerboard.h"
9 #include "SkColor.h"
10 #include "SkBitmapSource.h" 9 #include "SkBitmapSource.h"
11 #include "SkBlurImageFilter.h" 10 #include "SkBlurImageFilter.h"
11 #include "SkColor.h"
12 #include "SkDisplacementMapEffect.h" 12 #include "SkDisplacementMapEffect.h"
13 #include "SkDropShadowImageFilter.h" 13 #include "SkDropShadowImageFilter.h"
14 #include "SkGradientShader.h" 14 #include "SkGradientShader.h"
15 #include "SkMatrixImageFilter.h"
15 #include "SkMorphologyImageFilter.h" 16 #include "SkMorphologyImageFilter.h"
16 #include "SkOffsetImageFilter.h" 17 #include "SkOffsetImageFilter.h"
17 #include "SkPerlinNoiseShader.h" 18 #include "SkPerlinNoiseShader.h"
18 #include "SkRectShaderImageFilter.h" 19 #include "SkRectShaderImageFilter.h"
19 #include "SkMatrixImageFilter.h"
20 #include "SkScalar.h" 20 #include "SkScalar.h"
21 #include "gm.h"
21 22
22 #define RESIZE_FACTOR_X SkIntToScalar(2) 23 #define RESIZE_FACTOR_X SkIntToScalar(2)
23 #define RESIZE_FACTOR_Y SkIntToScalar(5) 24 #define RESIZE_FACTOR_Y SkIntToScalar(5)
24 25
25 namespace skiagm { 26 namespace skiagm {
26 27
27 class ImageFiltersClippedGM : public GM { 28 class ImageFiltersClippedGM : public GM {
28 public: 29 public:
29 ImageFiltersClippedGM() : fInitialized(false) { 30 ImageFiltersClippedGM() : fInitialized(false) {
30 this->setBGColor(0x00000000); 31 this->setBGColor(0x00000000);
31 } 32 }
32 33
33 protected: 34 protected:
34 35
35 SkString onShortName() SK_OVERRIDE { 36 SkString onShortName() SK_OVERRIDE {
36 return SkString("imagefiltersclipped"); 37 return SkString("imagefiltersclipped");
37 } 38 }
38 39
39 SkISize onISize() SK_OVERRIDE { 40 SkISize onISize() SK_OVERRIDE {
40 return SkISize::Make(860, 500); 41 return SkISize::Make(860, 500);
41 } 42 }
42 43
43 void make_checkerboard() {
44 fCheckerboard.allocN32Pixels(64, 64);
45 SkCanvas canvas(fCheckerboard);
46 canvas.clear(0x00000000);
47 SkPaint darkPaint;
48 darkPaint.setColor(0xFF404040);
49 SkPaint lightPaint;
50 lightPaint.setColor(0xFFA0A0A0);
51 for (int y = 0; y < 64; y += 16) {
52 for (int x = 0; x < 64; x += 16) {
53 canvas.save();
54 canvas.translate(SkIntToScalar(x), SkIntToScalar(y));
55 canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint);
56 canvas.drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint);
57 canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint);
58 canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint);
59 canvas.restore();
60 }
61 }
62 }
63
64 void make_gradient_circle(int width, int height) { 44 void make_gradient_circle(int width, int height) {
65 SkScalar x = SkIntToScalar(width / 2); 45 SkScalar x = SkIntToScalar(width / 2);
66 SkScalar y = SkIntToScalar(height / 2); 46 SkScalar y = SkIntToScalar(height / 2);
67 SkScalar radius = SkMinScalar(x, y) * 0.8f; 47 SkScalar radius = SkMinScalar(x, y) * 0.8f;
68 fGradientCircle.allocN32Pixels(width, height); 48 fGradientCircle.allocN32Pixels(width, height);
69 SkCanvas canvas(fGradientCircle); 49 SkCanvas canvas(fGradientCircle);
70 canvas.clear(0x00000000); 50 canvas.clear(0x00000000);
71 SkColor colors[2]; 51 SkColor colors[2];
72 colors[0] = SK_ColorWHITE; 52 colors[0] = SK_ColorWHITE;
73 colors[1] = SK_ColorBLACK; 53 colors[1] = SK_ColorBLACK;
74 SkAutoTUnref<SkShader> shader( 54 SkAutoTUnref<SkShader> shader(
75 SkGradientShader::CreateRadial(SkPoint::Make(x, y), radius, colors, NULL, 2, 55 SkGradientShader::CreateRadial(SkPoint::Make(x, y), radius, colors, NULL, 2,
76 SkShader::kClamp_TileMode) 56 SkShader::kClamp_TileMode)
77 ); 57 );
78 SkPaint paint; 58 SkPaint paint;
79 paint.setShader(shader); 59 paint.setShader(shader);
80 canvas.drawCircle(x, y, radius, paint); 60 canvas.drawCircle(x, y, radius, paint);
81 } 61 }
82 62
83 void onDraw(SkCanvas* canvas) SK_OVERRIDE { 63 void onDraw(SkCanvas* canvas) SK_OVERRIDE {
84 if (!fInitialized) { 64 if (!fInitialized) {
85 this->make_checkerboard(); 65 fCheckerboard.allocN32Pixels(64, 64);
66 SkCanvas checkerboardCanvas(fCheckerboard);
67 sk_tools::DrawCheckerboard(&checkerboardCanvas, 0xFFA0A0A0, 0xFF4040 40, 8);
68
86 this->make_gradient_circle(64, 64); 69 this->make_gradient_circle(64, 64);
87 fInitialized = true; 70 fInitialized = true;
88 } 71 }
89 canvas->clear(0x00000000); 72 canvas->clear(0x00000000);
90 73
91 SkAutoTUnref<SkImageFilter> gradient(SkBitmapSource::Create(fGradientCir cle)); 74 SkAutoTUnref<SkImageFilter> gradient(SkBitmapSource::Create(fGradientCir cle));
92 SkAutoTUnref<SkImageFilter> checkerboard(SkBitmapSource::Create(fChecker board)); 75 SkAutoTUnref<SkImageFilter> checkerboard(SkBitmapSource::Create(fChecker board));
93 SkAutoTUnref<SkShader> noise(SkPerlinNoiseShader::CreateFractalNoise( 76 SkAutoTUnref<SkShader> noise(SkPerlinNoiseShader::CreateFractalNoise(
94 SkDoubleToScalar(0.1), SkDoubleToScalar(0.05), 1, 0)); 77 SkDoubleToScalar(0.1), SkDoubleToScalar(0.05), 1, 0));
95 SkMatrix resizeMatrix; 78 SkMatrix resizeMatrix;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 SkBitmap fGradientCircle; 136 SkBitmap fGradientCircle;
154 typedef GM INHERITED; 137 typedef GM INHERITED;
155 }; 138 };
156 139
157 ////////////////////////////////////////////////////////////////////////////// 140 //////////////////////////////////////////////////////////////////////////////
158 141
159 static GM* MyFactory(void*) { return new ImageFiltersClippedGM; } 142 static GM* MyFactory(void*) { return new ImageFiltersClippedGM; }
160 static GMRegistry reg(MyFactory); 143 static GMRegistry reg(MyFactory);
161 144
162 } 145 }
OLDNEW
« no previous file with comments | « gm/displacement.cpp ('k') | gm/imagefiltersscaled.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698