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

Side by Side Diff: cc/trees/property_tree.h

Issue 1417963011: Added serialization to protobufs for property trees. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 5 years, 1 month 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_TREES_PROPERTY_TREE_H_ 5 #ifndef CC_TREES_PROPERTY_TREE_H_
6 #define CC_TREES_PROPERTY_TREE_H_ 6 #define CC_TREES_PROPERTY_TREE_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "cc/base/cc_export.h" 11 #include "cc/base/cc_export.h"
12 #include "ui/gfx/geometry/rect_f.h" 12 #include "ui/gfx/geometry/rect_f.h"
13 #include "ui/gfx/geometry/scroll_offset.h" 13 #include "ui/gfx/geometry/scroll_offset.h"
14 #include "ui/gfx/transform.h" 14 #include "ui/gfx/transform.h"
15 15
16 namespace cc { 16 namespace cc {
17 17
18 namespace proto {
19 class ClipNodeData;
20 class EffectNodeData;
21 class PropertyTree;
22 class PropertyTrees;
23 class TranformNodeData;
24 class TransformTreeData;
25 class TreeNode;
26 }
27
28 // Each class declared here has a corresponding proto defined in
29 // cc/proto/property_tree.proto. When making any changes to a class structure
30 // including addition/deletion/updation of a field, please also make the
31 // change to its proto and the ToProtobuf and FromProtobuf methods for that
32 // class.
33
18 template <typename T> 34 template <typename T>
19 struct CC_EXPORT TreeNode { 35 struct CC_EXPORT TreeNode {
20 TreeNode() : id(-1), parent_id(-1), owner_id(-1), data() {} 36 TreeNode() : id(-1), parent_id(-1), owner_id(-1), data() {}
21 int id; 37 int id;
22 int parent_id; 38 int parent_id;
23 int owner_id; 39 int owner_id;
24 T data; 40 T data;
41
42 void ToProtobuf(proto::TreeNode* proto) const;
43 void FromProtobuf(const proto::TreeNode& proto);
25 }; 44 };
26 45
27 struct CC_EXPORT TransformNodeData { 46 struct CC_EXPORT TransformNodeData {
28 TransformNodeData(); 47 TransformNodeData();
29 ~TransformNodeData(); 48 ~TransformNodeData();
30 49
31 // The local transform information is combined to form to_parent (ignoring 50 // The local transform information is combined to form to_parent (ignoring
32 // snapping) as follows: 51 // snapping) as follows:
33 // 52 //
34 // to_parent = M_post_local * T_scroll * M_local * M_pre_local. 53 // to_parent = M_post_local * T_scroll * M_local * M_pre_local.
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 162
144 void set_to_parent(const gfx::Transform& transform) { 163 void set_to_parent(const gfx::Transform& transform) {
145 to_parent = transform; 164 to_parent = transform;
146 is_invertible = to_parent.IsInvertible(); 165 is_invertible = to_parent.IsInvertible();
147 } 166 }
148 167
149 void update_pre_local_transform(const gfx::Point3F& transform_origin); 168 void update_pre_local_transform(const gfx::Point3F& transform_origin);
150 169
151 void update_post_local_transform(const gfx::PointF& position, 170 void update_post_local_transform(const gfx::PointF& position,
152 const gfx::Point3F& transform_origin); 171 const gfx::Point3F& transform_origin);
172
173 void ToProtobuf(proto::TreeNode* proto) const;
174 void FromProtobuf(const proto::TreeNode& proto);
153 }; 175 };
154 176
155 typedef TreeNode<TransformNodeData> TransformNode; 177 typedef TreeNode<TransformNodeData> TransformNode;
156 178
157 struct CC_EXPORT ClipNodeData { 179 struct CC_EXPORT ClipNodeData {
158 ClipNodeData(); 180 ClipNodeData();
159 181
160 // The clip rect that this node contributes, expressed in the space of its 182 // The clip rect that this node contributes, expressed in the space of its
161 // transform node. 183 // transform node.
162 gfx::RectF clip; 184 gfx::RectF clip;
(...skipping 28 matching lines...) Expand all
191 // True if target surface needs to be drawn with a clip applied. 213 // True if target surface needs to be drawn with a clip applied.
192 bool target_is_clipped : 1; 214 bool target_is_clipped : 1;
193 215
194 // True if layers with this clip tree node need to be drawn with a clip 216 // True if layers with this clip tree node need to be drawn with a clip
195 // applied. 217 // applied.
196 bool layers_are_clipped : 1; 218 bool layers_are_clipped : 1;
197 bool layers_are_clipped_when_surfaces_disabled : 1; 219 bool layers_are_clipped_when_surfaces_disabled : 1;
198 220
199 // Nodes that correspond to unclipped surfaces disregard ancestor clips. 221 // Nodes that correspond to unclipped surfaces disregard ancestor clips.
200 bool resets_clip : 1; 222 bool resets_clip : 1;
223
224 bool operator==(const ClipNodeData& other) const;
225
226 void ToProtobuf(proto::TreeNode* proto) const;
227 void FromProtobuf(const proto::TreeNode& proto);
201 }; 228 };
202 229
203 typedef TreeNode<ClipNodeData> ClipNode; 230 typedef TreeNode<ClipNodeData> ClipNode;
204 231
205 struct CC_EXPORT EffectNodeData { 232 struct CC_EXPORT EffectNodeData {
206 EffectNodeData(); 233 EffectNodeData();
207 234
208 float opacity; 235 float opacity;
209 float screen_space_opacity; 236 float screen_space_opacity;
210 237
211 bool has_render_surface; 238 bool has_render_surface;
212 int transform_id; 239 int transform_id;
213 int clip_id; 240 int clip_id;
241
242 bool operator==(const EffectNodeData& other) const;
243
244 void ToProtobuf(proto::TreeNode* proto) const;
245 void FromProtobuf(const proto::TreeNode& proto);
214 }; 246 };
215 247
216 typedef TreeNode<EffectNodeData> EffectNode; 248 typedef TreeNode<EffectNodeData> EffectNode;
217 249
218 template <typename T> 250 template <typename T>
219 class CC_EXPORT PropertyTree { 251 class CC_EXPORT PropertyTree {
220 public: 252 public:
221 PropertyTree(); 253 PropertyTree();
222 virtual ~PropertyTree(); 254 virtual ~PropertyTree();
223 255
(...skipping 19 matching lines...) Expand all
243 } 275 }
244 276
245 virtual void clear(); 277 virtual void clear();
246 size_t size() const { return nodes_.size(); } 278 size_t size() const { return nodes_.size(); }
247 279
248 void set_needs_update(bool needs_update) { needs_update_ = needs_update; } 280 void set_needs_update(bool needs_update) { needs_update_ = needs_update; }
249 bool needs_update() const { return needs_update_; } 281 bool needs_update() const { return needs_update_; }
250 282
251 int next_available_id() const { return static_cast<int>(size()); } 283 int next_available_id() const { return static_cast<int>(size()); }
252 284
285 void ToProtobuf(proto::PropertyTree* proto) const;
286 void FromProtobuf(const proto::PropertyTree& proto);
287
253 private: 288 private:
254 // Copy and assign are permitted. This is how we do tree sync. 289 // Copy and assign are permitted. This is how we do tree sync.
255 std::vector<T> nodes_; 290 std::vector<T> nodes_;
256 291
257 bool needs_update_; 292 bool needs_update_;
258 }; 293 };
259 294
260 class CC_EXPORT TransformTree final : public PropertyTree<TransformNode> { 295 class CC_EXPORT TransformTree final : public PropertyTree<TransformNode> {
261 public: 296 public:
262 TransformTree(); 297 TransformTree();
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 gfx::Vector2dF outer_viewport_bounds_delta() const { 376 gfx::Vector2dF outer_viewport_bounds_delta() const {
342 return outer_viewport_bounds_delta_; 377 return outer_viewport_bounds_delta_;
343 } 378 }
344 379
345 void AddNodeAffectedByInnerViewportBoundsDelta(int node_id); 380 void AddNodeAffectedByInnerViewportBoundsDelta(int node_id);
346 void AddNodeAffectedByOuterViewportBoundsDelta(int node_id); 381 void AddNodeAffectedByOuterViewportBoundsDelta(int node_id);
347 382
348 bool HasNodesAffectedByInnerViewportBoundsDelta() const; 383 bool HasNodesAffectedByInnerViewportBoundsDelta() const;
349 bool HasNodesAffectedByOuterViewportBoundsDelta() const; 384 bool HasNodesAffectedByOuterViewportBoundsDelta() const;
350 385
386 void ToProtobuf(proto::PropertyTree* proto) const;
387 void FromProtobuf(const proto::PropertyTree& proto);
388
351 private: 389 private:
352 // Returns true iff the node at |desc_id| is a descendant of the node at 390 // Returns true iff the node at |desc_id| is a descendant of the node at
353 // |anc_id|. 391 // |anc_id|.
354 bool IsDescendant(int desc_id, int anc_id) const; 392 bool IsDescendant(int desc_id, int anc_id) const;
355 393
356 // Computes the combined transform between |source_id| and |dest_id| and 394 // Computes the combined transform between |source_id| and |dest_id| and
357 // returns false if the inverse of a singular transform was used. These two 395 // returns false if the inverse of a singular transform was used. These two
358 // nodes must be on the same ancestor chain. 396 // nodes must be on the same ancestor chain.
359 bool CombineTransformsBetween(int source_id, 397 bool CombineTransformsBetween(int source_id,
360 int dest_id, 398 int dest_id,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 gfx::Vector2dF inner_viewport_bounds_delta_; 431 gfx::Vector2dF inner_viewport_bounds_delta_;
394 gfx::Vector2dF outer_viewport_bounds_delta_; 432 gfx::Vector2dF outer_viewport_bounds_delta_;
395 std::vector<int> nodes_affected_by_inner_viewport_bounds_delta_; 433 std::vector<int> nodes_affected_by_inner_viewport_bounds_delta_;
396 std::vector<int> nodes_affected_by_outer_viewport_bounds_delta_; 434 std::vector<int> nodes_affected_by_outer_viewport_bounds_delta_;
397 }; 435 };
398 436
399 class CC_EXPORT ClipTree final : public PropertyTree<ClipNode> { 437 class CC_EXPORT ClipTree final : public PropertyTree<ClipNode> {
400 public: 438 public:
401 void SetViewportClip(gfx::RectF viewport_rect); 439 void SetViewportClip(gfx::RectF viewport_rect);
402 gfx::RectF ViewportClip(); 440 gfx::RectF ViewportClip();
441
442 void ToProtobuf(proto::PropertyTree* proto) const;
443 void FromProtobuf(const proto::PropertyTree& proto);
403 }; 444 };
404 445
405 class CC_EXPORT EffectTree final : public PropertyTree<EffectNode> { 446 class CC_EXPORT EffectTree final : public PropertyTree<EffectNode> {
406 public: 447 public:
407 void UpdateOpacities(int id); 448 void UpdateOpacities(int id);
449
450 void ToProtobuf(proto::PropertyTree* proto) const;
451 void FromProtobuf(const proto::PropertyTree& proto);
408 }; 452 };
409 453
410 class CC_EXPORT PropertyTrees final { 454 class CC_EXPORT PropertyTrees final {
411 public: 455 public:
412 PropertyTrees(); 456 PropertyTrees();
413 457
458 static PropertyTrees CreateFromProtobuf(const proto::PropertyTrees& proto);
David Trainor- moved to gerrit 2015/11/12 22:46:11 do we want to just return a PropertyTrees object h
Khushal 2015/11/13 10:33:13 Yeah, just returning property trees is bad. I adde
459 void ToProtobuf(proto::PropertyTrees* proto) const;
460
414 TransformTree transform_tree; 461 TransformTree transform_tree;
415 EffectTree effect_tree; 462 EffectTree effect_tree;
416 ClipTree clip_tree; 463 ClipTree clip_tree;
417 bool needs_rebuild; 464 bool needs_rebuild;
418 bool non_root_surfaces_enabled; 465 bool non_root_surfaces_enabled;
419 int sequence_number; 466 int sequence_number;
420 }; 467 };
421 468
422 } // namespace cc 469 } // namespace cc
423 470
424 #endif // CC_TREES_PROPERTY_TREE_H_ 471 #endif // CC_TREES_PROPERTY_TREE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698