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
3 // found in the LICENSE file.
5 #include "cc/blink/web_display_item_list_impl.h"
9 #include "cc/blink/web_filter_operations_impl.h"
10 #include "cc/playback/clip_display_item.h"
11 #include "cc/playback/clip_path_display_item.h"
12 #include "cc/playback/compositing_display_item.h"
13 #include "cc/playback/display_item_list_settings.h"
14 #include "cc/playback/drawing_display_item.h"
15 #include "cc/playback/filter_display_item.h"
16 #include "cc/playback/float_clip_display_item.h"
17 #include "cc/playback/transform_display_item.h"
18 #include "skia/ext/refptr.h"
19 #include "third_party/WebKit/public/platform/WebFloatRect.h"
20 #include "third_party/WebKit/public/platform/WebRect.h"
21 #include "third_party/skia/include/core/SkColorFilter.h"
22 #include "third_party/skia/include/core/SkPicture.h"
23 #include "third_party/skia/include/utils/SkMatrix44.h"
24 #include "ui/gfx/geometry/safe_integer_conversions.h"
25 #include "ui/gfx/transform.h"
31 scoped_refptr
<cc::DisplayItemList
> CreateUncachedDisplayItemListForBlink() {
32 cc::DisplayItemListSettings settings
;
33 settings
.use_cached_picture
= false;
34 return cc::DisplayItemList::CreateWithoutCachedPicture(settings
);
39 WebDisplayItemListImpl::WebDisplayItemListImpl()
40 : display_item_list_(CreateUncachedDisplayItemListForBlink()) {
43 WebDisplayItemListImpl::WebDisplayItemListImpl(
44 cc::DisplayItemList
* display_list
)
45 : display_item_list_(display_list
) {
48 void WebDisplayItemListImpl::appendDrawingItem(const SkPicture
* picture
) {
49 if (display_item_list_
->RetainsIndividualDisplayItems()) {
51 display_item_list_
->CreateAndAppendItem
<cc::DrawingDisplayItem
>();
52 item
->SetNew(skia::SharePtr(const_cast<SkPicture
*>(picture
)));
54 cc::DrawingDisplayItem item
;
55 item
.SetNew(skia::SharePtr(const_cast<SkPicture
*>(picture
)));
56 display_item_list_
->RasterIntoCanvas(item
);
60 void WebDisplayItemListImpl::appendClipItem(
61 const blink::WebRect
& clip_rect
,
62 const blink::WebVector
<SkRRect
>& rounded_clip_rects
) {
63 std::vector
<SkRRect
> rounded_rects
;
64 for (size_t i
= 0; i
< rounded_clip_rects
.size(); ++i
) {
65 rounded_rects
.push_back(rounded_clip_rects
[i
]);
67 if (display_item_list_
->RetainsIndividualDisplayItems()) {
68 auto* item
= display_item_list_
->CreateAndAppendItem
<cc::ClipDisplayItem
>();
69 item
->SetNew(clip_rect
, rounded_rects
);
71 cc::ClipDisplayItem item
;
72 item
.SetNew(clip_rect
, rounded_rects
);
73 display_item_list_
->RasterIntoCanvas(item
);
77 void WebDisplayItemListImpl::appendEndClipItem() {
78 if (display_item_list_
->RetainsIndividualDisplayItems()) {
79 display_item_list_
->CreateAndAppendItem
<cc::EndClipDisplayItem
>();
81 display_item_list_
->RasterIntoCanvas(cc::EndClipDisplayItem());
85 void WebDisplayItemListImpl::appendClipPathItem(const SkPath
& clip_path
,
88 if (display_item_list_
->RetainsIndividualDisplayItems()) {
90 display_item_list_
->CreateAndAppendItem
<cc::ClipPathDisplayItem
>();
91 item
->SetNew(clip_path
, clip_op
, antialias
);
93 cc::ClipPathDisplayItem item
;
94 item
.SetNew(clip_path
, clip_op
, antialias
);
95 display_item_list_
->RasterIntoCanvas(item
);
99 void WebDisplayItemListImpl::appendEndClipPathItem() {
100 if (display_item_list_
->RetainsIndividualDisplayItems()) {
101 display_item_list_
->CreateAndAppendItem
<cc::EndClipPathDisplayItem
>();
103 display_item_list_
->RasterIntoCanvas(cc::EndClipPathDisplayItem());
107 void WebDisplayItemListImpl::appendFloatClipItem(
108 const blink::WebFloatRect
& clip_rect
) {
109 if (display_item_list_
->RetainsIndividualDisplayItems()) {
111 display_item_list_
->CreateAndAppendItem
<cc::FloatClipDisplayItem
>();
112 item
->SetNew(clip_rect
);
114 cc::FloatClipDisplayItem item
;
115 item
.SetNew(clip_rect
);
116 display_item_list_
->RasterIntoCanvas(item
);
120 void WebDisplayItemListImpl::appendEndFloatClipItem() {
121 if (display_item_list_
->RetainsIndividualDisplayItems()) {
122 display_item_list_
->CreateAndAppendItem
<cc::EndFloatClipDisplayItem
>();
124 display_item_list_
->RasterIntoCanvas(cc::EndFloatClipDisplayItem());
128 void WebDisplayItemListImpl::appendTransformItem(const SkMatrix44
& matrix
) {
129 gfx::Transform transform
;
130 transform
.matrix() = matrix
;
132 if (display_item_list_
->RetainsIndividualDisplayItems()) {
134 display_item_list_
->CreateAndAppendItem
<cc::TransformDisplayItem
>();
135 item
->SetNew(transform
);
137 cc::TransformDisplayItem item
;
138 item
.SetNew(transform
);
139 display_item_list_
->RasterIntoCanvas(item
);
143 void WebDisplayItemListImpl::appendEndTransformItem() {
144 if (display_item_list_
->RetainsIndividualDisplayItems()) {
145 display_item_list_
->CreateAndAppendItem
<cc::EndTransformDisplayItem
>();
147 display_item_list_
->RasterIntoCanvas(cc::EndTransformDisplayItem());
151 void WebDisplayItemListImpl::appendCompositingItem(
153 SkXfermode::Mode xfermode
,
155 SkColorFilter
* color_filter
) {
156 DCHECK_GE(opacity
, 0.f
);
157 DCHECK_LE(opacity
, 1.f
);
158 // TODO(ajuma): This should really be rounding instead of flooring the alpha
159 // value, but that breaks slimming paint reftests.
161 if (display_item_list_
->RetainsIndividualDisplayItems()) {
163 display_item_list_
->CreateAndAppendItem
<cc::CompositingDisplayItem
>();
164 item
->SetNew(static_cast<uint8_t>(gfx::ToFlooredInt(255 * opacity
)),
165 xfermode
, bounds
, skia::SharePtr(color_filter
));
167 cc::CompositingDisplayItem item
;
168 item
.SetNew(static_cast<uint8_t>(gfx::ToFlooredInt(255 * opacity
)),
169 xfermode
, bounds
, skia::SharePtr(color_filter
));
170 display_item_list_
->RasterIntoCanvas(item
);
174 void WebDisplayItemListImpl::appendEndCompositingItem() {
175 if (display_item_list_
->RetainsIndividualDisplayItems()) {
176 display_item_list_
->CreateAndAppendItem
<cc::EndCompositingDisplayItem
>();
178 display_item_list_
->RasterIntoCanvas(cc::EndCompositingDisplayItem());
182 void WebDisplayItemListImpl::appendFilterItem(
183 const blink::WebFilterOperations
& filters
,
184 const blink::WebFloatRect
& bounds
) {
185 const WebFilterOperationsImpl
& filters_impl
=
186 static_cast<const WebFilterOperationsImpl
&>(filters
);
188 if (display_item_list_
->RetainsIndividualDisplayItems()) {
190 display_item_list_
->CreateAndAppendItem
<cc::FilterDisplayItem
>();
191 item
->SetNew(filters_impl
.AsFilterOperations(), bounds
);
193 cc::FilterDisplayItem item
;
194 item
.SetNew(filters_impl
.AsFilterOperations(), bounds
);
195 display_item_list_
->RasterIntoCanvas(item
);
199 void WebDisplayItemListImpl::appendEndFilterItem() {
200 if (display_item_list_
->RetainsIndividualDisplayItems()) {
201 display_item_list_
->CreateAndAppendItem
<cc::EndFilterDisplayItem
>();
203 display_item_list_
->RasterIntoCanvas(cc::EndFilterDisplayItem());
207 void WebDisplayItemListImpl::appendScrollItem(
208 const blink::WebSize
& scrollOffset
,
211 matrix
.setTranslate(-scrollOffset
.width
, -scrollOffset
.height
, 0);
212 appendTransformItem(matrix
);
215 void WebDisplayItemListImpl::appendEndScrollItem() {
216 appendEndTransformItem();
219 WebDisplayItemListImpl::~WebDisplayItemListImpl() {
222 } // namespace cc_blink