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

Side by Side Diff: tests/RecordDrawTest.cpp

Issue 727363003: wip for drawables (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: make the pictures in the array also const (the array already was const) Created 6 years, 1 month 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 | « src/gpu/GrRecordReplaceDraw.cpp ('k') | tools/DumpRecord.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 2014 Google Inc. 2 * Copyright 2014 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 "Test.h" 8 #include "Test.h"
9 #include "RecordTestUtils.h" 9 #include "RecordTestUtils.h"
10 10
(...skipping 23 matching lines...) Expand all
34 // Record two commands. 34 // Record two commands.
35 SkRecord record; 35 SkRecord record;
36 SkRecorder recorder(&record, W, H); 36 SkRecorder recorder(&record, W, H);
37 recorder.drawRect(SkRect::MakeWH(200, 300), SkPaint()); 37 recorder.drawRect(SkRect::MakeWH(200, 300), SkPaint());
38 recorder.clipRect(SkRect::MakeWH(100, 200)); 38 recorder.clipRect(SkRect::MakeWH(100, 200));
39 39
40 SkRecord rerecord; 40 SkRecord rerecord;
41 SkRecorder canvas(&rerecord, W, H); 41 SkRecorder canvas(&rerecord, W, H);
42 42
43 JustOneDraw callback; 43 JustOneDraw callback;
44 SkRecordDraw(record, &canvas, NULL/*bbh*/, &callback); 44 SkRecordDraw(record, &canvas, NULL, 0, NULL/*bbh*/, &callback);
45 45
46 REPORTER_ASSERT(r, 3 == rerecord.count()); 46 REPORTER_ASSERT(r, 3 == rerecord.count());
47 assert_type<SkRecords::Save> (r, rerecord, 0); 47 assert_type<SkRecords::Save> (r, rerecord, 0);
48 assert_type<SkRecords::DrawRect>(r, rerecord, 1); 48 assert_type<SkRecords::DrawRect>(r, rerecord, 1);
49 assert_type<SkRecords::Restore> (r, rerecord, 2); 49 assert_type<SkRecords::Restore> (r, rerecord, 2);
50 } 50 }
51 51
52 DEF_TEST(RecordDraw_Unbalanced, r) { 52 DEF_TEST(RecordDraw_Unbalanced, r) {
53 SkRecord record; 53 SkRecord record;
54 SkRecorder recorder(&record, W, H); 54 SkRecorder recorder(&record, W, H);
55 recorder.save(); // We won't balance this, but SkRecordDraw will for us. 55 recorder.save(); // We won't balance this, but SkRecordDraw will for us.
56 56
57 SkRecord rerecord; 57 SkRecord rerecord;
58 SkRecorder canvas(&rerecord, W, H); 58 SkRecorder canvas(&rerecord, W, H);
59 SkRecordDraw(record, &canvas, NULL/*bbh*/, NULL/*callback*/); 59 SkRecordDraw(record, &canvas, NULL, 0, NULL/*bbh*/, NULL/*callback*/);
60 60
61 REPORTER_ASSERT(r, 4 == rerecord.count()); 61 REPORTER_ASSERT(r, 4 == rerecord.count());
62 assert_type<SkRecords::Save> (r, rerecord, 0); 62 assert_type<SkRecords::Save> (r, rerecord, 0);
63 assert_type<SkRecords::Save> (r, rerecord, 1); 63 assert_type<SkRecords::Save> (r, rerecord, 1);
64 assert_type<SkRecords::Restore> (r, rerecord, 2); 64 assert_type<SkRecords::Restore> (r, rerecord, 2);
65 assert_type<SkRecords::Restore> (r, rerecord, 3); 65 assert_type<SkRecords::Restore> (r, rerecord, 3);
66 } 66 }
67 67
68 DEF_TEST(RecordDraw_SetMatrixClobber, r) { 68 DEF_TEST(RecordDraw_SetMatrixClobber, r) {
69 // Set up an SkRecord that just scales by 2x,3x. 69 // Set up an SkRecord that just scales by 2x,3x.
70 SkRecord scaleRecord; 70 SkRecord scaleRecord;
71 SkRecorder scaleCanvas(&scaleRecord, W, H); 71 SkRecorder scaleCanvas(&scaleRecord, W, H);
72 SkMatrix scale; 72 SkMatrix scale;
73 scale.setScale(2, 3); 73 scale.setScale(2, 3);
74 scaleCanvas.setMatrix(scale); 74 scaleCanvas.setMatrix(scale);
75 75
76 // Set up an SkRecord with an initial +20, +20 translate. 76 // Set up an SkRecord with an initial +20, +20 translate.
77 SkRecord translateRecord; 77 SkRecord translateRecord;
78 SkRecorder translateCanvas(&translateRecord, W, H); 78 SkRecorder translateCanvas(&translateRecord, W, H);
79 SkMatrix translate; 79 SkMatrix translate;
80 translate.setTranslate(20, 20); 80 translate.setTranslate(20, 20);
81 translateCanvas.setMatrix(translate); 81 translateCanvas.setMatrix(translate);
82 82
83 SkRecordDraw(scaleRecord, &translateCanvas, NULL/*bbh*/, NULL/*callback*/); 83 SkRecordDraw(scaleRecord, &translateCanvas, NULL, 0, NULL/*bbh*/, NULL/*call back*/);
84 REPORTER_ASSERT(r, 4 == translateRecord.count()); 84 REPORTER_ASSERT(r, 4 == translateRecord.count());
85 assert_type<SkRecords::SetMatrix>(r, translateRecord, 0); 85 assert_type<SkRecords::SetMatrix>(r, translateRecord, 0);
86 assert_type<SkRecords::Save> (r, translateRecord, 1); 86 assert_type<SkRecords::Save> (r, translateRecord, 1);
87 assert_type<SkRecords::SetMatrix>(r, translateRecord, 2); 87 assert_type<SkRecords::SetMatrix>(r, translateRecord, 2);
88 assert_type<SkRecords::Restore> (r, translateRecord, 3); 88 assert_type<SkRecords::Restore> (r, translateRecord, 3);
89 89
90 // When we look at translateRecord now, it should have its first +20,+20 tra nslate, 90 // When we look at translateRecord now, it should have its first +20,+20 tra nslate,
91 // then a 2x,3x scale that's been concatted with that +20,+20 translate. 91 // then a 2x,3x scale that's been concatted with that +20,+20 translate.
92 const SkRecords::SetMatrix* setMatrix; 92 const SkRecords::SetMatrix* setMatrix;
93 setMatrix = assert_type<SkRecords::SetMatrix>(r, translateRecord, 0); 93 setMatrix = assert_type<SkRecords::SetMatrix>(r, translateRecord, 0);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 SkPaint p; 183 SkPaint p;
184 184
185 SkRecord record; 185 SkRecord record;
186 SkRecorder recorder(&record, kWidth, kHeight); 186 SkRecorder recorder(&record, kWidth, kHeight);
187 recorder.drawRect(r1, p); 187 recorder.drawRect(r1, p);
188 recorder.drawRect(r2, p); 188 recorder.drawRect(r2, p);
189 recorder.drawRect(r3, p); 189 recorder.drawRect(r3, p);
190 190
191 SkRecord rerecord; 191 SkRecord rerecord;
192 SkRecorder canvas(&rerecord, kWidth, kHeight); 192 SkRecorder canvas(&rerecord, kWidth, kHeight);
193 SkRecordPartialDraw(record, &canvas, r1, 1, 2, SkMatrix::I()); // replay jus t drawRect of r2 193 SkRecordPartialDraw(record, &canvas, NULL, 0, r1, 1, 2, SkMatrix::I()); // r eplay just drawRect of r2
194 194
195 REPORTER_ASSERT(r, 3 == rerecord.count()); 195 REPORTER_ASSERT(r, 3 == rerecord.count());
196 assert_type<SkRecords::Save> (r, rerecord, 0); 196 assert_type<SkRecords::Save> (r, rerecord, 0);
197 assert_type<SkRecords::DrawRect> (r, rerecord, 1); 197 assert_type<SkRecords::DrawRect> (r, rerecord, 1);
198 assert_type<SkRecords::Restore> (r, rerecord, 2); 198 assert_type<SkRecords::Restore> (r, rerecord, 2);
199 199
200 const SkRecords::DrawRect* drawRect = assert_type<SkRecords::DrawRect>(r, re record, 1); 200 const SkRecords::DrawRect* drawRect = assert_type<SkRecords::DrawRect>(r, re record, 1);
201 REPORTER_ASSERT(r, drawRect->rect == r2); 201 REPORTER_ASSERT(r, drawRect->rect == r2);
202 } 202 }
203 203
204 // Check that clears are converted to drawRects 204 // Check that clears are converted to drawRects
205 DEF_TEST(RecordDraw_PartialClear, r) { 205 DEF_TEST(RecordDraw_PartialClear, r) {
206 static const int kWidth = 10, kHeight = 10; 206 static const int kWidth = 10, kHeight = 10;
207 207
208 SkRect rect = { 0, 0, kWidth, kHeight }; 208 SkRect rect = { 0, 0, kWidth, kHeight };
209 209
210 SkRecord record; 210 SkRecord record;
211 SkRecorder recorder(&record, kWidth, kHeight); 211 SkRecorder recorder(&record, kWidth, kHeight);
212 recorder.clear(SK_ColorRED); 212 recorder.clear(SK_ColorRED);
213 213
214 SkRecord rerecord; 214 SkRecord rerecord;
215 SkRecorder canvas(&rerecord, kWidth, kHeight); 215 SkRecorder canvas(&rerecord, kWidth, kHeight);
216 SkRecordPartialDraw(record, &canvas, rect, 0, 1, SkMatrix::I()); // replay j ust the clear 216 SkRecordPartialDraw(record, &canvas, NULL, 0, rect, 0, 1, SkMatrix::I()); // replay just the clear
217 217
218 REPORTER_ASSERT(r, 3 == rerecord.count()); 218 REPORTER_ASSERT(r, 3 == rerecord.count());
219 assert_type<SkRecords::Save> (r, rerecord, 0); 219 assert_type<SkRecords::Save> (r, rerecord, 0);
220 assert_type<SkRecords::DrawRect>(r, rerecord, 1); 220 assert_type<SkRecords::DrawRect>(r, rerecord, 1);
221 assert_type<SkRecords::Restore> (r, rerecord, 2); 221 assert_type<SkRecords::Restore> (r, rerecord, 2);
222 222
223 const SkRecords::DrawRect* drawRect = assert_type<SkRecords::DrawRect>(r, re record, 1); 223 const SkRecords::DrawRect* drawRect = assert_type<SkRecords::DrawRect>(r, re record, 1);
224 REPORTER_ASSERT(r, drawRect->rect == rect); 224 REPORTER_ASSERT(r, drawRect->rect == rect);
225 REPORTER_ASSERT(r, drawRect->paint.getColor() == SK_ColorRED); 225 REPORTER_ASSERT(r, drawRect->paint.getColor() == SK_ColorRED);
226 } 226 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(10, 10)); 312 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(10, 10));
313 surface->getCanvas()->clear(SK_ColorGREEN); 313 surface->getCanvas()->clear(SK_ColorGREEN);
314 SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); 314 SkAutoTUnref<SkImage> image(surface->newImageSnapshot());
315 315
316 SkCanvasMock canvas(10, 10); 316 SkCanvasMock canvas(10, 10);
317 317
318 { 318 {
319 SkRecord record; 319 SkRecord record;
320 SkRecorder recorder(&record, 10, 10); 320 SkRecorder recorder(&record, 10, 10);
321 recorder.drawImage(image, 0, 0); 321 recorder.drawImage(image, 0, 0);
322 SkRecordDraw(record, &canvas, 0, 0); 322 SkRecordDraw(record, &canvas, NULL, 0, NULL, 0);
323 } 323 }
324 REPORTER_ASSERT(r, canvas.fDrawImageCalled); 324 REPORTER_ASSERT(r, canvas.fDrawImageCalled);
325 canvas.resetTestValues(); 325 canvas.resetTestValues();
326 326
327 { 327 {
328 SkRecord record; 328 SkRecord record;
329 SkRecorder recorder(&record, 10, 10); 329 SkRecorder recorder(&record, 10, 10);
330 recorder.drawImageRect(image, 0, SkRect::MakeWH(10, 10)); 330 recorder.drawImageRect(image, 0, SkRect::MakeWH(10, 10));
331 SkRecordDraw(record, &canvas, 0, 0); 331 SkRecordDraw(record, &canvas, NULL, 0, NULL, 0);
332 } 332 }
333 REPORTER_ASSERT(r, canvas.fDrawImageRectCalled); 333 REPORTER_ASSERT(r, canvas.fDrawImageRectCalled);
334 334
335 } 335 }
OLDNEW
« no previous file with comments | « src/gpu/GrRecordReplaceDraw.cpp ('k') | tools/DumpRecord.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698