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