Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: cc/playback/clip_display_item.cc

Issue 1521373005: Revert of cc: Shrink size of display item (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/playback/clip_display_item.h ('k') | cc/playback/clip_path_display_item.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/playback/clip_display_item.h" 5 #include "cc/playback/clip_display_item.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
11 #include "base/trace_event/trace_event_argument.h" 11 #include "base/trace_event/trace_event_argument.h"
12 #include "cc/proto/display_item.pb.h" 12 #include "cc/proto/display_item.pb.h"
13 #include "cc/proto/gfx_conversions.h" 13 #include "cc/proto/gfx_conversions.h"
14 #include "cc/proto/skia_conversions.h" 14 #include "cc/proto/skia_conversions.h"
15 #include "third_party/skia/include/core/SkCanvas.h" 15 #include "third_party/skia/include/core/SkCanvas.h"
16 #include "ui/gfx/skia_util.h" 16 #include "ui/gfx/skia_util.h"
17 17
18 namespace cc { 18 namespace cc {
19 19
20 ClipDisplayItem::ClipDisplayItem( 20 ClipDisplayItem::ClipDisplayItem() {
21 const gfx::Rect& clip_rect,
22 const std::vector<SkRRect>& rounded_clip_rects) {
23 SetNew(clip_rect, rounded_clip_rects);
24 } 21 }
25 22
26 ClipDisplayItem::ClipDisplayItem(const proto::DisplayItem& proto) { 23 ClipDisplayItem::~ClipDisplayItem() {
24 }
25
26 void ClipDisplayItem::SetNew(gfx::Rect clip_rect,
27 const std::vector<SkRRect>& rounded_clip_rects) {
28 clip_rect_ = clip_rect;
29 rounded_clip_rects_ = rounded_clip_rects;
30
31 size_t external_memory_usage =
32 rounded_clip_rects_.capacity() * sizeof(rounded_clip_rects_[0]);
33
34 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 1 /* op_count */,
35 external_memory_usage);
36 }
37
38 void ClipDisplayItem::ToProtobuf(proto::DisplayItem* proto) const {
39 proto->set_type(proto::DisplayItem::Type_Clip);
40
41 proto::ClipDisplayItem* details = proto->mutable_clip_item();
42 RectToProto(clip_rect_, details->mutable_clip_rect());
43 DCHECK_EQ(0, details->rounded_rects_size());
44 for (const auto& rrect : rounded_clip_rects_) {
45 SkRRectToProto(rrect, details->add_rounded_rects());
46 }
47 }
48
49 void ClipDisplayItem::FromProtobuf(const proto::DisplayItem& proto) {
27 DCHECK_EQ(proto::DisplayItem::Type_Clip, proto.type()); 50 DCHECK_EQ(proto::DisplayItem::Type_Clip, proto.type());
28 51
29 const proto::ClipDisplayItem& details = proto.clip_item(); 52 const proto::ClipDisplayItem& details = proto.clip_item();
30 gfx::Rect clip_rect = ProtoToRect(details.clip_rect()); 53 gfx::Rect clip_rect = ProtoToRect(details.clip_rect());
31 std::vector<SkRRect> rounded_clip_rects; 54 std::vector<SkRRect> rounded_clip_rects;
32 rounded_clip_rects.reserve(details.rounded_rects_size()); 55 rounded_clip_rects.reserve(details.rounded_rects_size());
33 for (int i = 0; i < details.rounded_rects_size(); i++) { 56 for (int i = 0; i < details.rounded_rects_size(); i++) {
34 rounded_clip_rects.push_back(ProtoToSkRRect(details.rounded_rects(i))); 57 rounded_clip_rects.push_back(ProtoToSkRRect(details.rounded_rects(i)));
35 } 58 }
36 SetNew(clip_rect, rounded_clip_rects); 59 SetNew(clip_rect, rounded_clip_rects);
37 } 60 }
38 61
39 void ClipDisplayItem::SetNew(const gfx::Rect& clip_rect,
40 const std::vector<SkRRect>& rounded_clip_rects) {
41 clip_rect_ = clip_rect;
42 rounded_clip_rects_ = rounded_clip_rects;
43 }
44
45 ClipDisplayItem::~ClipDisplayItem() {}
46
47 void ClipDisplayItem::ToProtobuf(proto::DisplayItem* proto) const {
48 proto->set_type(proto::DisplayItem::Type_Clip);
49
50 proto::ClipDisplayItem* details = proto->mutable_clip_item();
51 RectToProto(clip_rect_, details->mutable_clip_rect());
52 DCHECK_EQ(0, details->rounded_rects_size());
53 for (const auto& rrect : rounded_clip_rects_) {
54 SkRRectToProto(rrect, details->add_rounded_rects());
55 }
56 }
57
58 void ClipDisplayItem::Raster(SkCanvas* canvas, 62 void ClipDisplayItem::Raster(SkCanvas* canvas,
59 const gfx::Rect& canvas_target_playback_rect, 63 const gfx::Rect& canvas_target_playback_rect,
60 SkPicture::AbortCallback* callback) const { 64 SkPicture::AbortCallback* callback) const {
61 canvas->save(); 65 canvas->save();
62 canvas->clipRect(SkRect::MakeXYWH(clip_rect_.x(), clip_rect_.y(), 66 canvas->clipRect(SkRect::MakeXYWH(clip_rect_.x(), clip_rect_.y(),
63 clip_rect_.width(), clip_rect_.height())); 67 clip_rect_.width(), clip_rect_.height()));
64 for (size_t i = 0; i < rounded_clip_rects_.size(); ++i) { 68 for (size_t i = 0; i < rounded_clip_rects_.size(); ++i) {
65 if (rounded_clip_rects_[i].isRect()) { 69 if (rounded_clip_rects_[i].isRect()) {
66 canvas->clipRect(rounded_clip_rects_[i].rect()); 70 canvas->clipRect(rounded_clip_rects_[i].rect());
67 } else { 71 } else {
(...skipping 25 matching lines...) Expand all
93 rounded_rect.radii(SkRRect::kLowerRight_Corner); 97 rounded_rect.radii(SkRRect::kLowerRight_Corner);
94 base::StringAppendF(&value, " [%f,%f],", lower_right_radius.x(), 98 base::StringAppendF(&value, " [%f,%f],", lower_right_radius.x(),
95 lower_right_radius.y()); 99 lower_right_radius.y());
96 SkVector lower_left_radius = rounded_rect.radii(SkRRect::kLowerLeft_Corner); 100 SkVector lower_left_radius = rounded_rect.radii(SkRRect::kLowerLeft_Corner);
97 base::StringAppendF(&value, " [%f,%f]]", lower_left_radius.x(), 101 base::StringAppendF(&value, " [%f,%f]]", lower_left_radius.x(),
98 lower_left_radius.y()); 102 lower_left_radius.y());
99 } 103 }
100 array->AppendString(value); 104 array->AppendString(value);
101 } 105 }
102 106
103 size_t ClipDisplayItem::ExternalMemoryUsage() const { 107 EndClipDisplayItem::EndClipDisplayItem() {
104 return rounded_clip_rects_.capacity() * sizeof(rounded_clip_rects_[0]); 108 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 0 /* op_count */,
105 } 109 0 /* external_memory_usage */);
106
107 EndClipDisplayItem::EndClipDisplayItem() {}
108
109 EndClipDisplayItem::EndClipDisplayItem(const proto::DisplayItem& proto) {
110 DCHECK_EQ(proto::DisplayItem::Type_EndClip, proto.type());
111 } 110 }
112 111
113 EndClipDisplayItem::~EndClipDisplayItem() { 112 EndClipDisplayItem::~EndClipDisplayItem() {
114 } 113 }
115 114
116 void EndClipDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { 115 void EndClipDisplayItem::ToProtobuf(proto::DisplayItem* proto) const {
117 proto->set_type(proto::DisplayItem::Type_EndClip); 116 proto->set_type(proto::DisplayItem::Type_EndClip);
118 } 117 }
119 118
119 void EndClipDisplayItem::FromProtobuf(const proto::DisplayItem& proto) {
120 DCHECK_EQ(proto::DisplayItem::Type_EndClip, proto.type());
121 }
122
120 void EndClipDisplayItem::Raster(SkCanvas* canvas, 123 void EndClipDisplayItem::Raster(SkCanvas* canvas,
121 const gfx::Rect& canvas_target_playback_rect, 124 const gfx::Rect& canvas_target_playback_rect,
122 SkPicture::AbortCallback* callback) const { 125 SkPicture::AbortCallback* callback) const {
123 canvas->restore(); 126 canvas->restore();
124 } 127 }
125 128
126 void EndClipDisplayItem::AsValueInto( 129 void EndClipDisplayItem::AsValueInto(
127 const gfx::Rect& visual_rect, 130 const gfx::Rect& visual_rect,
128 base::trace_event::TracedValue* array) const { 131 base::trace_event::TracedValue* array) const {
129 array->AppendString(base::StringPrintf("EndClipDisplayItem visualRect: [%s]", 132 array->AppendString(base::StringPrintf("EndClipDisplayItem visualRect: [%s]",
130 visual_rect.ToString().c_str())); 133 visual_rect.ToString().c_str()));
131 } 134 }
132 135
133 size_t EndClipDisplayItem::ExternalMemoryUsage() const {
134 return 0;
135 }
136
137 } // namespace cc 136 } // namespace cc
OLDNEW
« no previous file with comments | « cc/playback/clip_display_item.h ('k') | cc/playback/clip_path_display_item.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698