Use multiline attribute to check for IA2_STATE_MULTILINE.
[chromium-blink-merge.git] / cc / resources / clip_display_item.cc
blobb124ba1a1a77c08fd6d3a01175dd601b31dfdea6
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/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(gfx::Rect clip_rect,
17 const std::vector<SkRRect>& rounded_clip_rects)
18 : clip_rect_(clip_rect), rounded_clip_rects_(rounded_clip_rects) {
21 ClipDisplayItem::~ClipDisplayItem() {
24 void ClipDisplayItem::Raster(SkCanvas* canvas,
25 SkDrawPictureCallback* callback) const {
26 canvas->save();
27 canvas->clipRect(SkRect::MakeXYWH(clip_rect_.x(), clip_rect_.y(),
28 clip_rect_.width(), clip_rect_.height()));
29 for (size_t i = 0; i < rounded_clip_rects_.size(); ++i) {
30 if (rounded_clip_rects_[i].isRect()) {
31 canvas->clipRect(rounded_clip_rects_[i].rect());
32 } else {
33 bool antialiased = true;
34 canvas->clipRRect(rounded_clip_rects_[i], SkRegion::kIntersect_Op,
35 antialiased);
40 bool ClipDisplayItem::IsSuitableForGpuRasterization() const {
41 return true;
44 int ClipDisplayItem::ApproximateOpCount() const {
45 return 1;
48 size_t ClipDisplayItem::PictureMemoryUsage() const {
49 size_t total_size = sizeof(gfx::Rect);
50 for (size_t i = 0; i < rounded_clip_rects_.size(); ++i) {
51 total_size += sizeof(rounded_clip_rects_[i]);
53 return total_size;
56 void ClipDisplayItem::AsValueInto(base::trace_event::TracedValue* array) const {
57 std::string value = base::StringPrintf("ClipDisplayItem rect: [%s]",
58 clip_rect_.ToString().c_str());
59 for (const SkRRect& rounded_rect : rounded_clip_rects_) {
60 base::StringAppendF(
61 &value, " rounded_rect: [rect: [%s]",
62 gfx::SkRectToRectF(rounded_rect.rect()).ToString().c_str());
63 base::StringAppendF(&value, " radii: [");
64 SkVector upper_left_radius = rounded_rect.radii(SkRRect::kUpperLeft_Corner);
65 base::StringAppendF(&value, "[%f,%f],", upper_left_radius.x(),
66 upper_left_radius.y());
67 SkVector upper_right_radius =
68 rounded_rect.radii(SkRRect::kUpperRight_Corner);
69 base::StringAppendF(&value, " [%f,%f],", upper_right_radius.x(),
70 upper_right_radius.y());
71 SkVector lower_right_radius =
72 rounded_rect.radii(SkRRect::kLowerRight_Corner);
73 base::StringAppendF(&value, " [%f,%f],", lower_right_radius.x(),
74 lower_right_radius.y());
75 SkVector lower_left_radius = rounded_rect.radii(SkRRect::kLowerLeft_Corner);
76 base::StringAppendF(&value, " [%f,%f]]", lower_left_radius.x(),
77 lower_left_radius.y());
79 array->AppendString(value);
82 EndClipDisplayItem::EndClipDisplayItem() {
85 EndClipDisplayItem::~EndClipDisplayItem() {
88 void EndClipDisplayItem::Raster(SkCanvas* canvas,
89 SkDrawPictureCallback* callback) const {
90 canvas->restore();
93 bool EndClipDisplayItem::IsSuitableForGpuRasterization() const {
94 return true;
97 int EndClipDisplayItem::ApproximateOpCount() const {
98 return 0;
101 size_t EndClipDisplayItem::PictureMemoryUsage() const {
102 return 0;
105 void EndClipDisplayItem::AsValueInto(
106 base::trace_event::TracedValue* array) const {
107 array->AppendString("EndClipDisplayItem");
110 } // namespace cc