OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/test/fake_content_layer_client.h" | 5 #include "cc/test/fake_content_layer_client.h" |
6 | 6 |
7 #include "cc/playback/clip_display_item.h" | 7 #include "cc/playback/clip_display_item.h" |
8 #include "cc/playback/display_item_list_settings.h" | 8 #include "cc/playback/display_item_list_settings.h" |
9 #include "cc/playback/drawing_display_item.h" | 9 #include "cc/playback/drawing_display_item.h" |
10 #include "cc/playback/transform_display_item.h" | 10 #include "cc/playback/transform_display_item.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 FakeContentLayerClient::PaintContentsToDisplayList( | 45 FakeContentLayerClient::PaintContentsToDisplayList( |
46 PaintingControlSetting painting_control) { | 46 PaintingControlSetting painting_control) { |
47 // Cached picture is used because unit tests expect to be able to | 47 // Cached picture is used because unit tests expect to be able to |
48 // use GatherPixelRefs. | 48 // use GatherPixelRefs. |
49 DisplayItemListSettings settings; | 49 DisplayItemListSettings settings; |
50 settings.use_cached_picture = true; | 50 settings.use_cached_picture = true; |
51 scoped_refptr<DisplayItemList> display_list = | 51 scoped_refptr<DisplayItemList> display_list = |
52 DisplayItemList::Create(PaintableRegion(), settings); | 52 DisplayItemList::Create(PaintableRegion(), settings); |
53 SkPictureRecorder recorder; | 53 SkPictureRecorder recorder; |
54 skia::RefPtr<SkCanvas> canvas; | 54 skia::RefPtr<SkCanvas> canvas; |
| 55 skia::RefPtr<SkPicture> picture; |
55 | 56 |
56 for (RectPaintVector::const_iterator it = draw_rects_.begin(); | 57 for (RectPaintVector::const_iterator it = draw_rects_.begin(); |
57 it != draw_rects_.end(); ++it) { | 58 it != draw_rects_.end(); ++it) { |
58 const gfx::RectF& draw_rect = it->first; | 59 const gfx::RectF& draw_rect = it->first; |
59 const SkPaint& paint = it->second; | 60 const SkPaint& paint = it->second; |
60 canvas = | 61 canvas = |
61 skia::SharePtr(recorder.beginRecording(gfx::RectFToSkRect(draw_rect))); | 62 skia::SharePtr(recorder.beginRecording(gfx::RectFToSkRect(draw_rect))); |
62 canvas->drawRect(gfx::RectFToSkRect(draw_rect), paint); | 63 canvas->drawRect(gfx::RectFToSkRect(draw_rect), paint); |
63 display_list->CreateAndAppendItem<DrawingDisplayItem>( | 64 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
64 ToEnclosingRect(draw_rect), | 65 auto* item = display_list->CreateAndAppendItem<DrawingDisplayItem>( |
65 skia::AdoptRef(recorder.endRecordingAsPicture())); | 66 ToEnclosingRect(draw_rect)); |
| 67 item->SetNew(std::move(picture)); |
66 } | 68 } |
67 | 69 |
68 for (ImageVector::const_iterator it = draw_images_.begin(); | 70 for (ImageVector::const_iterator it = draw_images_.begin(); |
69 it != draw_images_.end(); ++it) { | 71 it != draw_images_.end(); ++it) { |
70 if (!it->transform.IsIdentity()) { | 72 if (!it->transform.IsIdentity()) { |
71 display_list->CreateAndAppendItem<TransformDisplayItem>(PaintableRegion(), | 73 auto* item = display_list->CreateAndAppendItem<TransformDisplayItem>( |
72 it->transform); | 74 PaintableRegion()); |
| 75 item->SetNew(it->transform); |
73 } | 76 } |
74 canvas = skia::SharePtr( | 77 canvas = skia::SharePtr( |
75 recorder.beginRecording(it->image->width(), it->image->height())); | 78 recorder.beginRecording(it->image->width(), it->image->height())); |
76 canvas->drawImage(it->image.get(), it->point.x(), it->point.y(), | 79 canvas->drawImage(it->image.get(), it->point.x(), it->point.y(), |
77 &it->paint); | 80 &it->paint); |
78 display_list->CreateAndAppendItem<DrawingDisplayItem>( | 81 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
79 PaintableRegion(), skia::AdoptRef(recorder.endRecordingAsPicture())); | 82 auto* item = display_list->CreateAndAppendItem<DrawingDisplayItem>( |
| 83 PaintableRegion()); |
| 84 item->SetNew(std::move(picture)); |
80 if (!it->transform.IsIdentity()) { | 85 if (!it->transform.IsIdentity()) { |
81 display_list->CreateAndAppendItem<EndTransformDisplayItem>( | 86 display_list->CreateAndAppendItem<EndTransformDisplayItem>( |
82 PaintableRegion()); | 87 PaintableRegion()); |
83 } | 88 } |
84 } | 89 } |
85 | 90 |
86 if (fill_with_nonsolid_color_) { | 91 if (fill_with_nonsolid_color_) { |
87 gfx::Rect draw_rect = PaintableRegion(); | 92 gfx::Rect draw_rect = PaintableRegion(); |
88 bool red = true; | 93 bool red = true; |
89 while (!draw_rect.IsEmpty()) { | 94 while (!draw_rect.IsEmpty()) { |
90 SkPaint paint; | 95 SkPaint paint; |
91 paint.setColor(red ? SK_ColorRED : SK_ColorBLUE); | 96 paint.setColor(red ? SK_ColorRED : SK_ColorBLUE); |
92 canvas = | 97 canvas = |
93 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(draw_rect))); | 98 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(draw_rect))); |
94 canvas->drawIRect(gfx::RectToSkIRect(draw_rect), paint); | 99 canvas->drawIRect(gfx::RectToSkIRect(draw_rect), paint); |
95 display_list->CreateAndAppendItem<DrawingDisplayItem>( | 100 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
96 draw_rect, skia::AdoptRef(recorder.endRecordingAsPicture())); | 101 auto* item = |
| 102 display_list->CreateAndAppendItem<DrawingDisplayItem>(draw_rect); |
| 103 item->SetNew(std::move(picture)); |
97 draw_rect.Inset(1, 1); | 104 draw_rect.Inset(1, 1); |
98 } | 105 } |
99 } | 106 } |
100 | 107 |
101 | 108 |
102 display_list->Finalize(); | 109 display_list->Finalize(); |
103 return display_list; | 110 return display_list; |
104 } | 111 } |
105 | 112 |
106 bool FakeContentLayerClient::FillsBoundsCompletely() const { return false; } | 113 bool FakeContentLayerClient::FillsBoundsCompletely() const { return false; } |
107 | 114 |
108 size_t FakeContentLayerClient::GetApproximateUnsharedMemoryUsage() const { | 115 size_t FakeContentLayerClient::GetApproximateUnsharedMemoryUsage() const { |
109 return reported_memory_usage_; | 116 return reported_memory_usage_; |
110 } | 117 } |
111 | 118 |
112 } // namespace cc | 119 } // namespace cc |
OLD | NEW |