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

Side by Side Diff: gm/imagefiltersscaled.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: ignore pdf gm change 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
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 "checkerboard.h"
8 #include "gm.h" 9 #include "gm.h"
9 #include "SkColor.h" 10 #include "SkColor.h"
10 #include "SkBitmapSource.h" 11 #include "SkBitmapSource.h"
11 #include "SkBlurImageFilter.h" 12 #include "SkBlurImageFilter.h"
12 #include "SkDisplacementMapEffect.h" 13 #include "SkDisplacementMapEffect.h"
13 #include "SkDropShadowImageFilter.h" 14 #include "SkDropShadowImageFilter.h"
14 #include "SkGradientShader.h" 15 #include "SkGradientShader.h"
15 #include "SkLightingImageFilter.h" 16 #include "SkLightingImageFilter.h"
16 #include "SkMorphologyImageFilter.h" 17 #include "SkMorphologyImageFilter.h"
17 #include "SkOffsetImageFilter.h" 18 #include "SkOffsetImageFilter.h"
(...skipping 18 matching lines...) Expand all
36 } 37 }
37 38
38 virtual SkString onShortName() { 39 virtual SkString onShortName() {
39 return SkString("imagefiltersscaled"); 40 return SkString("imagefiltersscaled");
40 } 41 }
41 42
42 virtual SkISize onISize() { 43 virtual SkISize onISize() {
43 return SkISize::Make(1428, 500); 44 return SkISize::Make(1428, 500);
44 } 45 }
45 46
46 void make_checkerboard() {
47 fCheckerboard.allocN32Pixels(64, 64);
48 SkCanvas canvas(fCheckerboard);
49 canvas.clear(0x00000000);
50 SkPaint darkPaint;
51 darkPaint.setColor(0xFF404040);
52 SkPaint lightPaint;
53 lightPaint.setColor(0xFFA0A0A0);
54 for (int y = 0; y < 64; y += 16) {
55 for (int x = 0; x < 64; x += 16) {
56 canvas.save();
57 canvas.translate(SkIntToScalar(x), SkIntToScalar(y));
58 canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint);
59 canvas.drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint);
60 canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint);
61 canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint);
62 canvas.restore();
63 }
64 }
65 }
66
67 void make_gradient_circle(int width, int height) { 47 void make_gradient_circle(int width, int height) {
68 SkScalar x = SkIntToScalar(width / 2); 48 SkScalar x = SkIntToScalar(width / 2);
69 SkScalar y = SkIntToScalar(height / 2); 49 SkScalar y = SkIntToScalar(height / 2);
70 SkScalar radius = SkScalarMul(SkMinScalar(x, y), SkIntToScalar(4) / SkIn tToScalar(5)); 50 SkScalar radius = SkScalarMul(SkMinScalar(x, y), SkIntToScalar(4) / SkIn tToScalar(5));
71 fGradientCircle.allocN32Pixels(width, height); 51 fGradientCircle.allocN32Pixels(width, height);
72 SkCanvas canvas(fGradientCircle); 52 SkCanvas canvas(fGradientCircle);
73 canvas.clear(0x00000000); 53 canvas.clear(0x00000000);
74 SkColor colors[2]; 54 SkColor colors[2];
75 colors[0] = SK_ColorWHITE; 55 colors[0] = SK_ColorWHITE;
76 colors[1] = SK_ColorBLACK; 56 colors[1] = SK_ColorBLACK;
77 SkAutoTUnref<SkShader> shader( 57 SkAutoTUnref<SkShader> shader(
78 SkGradientShader::CreateRadial(SkPoint::Make(x, y), radius, colors, NULL, 2, 58 SkGradientShader::CreateRadial(SkPoint::Make(x, y), radius, colors, NULL, 2,
79 SkShader::kClamp_TileMode) 59 SkShader::kClamp_TileMode)
80 ); 60 );
81 SkPaint paint; 61 SkPaint paint;
82 paint.setShader(shader); 62 paint.setShader(shader);
83 canvas.drawCircle(x, y, radius, paint); 63 canvas.drawCircle(x, y, radius, paint);
84 } 64 }
85 65
86 virtual void onDraw(SkCanvas* canvas) { 66 virtual void onDraw(SkCanvas* canvas) {
87 if (!fInitialized) { 67 if (!fInitialized) {
88 this->make_checkerboard(); 68 fCheckerboard.allocN32Pixels(64, 64);
69 SkCanvas checkerboardCanvas(fCheckerboard);
70 skiagm::Checkerboard(&checkerboardCanvas, 0xFFA0A0A0, 0xFF404040);
71
89 this->make_gradient_circle(64, 64); 72 this->make_gradient_circle(64, 64);
90 fInitialized = true; 73 fInitialized = true;
91 } 74 }
92 canvas->clear(0x00000000); 75 canvas->clear(0x00000000);
93 76
94 SkAutoTUnref<SkImageFilter> gradient(SkBitmapSource::Create(fGradientCir cle)); 77 SkAutoTUnref<SkImageFilter> gradient(SkBitmapSource::Create(fGradientCir cle));
95 SkAutoTUnref<SkImageFilter> checkerboard(SkBitmapSource::Create(fChecker board)); 78 SkAutoTUnref<SkImageFilter> checkerboard(SkBitmapSource::Create(fChecker board));
96 SkAutoTUnref<SkShader> noise(SkPerlinNoiseShader::CreateFractalNoise( 79 SkAutoTUnref<SkShader> noise(SkPerlinNoiseShader::CreateFractalNoise(
97 SkDoubleToScalar(0.1), SkDoubleToScalar(0.05), 1, 0)); 80 SkDoubleToScalar(0.1), SkDoubleToScalar(0.05), 1, 0));
98 81
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 SkBitmap fGradientCircle; 158 SkBitmap fGradientCircle;
176 typedef GM INHERITED; 159 typedef GM INHERITED;
177 }; 160 };
178 161
179 ////////////////////////////////////////////////////////////////////////////// 162 //////////////////////////////////////////////////////////////////////////////
180 163
181 static GM* MyFactory(void*) { return new ImageFiltersScaledGM; } 164 static GM* MyFactory(void*) { return new ImageFiltersScaledGM; }
182 static GMRegistry reg(MyFactory); 165 static GMRegistry reg(MyFactory);
183 166
184 } 167 }
OLDNEW
« gm/checkerboard.h ('K') | « gm/imagefiltersclipped.cpp ('k') | gm/offsetimagefilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698