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

Side by Side Diff: tests/RecordOptsTest.cpp

Issue 452983002: SkRecord: Strip out cull-skipping and y-only drawPosTextH skipping. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Remove dead code. Created 6 years, 4 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
« no previous file with comments | « tests/RecordDrawTest.cpp ('k') | no next file » | 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
11 #include "SkRecord.h" 11 #include "SkRecord.h"
12 #include "SkRecordOpts.h" 12 #include "SkRecordOpts.h"
13 #include "SkRecorder.h" 13 #include "SkRecorder.h"
14 #include "SkRecords.h" 14 #include "SkRecords.h"
15 #include "SkXfermode.h" 15 #include "SkXfermode.h"
16 16
17 static const int W = 1920, H = 1080; 17 static const int W = 1920, H = 1080;
18 18
19 DEF_TEST(RecordOpts_Culling, r) {
20 SkRecord record;
21 SkRecorder recorder(&record, W, H);
22
23 recorder.drawRect(SkRect::MakeWH(1000, 10000), SkPaint());
24
25 recorder.pushCull(SkRect::MakeWH(100, 100));
26 recorder.drawRect(SkRect::MakeWH(10, 10), SkPaint());
27 recorder.drawRect(SkRect::MakeWH(30, 30), SkPaint());
28 recorder.pushCull(SkRect::MakeWH(5, 5));
29 recorder.drawRect(SkRect::MakeWH(1, 1), SkPaint());
30 recorder.popCull();
31 recorder.popCull();
32
33 SkRecordAnnotateCullingPairs(&record);
34
35 REPORTER_ASSERT(r, 6 == assert_type<SkRecords::PairedPushCull>(r, record, 1) ->skip);
36 REPORTER_ASSERT(r, 2 == assert_type<SkRecords::PairedPushCull>(r, record, 4) ->skip);
37 }
38
39 DEF_TEST(RecordOpts_NoopCulls, r) {
40 SkRecord record;
41 SkRecorder recorder(&record, W, H);
42
43 // All should be nooped.
44 recorder.pushCull(SkRect::MakeWH(200, 200));
45 recorder.pushCull(SkRect::MakeWH(100, 100));
46 recorder.popCull();
47 recorder.popCull();
48
49 // Kept for now. We could peel off a layer of culling.
50 recorder.pushCull(SkRect::MakeWH(5, 5));
51 recorder.pushCull(SkRect::MakeWH(5, 5));
52 recorder.drawRect(SkRect::MakeWH(1, 1), SkPaint());
53 recorder.popCull();
54 recorder.popCull();
55
56 SkRecordNoopCulls(&record);
57
58 for (unsigned i = 0; i < 4; i++) {
59 assert_type<SkRecords::NoOp>(r, record, i);
60 }
61 assert_type<SkRecords::PushCull>(r, record, 4);
62 assert_type<SkRecords::PushCull>(r, record, 5);
63 assert_type<SkRecords::DrawRect>(r, record, 6);
64 assert_type<SkRecords::PopCull>(r, record, 7);
65 assert_type<SkRecords::PopCull>(r, record, 8);
66 }
67
68 static void draw_pos_text(SkCanvas* canvas, const char* text, bool constantY) { 19 static void draw_pos_text(SkCanvas* canvas, const char* text, bool constantY) {
69 const size_t len = strlen(text); 20 const size_t len = strlen(text);
70 SkAutoTMalloc<SkPoint> pos(len); 21 SkAutoTMalloc<SkPoint> pos(len);
71 for (size_t i = 0; i < len; i++) { 22 for (size_t i = 0; i < len; i++) {
72 pos[i].fX = (SkScalar)i; 23 pos[i].fX = (SkScalar)i;
73 pos[i].fY = constantY ? SK_Scalar1 : (SkScalar)i; 24 pos[i].fY = constantY ? SK_Scalar1 : (SkScalar)i;
74 } 25 }
75 canvas->drawPosText(text, len, pos, SkPaint()); 26 canvas->drawPosText(text, len, pos, SkPaint());
76 } 27 }
77 28
78 DEF_TEST(RecordOpts_StrengthReduction, r) { 29 DEF_TEST(RecordOpts_StrengthReduction, r) {
79 SkRecord record; 30 SkRecord record;
80 SkRecorder recorder(&record, W, H); 31 SkRecorder recorder(&record, W, H);
81 32
82 // We can convert a drawPosText into a drawPosTextH when all the Ys are the same. 33 // We can convert a drawPosText into a drawPosTextH when all the Ys are the same.
83 draw_pos_text(&recorder, "This will be reduced to drawPosTextH.", true); 34 draw_pos_text(&recorder, "This will be reduced to drawPosTextH.", true);
84 draw_pos_text(&recorder, "This cannot be reduced to drawPosTextH.", false); 35 draw_pos_text(&recorder, "This cannot be reduced to drawPosTextH.", false);
85 36
86 SkRecordReduceDrawPosTextStrength(&record); 37 SkRecordReduceDrawPosTextStrength(&record);
87 38
88 assert_type<SkRecords::DrawPosTextH>(r, record, 0); 39 assert_type<SkRecords::DrawPosTextH>(r, record, 0);
89 assert_type<SkRecords::DrawPosText>(r, record, 1); 40 assert_type<SkRecords::DrawPosText>(r, record, 1);
90 } 41 }
91 42
92 DEF_TEST(RecordOpts_TextBounding, r) {
93 SkRecord record;
94 SkRecorder recorder(&record, W, H);
95
96 // First, get a drawPosTextH. Here's a handy way. Its text size will be th e default (12).
97 draw_pos_text(&recorder, "This will be reduced to drawPosTextH.", true);
98 SkRecordReduceDrawPosTextStrength(&record);
99
100 const SkRecords::DrawPosTextH* original =
101 assert_type<SkRecords::DrawPosTextH>(r, record, 0);
102
103 // This should wrap the original DrawPosTextH with minY and maxY.
104 SkRecordBoundDrawPosTextH(&record);
105
106 const SkRecords::BoundedDrawPosTextH* bounded =
107 assert_type<SkRecords::BoundedDrawPosTextH>(r, record, 0);
108
109 const SkPaint defaults;
110 REPORTER_ASSERT(r, bounded->base == original);
111 REPORTER_ASSERT(r, bounded->minY <= SK_Scalar1 - defaults.getTextSize());
112 REPORTER_ASSERT(r, bounded->maxY >= SK_Scalar1 + defaults.getTextSize());
113 }
114
115 DEF_TEST(RecordOpts_NoopDrawSaveRestore, r) { 43 DEF_TEST(RecordOpts_NoopDrawSaveRestore, r) {
116 SkRecord record; 44 SkRecord record;
117 SkRecorder recorder(&record, W, H); 45 SkRecorder recorder(&record, W, H);
118 46
119 // The save and restore are pointless if there's only draw commands in the m iddle. 47 // The save and restore are pointless if there's only draw commands in the m iddle.
120 recorder.save(); 48 recorder.save();
121 recorder.drawRect(SkRect::MakeWH(200, 200), SkPaint()); 49 recorder.drawRect(SkRect::MakeWH(200, 200), SkPaint());
122 recorder.drawRect(SkRect::MakeWH(300, 300), SkPaint()); 50 recorder.drawRect(SkRect::MakeWH(300, 300), SkPaint());
123 recorder.drawRect(SkRect::MakeWH(100, 100), SkPaint()); 51 recorder.drawRect(SkRect::MakeWH(100, 100), SkPaint());
124 recorder.restore(); 52 recorder.restore();
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 // SaveLayer/Restore removed: we can fold in the alpha! 164 // SaveLayer/Restore removed: we can fold in the alpha!
237 recorder.saveLayer(NULL, &goodLayerPaint); 165 recorder.saveLayer(NULL, &goodLayerPaint);
238 recorder.drawRect(draw, goodDrawPaint); 166 recorder.drawRect(draw, goodDrawPaint);
239 recorder.restore(); 167 recorder.restore();
240 assert_savelayer_restore(r, &record, 15, true); 168 assert_savelayer_restore(r, &record, 15, true);
241 169
242 const SkRecords::DrawRect* drawRect = assert_type<SkRecords::DrawRect>(r, re cord, 16); 170 const SkRecords::DrawRect* drawRect = assert_type<SkRecords::DrawRect>(r, re cord, 16);
243 REPORTER_ASSERT(r, drawRect != NULL); 171 REPORTER_ASSERT(r, drawRect != NULL);
244 REPORTER_ASSERT(r, drawRect->paint.getColor() == 0x03020202); 172 REPORTER_ASSERT(r, drawRect->paint.getColor() == 0x03020202);
245 } 173 }
OLDNEW
« no previous file with comments | « tests/RecordDrawTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698