Update V8 to version 4.7.37.
[chromium-blink-merge.git] / cc / playback / compositing_display_item.cc
blob31365b5881c22392077744219f114eca52d6c179
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"
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 external_memory_usage = 0;
35 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 1 /* op_count */,
36 external_memory_usage);
39 void CompositingDisplayItem::Raster(
40 SkCanvas* canvas,
41 const gfx::Rect& canvas_target_playback_rect,
42 SkPicture::AbortCallback* callback) const {
43 SkPaint paint;
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_));
54 if (has_bounds_)
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(
70 SkCanvas* canvas,
71 const gfx::Rect& canvas_target_playback_rect,
72 SkPicture::AbortCallback* callback) const {
73 canvas->restore();
76 void EndCompositingDisplayItem::AsValueInto(
77 base::trace_event::TracedValue* array) const {
78 array->AppendString("EndCompositingDisplayItem");
81 } // namespace cc