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

Side by Side Diff: tests/TileGridTest.cpp

Issue 238273012: Staged removal of SkPicture-derived classes (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: have SkPicture only friend SkPictureRecorder once 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
« no previous file with comments | « tests/SerializationTest.cpp ('k') | tools/PictureRenderer.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 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 16 matching lines...) Expand all
27 virtual void drawRect(const SkRect& rect, const SkPaint&) { 27 virtual void drawRect(const SkRect& rect, const SkPaint&) {
28 // This capture occurs before quick reject. 28 // This capture occurs before quick reject.
29 fRects.push(rect); 29 fRects.push(rect);
30 } 30 }
31 31
32 SkTDArray<SkRect> fRects; 32 SkTDArray<SkRect> fRects;
33 }; 33 };
34 34
35 static void verifyTileHits(skiatest::Reporter* reporter, SkIRect rect, 35 static void verifyTileHits(skiatest::Reporter* reporter, SkIRect rect,
36 uint32_t tileMask, int borderPixels = 0) { 36 uint32_t tileMask, int borderPixels = 0) {
37 SkTileGridPicture::TileGridInfo info; 37 SkTileGridFactory::TileGridInfo info;
38 info.fMargin.set(borderPixels, borderPixels); 38 info.fMargin.set(borderPixels, borderPixels);
39 info.fOffset.setZero(); 39 info.fOffset.setZero();
40 info.fTileInterval.set(10 - 2 * borderPixels, 10 - 2 * borderPixels); 40 info.fTileInterval.set(10 - 2 * borderPixels, 10 - 2 * borderPixels);
41 SkTileGrid grid(2, 2, info, NULL); 41 SkTileGrid grid(2, 2, info, NULL);
42 grid.insert(NULL, rect, false); 42 grid.insert(NULL, rect, false);
43 REPORTER_ASSERT(reporter, grid.tileCount(0, 0) == 43 REPORTER_ASSERT(reporter, grid.tileCount(0, 0) ==
44 ((tileMask & kTopLeft_Tile)? 1 : 0)); 44 ((tileMask & kTopLeft_Tile)? 1 : 0));
45 REPORTER_ASSERT(reporter, grid.tileCount(1, 0) == 45 REPORTER_ASSERT(reporter, grid.tileCount(1, 0) ==
46 ((tileMask & kTopRight_Tile)? 1 : 0)); 46 ((tileMask & kTopRight_Tile)? 1 : 0));
47 REPORTER_ASSERT(reporter, grid.tileCount(0, 1) == 47 REPORTER_ASSERT(reporter, grid.tileCount(0, 1) ==
48 ((tileMask & kBottomLeft_Tile)? 1 : 0)); 48 ((tileMask & kBottomLeft_Tile)? 1 : 0));
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 SkTileGridFactory::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 SkRect rect1 = SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0), 59 SkRect rect1 = SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0),
60 SkIntToScalar(8), SkIntToScalar(8)); 60 SkIntToScalar(8), SkIntToScalar(8));
61 SkRect rect2 = SkRect::MakeXYWH(SkIntToScalar(11), SkIntToScalar(11), 61 SkRect rect2 = SkRect::MakeXYWH(SkIntToScalar(11), SkIntToScalar(11),
62 SkIntToScalar(1), SkIntToScalar(1)); 62 SkIntToScalar(1), SkIntToScalar(1));
63 SkAutoTUnref<SkPictureFactory> factory(SkNEW_ARGS(SkTileGridPictureFactory, (info))); 63 SkTileGridFactory factory(info);
64 SkPictureRecorder recorder(factory); 64 SkPictureRecorder recorder;
65 SkCanvas* canvas = recorder.beginRecording(20, 20); 65 SkCanvas* canvas = recorder.beginRecording(20, 20, &factory, 0);
66 SkPaint paint; 66 SkPaint paint;
67 canvas->drawRect(rect1, paint); 67 canvas->drawRect(rect1, paint);
68 canvas->drawRect(rect2, paint); 68 canvas->drawRect(rect2, paint);
69 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); 69 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
70 70
71 SkBitmap store; 71 SkBitmap store;
72 store.allocN32Pixels(1, 1); 72 store.allocN32Pixels(1, 1);
73 73
74 // Test parts of top-left tile 74 // Test parts of top-left tile
75 { 75 {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 MockCanvas mockCanvas(store); 128 MockCanvas mockCanvas(store);
129 mockCanvas.translate(-16.0f, -22.0f); 129 mockCanvas.translate(-16.0f, -22.0f);
130 picture->draw(&mockCanvas); 130 picture->draw(&mockCanvas);
131 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); 131 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count());
132 REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[0]); 132 REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[0]);
133 } 133 }
134 } 134 }
135 135
136 DEF_TEST(TileGrid_OverlapOffsetQueryAlignment, reporter) { 136 DEF_TEST(TileGrid_OverlapOffsetQueryAlignment, reporter) {
137 // Use SkTileGridPicture to generate a SkTileGrid with a helper 137 // Use SkTileGridPicture to generate a SkTileGrid with a helper
138 SkTileGridPicture::TileGridInfo info; 138 SkTileGridFactory::TileGridInfo info;
139 info.fMargin.set(1, 1); 139 info.fMargin.set(1, 1);
140 info.fOffset.set(-1, -1); 140 info.fOffset.set(-1, -1);
141 info.fTileInterval.set(8, 8); 141 info.fTileInterval.set(8, 8);
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 SkAutoTUnref<SkPictureFactory> factory(SkNEW_ARGS(SkTileGridPictureFactory, (info))); 152 SkTileGridFactory factory(info);
153 SkPictureRecorder recorder(factory); 153 SkPictureRecorder recorder;
154 SkCanvas* canvas = recorder.beginRecording(20, 20); 154 SkCanvas* canvas = recorder.beginRecording(20, 20, &factory, 0);
155 SkPaint paint; 155 SkPaint paint;
156 canvas->drawRect(rect1, paint); 156 canvas->drawRect(rect1, paint);
157 canvas->drawRect(rect2, paint); 157 canvas->drawRect(rect2, paint);
158 canvas->drawRect(rect3, paint); 158 canvas->drawRect(rect3, paint);
159 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); 159 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
160 160
161 SkBitmap tileBitmap; 161 SkBitmap tileBitmap;
162 tileBitmap.allocN32Pixels(10, 10); 162 tileBitmap.allocN32Pixels(10, 10);
163 SkBitmap moreThanATileBitmap; 163 SkBitmap moreThanATileBitmap;
164 moreThanATileBitmap.allocN32Pixels(11, 11); 164 moreThanATileBitmap.allocN32Pixels(11, 11);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 verifyTileHits(reporter, SkIRect::MakeXYWH(10, 10, 1, 1), kBottomRight_Tile , 1); 243 verifyTileHits(reporter, SkIRect::MakeXYWH(10, 10, 1, 1), kBottomRight_Tile , 1);
244 verifyTileHits(reporter, SkIRect::MakeXYWH(17, 17, 1, 1), kBottomRight_Tile , 1); 244 verifyTileHits(reporter, SkIRect::MakeXYWH(17, 17, 1, 1), kBottomRight_Tile , 1);
245 245
246 // BBoxes that overlap tiles 246 // BBoxes that overlap tiles
247 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);
248 verifyTileHits(reporter, SkIRect::MakeXYWH(5, 5, 1, 10), kTopLeft_Tile | 248 verifyTileHits(reporter, SkIRect::MakeXYWH(5, 5, 1, 10), kTopLeft_Tile |
249 kBottomLeft_Tile); 249 kBottomLeft_Tile);
250 verifyTileHits(reporter, SkIRect::MakeXYWH(5, 5, 10, 10), kAll_Tile); 250 verifyTileHits(reporter, SkIRect::MakeXYWH(5, 5, 10, 10), kAll_Tile);
251 verifyTileHits(reporter, SkIRect::MakeXYWH(-10, -10, 40, 40), kAll_Tile); 251 verifyTileHits(reporter, SkIRect::MakeXYWH(-10, -10, 40, 40), kAll_Tile);
252 } 252 }
OLDNEW
« no previous file with comments | « tests/SerializationTest.cpp ('k') | tools/PictureRenderer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698