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

Side by Side Diff: tests/RecordDrawTest.cpp

Issue 251133008: Backfill unit tests for SkRecord (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 7 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 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 9
10 #include "SkDebugCanvas.h" 10 #include "SkDebugCanvas.h"
11 #include "SkRecord.h" 11 #include "SkRecord.h"
12 #include "SkRecordOpts.h" 12 #include "SkRecordOpts.h"
13 #include "SkRecordDraw.h" 13 #include "SkRecordDraw.h"
14 #include "SkRecorder.h" 14 #include "SkRecorder.h"
15 #include "SkRecords.h" 15 #include "SkRecords.h"
16 16
17 static const int W = 1920, H = 1080; 17 static const int W = 1920, H = 1080;
18 18
19 static void draw_pos_text_h(SkCanvas* canvas, const char* text, SkScalar y) {
20 const size_t len = strlen(text);
21 SkAutoTMalloc<SkScalar> xpos(len);
22 for (size_t i = 0; i < len; i++) {
23 xpos[i] = (SkScalar)i;
24 }
25 canvas->drawPosTextH(text, len, xpos, y, SkPaint());
26 }
27
28 // Rerecord into another SkRecord using full SkCanvas semantics,
29 // tracking clips and allowing SkRecordDraw's quickReject() calls to work.
30 static void record_clipped(const SkRecord& record, SkRect clip, SkRecord* clippe d) {
31 SkRecorder recorder(SkRecorder::kReadWrite_Mode, clipped, W, H);
32 recorder.clipRect(clip);
33 SkRecordDraw(record, &recorder);
34 }
35
36 DEF_TEST(RecordDraw_PosTextHQuickReject, r) {
37 SkRecord record;
38 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, W, H);
39
40 draw_pos_text_h(&recorder, "This will draw.", 20);
41 draw_pos_text_h(&recorder, "This won't.", 5000);
42
43 SkRecordBoundDrawPosTextH(&record);
44
45 SkRecord clipped;
46 record_clipped(record, SkRect::MakeLTRB(20, 20, 200, 200), &clipped);
47
48 // clipRect and the first drawPosTextH.
49 REPORTER_ASSERT(r, 2 == clipped.count());
50 }
51
19 DEF_TEST(RecordDraw_Culling, r) { 52 DEF_TEST(RecordDraw_Culling, r) {
20 // Record these 7 drawing commands verbatim. 53 // Record these 7 drawing commands verbatim.
21 SkRecord record; 54 SkRecord record;
22 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, W, H); 55 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, W, H);
23 56
24 recorder.pushCull(SkRect::MakeWH(100, 100)); 57 recorder.pushCull(SkRect::MakeWH(100, 100));
25 recorder.drawRect(SkRect::MakeWH(10, 10), SkPaint()); 58 recorder.drawRect(SkRect::MakeWH(10, 10), SkPaint());
26 recorder.drawRect(SkRect::MakeWH(30, 30), SkPaint()); 59 recorder.drawRect(SkRect::MakeWH(30, 30), SkPaint());
27 recorder.pushCull(SkRect::MakeWH(5, 5)); 60 recorder.pushCull(SkRect::MakeWH(5, 5));
28 recorder.drawRect(SkRect::MakeWH(1, 1), SkPaint()); 61 recorder.drawRect(SkRect::MakeWH(1, 1), SkPaint());
29 recorder.popCull(); 62 recorder.popCull();
30 recorder.popCull(); 63 recorder.popCull();
31 64
32 // Take a pass over to match up pushCulls and popCulls. 65 // Take a pass over to match up pushCulls and popCulls.
33 SkRecordAnnotateCullingPairs(&record); 66 SkRecordAnnotateCullingPairs(&record);
34 67
35 // Rerecord into another SkRecord using full SkCanvas semantics,
36 // tracking clips and allowing SkRecordDraw's quickReject() calls to work.
37 SkRecord rerecord;
38 SkRecorder rerecorder(SkRecorder::kReadWrite_Mode, &rerecord, W, H);
39 // This clip intersects the outer cull, but allows us to quick reject the in ner one. 68 // This clip intersects the outer cull, but allows us to quick reject the in ner one.
40 rerecorder.clipRect(SkRect::MakeLTRB(20, 20, 200, 200)); 69 SkRecord clipped;
41 70 record_clipped(record, SkRect::MakeLTRB(20, 20, 200, 200), &clipped);
42 SkRecordDraw(record, &rerecorder);
43 71
44 // We'll keep the clipRect call from above, and the outer two drawRects, and the push/pop pair. 72 // We'll keep the clipRect call from above, and the outer two drawRects, and the push/pop pair.
45 // If culling weren't working, we'd see 8 commands recorded here. 73 // If culling weren't working, we'd see 8 commands recorded here.
46 REPORTER_ASSERT(r, 5 == rerecord.count()); 74 REPORTER_ASSERT(r, 5 == clipped.count());
47 } 75 }
OLDNEW
« no previous file with comments | « tests/RecordCullingTest.cpp ('k') | tests/RecordOptsTest.cpp » ('j') | tests/RecordOptsTest.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698