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

Side by Side Diff: cc/base/region.cc

Issue 1460503004: Add support for converting cc::Region to and from protobuf. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@add-more-conversions
Patch Set: Created 5 years, 1 month 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/base/region.h" 5 #include "cc/base/region.h"
6 6
7 #include "base/trace_event/trace_event_argument.h" 7 #include "base/trace_event/trace_event_argument.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "cc/base/simple_enclosed_region.h" 9 #include "cc/base/simple_enclosed_region.h"
10 #include "cc/proto/region.pb.h"
10 11
11 namespace cc { 12 namespace cc {
12 13
13 Region::Region() { 14 Region::Region() {
14 } 15 }
15 16
16 Region::Region(const Region& region) 17 Region::Region(const Region& region)
17 : skregion_(region.skregion_) { 18 : skregion_(region.skregion_) {
18 } 19 }
19 20
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 void Region::AsValueInto(base::trace_event::TracedValue* result) const { 134 void Region::AsValueInto(base::trace_event::TracedValue* result) const {
134 for (Iterator it(*this); it.has_rect(); it.next()) { 135 for (Iterator it(*this); it.has_rect(); it.next()) {
135 gfx::Rect rect(it.rect()); 136 gfx::Rect rect(it.rect());
136 result->AppendInteger(rect.x()); 137 result->AppendInteger(rect.x());
137 result->AppendInteger(rect.y()); 138 result->AppendInteger(rect.y());
138 result->AppendInteger(rect.width()); 139 result->AppendInteger(rect.width());
139 result->AppendInteger(rect.height()); 140 result->AppendInteger(rect.height());
140 } 141 }
141 } 142 }
142 143
144 void Region::ToProtobuf(proto::Region* proto) const {
145 size_t region_size = skregion_.writeToMemory(nullptr);
146 if (region_size > 0) {
147 scoped_ptr<char[]> buffer(new char[region_size]);
David Trainor- moved to gerrit 2015/11/19 19:14:01 uint8_t? Again same for the DisplayItem protos :(
nyquist 2015/11/20 01:11:43 Done.
148 skregion_.writeToMemory(buffer.get());
149 proto->set_skregion(std::string(buffer.get(), region_size));
150 }
151 }
152
153 void Region::FromProtobuf(const proto::Region& proto) {
154 SkRegion region;
155 if (proto.has_skregion()) {
156 size_t bytes_read = region.readFromMemory(proto.skregion().c_str(),
David Trainor- moved to gerrit 2015/11/19 19:14:01 .data? Could you also do this for the DisplayItem
nyquist 2015/11/20 01:11:43 Done.
157 proto.skregion().size());
158 DCHECK_EQ(proto.skregion().size(), bytes_read);
159 }
160 skregion_ = region;
161 }
162
143 Region::Iterator::Iterator() { 163 Region::Iterator::Iterator() {
144 } 164 }
145 165
146 Region::Iterator::Iterator(const Region& region) 166 Region::Iterator::Iterator(const Region& region)
147 : it_(region.skregion_) { 167 : it_(region.skregion_) {
148 } 168 }
149 169
150 Region::Iterator::~Iterator() { 170 Region::Iterator::~Iterator() {
151 } 171 }
152 172
153 } // namespace cc 173 } // namespace cc
OLDNEW
« cc/base/DEPS ('K') | « cc/base/region.h ('k') | cc/base/region_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698