Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/blimp/compositor_state_deserializer.h" | 5 #include "cc/blimp/compositor_state_deserializer.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "cc/blimp/client_picture_cache.h" | |
| 9 #include "cc/blimp/compositor_state_deserializer_client.h" | 10 #include "cc/blimp/compositor_state_deserializer_client.h" |
| 11 #include "cc/blimp/deserialized_content_layer_client.h" | |
| 10 #include "cc/blimp/layer_factory.h" | 12 #include "cc/blimp/layer_factory.h" |
| 13 #include "cc/blimp/picture_data_conversions.h" | |
| 11 #include "cc/input/layer_selection_bound.h" | 14 #include "cc/input/layer_selection_bound.h" |
| 12 #include "cc/layers/layer.h" | 15 #include "cc/layers/layer.h" |
| 16 #include "cc/layers/picture_layer.h" | |
| 17 #include "cc/layers/solid_color_scrollbar_layer.h" | |
| 13 #include "cc/proto/cc_conversions.h" | 18 #include "cc/proto/cc_conversions.h" |
| 14 #include "cc/proto/gfx_conversions.h" | 19 #include "cc/proto/gfx_conversions.h" |
| 15 #include "cc/proto/layer_tree_host.pb.h" | 20 #include "cc/proto/layer_tree_host.pb.h" |
| 16 #include "cc/proto/skia_conversions.h" | 21 #include "cc/proto/skia_conversions.h" |
| 17 #include "cc/trees/layer_tree_host.h" | 22 #include "cc/trees/layer_tree_host.h" |
| 18 | 23 |
| 19 namespace cc { | 24 namespace cc { |
| 20 namespace { | 25 namespace { |
| 21 | 26 |
| 22 class DefaultLayerFactory : public LayerFactory { | 27 class DefaultLayerFactory : public LayerFactory { |
| 23 public: | 28 public: |
| 24 DefaultLayerFactory() = default; | 29 DefaultLayerFactory() = default; |
| 25 ~DefaultLayerFactory() override = default; | 30 ~DefaultLayerFactory() override = default; |
| 26 | 31 |
| 27 // LayerFactory implementation. | 32 // LayerFactory implementation. |
| 28 scoped_refptr<Layer> CreateLayer(int engine_layer_id) override { | 33 scoped_refptr<Layer> CreateLayer(int engine_layer_id) override { |
| 29 return Layer::Create(); | 34 return Layer::Create(); |
| 30 } | 35 } |
| 36 scoped_refptr<PictureLayer> CreatePictureLayer( | |
| 37 int engine_layer_id, | |
| 38 ContentLayerClient* content_layer_client) override { | |
| 39 return PictureLayer::Create(content_layer_client); | |
| 40 } | |
| 41 scoped_refptr<SolidColorScrollbarLayer> CreateSolidColorScrollbarLayer( | |
| 42 int engine_layer_id, | |
| 43 ScrollbarOrientation orientation, | |
| 44 int thumb_thickness, | |
| 45 int track_start, | |
| 46 bool is_left_side_vertical_scrollbar, | |
| 47 int scroll_layer_id) override { | |
| 48 return SolidColorScrollbarLayer::Create( | |
| 49 orientation, thumb_thickness, track_start, | |
| 50 is_left_side_vertical_scrollbar, scroll_layer_id); | |
| 51 } | |
| 31 }; | 52 }; |
| 32 | 53 |
| 33 } // namespace | 54 } // namespace |
| 34 | 55 |
| 56 CompositorStateDeserializer::LayerData::LayerData() = default; | |
| 57 | |
| 58 CompositorStateDeserializer::LayerData::LayerData(LayerData&& other) = default; | |
| 59 | |
| 60 CompositorStateDeserializer::LayerData& CompositorStateDeserializer::LayerData:: | |
| 61 operator=(LayerData&& other) = default; | |
| 62 | |
| 63 CompositorStateDeserializer::LayerData::~LayerData() = default; | |
|
vmpstr
2016/10/10 21:28:25
nit: move dtors to be next to ctors.
Khushal
2016/10/10 21:39:24
Done.
| |
| 64 | |
| 35 CompositorStateDeserializer::CompositorStateDeserializer( | 65 CompositorStateDeserializer::CompositorStateDeserializer( |
| 36 LayerTreeHost* layer_tree_host, | 66 LayerTreeHost* layer_tree_host, |
| 37 ScrollCallback scroll_callback, | 67 std::unique_ptr<ClientPictureCache> client_picture_cache, |
| 68 const ScrollCallback& scroll_callback, | |
| 38 CompositorStateDeserializerClient* client) | 69 CompositorStateDeserializerClient* client) |
| 39 : layer_factory_(base::MakeUnique<DefaultLayerFactory>()), | 70 : layer_factory_(base::MakeUnique<DefaultLayerFactory>()), |
| 40 layer_tree_host_(layer_tree_host), | 71 layer_tree_host_(layer_tree_host), |
| 72 client_picture_cache_(std::move(client_picture_cache)), | |
| 41 scroll_callback_(scroll_callback), | 73 scroll_callback_(scroll_callback), |
| 42 client_(client) { | 74 client_(client) { |
| 43 DCHECK(layer_tree_host_); | 75 DCHECK(layer_tree_host_); |
| 44 DCHECK(client_); | 76 DCHECK(client_); |
| 45 } | 77 } |
| 46 | 78 |
| 47 CompositorStateDeserializer::~CompositorStateDeserializer() = default; | 79 CompositorStateDeserializer::~CompositorStateDeserializer() = default; |
| 48 | 80 |
| 49 Layer* CompositorStateDeserializer::GetLayerForEngineId( | 81 Layer* CompositorStateDeserializer::GetLayerForEngineId( |
| 50 int engine_layer_id) const { | 82 int engine_layer_id) const { |
| 51 EngineIdToLayerMap::const_iterator layer_it = | 83 EngineIdToLayerMap::const_iterator layer_it = |
| 52 engine_id_to_layer_.find(engine_layer_id); | 84 engine_id_to_layer_.find(engine_layer_id); |
| 53 return layer_it != engine_id_to_layer_.end() ? layer_it->second.get() | 85 return layer_it != engine_id_to_layer_.end() ? layer_it->second.layer.get() |
| 54 : nullptr; | 86 : nullptr; |
| 55 } | 87 } |
| 56 | 88 |
| 57 void CompositorStateDeserializer::DeserializeCompositorUpdate( | 89 void CompositorStateDeserializer::DeserializeCompositorUpdate( |
| 58 const proto::LayerTreeHost& layer_tree_host_proto) { | 90 const proto::LayerTreeHost& layer_tree_host_proto) { |
| 59 SychronizeLayerTreeState(layer_tree_host_proto.layer_tree()); | 91 SychronizeLayerTreeState(layer_tree_host_proto.layer_tree()); |
| 60 | 92 |
| 93 // Ensure ClientPictureCache contains all the necessary SkPictures before | |
| 94 // deserializing the properties. | |
| 95 proto::SkPictures proto_pictures = layer_tree_host_proto.pictures(); | |
| 96 std::vector<PictureData> pictures = | |
| 97 SkPicturesProtoToPictureDataVector(proto_pictures); | |
| 98 client_picture_cache_->ApplyCacheUpdate(pictures); | |
| 99 | |
| 61 const proto::LayerUpdate& layer_updates = | 100 const proto::LayerUpdate& layer_updates = |
| 62 layer_tree_host_proto.layer_updates(); | 101 layer_tree_host_proto.layer_updates(); |
| 63 for (int i = 0; i < layer_updates.layers_size(); ++i) { | 102 for (int i = 0; i < layer_updates.layers_size(); ++i) { |
| 64 SynchronizeLayerState(layer_updates.layers(i)); | 103 SynchronizeLayerState(layer_updates.layers(i)); |
| 65 } | 104 } |
| 105 | |
| 106 // The deserialization is finished, so now clear the cache. | |
| 107 client_picture_cache_->Flush(); | |
| 66 } | 108 } |
| 67 | 109 |
| 68 void CompositorStateDeserializer::SetLayerFactoryForTesting( | 110 void CompositorStateDeserializer::SetLayerFactoryForTesting( |
| 69 std::unique_ptr<LayerFactory> layer_factory) { | 111 std::unique_ptr<LayerFactory> layer_factory) { |
| 70 layer_factory_ = std::move(layer_factory); | 112 layer_factory_ = std::move(layer_factory); |
| 71 } | 113 } |
| 72 | 114 |
| 73 void CompositorStateDeserializer::SychronizeLayerTreeState( | 115 void CompositorStateDeserializer::SychronizeLayerTreeState( |
| 74 const proto::LayerTree& layer_tree_proto) { | 116 const proto::LayerTree& layer_tree_proto) { |
| 75 LayerTree* layer_tree = layer_tree_host_->GetLayerTree(); | 117 LayerTree* layer_tree = layer_tree_host_->GetLayerTree(); |
| 76 | 118 |
| 77 // Synchronize the tree hierarchy first. | 119 // Synchronize the tree hierarchy first. |
| 78 // TODO(khushalsagar): Don't do this if the hierarchy didn't change. See | 120 // TODO(khushalsagar): Don't do this if the hierarchy didn't change. See |
| 79 // crbug.com/605170. | 121 // crbug.com/605170. |
| 80 EngineIdToLayerMap new_engine_id_to_layer; | 122 EngineIdToLayerMap new_engine_id_to_layer; |
| 123 ScrollbarLayerToScrollLayerId scrollbar_layer_to_scroll_layer; | |
| 81 if (layer_tree_proto.has_root_layer()) { | 124 if (layer_tree_proto.has_root_layer()) { |
| 82 const proto::LayerNode& root_layer_node = layer_tree_proto.root_layer(); | 125 const proto::LayerNode& root_layer_node = layer_tree_proto.root_layer(); |
| 83 layer_tree->SetRootLayer( | 126 layer_tree->SetRootLayer( |
| 84 GetLayerAndAddToNewMap(root_layer_node, &new_engine_id_to_layer)); | 127 GetLayerAndAddToNewMap(root_layer_node, &new_engine_id_to_layer, |
| 85 SynchronizeLayerHierarchyRecursive( | 128 &scrollbar_layer_to_scroll_layer)); |
| 86 layer_tree->root_layer(), root_layer_node, &new_engine_id_to_layer); | 129 SynchronizeLayerHierarchyRecursive(layer_tree->root_layer(), |
| 130 root_layer_node, &new_engine_id_to_layer, | |
| 131 &scrollbar_layer_to_scroll_layer); | |
| 87 } else { | 132 } else { |
| 88 layer_tree->SetRootLayer(nullptr); | 133 layer_tree->SetRootLayer(nullptr); |
| 89 } | 134 } |
| 90 engine_id_to_layer_.swap(new_engine_id_to_layer); | 135 engine_id_to_layer_.swap(new_engine_id_to_layer); |
| 91 | 136 |
| 137 // Now that the tree has been synced, we can set up the scroll layers, since | |
| 138 // the corresponding engine layers have been created. | |
| 139 for (const auto& scrollbar : scrollbar_layer_to_scroll_layer) { | |
| 140 SolidColorScrollbarLayer* scrollbar_layer = | |
| 141 static_cast<SolidColorScrollbarLayer*>( | |
| 142 GetLayerForEngineId(scrollbar.first)); | |
| 143 scrollbar_layer->SetScrollLayer(GetClientIdFromEngineId(scrollbar.second)); | |
|
vmpstr
2016/10/10 21:28:25
Can you explain the relationships between these id
Khushal
2016/10/10 21:39:24
Done.
| |
| 144 } | |
| 145 | |
| 92 // Synchronize rest of the tree state. | 146 // Synchronize rest of the tree state. |
| 93 layer_tree->RegisterViewportLayers( | 147 layer_tree->RegisterViewportLayers( |
| 94 GetLayer(layer_tree_proto.overscroll_elasticity_layer_id()), | 148 GetLayer(layer_tree_proto.overscroll_elasticity_layer_id()), |
| 95 GetLayer(layer_tree_proto.page_scale_layer_id()), | 149 GetLayer(layer_tree_proto.page_scale_layer_id()), |
| 96 GetLayer(layer_tree_proto.inner_viewport_scroll_layer_id()), | 150 GetLayer(layer_tree_proto.inner_viewport_scroll_layer_id()), |
| 97 GetLayer(layer_tree_proto.outer_viewport_scroll_layer_id())); | 151 GetLayer(layer_tree_proto.outer_viewport_scroll_layer_id())); |
| 98 | 152 |
| 99 layer_tree->SetDeviceScaleFactor(layer_tree_proto.device_scale_factor()); | 153 layer_tree->SetDeviceScaleFactor(layer_tree_proto.device_scale_factor()); |
| 100 layer_tree->SetPaintedDeviceScaleFactor( | 154 layer_tree->SetPaintedDeviceScaleFactor( |
| 101 layer_tree_proto.painted_device_scale_factor()); | 155 layer_tree_proto.painted_device_scale_factor()); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 132 EventListenerClass::kTouchEndOrCancel, | 186 EventListenerClass::kTouchEndOrCancel, |
| 133 static_cast<EventListenerProperties>( | 187 static_cast<EventListenerProperties>( |
| 134 layer_tree_proto.touch_end_or_cancel_event_listener_properties())); | 188 layer_tree_proto.touch_end_or_cancel_event_listener_properties())); |
| 135 } | 189 } |
| 136 | 190 |
| 137 void CompositorStateDeserializer::SynchronizeLayerState( | 191 void CompositorStateDeserializer::SynchronizeLayerState( |
| 138 const proto::LayerProperties& layer_properties_proto) { | 192 const proto::LayerProperties& layer_properties_proto) { |
| 139 int engine_layer_id = layer_properties_proto.id(); | 193 int engine_layer_id = layer_properties_proto.id(); |
| 140 Layer* layer = GetLayerForEngineId(engine_layer_id); | 194 Layer* layer = GetLayerForEngineId(engine_layer_id); |
| 141 | 195 |
| 196 // Layer Inputs ----------------------------------------------------- | |
| 142 const proto::BaseLayerProperties& base = layer_properties_proto.base(); | 197 const proto::BaseLayerProperties& base = layer_properties_proto.base(); |
| 143 | |
| 144 layer->SetNeedsDisplayRect(ProtoToRect(base.update_rect())); | 198 layer->SetNeedsDisplayRect(ProtoToRect(base.update_rect())); |
| 145 layer->SetBounds(ProtoToSize(base.bounds())); | 199 layer->SetBounds(ProtoToSize(base.bounds())); |
| 146 layer->SetMasksToBounds(base.masks_to_bounds()); | 200 layer->SetMasksToBounds(base.masks_to_bounds()); |
| 147 layer->SetOpacity(base.opacity()); | 201 layer->SetOpacity(base.opacity()); |
| 148 layer->SetBlendMode(SkXfermodeModeFromProto(base.blend_mode())); | 202 layer->SetBlendMode(SkXfermodeModeFromProto(base.blend_mode())); |
| 149 layer->SetIsRootForIsolatedGroup(base.is_root_for_isolated_group()); | 203 layer->SetIsRootForIsolatedGroup(base.is_root_for_isolated_group()); |
| 150 layer->SetContentsOpaque(base.contents_opaque()); | 204 layer->SetContentsOpaque(base.contents_opaque()); |
| 151 layer->SetPosition(ProtoToPointF(base.position())); | 205 layer->SetPosition(ProtoToPointF(base.position())); |
| 152 layer->SetTransform(ProtoToTransform(base.transform())); | 206 layer->SetTransform(ProtoToTransform(base.transform())); |
| 153 layer->SetTransformOrigin(ProtoToPoint3F(base.transform_origin())); | 207 layer->SetTransformOrigin(ProtoToPoint3F(base.transform_origin())); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 layer->SetPositionConstraint(position_constraint); | 243 layer->SetPositionConstraint(position_constraint); |
| 190 | 244 |
| 191 LayerStickyPositionConstraint sticky_position_constraint; | 245 LayerStickyPositionConstraint sticky_position_constraint; |
| 192 sticky_position_constraint.FromProtobuf(base.sticky_position_constraint()); | 246 sticky_position_constraint.FromProtobuf(base.sticky_position_constraint()); |
| 193 layer->SetStickyPositionConstraint(sticky_position_constraint); | 247 layer->SetStickyPositionConstraint(sticky_position_constraint); |
| 194 layer->SetScrollParent(GetLayerForEngineId(base.scroll_parent_id())); | 248 layer->SetScrollParent(GetLayerForEngineId(base.scroll_parent_id())); |
| 195 layer->SetClipParent(GetLayerForEngineId(base.clip_parent_id())); | 249 layer->SetClipParent(GetLayerForEngineId(base.clip_parent_id())); |
| 196 | 250 |
| 197 layer->SetHasWillChangeTransformHint(base.has_will_change_transform_hint()); | 251 layer->SetHasWillChangeTransformHint(base.has_will_change_transform_hint()); |
| 198 layer->SetHideLayerAndSubtree(base.hide_layer_and_subtree()); | 252 layer->SetHideLayerAndSubtree(base.hide_layer_and_subtree()); |
| 253 | |
| 254 // ------------------------------------------------------------------ | |
| 255 | |
| 256 // PictureLayer Properties deserialization. | |
| 257 if (layer_properties_proto.has_picture()) { | |
| 258 const proto::PictureLayerProperties& picture_properties = | |
| 259 layer_properties_proto.picture(); | |
| 260 | |
| 261 // Only PictureLayers set picture. | |
| 262 PictureLayer* picture_layer = | |
| 263 static_cast<PictureLayer*>(GetLayerForEngineId(engine_layer_id)); | |
| 264 picture_layer->SetNearestNeighbor(picture_properties.nearest_neighbor()); | |
| 265 | |
| 266 gfx::Rect recorded_viewport = | |
| 267 ProtoToRect(picture_properties.recorded_viewport()); | |
| 268 scoped_refptr<DisplayItemList> display_list; | |
| 269 std::vector<uint32_t> used_engine_picture_ids; | |
| 270 if (picture_properties.has_display_list()) { | |
| 271 display_list = DisplayItemList::CreateFromProto( | |
| 272 picture_properties.display_list(), client_picture_cache_.get(), | |
| 273 &used_engine_picture_ids); | |
| 274 } else { | |
| 275 display_list = nullptr; | |
| 276 } | |
| 277 | |
| 278 // TODO(khushalsagar): The caching here is sub-optimal. If a layer does not | |
| 279 // PushProperties, its pictures won't get counted here even if the layer | |
| 280 // is drawn in the current frame. | |
| 281 for (uint32_t engine_picture_id : used_engine_picture_ids) | |
| 282 client_picture_cache_->MarkUsed(engine_picture_id); | |
| 283 | |
| 284 GetContentLayerClient(engine_layer_id) | |
| 285 ->UpdateDisplayListAndRecordedViewport(display_list, recorded_viewport); | |
| 286 } | |
| 199 } | 287 } |
| 200 | 288 |
| 201 void CompositorStateDeserializer::SynchronizeLayerHierarchyRecursive( | 289 void CompositorStateDeserializer::SynchronizeLayerHierarchyRecursive( |
| 202 Layer* layer, | 290 Layer* layer, |
| 203 const proto::LayerNode& layer_node, | 291 const proto::LayerNode& layer_node, |
| 204 EngineIdToLayerMap* new_layer_map) { | 292 EngineIdToLayerMap* new_layer_map, |
| 293 ScrollbarLayerToScrollLayerId* scrollbar_layer_to_scroll_layer) { | |
| 205 layer->RemoveAllChildren(); | 294 layer->RemoveAllChildren(); |
| 206 | 295 |
| 207 // Children. | 296 // Children. |
| 208 for (int i = 0; i < layer_node.children_size(); i++) { | 297 for (int i = 0; i < layer_node.children_size(); i++) { |
| 209 const proto::LayerNode& child_layer_node = layer_node.children(i); | 298 const proto::LayerNode& child_layer_node = layer_node.children(i); |
| 210 scoped_refptr<Layer> child_layer = | 299 scoped_refptr<Layer> child_layer = GetLayerAndAddToNewMap( |
| 211 GetLayerAndAddToNewMap(child_layer_node, new_layer_map); | 300 child_layer_node, new_layer_map, scrollbar_layer_to_scroll_layer); |
| 212 layer->AddChild(child_layer); | 301 layer->AddChild(child_layer); |
| 213 SynchronizeLayerHierarchyRecursive(child_layer.get(), child_layer_node, | 302 SynchronizeLayerHierarchyRecursive(child_layer.get(), child_layer_node, |
| 214 new_layer_map); | 303 new_layer_map, |
| 304 scrollbar_layer_to_scroll_layer); | |
| 215 } | 305 } |
| 216 | 306 |
| 217 // Mask Layer. | 307 // Mask Layer. |
| 218 if (layer_node.has_mask_layer()) { | 308 if (layer_node.has_mask_layer()) { |
| 219 const proto::LayerNode& mask_layer_node = layer_node.mask_layer(); | 309 const proto::LayerNode& mask_layer_node = layer_node.mask_layer(); |
| 220 scoped_refptr<Layer> mask_layer = | 310 scoped_refptr<Layer> mask_layer = GetLayerAndAddToNewMap( |
| 221 GetLayerAndAddToNewMap(mask_layer_node, new_layer_map); | 311 mask_layer_node, new_layer_map, scrollbar_layer_to_scroll_layer); |
| 222 layer->SetMaskLayer(mask_layer.get()); | 312 layer->SetMaskLayer(mask_layer.get()); |
| 223 SynchronizeLayerHierarchyRecursive(mask_layer.get(), mask_layer_node, | 313 SynchronizeLayerHierarchyRecursive(mask_layer.get(), mask_layer_node, |
| 224 new_layer_map); | 314 new_layer_map, |
| 315 scrollbar_layer_to_scroll_layer); | |
| 225 } else { | 316 } else { |
| 226 layer->SetMaskLayer(nullptr); | 317 layer->SetMaskLayer(nullptr); |
| 227 } | 318 } |
| 228 | 319 |
| 229 // Scroll callback. | 320 // Scroll callback. |
| 230 layer->set_did_scroll_callback(base::Bind(scroll_callback_, layer_node.id())); | 321 layer->set_did_scroll_callback(base::Bind(scroll_callback_, layer_node.id())); |
| 231 } | 322 } |
| 232 | 323 |
| 233 scoped_refptr<Layer> CompositorStateDeserializer::GetLayerAndAddToNewMap( | 324 scoped_refptr<Layer> CompositorStateDeserializer::GetLayerAndAddToNewMap( |
| 234 const proto::LayerNode& layer_node, | 325 const proto::LayerNode& layer_node, |
| 235 EngineIdToLayerMap* new_layer_map) { | 326 EngineIdToLayerMap* new_layer_map, |
| 327 ScrollbarLayerToScrollLayerId* scrollbar_layer_to_scroll_layer) { | |
| 236 DCHECK(new_layer_map->find(layer_node.id()) == new_layer_map->end()) | 328 DCHECK(new_layer_map->find(layer_node.id()) == new_layer_map->end()) |
| 237 << "A LayerNode should have been de-serialized only once"; | 329 << "A LayerNode should have been de-serialized only once"; |
| 238 | 330 |
| 331 scoped_refptr<Layer> layer; | |
| 239 EngineIdToLayerMap::iterator layer_map_it = | 332 EngineIdToLayerMap::iterator layer_map_it = |
| 240 engine_id_to_layer_.find(layer_node.id()); | 333 engine_id_to_layer_.find(layer_node.id()); |
| 241 | 334 |
| 242 if (layer_map_it != engine_id_to_layer_.end()) { | 335 if (layer_map_it != engine_id_to_layer_.end()) { |
| 243 // We can re-use the old layer. | 336 // We can re-use the old layer. |
| 244 (*new_layer_map)[layer_node.id()] = layer_map_it->second; | 337 layer = layer_map_it->second.layer; |
| 245 return layer_map_it->second; | 338 (*new_layer_map)[layer_node.id()] = std::move(layer_map_it->second); |
| 339 engine_id_to_layer_.erase(layer_map_it); | |
| 340 return layer; | |
| 246 } | 341 } |
| 247 | 342 |
| 248 // We need to create a new layer. | 343 // We need to create a new layer. |
| 249 scoped_refptr<Layer> layer; | 344 auto& layer_data = (*new_layer_map)[layer_node.id()]; |
| 250 switch (layer_node.type()) { | 345 switch (layer_node.type()) { |
| 251 case proto::LayerNode::UNKNOWN: | 346 case proto::LayerNode::UNKNOWN: |
| 252 NOTREACHED() << "Unknown Layer type"; | 347 NOTREACHED() << "Unknown Layer type"; |
| 253 case proto::LayerNode::LAYER: | 348 case proto::LayerNode::LAYER: |
| 254 layer = layer_factory_->CreateLayer(layer_node.id()); | 349 layer_data.layer = layer_factory_->CreateLayer(layer_node.id()); |
| 255 break; | 350 break; |
| 256 default: | 351 case proto::LayerNode::PICTURE_LAYER: |
| 257 // TODO(khushalsagar): Add other Layer types. | 352 layer_data.content_layer_client = |
| 353 base::MakeUnique<DeserializedContentLayerClient>(); | |
| 354 layer_data.layer = layer_factory_->CreatePictureLayer( | |
| 355 layer_node.id(), layer_data.content_layer_client.get()); | |
| 356 break; | |
| 357 case proto::LayerNode::SOLID_COLOR_SCROLLBAR_LAYER: { | |
| 358 // SolidColorScrollbarLayers attach their properties in the LayerNode | |
| 359 // itself. | |
| 360 const proto::SolidColorScrollbarLayerProperties& scrollbar = | |
| 361 layer_node.solid_scrollbar(); | |
| 362 | |
| 363 DCHECK(scrollbar_layer_to_scroll_layer->find(layer_node.id()) == | |
| 364 scrollbar_layer_to_scroll_layer->end()); | |
| 365 int scroll_layer_id = scrollbar.scroll_layer_id(); | |
| 366 (*scrollbar_layer_to_scroll_layer)[layer_node.id()] = scroll_layer_id; | |
| 367 | |
| 368 int thumb_thickness = scrollbar.thumb_thickness(); | |
| 369 int track_start = scrollbar.track_start(); | |
| 370 bool is_left_side_vertical_scrollbar = | |
| 371 scrollbar.is_left_side_vertical_scrollbar(); | |
| 372 ScrollbarOrientation orientation = | |
| 373 ScrollbarOrientationFromProto(scrollbar.orientation()); | |
| 374 | |
| 375 // We use the invalid id for the |scroll_layer_id| because the | |
| 376 // corresponding layer on the client may not have been created yet. | |
| 377 layer_data.layer = layer_factory_->CreateSolidColorScrollbarLayer( | |
| 378 layer_node.id(), orientation, thumb_thickness, track_start, | |
| 379 is_left_side_vertical_scrollbar, Layer::LayerIdLabels::INVALID_ID); | |
| 380 } break; | |
| 381 case proto::LayerNode::HEADS_UP_DISPLAY_LAYER: | |
| 382 // TODO(khushalsagar): Remove this from proto. | |
| 258 NOTREACHED(); | 383 NOTREACHED(); |
| 259 } | 384 } |
| 260 | 385 |
| 261 (*new_layer_map)[layer_node.id()] = layer; | 386 layer = layer_data.layer; |
| 262 return layer; | 387 return layer; |
| 263 } | 388 } |
| 264 | 389 |
| 265 int CompositorStateDeserializer::GetClientIdFromEngineId(int engine_layer_id) { | 390 int CompositorStateDeserializer::GetClientIdFromEngineId( |
| 391 int engine_layer_id) const { | |
| 266 Layer* layer = GetLayerForEngineId(engine_layer_id); | 392 Layer* layer = GetLayerForEngineId(engine_layer_id); |
| 267 return layer ? layer->id() : Layer::LayerIdLabels::INVALID_ID; | 393 return layer ? layer->id() : Layer::LayerIdLabels::INVALID_ID; |
| 268 } | 394 } |
| 269 | 395 |
| 270 scoped_refptr<Layer> CompositorStateDeserializer::GetLayer( | 396 scoped_refptr<Layer> CompositorStateDeserializer::GetLayer( |
| 271 int engine_layer_id) { | 397 int engine_layer_id) const { |
| 272 EngineIdToLayerMap::const_iterator layer_it = | 398 EngineIdToLayerMap::const_iterator layer_it = |
| 273 engine_id_to_layer_.find(engine_layer_id); | 399 engine_id_to_layer_.find(engine_layer_id); |
| 274 return layer_it != engine_id_to_layer_.end() ? layer_it->second : nullptr; | 400 return layer_it != engine_id_to_layer_.end() ? layer_it->second.layer |
| 401 : nullptr; | |
| 402 } | |
| 403 | |
| 404 DeserializedContentLayerClient* | |
| 405 CompositorStateDeserializer::GetContentLayerClient(int engine_layer_id) const { | |
| 406 EngineIdToLayerMap::const_iterator layer_it = | |
| 407 engine_id_to_layer_.find(engine_layer_id); | |
| 408 return layer_it != engine_id_to_layer_.end() | |
| 409 ? layer_it->second.content_layer_client.get() | |
| 410 : nullptr; | |
| 275 } | 411 } |
| 276 | 412 |
| 277 } // namespace cc | 413 } // namespace cc |
| OLD | NEW |