Landing Recent QUIC changes until 8/19/2015 17:00 UTC.
[chromium-blink-merge.git] / cc / playback / clip_display_item.cc
blob5941502860bff21cff6723c64fbcc42c13e83574
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/playback/clip_display_item.h"
7 #include <string>
9 #include "base/strings/stringprintf.h"
10 #include "base/trace_event/trace_event_argument.h"
11 #include "third_party/skia/include/core/SkCanvas.h"
12 #include "ui/gfx/skia_util.h"
14 namespace cc {
16 ClipDisplayItem::ClipDisplayItem() {
19 ClipDisplayItem::~ClipDisplayItem() {
22 void ClipDisplayItem::SetNew(gfx::Rect clip_rect,
23 const std::vector<SkRRect>& rounded_clip_rects) {
24 clip_rect_ = clip_rect;
25 rounded_clip_rects_ = rounded_clip_rects;
27 size_t external_memory_usage =
28 rounded_clip_rects_.capacity() * sizeof(rounded_clip_rects_[0]);
30 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 1 /* op_count */,
31 external_memory_usage);
34 void ClipDisplayItem::Raster(SkCanvas* canvas,
35 const gfx::Rect& canvas_target_playback_rect,
36 SkPicture::AbortCallback* callback) const {
37 canvas->save();
38 canvas->clipRect(SkRect::MakeXYWH(clip_rect_.x(), clip_rect_.y(),
39 clip_rect_.width(), clip_rect_.height()));
40 for (size_t i = 0; i < rounded_clip_rects_.size(); ++i) {
41 if (rounded_clip_rects_[i].isRect()) {
42 canvas->clipRect(rounded_clip_rects_[i].rect());
43 } else {
44 bool antialiased = true;
45 canvas->clipRRect(rounded_clip_rects_[i], SkRegion::kIntersect_Op,
46 antialiased);
51 void ClipDisplayItem::AsValueInto(base::trace_event::TracedValue* array) const {
52 std::string value = base::StringPrintf("ClipDisplayItem rect: [%s]",
53 clip_rect_.ToString().c_str());
54 for (const SkRRect& rounded_rect : rounded_clip_rects_) {
55 base::StringAppendF(
56 &value, " rounded_rect: [rect: [%s]",
57 gfx::SkRectToRectF(rounded_rect.rect()).ToString().c_str());
58 base::StringAppendF(&value, " radii: [");
59 SkVector upper_left_radius = rounded_rect.radii(SkRRect::kUpperLeft_Corner);
60 base::StringAppendF(&value, "[%f,%f],", upper_left_radius.x(),
61 upper_left_radius.y());
62 SkVector upper_right_radius =
63 rounded_rect.radii(SkRRect::kUpperRight_Corner);
64 base::StringAppendF(&value, " [%f,%f],", upper_right_radius.x(),
65 upper_right_radius.y());
66 SkVector lower_right_radius =
67 rounded_rect.radii(SkRRect::kLowerRight_Corner);
68 base::StringAppendF(&value, " [%f,%f],", lower_right_radius.x(),
69 lower_right_radius.y());
70 SkVector lower_left_radius = rounded_rect.radii(SkRRect::kLowerLeft_Corner);
71 base::StringAppendF(&value, " [%f,%f]]", lower_left_radius.x(),
72 lower_left_radius.y());
74 array->AppendString(value);
77 EndClipDisplayItem::EndClipDisplayItem() {
78 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 0 /* op_count */,
79 0 /* external_memory_usage */);
82 EndClipDisplayItem::~EndClipDisplayItem() {
85 void EndClipDisplayItem::Raster(SkCanvas* canvas,
86 const gfx::Rect& canvas_target_playback_rect,
87 SkPicture::AbortCallback* callback) const {
88 canvas->restore();
91 void EndClipDisplayItem::AsValueInto(
92 base::trace_event::TracedValue* array) const {
93 array->AppendString("EndClipDisplayItem");
96 } // namespace cc