Chromium Code Reviews| 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 25 matching lines...) Expand all Loading... | |
| 36 | 36 |
| 37 namespace { | 37 namespace { |
| 38 | 38 |
| 39 const gfx::Rect kVisualRect(0, 0, 42, 42); | 39 const gfx::Rect kVisualRect(0, 0, 42, 42); |
| 40 | 40 |
| 41 void AppendFirstSerializationTestPicture(scoped_refptr<DisplayItemList> list, | 41 void AppendFirstSerializationTestPicture(scoped_refptr<DisplayItemList> list, |
| 42 const gfx::Size& layer_size) { | 42 const gfx::Size& layer_size) { |
| 43 gfx::PointF offset(2.f, 3.f); | 43 gfx::PointF offset(2.f, 3.f); |
| 44 SkPictureRecorder recorder; | 44 SkPictureRecorder recorder; |
| 45 skia::RefPtr<SkCanvas> canvas; | 45 skia::RefPtr<SkCanvas> canvas; |
| 46 skia::RefPtr<SkPicture> picture; | |
| 47 | 46 |
| 48 SkPaint red_paint; | 47 SkPaint red_paint; |
| 49 red_paint.setColor(SK_ColorRED); | 48 red_paint.setColor(SK_ColorRED); |
| 50 | 49 |
| 51 canvas = skia::SharePtr(recorder.beginRecording(SkRect::MakeXYWH( | 50 canvas = skia::SharePtr(recorder.beginRecording(SkRect::MakeXYWH( |
| 52 offset.x(), offset.y(), layer_size.width(), layer_size.height()))); | 51 offset.x(), offset.y(), layer_size.width(), layer_size.height()))); |
| 53 canvas->translate(offset.x(), offset.y()); | 52 canvas->translate(offset.x(), offset.y()); |
| 54 canvas->drawRectCoords(0.f, 0.f, 4.f, 4.f, red_paint); | 53 canvas->drawRectCoords(0.f, 0.f, 4.f, 4.f, red_paint); |
| 55 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 54 list->CreateAndAppendItem<DrawingDisplayItem>( |
| 56 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect)->SetNew(picture); | 55 kVisualRect, skia::AdoptRef(recorder.endRecordingAsPicture())); |
| 57 } | 56 } |
| 58 | 57 |
| 59 void AppendSecondSerializationTestPicture(scoped_refptr<DisplayItemList> list, | 58 void AppendSecondSerializationTestPicture(scoped_refptr<DisplayItemList> list, |
| 60 const gfx::Size& layer_size) { | 59 const gfx::Size& layer_size) { |
| 61 gfx::PointF offset(2.f, 2.f); | 60 gfx::PointF offset(2.f, 2.f); |
| 62 SkPictureRecorder recorder; | 61 SkPictureRecorder recorder; |
| 63 skia::RefPtr<SkCanvas> canvas; | 62 skia::RefPtr<SkCanvas> canvas; |
| 64 skia::RefPtr<SkPicture> picture; | |
| 65 | 63 |
| 66 SkPaint blue_paint; | 64 SkPaint blue_paint; |
| 67 blue_paint.setColor(SK_ColorBLUE); | 65 blue_paint.setColor(SK_ColorBLUE); |
| 68 | 66 |
| 69 canvas = skia::SharePtr(recorder.beginRecording(SkRect::MakeXYWH( | 67 canvas = skia::SharePtr(recorder.beginRecording(SkRect::MakeXYWH( |
| 70 offset.x(), offset.y(), layer_size.width(), layer_size.height()))); | 68 offset.x(), offset.y(), layer_size.width(), layer_size.height()))); |
| 71 canvas->translate(offset.x(), offset.y()); | 69 canvas->translate(offset.x(), offset.y()); |
| 72 canvas->drawRectCoords(3.f, 3.f, 7.f, 7.f, blue_paint); | 70 canvas->drawRectCoords(3.f, 3.f, 7.f, 7.f, blue_paint); |
| 73 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 71 list->CreateAndAppendItem<DrawingDisplayItem>( |
| 74 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect)->SetNew(picture); | 72 kVisualRect, skia::AdoptRef(recorder.endRecordingAsPicture())); |
| 75 } | 73 } |
| 76 | 74 |
| 77 void ValidateDisplayItemListSerialization(const gfx::Size& layer_size, | 75 void ValidateDisplayItemListSerialization(const gfx::Size& layer_size, |
| 78 scoped_refptr<DisplayItemList> list) { | 76 scoped_refptr<DisplayItemList> list) { |
| 79 list->Finalize(); | 77 list->Finalize(); |
| 80 | 78 |
| 81 // Serialize and deserialize the DisplayItemList. | 79 // Serialize and deserialize the DisplayItemList. |
| 82 proto::DisplayItemList proto; | 80 proto::DisplayItemList proto; |
| 83 list->ToProtobuf(&proto); | 81 list->ToProtobuf(&proto); |
| 84 scoped_refptr<DisplayItemList> new_list = | 82 scoped_refptr<DisplayItemList> new_list = |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 scoped_refptr<DisplayItemList> list = | 142 scoped_refptr<DisplayItemList> list = |
| 145 DisplayItemList::Create(gfx::Rect(layer_size), settings); | 143 DisplayItemList::Create(gfx::Rect(layer_size), settings); |
| 146 | 144 |
| 147 // Build the DrawingDisplayItem. | 145 // Build the DrawingDisplayItem. |
| 148 AppendFirstSerializationTestPicture(list, layer_size); | 146 AppendFirstSerializationTestPicture(list, layer_size); |
| 149 | 147 |
| 150 // Build the ClipDisplayItem. | 148 // Build the ClipDisplayItem. |
| 151 gfx::Rect clip_rect(6, 6, 1, 1); | 149 gfx::Rect clip_rect(6, 6, 1, 1); |
| 152 std::vector<SkRRect> rrects; | 150 std::vector<SkRRect> rrects; |
| 153 rrects.push_back(SkRRect::MakeOval(SkRect::MakeXYWH(5.f, 5.f, 4.f, 4.f))); | 151 rrects.push_back(SkRRect::MakeOval(SkRect::MakeXYWH(5.f, 5.f, 4.f, 4.f))); |
| 154 auto* item = list->CreateAndAppendItem<ClipDisplayItem>(kVisualRect); | 152 list->CreateAndAppendItem<ClipDisplayItem>(kVisualRect, clip_rect, rrects); |
| 155 item->SetNew(clip_rect, rrects); | |
| 156 | 153 |
| 157 // Build the second DrawingDisplayItem. | 154 // Build the second DrawingDisplayItem. |
| 158 AppendSecondSerializationTestPicture(list, layer_size); | 155 AppendSecondSerializationTestPicture(list, layer_size); |
| 159 | 156 |
| 160 // Build the EndClipDisplayItem. | 157 // Build the EndClipDisplayItem. |
| 161 list->CreateAndAppendItem<EndClipDisplayItem>(kVisualRect); | 158 list->CreateAndAppendItem<EndClipDisplayItem>(kVisualRect); |
| 162 | 159 |
| 163 ValidateDisplayItemListSerialization(layer_size, list); | 160 ValidateDisplayItemListSerialization(layer_size, list); |
| 164 } | 161 } |
| 165 | 162 |
| 166 TEST(DisplayItemListTest, SerializeClipPathItem) { | 163 TEST(DisplayItemListTest, SerializeClipPathItem) { |
| 167 gfx::Size layer_size(10, 10); | 164 gfx::Size layer_size(10, 10); |
| 168 | 165 |
| 169 DisplayItemListSettings settings; | 166 DisplayItemListSettings settings; |
| 170 scoped_refptr<DisplayItemList> list = | 167 scoped_refptr<DisplayItemList> list = |
| 171 DisplayItemList::Create(gfx::Rect(layer_size), settings); | 168 DisplayItemList::Create(gfx::Rect(layer_size), settings); |
| 172 | 169 |
| 173 // Build the DrawingDisplayItem. | 170 // Build the DrawingDisplayItem. |
| 174 AppendFirstSerializationTestPicture(list, layer_size); | 171 AppendFirstSerializationTestPicture(list, layer_size); |
| 175 | 172 |
| 176 // Build the ClipPathDisplayItem. | 173 // Build the ClipPathDisplayItem. |
| 177 SkPath path; | 174 SkPath path; |
| 178 path.addCircle(5.f, 5.f, 2.f, SkPath::Direction::kCW_Direction); | 175 path.addCircle(5.f, 5.f, 2.f, SkPath::Direction::kCW_Direction); |
| 179 auto* item = list->CreateAndAppendItem<ClipPathDisplayItem>(kVisualRect); | 176 list->CreateAndAppendItem<ClipPathDisplayItem>( |
| 180 item->SetNew(path, SkRegion::Op::kReplace_Op, false); | 177 kVisualRect, path, SkRegion::Op::kReplace_Op, false); |
| 181 | 178 |
| 182 // Build the second DrawingDisplayItem. | 179 // Build the second DrawingDisplayItem. |
| 183 AppendSecondSerializationTestPicture(list, layer_size); | 180 AppendSecondSerializationTestPicture(list, layer_size); |
| 184 | 181 |
| 185 // Build the EndClipPathDisplayItem. | 182 // Build the EndClipPathDisplayItem. |
| 186 list->CreateAndAppendItem<EndClipPathDisplayItem>(kVisualRect); | 183 list->CreateAndAppendItem<EndClipPathDisplayItem>(kVisualRect); |
| 187 | 184 |
| 188 ValidateDisplayItemListSerialization(layer_size, list); | 185 ValidateDisplayItemListSerialization(layer_size, list); |
| 189 } | 186 } |
| 190 | 187 |
| 191 TEST(DisplayItemListTest, SerializeCompositingItem) { | 188 TEST(DisplayItemListTest, SerializeCompositingItem) { |
| 192 gfx::Size layer_size(10, 10); | 189 gfx::Size layer_size(10, 10); |
| 193 | 190 |
| 194 DisplayItemListSettings settings; | 191 DisplayItemListSettings settings; |
| 195 scoped_refptr<DisplayItemList> list = | 192 scoped_refptr<DisplayItemList> list = |
| 196 DisplayItemList::Create(gfx::Rect(layer_size), settings); | 193 DisplayItemList::Create(gfx::Rect(layer_size), settings); |
| 197 | 194 |
| 198 // Build the DrawingDisplayItem. | 195 // Build the DrawingDisplayItem. |
| 199 AppendFirstSerializationTestPicture(list, layer_size); | 196 AppendFirstSerializationTestPicture(list, layer_size); |
| 200 | 197 |
| 201 // Build the CompositingDisplayItem. | 198 // Build the CompositingDisplayItem. |
| 202 skia::RefPtr<SkColorFilter> filter = skia::AdoptRef( | 199 skia::RefPtr<SkColorFilter> filter = skia::AdoptRef( |
| 203 SkColorFilter::CreateLightingFilter(SK_ColorRED, SK_ColorGREEN)); | 200 SkColorFilter::CreateLightingFilter(SK_ColorRED, SK_ColorGREEN)); |
| 204 auto* item = list->CreateAndAppendItem<CompositingDisplayItem>(kVisualRect); | 201 list->CreateAndAppendItem<CompositingDisplayItem>( |
| 205 item->SetNew(150, SkXfermode::Mode::kDst_Mode, nullptr, filter); | 202 kVisualRect, 150, SkXfermode::Mode::kDst_Mode, nullptr, filter); |
| 206 | 203 |
| 207 // Build the second DrawingDisplayItem. | 204 // Build the second DrawingDisplayItem. |
| 208 AppendSecondSerializationTestPicture(list, layer_size); | 205 AppendSecondSerializationTestPicture(list, layer_size); |
| 209 | 206 |
| 210 // Build the EndCompositingDisplayItem. | 207 // Build the EndCompositingDisplayItem. |
| 211 list->CreateAndAppendItem<EndCompositingDisplayItem>(kVisualRect); | 208 list->CreateAndAppendItem<EndCompositingDisplayItem>(kVisualRect); |
| 212 | 209 |
| 213 ValidateDisplayItemListSerialization(layer_size, list); | 210 ValidateDisplayItemListSerialization(layer_size, list); |
| 214 } | 211 } |
| 215 | 212 |
| 216 TEST(DisplayItemListTest, SerializeFloatClipItem) { | 213 TEST(DisplayItemListTest, SerializeFloatClipItem) { |
| 217 gfx::Size layer_size(10, 10); | 214 gfx::Size layer_size(10, 10); |
| 218 | 215 |
| 219 DisplayItemListSettings settings; | 216 DisplayItemListSettings settings; |
| 220 scoped_refptr<DisplayItemList> list = | 217 scoped_refptr<DisplayItemList> list = |
| 221 DisplayItemList::Create(gfx::Rect(layer_size), settings); | 218 DisplayItemList::Create(gfx::Rect(layer_size), settings); |
| 222 | 219 |
| 223 // Build the DrawingDisplayItem. | 220 // Build the DrawingDisplayItem. |
| 224 AppendFirstSerializationTestPicture(list, layer_size); | 221 AppendFirstSerializationTestPicture(list, layer_size); |
| 225 | 222 |
| 226 // Build the FloatClipDisplayItem. | 223 // Build the FloatClipDisplayItem. |
| 227 gfx::RectF clip_rect(6.f, 6.f, 1.f, 1.f); | 224 gfx::RectF clip_rect(6.f, 6.f, 1.f, 1.f); |
| 228 auto* item2 = list->CreateAndAppendItem<FloatClipDisplayItem>(kVisualRect); | 225 list->CreateAndAppendItem<FloatClipDisplayItem>(kVisualRect, clip_rect); |
| 229 item2->SetNew(clip_rect); | |
| 230 | 226 |
| 231 // Build the second DrawingDisplayItem. | 227 // Build the second DrawingDisplayItem. |
| 232 AppendSecondSerializationTestPicture(list, layer_size); | 228 AppendSecondSerializationTestPicture(list, layer_size); |
| 233 | 229 |
| 234 // Build the EndFloatClipDisplayItem. | 230 // Build the EndFloatClipDisplayItem. |
| 235 list->CreateAndAppendItem<EndFloatClipDisplayItem>(kVisualRect); | 231 list->CreateAndAppendItem<EndFloatClipDisplayItem>(kVisualRect); |
| 236 | 232 |
| 237 ValidateDisplayItemListSerialization(layer_size, list); | 233 ValidateDisplayItemListSerialization(layer_size, list); |
| 238 } | 234 } |
| 239 | 235 |
| 240 TEST(DisplayItemListTest, SerializeTransformItem) { | 236 TEST(DisplayItemListTest, SerializeTransformItem) { |
| 241 gfx::Size layer_size(10, 10); | 237 gfx::Size layer_size(10, 10); |
| 242 | 238 |
| 243 DisplayItemListSettings settings; | 239 DisplayItemListSettings settings; |
| 244 scoped_refptr<DisplayItemList> list = | 240 scoped_refptr<DisplayItemList> list = |
| 245 DisplayItemList::Create(gfx::Rect(layer_size), settings); | 241 DisplayItemList::Create(gfx::Rect(layer_size), settings); |
| 246 | 242 |
| 247 // Build the DrawingDisplayItem. | 243 // Build the DrawingDisplayItem. |
| 248 AppendFirstSerializationTestPicture(list, layer_size); | 244 AppendFirstSerializationTestPicture(list, layer_size); |
| 249 | 245 |
| 250 // Build the TransformDisplayItem. | 246 // Build the TransformDisplayItem. |
| 251 gfx::Transform transform; | 247 gfx::Transform transform; |
| 252 transform.Scale(1.25f, 1.25f); | 248 transform.Scale(1.25f, 1.25f); |
| 253 transform.Translate(-1.f, -1.f); | 249 transform.Translate(-1.f, -1.f); |
| 254 auto* item2 = list->CreateAndAppendItem<TransformDisplayItem>(kVisualRect); | 250 list->CreateAndAppendItem<TransformDisplayItem>(kVisualRect, transform); |
| 255 item2->SetNew(transform); | |
| 256 | 251 |
| 257 // Build the second DrawingDisplayItem. | 252 // Build the second DrawingDisplayItem. |
| 258 AppendSecondSerializationTestPicture(list, layer_size); | 253 AppendSecondSerializationTestPicture(list, layer_size); |
| 259 | 254 |
| 260 // Build the EndTransformDisplayItem. | 255 // Build the EndTransformDisplayItem. |
| 261 list->CreateAndAppendItem<EndTransformDisplayItem>(kVisualRect); | 256 list->CreateAndAppendItem<EndTransformDisplayItem>(kVisualRect); |
| 262 | 257 |
| 263 ValidateDisplayItemListSerialization(layer_size, list); | 258 ValidateDisplayItemListSerialization(layer_size, list); |
| 264 } | 259 } |
| 265 | 260 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 278 DisplayItemList::Create(layer_rect, settings); | 273 DisplayItemList::Create(layer_rect, settings); |
| 279 | 274 |
| 280 gfx::PointF offset(8.f, 9.f); | 275 gfx::PointF offset(8.f, 9.f); |
| 281 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); | 276 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); |
| 282 canvas = skia::SharePtr( | 277 canvas = skia::SharePtr( |
| 283 recorder.beginRecording(gfx::RectFToSkRect(recording_rect))); | 278 recorder.beginRecording(gfx::RectFToSkRect(recording_rect))); |
| 284 canvas->translate(offset.x(), offset.y()); | 279 canvas->translate(offset.x(), offset.y()); |
| 285 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); | 280 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); |
| 286 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); | 281 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); |
| 287 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 282 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
| 288 auto* item = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); | 283 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, |
| 289 item->SetNew(picture); | 284 std::move(picture)); |
| 290 list->Finalize(); | 285 list->Finalize(); |
| 291 DrawDisplayList(pixels, layer_rect, list); | 286 DrawDisplayList(pixels, layer_rect, list); |
| 292 | 287 |
| 293 SkBitmap expected_bitmap; | 288 SkBitmap expected_bitmap; |
| 294 unsigned char expected_pixels[4 * 100 * 100] = {0}; | 289 unsigned char expected_pixels[4 * 100 * 100] = {0}; |
| 295 SkImageInfo info = | 290 SkImageInfo info = |
| 296 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); | 291 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); |
| 297 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); | 292 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); |
| 298 SkCanvas expected_canvas(expected_bitmap); | 293 SkCanvas expected_canvas(expected_bitmap); |
| 299 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); | 294 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); |
| 300 expected_canvas.drawRectCoords(0.f + offset.x(), 0.f + offset.y(), | 295 expected_canvas.drawRectCoords(0.f + offset.x(), 0.f + offset.y(), |
| 301 60.f + offset.x(), 60.f + offset.y(), | 296 60.f + offset.x(), 60.f + offset.y(), |
| 302 red_paint); | 297 red_paint); |
| 303 expected_canvas.drawRectCoords(50.f + offset.x(), 50.f + offset.y(), | 298 expected_canvas.drawRectCoords(50.f + offset.x(), 50.f + offset.y(), |
| 304 75.f + offset.x(), 75.f + offset.y(), | 299 75.f + offset.x(), 75.f + offset.y(), |
| 305 blue_paint); | 300 blue_paint); |
| 306 | 301 |
| 307 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); | 302 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); |
| 308 } | 303 } |
| 309 | 304 |
| 310 TEST(DisplayItemListTest, ClipItem) { | 305 TEST(DisplayItemListTest, ClipItem) { |
| 311 gfx::Rect layer_rect(100, 100); | 306 gfx::Rect layer_rect(100, 100); |
| 312 SkPictureRecorder recorder; | 307 SkPictureRecorder recorder; |
| 313 skia::RefPtr<SkCanvas> canvas; | 308 skia::RefPtr<SkCanvas> canvas; |
| 314 skia::RefPtr<SkPicture> picture; | |
| 315 SkPaint blue_paint; | 309 SkPaint blue_paint; |
| 316 blue_paint.setColor(SK_ColorBLUE); | 310 blue_paint.setColor(SK_ColorBLUE); |
| 317 SkPaint red_paint; | 311 SkPaint red_paint; |
| 318 red_paint.setColor(SK_ColorRED); | 312 red_paint.setColor(SK_ColorRED); |
| 319 unsigned char pixels[4 * 100 * 100] = {0}; | 313 unsigned char pixels[4 * 100 * 100] = {0}; |
| 320 DisplayItemListSettings settings; | 314 DisplayItemListSettings settings; |
| 321 settings.use_cached_picture = true; | 315 settings.use_cached_picture = true; |
| 322 scoped_refptr<DisplayItemList> list = | 316 scoped_refptr<DisplayItemList> list = |
| 323 DisplayItemList::Create(layer_rect, settings); | 317 DisplayItemList::Create(layer_rect, settings); |
| 324 | 318 |
| 325 gfx::PointF first_offset(8.f, 9.f); | 319 gfx::PointF first_offset(8.f, 9.f); |
| 326 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); | 320 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); |
| 327 canvas = skia::SharePtr( | 321 canvas = skia::SharePtr( |
| 328 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect))); | 322 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect))); |
| 329 canvas->translate(first_offset.x(), first_offset.y()); | 323 canvas->translate(first_offset.x(), first_offset.y()); |
| 330 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); | 324 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); |
| 331 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 325 list->CreateAndAppendItem<DrawingDisplayItem>( |
| 332 auto* item1 = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); | 326 kVisualRect, skia::AdoptRef(recorder.endRecordingAsPicture())); |
| 333 item1->SetNew(std::move(picture)); | |
| 334 | 327 |
| 335 gfx::Rect clip_rect(60, 60, 10, 10); | 328 gfx::Rect clip_rect(60, 60, 10, 10); |
| 336 auto* item2 = list->CreateAndAppendItem<ClipDisplayItem>(kVisualRect); | 329 list->CreateAndAppendItem<ClipDisplayItem>(kVisualRect, clip_rect, |
| 337 item2->SetNew(clip_rect, std::vector<SkRRect>()); | 330 std::vector<SkRRect>()); |
| 338 | 331 |
| 339 gfx::PointF second_offset(2.f, 3.f); | 332 gfx::PointF second_offset(2.f, 3.f); |
| 340 gfx::RectF second_recording_rect(second_offset, | 333 gfx::RectF second_recording_rect(second_offset, |
| 341 gfx::SizeF(layer_rect.size())); | 334 gfx::SizeF(layer_rect.size())); |
| 342 canvas = skia::SharePtr( | 335 canvas = skia::SharePtr( |
| 343 recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect))); | 336 recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect))); |
| 344 canvas->translate(second_offset.x(), second_offset.y()); | 337 canvas->translate(second_offset.x(), second_offset.y()); |
| 345 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); | 338 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); |
| 346 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 339 list->CreateAndAppendItem<DrawingDisplayItem>( |
| 347 auto* item3 = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); | 340 kVisualRect, skia::AdoptRef(recorder.endRecordingAsPicture())); |
| 348 item3->SetNew(std::move(picture)); | |
| 349 | 341 |
| 350 list->CreateAndAppendItem<EndClipDisplayItem>(kVisualRect); | 342 list->CreateAndAppendItem<EndClipDisplayItem>(kVisualRect); |
| 351 list->Finalize(); | 343 list->Finalize(); |
| 352 | 344 |
| 353 DrawDisplayList(pixels, layer_rect, list); | 345 DrawDisplayList(pixels, layer_rect, list); |
| 354 | 346 |
| 355 SkBitmap expected_bitmap; | 347 SkBitmap expected_bitmap; |
| 356 unsigned char expected_pixels[4 * 100 * 100] = {0}; | 348 unsigned char expected_pixels[4 * 100 * 100] = {0}; |
| 357 SkImageInfo info = | 349 SkImageInfo info = |
| 358 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); | 350 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); |
| 359 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); | 351 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); |
| 360 SkCanvas expected_canvas(expected_bitmap); | 352 SkCanvas expected_canvas(expected_bitmap); |
| 361 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); | 353 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); |
| 362 expected_canvas.drawRectCoords(0.f + first_offset.x(), 0.f + first_offset.y(), | 354 expected_canvas.drawRectCoords(0.f + first_offset.x(), 0.f + first_offset.y(), |
| 363 60.f + first_offset.x(), | 355 60.f + first_offset.x(), |
| 364 60.f + first_offset.y(), red_paint); | 356 60.f + first_offset.y(), red_paint); |
| 365 expected_canvas.clipRect(gfx::RectToSkRect(clip_rect)); | 357 expected_canvas.clipRect(gfx::RectToSkRect(clip_rect)); |
| 366 expected_canvas.drawRectCoords( | 358 expected_canvas.drawRectCoords( |
| 367 50.f + second_offset.x(), 50.f + second_offset.y(), | 359 50.f + second_offset.x(), 50.f + second_offset.y(), |
| 368 75.f + second_offset.x(), 75.f + second_offset.y(), blue_paint); | 360 75.f + second_offset.x(), 75.f + second_offset.y(), blue_paint); |
| 369 | 361 |
| 370 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); | 362 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); |
| 371 } | 363 } |
| 372 | 364 |
| 373 TEST(DisplayItemListTest, TransformItem) { | 365 TEST(DisplayItemListTest, TransformItem) { |
| 374 gfx::Rect layer_rect(100, 100); | 366 gfx::Rect layer_rect(100, 100); |
| 375 SkPictureRecorder recorder; | 367 SkPictureRecorder recorder; |
| 376 skia::RefPtr<SkCanvas> canvas; | 368 skia::RefPtr<SkCanvas> canvas; |
| 377 skia::RefPtr<SkPicture> picture; | |
| 378 SkPaint blue_paint; | 369 SkPaint blue_paint; |
| 379 blue_paint.setColor(SK_ColorBLUE); | 370 blue_paint.setColor(SK_ColorBLUE); |
| 380 SkPaint red_paint; | 371 SkPaint red_paint; |
| 381 red_paint.setColor(SK_ColorRED); | 372 red_paint.setColor(SK_ColorRED); |
| 382 unsigned char pixels[4 * 100 * 100] = {0}; | 373 unsigned char pixels[4 * 100 * 100] = {0}; |
| 383 DisplayItemListSettings settings; | 374 DisplayItemListSettings settings; |
| 384 settings.use_cached_picture = true; | 375 settings.use_cached_picture = true; |
| 385 scoped_refptr<DisplayItemList> list = | 376 scoped_refptr<DisplayItemList> list = |
| 386 DisplayItemList::Create(layer_rect, settings); | 377 DisplayItemList::Create(layer_rect, settings); |
| 387 | 378 |
| 388 gfx::PointF first_offset(8.f, 9.f); | 379 gfx::PointF first_offset(8.f, 9.f); |
| 389 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); | 380 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); |
| 390 canvas = skia::SharePtr( | 381 canvas = skia::SharePtr( |
| 391 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect))); | 382 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect))); |
| 392 canvas->translate(first_offset.x(), first_offset.y()); | 383 canvas->translate(first_offset.x(), first_offset.y()); |
| 393 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); | 384 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); |
| 394 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 385 list->CreateAndAppendItem<DrawingDisplayItem>( |
| 395 auto* item1 = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); | 386 kVisualRect, skia::AdoptRef(recorder.endRecordingAsPicture())); |
| 396 item1->SetNew(picture); | |
| 397 | 387 |
| 398 gfx::Transform transform; | 388 gfx::Transform transform; |
| 399 transform.Rotate(45.0); | 389 transform.Rotate(45.0); |
| 400 auto* item2 = list->CreateAndAppendItem<TransformDisplayItem>(kVisualRect); | 390 list->CreateAndAppendItem<TransformDisplayItem>(kVisualRect, transform); |
| 401 item2->SetNew(transform); | |
| 402 | 391 |
| 403 gfx::PointF second_offset(2.f, 3.f); | 392 gfx::PointF second_offset(2.f, 3.f); |
| 404 gfx::RectF second_recording_rect(second_offset, | 393 gfx::RectF second_recording_rect(second_offset, |
| 405 gfx::SizeF(layer_rect.size())); | 394 gfx::SizeF(layer_rect.size())); |
| 406 canvas = skia::SharePtr( | 395 canvas = skia::SharePtr( |
| 407 recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect))); | 396 recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect))); |
| 408 canvas->translate(second_offset.x(), second_offset.y()); | 397 canvas->translate(second_offset.x(), second_offset.y()); |
| 409 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); | 398 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); |
| 410 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 399 list->CreateAndAppendItem<DrawingDisplayItem>( |
| 411 auto* item3 = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); | 400 kVisualRect, skia::AdoptRef(recorder.endRecordingAsPicture())); |
| 412 item3->SetNew(picture); | |
| 413 | 401 |
| 414 list->CreateAndAppendItem<EndTransformDisplayItem>(kVisualRect); | 402 list->CreateAndAppendItem<EndTransformDisplayItem>(kVisualRect); |
| 415 list->Finalize(); | 403 list->Finalize(); |
| 416 | 404 |
| 417 DrawDisplayList(pixels, layer_rect, list); | 405 DrawDisplayList(pixels, layer_rect, list); |
| 418 | 406 |
| 419 SkBitmap expected_bitmap; | 407 SkBitmap expected_bitmap; |
| 420 unsigned char expected_pixels[4 * 100 * 100] = {0}; | 408 unsigned char expected_pixels[4 * 100 * 100] = {0}; |
| 421 SkImageInfo info = | 409 SkImageInfo info = |
| 422 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); | 410 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 459 // translating |dst| after it is computed by computeFastBounds, rather than | 447 // translating |dst| after it is computed by computeFastBounds, rather than |
| 460 // translating |src| before it provided to computedFastBounds) can cause | 448 // translating |src| before it provided to computedFastBounds) can cause |
| 461 // incorrect clipping of filter output. To test for this, we include an | 449 // incorrect clipping of filter output. To test for this, we include an |
| 462 // SkImageSource filter in |filters|. Here, |src| is |filter_bounds|, defined | 450 // SkImageSource filter in |filters|. Here, |src| is |filter_bounds|, defined |
| 463 // below. | 451 // below. |
| 464 skia::RefPtr<SkImageFilter> image_filter = | 452 skia::RefPtr<SkImageFilter> image_filter = |
| 465 skia::AdoptRef(SkImageSource::Create(source_image.get())); | 453 skia::AdoptRef(SkImageSource::Create(source_image.get())); |
| 466 filters.Append(FilterOperation::CreateReferenceFilter(image_filter)); | 454 filters.Append(FilterOperation::CreateReferenceFilter(image_filter)); |
| 467 filters.Append(FilterOperation::CreateBrightnessFilter(0.5f)); | 455 filters.Append(FilterOperation::CreateBrightnessFilter(0.5f)); |
| 468 gfx::RectF filter_bounds(10.f, 10.f, 50.f, 50.f); | 456 gfx::RectF filter_bounds(10.f, 10.f, 50.f, 50.f); |
| 469 auto* item = list->CreateAndAppendItem<FilterDisplayItem>(kVisualRect); | 457 list->CreateAndAppendItem<FilterDisplayItem>(kVisualRect, filters, |
| 470 item->SetNew(filters, filter_bounds); | 458 filter_bounds); |
| 471 list->CreateAndAppendItem<EndFilterDisplayItem>(kVisualRect); | 459 list->CreateAndAppendItem<EndFilterDisplayItem>(kVisualRect); |
| 472 list->Finalize(); | 460 list->Finalize(); |
| 473 | 461 |
| 474 DrawDisplayList(pixels, layer_rect, list); | 462 DrawDisplayList(pixels, layer_rect, list); |
| 475 | 463 |
| 476 SkBitmap expected_bitmap; | 464 SkBitmap expected_bitmap; |
| 477 unsigned char expected_pixels[4 * 100 * 100] = {0}; | 465 unsigned char expected_pixels[4 * 100 * 100] = {0}; |
| 478 SkPaint paint; | 466 SkPaint paint; |
| 479 paint.setColor(SkColorSetRGB(64, 64, 64)); | 467 paint.setColor(SkColorSetRGB(64, 64, 64)); |
| 480 SkImageInfo info = | 468 SkImageInfo info = |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 504 no_caching_settings.use_cached_picture = false; | 492 no_caching_settings.use_cached_picture = false; |
| 505 scoped_refptr<DisplayItemList> list_without_caching = | 493 scoped_refptr<DisplayItemList> list_without_caching = |
| 506 DisplayItemList::Create(layer_rect, no_caching_settings); | 494 DisplayItemList::Create(layer_rect, no_caching_settings); |
| 507 | 495 |
| 508 canvas = skia::SharePtr( | 496 canvas = skia::SharePtr( |
| 509 recorder.beginRecording(gfx::RectFToSkRect(recording_rect))); | 497 recorder.beginRecording(gfx::RectFToSkRect(recording_rect))); |
| 510 canvas->translate(offset.x(), offset.y()); | 498 canvas->translate(offset.x(), offset.y()); |
| 511 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); | 499 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); |
| 512 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); | 500 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); |
| 513 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 501 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
| 514 auto* item1 = list_without_caching->CreateAndAppendItem<DrawingDisplayItem>( | 502 list_without_caching->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, |
| 515 kVisualRect); | 503 picture); |
| 516 item1->SetNew(picture); | |
| 517 list_without_caching->Finalize(); | 504 list_without_caching->Finalize(); |
| 518 DrawDisplayList(pixels, layer_rect, list_without_caching); | 505 DrawDisplayList(pixels, layer_rect, list_without_caching); |
| 519 | 506 |
| 520 unsigned char expected_pixels[4 * 100 * 100] = {0}; | 507 unsigned char expected_pixels[4 * 100 * 100] = {0}; |
| 521 DisplayItemListSettings caching_settings; | 508 DisplayItemListSettings caching_settings; |
| 522 caching_settings.use_cached_picture = true; | 509 caching_settings.use_cached_picture = true; |
| 523 scoped_refptr<DisplayItemList> list_with_caching = | 510 scoped_refptr<DisplayItemList> list_with_caching = |
| 524 DisplayItemList::Create(layer_rect, caching_settings); | 511 DisplayItemList::Create(layer_rect, caching_settings); |
| 525 auto* item2 = | 512 list_with_caching->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, |
| 526 list_with_caching->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); | 513 picture); |
| 527 item2->SetNew(picture); | |
| 528 list_with_caching->Finalize(); | 514 list_with_caching->Finalize(); |
| 529 DrawDisplayList(expected_pixels, layer_rect, list_with_caching); | 515 DrawDisplayList(expected_pixels, layer_rect, list_with_caching); |
| 530 | 516 |
| 531 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); | 517 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); |
| 532 } | 518 } |
| 533 | 519 |
| 534 TEST(DisplayItemListTest, IsSuitableForGpuRasterizationWithCachedPicture) { | 520 TEST(DisplayItemListTest, IsSuitableForGpuRasterizationWithCachedPicture) { |
| 535 gfx::Rect layer_rect(1000, 1000); | 521 gfx::Rect layer_rect(1000, 1000); |
| 536 SkPictureRecorder recorder; | 522 SkPictureRecorder recorder; |
| 537 skia::RefPtr<SkCanvas> canvas; | 523 skia::RefPtr<SkCanvas> canvas; |
| 538 skia::RefPtr<SkPicture> picture; | |
| 539 | 524 |
| 540 DisplayItemListSettings settings; | 525 DisplayItemListSettings settings; |
| 541 settings.use_cached_picture = true; | 526 settings.use_cached_picture = true; |
| 542 scoped_refptr<DisplayItemList> list = | 527 scoped_refptr<DisplayItemList> list = |
| 543 DisplayItemList::Create(layer_rect, settings); | 528 DisplayItemList::Create(layer_rect, settings); |
| 544 canvas = | 529 canvas = |
| 545 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); | 530 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); |
| 546 | 531 |
| 547 SkPath path; | 532 SkPath path; |
| 548 path.moveTo(0, 0); | 533 path.moveTo(0, 0); |
| 549 path.lineTo(0, 100); | 534 path.lineTo(0, 100); |
| 550 path.lineTo(50, 50); | 535 path.lineTo(50, 50); |
| 551 path.lineTo(100, 100); | 536 path.lineTo(100, 100); |
| 552 path.lineTo(100, 0); | 537 path.lineTo(100, 0); |
| 553 path.close(); | 538 path.close(); |
| 554 | 539 |
| 555 SkPaint paint; | 540 SkPaint paint; |
| 556 paint.setAntiAlias(true); | 541 paint.setAntiAlias(true); |
| 557 canvas->drawPath(path, paint); | 542 canvas->drawPath(path, paint); |
| 558 | 543 |
| 559 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 544 list->CreateAndAppendItem<DrawingDisplayItem>( |
| 560 DrawingDisplayItem* item = | 545 kVisualRect, skia::AdoptRef(recorder.endRecordingAsPicture())); |
| 561 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); | |
| 562 item->SetNew(picture); | |
| 563 list->Finalize(); | 546 list->Finalize(); |
| 564 | 547 |
| 565 // A single DrawingDisplayItem with a large AA concave path shouldn't trigger | 548 // A single DrawingDisplayItem with a large AA concave path shouldn't trigger |
| 566 // a veto. | 549 // a veto. |
| 567 EXPECT_TRUE(list->IsSuitableForGpuRasterization()); | 550 EXPECT_TRUE(list->IsSuitableForGpuRasterization()); |
| 568 | 551 |
| 569 list = DisplayItemList::Create(layer_rect, settings); | 552 list = DisplayItemList::Create(layer_rect, settings); |
| 570 canvas = | 553 canvas = |
| 571 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); | 554 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); |
| 572 for (int i = 0; i < 10; ++i) | 555 for (int i = 0; i < 10; ++i) |
| 573 canvas->drawPath(path, paint); | 556 canvas->drawPath(path, paint); |
| 574 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 557 list->CreateAndAppendItem<DrawingDisplayItem>( |
| 575 item = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); | 558 kVisualRect, skia::AdoptRef(recorder.endRecordingAsPicture())); |
| 576 item->SetNew(picture); | |
| 577 list->Finalize(); | 559 list->Finalize(); |
| 578 | 560 |
| 579 // A single DrawingDisplayItem with several large AA concave paths should | 561 // A single DrawingDisplayItem with several large AA concave paths should |
| 580 // trigger a veto. | 562 // trigger a veto. |
| 581 EXPECT_FALSE(list->IsSuitableForGpuRasterization()); | 563 EXPECT_FALSE(list->IsSuitableForGpuRasterization()); |
| 582 | |
| 583 list = DisplayItemList::Create(layer_rect, settings); | |
| 584 for (int i = 0; i < 10; ++i) { | |
| 585 canvas = | |
| 586 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); | |
| 587 canvas->drawPath(path, paint); | |
|
danakj
2015/12/08 19:18:16
Where'd this case go?
enne (OOO)
2015/12/08 19:47:27
This patch changes the behavior of DisplayItemList
| |
| 588 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | |
| 589 item = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); | |
| 590 item->SetNew(picture); | |
| 591 } | |
| 592 list->Finalize(); | |
| 593 | |
| 594 // Having several DrawingDisplayItems that each contain a large AA concave | |
| 595 // path should trigger a veto. | |
| 596 EXPECT_FALSE(list->IsSuitableForGpuRasterization()); | |
| 597 } | 564 } |
| 598 | 565 |
| 599 TEST(DisplayItemListTest, IsSuitableForGpuRasterizationWithoutCachedPicture) { | 566 TEST(DisplayItemListTest, IsSuitableForGpuRasterizationWithoutCachedPicture) { |
| 600 gfx::Rect layer_rect(1000, 1000); | 567 gfx::Rect layer_rect(1000, 1000); |
| 601 SkPictureRecorder recorder; | 568 SkPictureRecorder recorder; |
| 602 skia::RefPtr<SkCanvas> canvas; | 569 skia::RefPtr<SkCanvas> canvas; |
| 603 skia::RefPtr<SkPicture> picture; | 570 skia::RefPtr<SkPicture> picture; |
| 604 | 571 |
| 605 DisplayItemListSettings settings; | 572 DisplayItemListSettings settings; |
| 606 settings.use_cached_picture = false; | 573 settings.use_cached_picture = false; |
| 607 scoped_refptr<DisplayItemList> list = | 574 scoped_refptr<DisplayItemList> list = |
| 608 DisplayItemList::Create(layer_rect, settings); | 575 DisplayItemList::Create(layer_rect, settings); |
| 609 canvas = | 576 canvas = |
| 610 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); | 577 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); |
| 611 | 578 |
| 612 SkPath path; | 579 SkPath path; |
| 613 path.moveTo(0, 0); | 580 path.moveTo(0, 0); |
| 614 path.lineTo(0, 100); | 581 path.lineTo(0, 100); |
| 615 path.lineTo(50, 50); | 582 path.lineTo(50, 50); |
| 616 path.lineTo(100, 100); | 583 path.lineTo(100, 100); |
| 617 path.lineTo(100, 0); | 584 path.lineTo(100, 0); |
| 618 path.close(); | 585 path.close(); |
| 619 | 586 |
| 620 SkPaint paint; | 587 SkPaint paint; |
| 621 paint.setAntiAlias(true); | 588 paint.setAntiAlias(true); |
| 622 canvas->drawPath(path, paint); | 589 canvas->drawPath(path, paint); |
| 623 | 590 |
| 624 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 591 list->CreateAndAppendItem<DrawingDisplayItem>( |
| 625 DrawingDisplayItem* item = | 592 kVisualRect, skia::AdoptRef(recorder.endRecordingAsPicture())); |
| 626 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); | |
| 627 item->SetNew(picture); | |
| 628 list->Finalize(); | 593 list->Finalize(); |
| 629 | 594 |
| 630 // A single DrawingDisplayItem with a large AA concave path shouldn't trigger | 595 // A single DrawingDisplayItem with a large AA concave path shouldn't trigger |
| 631 // a veto. | 596 // a veto. |
| 632 EXPECT_TRUE(list->IsSuitableForGpuRasterization()); | 597 EXPECT_TRUE(list->IsSuitableForGpuRasterization()); |
| 633 | 598 |
| 634 list = DisplayItemList::Create(layer_rect, settings); | 599 list = DisplayItemList::Create(layer_rect, settings); |
| 635 canvas = | 600 canvas = |
| 636 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); | 601 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); |
| 637 for (int i = 0; i < 10; ++i) | 602 for (int i = 0; i < 10; ++i) |
| 638 canvas->drawPath(path, paint); | 603 canvas->drawPath(path, paint); |
| 639 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 604 list->CreateAndAppendItem<DrawingDisplayItem>( |
| 640 item = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); | 605 kVisualRect, skia::AdoptRef(recorder.endRecordingAsPicture())); |
| 641 item->SetNew(picture); | |
| 642 list->Finalize(); | 606 list->Finalize(); |
| 643 | 607 |
| 644 // A single DrawingDisplayItem with several large AA concave paths should | 608 // A single DrawingDisplayItem with several large AA concave paths should |
| 645 // trigger a veto. | 609 // trigger a veto. |
| 646 EXPECT_FALSE(list->IsSuitableForGpuRasterization()); | 610 EXPECT_FALSE(list->IsSuitableForGpuRasterization()); |
| 647 | 611 |
| 648 list = DisplayItemList::Create(layer_rect, settings); | 612 list = DisplayItemList::Create(layer_rect, settings); |
| 649 for (int i = 0; i < 10; ++i) { | 613 for (int i = 0; i < 10; ++i) { |
| 650 canvas = | 614 canvas = |
| 651 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); | 615 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); |
| 652 canvas->drawPath(path, paint); | 616 canvas->drawPath(path, paint); |
| 653 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 617 list->CreateAndAppendItem<DrawingDisplayItem>( |
| 654 item = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); | 618 kVisualRect, skia::AdoptRef(recorder.endRecordingAsPicture())); |
| 655 item->SetNew(picture); | |
| 656 } | 619 } |
| 657 list->Finalize(); | 620 list->Finalize(); |
| 658 | 621 |
| 659 // Without a cached picture, having several DrawingDisplayItems that each | 622 // Without a cached picture, having several DrawingDisplayItems that each |
| 660 // contain a single large AA concave will not trigger a veto, since each item | 623 // contain a single large AA concave will not trigger a veto, since each item |
| 661 // is individually suitable for GPU rasterization. | 624 // is individually suitable for GPU rasterization. |
| 662 EXPECT_TRUE(list->IsSuitableForGpuRasterization()); | 625 EXPECT_TRUE(list->IsSuitableForGpuRasterization()); |
| 663 } | 626 } |
| 664 | 627 |
| 665 TEST(DisplayItemListTest, ApproximateMemoryUsage) { | 628 TEST(DisplayItemListTest, ApproximateMemoryUsage) { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 677 canvas->drawPaint(blue_paint); | 640 canvas->drawPaint(blue_paint); |
| 678 skia::RefPtr<SkPicture> picture = | 641 skia::RefPtr<SkPicture> picture = |
| 679 skia::AdoptRef(recorder.endRecordingAsPicture()); | 642 skia::AdoptRef(recorder.endRecordingAsPicture()); |
| 680 size_t picture_size = SkPictureUtils::ApproximateBytesUsed(picture.get()); | 643 size_t picture_size = SkPictureUtils::ApproximateBytesUsed(picture.get()); |
| 681 ASSERT_GE(picture_size, kNumCommandsInTestSkPicture * sizeof(blue_paint)); | 644 ASSERT_GE(picture_size, kNumCommandsInTestSkPicture * sizeof(blue_paint)); |
| 682 | 645 |
| 683 // Using a cached picture, we should get about the right size. | 646 // Using a cached picture, we should get about the right size. |
| 684 DisplayItemListSettings caching_settings; | 647 DisplayItemListSettings caching_settings; |
| 685 caching_settings.use_cached_picture = true; | 648 caching_settings.use_cached_picture = true; |
| 686 list = DisplayItemList::Create(layer_rect, caching_settings); | 649 list = DisplayItemList::Create(layer_rect, caching_settings); |
| 687 auto* item = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); | 650 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, picture); |
| 688 item->SetNew(picture); | |
| 689 list->Finalize(); | 651 list->Finalize(); |
| 690 memory_usage = list->ApproximateMemoryUsage(); | 652 memory_usage = list->ApproximateMemoryUsage(); |
| 691 EXPECT_GE(memory_usage, picture_size); | 653 EXPECT_GE(memory_usage, picture_size); |
| 692 EXPECT_LE(memory_usage, 2 * picture_size); | 654 EXPECT_LE(memory_usage, 2 * picture_size); |
| 693 | 655 |
| 694 // Using no cached picture, we should still get the right size. | 656 // Using no cached picture, we should still get the right size. |
| 695 DisplayItemListSettings no_caching_settings; | 657 DisplayItemListSettings no_caching_settings; |
| 696 no_caching_settings.use_cached_picture = false; | 658 no_caching_settings.use_cached_picture = false; |
| 697 list = DisplayItemList::Create(layer_rect, no_caching_settings); | 659 list = DisplayItemList::Create(layer_rect, no_caching_settings); |
| 698 item = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); | 660 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, picture); |
| 699 item->SetNew(picture); | |
| 700 list->Finalize(); | 661 list->Finalize(); |
| 701 memory_usage = list->ApproximateMemoryUsage(); | 662 memory_usage = list->ApproximateMemoryUsage(); |
| 702 EXPECT_GE(memory_usage, picture_size); | 663 EXPECT_GE(memory_usage, picture_size); |
| 703 EXPECT_LE(memory_usage, 2 * picture_size); | 664 EXPECT_LE(memory_usage, 2 * picture_size); |
| 704 | 665 |
| 705 // To avoid double counting, we expect zero size to be computed if both the | 666 // To avoid double counting, we expect zero size to be computed if both the |
| 706 // picture and items are retained (currently this only happens due to certain | 667 // picture and items are retained (currently this only happens due to certain |
| 707 // categories being traced). | 668 // categories being traced). |
| 708 list = new DisplayItemList(layer_rect, caching_settings, true); | 669 list = new DisplayItemList(layer_rect, caching_settings, true); |
| 709 item = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); | 670 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, picture); |
| 710 item->SetNew(picture); | |
| 711 list->Finalize(); | 671 list->Finalize(); |
| 712 memory_usage = list->ApproximateMemoryUsage(); | 672 memory_usage = list->ApproximateMemoryUsage(); |
| 713 EXPECT_EQ(static_cast<size_t>(0), memory_usage); | 673 EXPECT_EQ(static_cast<size_t>(0), memory_usage); |
| 714 } | 674 } |
| 715 | 675 |
| 716 } // namespace cc | 676 } // namespace cc |
| OLD | NEW |