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

Side by Side Diff: tests/RecordDrawTest.cpp

Issue 531933002: Fix drawPosText() bounds bug. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: get rid of line feed Created 6 years, 3 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 | « src/core/SkRecordDraw.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
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 virtual void rewindInserts() SK_OVERRIDE {} 110 virtual void rewindInserts() SK_OVERRIDE {}
111 virtual int getDepth() const SK_OVERRIDE { return -1; } 111 virtual int getDepth() const SK_OVERRIDE { return -1; }
112 112
113 struct Entry { 113 struct Entry {
114 uintptr_t data; 114 uintptr_t data;
115 SkRect bounds; 115 SkRect bounds;
116 }; 116 };
117 SkTDArray<Entry> entries; 117 SkTDArray<Entry> entries;
118 }; 118 };
119 119
120 // Like a==b, with a little slop recognizing that float equality can be weird.
121 static bool sloppy_rect_eq(SkRect a, SkRect b) {
122 SkRect inset(a), outset(a);
123 inset.inset(1, 1);
124 outset.outset(1, 1);
125 return outset.contains(b) && !inset.contains(b);
126 }
127
120 // This test is not meant to make total sense yet. It's testing the status quo 128 // This test is not meant to make total sense yet. It's testing the status quo
121 // of SkRecordFillBounds(), which itself doesn't make total sense yet. 129 // of SkRecordFillBounds(), which itself doesn't make total sense yet.
122 DEF_TEST(RecordDraw_BBH, r) { 130 DEF_TEST(RecordDraw_BBH, r) {
123 TestBBH bbh;
124
125 SkRecord record; 131 SkRecord record;
126
127 SkRecorder recorder(&record, W, H); 132 SkRecorder recorder(&record, W, H);
128 recorder.save(); 133 recorder.save();
129 recorder.clipRect(SkRect::MakeWH(400, 500)); 134 recorder.clipRect(SkRect::MakeWH(400, 500));
130 recorder.scale(2, 2); 135 recorder.scale(2, 2);
131 recorder.drawRect(SkRect::MakeWH(320, 240), SkPaint()); 136 recorder.drawRect(SkRect::MakeWH(320, 240), SkPaint());
132 recorder.restore(); 137 recorder.restore();
133 138
139 TestBBH bbh;
134 SkRecordFillBounds(record, &bbh); 140 SkRecordFillBounds(record, &bbh);
135 141
136 REPORTER_ASSERT(r, bbh.entries.count() == 5); 142 REPORTER_ASSERT(r, bbh.entries.count() == 5);
137 for (int i = 0; i < bbh.entries.count(); i++) { 143 for (int i = 0; i < bbh.entries.count(); i++) {
138 REPORTER_ASSERT(r, bbh.entries[i].data == (uintptr_t)i); 144 REPORTER_ASSERT(r, bbh.entries[i].data == (uintptr_t)i);
139 145
140 // We'd like to assert bounds == SkRect::MakeWH(400, 480). 146 REPORTER_ASSERT(r, sloppy_rect_eq(SkRect::MakeWH(400, 480), bbh.entries[ i].bounds));
141 // But we allow a little slop in recognition that float equality can be weird.
142 REPORTER_ASSERT(r, SkRect::MakeLTRB(-1, -1, 401, 481).contains(bbh.entr ies[i].bounds));
143 REPORTER_ASSERT(r, !SkRect::MakeLTRB(+1, +1, 399, 479).contains(bbh.entr ies[i].bounds));
144 } 147 }
145 } 148 }
146 149
150 // A regression test for crbug.com/409110.
151 DEF_TEST(RecordDraw_TextBounds, r) {
152 SkRecord record;
153 SkRecorder recorder(&record, W, H);
154
155 // Two Chinese characters in UTF-8.
156 const char text[] = { '\xe6', '\xbc', '\xa2', '\xe5', '\xad', '\x97' };
157 const size_t bytes = SK_ARRAY_COUNT(text);
158
159 const SkScalar xpos[] = { 10, 20 };
160 recorder.drawPosTextH(text, bytes, xpos, 30, SkPaint());
161
162 const SkPoint pos[] = { {40, 50}, {60, 70} };
163 recorder.drawPosText(text, bytes, pos, SkPaint());
164
165 TestBBH bbh;
166 SkRecordFillBounds(record, &bbh);
167 REPORTER_ASSERT(r, bbh.entries.count() == 2);
168
169 // We can make these next assertions confidently because SkRecordFillBounds
170 // builds its bounds by overestimating font metrics in a platform-independen t way.
171 // If that changes, these tests will need to be more flexible.
172 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.entries[0].bounds, SkRect::MakeLTRB(-8 6, 6, 116, 54)));
173 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.entries[1].bounds, SkRect::MakeLTRB(-5 6, 26, 156, 94)));
174 }
175
147 // Base test to ensure start/stop range is respected 176 // Base test to ensure start/stop range is respected
148 DEF_TEST(RecordDraw_PartialStartStop, r) { 177 DEF_TEST(RecordDraw_PartialStartStop, r) {
149 static const int kWidth = 10, kHeight = 10; 178 static const int kWidth = 10, kHeight = 10;
150 179
151 SkRect r1 = { 0, 0, kWidth, kHeight }; 180 SkRect r1 = { 0, 0, kWidth, kHeight };
152 SkRect r2 = { 0, 0, kWidth, kHeight/2 }; 181 SkRect r2 = { 0, 0, kWidth, kHeight/2 };
153 SkRect r3 = { 0, 0, kWidth/2, kHeight }; 182 SkRect r3 = { 0, 0, kWidth/2, kHeight };
154 SkPaint p; 183 SkPaint p;
155 184
156 SkRecord record; 185 SkRecord record;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 217
189 REPORTER_ASSERT(r, 3 == rerecord.count()); 218 REPORTER_ASSERT(r, 3 == rerecord.count());
190 assert_type<SkRecords::Save> (r, rerecord, 0); 219 assert_type<SkRecords::Save> (r, rerecord, 0);
191 assert_type<SkRecords::DrawRect>(r, rerecord, 1); 220 assert_type<SkRecords::DrawRect>(r, rerecord, 1);
192 assert_type<SkRecords::Restore> (r, rerecord, 2); 221 assert_type<SkRecords::Restore> (r, rerecord, 2);
193 222
194 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);
195 REPORTER_ASSERT(r, drawRect->rect == rect); 224 REPORTER_ASSERT(r, drawRect->rect == rect);
196 REPORTER_ASSERT(r, drawRect->paint.getColor() == SK_ColorRED); 225 REPORTER_ASSERT(r, drawRect->paint.getColor() == SK_ColorRED);
197 } 226 }
OLDNEW
« no previous file with comments | « src/core/SkRecordDraw.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698