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/resources/transparency_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 TransparencyDisplayItem::TransparencyDisplayItem(float opacity
,
17 SkXfermode::Mode blend_mode
)
18 : opacity_(opacity
), blend_mode_(blend_mode
) {
21 TransparencyDisplayItem::~TransparencyDisplayItem() {
24 void TransparencyDisplayItem::Raster(SkCanvas
* canvas
,
25 SkDrawPictureCallback
* callback
) const {
27 paint
.setXfermodeMode(blend_mode_
);
28 paint
.setAlpha(opacity_
* 255);
29 canvas
->saveLayer(NULL
, &paint
);
32 bool TransparencyDisplayItem::IsSuitableForGpuRasterization() const {
36 int TransparencyDisplayItem::ApproximateOpCount() const {
40 size_t TransparencyDisplayItem::PictureMemoryUsage() const {
41 return sizeof(float) + sizeof(SkXfermode::Mode
);
44 void TransparencyDisplayItem::AsValueInto(
45 base::trace_event::TracedValue
* array
) const {
47 base::StringPrintf("TransparencyDisplayItem opacity: %f, blend_mode: %d",
48 opacity_
, blend_mode_
));
51 EndTransparencyDisplayItem::EndTransparencyDisplayItem() {
54 EndTransparencyDisplayItem::~EndTransparencyDisplayItem() {
57 void EndTransparencyDisplayItem::Raster(SkCanvas
* canvas
,
58 SkDrawPictureCallback
* callback
) const {
62 bool EndTransparencyDisplayItem::IsSuitableForGpuRasterization() const {
66 int EndTransparencyDisplayItem::ApproximateOpCount() const {
70 size_t EndTransparencyDisplayItem::PictureMemoryUsage() const {
74 void EndTransparencyDisplayItem::AsValueInto(
75 base::trace_event::TracedValue
* array
) const {
76 array
->AppendString("EndTransparencyDisplayItem");