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" |
11 #include "third_party/skia/include/core/SkCanvas.h" | 11 #include "third_party/skia/include/core/SkCanvas.h" |
12 #include "third_party/skia/include/core/SkPictureRecorder.h" | 12 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 13 #include "ui/gfx/geometry/rect_conversions.h" |
13 #include "ui/gfx/skia_util.h" | 14 #include "ui/gfx/skia_util.h" |
14 | 15 |
15 namespace cc { | 16 namespace cc { |
16 | 17 |
17 FakeContentLayerClient::ImageData::ImageData(const SkImage* img, | 18 FakeContentLayerClient::ImageData::ImageData(const SkImage* img, |
18 const gfx::Point& point, | 19 const gfx::Point& point, |
19 const SkPaint& paint) | 20 const SkPaint& paint) |
20 : image(skia::SharePtr(img)), point(point), paint(paint) {} | 21 : image(skia::SharePtr(img)), point(point), paint(paint) {} |
21 | 22 |
22 FakeContentLayerClient::ImageData::ImageData(const SkImage* img, | 23 FakeContentLayerClient::ImageData::ImageData(const SkImage* img, |
(...skipping 23 matching lines...) Expand all Loading... |
46 PaintingControlSetting painting_control) { | 47 PaintingControlSetting painting_control) { |
47 // Cached picture is used because unit tests expect to be able to | 48 // Cached picture is used because unit tests expect to be able to |
48 // use GatherPixelRefs. | 49 // use GatherPixelRefs. |
49 DisplayItemListSettings settings; | 50 DisplayItemListSettings settings; |
50 settings.use_cached_picture = true; | 51 settings.use_cached_picture = true; |
51 scoped_refptr<DisplayItemList> display_list = | 52 scoped_refptr<DisplayItemList> display_list = |
52 DisplayItemList::Create(clip, settings); | 53 DisplayItemList::Create(clip, settings); |
53 SkPictureRecorder recorder; | 54 SkPictureRecorder recorder; |
54 skia::RefPtr<SkCanvas> canvas; | 55 skia::RefPtr<SkCanvas> canvas; |
55 skia::RefPtr<SkPicture> picture; | 56 skia::RefPtr<SkPicture> picture; |
56 auto* item = display_list->CreateAndAppendItem<ClipDisplayItem>(); | 57 auto* item = display_list->CreateAndAppendItem<ClipDisplayItem>(clip); |
57 item->SetNew(clip, std::vector<SkRRect>()); | 58 item->SetNew(clip, std::vector<SkRRect>()); |
58 | 59 |
59 for (RectPaintVector::const_iterator it = draw_rects_.begin(); | 60 for (RectPaintVector::const_iterator it = draw_rects_.begin(); |
60 it != draw_rects_.end(); ++it) { | 61 it != draw_rects_.end(); ++it) { |
61 const gfx::RectF& draw_rect = it->first; | 62 const gfx::RectF& draw_rect = it->first; |
62 const SkPaint& paint = it->second; | 63 const SkPaint& paint = it->second; |
63 canvas = | 64 canvas = |
64 skia::SharePtr(recorder.beginRecording(gfx::RectFToSkRect(draw_rect))); | 65 skia::SharePtr(recorder.beginRecording(gfx::RectFToSkRect(draw_rect))); |
65 canvas->drawRect(gfx::RectFToSkRect(draw_rect), paint); | 66 canvas->drawRect(gfx::RectFToSkRect(draw_rect), paint); |
66 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 67 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
67 auto* item = display_list->CreateAndAppendItem<DrawingDisplayItem>(); | 68 auto* item = display_list->CreateAndAppendItem<DrawingDisplayItem>( |
| 69 ToEnclosingRect(draw_rect)); |
68 item->SetNew(std::move(picture)); | 70 item->SetNew(std::move(picture)); |
69 } | 71 } |
70 | 72 |
71 for (ImageVector::const_iterator it = draw_images_.begin(); | 73 for (ImageVector::const_iterator it = draw_images_.begin(); |
72 it != draw_images_.end(); ++it) { | 74 it != draw_images_.end(); ++it) { |
73 if (!it->transform.IsIdentity()) { | 75 if (!it->transform.IsIdentity()) { |
74 auto* item = display_list->CreateAndAppendItem<TransformDisplayItem>(); | 76 auto* item = |
| 77 display_list->CreateAndAppendItem<TransformDisplayItem>(clip); |
75 item->SetNew(it->transform); | 78 item->SetNew(it->transform); |
76 } | 79 } |
77 canvas = skia::SharePtr( | 80 canvas = skia::SharePtr( |
78 recorder.beginRecording(it->image->width(), it->image->height())); | 81 recorder.beginRecording(it->image->width(), it->image->height())); |
79 canvas->drawImage(it->image.get(), it->point.x(), it->point.y(), | 82 canvas->drawImage(it->image.get(), it->point.x(), it->point.y(), |
80 &it->paint); | 83 &it->paint); |
81 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 84 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
82 auto* item = display_list->CreateAndAppendItem<DrawingDisplayItem>(); | 85 auto* item = display_list->CreateAndAppendItem<DrawingDisplayItem>(clip); |
83 item->SetNew(std::move(picture)); | 86 item->SetNew(std::move(picture)); |
84 if (!it->transform.IsIdentity()) { | 87 if (!it->transform.IsIdentity()) { |
85 display_list->CreateAndAppendItem<EndTransformDisplayItem>(); | 88 display_list->CreateAndAppendItem<EndTransformDisplayItem>(clip); |
86 } | 89 } |
87 } | 90 } |
88 | 91 |
89 if (fill_with_nonsolid_color_) { | 92 if (fill_with_nonsolid_color_) { |
90 gfx::Rect draw_rect = clip; | 93 gfx::Rect draw_rect = clip; |
91 bool red = true; | 94 bool red = true; |
92 while (!draw_rect.IsEmpty()) { | 95 while (!draw_rect.IsEmpty()) { |
93 SkPaint paint; | 96 SkPaint paint; |
94 paint.setColor(red ? SK_ColorRED : SK_ColorBLUE); | 97 paint.setColor(red ? SK_ColorRED : SK_ColorBLUE); |
95 canvas = | 98 canvas = |
96 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(draw_rect))); | 99 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(draw_rect))); |
97 canvas->drawIRect(gfx::RectToSkIRect(draw_rect), paint); | 100 canvas->drawIRect(gfx::RectToSkIRect(draw_rect), paint); |
98 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 101 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
99 auto* item = display_list->CreateAndAppendItem<DrawingDisplayItem>(); | 102 auto* item = |
| 103 display_list->CreateAndAppendItem<DrawingDisplayItem>(draw_rect); |
100 item->SetNew(std::move(picture)); | 104 item->SetNew(std::move(picture)); |
101 draw_rect.Inset(1, 1); | 105 draw_rect.Inset(1, 1); |
102 } | 106 } |
103 } | 107 } |
104 | 108 |
105 display_list->CreateAndAppendItem<EndClipDisplayItem>(); | 109 display_list->CreateAndAppendItem<EndClipDisplayItem>(clip); |
106 | 110 |
107 display_list->Finalize(); | 111 display_list->Finalize(); |
108 return display_list; | 112 return display_list; |
109 } | 113 } |
110 | 114 |
111 bool FakeContentLayerClient::FillsBoundsCompletely() const { return false; } | 115 bool FakeContentLayerClient::FillsBoundsCompletely() const { return false; } |
112 | 116 |
113 size_t FakeContentLayerClient::GetApproximateUnsharedMemoryUsage() const { | 117 size_t FakeContentLayerClient::GetApproximateUnsharedMemoryUsage() const { |
114 return reported_memory_usage_; | 118 return reported_memory_usage_; |
115 } | 119 } |
116 | 120 |
117 } // namespace cc | 121 } // namespace cc |
OLD | NEW |