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

Side by Side Diff: gm/tileimagefilter.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/offsetimagefilter.cpp ('k') | gm/xfermodeimagefilter.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 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 "Checkerboard.h"
9 #include "SkBitmapSource.h"
10 #include "SkColorFilterImageFilter.h"
11 #include "SkColorMatrixFilter.h"
12 #include "SkTileImageFilter.h"
8 #include "gm.h" 13 #include "gm.h"
9 #include "SkColorMatrixFilter.h"
10 #include "SkColorFilterImageFilter.h"
11 #include "SkTileImageFilter.h"
12 #include "SkBitmapSource.h"
13 14
14 #define WIDTH 400 15 #define WIDTH 400
15 #define HEIGHT 100 16 #define HEIGHT 100
16 #define MARGIN 12 17 #define MARGIN 12
17 18
18 namespace skiagm { 19 namespace skiagm {
19 20
20 class TileImageFilterGM : public GM { 21 class TileImageFilterGM : public GM {
21 public: 22 public:
22 TileImageFilterGM() : fInitialized(false) { 23 TileImageFilterGM() : fInitialized(false) {
(...skipping 11 matching lines...) Expand all
34 canvas.clear(0xFF000000); 35 canvas.clear(0xFF000000);
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(50)); 40 paint.setTextSize(SkIntToScalar(50));
40 const char* str = "e"; 41 const char* str = "e";
41 canvas.drawText(str, strlen(str), SkIntToScalar(10), SkIntToScalar(45), paint); 42 canvas.drawText(str, strlen(str), SkIntToScalar(10), SkIntToScalar(45), 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 virtual SkISize onISize() { 45 virtual SkISize onISize() {
66 return SkISize::Make(WIDTH, HEIGHT); 46 return SkISize::Make(WIDTH, HEIGHT);
67 } 47 }
68 48
69 virtual void onDraw(SkCanvas* canvas) { 49 virtual void onDraw(SkCanvas* canvas) {
70 if (!fInitialized) { 50 if (!fInitialized) {
71 make_bitmap(); 51 make_bitmap();
72 make_checkerboard(); 52
53 fCheckerboard.allocN32Pixels(80, 80);
54 SkCanvas checkerboardCanvas(fCheckerboard);
55 sk_tools::DrawCheckerboard(&checkerboardCanvas, 0xFFA0A0A0, 0xFF4040 40, 8);
56
73 fInitialized = true; 57 fInitialized = true;
74 } 58 }
75 canvas->clear(0x00000000); 59 canvas->clear(0x00000000);
76 60
77 int x = 0, y = 0; 61 int x = 0, y = 0;
78 for (size_t i = 0; i < 4; i++) { 62 for (size_t i = 0; i < 4; i++) {
79 SkBitmap* bitmap = (i & 0x01) ? &fCheckerboard : &fBitmap; 63 SkBitmap* bitmap = (i & 0x01) ? &fCheckerboard : &fBitmap;
80 SkRect srcRect = SkRect::MakeXYWH(SkIntToScalar(bitmap->width()/4), 64 SkRect srcRect = SkRect::MakeXYWH(SkIntToScalar(bitmap->width()/4),
81 SkIntToScalar(bitmap->height()/4), 65 SkIntToScalar(bitmap->height()/4),
82 SkIntToScalar(bitmap->width()/(i+1 )), 66 SkIntToScalar(bitmap->width()/(i+1 )),
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 SkBitmap fBitmap, fCheckerboard; 113 SkBitmap fBitmap, fCheckerboard;
130 bool fInitialized; 114 bool fInitialized;
131 }; 115 };
132 116
133 ////////////////////////////////////////////////////////////////////////////// 117 //////////////////////////////////////////////////////////////////////////////
134 118
135 static GM* MyFactory(void*) { return new TileImageFilterGM; } 119 static GM* MyFactory(void*) { return new TileImageFilterGM; }
136 static GMRegistry reg(MyFactory); 120 static GMRegistry reg(MyFactory);
137 121
138 } 122 }
OLDNEW
« no previous file with comments | « gm/offsetimagefilter.cpp ('k') | gm/xfermodeimagefilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698