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: tests/TileGridTest.cpp

Issue 214953003: split SkPictureRecorder out of SkPicture (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: update to ToT (again) Created 6 years, 8 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
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 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 "SkBitmapDevice.h" 8 #include "SkBitmapDevice.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkTileGrid.h" 10 #include "SkTileGrid.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 REPORTER_ASSERT(reporter, grid.tileCount(1, 1) == 49 REPORTER_ASSERT(reporter, grid.tileCount(1, 1) ==
50 ((tileMask & kBottomRight_Tile)? 1 : 0)); 50 ((tileMask & kBottomRight_Tile)? 1 : 0));
51 } 51 }
52 52
53 DEF_TEST(TileGrid_UnalignedQuery, reporter) { 53 DEF_TEST(TileGrid_UnalignedQuery, reporter) {
54 // Use SkTileGridPicture to generate a SkTileGrid with a helper 54 // Use SkTileGridPicture to generate a SkTileGrid with a helper
55 SkTileGridPicture::TileGridInfo info; 55 SkTileGridPicture::TileGridInfo info;
56 info.fMargin.setEmpty(); 56 info.fMargin.setEmpty();
57 info.fOffset.setZero(); 57 info.fOffset.setZero();
58 info.fTileInterval.set(10, 10); 58 info.fTileInterval.set(10, 10);
59 SkTileGridPicture picture(20, 20, info);
60 SkRect rect1 = SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0), 59 SkRect rect1 = SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0),
61 SkIntToScalar(8), SkIntToScalar(8)); 60 SkIntToScalar(8), SkIntToScalar(8));
62 SkRect rect2 = SkRect::MakeXYWH(SkIntToScalar(11), SkIntToScalar(11), 61 SkRect rect2 = SkRect::MakeXYWH(SkIntToScalar(11), SkIntToScalar(11),
63 SkIntToScalar(1), SkIntToScalar(1)); 62 SkIntToScalar(1), SkIntToScalar(1));
64 SkCanvas* canvas = picture.beginRecording(20, 20, SkPicture::kOptimizeForCli ppedPlayback_RecordingFlag); 63 SkAutoTUnref<SkPictureFactory> factory(SkNEW_ARGS(SkTileGridPictureFactory, (info)));
64 SkPictureRecorder recorder(factory);
65 SkCanvas* canvas = recorder.beginRecording(20, 20, SkPicture::kOptimizeForCl ippedPlayback_RecordingFlag);
65 SkPaint paint; 66 SkPaint paint;
66 canvas->drawRect(rect1, paint); 67 canvas->drawRect(rect1, paint);
67 canvas->drawRect(rect2, paint); 68 canvas->drawRect(rect2, paint);
68 picture.endRecording(); 69 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
69 70
70 SkBitmap store; 71 SkBitmap store;
71 store.allocN32Pixels(1, 1); 72 store.allocN32Pixels(1, 1);
72 73
73 // Test parts of top-left tile 74 // Test parts of top-left tile
74 { 75 {
75 MockCanvas mockCanvas(store); 76 MockCanvas mockCanvas(store);
76 picture.draw(&mockCanvas); 77 picture->draw(&mockCanvas);
77 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); 78 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count());
78 REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]); 79 REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]);
79 } 80 }
80 { 81 {
81 MockCanvas mockCanvas(store); 82 MockCanvas mockCanvas(store);
82 mockCanvas.translate(-7.99f, -7.99f); 83 mockCanvas.translate(-7.99f, -7.99f);
83 picture.draw(&mockCanvas); 84 picture->draw(&mockCanvas);
84 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); 85 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count());
85 REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]); 86 REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]);
86 } 87 }
87 // Corner overlap 88 // Corner overlap
88 { 89 {
89 MockCanvas mockCanvas(store); 90 MockCanvas mockCanvas(store);
90 mockCanvas.translate(-9.5f, -9.5f); 91 mockCanvas.translate(-9.5f, -9.5f);
91 picture.draw(&mockCanvas); 92 picture->draw(&mockCanvas);
92 REPORTER_ASSERT(reporter, 2 == mockCanvas.fRects.count()); 93 REPORTER_ASSERT(reporter, 2 == mockCanvas.fRects.count());
93 REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]); 94 REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]);
94 REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[1]); 95 REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[1]);
95 } 96 }
96 // Intersect bottom right tile, but does not overlap rect 2 97 // Intersect bottom right tile, but does not overlap rect 2
97 { 98 {
98 MockCanvas mockCanvas(store); 99 MockCanvas mockCanvas(store);
99 mockCanvas.translate(-16.0f, -16.0f); 100 mockCanvas.translate(-16.0f, -16.0f);
100 picture.draw(&mockCanvas); 101 picture->draw(&mockCanvas);
101 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); 102 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count());
102 REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[0]); 103 REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[0]);
103 } 104 }
104 // Out of bounds queries, snap to border tiles 105 // Out of bounds queries, snap to border tiles
105 { 106 {
106 MockCanvas mockCanvas(store); 107 MockCanvas mockCanvas(store);
107 mockCanvas.translate(2.0f, 0.0f); 108 mockCanvas.translate(2.0f, 0.0f);
108 picture.draw(&mockCanvas); 109 picture->draw(&mockCanvas);
109 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); 110 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count());
110 REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]); 111 REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]);
111 } 112 }
112 { 113 {
113 MockCanvas mockCanvas(store); 114 MockCanvas mockCanvas(store);
114 mockCanvas.translate(0.0f, 2.0f); 115 mockCanvas.translate(0.0f, 2.0f);
115 picture.draw(&mockCanvas); 116 picture->draw(&mockCanvas);
116 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); 117 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count());
117 REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]); 118 REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]);
118 } 119 }
119 { 120 {
120 MockCanvas mockCanvas(store); 121 MockCanvas mockCanvas(store);
121 mockCanvas.translate(-22.0f, -16.0f); 122 mockCanvas.translate(-22.0f, -16.0f);
122 picture.draw(&mockCanvas); 123 picture->draw(&mockCanvas);
123 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); 124 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count());
124 REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[0]); 125 REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[0]);
125 } 126 }
126 { 127 {
127 MockCanvas mockCanvas(store); 128 MockCanvas mockCanvas(store);
128 mockCanvas.translate(-16.0f, -22.0f); 129 mockCanvas.translate(-16.0f, -22.0f);
129 picture.draw(&mockCanvas); 130 picture->draw(&mockCanvas);
130 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); 131 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count());
131 REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[0]); 132 REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[0]);
132 } 133 }
133 } 134 }
134 135
135 DEF_TEST(TileGrid_OverlapOffsetQueryAlignment, reporter) { 136 DEF_TEST(TileGrid_OverlapOffsetQueryAlignment, reporter) {
136 // Use SkTileGridPicture to generate a SkTileGrid with a helper 137 // Use SkTileGridPicture to generate a SkTileGrid with a helper
137 SkTileGridPicture::TileGridInfo info; 138 SkTileGridPicture::TileGridInfo info;
138 info.fMargin.set(1, 1); 139 info.fMargin.set(1, 1);
139 info.fOffset.set(-1, -1); 140 info.fOffset.set(-1, -1);
140 info.fTileInterval.set(8, 8); 141 info.fTileInterval.set(8, 8);
141 SkTileGridPicture picture(20, 20, info);
142 142
143 // rect landing entirely in top left tile 143 // rect landing entirely in top left tile
144 SkRect rect1 = SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0), 144 SkRect rect1 = SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0),
145 SkIntToScalar(1), SkIntToScalar(1)); 145 SkIntToScalar(1), SkIntToScalar(1));
146 // rect landing entirely in center tile 146 // rect landing entirely in center tile
147 SkRect rect2 = SkRect::MakeXYWH(SkIntToScalar(12), SkIntToScalar(12), 147 SkRect rect2 = SkRect::MakeXYWH(SkIntToScalar(12), SkIntToScalar(12),
148 SkIntToScalar(1), SkIntToScalar(1)); 148 SkIntToScalar(1), SkIntToScalar(1));
149 // rect landing entirely in bottomright tile 149 // rect landing entirely in bottomright tile
150 SkRect rect3 = SkRect::MakeXYWH(SkIntToScalar(19), SkIntToScalar(19), 150 SkRect rect3 = SkRect::MakeXYWH(SkIntToScalar(19), SkIntToScalar(19),
151 SkIntToScalar(1), SkIntToScalar(1)); 151 SkIntToScalar(1), SkIntToScalar(1));
152 SkCanvas* canvas = picture.beginRecording(20, 20, SkPicture::kOptimizeForCli ppedPlayback_RecordingFlag); 152 SkAutoTUnref<SkPictureFactory> factory(SkNEW_ARGS(SkTileGridPictureFactory, (info)));
153 SkPictureRecorder recorder(factory);
154 SkCanvas* canvas = recorder.beginRecording(20, 20, SkPicture::kOptimizeForCl ippedPlayback_RecordingFlag);
153 SkPaint paint; 155 SkPaint paint;
154 canvas->drawRect(rect1, paint); 156 canvas->drawRect(rect1, paint);
155 canvas->drawRect(rect2, paint); 157 canvas->drawRect(rect2, paint);
156 canvas->drawRect(rect3, paint); 158 canvas->drawRect(rect3, paint);
157 picture.endRecording(); 159 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
158 160
159 SkBitmap tileBitmap; 161 SkBitmap tileBitmap;
160 tileBitmap.allocN32Pixels(10, 10); 162 tileBitmap.allocN32Pixels(10, 10);
161 SkBitmap moreThanATileBitmap; 163 SkBitmap moreThanATileBitmap;
162 moreThanATileBitmap.allocN32Pixels(11, 11); 164 moreThanATileBitmap.allocN32Pixels(11, 11);
163 SkBitmap tinyBitmap; 165 SkBitmap tinyBitmap;
164 tinyBitmap.allocN32Pixels(2, 2); 166 tinyBitmap.allocN32Pixels(2, 2);
165 // Test parts of top-left tile 167 // Test parts of top-left tile
166 { 168 {
167 // The offset should cancel the top and left borders of the top left til e 169 // The offset should cancel the top and left borders of the top left til e
168 // So a look-up at interval 0-10 should be grid aligned, 170 // So a look-up at interval 0-10 should be grid aligned,
169 MockCanvas mockCanvas(tileBitmap); 171 MockCanvas mockCanvas(tileBitmap);
170 picture.draw(&mockCanvas); 172 picture->draw(&mockCanvas);
171 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); 173 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count());
172 REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]); 174 REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]);
173 } 175 }
174 { 176 {
175 // Encroaching border by one pixel 177 // Encroaching border by one pixel
176 MockCanvas mockCanvas(moreThanATileBitmap); 178 MockCanvas mockCanvas(moreThanATileBitmap);
177 picture.draw(&mockCanvas); 179 picture->draw(&mockCanvas);
178 REPORTER_ASSERT(reporter, 2 == mockCanvas.fRects.count()); 180 REPORTER_ASSERT(reporter, 2 == mockCanvas.fRects.count());
179 REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]); 181 REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]);
180 REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[1]); 182 REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[1]);
181 } 183 }
182 { 184 {
183 // Tile stride is 8 (tileWidth - 2 * border pixels 185 // Tile stride is 8 (tileWidth - 2 * border pixels
184 // so translating by 8, should make query grid-aligned 186 // so translating by 8, should make query grid-aligned
185 // with middle tile. 187 // with middle tile.
186 MockCanvas mockCanvas(tileBitmap); 188 MockCanvas mockCanvas(tileBitmap);
187 mockCanvas.translate(SkIntToScalar(-8), SkIntToScalar(-8)); 189 mockCanvas.translate(SkIntToScalar(-8), SkIntToScalar(-8));
188 picture.draw(&mockCanvas); 190 picture->draw(&mockCanvas);
189 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); 191 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count());
190 REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[0]); 192 REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[0]);
191 } 193 }
192 { 194 {
193 MockCanvas mockCanvas(tileBitmap); 195 MockCanvas mockCanvas(tileBitmap);
194 mockCanvas.translate(-7.9f, -7.9f); 196 mockCanvas.translate(-7.9f, -7.9f);
195 picture.draw(&mockCanvas); 197 picture->draw(&mockCanvas);
196 REPORTER_ASSERT(reporter, 2 == mockCanvas.fRects.count()); 198 REPORTER_ASSERT(reporter, 2 == mockCanvas.fRects.count());
197 REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]); 199 REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]);
198 REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[1]); 200 REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[1]);
199 } 201 }
200 { 202 {
201 MockCanvas mockCanvas(tileBitmap); 203 MockCanvas mockCanvas(tileBitmap);
202 mockCanvas.translate(-8.1f, -8.1f); 204 mockCanvas.translate(-8.1f, -8.1f);
203 picture.draw(&mockCanvas); 205 picture->draw(&mockCanvas);
204 REPORTER_ASSERT(reporter, 2 == mockCanvas.fRects.count()); 206 REPORTER_ASSERT(reporter, 2 == mockCanvas.fRects.count());
205 REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[0]); 207 REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[0]);
206 REPORTER_ASSERT(reporter, rect3 == mockCanvas.fRects[1]); 208 REPORTER_ASSERT(reporter, rect3 == mockCanvas.fRects[1]);
207 } 209 }
208 { 210 {
209 // Regression test for crbug.com/234688 211 // Regression test for crbug.com/234688
210 // Once the 2x2 device region is inset by margin, it yields an empty 212 // Once the 2x2 device region is inset by margin, it yields an empty
211 // adjusted region, sitting right on top of the tile boundary. 213 // adjusted region, sitting right on top of the tile boundary.
212 MockCanvas mockCanvas(tinyBitmap); 214 MockCanvas mockCanvas(tinyBitmap);
213 mockCanvas.translate(-8.0f, -8.0f); 215 mockCanvas.translate(-8.0f, -8.0f);
214 picture.draw(&mockCanvas); 216 picture->draw(&mockCanvas);
215 // This test passes by not asserting. We do not validate the rects recor ded 217 // This test passes by not asserting. We do not validate the rects recor ded
216 // because the result is numerically unstable (floating point equality). 218 // because the result is numerically unstable (floating point equality).
217 // The content of any one of the four tiles of the tilegrid would be a v alid 219 // The content of any one of the four tiles of the tilegrid would be a v alid
218 // result since any bbox that covers the center point of the canvas will be 220 // result since any bbox that covers the center point of the canvas will be
219 // recorded in all four tiles. 221 // recorded in all four tiles.
220 } 222 }
221 } 223 }
222 224
223 DEF_TEST(TileGrid, reporter) { 225 DEF_TEST(TileGrid, reporter) {
224 // Out of bounds 226 // Out of bounds
(...skipping 16 matching lines...) Expand all
241 verifyTileHits(reporter, SkIRect::MakeXYWH(10, 10, 1, 1), kBottomRight_Tile , 1); 243 verifyTileHits(reporter, SkIRect::MakeXYWH(10, 10, 1, 1), kBottomRight_Tile , 1);
242 verifyTileHits(reporter, SkIRect::MakeXYWH(17, 17, 1, 1), kBottomRight_Tile , 1); 244 verifyTileHits(reporter, SkIRect::MakeXYWH(17, 17, 1, 1), kBottomRight_Tile , 1);
243 245
244 // BBoxes that overlap tiles 246 // BBoxes that overlap tiles
245 verifyTileHits(reporter, SkIRect::MakeXYWH(5, 5, 10, 1), kTopLeft_Tile | kT opRight_Tile); 247 verifyTileHits(reporter, SkIRect::MakeXYWH(5, 5, 10, 1), kTopLeft_Tile | kT opRight_Tile);
246 verifyTileHits(reporter, SkIRect::MakeXYWH(5, 5, 1, 10), kTopLeft_Tile | 248 verifyTileHits(reporter, SkIRect::MakeXYWH(5, 5, 1, 10), kTopLeft_Tile |
247 kBottomLeft_Tile); 249 kBottomLeft_Tile);
248 verifyTileHits(reporter, SkIRect::MakeXYWH(5, 5, 10, 10), kAll_Tile); 250 verifyTileHits(reporter, SkIRect::MakeXYWH(5, 5, 10, 10), kAll_Tile);
249 verifyTileHits(reporter, SkIRect::MakeXYWH(-10, -10, 40, 40), kAll_Tile); 251 verifyTileHits(reporter, SkIRect::MakeXYWH(-10, -10, 40, 40), kAll_Tile);
250 } 252 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698