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

Side by Side Diff: gm/tileimagefilter.cpp

Issue 112803004: Make SkImageFilter crop rects relative to the primitive origin, instead of relative to their parent (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Updated to ToT Created 6 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 | Annotate | Revision Log
« no previous file with comments | « gm/offsetimagefilter.cpp ('k') | include/core/SkImageFilter.h » ('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 "SkTileImageFilter.h" 9 #include "SkTileImageFilter.h"
10 #include "SkBitmapSource.h" 10 #include "SkBitmapSource.h"
(...skipping 13 matching lines...) Expand all
24 protected: 24 protected:
25 virtual SkString onShortName() { 25 virtual SkString onShortName() {
26 return SkString("tileimagefilter"); 26 return SkString("tileimagefilter");
27 } 27 }
28 28
29 void make_bitmap() { 29 void make_bitmap() {
30 fBitmap.setConfig(SkBitmap::kARGB_8888_Config, 80, 80); 30 fBitmap.setConfig(SkBitmap::kARGB_8888_Config, 80, 80);
31 fBitmap.allocPixels(); 31 fBitmap.allocPixels();
32 SkBitmapDevice device(fBitmap); 32 SkBitmapDevice device(fBitmap);
33 SkCanvas canvas(&device); 33 SkCanvas canvas(&device);
34 canvas.clear(0x00000000); 34 canvas.clear(0xFF000000);
35 SkPaint paint; 35 SkPaint paint;
36 paint.setAntiAlias(true); 36 paint.setAntiAlias(true);
37 paint.setColor(0xD000D000); 37 paint.setColor(0xD000D000);
38 paint.setTextSize(SkIntToScalar(96)); 38 paint.setTextSize(SkIntToScalar(96));
39 const char* str = "e"; 39 const char* str = "e";
40 canvas.drawText(str, strlen(str), SkIntToScalar(15), SkIntToScalar(65), paint); 40 canvas.drawText(str, strlen(str), SkIntToScalar(15), SkIntToScalar(65), paint);
41 } 41 }
42 42
43 void make_checkerboard() { 43 void make_checkerboard() {
44 fCheckerboard.setConfig(SkBitmap::kARGB_8888_Config, 80, 80); 44 fCheckerboard.setConfig(SkBitmap::kARGB_8888_Config, 80, 80);
(...skipping 15 matching lines...) Expand all
60 canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint); 60 canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint);
61 canvas.restore(); 61 canvas.restore();
62 } 62 }
63 } 63 }
64 } 64 }
65 65
66 virtual SkISize onISize() { 66 virtual SkISize onISize() {
67 return make_isize(WIDTH, HEIGHT); 67 return make_isize(WIDTH, HEIGHT);
68 } 68 }
69 69
70 void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, const SkPai nt& paint,
71 SkScalar x, SkScalar y) {
72 canvas->save();
73 canvas->translate(x, y);
74 canvas->clipRect(SkRect::MakeXYWH(0, 0,
75 SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height())));
76 canvas->drawBitmap(bitmap, 0, 0, &paint);
77 canvas->restore();
78 }
79
80 virtual void onDraw(SkCanvas* canvas) { 70 virtual void onDraw(SkCanvas* canvas) {
81 if (!fInitialized) { 71 if (!fInitialized) {
82 make_bitmap(); 72 make_bitmap();
83 make_checkerboard(); 73 make_checkerboard();
84 fInitialized = true; 74 fInitialized = true;
85 } 75 }
86 canvas->clear(0x00000000); 76 canvas->clear(0x00000000);
87 SkPaint paint; 77 SkPaint paint;
88 78
89 int x = 0, y = 0; 79 int x = 0, y = 0;
90 for (size_t i = 0; i < 4; i++) { 80 for (size_t i = 0; i < 4; i++) {
91 SkBitmap* bitmap = (i & 0x01) ? &fCheckerboard : &fBitmap; 81 SkBitmap* bitmap = (i & 0x01) ? &fCheckerboard : &fBitmap;
92 SkRect srcRect = SkRect::MakeXYWH(SkIntToScalar(bitmap->width()/4), 82 SkRect srcRect = SkRect::MakeXYWH(SkIntToScalar(bitmap->width()/4),
93 SkIntToScalar(bitmap->height()/4), 83 SkIntToScalar(bitmap->height()/4),
94 SkIntToScalar(bitmap->width()/(i+1 )), 84 SkIntToScalar(bitmap->width()/(i+1 )),
95 SkIntToScalar(bitmap->height()/(i+ 1))); 85 SkIntToScalar(bitmap->height()/(i+ 1)));
96 SkRect dstRect = SkRect::MakeXYWH(SkIntToScalar(i * 8), 86 SkRect dstRect = SkRect::MakeXYWH(SkIntToScalar(i * 8),
97 SkIntToScalar(i * 4), 87 SkIntToScalar(i * 4),
98 SkIntToScalar(bitmap->width() - i * 4), 88 SkIntToScalar(bitmap->width() - i * 12),
99 SkIntToScalar(bitmap->height()) - i * 8); 89 SkIntToScalar(bitmap->height()) - i * 12);
100 SkAutoTUnref<SkImageFilter> tileInput(SkNEW_ARGS(SkBitmapSource, (*b itmap))); 90 SkAutoTUnref<SkImageFilter> tileInput(SkNEW_ARGS(SkBitmapSource, (*b itmap)));
101 SkAutoTUnref<SkImageFilter> filter(SkNEW_ARGS( 91 SkAutoTUnref<SkImageFilter> filter(SkNEW_ARGS(
102 SkTileImageFilter, (srcRect, dstRect, tileInput))); 92 SkTileImageFilter, (srcRect, dstRect, tileInput)));
93 canvas->save();
94 canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
103 paint.setImageFilter(filter); 95 paint.setImageFilter(filter);
104 drawClippedBitmap(canvas, *bitmap, paint, SkIntToScalar(x), SkIntToS calar(y)); 96 canvas->drawBitmap(fBitmap, 0, 0, &paint);
97 canvas->restore();
105 x += bitmap->width() + MARGIN; 98 x += bitmap->width() + MARGIN;
106 if (x + bitmap->width() > WIDTH) { 99 if (x + bitmap->width() > WIDTH) {
107 x = 0; 100 x = 0;
108 y += bitmap->height() + MARGIN; 101 y += bitmap->height() + MARGIN;
109 } 102 }
110 } 103 }
111 } 104 }
112 private: 105 private:
113 typedef GM INHERITED; 106 typedef GM INHERITED;
114 SkBitmap fBitmap, fCheckerboard; 107 SkBitmap fBitmap, fCheckerboard;
115 bool fInitialized; 108 bool fInitialized;
116 }; 109 };
117 110
118 ////////////////////////////////////////////////////////////////////////////// 111 //////////////////////////////////////////////////////////////////////////////
119 112
120 static GM* MyFactory(void*) { return new TileImageFilterGM; } 113 static GM* MyFactory(void*) { return new TileImageFilterGM; }
121 static GMRegistry reg(MyFactory); 114 static GMRegistry reg(MyFactory);
122 115
123 } 116 }
OLDNEW
« no previous file with comments | « gm/offsetimagefilter.cpp ('k') | include/core/SkImageFilter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698