cc: Adding DidFinishImplFrame to LTHI.
[chromium-blink-merge.git] / cc / resources / compositing_display_item.cc
blob15bd75cb380e9b42ec88b8143a162e9877247dcb
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"
14 namespace cc {
16 CompositingDisplayItem::CompositingDisplayItem(uint8_t alpha,
17 SkXfermode::Mode xfermode,
18 SkRect* bounds,
19 skia::RefPtr<SkColorFilter> cf)
20 : alpha_(alpha),
21 xfermode_(xfermode),
22 has_bounds_(!!bounds),
23 color_filter_(cf) {
24 if (bounds)
25 bounds_ = SkRect(*bounds);
28 CompositingDisplayItem::~CompositingDisplayItem() {
31 void CompositingDisplayItem::Raster(SkCanvas* canvas,
32 SkDrawPictureCallback* callback) const {
33 SkPaint paint;
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 {
41 return true;
44 int CompositingDisplayItem::ApproximateOpCount() const {
45 return 1;
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_));
58 if (has_bounds_)
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 {
73 canvas->restore();
76 bool EndCompositingDisplayItem::IsSuitableForGpuRasterization() const {
77 return true;
80 int EndCompositingDisplayItem::ApproximateOpCount() const {
81 return 0;
84 size_t EndCompositingDisplayItem::PictureMemoryUsage() const {
85 return 0;
88 void EndCompositingDisplayItem::AsValueInto(
89 base::trace_event::TracedValue* array) const {
90 array->AppendString("EndCompositingDisplayItem");
93 } // namespace cc