summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornyquist <nyquist@chromium.org>2015-11-24 02:04:17 -0800
committerCommit bot <commit-bot@chromium.org>2015-11-24 10:05:13 +0000
commit04b8bd2ea68f22f8051d9988e4872e51c4ab4409 (patch)
treeeffe1cb2581aa3f180f361d737187156ad9de524
parent94740e359d1173f1d262857b7ebeb7913bf2218a (diff)
downloadchromium_src-04b8bd2ea68f22f8051d9988e4872e51c4ab4409.zip
chromium_src-04b8bd2ea68f22f8051d9988e4872e51c4ab4409.tar.gz
chromium_src-04b8bd2ea68f22f8051d9988e4872e51c4ab4409.tar.bz2
Add support for converting cc::Region to and from protobuf.
For the (de)serialization of property trees and layers, we need to be able to serialize several data types and this CL adds conversions and a unit test for the cc::Region type. The conversion of cc::Region happens by serializing a list of gfx::Rect objects, and then on the deserialization side the union of the gfx::Rect objects are created to recreate the cc::Region. The initial version of this CL used writeToMemory and readFromMemory in Skia, and a suggestion was made to fix using uint8_t instead of char[], and this change still keeps this fix, even after those methods are not in use anymore. This is done in a separate CL to keep the logic-changing CLs clean and focused. BUG=538710 CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel Review URL: https://codereview.chromium.org/1460503004 Cr-Commit-Position: refs/heads/master@{#361302}
-rw-r--r--cc/BUILD.gn3
-rw-r--r--cc/cc.gyp3
-rw-r--r--cc/cc_tests.gyp1
-rw-r--r--cc/playback/clip_path_display_item.cc6
-rw-r--r--cc/proto/BUILD.gn1
-rw-r--r--cc/proto/cc_conversions.cc25
-rw-r--r--cc/proto/cc_conversions.h24
-rw-r--r--cc/proto/cc_conversions_unittest.cc54
-rw-r--r--cc/proto/region.proto15
9 files changed, 129 insertions, 3 deletions
diff --git a/cc/BUILD.gn b/cc/BUILD.gn
index 8fd1828..3e5b0a2 100644
--- a/cc/BUILD.gn
+++ b/cc/BUILD.gn
@@ -313,6 +313,8 @@ component("cc") {
"playback/largest_display_item.h",
"playback/transform_display_item.cc",
"playback/transform_display_item.h",
+ "proto/cc_conversions.cc",
+ "proto/cc_conversions.h",
"proto/gfx_conversions.cc",
"proto/gfx_conversions.h",
"proto/skia_conversions.cc",
@@ -796,6 +798,7 @@ test("cc_unittests") {
"playback/display_item_list_unittest.cc",
"playback/display_list_raster_source_unittest.cc",
"playback/display_list_recording_source_unittest.cc",
+ "proto/cc_conversions_unittest.cc",
"proto/gfx_conversions_unittest.cc",
"proto/skia_conversions_unittest.cc",
"quads/draw_polygon_unittest.cc",
diff --git a/cc/cc.gyp b/cc/cc.gyp
index cf12888..8205cb7 100644
--- a/cc/cc.gyp
+++ b/cc/cc.gyp
@@ -373,6 +373,8 @@
'playback/largest_display_item.h',
'playback/transform_display_item.cc',
'playback/transform_display_item.h',
+ 'proto/cc_conversions.cc',
+ 'proto/cc_conversions.h',
'proto/gfx_conversions.cc',
'proto/gfx_conversions.h',
'proto/skia_conversions.cc',
@@ -594,6 +596,7 @@
'proto/pointf.proto',
'proto/rect.proto',
'proto/rectf.proto',
+ 'proto/region.proto',
'proto/scroll_offset.proto',
'proto/size.proto',
'proto/sizef.proto',
diff --git a/cc/cc_tests.gyp b/cc/cc_tests.gyp
index 8c45b8d..b5fe7b8 100644
--- a/cc/cc_tests.gyp
+++ b/cc/cc_tests.gyp
@@ -84,6 +84,7 @@
'playback/display_item_list_unittest.cc',
'playback/display_list_raster_source_unittest.cc',
'playback/display_list_recording_source_unittest.cc',
+ 'proto/cc_conversions_unittest.cc',
'proto/gfx_conversions_unittest.cc',
'proto/skia_conversions_unittest.cc',
'quads/draw_polygon_unittest.cc',
diff --git a/cc/playback/clip_path_display_item.cc b/cc/playback/clip_path_display_item.cc
index 3b46621..a5037a2 100644
--- a/cc/playback/clip_path_display_item.cc
+++ b/cc/playback/clip_path_display_item.cc
@@ -41,9 +41,9 @@ void ClipPathDisplayItem::ToProtobuf(proto::DisplayItem* proto) const {
// Just use skia's serialization method for the SkPath for now.
size_t path_size = clip_path_.writeToMemory(nullptr);
if (path_size > 0) {
- scoped_ptr<char[]> buffer(new char[path_size]);
+ scoped_ptr<uint8_t[]> buffer(new uint8_t[path_size]);
clip_path_.writeToMemory(buffer.get());
- details->set_clip_path(std::string(buffer.get(), path_size));
+ details->set_clip_path(buffer.get(), path_size);
}
}
@@ -56,7 +56,7 @@ void ClipPathDisplayItem::FromProtobuf(const proto::DisplayItem& proto) {
SkPath clip_path;
if (details.has_clip_path()) {
- size_t bytes_read = clip_path.readFromMemory(details.clip_path().c_str(),
+ size_t bytes_read = clip_path.readFromMemory(details.clip_path().data(),
details.clip_path().size());
DCHECK_EQ(details.clip_path().size(), bytes_read);
}
diff --git a/cc/proto/BUILD.gn b/cc/proto/BUILD.gn
index 33e3e58..07258a6 100644
--- a/cc/proto/BUILD.gn
+++ b/cc/proto/BUILD.gn
@@ -38,6 +38,7 @@ proto_library("proto_internal") {
"pointf.proto",
"rect.proto",
"rectf.proto",
+ "region.proto",
"scroll_offset.proto",
"size.proto",
"sizef.proto",
diff --git a/cc/proto/cc_conversions.cc b/cc/proto/cc_conversions.cc
new file mode 100644
index 0000000..7e466f3
--- /dev/null
+++ b/cc/proto/cc_conversions.cc
@@ -0,0 +1,25 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "cc/proto/cc_conversions.h"
+
+#include "cc/base/region.h"
+#include "cc/proto/gfx_conversions.h"
+#include "cc/proto/region.pb.h"
+
+namespace cc {
+
+void RegionToProto(const Region& region, proto::Region* proto) {
+ for (Region::Iterator it(region); it.has_rect(); it.next())
+ RectToProto(it.rect(), proto->add_rects());
+}
+
+Region RegionFromProto(const proto::Region& proto) {
+ Region region;
+ for (int i = 0; i < proto.rects_size(); ++i)
+ region.Union(ProtoToRect(proto.rects(i)));
+ return region;
+}
+
+} // namespace cc
diff --git a/cc/proto/cc_conversions.h b/cc/proto/cc_conversions.h
new file mode 100644
index 0000000..4060e6f
--- /dev/null
+++ b/cc/proto/cc_conversions.h
@@ -0,0 +1,24 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CC_PROTO_CC_CONVERSIONS_H_
+#define CC_PROTO_CC_CONVERSIONS_H_
+
+#include "cc/base/cc_export.h"
+
+namespace cc {
+class Region;
+
+namespace proto {
+class Region;
+} // namespace proto
+
+// TODO(dtrainor): Move these to a class and make them static
+// (crbug.com/548432).
+CC_EXPORT void RegionToProto(const Region& region, proto::Region* proto);
+CC_EXPORT Region RegionFromProto(const proto::Region& proto);
+
+} // namespace cc
+
+#endif // CC_PROTO_CC_CONVERSIONS_H_
diff --git a/cc/proto/cc_conversions_unittest.cc b/cc/proto/cc_conversions_unittest.cc
new file mode 100644
index 0000000..8612dda
--- /dev/null
+++ b/cc/proto/cc_conversions_unittest.cc
@@ -0,0 +1,54 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "cc/proto/cc_conversions.h"
+
+#include "cc/base/region.h"
+#include "cc/proto/region.pb.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/gfx/geometry/rect.h"
+
+namespace cc {
+namespace {
+
+void VerifySerializeAndDeserializeProto(const Region& region1) {
+ proto::Region proto;
+ RegionToProto(region1, &proto);
+ Region region2 = RegionFromProto(proto);
+ EXPECT_EQ(region1, region2);
+}
+
+TEST(RegionTest, SingleRectProtoConversion) {
+ Region region(gfx::Rect(14, 15, 16, 17));
+ VerifySerializeAndDeserializeProto(region);
+}
+
+TEST(RegionTest, MultipleRectProtoConversion) {
+ Region region(gfx::Rect(0, 0, 1, 1));
+ region.Union(gfx::Rect(9, 0, 1, 1));
+ region.Union(gfx::Rect(0, 9, 1, 1));
+ region.Union(gfx::Rect(9, 9, 1, 1));
+ VerifySerializeAndDeserializeProto(region);
+}
+
+TEST(RegionTest, OverlappingRectIntersectProtoConversion) {
+ Region region(gfx::Rect(0, 0, 10, 10));
+ region.Intersect(gfx::Rect(5, 5, 10, 10));
+ VerifySerializeAndDeserializeProto(region);
+}
+
+TEST(RegionTest, OverlappingRectUnionProtoConversion) {
+ Region region(gfx::Rect(0, 0, 10, 10));
+ region.Union(gfx::Rect(5, 5, 10, 10));
+ VerifySerializeAndDeserializeProto(region);
+}
+
+TEST(RegionTest, OverlappingRectSubtractProtoConversion) {
+ Region region(gfx::Rect(0, 0, 10, 10));
+ region.Subtract(gfx::Rect(5, 5, 1, 1));
+ VerifySerializeAndDeserializeProto(region);
+}
+
+} // namespace
+} // namespace cc
diff --git a/cc/proto/region.proto b/cc/proto/region.proto
new file mode 100644
index 0000000..a4d235b
--- /dev/null
+++ b/cc/proto/region.proto
@@ -0,0 +1,15 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+syntax = "proto2";
+
+import "rect.proto";
+
+option optimize_for = LITE_RUNTIME;
+
+package cc.proto;
+
+message Region {
+ repeated Rect rects = 1;
+}