OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/playback/display_item_list.h" | 5 #include "cc/playback/display_item_list.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "cc/output/filter_operation.h" | 9 #include "cc/output/filter_operation.h" |
10 #include "cc/output/filter_operations.h" | 10 #include "cc/output/filter_operations.h" |
(...skipping 10 matching lines...) Expand all Loading... | |
21 #include "skia/ext/refptr.h" | 21 #include "skia/ext/refptr.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
23 #include "third_party/skia/include/core/SkBitmap.h" | 23 #include "third_party/skia/include/core/SkBitmap.h" |
24 #include "third_party/skia/include/core/SkCanvas.h" | 24 #include "third_party/skia/include/core/SkCanvas.h" |
25 #include "third_party/skia/include/core/SkColor.h" | 25 #include "third_party/skia/include/core/SkColor.h" |
26 #include "third_party/skia/include/core/SkPictureRecorder.h" | 26 #include "third_party/skia/include/core/SkPictureRecorder.h" |
27 #include "third_party/skia/include/core/SkSurface.h" | 27 #include "third_party/skia/include/core/SkSurface.h" |
28 #include "third_party/skia/include/core/SkXfermode.h" | 28 #include "third_party/skia/include/core/SkXfermode.h" |
29 #include "third_party/skia/include/effects/SkImageSource.h" | 29 #include "third_party/skia/include/effects/SkImageSource.h" |
30 #include "third_party/skia/include/utils/SkPictureUtils.h" | 30 #include "third_party/skia/include/utils/SkPictureUtils.h" |
31 #include "ui/gfx/geometry/rect.h" | |
31 #include "ui/gfx/geometry/rect_conversions.h" | 32 #include "ui/gfx/geometry/rect_conversions.h" |
32 #include "ui/gfx/skia_util.h" | 33 #include "ui/gfx/skia_util.h" |
33 | 34 |
34 namespace cc { | 35 namespace cc { |
35 | 36 |
36 namespace { | 37 namespace { |
37 | 38 |
39 static const gfx::Rect kVisualRect(0, 0, 42, 42); | |
vmpstr
2015/11/17 21:15:13
static and anonymous namespaces are redundant, i t
| |
40 | |
38 void AppendFirstSerializationTestPicture(scoped_refptr<DisplayItemList> list, | 41 void AppendFirstSerializationTestPicture(scoped_refptr<DisplayItemList> list, |
39 const gfx::Size& layer_size) { | 42 const gfx::Size& layer_size) { |
40 gfx::PointF offset(2.f, 3.f); | 43 gfx::PointF offset(2.f, 3.f); |
41 SkPictureRecorder recorder; | 44 SkPictureRecorder recorder; |
42 skia::RefPtr<SkCanvas> canvas; | 45 skia::RefPtr<SkCanvas> canvas; |
43 skia::RefPtr<SkPicture> picture; | 46 skia::RefPtr<SkPicture> picture; |
44 | 47 |
45 SkPaint red_paint; | 48 SkPaint red_paint; |
46 red_paint.setColor(SK_ColorRED); | 49 red_paint.setColor(SK_ColorRED); |
47 | 50 |
48 canvas = skia::SharePtr(recorder.beginRecording(SkRect::MakeXYWH( | 51 canvas = skia::SharePtr(recorder.beginRecording(SkRect::MakeXYWH( |
49 offset.x(), offset.y(), layer_size.width(), layer_size.height()))); | 52 offset.x(), offset.y(), layer_size.width(), layer_size.height()))); |
50 canvas->translate(offset.x(), offset.y()); | 53 canvas->translate(offset.x(), offset.y()); |
51 canvas->drawRectCoords(0.f, 0.f, 4.f, 4.f, red_paint); | 54 canvas->drawRectCoords(0.f, 0.f, 4.f, 4.f, red_paint); |
52 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 55 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
53 list->CreateAndAppendItem<DrawingDisplayItem>()->SetNew(picture); | 56 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect)->SetNew(picture); |
54 } | 57 } |
55 | 58 |
56 void AppendSecondSerializationTestPicture(scoped_refptr<DisplayItemList> list, | 59 void AppendSecondSerializationTestPicture(scoped_refptr<DisplayItemList> list, |
57 const gfx::Size& layer_size) { | 60 const gfx::Size& layer_size) { |
58 gfx::PointF offset(2.f, 2.f); | 61 gfx::PointF offset(2.f, 2.f); |
59 SkPictureRecorder recorder; | 62 SkPictureRecorder recorder; |
60 skia::RefPtr<SkCanvas> canvas; | 63 skia::RefPtr<SkCanvas> canvas; |
61 skia::RefPtr<SkPicture> picture; | 64 skia::RefPtr<SkPicture> picture; |
62 | 65 |
63 SkPaint blue_paint; | 66 SkPaint blue_paint; |
64 blue_paint.setColor(SK_ColorBLUE); | 67 blue_paint.setColor(SK_ColorBLUE); |
65 | 68 |
66 canvas = skia::SharePtr(recorder.beginRecording(SkRect::MakeXYWH( | 69 canvas = skia::SharePtr(recorder.beginRecording(SkRect::MakeXYWH( |
67 offset.x(), offset.y(), layer_size.width(), layer_size.height()))); | 70 offset.x(), offset.y(), layer_size.width(), layer_size.height()))); |
68 canvas->translate(offset.x(), offset.y()); | 71 canvas->translate(offset.x(), offset.y()); |
69 canvas->drawRectCoords(3.f, 3.f, 7.f, 7.f, blue_paint); | 72 canvas->drawRectCoords(3.f, 3.f, 7.f, 7.f, blue_paint); |
70 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 73 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
71 list->CreateAndAppendItem<DrawingDisplayItem>()->SetNew(picture); | 74 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect)->SetNew(picture); |
72 } | 75 } |
73 | 76 |
74 void ValidateDisplayItemListSerialization(const gfx::Size& layer_size, | 77 void ValidateDisplayItemListSerialization(const gfx::Size& layer_size, |
75 scoped_refptr<DisplayItemList> list) { | 78 scoped_refptr<DisplayItemList> list) { |
76 // Serialize and deserialize the DisplayItemList. | 79 // Serialize and deserialize the DisplayItemList. |
77 proto::DisplayItemList proto; | 80 proto::DisplayItemList proto; |
78 list->ToProtobuf(&proto); | 81 list->ToProtobuf(&proto); |
79 scoped_refptr<DisplayItemList> new_list = | 82 scoped_refptr<DisplayItemList> new_list = |
80 DisplayItemList::CreateFromProto(proto); | 83 DisplayItemList::CreateFromProto(proto); |
81 | 84 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 scoped_refptr<DisplayItemList> list = | 145 scoped_refptr<DisplayItemList> list = |
143 DisplayItemList::Create(gfx::Rect(layer_size), settings); | 146 DisplayItemList::Create(gfx::Rect(layer_size), settings); |
144 | 147 |
145 // Build the DrawingDisplayItem. | 148 // Build the DrawingDisplayItem. |
146 AppendFirstSerializationTestPicture(list, layer_size); | 149 AppendFirstSerializationTestPicture(list, layer_size); |
147 | 150 |
148 // Build the ClipDisplayItem. | 151 // Build the ClipDisplayItem. |
149 gfx::Rect clip_rect(6, 6, 1, 1); | 152 gfx::Rect clip_rect(6, 6, 1, 1); |
150 std::vector<SkRRect> rrects; | 153 std::vector<SkRRect> rrects; |
151 rrects.push_back(SkRRect::MakeOval(SkRect::MakeXYWH(5.f, 5.f, 4.f, 4.f))); | 154 rrects.push_back(SkRRect::MakeOval(SkRect::MakeXYWH(5.f, 5.f, 4.f, 4.f))); |
152 auto* item = list->CreateAndAppendItem<ClipDisplayItem>(); | 155 auto* item = list->CreateAndAppendItem<ClipDisplayItem>(kVisualRect); |
153 item->SetNew(clip_rect, rrects); | 156 item->SetNew(clip_rect, rrects); |
154 | 157 |
155 // Build the second DrawingDisplayItem. | 158 // Build the second DrawingDisplayItem. |
156 AppendSecondSerializationTestPicture(list, layer_size); | 159 AppendSecondSerializationTestPicture(list, layer_size); |
157 | 160 |
158 // Build the EndClipDisplayItem. | 161 // Build the EndClipDisplayItem. |
159 list->CreateAndAppendItem<EndClipDisplayItem>(); | 162 list->CreateAndAppendItem<EndClipDisplayItem>(kVisualRect); |
160 | 163 |
161 ValidateDisplayItemListSerialization(layer_size, list); | 164 ValidateDisplayItemListSerialization(layer_size, list); |
162 } | 165 } |
163 | 166 |
164 TEST(DisplayItemListTest, SerializeClipPathItem) { | 167 TEST(DisplayItemListTest, SerializeClipPathItem) { |
165 gfx::Size layer_size(10, 10); | 168 gfx::Size layer_size(10, 10); |
166 | 169 |
167 DisplayItemListSettings settings; | 170 DisplayItemListSettings settings; |
168 settings.use_cached_picture = true; | 171 settings.use_cached_picture = true; |
169 scoped_refptr<DisplayItemList> list = | 172 scoped_refptr<DisplayItemList> list = |
170 DisplayItemList::Create(gfx::Rect(layer_size), settings); | 173 DisplayItemList::Create(gfx::Rect(layer_size), settings); |
171 | 174 |
172 // Build the DrawingDisplayItem. | 175 // Build the DrawingDisplayItem. |
173 AppendFirstSerializationTestPicture(list, layer_size); | 176 AppendFirstSerializationTestPicture(list, layer_size); |
174 | 177 |
175 // Build the ClipPathDisplayItem. | 178 // Build the ClipPathDisplayItem. |
176 SkPath path; | 179 SkPath path; |
177 path.addCircle(5.f, 5.f, 2.f, SkPath::Direction::kCW_Direction); | 180 path.addCircle(5.f, 5.f, 2.f, SkPath::Direction::kCW_Direction); |
178 auto* item = list->CreateAndAppendItem<ClipPathDisplayItem>(); | 181 auto* item = list->CreateAndAppendItem<ClipPathDisplayItem>(kVisualRect); |
179 item->SetNew(path, SkRegion::Op::kReplace_Op, false); | 182 item->SetNew(path, SkRegion::Op::kReplace_Op, false); |
180 | 183 |
181 // Build the second DrawingDisplayItem. | 184 // Build the second DrawingDisplayItem. |
182 AppendSecondSerializationTestPicture(list, layer_size); | 185 AppendSecondSerializationTestPicture(list, layer_size); |
183 | 186 |
184 // Build the EndClipPathDisplayItem. | 187 // Build the EndClipPathDisplayItem. |
185 list->CreateAndAppendItem<EndClipPathDisplayItem>(); | 188 list->CreateAndAppendItem<EndClipPathDisplayItem>(kVisualRect); |
186 | 189 |
187 ValidateDisplayItemListSerialization(layer_size, list); | 190 ValidateDisplayItemListSerialization(layer_size, list); |
188 } | 191 } |
189 | 192 |
190 TEST(DisplayItemListTest, SerializeCompositingItem) { | 193 TEST(DisplayItemListTest, SerializeCompositingItem) { |
191 gfx::Size layer_size(10, 10); | 194 gfx::Size layer_size(10, 10); |
192 | 195 |
193 DisplayItemListSettings settings; | 196 DisplayItemListSettings settings; |
194 settings.use_cached_picture = true; | 197 settings.use_cached_picture = true; |
195 scoped_refptr<DisplayItemList> list = | 198 scoped_refptr<DisplayItemList> list = |
196 DisplayItemList::Create(gfx::Rect(layer_size), settings); | 199 DisplayItemList::Create(gfx::Rect(layer_size), settings); |
197 | 200 |
198 // Build the DrawingDisplayItem. | 201 // Build the DrawingDisplayItem. |
199 AppendFirstSerializationTestPicture(list, layer_size); | 202 AppendFirstSerializationTestPicture(list, layer_size); |
200 | 203 |
201 // Build the CompositingDisplayItem. | 204 // Build the CompositingDisplayItem. |
202 skia::RefPtr<SkColorFilter> filter = skia::AdoptRef( | 205 skia::RefPtr<SkColorFilter> filter = skia::AdoptRef( |
203 SkColorFilter::CreateLightingFilter(SK_ColorRED, SK_ColorGREEN)); | 206 SkColorFilter::CreateLightingFilter(SK_ColorRED, SK_ColorGREEN)); |
204 auto* item = list->CreateAndAppendItem<CompositingDisplayItem>(); | 207 auto* item = list->CreateAndAppendItem<CompositingDisplayItem>(kVisualRect); |
205 item->SetNew(150, SkXfermode::Mode::kDst_Mode, nullptr, filter); | 208 item->SetNew(150, SkXfermode::Mode::kDst_Mode, nullptr, filter); |
206 | 209 |
207 // Build the second DrawingDisplayItem. | 210 // Build the second DrawingDisplayItem. |
208 AppendSecondSerializationTestPicture(list, layer_size); | 211 AppendSecondSerializationTestPicture(list, layer_size); |
209 | 212 |
210 // Build the EndCompositingDisplayItem. | 213 // Build the EndCompositingDisplayItem. |
211 list->CreateAndAppendItem<EndCompositingDisplayItem>(); | 214 list->CreateAndAppendItem<EndCompositingDisplayItem>(kVisualRect); |
212 | 215 |
213 ValidateDisplayItemListSerialization(layer_size, list); | 216 ValidateDisplayItemListSerialization(layer_size, list); |
214 } | 217 } |
215 | 218 |
216 TEST(DisplayItemListTest, SerializeFloatClipItem) { | 219 TEST(DisplayItemListTest, SerializeFloatClipItem) { |
217 gfx::Size layer_size(10, 10); | 220 gfx::Size layer_size(10, 10); |
218 | 221 |
219 DisplayItemListSettings settings; | 222 DisplayItemListSettings settings; |
220 settings.use_cached_picture = true; | 223 settings.use_cached_picture = true; |
221 scoped_refptr<DisplayItemList> list = | 224 scoped_refptr<DisplayItemList> list = |
222 DisplayItemList::Create(gfx::Rect(layer_size), settings); | 225 DisplayItemList::Create(gfx::Rect(layer_size), settings); |
223 | 226 |
224 // Build the DrawingDisplayItem. | 227 // Build the DrawingDisplayItem. |
225 AppendFirstSerializationTestPicture(list, layer_size); | 228 AppendFirstSerializationTestPicture(list, layer_size); |
226 | 229 |
227 // Build the FloatClipDisplayItem. | 230 // Build the FloatClipDisplayItem. |
228 gfx::RectF clip_rect(6.f, 6.f, 1.f, 1.f); | 231 gfx::RectF clip_rect(6.f, 6.f, 1.f, 1.f); |
229 auto* item2 = list->CreateAndAppendItem<FloatClipDisplayItem>(); | 232 auto* item2 = list->CreateAndAppendItem<FloatClipDisplayItem>(kVisualRect); |
230 item2->SetNew(clip_rect); | 233 item2->SetNew(clip_rect); |
231 | 234 |
232 // Build the second DrawingDisplayItem. | 235 // Build the second DrawingDisplayItem. |
233 AppendSecondSerializationTestPicture(list, layer_size); | 236 AppendSecondSerializationTestPicture(list, layer_size); |
234 | 237 |
235 // Build the EndFloatClipDisplayItem. | 238 // Build the EndFloatClipDisplayItem. |
236 list->CreateAndAppendItem<EndFloatClipDisplayItem>(); | 239 list->CreateAndAppendItem<EndFloatClipDisplayItem>(kVisualRect); |
237 | 240 |
238 ValidateDisplayItemListSerialization(layer_size, list); | 241 ValidateDisplayItemListSerialization(layer_size, list); |
239 } | 242 } |
240 | 243 |
241 TEST(DisplayItemListTest, SerializeTransformItem) { | 244 TEST(DisplayItemListTest, SerializeTransformItem) { |
242 gfx::Size layer_size(10, 10); | 245 gfx::Size layer_size(10, 10); |
243 | 246 |
244 DisplayItemListSettings settings; | 247 DisplayItemListSettings settings; |
245 settings.use_cached_picture = true; | 248 settings.use_cached_picture = true; |
246 scoped_refptr<DisplayItemList> list = | 249 scoped_refptr<DisplayItemList> list = |
247 DisplayItemList::Create(gfx::Rect(layer_size), settings); | 250 DisplayItemList::Create(gfx::Rect(layer_size), settings); |
248 | 251 |
249 // Build the DrawingDisplayItem. | 252 // Build the DrawingDisplayItem. |
250 AppendFirstSerializationTestPicture(list, layer_size); | 253 AppendFirstSerializationTestPicture(list, layer_size); |
251 | 254 |
252 // Build the TransformDisplayItem. | 255 // Build the TransformDisplayItem. |
253 gfx::Transform transform; | 256 gfx::Transform transform; |
254 transform.Scale(1.25f, 1.25f); | 257 transform.Scale(1.25f, 1.25f); |
255 transform.Translate(-1.f, -1.f); | 258 transform.Translate(-1.f, -1.f); |
256 auto* item2 = list->CreateAndAppendItem<TransformDisplayItem>(); | 259 auto* item2 = list->CreateAndAppendItem<TransformDisplayItem>(kVisualRect); |
257 item2->SetNew(transform); | 260 item2->SetNew(transform); |
258 | 261 |
259 // Build the second DrawingDisplayItem. | 262 // Build the second DrawingDisplayItem. |
260 AppendSecondSerializationTestPicture(list, layer_size); | 263 AppendSecondSerializationTestPicture(list, layer_size); |
261 | 264 |
262 // Build the EndTransformDisplayItem. | 265 // Build the EndTransformDisplayItem. |
263 list->CreateAndAppendItem<EndTransformDisplayItem>(); | 266 list->CreateAndAppendItem<EndTransformDisplayItem>(kVisualRect); |
264 | 267 |
265 ValidateDisplayItemListSerialization(layer_size, list); | 268 ValidateDisplayItemListSerialization(layer_size, list); |
266 } | 269 } |
267 | 270 |
268 TEST(DisplayItemListTest, SingleDrawingItem) { | 271 TEST(DisplayItemListTest, SingleDrawingItem) { |
269 gfx::Rect layer_rect(100, 100); | 272 gfx::Rect layer_rect(100, 100); |
270 SkPictureRecorder recorder; | 273 SkPictureRecorder recorder; |
271 skia::RefPtr<SkCanvas> canvas; | 274 skia::RefPtr<SkCanvas> canvas; |
272 skia::RefPtr<SkPicture> picture; | 275 skia::RefPtr<SkPicture> picture; |
273 SkPaint blue_paint; | 276 SkPaint blue_paint; |
274 blue_paint.setColor(SK_ColorBLUE); | 277 blue_paint.setColor(SK_ColorBLUE); |
275 SkPaint red_paint; | 278 SkPaint red_paint; |
276 red_paint.setColor(SK_ColorRED); | 279 red_paint.setColor(SK_ColorRED); |
277 unsigned char pixels[4 * 100 * 100] = {0}; | 280 unsigned char pixels[4 * 100 * 100] = {0}; |
278 DisplayItemListSettings settings; | 281 DisplayItemListSettings settings; |
279 settings.use_cached_picture = true; | 282 settings.use_cached_picture = true; |
280 scoped_refptr<DisplayItemList> list = | 283 scoped_refptr<DisplayItemList> list = |
281 DisplayItemList::Create(layer_rect, settings); | 284 DisplayItemList::Create(layer_rect, settings); |
282 | 285 |
283 gfx::PointF offset(8.f, 9.f); | 286 gfx::PointF offset(8.f, 9.f); |
284 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); | 287 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); |
285 canvas = skia::SharePtr( | 288 canvas = skia::SharePtr( |
286 recorder.beginRecording(gfx::RectFToSkRect(recording_rect))); | 289 recorder.beginRecording(gfx::RectFToSkRect(recording_rect))); |
287 canvas->translate(offset.x(), offset.y()); | 290 canvas->translate(offset.x(), offset.y()); |
288 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); | 291 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); |
289 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); | 292 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); |
290 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 293 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
291 auto* item = list->CreateAndAppendItem<DrawingDisplayItem>(); | 294 auto* item = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); |
292 item->SetNew(picture); | 295 item->SetNew(picture); |
293 list->Finalize(); | 296 list->Finalize(); |
294 DrawDisplayList(pixels, layer_rect, list); | 297 DrawDisplayList(pixels, layer_rect, list); |
295 | 298 |
296 SkBitmap expected_bitmap; | 299 SkBitmap expected_bitmap; |
297 unsigned char expected_pixels[4 * 100 * 100] = {0}; | 300 unsigned char expected_pixels[4 * 100 * 100] = {0}; |
298 SkImageInfo info = | 301 SkImageInfo info = |
299 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); | 302 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); |
300 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); | 303 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); |
301 SkCanvas expected_canvas(expected_bitmap); | 304 SkCanvas expected_canvas(expected_bitmap); |
(...skipping 23 matching lines...) Expand all Loading... | |
325 scoped_refptr<DisplayItemList> list = | 328 scoped_refptr<DisplayItemList> list = |
326 DisplayItemList::Create(layer_rect, settings); | 329 DisplayItemList::Create(layer_rect, settings); |
327 | 330 |
328 gfx::PointF first_offset(8.f, 9.f); | 331 gfx::PointF first_offset(8.f, 9.f); |
329 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); | 332 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); |
330 canvas = skia::SharePtr( | 333 canvas = skia::SharePtr( |
331 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect))); | 334 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect))); |
332 canvas->translate(first_offset.x(), first_offset.y()); | 335 canvas->translate(first_offset.x(), first_offset.y()); |
333 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); | 336 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); |
334 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 337 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
335 auto* item1 = list->CreateAndAppendItem<DrawingDisplayItem>(); | 338 auto* item1 = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); |
336 item1->SetNew(picture.Pass()); | 339 item1->SetNew(picture.Pass()); |
337 | 340 |
338 gfx::Rect clip_rect(60, 60, 10, 10); | 341 gfx::Rect clip_rect(60, 60, 10, 10); |
339 auto* item2 = list->CreateAndAppendItem<ClipDisplayItem>(); | 342 auto* item2 = list->CreateAndAppendItem<ClipDisplayItem>(kVisualRect); |
340 item2->SetNew(clip_rect, std::vector<SkRRect>()); | 343 item2->SetNew(clip_rect, std::vector<SkRRect>()); |
341 | 344 |
342 gfx::PointF second_offset(2.f, 3.f); | 345 gfx::PointF second_offset(2.f, 3.f); |
343 gfx::RectF second_recording_rect(second_offset, | 346 gfx::RectF second_recording_rect(second_offset, |
344 gfx::SizeF(layer_rect.size())); | 347 gfx::SizeF(layer_rect.size())); |
345 canvas = skia::SharePtr( | 348 canvas = skia::SharePtr( |
346 recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect))); | 349 recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect))); |
347 canvas->translate(second_offset.x(), second_offset.y()); | 350 canvas->translate(second_offset.x(), second_offset.y()); |
348 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); | 351 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); |
349 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 352 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
350 auto* item3 = list->CreateAndAppendItem<DrawingDisplayItem>(); | 353 auto* item3 = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); |
351 item3->SetNew(picture.Pass()); | 354 item3->SetNew(picture.Pass()); |
352 | 355 |
353 list->CreateAndAppendItem<EndClipDisplayItem>(); | 356 list->CreateAndAppendItem<EndClipDisplayItem>(kVisualRect); |
354 list->Finalize(); | 357 list->Finalize(); |
355 | 358 |
356 DrawDisplayList(pixels, layer_rect, list); | 359 DrawDisplayList(pixels, layer_rect, list); |
357 | 360 |
358 SkBitmap expected_bitmap; | 361 SkBitmap expected_bitmap; |
359 unsigned char expected_pixels[4 * 100 * 100] = {0}; | 362 unsigned char expected_pixels[4 * 100 * 100] = {0}; |
360 SkImageInfo info = | 363 SkImageInfo info = |
361 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); | 364 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); |
362 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); | 365 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); |
363 SkCanvas expected_canvas(expected_bitmap); | 366 SkCanvas expected_canvas(expected_bitmap); |
(...skipping 24 matching lines...) Expand all Loading... | |
388 scoped_refptr<DisplayItemList> list = | 391 scoped_refptr<DisplayItemList> list = |
389 DisplayItemList::Create(layer_rect, settings); | 392 DisplayItemList::Create(layer_rect, settings); |
390 | 393 |
391 gfx::PointF first_offset(8.f, 9.f); | 394 gfx::PointF first_offset(8.f, 9.f); |
392 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); | 395 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); |
393 canvas = skia::SharePtr( | 396 canvas = skia::SharePtr( |
394 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect))); | 397 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect))); |
395 canvas->translate(first_offset.x(), first_offset.y()); | 398 canvas->translate(first_offset.x(), first_offset.y()); |
396 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); | 399 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); |
397 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 400 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
398 auto* item1 = list->CreateAndAppendItem<DrawingDisplayItem>(); | 401 auto* item1 = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); |
399 item1->SetNew(picture); | 402 item1->SetNew(picture); |
400 | 403 |
401 gfx::Transform transform; | 404 gfx::Transform transform; |
402 transform.Rotate(45.0); | 405 transform.Rotate(45.0); |
403 auto* item2 = list->CreateAndAppendItem<TransformDisplayItem>(); | 406 auto* item2 = list->CreateAndAppendItem<TransformDisplayItem>(kVisualRect); |
404 item2->SetNew(transform); | 407 item2->SetNew(transform); |
405 | 408 |
406 gfx::PointF second_offset(2.f, 3.f); | 409 gfx::PointF second_offset(2.f, 3.f); |
407 gfx::RectF second_recording_rect(second_offset, | 410 gfx::RectF second_recording_rect(second_offset, |
408 gfx::SizeF(layer_rect.size())); | 411 gfx::SizeF(layer_rect.size())); |
409 canvas = skia::SharePtr( | 412 canvas = skia::SharePtr( |
410 recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect))); | 413 recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect))); |
411 canvas->translate(second_offset.x(), second_offset.y()); | 414 canvas->translate(second_offset.x(), second_offset.y()); |
412 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); | 415 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); |
413 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 416 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
414 auto* item3 = list->CreateAndAppendItem<DrawingDisplayItem>(); | 417 auto* item3 = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); |
415 item3->SetNew(picture); | 418 item3->SetNew(picture); |
416 | 419 |
417 list->CreateAndAppendItem<EndTransformDisplayItem>(); | 420 list->CreateAndAppendItem<EndTransformDisplayItem>(kVisualRect); |
418 list->Finalize(); | 421 list->Finalize(); |
419 | 422 |
420 DrawDisplayList(pixels, layer_rect, list); | 423 DrawDisplayList(pixels, layer_rect, list); |
421 | 424 |
422 SkBitmap expected_bitmap; | 425 SkBitmap expected_bitmap; |
423 unsigned char expected_pixels[4 * 100 * 100] = {0}; | 426 unsigned char expected_pixels[4 * 100 * 100] = {0}; |
424 SkImageInfo info = | 427 SkImageInfo info = |
425 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); | 428 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); |
426 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); | 429 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); |
427 SkCanvas expected_canvas(expected_bitmap); | 430 SkCanvas expected_canvas(expected_bitmap); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
462 // translating |dst| after it is computed by computeFastBounds, rather than | 465 // translating |dst| after it is computed by computeFastBounds, rather than |
463 // translating |src| before it provided to computedFastBounds) can cause | 466 // translating |src| before it provided to computedFastBounds) can cause |
464 // incorrect clipping of filter output. To test for this, we include an | 467 // incorrect clipping of filter output. To test for this, we include an |
465 // SkImageSource filter in |filters|. Here, |src| is |filter_bounds|, defined | 468 // SkImageSource filter in |filters|. Here, |src| is |filter_bounds|, defined |
466 // below. | 469 // below. |
467 skia::RefPtr<SkImageFilter> image_filter = | 470 skia::RefPtr<SkImageFilter> image_filter = |
468 skia::AdoptRef(SkImageSource::Create(source_image.get())); | 471 skia::AdoptRef(SkImageSource::Create(source_image.get())); |
469 filters.Append(FilterOperation::CreateReferenceFilter(image_filter)); | 472 filters.Append(FilterOperation::CreateReferenceFilter(image_filter)); |
470 filters.Append(FilterOperation::CreateBrightnessFilter(0.5f)); | 473 filters.Append(FilterOperation::CreateBrightnessFilter(0.5f)); |
471 gfx::RectF filter_bounds(10.f, 10.f, 50.f, 50.f); | 474 gfx::RectF filter_bounds(10.f, 10.f, 50.f, 50.f); |
472 auto* item = list->CreateAndAppendItem<FilterDisplayItem>(); | 475 auto* item = list->CreateAndAppendItem<FilterDisplayItem>(kVisualRect); |
473 item->SetNew(filters, filter_bounds); | 476 item->SetNew(filters, filter_bounds); |
474 list->CreateAndAppendItem<EndFilterDisplayItem>(); | 477 list->CreateAndAppendItem<EndFilterDisplayItem>(kVisualRect); |
475 list->Finalize(); | 478 list->Finalize(); |
476 | 479 |
477 DrawDisplayList(pixels, layer_rect, list); | 480 DrawDisplayList(pixels, layer_rect, list); |
478 | 481 |
479 SkBitmap expected_bitmap; | 482 SkBitmap expected_bitmap; |
480 unsigned char expected_pixels[4 * 100 * 100] = {0}; | 483 unsigned char expected_pixels[4 * 100 * 100] = {0}; |
481 SkPaint paint; | 484 SkPaint paint; |
482 paint.setColor(SkColorSetRGB(64, 64, 64)); | 485 paint.setColor(SkColorSetRGB(64, 64, 64)); |
483 SkImageInfo info = | 486 SkImageInfo info = |
484 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); | 487 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); |
(...skipping 22 matching lines...) Expand all Loading... | |
507 no_caching_settings.use_cached_picture = false; | 510 no_caching_settings.use_cached_picture = false; |
508 scoped_refptr<DisplayItemList> list_without_caching = | 511 scoped_refptr<DisplayItemList> list_without_caching = |
509 DisplayItemList::Create(layer_rect, no_caching_settings); | 512 DisplayItemList::Create(layer_rect, no_caching_settings); |
510 | 513 |
511 canvas = skia::SharePtr( | 514 canvas = skia::SharePtr( |
512 recorder.beginRecording(gfx::RectFToSkRect(recording_rect))); | 515 recorder.beginRecording(gfx::RectFToSkRect(recording_rect))); |
513 canvas->translate(offset.x(), offset.y()); | 516 canvas->translate(offset.x(), offset.y()); |
514 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); | 517 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); |
515 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); | 518 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); |
516 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 519 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
517 auto* item1 = list_without_caching->CreateAndAppendItem<DrawingDisplayItem>(); | 520 auto* item1 = list_without_caching->CreateAndAppendItem<DrawingDisplayItem>( |
521 kVisualRect); | |
518 item1->SetNew(picture); | 522 item1->SetNew(picture); |
519 list_without_caching->Finalize(); | 523 list_without_caching->Finalize(); |
520 DrawDisplayList(pixels, layer_rect, list_without_caching); | 524 DrawDisplayList(pixels, layer_rect, list_without_caching); |
521 | 525 |
522 unsigned char expected_pixels[4 * 100 * 100] = {0}; | 526 unsigned char expected_pixels[4 * 100 * 100] = {0}; |
523 DisplayItemListSettings caching_settings; | 527 DisplayItemListSettings caching_settings; |
524 caching_settings.use_cached_picture = true; | 528 caching_settings.use_cached_picture = true; |
525 scoped_refptr<DisplayItemList> list_with_caching = | 529 scoped_refptr<DisplayItemList> list_with_caching = |
526 DisplayItemList::Create(layer_rect, caching_settings); | 530 DisplayItemList::Create(layer_rect, caching_settings); |
527 auto* item2 = list_with_caching->CreateAndAppendItem<DrawingDisplayItem>(); | 531 auto* item2 = |
532 list_with_caching->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); | |
528 item2->SetNew(picture); | 533 item2->SetNew(picture); |
529 list_with_caching->Finalize(); | 534 list_with_caching->Finalize(); |
530 DrawDisplayList(expected_pixels, layer_rect, list_with_caching); | 535 DrawDisplayList(expected_pixels, layer_rect, list_with_caching); |
531 | 536 |
532 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); | 537 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); |
533 } | 538 } |
534 | 539 |
535 TEST(DisplayItemListTest, IsSuitableForGpuRasterizationWithCachedPicture) { | 540 TEST(DisplayItemListTest, IsSuitableForGpuRasterizationWithCachedPicture) { |
536 gfx::Rect layer_rect(1000, 1000); | 541 gfx::Rect layer_rect(1000, 1000); |
537 SkPictureRecorder recorder; | 542 SkPictureRecorder recorder; |
(...skipping 13 matching lines...) Expand all Loading... | |
551 path.lineTo(50, 50); | 556 path.lineTo(50, 50); |
552 path.lineTo(100, 100); | 557 path.lineTo(100, 100); |
553 path.lineTo(100, 0); | 558 path.lineTo(100, 0); |
554 path.close(); | 559 path.close(); |
555 | 560 |
556 SkPaint paint; | 561 SkPaint paint; |
557 paint.setAntiAlias(true); | 562 paint.setAntiAlias(true); |
558 canvas->drawPath(path, paint); | 563 canvas->drawPath(path, paint); |
559 | 564 |
560 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 565 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
561 DrawingDisplayItem* item = list->CreateAndAppendItem<DrawingDisplayItem>(); | 566 DrawingDisplayItem* item = |
567 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); | |
562 item->SetNew(picture); | 568 item->SetNew(picture); |
563 list->Finalize(); | 569 list->Finalize(); |
564 | 570 |
565 // A single DrawingDisplayItem with a large AA concave path shouldn't trigger | 571 // A single DrawingDisplayItem with a large AA concave path shouldn't trigger |
566 // a veto. | 572 // a veto. |
567 EXPECT_TRUE(list->IsSuitableForGpuRasterization()); | 573 EXPECT_TRUE(list->IsSuitableForGpuRasterization()); |
568 | 574 |
569 list = DisplayItemList::Create(layer_rect, settings); | 575 list = DisplayItemList::Create(layer_rect, settings); |
570 canvas = | 576 canvas = |
571 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); | 577 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); |
572 for (int i = 0; i < 10; ++i) | 578 for (int i = 0; i < 10; ++i) |
573 canvas->drawPath(path, paint); | 579 canvas->drawPath(path, paint); |
574 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 580 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
575 item = list->CreateAndAppendItem<DrawingDisplayItem>(); | 581 item = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); |
576 item->SetNew(picture); | 582 item->SetNew(picture); |
577 list->Finalize(); | 583 list->Finalize(); |
578 | 584 |
579 // A single DrawingDisplayItem with several large AA concave paths should | 585 // A single DrawingDisplayItem with several large AA concave paths should |
580 // trigger a veto. | 586 // trigger a veto. |
581 EXPECT_FALSE(list->IsSuitableForGpuRasterization()); | 587 EXPECT_FALSE(list->IsSuitableForGpuRasterization()); |
582 | 588 |
583 list = DisplayItemList::Create(layer_rect, settings); | 589 list = DisplayItemList::Create(layer_rect, settings); |
584 for (int i = 0; i < 10; ++i) { | 590 for (int i = 0; i < 10; ++i) { |
585 canvas = | 591 canvas = |
586 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); | 592 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); |
587 canvas->drawPath(path, paint); | 593 canvas->drawPath(path, paint); |
588 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 594 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
589 item = list->CreateAndAppendItem<DrawingDisplayItem>(); | 595 item = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); |
590 item->SetNew(picture); | 596 item->SetNew(picture); |
591 } | 597 } |
592 list->Finalize(); | 598 list->Finalize(); |
593 | 599 |
594 // Having several DrawingDisplayItems that each contain a large AA concave | 600 // Having several DrawingDisplayItems that each contain a large AA concave |
595 // path should trigger a veto. | 601 // path should trigger a veto. |
596 EXPECT_FALSE(list->IsSuitableForGpuRasterization()); | 602 EXPECT_FALSE(list->IsSuitableForGpuRasterization()); |
597 } | 603 } |
598 | 604 |
599 TEST(DisplayItemListTest, IsSuitableForGpuRasterizationWithoutCachedPicture) { | 605 TEST(DisplayItemListTest, IsSuitableForGpuRasterizationWithoutCachedPicture) { |
(...skipping 15 matching lines...) Expand all Loading... | |
615 path.lineTo(50, 50); | 621 path.lineTo(50, 50); |
616 path.lineTo(100, 100); | 622 path.lineTo(100, 100); |
617 path.lineTo(100, 0); | 623 path.lineTo(100, 0); |
618 path.close(); | 624 path.close(); |
619 | 625 |
620 SkPaint paint; | 626 SkPaint paint; |
621 paint.setAntiAlias(true); | 627 paint.setAntiAlias(true); |
622 canvas->drawPath(path, paint); | 628 canvas->drawPath(path, paint); |
623 | 629 |
624 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 630 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
625 DrawingDisplayItem* item = list->CreateAndAppendItem<DrawingDisplayItem>(); | 631 DrawingDisplayItem* item = |
632 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); | |
626 item->SetNew(picture); | 633 item->SetNew(picture); |
627 list->Finalize(); | 634 list->Finalize(); |
628 | 635 |
629 // A single DrawingDisplayItem with a large AA concave path shouldn't trigger | 636 // A single DrawingDisplayItem with a large AA concave path shouldn't trigger |
630 // a veto. | 637 // a veto. |
631 EXPECT_TRUE(list->IsSuitableForGpuRasterization()); | 638 EXPECT_TRUE(list->IsSuitableForGpuRasterization()); |
632 | 639 |
633 list = DisplayItemList::Create(layer_rect, settings); | 640 list = DisplayItemList::Create(layer_rect, settings); |
634 canvas = | 641 canvas = |
635 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); | 642 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); |
636 for (int i = 0; i < 10; ++i) | 643 for (int i = 0; i < 10; ++i) |
637 canvas->drawPath(path, paint); | 644 canvas->drawPath(path, paint); |
638 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 645 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
639 item = list->CreateAndAppendItem<DrawingDisplayItem>(); | 646 item = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); |
640 item->SetNew(picture); | 647 item->SetNew(picture); |
641 list->Finalize(); | 648 list->Finalize(); |
642 | 649 |
643 // A single DrawingDisplayItem with several large AA concave paths should | 650 // A single DrawingDisplayItem with several large AA concave paths should |
644 // trigger a veto. | 651 // trigger a veto. |
645 EXPECT_FALSE(list->IsSuitableForGpuRasterization()); | 652 EXPECT_FALSE(list->IsSuitableForGpuRasterization()); |
646 | 653 |
647 list = DisplayItemList::Create(layer_rect, settings); | 654 list = DisplayItemList::Create(layer_rect, settings); |
648 for (int i = 0; i < 10; ++i) { | 655 for (int i = 0; i < 10; ++i) { |
649 canvas = | 656 canvas = |
650 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); | 657 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); |
651 canvas->drawPath(path, paint); | 658 canvas->drawPath(path, paint); |
652 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 659 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
653 item = list->CreateAndAppendItem<DrawingDisplayItem>(); | 660 item = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); |
654 item->SetNew(picture); | 661 item->SetNew(picture); |
655 } | 662 } |
656 list->Finalize(); | 663 list->Finalize(); |
657 | 664 |
658 // Without a cached picture, having several DrawingDisplayItems that each | 665 // Without a cached picture, having several DrawingDisplayItems that each |
659 // contain a single large AA concave will not trigger a veto, since each item | 666 // contain a single large AA concave will not trigger a veto, since each item |
660 // is individually suitable for GPU rasterization. | 667 // is individually suitable for GPU rasterization. |
661 EXPECT_TRUE(list->IsSuitableForGpuRasterization()); | 668 EXPECT_TRUE(list->IsSuitableForGpuRasterization()); |
662 } | 669 } |
663 | 670 |
(...skipping 12 matching lines...) Expand all Loading... | |
676 canvas->drawPaint(blue_paint); | 683 canvas->drawPaint(blue_paint); |
677 skia::RefPtr<SkPicture> picture = | 684 skia::RefPtr<SkPicture> picture = |
678 skia::AdoptRef(recorder.endRecordingAsPicture()); | 685 skia::AdoptRef(recorder.endRecordingAsPicture()); |
679 size_t picture_size = SkPictureUtils::ApproximateBytesUsed(picture.get()); | 686 size_t picture_size = SkPictureUtils::ApproximateBytesUsed(picture.get()); |
680 ASSERT_GE(picture_size, kNumCommandsInTestSkPicture * sizeof(blue_paint)); | 687 ASSERT_GE(picture_size, kNumCommandsInTestSkPicture * sizeof(blue_paint)); |
681 | 688 |
682 // Using a cached picture, we should get about the right size. | 689 // Using a cached picture, we should get about the right size. |
683 DisplayItemListSettings caching_settings; | 690 DisplayItemListSettings caching_settings; |
684 caching_settings.use_cached_picture = true; | 691 caching_settings.use_cached_picture = true; |
685 list = DisplayItemList::Create(layer_rect, caching_settings); | 692 list = DisplayItemList::Create(layer_rect, caching_settings); |
686 auto* item = list->CreateAndAppendItem<DrawingDisplayItem>(); | 693 auto* item = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); |
687 item->SetNew(picture); | 694 item->SetNew(picture); |
688 list->Finalize(); | 695 list->Finalize(); |
689 memory_usage = list->ApproximateMemoryUsage(); | 696 memory_usage = list->ApproximateMemoryUsage(); |
690 EXPECT_GE(memory_usage, picture_size); | 697 EXPECT_GE(memory_usage, picture_size); |
691 EXPECT_LE(memory_usage, 2 * picture_size); | 698 EXPECT_LE(memory_usage, 2 * picture_size); |
692 | 699 |
693 // Using no cached picture, we should still get the right size. | 700 // Using no cached picture, we should still get the right size. |
694 DisplayItemListSettings no_caching_settings; | 701 DisplayItemListSettings no_caching_settings; |
695 no_caching_settings.use_cached_picture = false; | 702 no_caching_settings.use_cached_picture = false; |
696 list = DisplayItemList::Create(layer_rect, no_caching_settings); | 703 list = DisplayItemList::Create(layer_rect, no_caching_settings); |
697 item = list->CreateAndAppendItem<DrawingDisplayItem>(); | 704 item = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); |
698 item->SetNew(picture); | 705 item->SetNew(picture); |
699 list->Finalize(); | 706 list->Finalize(); |
700 memory_usage = list->ApproximateMemoryUsage(); | 707 memory_usage = list->ApproximateMemoryUsage(); |
701 EXPECT_GE(memory_usage, picture_size); | 708 EXPECT_GE(memory_usage, picture_size); |
702 EXPECT_LE(memory_usage, 2 * picture_size); | 709 EXPECT_LE(memory_usage, 2 * picture_size); |
703 | 710 |
704 // To avoid double counting, we expect zero size to be computed if both the | 711 // To avoid double counting, we expect zero size to be computed if both the |
705 // picture and items are retained (currently this only happens due to certain | 712 // picture and items are retained (currently this only happens due to certain |
706 // categories being traced). | 713 // categories being traced). |
707 list = new DisplayItemList(layer_rect, caching_settings, true); | 714 list = new DisplayItemList(layer_rect, caching_settings, true); |
708 item = list->CreateAndAppendItem<DrawingDisplayItem>(); | 715 item = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); |
709 item->SetNew(picture); | 716 item->SetNew(picture); |
710 list->Finalize(); | 717 list->Finalize(); |
711 memory_usage = list->ApproximateMemoryUsage(); | 718 memory_usage = list->ApproximateMemoryUsage(); |
712 EXPECT_EQ(static_cast<size_t>(0), memory_usage); | 719 EXPECT_EQ(static_cast<size_t>(0), memory_usage); |
713 } | 720 } |
714 | 721 |
715 } // namespace cc | 722 } // namespace cc |
OLD | NEW |