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

Side by Side Diff: gm/offsetimagefilter.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 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"
8 #include "gm.h" 9 #include "gm.h"
9 #include "SkOffsetImageFilter.h" 10 #include "SkOffsetImageFilter.h"
10 #include "SkBitmapSource.h" 11 #include "SkBitmapSource.h"
11 12
12 #define WIDTH 600 13 #define WIDTH 600
13 #define HEIGHT 100 14 #define HEIGHT 100
14 #define MARGIN 12 15 #define MARGIN 12
15 16
16 namespace skiagm { 17 namespace skiagm {
17 18
(...skipping 14 matching lines...) Expand all
32 canvas.clear(0x00000000); 33 canvas.clear(0x00000000);
33 SkPaint paint; 34 SkPaint paint;
34 paint.setAntiAlias(true); 35 paint.setAntiAlias(true);
35 sk_tool_utils::set_portable_typeface(&paint); 36 sk_tool_utils::set_portable_typeface(&paint);
36 paint.setColor(0xD000D000); 37 paint.setColor(0xD000D000);
37 paint.setTextSize(SkIntToScalar(96)); 38 paint.setTextSize(SkIntToScalar(96));
38 const char* str = "e"; 39 const char* str = "e";
39 canvas.drawText(str, strlen(str), SkIntToScalar(15), SkIntToScalar(65), paint); 40 canvas.drawText(str, strlen(str), SkIntToScalar(15), SkIntToScalar(65), paint);
40 } 41 }
41 42
42 void make_checkerboard() {
43 fCheckerboard.allocN32Pixels(80, 80);
44 SkCanvas canvas(fCheckerboard);
45 canvas.clear(0x00000000);
46 SkPaint darkPaint;
47 darkPaint.setColor(0xFF404040);
48 SkPaint lightPaint;
49 lightPaint.setColor(0xFFA0A0A0);
50 for (int y = 0; y < 80; y += 16) {
51 for (int x = 0; x < 80; x += 16) {
52 canvas.save();
53 canvas.translate(SkIntToScalar(x), SkIntToScalar(y));
54 canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint);
55 canvas.drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint);
56 canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint);
57 canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint);
58 canvas.restore();
59 }
60 }
61 }
62
63 virtual SkISize onISize() { 43 virtual SkISize onISize() {
64 return SkISize::Make(WIDTH, HEIGHT); 44 return SkISize::Make(WIDTH, HEIGHT);
65 } 45 }
66 46
67 void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, const SkPai nt& paint, SkScalar scale, const SkIRect& cropRect) { 47 void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, const SkPai nt& paint, SkScalar scale, const SkIRect& cropRect) {
68 canvas->save(); 48 canvas->save();
69 SkRect clipRect = SkRect::MakeWH( 49 SkRect clipRect = SkRect::MakeWH(
70 SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height())); 50 SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height()));
71 canvas->clipRect(clipRect); 51 canvas->clipRect(clipRect);
72 canvas->scale(scale, scale); 52 canvas->scale(scale, scale);
73 canvas->drawBitmap(bitmap, 0, 0, &paint); 53 canvas->drawBitmap(bitmap, 0, 0, &paint);
74 canvas->restore(); 54 canvas->restore();
75 SkPaint strokePaint; 55 SkPaint strokePaint;
76 strokePaint.setStyle(SkPaint::kStroke_Style); 56 strokePaint.setStyle(SkPaint::kStroke_Style);
77 strokePaint.setColor(SK_ColorRED); 57 strokePaint.setColor(SK_ColorRED);
78 58
79 // Draw a boundary rect around the intersection of the clip rect 59 // Draw a boundary rect around the intersection of the clip rect
80 // and crop rect. 60 // and crop rect.
81 SkMatrix scaleMatrix; 61 SkMatrix scaleMatrix;
82 scaleMatrix.setScale(scale, scale); 62 scaleMatrix.setScale(scale, scale);
83 SkRect cropRectFloat; 63 SkRect cropRectFloat;
84 scaleMatrix.mapRect(&cropRectFloat, SkRect::Make(cropRect)); 64 scaleMatrix.mapRect(&cropRectFloat, SkRect::Make(cropRect));
85 clipRect.intersect(cropRectFloat); 65 clipRect.intersect(cropRectFloat);
86 canvas->drawRect(clipRect, strokePaint); 66 canvas->drawRect(clipRect, strokePaint);
87 } 67 }
88 68
89 virtual void onDraw(SkCanvas* canvas) { 69 virtual void onDraw(SkCanvas* canvas) {
90 if (!fInitialized) { 70 if (!fInitialized) {
91 make_bitmap(); 71 make_bitmap();
92 make_checkerboard(); 72
73 fCheckerboard.allocN32Pixels(80, 80);
74 SkCanvas checkerboardCanvas(fCheckerboard);
75 skiagm::Checkerboard(&checkerboardCanvas, 0xFFA0A0A0, 0xFF404040);
76
93 fInitialized = true; 77 fInitialized = true;
94 } 78 }
95 canvas->clear(0x00000000); 79 canvas->clear(0x00000000);
96 SkPaint paint; 80 SkPaint paint;
97 81
98 for (int i = 0; i < 4; i++) { 82 for (int i = 0; i < 4; i++) {
99 SkBitmap* bitmap = (i & 0x01) ? &fCheckerboard : &fBitmap; 83 SkBitmap* bitmap = (i & 0x01) ? &fCheckerboard : &fBitmap;
100 SkIRect cropRect = SkIRect::MakeXYWH(i * 12, 84 SkIRect cropRect = SkIRect::MakeXYWH(i * 12,
101 i * 8, 85 i * 8,
102 bitmap->width() - i * 8, 86 bitmap->width() - i * 8,
(...skipping 21 matching lines...) Expand all
124 SkBitmap fBitmap, fCheckerboard; 108 SkBitmap fBitmap, fCheckerboard;
125 bool fInitialized; 109 bool fInitialized;
126 }; 110 };
127 111
128 ////////////////////////////////////////////////////////////////////////////// 112 //////////////////////////////////////////////////////////////////////////////
129 113
130 static GM* MyFactory(void*) { return new OffsetImageFilterGM; } 114 static GM* MyFactory(void*) { return new OffsetImageFilterGM; }
131 static GMRegistry reg(MyFactory); 115 static GMRegistry reg(MyFactory);
132 116
133 } 117 }
OLDNEW
« gm/checkerboard.h ('K') | « gm/imagefiltersscaled.cpp ('k') | gm/tileimagefilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698