| 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 settings.ToProtobuf(&proto); | 121 settings.ToProtobuf(&proto); |
| 122 DisplayItemListSettings deserialized(proto); | 122 DisplayItemListSettings deserialized(proto); |
| 123 EXPECT_EQ(settings.use_cached_picture, deserialized.use_cached_picture); | 123 EXPECT_EQ(settings.use_cached_picture, deserialized.use_cached_picture); |
| 124 } | 124 } |
| 125 } | 125 } |
| 126 | 126 |
| 127 TEST(DisplayItemListTest, SerializeSingleDrawingItem) { | 127 TEST(DisplayItemListTest, SerializeSingleDrawingItem) { |
| 128 gfx::Size layer_size(10, 10); | 128 gfx::Size layer_size(10, 10); |
| 129 | 129 |
| 130 DisplayItemListSettings settings; | 130 DisplayItemListSettings settings; |
| 131 scoped_refptr<DisplayItemList> list = | 131 settings.use_cached_picture = true; |
| 132 DisplayItemList::Create(gfx::Rect(layer_size), settings); | 132 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings); |
| 133 | 133 |
| 134 // Build the DrawingDisplayItem. | 134 // Build the DrawingDisplayItem. |
| 135 AppendFirstSerializationTestPicture(list, layer_size); | 135 AppendFirstSerializationTestPicture(list, layer_size); |
| 136 | 136 |
| 137 ValidateDisplayItemListSerialization(layer_size, list); | 137 ValidateDisplayItemListSerialization(layer_size, list); |
| 138 } | 138 } |
| 139 | 139 |
| 140 TEST(DisplayItemListTest, SerializeClipItem) { | 140 TEST(DisplayItemListTest, SerializeClipItem) { |
| 141 gfx::Size layer_size(10, 10); | 141 gfx::Size layer_size(10, 10); |
| 142 | 142 |
| 143 DisplayItemListSettings settings; | 143 DisplayItemListSettings settings; |
| 144 scoped_refptr<DisplayItemList> list = | 144 settings.use_cached_picture = true; |
| 145 DisplayItemList::Create(gfx::Rect(layer_size), settings); | 145 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings); |
| 146 | 146 |
| 147 // Build the DrawingDisplayItem. | 147 // Build the DrawingDisplayItem. |
| 148 AppendFirstSerializationTestPicture(list, layer_size); | 148 AppendFirstSerializationTestPicture(list, layer_size); |
| 149 | 149 |
| 150 // Build the ClipDisplayItem. | 150 // Build the ClipDisplayItem. |
| 151 gfx::Rect clip_rect(6, 6, 1, 1); | 151 gfx::Rect clip_rect(6, 6, 1, 1); |
| 152 std::vector<SkRRect> rrects; | 152 std::vector<SkRRect> rrects; |
| 153 rrects.push_back(SkRRect::MakeOval(SkRect::MakeXYWH(5.f, 5.f, 4.f, 4.f))); | 153 rrects.push_back(SkRRect::MakeOval(SkRect::MakeXYWH(5.f, 5.f, 4.f, 4.f))); |
| 154 auto* item = list->CreateAndAppendItem<ClipDisplayItem>(kVisualRect); | 154 auto* item = list->CreateAndAppendItem<ClipDisplayItem>(kVisualRect); |
| 155 item->SetNew(clip_rect, rrects); | 155 item->SetNew(clip_rect, rrects); |
| 156 | 156 |
| 157 // Build the second DrawingDisplayItem. | 157 // Build the second DrawingDisplayItem. |
| 158 AppendSecondSerializationTestPicture(list, layer_size); | 158 AppendSecondSerializationTestPicture(list, layer_size); |
| 159 | 159 |
| 160 // Build the EndClipDisplayItem. | 160 // Build the EndClipDisplayItem. |
| 161 list->CreateAndAppendItem<EndClipDisplayItem>(kVisualRect); | 161 list->CreateAndAppendItem<EndClipDisplayItem>(kVisualRect); |
| 162 | 162 |
| 163 ValidateDisplayItemListSerialization(layer_size, list); | 163 ValidateDisplayItemListSerialization(layer_size, list); |
| 164 } | 164 } |
| 165 | 165 |
| 166 TEST(DisplayItemListTest, SerializeClipPathItem) { | 166 TEST(DisplayItemListTest, SerializeClipPathItem) { |
| 167 gfx::Size layer_size(10, 10); | 167 gfx::Size layer_size(10, 10); |
| 168 | 168 |
| 169 DisplayItemListSettings settings; | 169 DisplayItemListSettings settings; |
| 170 scoped_refptr<DisplayItemList> list = | 170 settings.use_cached_picture = true; |
| 171 DisplayItemList::Create(gfx::Rect(layer_size), settings); | 171 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings); |
| 172 | 172 |
| 173 // Build the DrawingDisplayItem. | 173 // Build the DrawingDisplayItem. |
| 174 AppendFirstSerializationTestPicture(list, layer_size); | 174 AppendFirstSerializationTestPicture(list, layer_size); |
| 175 | 175 |
| 176 // Build the ClipPathDisplayItem. | 176 // Build the ClipPathDisplayItem. |
| 177 SkPath path; | 177 SkPath path; |
| 178 path.addCircle(5.f, 5.f, 2.f, SkPath::Direction::kCW_Direction); | 178 path.addCircle(5.f, 5.f, 2.f, SkPath::Direction::kCW_Direction); |
| 179 auto* item = list->CreateAndAppendItem<ClipPathDisplayItem>(kVisualRect); | 179 auto* item = list->CreateAndAppendItem<ClipPathDisplayItem>(kVisualRect); |
| 180 item->SetNew(path, SkRegion::Op::kReplace_Op, false); | 180 item->SetNew(path, SkRegion::Op::kReplace_Op, false); |
| 181 | 181 |
| 182 // Build the second DrawingDisplayItem. | 182 // Build the second DrawingDisplayItem. |
| 183 AppendSecondSerializationTestPicture(list, layer_size); | 183 AppendSecondSerializationTestPicture(list, layer_size); |
| 184 | 184 |
| 185 // Build the EndClipPathDisplayItem. | 185 // Build the EndClipPathDisplayItem. |
| 186 list->CreateAndAppendItem<EndClipPathDisplayItem>(kVisualRect); | 186 list->CreateAndAppendItem<EndClipPathDisplayItem>(kVisualRect); |
| 187 | 187 |
| 188 ValidateDisplayItemListSerialization(layer_size, list); | 188 ValidateDisplayItemListSerialization(layer_size, list); |
| 189 } | 189 } |
| 190 | 190 |
| 191 TEST(DisplayItemListTest, SerializeCompositingItem) { | 191 TEST(DisplayItemListTest, SerializeCompositingItem) { |
| 192 gfx::Size layer_size(10, 10); | 192 gfx::Size layer_size(10, 10); |
| 193 | 193 |
| 194 DisplayItemListSettings settings; | 194 DisplayItemListSettings settings; |
| 195 scoped_refptr<DisplayItemList> list = | 195 settings.use_cached_picture = true; |
| 196 DisplayItemList::Create(gfx::Rect(layer_size), settings); | 196 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings); |
| 197 | 197 |
| 198 // Build the DrawingDisplayItem. | 198 // Build the DrawingDisplayItem. |
| 199 AppendFirstSerializationTestPicture(list, layer_size); | 199 AppendFirstSerializationTestPicture(list, layer_size); |
| 200 | 200 |
| 201 // Build the CompositingDisplayItem. | 201 // Build the CompositingDisplayItem. |
| 202 skia::RefPtr<SkColorFilter> filter = skia::AdoptRef( | 202 skia::RefPtr<SkColorFilter> filter = skia::AdoptRef( |
| 203 SkColorFilter::CreateLightingFilter(SK_ColorRED, SK_ColorGREEN)); | 203 SkColorFilter::CreateLightingFilter(SK_ColorRED, SK_ColorGREEN)); |
| 204 auto* item = list->CreateAndAppendItem<CompositingDisplayItem>(kVisualRect); | 204 auto* item = list->CreateAndAppendItem<CompositingDisplayItem>(kVisualRect); |
| 205 item->SetNew(150, SkXfermode::Mode::kDst_Mode, nullptr, filter); | 205 item->SetNew(150, SkXfermode::Mode::kDst_Mode, nullptr, filter); |
| 206 | 206 |
| 207 // Build the second DrawingDisplayItem. | 207 // Build the second DrawingDisplayItem. |
| 208 AppendSecondSerializationTestPicture(list, layer_size); | 208 AppendSecondSerializationTestPicture(list, layer_size); |
| 209 | 209 |
| 210 // Build the EndCompositingDisplayItem. | 210 // Build the EndCompositingDisplayItem. |
| 211 list->CreateAndAppendItem<EndCompositingDisplayItem>(kVisualRect); | 211 list->CreateAndAppendItem<EndCompositingDisplayItem>(kVisualRect); |
| 212 | 212 |
| 213 ValidateDisplayItemListSerialization(layer_size, list); | 213 ValidateDisplayItemListSerialization(layer_size, list); |
| 214 } | 214 } |
| 215 | 215 |
| 216 TEST(DisplayItemListTest, SerializeFloatClipItem) { | 216 TEST(DisplayItemListTest, SerializeFloatClipItem) { |
| 217 gfx::Size layer_size(10, 10); | 217 gfx::Size layer_size(10, 10); |
| 218 | 218 |
| 219 DisplayItemListSettings settings; | 219 DisplayItemListSettings settings; |
| 220 scoped_refptr<DisplayItemList> list = | 220 settings.use_cached_picture = true; |
| 221 DisplayItemList::Create(gfx::Rect(layer_size), settings); | 221 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings); |
| 222 | 222 |
| 223 // Build the DrawingDisplayItem. | 223 // Build the DrawingDisplayItem. |
| 224 AppendFirstSerializationTestPicture(list, layer_size); | 224 AppendFirstSerializationTestPicture(list, layer_size); |
| 225 | 225 |
| 226 // Build the FloatClipDisplayItem. | 226 // Build the FloatClipDisplayItem. |
| 227 gfx::RectF clip_rect(6.f, 6.f, 1.f, 1.f); | 227 gfx::RectF clip_rect(6.f, 6.f, 1.f, 1.f); |
| 228 auto* item2 = list->CreateAndAppendItem<FloatClipDisplayItem>(kVisualRect); | 228 auto* item2 = list->CreateAndAppendItem<FloatClipDisplayItem>(kVisualRect); |
| 229 item2->SetNew(clip_rect); | 229 item2->SetNew(clip_rect); |
| 230 | 230 |
| 231 // Build the second DrawingDisplayItem. | 231 // Build the second DrawingDisplayItem. |
| 232 AppendSecondSerializationTestPicture(list, layer_size); | 232 AppendSecondSerializationTestPicture(list, layer_size); |
| 233 | 233 |
| 234 // Build the EndFloatClipDisplayItem. | 234 // Build the EndFloatClipDisplayItem. |
| 235 list->CreateAndAppendItem<EndFloatClipDisplayItem>(kVisualRect); | 235 list->CreateAndAppendItem<EndFloatClipDisplayItem>(kVisualRect); |
| 236 | 236 |
| 237 ValidateDisplayItemListSerialization(layer_size, list); | 237 ValidateDisplayItemListSerialization(layer_size, list); |
| 238 } | 238 } |
| 239 | 239 |
| 240 TEST(DisplayItemListTest, SerializeTransformItem) { | 240 TEST(DisplayItemListTest, SerializeTransformItem) { |
| 241 gfx::Size layer_size(10, 10); | 241 gfx::Size layer_size(10, 10); |
| 242 | 242 |
| 243 DisplayItemListSettings settings; | 243 DisplayItemListSettings settings; |
| 244 scoped_refptr<DisplayItemList> list = | 244 settings.use_cached_picture = true; |
| 245 DisplayItemList::Create(gfx::Rect(layer_size), settings); | 245 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings); |
| 246 | 246 |
| 247 // Build the DrawingDisplayItem. | 247 // Build the DrawingDisplayItem. |
| 248 AppendFirstSerializationTestPicture(list, layer_size); | 248 AppendFirstSerializationTestPicture(list, layer_size); |
| 249 | 249 |
| 250 // Build the TransformDisplayItem. | 250 // Build the TransformDisplayItem. |
| 251 gfx::Transform transform; | 251 gfx::Transform transform; |
| 252 transform.Scale(1.25f, 1.25f); | 252 transform.Scale(1.25f, 1.25f); |
| 253 transform.Translate(-1.f, -1.f); | 253 transform.Translate(-1.f, -1.f); |
| 254 auto* item2 = list->CreateAndAppendItem<TransformDisplayItem>(kVisualRect); | 254 auto* item2 = list->CreateAndAppendItem<TransformDisplayItem>(kVisualRect); |
| 255 item2->SetNew(transform); | 255 item2->SetNew(transform); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 267 gfx::Rect layer_rect(100, 100); | 267 gfx::Rect layer_rect(100, 100); |
| 268 SkPictureRecorder recorder; | 268 SkPictureRecorder recorder; |
| 269 skia::RefPtr<SkCanvas> canvas; | 269 skia::RefPtr<SkCanvas> canvas; |
| 270 skia::RefPtr<SkPicture> picture; | 270 skia::RefPtr<SkPicture> picture; |
| 271 SkPaint blue_paint; | 271 SkPaint blue_paint; |
| 272 blue_paint.setColor(SK_ColorBLUE); | 272 blue_paint.setColor(SK_ColorBLUE); |
| 273 SkPaint red_paint; | 273 SkPaint red_paint; |
| 274 red_paint.setColor(SK_ColorRED); | 274 red_paint.setColor(SK_ColorRED); |
| 275 unsigned char pixels[4 * 100 * 100] = {0}; | 275 unsigned char pixels[4 * 100 * 100] = {0}; |
| 276 DisplayItemListSettings settings; | 276 DisplayItemListSettings settings; |
| 277 scoped_refptr<DisplayItemList> list = | 277 settings.use_cached_picture = true; |
| 278 DisplayItemList::Create(layer_rect, settings); | 278 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings); |
| 279 | 279 |
| 280 gfx::PointF offset(8.f, 9.f); | 280 gfx::PointF offset(8.f, 9.f); |
| 281 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); | 281 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); |
| 282 canvas = skia::SharePtr( | 282 canvas = skia::SharePtr( |
| 283 recorder.beginRecording(gfx::RectFToSkRect(recording_rect))); | 283 recorder.beginRecording(gfx::RectFToSkRect(recording_rect))); |
| 284 canvas->translate(offset.x(), offset.y()); | 284 canvas->translate(offset.x(), offset.y()); |
| 285 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); | 285 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); | 286 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); |
| 287 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 287 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
| 288 auto* item = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); | 288 auto* item = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 312 SkPictureRecorder recorder; | 312 SkPictureRecorder recorder; |
| 313 skia::RefPtr<SkCanvas> canvas; | 313 skia::RefPtr<SkCanvas> canvas; |
| 314 skia::RefPtr<SkPicture> picture; | 314 skia::RefPtr<SkPicture> picture; |
| 315 SkPaint blue_paint; | 315 SkPaint blue_paint; |
| 316 blue_paint.setColor(SK_ColorBLUE); | 316 blue_paint.setColor(SK_ColorBLUE); |
| 317 SkPaint red_paint; | 317 SkPaint red_paint; |
| 318 red_paint.setColor(SK_ColorRED); | 318 red_paint.setColor(SK_ColorRED); |
| 319 unsigned char pixels[4 * 100 * 100] = {0}; | 319 unsigned char pixels[4 * 100 * 100] = {0}; |
| 320 DisplayItemListSettings settings; | 320 DisplayItemListSettings settings; |
| 321 settings.use_cached_picture = true; | 321 settings.use_cached_picture = true; |
| 322 scoped_refptr<DisplayItemList> list = | 322 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings); |
| 323 DisplayItemList::Create(layer_rect, settings); | |
| 324 | 323 |
| 325 gfx::PointF first_offset(8.f, 9.f); | 324 gfx::PointF first_offset(8.f, 9.f); |
| 326 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); | 325 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); |
| 327 canvas = skia::SharePtr( | 326 canvas = skia::SharePtr( |
| 328 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect))); | 327 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect))); |
| 329 canvas->translate(first_offset.x(), first_offset.y()); | 328 canvas->translate(first_offset.x(), first_offset.y()); |
| 330 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); | 329 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); |
| 331 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 330 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
| 332 auto* item1 = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); | 331 auto* item1 = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); |
| 333 item1->SetNew(std::move(picture)); | 332 item1->SetNew(std::move(picture)); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 SkPictureRecorder recorder; | 374 SkPictureRecorder recorder; |
| 376 skia::RefPtr<SkCanvas> canvas; | 375 skia::RefPtr<SkCanvas> canvas; |
| 377 skia::RefPtr<SkPicture> picture; | 376 skia::RefPtr<SkPicture> picture; |
| 378 SkPaint blue_paint; | 377 SkPaint blue_paint; |
| 379 blue_paint.setColor(SK_ColorBLUE); | 378 blue_paint.setColor(SK_ColorBLUE); |
| 380 SkPaint red_paint; | 379 SkPaint red_paint; |
| 381 red_paint.setColor(SK_ColorRED); | 380 red_paint.setColor(SK_ColorRED); |
| 382 unsigned char pixels[4 * 100 * 100] = {0}; | 381 unsigned char pixels[4 * 100 * 100] = {0}; |
| 383 DisplayItemListSettings settings; | 382 DisplayItemListSettings settings; |
| 384 settings.use_cached_picture = true; | 383 settings.use_cached_picture = true; |
| 385 scoped_refptr<DisplayItemList> list = | 384 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings); |
| 386 DisplayItemList::Create(layer_rect, settings); | |
| 387 | 385 |
| 388 gfx::PointF first_offset(8.f, 9.f); | 386 gfx::PointF first_offset(8.f, 9.f); |
| 389 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); | 387 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); |
| 390 canvas = skia::SharePtr( | 388 canvas = skia::SharePtr( |
| 391 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect))); | 389 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect))); |
| 392 canvas->translate(first_offset.x(), first_offset.y()); | 390 canvas->translate(first_offset.x(), first_offset.y()); |
| 393 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); | 391 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); |
| 394 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 392 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
| 395 auto* item1 = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); | 393 auto* item1 = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); |
| 396 item1->SetNew(picture); | 394 item1->SetNew(picture); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 50.f + second_offset.x(), 50.f + second_offset.y(), | 429 50.f + second_offset.x(), 50.f + second_offset.y(), |
| 432 75.f + second_offset.x(), 75.f + second_offset.y(), blue_paint); | 430 75.f + second_offset.x(), 75.f + second_offset.y(), blue_paint); |
| 433 | 431 |
| 434 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); | 432 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); |
| 435 } | 433 } |
| 436 | 434 |
| 437 TEST(DisplayItemListTest, FilterItem) { | 435 TEST(DisplayItemListTest, FilterItem) { |
| 438 gfx::Rect layer_rect(100, 100); | 436 gfx::Rect layer_rect(100, 100); |
| 439 FilterOperations filters; | 437 FilterOperations filters; |
| 440 unsigned char pixels[4 * 100 * 100] = {0}; | 438 unsigned char pixels[4 * 100 * 100] = {0}; |
| 441 DisplayItemListSettings settings; | |
| 442 settings.use_cached_picture = true; | |
| 443 scoped_refptr<DisplayItemList> list = | 439 scoped_refptr<DisplayItemList> list = |
| 444 DisplayItemList::Create(layer_rect, settings); | 440 DisplayItemList::Create(DisplayItemListSettings()); |
| 445 | 441 |
| 446 skia::RefPtr<SkSurface> source_surface = | 442 skia::RefPtr<SkSurface> source_surface = |
| 447 skia::AdoptRef(SkSurface::NewRasterN32Premul(50, 50)); | 443 skia::AdoptRef(SkSurface::NewRasterN32Premul(50, 50)); |
| 448 SkCanvas* source_canvas = source_surface->getCanvas(); | 444 SkCanvas* source_canvas = source_surface->getCanvas(); |
| 449 source_canvas->clear(SkColorSetRGB(128, 128, 128)); | 445 source_canvas->clear(SkColorSetRGB(128, 128, 128)); |
| 450 skia::RefPtr<SkImage> source_image = | 446 skia::RefPtr<SkImage> source_image = |
| 451 skia::AdoptRef(source_surface->newImageSnapshot()); | 447 skia::AdoptRef(source_surface->newImageSnapshot()); |
| 452 | 448 |
| 453 // For most SkImageFilters, the |dst| bounds computed by computeFastBounds are | 449 // For most SkImageFilters, the |dst| bounds computed by computeFastBounds are |
| 454 // dependent on the provided |src| bounds. This means, for example, that | 450 // dependent on the provided |src| bounds. This means, for example, that |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 SkPaint blue_paint; | 490 SkPaint blue_paint; |
| 495 blue_paint.setColor(SK_ColorBLUE); | 491 blue_paint.setColor(SK_ColorBLUE); |
| 496 SkPaint red_paint; | 492 SkPaint red_paint; |
| 497 red_paint.setColor(SK_ColorRED); | 493 red_paint.setColor(SK_ColorRED); |
| 498 unsigned char pixels[4 * 100 * 100] = {0}; | 494 unsigned char pixels[4 * 100 * 100] = {0}; |
| 499 | 495 |
| 500 gfx::PointF offset(8.f, 9.f); | 496 gfx::PointF offset(8.f, 9.f); |
| 501 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); | 497 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); |
| 502 | 498 |
| 503 DisplayItemListSettings no_caching_settings; | 499 DisplayItemListSettings no_caching_settings; |
| 504 no_caching_settings.use_cached_picture = false; | |
| 505 scoped_refptr<DisplayItemList> list_without_caching = | 500 scoped_refptr<DisplayItemList> list_without_caching = |
| 506 DisplayItemList::Create(layer_rect, no_caching_settings); | 501 DisplayItemList::Create(no_caching_settings); |
| 507 | 502 |
| 508 canvas = skia::SharePtr( | 503 canvas = skia::SharePtr( |
| 509 recorder.beginRecording(gfx::RectFToSkRect(recording_rect))); | 504 recorder.beginRecording(gfx::RectFToSkRect(recording_rect))); |
| 510 canvas->translate(offset.x(), offset.y()); | 505 canvas->translate(offset.x(), offset.y()); |
| 511 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); | 506 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); | 507 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); |
| 513 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 508 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
| 514 auto* item1 = list_without_caching->CreateAndAppendItem<DrawingDisplayItem>( | 509 auto* item1 = list_without_caching->CreateAndAppendItem<DrawingDisplayItem>( |
| 515 kVisualRect); | 510 kVisualRect); |
| 516 item1->SetNew(picture); | 511 item1->SetNew(picture); |
| 517 list_without_caching->Finalize(); | 512 list_without_caching->Finalize(); |
| 518 DrawDisplayList(pixels, layer_rect, list_without_caching); | 513 DrawDisplayList(pixels, layer_rect, list_without_caching); |
| 519 | 514 |
| 520 unsigned char expected_pixels[4 * 100 * 100] = {0}; | 515 unsigned char expected_pixels[4 * 100 * 100] = {0}; |
| 521 DisplayItemListSettings caching_settings; | 516 DisplayItemListSettings caching_settings; |
| 522 caching_settings.use_cached_picture = true; | 517 caching_settings.use_cached_picture = true; |
| 523 scoped_refptr<DisplayItemList> list_with_caching = | 518 scoped_refptr<DisplayItemList> list_with_caching = |
| 524 DisplayItemList::Create(layer_rect, caching_settings); | 519 DisplayItemList::Create(caching_settings); |
| 525 auto* item2 = | 520 auto* item2 = |
| 526 list_with_caching->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); | 521 list_with_caching->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); |
| 527 item2->SetNew(picture); | 522 item2->SetNew(picture); |
| 528 list_with_caching->Finalize(); | 523 list_with_caching->Finalize(); |
| 529 DrawDisplayList(expected_pixels, layer_rect, list_with_caching); | 524 DrawDisplayList(expected_pixels, layer_rect, list_with_caching); |
| 530 | 525 |
| 531 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); | 526 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); |
| 532 } | 527 } |
| 533 | 528 |
| 534 TEST(DisplayItemListTest, IsSuitableForGpuRasterizationWithCachedPicture) { | |
| 535 gfx::Rect layer_rect(1000, 1000); | |
| 536 SkPictureRecorder recorder; | |
| 537 skia::RefPtr<SkCanvas> canvas; | |
| 538 skia::RefPtr<SkPicture> picture; | |
| 539 | |
| 540 DisplayItemListSettings settings; | |
| 541 settings.use_cached_picture = true; | |
| 542 scoped_refptr<DisplayItemList> list = | |
| 543 DisplayItemList::Create(layer_rect, settings); | |
| 544 canvas = | |
| 545 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); | |
| 546 | |
| 547 SkPath path; | |
| 548 path.moveTo(0, 0); | |
| 549 path.lineTo(0, 100); | |
| 550 path.lineTo(50, 50); | |
| 551 path.lineTo(100, 100); | |
| 552 path.lineTo(100, 0); | |
| 553 path.close(); | |
| 554 | |
| 555 SkPaint paint; | |
| 556 paint.setAntiAlias(true); | |
| 557 canvas->drawPath(path, paint); | |
| 558 | |
| 559 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | |
| 560 DrawingDisplayItem* item = | |
| 561 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); | |
| 562 item->SetNew(picture); | |
| 563 list->Finalize(); | |
| 564 | |
| 565 // A single DrawingDisplayItem with a large AA concave path shouldn't trigger | |
| 566 // a veto. | |
| 567 EXPECT_TRUE(list->IsSuitableForGpuRasterization()); | |
| 568 | |
| 569 list = DisplayItemList::Create(layer_rect, settings); | |
| 570 canvas = | |
| 571 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); | |
| 572 for (int i = 0; i < 10; ++i) | |
| 573 canvas->drawPath(path, paint); | |
| 574 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | |
| 575 item = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); | |
| 576 item->SetNew(picture); | |
| 577 list->Finalize(); | |
| 578 | |
| 579 // A single DrawingDisplayItem with several large AA concave paths should | |
| 580 // trigger a veto. | |
| 581 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); | |
| 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 } | |
| 598 | |
| 599 TEST(DisplayItemListTest, IsSuitableForGpuRasterizationWithoutCachedPicture) { | 529 TEST(DisplayItemListTest, IsSuitableForGpuRasterizationWithoutCachedPicture) { |
| 600 gfx::Rect layer_rect(1000, 1000); | 530 gfx::Rect layer_rect(1000, 1000); |
| 601 SkPictureRecorder recorder; | 531 SkPictureRecorder recorder; |
| 602 skia::RefPtr<SkCanvas> canvas; | 532 skia::RefPtr<SkCanvas> canvas; |
| 603 skia::RefPtr<SkPicture> picture; | 533 skia::RefPtr<SkPicture> picture; |
| 604 | 534 |
| 605 DisplayItemListSettings settings; | 535 DisplayItemListSettings settings; |
| 606 settings.use_cached_picture = false; | 536 settings.use_cached_picture = false; |
| 607 scoped_refptr<DisplayItemList> list = | 537 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings); |
| 608 DisplayItemList::Create(layer_rect, settings); | |
| 609 canvas = | 538 canvas = |
| 610 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); | 539 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); |
| 611 | 540 |
| 612 SkPath path; | 541 SkPath path; |
| 613 path.moveTo(0, 0); | 542 path.moveTo(0, 0); |
| 614 path.lineTo(0, 100); | 543 path.lineTo(0, 100); |
| 615 path.lineTo(50, 50); | 544 path.lineTo(50, 50); |
| 616 path.lineTo(100, 100); | 545 path.lineTo(100, 100); |
| 617 path.lineTo(100, 0); | 546 path.lineTo(100, 0); |
| 618 path.close(); | 547 path.close(); |
| 619 | 548 |
| 620 SkPaint paint; | 549 SkPaint paint; |
| 621 paint.setAntiAlias(true); | 550 paint.setAntiAlias(true); |
| 622 canvas->drawPath(path, paint); | 551 canvas->drawPath(path, paint); |
| 623 | 552 |
| 624 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 553 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
| 625 DrawingDisplayItem* item = | 554 DrawingDisplayItem* item = |
| 626 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); | 555 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); |
| 627 item->SetNew(picture); | 556 item->SetNew(picture); |
| 628 list->Finalize(); | 557 list->Finalize(); |
| 629 | 558 |
| 630 // A single DrawingDisplayItem with a large AA concave path shouldn't trigger | 559 // A single DrawingDisplayItem with a large AA concave path shouldn't trigger |
| 631 // a veto. | 560 // a veto. |
| 632 EXPECT_TRUE(list->IsSuitableForGpuRasterization()); | 561 EXPECT_TRUE(list->IsSuitableForGpuRasterization()); |
| 633 | 562 |
| 634 list = DisplayItemList::Create(layer_rect, settings); | 563 list = DisplayItemList::Create(settings); |
| 635 canvas = | 564 canvas = |
| 636 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); | 565 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); |
| 637 for (int i = 0; i < 10; ++i) | 566 for (int i = 0; i < 10; ++i) |
| 638 canvas->drawPath(path, paint); | 567 canvas->drawPath(path, paint); |
| 639 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 568 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
| 640 item = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); | 569 item = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); |
| 641 item->SetNew(picture); | 570 item->SetNew(picture); |
| 642 list->Finalize(); | 571 list->Finalize(); |
| 643 | 572 |
| 644 // A single DrawingDisplayItem with several large AA concave paths should | 573 // A single DrawingDisplayItem with several large AA concave paths should |
| 645 // trigger a veto. | 574 // trigger a veto. |
| 646 EXPECT_FALSE(list->IsSuitableForGpuRasterization()); | 575 EXPECT_FALSE(list->IsSuitableForGpuRasterization()); |
| 647 | 576 |
| 648 list = DisplayItemList::Create(layer_rect, settings); | 577 list = DisplayItemList::Create(settings); |
| 649 for (int i = 0; i < 10; ++i) { | 578 for (int i = 0; i < 10; ++i) { |
| 650 canvas = | 579 canvas = |
| 651 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); | 580 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); |
| 652 canvas->drawPath(path, paint); | 581 canvas->drawPath(path, paint); |
| 653 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 582 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
| 654 item = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); | 583 item = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); |
| 655 item->SetNew(picture); | 584 item->SetNew(picture); |
| 656 } | 585 } |
| 657 list->Finalize(); | 586 list->Finalize(); |
| 658 | 587 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 676 for (int i = 0; i < kNumCommandsInTestSkPicture; i++) | 605 for (int i = 0; i < kNumCommandsInTestSkPicture; i++) |
| 677 canvas->drawPaint(blue_paint); | 606 canvas->drawPaint(blue_paint); |
| 678 skia::RefPtr<SkPicture> picture = | 607 skia::RefPtr<SkPicture> picture = |
| 679 skia::AdoptRef(recorder.endRecordingAsPicture()); | 608 skia::AdoptRef(recorder.endRecordingAsPicture()); |
| 680 size_t picture_size = SkPictureUtils::ApproximateBytesUsed(picture.get()); | 609 size_t picture_size = SkPictureUtils::ApproximateBytesUsed(picture.get()); |
| 681 ASSERT_GE(picture_size, kNumCommandsInTestSkPicture * sizeof(blue_paint)); | 610 ASSERT_GE(picture_size, kNumCommandsInTestSkPicture * sizeof(blue_paint)); |
| 682 | 611 |
| 683 // Using a cached picture, we should get about the right size. | 612 // Using a cached picture, we should get about the right size. |
| 684 DisplayItemListSettings caching_settings; | 613 DisplayItemListSettings caching_settings; |
| 685 caching_settings.use_cached_picture = true; | 614 caching_settings.use_cached_picture = true; |
| 686 list = DisplayItemList::Create(layer_rect, caching_settings); | 615 list = DisplayItemList::Create(caching_settings); |
| 687 auto* item = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); | 616 auto* item = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); |
| 688 item->SetNew(picture); | 617 item->SetNew(picture); |
| 689 list->Finalize(); | 618 list->Finalize(); |
| 690 memory_usage = list->ApproximateMemoryUsage(); | 619 memory_usage = list->ApproximateMemoryUsage(); |
| 691 EXPECT_GE(memory_usage, picture_size); | 620 EXPECT_GE(memory_usage, picture_size); |
| 692 EXPECT_LE(memory_usage, 2 * picture_size); | 621 EXPECT_LE(memory_usage, 2 * picture_size); |
| 693 | 622 |
| 694 // Using no cached picture, we should still get the right size. | 623 // Using no cached picture, we should still get the right size. |
| 695 DisplayItemListSettings no_caching_settings; | 624 DisplayItemListSettings no_caching_settings; |
| 696 no_caching_settings.use_cached_picture = false; | 625 no_caching_settings.use_cached_picture = false; |
| 697 list = DisplayItemList::Create(layer_rect, no_caching_settings); | 626 list = DisplayItemList::Create(no_caching_settings); |
| 698 item = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); | 627 item = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); |
| 699 item->SetNew(picture); | 628 item->SetNew(picture); |
| 700 list->Finalize(); | 629 list->Finalize(); |
| 701 memory_usage = list->ApproximateMemoryUsage(); | 630 memory_usage = list->ApproximateMemoryUsage(); |
| 702 EXPECT_GE(memory_usage, picture_size); | 631 EXPECT_GE(memory_usage, picture_size); |
| 703 EXPECT_LE(memory_usage, 2 * picture_size); | 632 EXPECT_LE(memory_usage, 2 * picture_size); |
| 704 | |
| 705 // 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 | |
| 707 // categories being traced). | |
| 708 list = new DisplayItemList(layer_rect, caching_settings, true); | |
| 709 item = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); | |
| 710 item->SetNew(picture); | |
| 711 list->Finalize(); | |
| 712 memory_usage = list->ApproximateMemoryUsage(); | |
| 713 EXPECT_EQ(static_cast<size_t>(0), memory_usage); | |
| 714 } | 633 } |
| 715 | 634 |
| 716 } // namespace cc | 635 } // namespace cc |
| OLD | NEW |