Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(959)

Side by Side Diff: cc/blimp/compositor_state_deserializer.h

Issue 2397843003: cc/blimp: Add (de)-serialization for PictureLayer and ScrollbarLayer. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #ifndef CC_BLIMP_COMPOSITOR_STATE_DESERIALIZER_H_ 5 #ifndef CC_BLIMP_COMPOSITOR_STATE_DESERIALIZER_H_
6 #define CC_BLIMP_COMPOSITOR_STATE_DESERIALIZER_H_ 6 #define CC_BLIMP_COMPOSITOR_STATE_DESERIALIZER_H_
7 7
8 #include <unordered_map> 8 #include <unordered_map>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "cc/base/cc_export.h" 12 #include "cc/base/cc_export.h"
13 13
14 namespace cc { 14 namespace cc {
15 namespace proto { 15 namespace proto {
16 class LayerNode; 16 class LayerNode;
17 class LayerProperties; 17 class LayerProperties;
18 class LayerTree; 18 class LayerTree;
19 class LayerTreeHost; 19 class LayerTreeHost;
20 } // namespace proto 20 } // namespace proto
21 21
22 class ClientPictureCache;
22 class CompositorStateDeserializerClient; 23 class CompositorStateDeserializerClient;
24 class DeserializedContentLayerClient;
23 class Layer; 25 class Layer;
24 class LayerFactory; 26 class LayerFactory;
25 class LayerTreeHost; 27 class LayerTreeHost;
26 28
27 // Deserializes the compositor updates into the LayerTreeHost. 29 // Deserializes the compositor updates into the LayerTreeHost.
28 class CC_EXPORT CompositorStateDeserializer { 30 class CC_EXPORT CompositorStateDeserializer {
29 public: 31 public:
30 // ScrollCallback used to notify the client when the scroll offset for a layer 32 // ScrollCallback used to notify the client when the scroll offset for a layer
31 // is updated. 33 // is updated.
32 using ScrollCallback = base::Callback<void(int engine_layer_id)>; 34 using ScrollCallback = base::Callback<void(int engine_layer_id)>;
33 35
34 CompositorStateDeserializer(LayerTreeHost* layer_tree_host, 36 CompositorStateDeserializer(
35 ScrollCallback scroll_callback, 37 LayerTreeHost* layer_tree_host,
36 CompositorStateDeserializerClient* client); 38 std::unique_ptr<ClientPictureCache> client_picture_cache,
vmpstr 2016/10/06 18:34:21 It looks a bit weird that the deserializer takes o
Khushal 2016/10/06 20:05:40 TBH I want to restructure the code to eliminate th
39 ScrollCallback scroll_callback,
vmpstr 2016/10/06 18:34:21 const ref
Khushal 2016/10/06 20:05:40 Done.
40 CompositorStateDeserializerClient* client);
37 ~CompositorStateDeserializer(); 41 ~CompositorStateDeserializer();
38 42
39 // Returns the local layer on the client for the given |engine_layer_id|. 43 // Returns the local layer on the client for the given |engine_layer_id|.
40 Layer* GetLayerForEngineId(int engine_layer_id) const; 44 Layer* GetLayerForEngineId(int engine_layer_id) const;
41 45
46 // Returns the local layer id on the client for the given |engine_layer_id|.
47 int GetClientIdFromEngineId(int engine_layer_id) const;
vmpstr 2016/10/06 18:34:21 Is this just GetLayerForEngineId()->id()? (if one
Khushal 2016/10/06 20:05:40 Meh. Was just being lazy. Removed.
48
42 // Deserializes the |layer_tree_host_proto| into the LayerTreeHost. 49 // Deserializes the |layer_tree_host_proto| into the LayerTreeHost.
43 void DeserializeCompositorUpdate( 50 void DeserializeCompositorUpdate(
44 const proto::LayerTreeHost& layer_tree_host_proto); 51 const proto::LayerTreeHost& layer_tree_host_proto);
45 52
46 // Allows tests to inject the LayerFactory. 53 // Allows tests to inject the LayerFactory.
47 void SetLayerFactoryForTesting(std::unique_ptr<LayerFactory> layer_factory); 54 void SetLayerFactoryForTesting(std::unique_ptr<LayerFactory> layer_factory);
48 55
49 private: 56 private:
50 using EngineIdToLayerMap = std::unordered_map<int, scoped_refptr<Layer>>; 57 // A holder for the Layer and any data tied to it.
58 struct LayerData {
59 LayerData();
60 ~LayerData();
61
62 scoped_refptr<Layer> layer;
63
64 // Set only for PictureLayers.
65 std::unique_ptr<DeserializedContentLayerClient> content_layer_client;
vmpstr 2016/10/06 18:34:21 Can this just be a member and not a unique_ptr?
Khushal 2016/10/06 20:05:40 Only needed for PictureLayers so I used a unique_p
66 };
67
68 using EngineIdToLayerMap =
69 std::unordered_map<int, std::unique_ptr<LayerData>>;
vmpstr 2016/10/06 18:34:21 Can this be a map of int to LayerData? And maybe y
Khushal 2016/10/06 20:05:40 Good point. Done.
70 // Map of the scrollbar layer id to the corresponding scroll layer id. Both
71 // ids refer to the engine layer id.
72 using ScrollbarLayerToScrollLayerId = std::unordered_map<int, int>;
51 73
52 void SychronizeLayerTreeState(const proto::LayerTree& layer_tree_proto); 74 void SychronizeLayerTreeState(const proto::LayerTree& layer_tree_proto);
53 void SynchronizeLayerState( 75 void SynchronizeLayerState(
54 const proto::LayerProperties& layer_properties_proto); 76 const proto::LayerProperties& layer_properties_proto);
55 void SynchronizeLayerHierarchyRecursive(Layer* layer, 77 void SynchronizeLayerHierarchyRecursive(
56 const proto::LayerNode& layer_node, 78 Layer* layer,
57 EngineIdToLayerMap* new_layer_map); 79 const proto::LayerNode& layer_node,
80 EngineIdToLayerMap* new_layer_map,
81 ScrollbarLayerToScrollLayerId* scrollbar_layer_to_scroll_layer);
58 scoped_refptr<Layer> GetLayerAndAddToNewMap( 82 scoped_refptr<Layer> GetLayerAndAddToNewMap(
59 const proto::LayerNode& layer_node, 83 const proto::LayerNode& layer_node,
60 EngineIdToLayerMap* new_layer_map); 84 EngineIdToLayerMap* new_layer_map,
85 ScrollbarLayerToScrollLayerId* scrollbar_layer_to_scroll_layer);
61 86
62 int GetClientIdFromEngineId(int engine_layer_id); 87 scoped_refptr<Layer> GetLayer(int engine_layer_id) const;
63 scoped_refptr<Layer> GetLayer(int engine_layer_id); 88 DeserializedContentLayerClient* GetContentLayerClient(
89 int engine_layer_id) const;
64 90
65 std::unique_ptr<LayerFactory> layer_factory_; 91 std::unique_ptr<LayerFactory> layer_factory_;
92
66 LayerTreeHost* layer_tree_host_; 93 LayerTreeHost* layer_tree_host_;
94 std::unique_ptr<ClientPictureCache> client_picture_cache_;
67 ScrollCallback scroll_callback_; 95 ScrollCallback scroll_callback_;
68 CompositorStateDeserializerClient* client_; 96 CompositorStateDeserializerClient* client_;
69 97
70 EngineIdToLayerMap engine_id_to_layer_; 98 EngineIdToLayerMap engine_id_to_layer_;
71 99
72 DISALLOW_COPY_AND_ASSIGN(CompositorStateDeserializer); 100 DISALLOW_COPY_AND_ASSIGN(CompositorStateDeserializer);
73 }; 101 };
74 102
75 } // namespace cc 103 } // namespace cc
76 104
77 #endif // CC_BLIMP_COMPOSITOR_STATE_DESERIALIZER_H_ 105 #endif // CC_BLIMP_COMPOSITOR_STATE_DESERIALIZER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698