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/playback/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() {
19 CompositingDisplayItem::~CompositingDisplayItem() {
22 void CompositingDisplayItem::SetNew(uint8_t alpha
,
23 SkXfermode::Mode xfermode
,
25 skia::RefPtr
<SkColorFilter
> cf
) {
28 has_bounds_
= !!bounds
;
30 bounds_
= SkRect(*bounds
);
33 // TODO(pdr): Include color_filter's memory here.
34 size_t external_memory_usage
= 0;
35 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 1 /* op_count */,
36 external_memory_usage
);
39 void CompositingDisplayItem::Raster(
41 const gfx::Rect
& canvas_target_playback_rect
,
42 SkPicture::AbortCallback
* callback
) const {
44 paint
.setXfermodeMode(xfermode_
);
45 paint
.setAlpha(alpha_
);
46 paint
.setColorFilter(color_filter_
.get());
47 canvas
->saveLayer(has_bounds_
? &bounds_
: nullptr, &paint
);
50 void CompositingDisplayItem::AsValueInto(
51 base::trace_event::TracedValue
* array
) const {
52 array
->AppendString(base::StringPrintf(
53 "CompositingDisplayItem alpha: %d, xfermode: %d", alpha_
, xfermode_
));
55 array
->AppendString(base::StringPrintf(
56 ", bounds: [%f, %f, %f, %f]", static_cast<float>(bounds_
.x()),
57 static_cast<float>(bounds_
.y()), static_cast<float>(bounds_
.width()),
58 static_cast<float>(bounds_
.height())));
61 EndCompositingDisplayItem::EndCompositingDisplayItem() {
62 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 0 /* op_count */,
63 0 /* external_memory_usage */);
66 EndCompositingDisplayItem::~EndCompositingDisplayItem() {
69 void EndCompositingDisplayItem::Raster(
71 const gfx::Rect
& canvas_target_playback_rect
,
72 SkPicture::AbortCallback
* callback
) const {
76 void EndCompositingDisplayItem::AsValueInto(
77 base::trace_event::TracedValue
* array
) const {
78 array
->AppendString("EndCompositingDisplayItem");