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

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: Addressed comments from dtrainor 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..0a2f0c2b62447c56791ba372d7f2def64ed1a823 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<uint8_t> buffer(new uint8_t[region_size]);
+ skregion_.writeToMemory(buffer.get());
+ proto->set_skregion(buffer.get(), region_size);
David Trainor- moved to gerrit 2015/11/20 21:46:50 base::checked_cast<int>? IIRC set_skregion() will
+ }
+}
+
+void Region::FromProtobuf(const proto::Region& proto) {
+ SkRegion region;
+ if (proto.has_skregion()) {
+ size_t bytes_read =
+ region.readFromMemory(proto.skregion().data(), proto.skregion().size());
+ DCHECK_EQ(proto.skregion().size(), bytes_read);
+ }
+ skregion_ = region;
+}
+
Region::Iterator::Iterator() {
}

Powered by Google App Engine
This is Rietveld 408576698