summaryrefslogtreecommitdiffstats
path: root/cc/output
diff options
context:
space:
mode:
authorkhushalsagar <khushalsagar@chromium.org>2016-01-15 12:46:48 -0800
committerCommit bot <commit-bot@chromium.org>2016-01-15 20:48:00 +0000
commit376942135fb8ad3d33340c506ff251f3c3afba3d (patch)
treed65d8ccbee3ffb1555508b03035f8fa65f8746e8 /cc/output
parent272ad4a2612601ae1c7cd8aca68bf8ada4f5a494 (diff)
downloadchromium_src-376942135fb8ad3d33340c506ff251f3c3afba3d.zip
chromium_src-376942135fb8ad3d33340c506ff251f3c3afba3d.tar.gz
chromium_src-376942135fb8ad3d33340c506ff251f3c3afba3d.tar.bz2
(De)-serialize BeginMainFrameAndCommitState to protobuf.
BUG=550687 CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel Review URL: https://codereview.chromium.org/1581773002 Cr-Commit-Position: refs/heads/master@{#369836}
Diffstat (limited to 'cc/output')
-rw-r--r--cc/output/begin_frame_args.cc56
-rw-r--r--cc/output/begin_frame_args.h9
-rw-r--r--cc/output/begin_frame_args_unittest.cc32
3 files changed, 97 insertions, 0 deletions
diff --git a/cc/output/begin_frame_args.cc b/cc/output/begin_frame_args.cc
index 216eb52..c50d5f8 100644
--- a/cc/output/begin_frame_args.cc
+++ b/cc/output/begin_frame_args.cc
@@ -5,6 +5,8 @@
#include "cc/output/begin_frame_args.h"
#include "base/trace_event/trace_event_argument.h"
+#include "cc/proto/base_conversions.h"
+#include "cc/proto/begin_main_frame_and_commit_state.pb.h"
namespace cc {
@@ -23,6 +25,44 @@ const char* BeginFrameArgs::TypeToString(BeginFrameArgsType type) {
return "???";
}
+void BeginFrameArgs::BeginFrameArgsTypeToProtobuf(
+ proto::BeginFrameArgs* proto) const {
+ switch (type) {
+ case BeginFrameArgs::INVALID:
+ proto->set_type(proto::BeginFrameArgs::INVALID);
+ return;
+ case BeginFrameArgs::NORMAL:
+ proto->set_type(proto::BeginFrameArgs::NORMAL);
+ return;
+ case BeginFrameArgs::MISSED:
+ proto->set_type(proto::BeginFrameArgs::MISSED);
+ return;
+ case BeginFrameArgs::BEGIN_FRAME_ARGS_TYPE_MAX:
+ proto->set_type(proto::BeginFrameArgs::BEGIN_FRAME_ARGS_TYPE_MAX);
+ return;
+ }
+ NOTREACHED();
+}
+
+void BeginFrameArgs::BeginFrameArgsTypeFromProtobuf(
+ const proto::BeginFrameArgs& proto) {
+ switch (proto.type()) {
+ case proto::BeginFrameArgs::INVALID:
+ type = BeginFrameArgs::INVALID;
+ return;
+ case proto::BeginFrameArgs::NORMAL:
+ type = BeginFrameArgs::NORMAL;
+ return;
+ case proto::BeginFrameArgs::MISSED:
+ type = BeginFrameArgs::MISSED;
+ return;
+ case proto::BeginFrameArgs::BEGIN_FRAME_ARGS_TYPE_MAX:
+ type = BeginFrameArgs::BEGIN_FRAME_ARGS_TYPE_MAX;
+ return;
+ }
+ NOTREACHED();
+}
+
BeginFrameArgs::BeginFrameArgs()
: frame_time(base::TimeTicks()),
deadline(base::TimeTicks()),
@@ -78,6 +118,22 @@ void BeginFrameArgs::AsValueInto(base::trace_event::TracedValue* state) const {
state->SetBoolean("on_critical_path", on_critical_path);
}
+void BeginFrameArgs::ToProtobuf(proto::BeginFrameArgs* proto) const {
+ proto->set_frame_time(TimeTicksToProto(frame_time));
+ proto->set_deadline(TimeTicksToProto(deadline));
+ proto->set_interval(interval.ToInternalValue());
+ BeginFrameArgsTypeToProtobuf(proto);
+ proto->set_on_critical_path(on_critical_path);
+}
+
+void BeginFrameArgs::FromProtobuf(const proto::BeginFrameArgs& proto) {
+ frame_time = ProtoToTimeTicks(proto.frame_time());
+ deadline = ProtoToTimeTicks(proto.deadline());
+ interval = base::TimeDelta::FromInternalValue(proto.interval());
+ BeginFrameArgsTypeFromProtobuf(proto);
+ on_critical_path = proto.on_critical_path();
+}
+
// This is a hard-coded deadline adjustment that assumes 60Hz, to be used in
// cases where a good estimated draw time is not known. Using 1/3 of the vsync
// as the default adjustment gives the Browser the last 1/3 of a frame to
diff --git a/cc/output/begin_frame_args.h b/cc/output/begin_frame_args.h
index 1a7ae5f..1f6bc36 100644
--- a/cc/output/begin_frame_args.h
+++ b/cc/output/begin_frame_args.h
@@ -36,6 +36,10 @@ class TracedValue;
namespace cc {
+namespace proto {
+class BeginFrameArgs;
+}
+
struct CC_EXPORT BeginFrameArgs {
enum BeginFrameArgsType {
INVALID,
@@ -46,6 +50,8 @@ struct CC_EXPORT BeginFrameArgs {
BEGIN_FRAME_ARGS_TYPE_MAX,
};
static const char* TypeToString(BeginFrameArgsType type);
+ void BeginFrameArgsTypeToProtobuf(proto::BeginFrameArgs* proto) const;
+ void BeginFrameArgsTypeFromProtobuf(const proto::BeginFrameArgs& proto);
// Creates an invalid set of values.
BeginFrameArgs();
@@ -79,6 +85,9 @@ struct CC_EXPORT BeginFrameArgs {
scoped_refptr<base::trace_event::ConvertableToTraceFormat> AsValue() const;
void AsValueInto(base::trace_event::TracedValue* dict) const;
+ void ToProtobuf(proto::BeginFrameArgs* proto) const;
+ void FromProtobuf(const proto::BeginFrameArgs& proto);
+
base::TimeTicks frame_time;
base::TimeTicks deadline;
base::TimeDelta interval;
diff --git a/cc/output/begin_frame_args_unittest.cc b/cc/output/begin_frame_args_unittest.cc
index eb63cc7..6097201 100644
--- a/cc/output/begin_frame_args_unittest.cc
+++ b/cc/output/begin_frame_args_unittest.cc
@@ -5,6 +5,7 @@
#include <string>
#include "cc/output/begin_frame_args.h"
+#include "cc/proto/begin_main_frame_and_commit_state.pb.h"
#include "cc/test/begin_frame_args_test.h"
#include "testing/gtest/include/gtest/gtest-spi.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -84,6 +85,37 @@ TEST(BeginFrameArgsTest, Create) {
EXPECT_EQ(BeginFrameArgs::NORMAL, args2.type) << args2;
}
+TEST(BeginFrameArgsSerializationTest, BeginFrameArgsType) {
+ for (size_t i = 0;
+ i < BeginFrameArgs::BeginFrameArgsType::BEGIN_FRAME_ARGS_TYPE_MAX; ++i) {
+ BeginFrameArgs::BeginFrameArgsType type =
+ static_cast<BeginFrameArgs::BeginFrameArgsType>(i);
+ BeginFrameArgs args;
+ args.type = type;
+
+ proto::BeginFrameArgs proto;
+ args.BeginFrameArgsTypeToProtobuf(&proto);
+
+ BeginFrameArgs new_args;
+ new_args.BeginFrameArgsTypeFromProtobuf(proto);
+ EXPECT_EQ(args.type, new_args.type);
+ }
+}
+
+TEST(BeginFrameArgsSerializationTest, BeginFrameArgs) {
+ BeginFrameArgs args = BeginFrameArgs::Create(
+ BEGINFRAME_FROM_HERE, base::TimeTicks::FromInternalValue(1),
+ base::TimeTicks::FromInternalValue(2),
+ base::TimeDelta::FromInternalValue(3), BeginFrameArgs::NORMAL);
+ proto::BeginFrameArgs proto;
+ args.ToProtobuf(&proto);
+
+ BeginFrameArgs new_args;
+ new_args.FromProtobuf(proto);
+
+ EXPECT_EQ(args, new_args);
+}
+
#ifndef NDEBUG
TEST(BeginFrameArgsTest, Location) {
tracked_objects::Location expected_location = BEGINFRAME_FROM_HERE;