Skip to content

Commit

Permalink
Add support for (de)serializing HeadsUpDisplayLayer
Browse files Browse the repository at this point in the history
They LayerTreeHost has a HUD-layer as a member, and as part of the
CL for adding support for (de)serializing the LayerTreeHost,
the test code incorrectly creates a cc:Layer instead
of a cc:HeadsUpDisplayLayer, and this is not checked.

The Linux CFI bot luckily caught this error, so this CL fixes
the error by adding support for the layer type.

The HUD layer has no special members, but do have some special logic
for drawing, so only the type needed to be serialized.

BUG=577972
CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel

Review URL: https://codereview.chromium.org/1581693010

Cr-Commit-Position: refs/heads/master@{#369916}
  • Loading branch information
tommynyquist authored and Commit bot committed Jan 16, 2016
1 parent 249a265 commit 7e17940
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 1 deletion.
6 changes: 6 additions & 0 deletions cc/layers/heads_up_display_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "base/trace_event/trace_event.h"
#include "cc/layers/heads_up_display_layer_impl.h"
#include "cc/proto/layer.pb.h"
#include "cc/trees/layer_tree_host.h"

namespace cc {
Expand Down Expand Up @@ -61,4 +62,9 @@ scoped_ptr<LayerImpl> HeadsUpDisplayLayer::CreateLayerImpl(
return HeadsUpDisplayLayerImpl::Create(tree_impl, layer_id_);
}

void HeadsUpDisplayLayer::SetTypeForProtoSerialization(
proto::LayerNode* proto) const {
proto->set_type(proto::LayerType::HEADS_UP_DISPLAY_LAYER);
}

} // namespace cc
6 changes: 6 additions & 0 deletions cc/layers/heads_up_display_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

namespace cc {

namespace proto {
class LayerNode;
} // namespace proto

class CC_EXPORT HeadsUpDisplayLayer : public Layer {
public:
static scoped_refptr<HeadsUpDisplayLayer> Create(
Expand All @@ -24,6 +28,8 @@ class CC_EXPORT HeadsUpDisplayLayer : public Layer {

scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override;

void SetTypeForProtoSerialization(proto::LayerNode* proto) const override;

protected:
explicit HeadsUpDisplayLayer(const LayerSettings& settings);
bool HasDrawableContent() const override;
Expand Down
3 changes: 3 additions & 0 deletions cc/layers/layer_proto_converter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "base/stl_util.h"
#include "cc/layers/empty_content_layer_client.h"
#include "cc/layers/heads_up_display_layer.h"
#include "cc/layers/layer.h"
#include "cc/layers/layer_settings.h"
#include "cc/layers/picture_layer.h"
Expand Down Expand Up @@ -116,6 +117,8 @@ scoped_refptr<Layer> LayerProtoConverter::FindOrAllocateAndConstruct(
case proto::PICTURE_LAYER:
return PictureLayer::Create(LayerSettings(),
EmptyContentLayerClient::GetInstance());
case proto::HEADS_UP_DISPLAY_LAYER:
return HeadsUpDisplayLayer::Create(LayerSettings());
}
// TODO(nyquist): Add the rest of the necessary LayerTypes. This function
// should not return null.
Expand Down
33 changes: 33 additions & 0 deletions cc/layers/layer_proto_converter_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "cc/layers/layer_proto_converter.h"

#include "cc/layers/empty_content_layer_client.h"
#include "cc/layers/heads_up_display_layer.h"
#include "cc/layers/layer.h"
#include "cc/layers/layer_settings.h"
#include "cc/layers/picture_layer.h"
Expand Down Expand Up @@ -403,5 +404,37 @@ TEST_F(LayerProtoConverterTest, PictureLayerTypeDeserialization) {
EXPECT_EQ(proto::LayerType::PICTURE_LAYER, layer_node.type());
}

TEST_F(LayerProtoConverterTest, HudLayerTypeSerialization) {
// Make sure that PictureLayers serialize to the
// proto::LayerType::HEADS_UP_DISPLAY_LAYER type.
scoped_refptr<HeadsUpDisplayLayer> layer =
HeadsUpDisplayLayer::Create(LayerSettings());

proto::LayerNode layer_hierarchy;
LayerProtoConverter::SerializeLayerHierarchy(layer.get(), &layer_hierarchy);
EXPECT_EQ(proto::LayerType::HEADS_UP_DISPLAY_LAYER, layer_hierarchy.type());
}

TEST_F(LayerProtoConverterTest, HudLayerTypeDeserialization) {
// Make sure that proto::LayerType::HEADS_UP_DISPLAY_LAYER ends up building a
// HeadsUpDisplayLayer.
scoped_refptr<Layer> old_root = HeadsUpDisplayLayer::Create(LayerSettings());
proto::LayerNode root_node;
root_node.set_id(old_root->id());
root_node.set_type(proto::LayerType::HEADS_UP_DISPLAY_LAYER);

scoped_refptr<Layer> new_root =
LayerProtoConverter::DeserializeLayerHierarchy(old_root, root_node);

// Validate that the ids are equal.
EXPECT_EQ(old_root->id(), new_root->id());

// Check that the layer type is equal by using the type this layer would
// serialize to.
proto::LayerNode layer_node;
new_root->SetTypeForProtoSerialization(&layer_node);
EXPECT_EQ(proto::LayerType::HEADS_UP_DISPLAY_LAYER, layer_node.type());
}

} // namespace
} // namespace cc
3 changes: 2 additions & 1 deletion cc/proto/layer.proto
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ enum LayerType {
UNKNOWN = 0;
LAYER = 1;
PICTURE_LAYER = 2;
HEADS_UP_DISPLAY_LAYER = 3;

// TODO(nyquist): Add the rest of the necessary LayerTypes.
};
Expand Down Expand Up @@ -138,4 +139,4 @@ message PictureLayerProperties {
optional bool nearest_neighbor = 5;

optional int64 update_source_frame_number = 6;
}
}
13 changes: 13 additions & 0 deletions cc/trees/layer_tree_host_unittest_serialization.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@ class LayerTreeHostSerializationTest : public testing::Test {
if (layer_tree_host_src_->hud_layer_) {
EXPECT_EQ(layer_tree_host_src_->hud_layer_->id(),
layer_tree_host_dst_->hud_layer_->id());
// The HUD layer member is a HeadsUpDisplayLayer instead of Layer, so
// inspect the proto to see if it contains the the right layer type.
bool found_hud_layer_type = false;
for (int i = 0; i < proto.root_layer().children_size(); ++i) {
if (proto.root_layer().children(i).id() ==
layer_tree_host_src_->hud_layer_->id()) {
EXPECT_EQ(proto::HEADS_UP_DISPLAY_LAYER,
proto.root_layer().children(i).type());
found_hud_layer_type = true;
break;
}
}
EXPECT_TRUE(found_hud_layer_type);
} else {
EXPECT_EQ(nullptr, layer_tree_host_dst_->hud_layer_);
}
Expand Down

0 comments on commit 7e17940

Please sign in to comment.