cc: Separate the priority from the tile and put in new PrioritizedTile
[chromium-blink-merge.git] / cc / resources / compositing_display_item.cc
blobac476fa39e9c8a8aa0de6fb0dabfa95590fe8898
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() {
19 CompositingDisplayItem::~CompositingDisplayItem() {
22 void CompositingDisplayItem::SetNew(uint8_t alpha,
23 SkXfermode::Mode xfermode,
24 SkRect* bounds,
25 skia::RefPtr<SkColorFilter> cf) {
26 alpha_ = alpha;
27 xfermode_ = xfermode;
28 has_bounds_ = !!bounds;
29 if (bounds)
30 bounds_ = SkRect(*bounds);
31 color_filter_ = cf;
33 // TODO(pdr): Include color_filter's memory here.
34 size_t memory_usage =
35 sizeof(float) + sizeof(bool) + sizeof(SkRect) + sizeof(SkXfermode::Mode);
36 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 1 /* op_count */,
37 memory_usage);
40 void CompositingDisplayItem::Raster(SkCanvas* canvas,
41 SkDrawPictureCallback* callback) const {
42 SkPaint paint;
43 paint.setXfermodeMode(xfermode_);
44 paint.setAlpha(alpha_);
45 paint.setColorFilter(color_filter_.get());
46 canvas->saveLayer(has_bounds_ ? &bounds_ : nullptr, &paint);
49 void CompositingDisplayItem::AsValueInto(
50 base::trace_event::TracedValue* array) const {
51 array->AppendString(base::StringPrintf(
52 "CompositingDisplayItem alpha: %d, xfermode: %d", alpha_, xfermode_));
53 if (has_bounds_)
54 array->AppendString(base::StringPrintf(
55 ", bounds: [%f, %f, %f, %f]", static_cast<float>(bounds_.x()),
56 static_cast<float>(bounds_.y()), static_cast<float>(bounds_.width()),
57 static_cast<float>(bounds_.height())));
60 EndCompositingDisplayItem::EndCompositingDisplayItem() {
61 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 0 /* op_count */,
62 0 /* memory_usage */);
65 EndCompositingDisplayItem::~EndCompositingDisplayItem() {
68 void EndCompositingDisplayItem::Raster(SkCanvas* canvas,
69 SkDrawPictureCallback* callback) const {
70 canvas->restore();
73 void EndCompositingDisplayItem::AsValueInto(
74 base::trace_event::TracedValue* array) const {
75 array->AppendString("EndCompositingDisplayItem");
78 } // namespace cc