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

Side by Side Diff: gm/xfermodeimagefilter.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, 10 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/tileimagefilter.cpp ('k') | gyp/SampleApp.gyp » ('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 2013 Google Inc. 2 * Copyright 2013 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 "gm.h"
9 #include "Checkerboard.h"
9 #include "SkArithmeticMode.h" 10 #include "SkArithmeticMode.h"
10 #include "SkOffsetImageFilter.h" 11 #include "SkOffsetImageFilter.h"
11 #include "SkXfermodeImageFilter.h" 12 #include "SkXfermodeImageFilter.h"
12 #include "SkBitmapSource.h" 13 #include "SkBitmapSource.h"
13 14
14 #define WIDTH 600 15 #define WIDTH 600
15 #define HEIGHT 600 16 #define HEIGHT 600
16 #define MARGIN 12 17 #define MARGIN 12
17 18
18 namespace skiagm { 19 namespace skiagm {
(...skipping 15 matching lines...) Expand all
34 canvas.clear(0x00000000); 35 canvas.clear(0x00000000);
35 SkPaint paint; 36 SkPaint paint;
36 paint.setAntiAlias(true); 37 paint.setAntiAlias(true);
37 sk_tool_utils::set_portable_typeface(&paint); 38 sk_tool_utils::set_portable_typeface(&paint);
38 paint.setColor(0xD000D000); 39 paint.setColor(0xD000D000);
39 paint.setTextSize(SkIntToScalar(96)); 40 paint.setTextSize(SkIntToScalar(96));
40 const char* str = "e"; 41 const char* str = "e";
41 canvas.drawText(str, strlen(str), SkIntToScalar(15), SkIntToScalar(65), paint); 42 canvas.drawText(str, strlen(str), SkIntToScalar(15), SkIntToScalar(65), paint);
42 } 43 }
43 44
44 void make_checkerboard() {
45 fCheckerboard.allocN32Pixels(80, 80);
46 SkCanvas canvas(fCheckerboard);
47 canvas.clear(0x00000000);
48 SkPaint darkPaint;
49 darkPaint.setColor(0xFF404040);
50 SkPaint lightPaint;
51 lightPaint.setColor(0xFFA0A0A0);
52 for (int y = 0; y < 80; y += 16) {
53 for (int x = 0; x < 80; x += 16) {
54 canvas.save();
55 canvas.translate(SkIntToScalar(x), SkIntToScalar(y));
56 canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint);
57 canvas.drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint);
58 canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint);
59 canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint);
60 canvas.restore();
61 }
62 }
63 }
64
65 SkISize onISize() SK_OVERRIDE { 45 SkISize onISize() SK_OVERRIDE {
66 return SkISize::Make(WIDTH, HEIGHT); 46 return SkISize::Make(WIDTH, HEIGHT);
67 } 47 }
68 48
69 static void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, cons t SkPaint& paint, 49 static void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, cons t SkPaint& paint,
70 int x, int y) { 50 int x, int y) {
71 canvas->save(); 51 canvas->save();
72 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); 52 canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
73 canvas->clipRect(SkRect::MakeWH( 53 canvas->clipRect(SkRect::MakeWH(
74 SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height()))); 54 SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height())));
75 canvas->drawBitmap(bitmap, 0, 0, &paint); 55 canvas->drawBitmap(bitmap, 0, 0, &paint);
76 canvas->restore(); 56 canvas->restore();
77 } 57 }
78 58
79 static void drawClippedPaint(SkCanvas* canvas, const SkRect& rect, const SkP aint& paint, 59 static void drawClippedPaint(SkCanvas* canvas, const SkRect& rect, const SkP aint& paint,
80 int x, int y) { 60 int x, int y) {
81 canvas->save(); 61 canvas->save();
82 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); 62 canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
83 canvas->clipRect(rect); 63 canvas->clipRect(rect);
84 canvas->drawPaint(paint); 64 canvas->drawPaint(paint);
85 canvas->restore(); 65 canvas->restore();
86 } 66 }
87 67
88 void onOnceBeforeDraw() SK_OVERRIDE { 68 void onOnceBeforeDraw() SK_OVERRIDE {
89 make_bitmap(); 69 make_bitmap();
90 make_checkerboard(); 70
71 fCheckerboard.allocN32Pixels(80, 80);
72 SkCanvas checkerboardCanvas(fCheckerboard);
73 sk_tools::DrawCheckerboard(&checkerboardCanvas, 0xFFA0A0A0, 0xFF404040, 8);
91 } 74 }
92 75
93 void onDraw(SkCanvas* canvas) SK_OVERRIDE { 76 void onDraw(SkCanvas* canvas) SK_OVERRIDE {
94 canvas->clear(0x00000000); 77 canvas->clear(0x00000000);
95 SkPaint paint; 78 SkPaint paint;
96 79
97 const struct { 80 const struct {
98 SkXfermode::Mode fMode; 81 SkXfermode::Mode fMode;
99 const char* fLabel; 82 const char* fLabel;
100 } gModes[] = { 83 } gModes[] = {
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 private: 201 private:
219 SkBitmap fBitmap, fCheckerboard; 202 SkBitmap fBitmap, fCheckerboard;
220 typedef GM INHERITED; 203 typedef GM INHERITED;
221 }; 204 };
222 205
223 ////////////////////////////////////////////////////////////////////////////// 206 //////////////////////////////////////////////////////////////////////////////
224 207
225 DEF_GM( return new XfermodeImageFilterGM; ); 208 DEF_GM( return new XfermodeImageFilterGM; );
226 209
227 } 210 }
OLDNEW
« no previous file with comments | « gm/tileimagefilter.cpp ('k') | gyp/SampleApp.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698