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

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: 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 "SkMorphologyImageFilter.h" 16 #include "SkMorphologyImageFilter.h"
16 #include "SkOffsetImageFilter.h" 17 #include "SkOffsetImageFilter.h"
17 #include "SkPerlinNoiseShader.h" 18 #include "SkPerlinNoiseShader.h"
(...skipping 18 matching lines...) Expand all
36 } 37 }
37 38
38 virtual SkString onShortName() SK_OVERRIDE { 39 virtual SkString onShortName() SK_OVERRIDE {
39 return SkString("imagefiltersclipped"); 40 return SkString("imagefiltersclipped");
40 } 41 }
41 42
42 virtual SkISize onISize() SK_OVERRIDE { 43 virtual SkISize onISize() SK_OVERRIDE {
43 return SkISize::Make(860, 500); 44 return SkISize::Make(860, 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 = SkMinScalar(x, y) * 0.8f; 50 SkScalar radius = SkMinScalar(x, y) * 0.8f;
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) SK_OVERRIDE { 66 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
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 SkMatrix resizeMatrix; 81 SkMatrix resizeMatrix;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 SkBitmap fGradientCircle; 139 SkBitmap fGradientCircle;
157 typedef GM INHERITED; 140 typedef GM INHERITED;
158 }; 141 };
159 142
160 ////////////////////////////////////////////////////////////////////////////// 143 //////////////////////////////////////////////////////////////////////////////
161 144
162 static GM* MyFactory(void*) { return new ImageFiltersClippedGM; } 145 static GM* MyFactory(void*) { return new ImageFiltersClippedGM; }
163 static GMRegistry reg(MyFactory); 146 static GMRegistry reg(MyFactory);
164 147
165 } 148 }
OLDNEW
« gm/checkerboard.h ('K') | « gm/displacement.cpp ('k') | gm/imagefiltersscaled.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698