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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: cc/base/region.cc
diff --git a/cc/base/region.cc b/cc/base/region.cc
index c048c89e5710ba0412910008c9eabb2fdaa37abc..0a7ee5d6b62fbd591e549ea448a3b7d0591110c3 100644
--- a/cc/base/region.cc
+++ b/cc/base/region.cc
@@ -7,6 +7,7 @@
#include "base/trace_event/trace_event_argument.h"
#include "base/values.h"
#include "cc/base/simple_enclosed_region.h"
+#include "cc/proto/region.pb.h"
namespace cc {
@@ -140,6 +141,25 @@ void Region::AsValueInto(base::trace_event::TracedValue* result) const {
}
}
+void Region::ToProtobuf(proto::Region* proto) const {
+ size_t region_size = skregion_.writeToMemory(nullptr);
+ if (region_size > 0) {
+ 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.
+ skregion_.writeToMemory(buffer.get());
+ proto->set_skregion(std::string(buffer.get(), region_size));
+ }
+}
+
+void Region::FromProtobuf(const proto::Region& proto) {
+ SkRegion region;
+ if (proto.has_skregion()) {
+ 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.
+ proto.skregion().size());
+ DCHECK_EQ(proto.skregion().size(), bytes_read);
+ }
+ skregion_ = region;
+}
+
Region::Iterator::Iterator() {
}
« 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