1 // Copyright 2015 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/resources/compositing_display_item.h"
7 #include "base/strings/stringprintf.h"
8 #include "base/trace_event/trace_event_argument.h"
9 #include "third_party/skia/include/core/SkCanvas.h"
10 #include "third_party/skia/include/core/SkPaint.h"
11 #include "third_party/skia/include/core/SkXfermode.h"
12 #include "ui/gfx/skia_util.h"
16 CompositingDisplayItem::CompositingDisplayItem(uint8_t alpha
,
17 SkXfermode::Mode xfermode
,
19 skia::RefPtr
<SkColorFilter
> cf
)
22 has_bounds_(!!bounds
),
25 bounds_
= SkRect(*bounds
);
28 CompositingDisplayItem::~CompositingDisplayItem() {
31 void CompositingDisplayItem::Raster(SkCanvas
* canvas
,
32 SkDrawPictureCallback
* callback
) const {
34 paint
.setXfermodeMode(xfermode_
);
35 paint
.setAlpha(alpha_
);
36 paint
.setColorFilter(color_filter_
.get());
37 canvas
->saveLayer(has_bounds_
? &bounds_
: nullptr, &paint
);
40 bool CompositingDisplayItem::IsSuitableForGpuRasterization() const {
44 int CompositingDisplayItem::ApproximateOpCount() const {
48 size_t CompositingDisplayItem::PictureMemoryUsage() const {
49 // TODO(pdr): Include color_filter's memory here.
50 return sizeof(float) + sizeof(bool) + sizeof(SkRect
) +
51 sizeof(SkXfermode::Mode
);
54 void CompositingDisplayItem::AsValueInto(
55 base::trace_event::TracedValue
* array
) const {
56 array
->AppendString(base::StringPrintf(
57 "CompositingDisplayItem alpha: %d, xfermode: %d", alpha_
, xfermode_
));
59 array
->AppendString(base::StringPrintf(
60 ", bounds: [%f, %f, %f, %f]", static_cast<float>(bounds_
.x()),
61 static_cast<float>(bounds_
.y()), static_cast<float>(bounds_
.width()),
62 static_cast<float>(bounds_
.height())));
65 EndCompositingDisplayItem::EndCompositingDisplayItem() {
68 EndCompositingDisplayItem::~EndCompositingDisplayItem() {
71 void EndCompositingDisplayItem::Raster(SkCanvas
* canvas
,
72 SkDrawPictureCallback
* callback
) const {
76 bool EndCompositingDisplayItem::IsSuitableForGpuRasterization() const {
80 int EndCompositingDisplayItem::ApproximateOpCount() const {
84 size_t EndCompositingDisplayItem::PictureMemoryUsage() const {
88 void EndCompositingDisplayItem::AsValueInto(
89 base::trace_event::TracedValue
* array
) const {
90 array
->AppendString("EndCompositingDisplayItem");