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_blend_mode.h"
10 #include "cc/blink/web_filter_operations_impl.h"
11 #include "cc/resources/clip_display_item.h"
12 #include "cc/resources/clip_path_display_item.h"
13 #include "cc/resources/compositing_display_item.h"
14 #include "cc/resources/drawing_display_item.h"
15 #include "cc/resources/filter_display_item.h"
16 #include "cc/resources/float_clip_display_item.h"
17 #include "cc/resources/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/SkImageFilter.h"
23 #include "third_party/skia/include/core/SkPicture.h"
24 #include "third_party/skia/include/utils/SkMatrix44.h"
25 #include "ui/gfx/transform.h"
29 WebDisplayItemListImpl::WebDisplayItemListImpl()
30 : display_item_list_(cc::DisplayItemList::Create()) {
33 scoped_refptr
<cc::DisplayItemList
> WebDisplayItemListImpl::ToDisplayItemList() {
34 return display_item_list_
;
37 void WebDisplayItemListImpl::appendDrawingItem(const SkPicture
* picture
) {
38 display_item_list_
->AppendItem(cc::DrawingDisplayItem::Create(
39 skia::SharePtr(const_cast<SkPicture
*>(picture
))));
42 void WebDisplayItemListImpl::appendClipItem(
43 const blink::WebRect
& clip_rect
,
44 const blink::WebVector
<SkRRect
>& rounded_clip_rects
) {
45 std::vector
<SkRRect
> rounded_rects
;
46 for (size_t i
= 0; i
< rounded_clip_rects
.size(); ++i
) {
47 rounded_rects
.push_back(rounded_clip_rects
[i
]);
49 display_item_list_
->AppendItem(
50 cc::ClipDisplayItem::Create(clip_rect
, rounded_rects
));
53 void WebDisplayItemListImpl::appendEndClipItem() {
54 display_item_list_
->AppendItem(cc::EndClipDisplayItem::Create());
57 void WebDisplayItemListImpl::appendClipPathItem(const SkPath
& clip_path
,
60 display_item_list_
->AppendItem(
61 cc::ClipPathDisplayItem::Create(clip_path
, clip_op
, antialias
));
64 void WebDisplayItemListImpl::appendEndClipPathItem() {
65 display_item_list_
->AppendItem(cc::EndClipPathDisplayItem::Create());
68 void WebDisplayItemListImpl::appendFloatClipItem(
69 const blink::WebFloatRect
& clip_rect
) {
70 display_item_list_
->AppendItem(cc::FloatClipDisplayItem::Create(clip_rect
));
73 void WebDisplayItemListImpl::appendEndFloatClipItem() {
74 display_item_list_
->AppendItem(cc::EndFloatClipDisplayItem::Create());
77 void WebDisplayItemListImpl::appendTransformItem(const SkMatrix44
& matrix
) {
78 gfx::Transform transform
;
79 transform
.matrix() = matrix
;
80 display_item_list_
->AppendItem(cc::TransformDisplayItem::Create(transform
));
83 void WebDisplayItemListImpl::appendEndTransformItem() {
84 display_item_list_
->AppendItem(cc::EndTransformDisplayItem::Create());
87 // TODO(pdr): Remove this once the blink-side callers have been removed.
88 void WebDisplayItemListImpl::appendCompositingItem(
90 SkXfermode::Mode xfermode
,
91 SkColorFilter
* color_filter
) {
92 appendCompositingItem(opacity
, xfermode
, nullptr, color_filter
);
95 void WebDisplayItemListImpl::appendCompositingItem(
97 SkXfermode::Mode xfermode
,
99 SkColorFilter
* color_filter
) {
100 display_item_list_
->AppendItem(cc::CompositingDisplayItem::Create(
101 opacity
, xfermode
, bounds
, skia::SharePtr(color_filter
)));
104 void WebDisplayItemListImpl::appendEndCompositingItem() {
105 display_item_list_
->AppendItem(cc::EndCompositingDisplayItem::Create());
108 void WebDisplayItemListImpl::appendFilterItem(
109 const blink::WebFilterOperations
& filters
,
110 const blink::WebFloatRect
& bounds
) {
111 const WebFilterOperationsImpl
& filters_impl
=
112 static_cast<const WebFilterOperationsImpl
&>(filters
);
113 display_item_list_
->AppendItem(
114 cc::FilterDisplayItem::Create(filters_impl
.AsFilterOperations(), bounds
));
117 void WebDisplayItemListImpl::appendEndFilterItem() {
118 display_item_list_
->AppendItem(cc::EndFilterDisplayItem::Create());
121 void WebDisplayItemListImpl::appendScrollItem(
122 const blink::WebSize
& scrollOffset
,
125 matrix
.setTranslate(-scrollOffset
.width
, -scrollOffset
.height
, 0);
126 appendTransformItem(matrix
);
129 void WebDisplayItemListImpl::appendEndScrollItem() {
130 appendEndTransformItem();
133 WebDisplayItemListImpl::~WebDisplayItemListImpl() {
136 } // namespace cc_blink