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/resources/clip_display_item.h"
11 #include "cc/resources/clip_path_display_item.h"
12 #include "cc/resources/compositing_display_item.h"
13 #include "cc/resources/drawing_display_item.h"
14 #include "cc/resources/filter_display_item.h"
15 #include "cc/resources/float_clip_display_item.h"
16 #include "cc/resources/transform_display_item.h"
17 #include "skia/ext/refptr.h"
18 #include "third_party/WebKit/public/platform/WebFloatRect.h"
19 #include "third_party/WebKit/public/platform/WebRect.h"
20 #include "third_party/skia/include/core/SkColorFilter.h"
21 #include "third_party/skia/include/core/SkPicture.h"
22 #include "third_party/skia/include/utils/SkMatrix44.h"
23 #include "ui/gfx/geometry/safe_integer_conversions.h"
24 #include "ui/gfx/transform.h"
28 WebDisplayItemListImpl::WebDisplayItemListImpl(
29 cc::DisplayItemList
* display_list
)
30 : display_item_list_(display_list
) {
33 void WebDisplayItemListImpl::appendDrawingItem(const SkPicture
* picture
) {
34 display_item_list_
->AppendItem(cc::DrawingDisplayItem::Create(
35 skia::SharePtr(const_cast<SkPicture
*>(picture
))));
38 void WebDisplayItemListImpl::appendClipItem(
39 const blink::WebRect
& clip_rect
,
40 const blink::WebVector
<SkRRect
>& rounded_clip_rects
) {
41 std::vector
<SkRRect
> rounded_rects
;
42 for (size_t i
= 0; i
< rounded_clip_rects
.size(); ++i
) {
43 rounded_rects
.push_back(rounded_clip_rects
[i
]);
45 display_item_list_
->AppendItem(
46 cc::ClipDisplayItem::Create(clip_rect
, rounded_rects
));
49 void WebDisplayItemListImpl::appendEndClipItem() {
50 display_item_list_
->AppendItem(cc::EndClipDisplayItem::Create());
53 void WebDisplayItemListImpl::appendClipPathItem(const SkPath
& clip_path
,
56 display_item_list_
->AppendItem(
57 cc::ClipPathDisplayItem::Create(clip_path
, clip_op
, antialias
));
60 void WebDisplayItemListImpl::appendEndClipPathItem() {
61 display_item_list_
->AppendItem(cc::EndClipPathDisplayItem::Create());
64 void WebDisplayItemListImpl::appendFloatClipItem(
65 const blink::WebFloatRect
& clip_rect
) {
66 display_item_list_
->AppendItem(cc::FloatClipDisplayItem::Create(clip_rect
));
69 void WebDisplayItemListImpl::appendEndFloatClipItem() {
70 display_item_list_
->AppendItem(cc::EndFloatClipDisplayItem::Create());
73 void WebDisplayItemListImpl::appendTransformItem(const SkMatrix44
& matrix
) {
74 gfx::Transform transform
;
75 transform
.matrix() = matrix
;
76 display_item_list_
->AppendItem(cc::TransformDisplayItem::Create(transform
));
79 void WebDisplayItemListImpl::appendEndTransformItem() {
80 display_item_list_
->AppendItem(cc::EndTransformDisplayItem::Create());
83 void WebDisplayItemListImpl::appendCompositingItem(
85 SkXfermode::Mode xfermode
,
87 SkColorFilter
* color_filter
) {
88 DCHECK_GE(opacity
, 0.f
);
89 DCHECK_LE(opacity
, 1.f
);
90 // TODO(ajuma): This should really be rounding instead of flooring the alpha
91 // value, but that breaks slimming paint reftests.
92 display_item_list_
->AppendItem(cc::CompositingDisplayItem::Create(
93 static_cast<uint8_t>(gfx::ToFlooredInt(255 * opacity
)), xfermode
, bounds
,
94 skia::SharePtr(color_filter
)));
97 void WebDisplayItemListImpl::appendEndCompositingItem() {
98 display_item_list_
->AppendItem(cc::EndCompositingDisplayItem::Create());
101 void WebDisplayItemListImpl::appendFilterItem(
102 const blink::WebFilterOperations
& filters
,
103 const blink::WebFloatRect
& bounds
) {
104 const WebFilterOperationsImpl
& filters_impl
=
105 static_cast<const WebFilterOperationsImpl
&>(filters
);
106 display_item_list_
->AppendItem(
107 cc::FilterDisplayItem::Create(filters_impl
.AsFilterOperations(), bounds
));
110 void WebDisplayItemListImpl::appendEndFilterItem() {
111 display_item_list_
->AppendItem(cc::EndFilterDisplayItem::Create());
114 void WebDisplayItemListImpl::appendScrollItem(
115 const blink::WebSize
& scrollOffset
,
118 matrix
.setTranslate(-scrollOffset
.width
, -scrollOffset
.height
, 0);
119 appendTransformItem(matrix
);
122 void WebDisplayItemListImpl::appendEndScrollItem() {
123 appendEndTransformItem();
126 WebDisplayItemListImpl::~WebDisplayItemListImpl() {
129 } // namespace cc_blink