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

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: Rebase and address comments. Created 5 years 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
« no previous file with comments | « cc/proto/property_tree.proto ('k') | cc/trees/property_tree.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // ------------------------------*IMPORTANT*---------------------------------
29 // Each class declared here has a corresponding proto defined in
30 // cc/proto/property_tree.proto. When making any changes to a class structure
31 // including addition/deletion/updation of a field, please also make the
32 // change to its proto and the ToProtobuf and FromProtobuf methods for that
33 // class.
34
18 template <typename T> 35 template <typename T>
19 struct CC_EXPORT TreeNode { 36 struct CC_EXPORT TreeNode {
20 TreeNode() : id(-1), parent_id(-1), owner_id(-1), data() {} 37 TreeNode() : id(-1), parent_id(-1), owner_id(-1), data() {}
21 int id; 38 int id;
22 int parent_id; 39 int parent_id;
23 int owner_id; 40 int owner_id;
24 T data; 41 T data;
42
43 bool operator==(const TreeNode<T>& other) const;
44
45 void ToProtobuf(proto::TreeNode* proto) const;
46 void FromProtobuf(const proto::TreeNode& proto);
25 }; 47 };
26 48
27 struct CC_EXPORT TransformNodeData { 49 struct CC_EXPORT TransformNodeData {
28 TransformNodeData(); 50 TransformNodeData();
29 ~TransformNodeData(); 51 ~TransformNodeData();
30 52
31 // The local transform information is combined to form to_parent (ignoring 53 // The local transform information is combined to form to_parent (ignoring
32 // snapping) as follows: 54 // snapping) as follows:
33 // 55 //
34 // to_parent = M_post_local * T_scroll * M_local * M_pre_local. 56 // to_parent = M_post_local * T_scroll * M_local * M_pre_local.
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 156
135 // We scroll snap where possible, but this has an effect on scroll 157 // We scroll snap where possible, but this has an effect on scroll
136 // compensation: the snap is yet more scrolling that must be compensated for. 158 // compensation: the snap is yet more scrolling that must be compensated for.
137 // This value stores the snapped amount for this purpose. 159 // This value stores the snapped amount for this purpose.
138 gfx::Vector2dF scroll_snap; 160 gfx::Vector2dF scroll_snap;
139 161
140 // TODO(vollick): will be moved when accelerated effects are implemented. 162 // TODO(vollick): will be moved when accelerated effects are implemented.
141 gfx::Vector2dF source_offset; 163 gfx::Vector2dF source_offset;
142 gfx::Vector2dF source_to_parent; 164 gfx::Vector2dF source_to_parent;
143 165
166 bool operator==(const TransformNodeData& other) const;
167
144 void set_to_parent(const gfx::Transform& transform) { 168 void set_to_parent(const gfx::Transform& transform) {
145 to_parent = transform; 169 to_parent = transform;
146 is_invertible = to_parent.IsInvertible(); 170 is_invertible = to_parent.IsInvertible();
147 } 171 }
148 172
149 void update_pre_local_transform(const gfx::Point3F& transform_origin); 173 void update_pre_local_transform(const gfx::Point3F& transform_origin);
150 174
151 void update_post_local_transform(const gfx::PointF& position, 175 void update_post_local_transform(const gfx::PointF& position,
152 const gfx::Point3F& transform_origin); 176 const gfx::Point3F& transform_origin);
177
178 void ToProtobuf(proto::TreeNode* proto) const;
179 void FromProtobuf(const proto::TreeNode& proto);
153 }; 180 };
154 181
155 typedef TreeNode<TransformNodeData> TransformNode; 182 typedef TreeNode<TransformNodeData> TransformNode;
156 183
157 struct CC_EXPORT ClipNodeData { 184 struct CC_EXPORT ClipNodeData {
158 ClipNodeData(); 185 ClipNodeData();
159 186
160 // The clip rect that this node contributes, expressed in the space of its 187 // The clip rect that this node contributes, expressed in the space of its
161 // transform node. 188 // transform node.
162 gfx::RectF clip; 189 gfx::RectF clip;
(...skipping 28 matching lines...) Expand all
191 // True if target surface needs to be drawn with a clip applied. 218 // True if target surface needs to be drawn with a clip applied.
192 bool target_is_clipped : 1; 219 bool target_is_clipped : 1;
193 220
194 // True if layers with this clip tree node need to be drawn with a clip 221 // True if layers with this clip tree node need to be drawn with a clip
195 // applied. 222 // applied.
196 bool layers_are_clipped : 1; 223 bool layers_are_clipped : 1;
197 bool layers_are_clipped_when_surfaces_disabled : 1; 224 bool layers_are_clipped_when_surfaces_disabled : 1;
198 225
199 // Nodes that correspond to unclipped surfaces disregard ancestor clips. 226 // Nodes that correspond to unclipped surfaces disregard ancestor clips.
200 bool resets_clip : 1; 227 bool resets_clip : 1;
228
229 bool operator==(const ClipNodeData& other) const;
230
231 void ToProtobuf(proto::TreeNode* proto) const;
232 void FromProtobuf(const proto::TreeNode& proto);
201 }; 233 };
202 234
203 typedef TreeNode<ClipNodeData> ClipNode; 235 typedef TreeNode<ClipNodeData> ClipNode;
204 236
205 struct CC_EXPORT EffectNodeData { 237 struct CC_EXPORT EffectNodeData {
206 EffectNodeData(); 238 EffectNodeData();
207 239
208 float opacity; 240 float opacity;
209 float screen_space_opacity; 241 float screen_space_opacity;
210 242
211 bool has_render_surface; 243 bool has_render_surface;
212 int transform_id; 244 int transform_id;
213 int clip_id; 245 int clip_id;
246
247 bool operator==(const EffectNodeData& other) const;
248
249 void ToProtobuf(proto::TreeNode* proto) const;
250 void FromProtobuf(const proto::TreeNode& proto);
214 }; 251 };
215 252
216 typedef TreeNode<EffectNodeData> EffectNode; 253 typedef TreeNode<EffectNodeData> EffectNode;
217 254
218 template <typename T> 255 template <typename T>
219 class CC_EXPORT PropertyTree { 256 class CC_EXPORT PropertyTree {
220 public: 257 public:
221 PropertyTree(); 258 PropertyTree();
222 virtual ~PropertyTree(); 259 virtual ~PropertyTree();
223 260
261 bool operator==(const PropertyTree<T>& other) const;
262
224 int Insert(const T& tree_node, int parent_id); 263 int Insert(const T& tree_node, int parent_id);
225 264
226 T* Node(int i) { 265 T* Node(int i) {
227 // TODO(vollick): remove this. 266 // TODO(vollick): remove this.
228 CHECK(i < static_cast<int>(nodes_.size())); 267 CHECK(i < static_cast<int>(nodes_.size()));
229 return i > -1 ? &nodes_[i] : nullptr; 268 return i > -1 ? &nodes_[i] : nullptr;
230 } 269 }
231 const T* Node(int i) const { 270 const T* Node(int i) const {
232 // TODO(vollick): remove this. 271 // TODO(vollick): remove this.
233 CHECK(i < static_cast<int>(nodes_.size())); 272 CHECK(i < static_cast<int>(nodes_.size()));
234 return i > -1 ? &nodes_[i] : nullptr; 273 return i > -1 ? &nodes_[i] : nullptr;
235 } 274 }
236 275
237 T* parent(const T* t) { return Node(t->parent_id); } 276 T* parent(const T* t) { return Node(t->parent_id); }
238 const T* parent(const T* t) const { return Node(t->parent_id); } 277 const T* parent(const T* t) const { return Node(t->parent_id); }
239 278
240 T* back() { return size() ? &nodes_[nodes_.size() - 1] : nullptr; } 279 T* back() { return size() ? &nodes_[nodes_.size() - 1] : nullptr; }
241 const T* back() const { 280 const T* back() const {
242 return size() ? &nodes_[nodes_.size() - 1] : nullptr; 281 return size() ? &nodes_[nodes_.size() - 1] : nullptr;
243 } 282 }
244 283
245 virtual void clear(); 284 virtual void clear();
246 size_t size() const { return nodes_.size(); } 285 size_t size() const { return nodes_.size(); }
247 286
248 void set_needs_update(bool needs_update) { needs_update_ = needs_update; } 287 void set_needs_update(bool needs_update) { needs_update_ = needs_update; }
249 bool needs_update() const { return needs_update_; } 288 bool needs_update() const { return needs_update_; }
250 289
290 const std::vector<T>& nodes() const { return nodes_; }
291
251 int next_available_id() const { return static_cast<int>(size()); } 292 int next_available_id() const { return static_cast<int>(size()); }
252 293
294 void ToProtobuf(proto::PropertyTree* proto) const;
295 void FromProtobuf(const proto::PropertyTree& proto);
296
253 private: 297 private:
254 // Copy and assign are permitted. This is how we do tree sync. 298 // Copy and assign are permitted. This is how we do tree sync.
255 std::vector<T> nodes_; 299 std::vector<T> nodes_;
256 300
257 bool needs_update_; 301 bool needs_update_;
258 }; 302 };
259 303
260 class CC_EXPORT TransformTree final : public PropertyTree<TransformNode> { 304 class CC_EXPORT TransformTree final : public PropertyTree<TransformNode> {
261 public: 305 public:
262 TransformTree(); 306 TransformTree();
263 ~TransformTree() override; 307 ~TransformTree() override;
264 308
309 bool operator==(const TransformTree& other) const;
310
265 void clear() override; 311 void clear() override;
266 312
267 // Computes the change of basis transform from node |source_id| to |dest_id|. 313 // Computes the change of basis transform from node |source_id| to |dest_id|.
268 // The function returns false iff the inverse of a singular transform was 314 // The function returns false iff the inverse of a singular transform was
269 // used (and the result should, therefore, not be trusted). Transforms may 315 // used (and the result should, therefore, not be trusted). Transforms may
270 // be computed between any pair of nodes that have an ancestor/descendant 316 // be computed between any pair of nodes that have an ancestor/descendant
271 // relationship. Transforms between other pairs of nodes may only be computed 317 // relationship. Transforms between other pairs of nodes may only be computed
272 // if the following condition holds: let id1 the larger id and let id2 be the 318 // if the following condition holds: let id1 the larger id and let id2 be the
273 // other id; then the nearest ancestor of node id1 whose id is smaller than 319 // other id; then the nearest ancestor of node id1 whose id is smaller than
274 // id2 is the lowest common ancestor of the pair of nodes, and the transform 320 // id2 is the lowest common ancestor of the pair of nodes, and the transform
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 float page_scale_factor() const { return page_scale_factor_; } 370 float page_scale_factor() const { return page_scale_factor_; }
325 371
326 void set_device_scale_factor(float device_scale_factor) { 372 void set_device_scale_factor(float device_scale_factor) {
327 device_scale_factor_ = device_scale_factor; 373 device_scale_factor_ = device_scale_factor;
328 } 374 }
329 float device_scale_factor() const { return device_scale_factor_; } 375 float device_scale_factor() const { return device_scale_factor_; }
330 376
331 void SetDeviceTransform(const gfx::Transform& transform, 377 void SetDeviceTransform(const gfx::Transform& transform,
332 gfx::PointF root_position); 378 gfx::PointF root_position);
333 void SetDeviceTransformScaleFactor(const gfx::Transform& transform); 379 void SetDeviceTransformScaleFactor(const gfx::Transform& transform);
380 float device_transform_scale_factor() const {
381 return device_transform_scale_factor_;
382 }
334 383
335 void SetInnerViewportBoundsDelta(gfx::Vector2dF bounds_delta); 384 void SetInnerViewportBoundsDelta(gfx::Vector2dF bounds_delta);
336 gfx::Vector2dF inner_viewport_bounds_delta() const { 385 gfx::Vector2dF inner_viewport_bounds_delta() const {
337 return inner_viewport_bounds_delta_; 386 return inner_viewport_bounds_delta_;
338 } 387 }
339 388
340 void SetOuterViewportBoundsDelta(gfx::Vector2dF bounds_delta); 389 void SetOuterViewportBoundsDelta(gfx::Vector2dF bounds_delta);
341 gfx::Vector2dF outer_viewport_bounds_delta() const { 390 gfx::Vector2dF outer_viewport_bounds_delta() const {
342 return outer_viewport_bounds_delta_; 391 return outer_viewport_bounds_delta_;
343 } 392 }
344 393
345 void AddNodeAffectedByInnerViewportBoundsDelta(int node_id); 394 void AddNodeAffectedByInnerViewportBoundsDelta(int node_id);
346 void AddNodeAffectedByOuterViewportBoundsDelta(int node_id); 395 void AddNodeAffectedByOuterViewportBoundsDelta(int node_id);
347 396
348 bool HasNodesAffectedByInnerViewportBoundsDelta() const; 397 bool HasNodesAffectedByInnerViewportBoundsDelta() const;
349 bool HasNodesAffectedByOuterViewportBoundsDelta() const; 398 bool HasNodesAffectedByOuterViewportBoundsDelta() const;
350 399
400 const std::vector<int>& nodes_affected_by_inner_viewport_bounds_delta()
401 const {
402 return nodes_affected_by_inner_viewport_bounds_delta_;
403 }
404 const std::vector<int>& nodes_affected_by_outer_viewport_bounds_delta()
405 const {
406 return nodes_affected_by_outer_viewport_bounds_delta_;
407 }
408
409 void ToProtobuf(proto::PropertyTree* proto) const;
410 void FromProtobuf(const proto::PropertyTree& proto);
411
351 private: 412 private:
352 // Returns true iff the node at |desc_id| is a descendant of the node at 413 // Returns true iff the node at |desc_id| is a descendant of the node at
353 // |anc_id|. 414 // |anc_id|.
354 bool IsDescendant(int desc_id, int anc_id) const; 415 bool IsDescendant(int desc_id, int anc_id) const;
355 416
356 // Computes the combined transform between |source_id| and |dest_id| and 417 // 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 418 // returns false if the inverse of a singular transform was used. These two
358 // nodes must be on the same ancestor chain. 419 // nodes must be on the same ancestor chain.
359 bool CombineTransformsBetween(int source_id, 420 bool CombineTransformsBetween(int source_id,
360 int dest_id, 421 int dest_id,
(...skipping 30 matching lines...) Expand all
391 float device_scale_factor_; 452 float device_scale_factor_;
392 float device_transform_scale_factor_; 453 float device_transform_scale_factor_;
393 gfx::Vector2dF inner_viewport_bounds_delta_; 454 gfx::Vector2dF inner_viewport_bounds_delta_;
394 gfx::Vector2dF outer_viewport_bounds_delta_; 455 gfx::Vector2dF outer_viewport_bounds_delta_;
395 std::vector<int> nodes_affected_by_inner_viewport_bounds_delta_; 456 std::vector<int> nodes_affected_by_inner_viewport_bounds_delta_;
396 std::vector<int> nodes_affected_by_outer_viewport_bounds_delta_; 457 std::vector<int> nodes_affected_by_outer_viewport_bounds_delta_;
397 }; 458 };
398 459
399 class CC_EXPORT ClipTree final : public PropertyTree<ClipNode> { 460 class CC_EXPORT ClipTree final : public PropertyTree<ClipNode> {
400 public: 461 public:
462 bool operator==(const ClipTree& other) const;
463
401 void SetViewportClip(gfx::RectF viewport_rect); 464 void SetViewportClip(gfx::RectF viewport_rect);
402 gfx::RectF ViewportClip(); 465 gfx::RectF ViewportClip();
466
467 void ToProtobuf(proto::PropertyTree* proto) const;
468 void FromProtobuf(const proto::PropertyTree& proto);
403 }; 469 };
404 470
405 class CC_EXPORT EffectTree final : public PropertyTree<EffectNode> { 471 class CC_EXPORT EffectTree final : public PropertyTree<EffectNode> {
406 public: 472 public:
473 bool operator==(const EffectTree& other) const;
474
407 void UpdateOpacities(int id); 475 void UpdateOpacities(int id);
476
477 void ToProtobuf(proto::PropertyTree* proto) const;
478 void FromProtobuf(const proto::PropertyTree& proto);
408 }; 479 };
409 480
410 class CC_EXPORT PropertyTrees final { 481 class CC_EXPORT PropertyTrees final {
411 public: 482 public:
412 PropertyTrees(); 483 PropertyTrees();
413 484
485 bool operator==(const PropertyTrees& other) const;
486
487 void ToProtobuf(proto::PropertyTrees* proto) const;
488 void FromProtobuf(const proto::PropertyTrees& proto);
489
414 TransformTree transform_tree; 490 TransformTree transform_tree;
415 EffectTree effect_tree; 491 EffectTree effect_tree;
416 ClipTree clip_tree; 492 ClipTree clip_tree;
417 bool needs_rebuild; 493 bool needs_rebuild;
418 bool non_root_surfaces_enabled; 494 bool non_root_surfaces_enabled;
419 int sequence_number; 495 int sequence_number;
420 }; 496 };
421 497
422 } // namespace cc 498 } // namespace cc
423 499
424 #endif // CC_TREES_PROPERTY_TREE_H_ 500 #endif // CC_TREES_PROPERTY_TREE_H_
OLDNEW
« no previous file with comments | « cc/proto/property_tree.proto ('k') | cc/trees/property_tree.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698