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
) {
50 display_item_list_
->CreateAndAppendItem
<cc::DrawingDisplayItem
>();
51 item
->SetNew(skia::SharePtr(const_cast<SkPicture
*>(picture
)));
54 void WebDisplayItemListImpl::appendClipItem(
55 const blink::WebRect
& clip_rect
,
56 const blink::WebVector
<SkRRect
>& rounded_clip_rects
) {
57 std::vector
<SkRRect
> rounded_rects
;
58 for (size_t i
= 0; i
< rounded_clip_rects
.size(); ++i
) {
59 rounded_rects
.push_back(rounded_clip_rects
[i
]);
61 auto* item
= display_item_list_
->CreateAndAppendItem
<cc::ClipDisplayItem
>();
62 item
->SetNew(clip_rect
, rounded_rects
);
65 void WebDisplayItemListImpl::appendEndClipItem() {
66 display_item_list_
->CreateAndAppendItem
<cc::EndClipDisplayItem
>();
69 void WebDisplayItemListImpl::appendClipPathItem(const SkPath
& clip_path
,
73 display_item_list_
->CreateAndAppendItem
<cc::ClipPathDisplayItem
>();
74 item
->SetNew(clip_path
, clip_op
, antialias
);
77 void WebDisplayItemListImpl::appendEndClipPathItem() {
78 display_item_list_
->CreateAndAppendItem
<cc::EndClipPathDisplayItem
>();
81 void WebDisplayItemListImpl::appendFloatClipItem(
82 const blink::WebFloatRect
& clip_rect
) {
84 display_item_list_
->CreateAndAppendItem
<cc::FloatClipDisplayItem
>();
85 item
->SetNew(clip_rect
);
88 void WebDisplayItemListImpl::appendEndFloatClipItem() {
89 display_item_list_
->CreateAndAppendItem
<cc::EndFloatClipDisplayItem
>();
92 void WebDisplayItemListImpl::appendTransformItem(const SkMatrix44
& matrix
) {
93 gfx::Transform transform
;
94 transform
.matrix() = matrix
;
96 display_item_list_
->CreateAndAppendItem
<cc::TransformDisplayItem
>();
97 item
->SetNew(transform
);
100 void WebDisplayItemListImpl::appendEndTransformItem() {
101 display_item_list_
->CreateAndAppendItem
<cc::EndTransformDisplayItem
>();
104 void WebDisplayItemListImpl::appendCompositingItem(
106 SkXfermode::Mode xfermode
,
108 SkColorFilter
* color_filter
) {
109 DCHECK_GE(opacity
, 0.f
);
110 DCHECK_LE(opacity
, 1.f
);
111 // TODO(ajuma): This should really be rounding instead of flooring the alpha
112 // value, but that breaks slimming paint reftests.
114 display_item_list_
->CreateAndAppendItem
<cc::CompositingDisplayItem
>();
115 item
->SetNew(static_cast<uint8_t>(gfx::ToFlooredInt(255 * opacity
)), xfermode
,
116 bounds
, skia::SharePtr(color_filter
));
119 void WebDisplayItemListImpl::appendEndCompositingItem() {
120 display_item_list_
->CreateAndAppendItem
<cc::EndCompositingDisplayItem
>();
123 void WebDisplayItemListImpl::appendFilterItem(
124 const blink::WebFilterOperations
& filters
,
125 const blink::WebFloatRect
& bounds
) {
126 const WebFilterOperationsImpl
& filters_impl
=
127 static_cast<const WebFilterOperationsImpl
&>(filters
);
128 auto* item
= display_item_list_
->CreateAndAppendItem
<cc::FilterDisplayItem
>();
129 item
->SetNew(filters_impl
.AsFilterOperations(), bounds
);
132 void WebDisplayItemListImpl::appendEndFilterItem() {
133 display_item_list_
->CreateAndAppendItem
<cc::EndFilterDisplayItem
>();
136 void WebDisplayItemListImpl::appendScrollItem(
137 const blink::WebSize
& scrollOffset
,
140 matrix
.setTranslate(-scrollOffset
.width
, -scrollOffset
.height
, 0);
141 appendTransformItem(matrix
);
144 void WebDisplayItemListImpl::appendEndScrollItem() {
145 appendEndTransformItem();
148 WebDisplayItemListImpl::~WebDisplayItemListImpl() {
151 } // namespace cc_blink