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

Side by Side Diff: cc/layers/layer_impl.h

Issue 800613009: Convert scroll offsets to use SyncedProperty. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Clean up, rebase Created 5 years, 10 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 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 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_LAYERS_LAYER_IMPL_H_ 5 #ifndef CC_LAYERS_LAYER_IMPL_H_
6 #define CC_LAYERS_LAYER_IMPL_H_ 6 #define CC_LAYERS_LAYER_IMPL_H_
7 7
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "cc/animation/animation_delegate.h" 15 #include "cc/animation/animation_delegate.h"
16 #include "cc/animation/layer_animation_controller.h" 16 #include "cc/animation/layer_animation_controller.h"
17 #include "cc/animation/layer_animation_value_observer.h" 17 #include "cc/animation/layer_animation_value_observer.h"
18 #include "cc/animation/layer_animation_value_provider.h" 18 #include "cc/animation/layer_animation_value_provider.h"
19 #include "cc/base/cc_export.h" 19 #include "cc/base/cc_export.h"
20 #include "cc/base/region.h" 20 #include "cc/base/region.h"
21 #include "cc/base/scoped_ptr_vector.h" 21 #include "cc/base/scoped_ptr_vector.h"
22 #include "cc/base/synced_property.h"
22 #include "cc/debug/frame_timing_request.h" 23 #include "cc/debug/frame_timing_request.h"
23 #include "cc/input/input_handler.h" 24 #include "cc/input/input_handler.h"
24 #include "cc/input/scrollbar.h" 25 #include "cc/input/scrollbar.h"
25 #include "cc/layers/draw_properties.h" 26 #include "cc/layers/draw_properties.h"
26 #include "cc/layers/layer_lists.h" 27 #include "cc/layers/layer_lists.h"
27 #include "cc/layers/layer_position_constraint.h" 28 #include "cc/layers/layer_position_constraint.h"
28 #include "cc/layers/render_surface_impl.h" 29 #include "cc/layers/render_surface_impl.h"
29 #include "cc/output/filter_operations.h" 30 #include "cc/output/filter_operations.h"
30 #include "cc/quads/shared_quad_state.h" 31 #include "cc/quads/shared_quad_state.h"
31 #include "cc/resources/resource_provider.h" 32 #include "cc/resources/resource_provider.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 }; 75 };
75 76
76 class CC_EXPORT LayerImpl : public LayerAnimationValueObserver, 77 class CC_EXPORT LayerImpl : public LayerAnimationValueObserver,
77 public LayerAnimationValueProvider, 78 public LayerAnimationValueProvider,
78 public AnimationDelegate { 79 public AnimationDelegate {
79 public: 80 public:
80 // Allows for the ownership of the total scroll offset to be delegated outside 81 // Allows for the ownership of the total scroll offset to be delegated outside
81 // of the layer. 82 // of the layer.
82 class ScrollOffsetDelegate { 83 class ScrollOffsetDelegate {
83 public: 84 public:
84 virtual void SetTotalScrollOffset(const gfx::ScrollOffset& new_value) = 0; 85 virtual void SetCurrentScrollOffset(const gfx::ScrollOffset& new_value) = 0;
85 virtual gfx::ScrollOffset GetTotalScrollOffset() = 0; 86 virtual gfx::ScrollOffset GetCurrentScrollOffset() = 0;
86 virtual bool IsExternalFlingActive() const = 0; 87 virtual bool IsExternalFlingActive() const = 0;
87 virtual void Update() const = 0; 88 virtual void Update() const = 0;
88 }; 89 };
89 90
91 typedef SyncedProperty<AdditionGroup<gfx::ScrollOffset>> SyncedScrollOffset;
90 typedef LayerImplList RenderSurfaceListType; 92 typedef LayerImplList RenderSurfaceListType;
91 typedef LayerImplList LayerListType; 93 typedef LayerImplList LayerListType;
92 typedef RenderSurfaceImpl RenderSurfaceType; 94 typedef RenderSurfaceImpl RenderSurfaceType;
93 95
94 enum RenderingContextConstants { NO_RENDERING_CONTEXT = 0 }; 96 enum RenderingContextConstants { NO_RENDERING_CONTEXT = 0 };
95 97
98 static scoped_ptr<LayerImpl> Create(
99 LayerTreeImpl* tree_impl,
100 int id,
101 scoped_refptr<SyncedScrollOffset> scroll_offset) {
102 return make_scoped_ptr(new LayerImpl(tree_impl, id, scroll_offset));
103 }
104
96 static scoped_ptr<LayerImpl> Create(LayerTreeImpl* tree_impl, int id) { 105 static scoped_ptr<LayerImpl> Create(LayerTreeImpl* tree_impl, int id) {
97 return make_scoped_ptr(new LayerImpl(tree_impl, id)); 106 return make_scoped_ptr(new LayerImpl(tree_impl, id));
98 } 107 }
99 108
100 ~LayerImpl() override; 109 ~LayerImpl() override;
101 110
102 int id() const { return layer_id_; } 111 int id() const { return layer_id_; }
103 112
104 // LayerAnimationValueProvider implementation. 113 // LayerAnimationValueProvider implementation.
105 gfx::ScrollOffset ScrollOffsetForAnimation() const override; 114 gfx::ScrollOffset ScrollOffsetForAnimation() const override;
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 gfx::Vector2dF bounds_delta() const { return bounds_delta_; } 387 gfx::Vector2dF bounds_delta() const { return bounds_delta_; }
379 388
380 void SetContentBounds(const gfx::Size& content_bounds); 389 void SetContentBounds(const gfx::Size& content_bounds);
381 gfx::Size content_bounds() const { return draw_properties_.content_bounds; } 390 gfx::Size content_bounds() const { return draw_properties_.content_bounds; }
382 391
383 float contents_scale_x() const { return draw_properties_.contents_scale_x; } 392 float contents_scale_x() const { return draw_properties_.contents_scale_x; }
384 float contents_scale_y() const { return draw_properties_.contents_scale_y; } 393 float contents_scale_y() const { return draw_properties_.contents_scale_y; }
385 void SetContentsScale(float contents_scale_x, float contents_scale_y); 394 void SetContentsScale(float contents_scale_x, float contents_scale_y);
386 395
387 void SetScrollOffsetDelegate(ScrollOffsetDelegate* scroll_offset_delegate); 396 void SetScrollOffsetDelegate(ScrollOffsetDelegate* scroll_offset_delegate);
388 void DidScroll(); 397 void RefreshFromScrollDelegate();
389 bool IsExternalFlingActive() const; 398 bool IsExternalFlingActive() const;
390 399
391 void SetScrollOffset(const gfx::ScrollOffset& scroll_offset); 400 void SetCurrentScrollOffset(const gfx::ScrollOffset& scroll_offset);
392 void SetScrollOffsetAndDelta(const gfx::ScrollOffset& scroll_offset, 401 void PushScrollOffsetFromMainThread(const gfx::ScrollOffset& scroll_offset);
393 const gfx::Vector2dF& scroll_delta); 402 gfx::ScrollOffset PullDeltaForMainThread();
394 gfx::ScrollOffset scroll_offset() const { return scroll_offset_; } 403 gfx::ScrollOffset CurrentScrollOffset() const;
404 gfx::ScrollOffset BaseScrollOffset() const;
405 gfx::Vector2dF ScrollDelta() const;
406 void SetScrollDelta(const gfx::Vector2dF& delta);
395 407
396 gfx::ScrollOffset MaxScrollOffset() const; 408 gfx::ScrollOffset MaxScrollOffset() const;
409 gfx::ScrollOffset ClampScrollOffsetToLimits(gfx::ScrollOffset offset) const;
397 gfx::Vector2dF ClampScrollToMaxScrollOffset(); 410 gfx::Vector2dF ClampScrollToMaxScrollOffset();
398 void SetScrollbarPosition(ScrollbarLayerImplBase* scrollbar_layer, 411 void SetScrollbarPosition(ScrollbarLayerImplBase* scrollbar_layer,
399 LayerImpl* scrollbar_clip_layer, 412 LayerImpl* scrollbar_clip_layer,
400 bool on_resize) const; 413 bool on_resize) const;
401 void SetScrollDelta(const gfx::Vector2dF& scroll_delta);
402 gfx::Vector2dF ScrollDelta() const;
403
404 void SetMainScrollOffsetFractionalPart(const gfx::Vector2dF& scroll_offset) { 414 void SetMainScrollOffsetFractionalPart(const gfx::Vector2dF& scroll_offset) {
405 main_scroll_offset_fractional_part_ = scroll_offset; 415 main_scroll_offset_fractional_part_ = scroll_offset;
406 } 416 }
407 gfx::Vector2dF MainScrollOffsetFractionalPart() const { 417 gfx::Vector2dF MainScrollOffsetFractionalPart() const {
408 return main_scroll_offset_fractional_part_; 418 return main_scroll_offset_fractional_part_;
409 } 419 }
410 420
411 gfx::ScrollOffset TotalScrollOffset() const;
412
413 void SetSentScrollDelta(const gfx::Vector2dF& sent_scroll_delta);
414 gfx::Vector2dF sent_scroll_delta() const { return sent_scroll_delta_; }
415
416 // Returns the delta of the scroll that was outside of the bounds of the 421 // Returns the delta of the scroll that was outside of the bounds of the
417 // initial scroll 422 // initial scroll
418 gfx::Vector2dF ScrollBy(const gfx::Vector2dF& scroll); 423 gfx::Vector2dF ScrollBy(const gfx::Vector2dF& scroll);
419 424
425 // TODO(aelias): Delete these three methods after doing a mass rename in
aelias_OOO_until_Jul13 2015/01/30 05:52:31 I want to rename these methods but they're used in
enne (OOO) 2015/01/30 21:08:14 sgtm
426 // tests.
427 gfx::ScrollOffset TotalScrollOffset() const { return CurrentScrollOffset(); }
428 void SetScrollOffset(const gfx::ScrollOffset& scroll_offset) {
429 PushScrollOffsetFromMainThread(scroll_offset);
430 }
431 gfx::ScrollOffset scroll_offset() const { return BaseScrollOffset(); }
432
420 void SetScrollClipLayer(int scroll_clip_layer_id); 433 void SetScrollClipLayer(int scroll_clip_layer_id);
421 LayerImpl* scroll_clip_layer() const { return scroll_clip_layer_; } 434 LayerImpl* scroll_clip_layer() const { return scroll_clip_layer_; }
422 bool scrollable() const { return !!scroll_clip_layer_; } 435 bool scrollable() const { return !!scroll_clip_layer_; }
423 436
424 void set_user_scrollable_horizontal(bool scrollable) { 437 void set_user_scrollable_horizontal(bool scrollable) {
425 user_scrollable_horizontal_ = scrollable; 438 user_scrollable_horizontal_ = scrollable;
426 } 439 }
427 bool user_scrollable_horizontal() const { 440 bool user_scrollable_horizontal() const {
428 return user_scrollable_horizontal_; 441 return user_scrollable_horizontal_;
429 } 442 }
430 void set_user_scrollable_vertical(bool scrollable) { 443 void set_user_scrollable_vertical(bool scrollable) {
431 user_scrollable_vertical_ = scrollable; 444 user_scrollable_vertical_ = scrollable;
432 } 445 }
433 bool user_scrollable_vertical() const { return user_scrollable_vertical_; } 446 bool user_scrollable_vertical() const { return user_scrollable_vertical_; }
434 447
435 bool user_scrollable(ScrollbarOrientation orientation) const; 448 bool user_scrollable(ScrollbarOrientation orientation) const;
436 449
437 void ApplySentScrollDeltasFromAbortedCommit(); 450 void ApplySentScrollDeltasFromAbortedCommit();
438 void ApplyScrollDeltasSinceBeginMainFrame();
439 451
440 void SetShouldScrollOnMainThread(bool should_scroll_on_main_thread) { 452 void SetShouldScrollOnMainThread(bool should_scroll_on_main_thread) {
441 should_scroll_on_main_thread_ = should_scroll_on_main_thread; 453 should_scroll_on_main_thread_ = should_scroll_on_main_thread;
442 } 454 }
443 bool should_scroll_on_main_thread() const { 455 bool should_scroll_on_main_thread() const {
444 return should_scroll_on_main_thread_; 456 return should_scroll_on_main_thread_;
445 } 457 }
446 458
447 void SetHaveWheelEventHandlers(bool have_wheel_event_handlers) { 459 void SetHaveWheelEventHandlers(bool have_wheel_event_handlers) {
448 have_wheel_event_handlers_ = have_wheel_event_handlers; 460 have_wheel_event_handlers_ = have_wheel_event_handlers;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 586
575 void Set3dSortingContextId(int id); 587 void Set3dSortingContextId(int id);
576 int sorting_context_id() { return sorting_context_id_; } 588 int sorting_context_id() { return sorting_context_id_; }
577 589
578 void PassFrameTimingRequests( 590 void PassFrameTimingRequests(
579 std::vector<FrameTimingRequest>* frame_timing_requests); 591 std::vector<FrameTimingRequest>* frame_timing_requests);
580 const std::vector<FrameTimingRequest>& frame_timing_requests() const { 592 const std::vector<FrameTimingRequest>& frame_timing_requests() const {
581 return frame_timing_requests_; 593 return frame_timing_requests_;
582 } 594 }
583 595
596 SyncedScrollOffset* synced_scroll_offset() { return scroll_offset_.get(); }
597
584 protected: 598 protected:
599 LayerImpl(LayerTreeImpl* layer_impl,
600 int id,
601 scoped_refptr<SyncedScrollOffset> scroll_offset);
585 LayerImpl(LayerTreeImpl* layer_impl, int id); 602 LayerImpl(LayerTreeImpl* layer_impl, int id);
586 603
587 // Get the color and size of the layer's debug border. 604 // Get the color and size of the layer's debug border.
588 virtual void GetDebugBorderProperties(SkColor* color, float* width) const; 605 virtual void GetDebugBorderProperties(SkColor* color, float* width) const;
589 606
590 void AppendDebugBorderQuad(RenderPass* render_pass, 607 void AppendDebugBorderQuad(RenderPass* render_pass,
591 const gfx::Size& content_bounds, 608 const gfx::Size& content_bounds,
592 const SharedQuadState* shared_quad_state, 609 const SharedQuadState* shared_quad_state,
593 AppendQuadsData* append_quads_data) const; 610 AppendQuadsData* append_quads_data) const;
594 void AppendDebugBorderQuad(RenderPass* render_pass, 611 void AppendDebugBorderQuad(RenderPass* render_pass,
595 const gfx::Size& content_bounds, 612 const gfx::Size& content_bounds,
596 const SharedQuadState* shared_quad_state, 613 const SharedQuadState* shared_quad_state,
597 AppendQuadsData* append_quads_data, 614 AppendQuadsData* append_quads_data,
598 SkColor color, 615 SkColor color,
599 float width) const; 616 float width) const;
600 617
601 void NoteLayerPropertyChanged(); 618 void NoteLayerPropertyChanged();
602 void NoteLayerPropertyChangedForSubtree(); 619 void NoteLayerPropertyChangedForSubtree();
603 620
604 // Note carefully this does not affect the current layer. 621 // Note carefully this does not affect the current layer.
605 void NoteLayerPropertyChangedForDescendants(); 622 void NoteLayerPropertyChangedForDescendants();
606 623
607 private: 624 private:
625 void PushScrollOffset(const gfx::ScrollOffset* scroll_offset);
626 void DidUpdateScrollOffset();
608 void NoteLayerPropertyChangedForDescendantsInternal(); 627 void NoteLayerPropertyChangedForDescendantsInternal();
609 628
610 virtual const char* LayerTypeAsString() const; 629 virtual const char* LayerTypeAsString() const;
611 630
612 // Properties internal to LayerImpl 631 // Properties internal to LayerImpl
613 LayerImpl* parent_; 632 LayerImpl* parent_;
614 OwnedLayerImplList children_; 633 OwnedLayerImplList children_;
615 634
616 LayerImpl* scroll_parent_; 635 LayerImpl* scroll_parent_;
617 636
618 // Storing a pointer to a set rather than a set since this will be rarely 637 // Storing a pointer to a set rather than a set since this will be rarely
619 // used. If this pointer turns out to be too heavy, we could have this (and 638 // used. If this pointer turns out to be too heavy, we could have this (and
620 // the scroll parent above) be stored in a LayerImpl -> scroll_info 639 // the scroll parent above) be stored in a LayerImpl -> scroll_info
621 // map somewhere. 640 // map somewhere.
622 scoped_ptr<std::set<LayerImpl*>> scroll_children_; 641 scoped_ptr<std::set<LayerImpl*>> scroll_children_;
623 642
624 LayerImpl* clip_parent_; 643 LayerImpl* clip_parent_;
625 scoped_ptr<std::set<LayerImpl*>> clip_children_; 644 scoped_ptr<std::set<LayerImpl*>> clip_children_;
626 645
627 // mask_layer_ can be temporarily stolen during tree sync, we need this ID to 646 // mask_layer_ can be temporarily stolen during tree sync, we need this ID to
628 // confirm newly assigned layer is still the previous one 647 // confirm newly assigned layer is still the previous one
629 int mask_layer_id_; 648 int mask_layer_id_;
630 scoped_ptr<LayerImpl> mask_layer_; 649 scoped_ptr<LayerImpl> mask_layer_;
631 int replica_layer_id_; // ditto 650 int replica_layer_id_; // ditto
632 scoped_ptr<LayerImpl> replica_layer_; 651 scoped_ptr<LayerImpl> replica_layer_;
633 int layer_id_; 652 int layer_id_;
634 LayerTreeImpl* layer_tree_impl_; 653 LayerTreeImpl* layer_tree_impl_;
635 654
655 // Properties dynamically changeable on active tree.
656 scoped_refptr<SyncedScrollOffset> scroll_offset_;
657 gfx::Vector2dF bounds_delta_;
658
636 // Properties synchronized from the associated Layer. 659 // Properties synchronized from the associated Layer.
637 gfx::Point3F transform_origin_; 660 gfx::Point3F transform_origin_;
638 gfx::Size bounds_; 661 gfx::Size bounds_;
639 gfx::Vector2dF bounds_delta_;
640 gfx::ScrollOffset scroll_offset_;
641 ScrollOffsetDelegate* scroll_offset_delegate_; 662 ScrollOffsetDelegate* scroll_offset_delegate_;
642 LayerImpl* scroll_clip_layer_; 663 LayerImpl* scroll_clip_layer_;
643 bool scrollable_ : 1; 664 bool scrollable_ : 1;
644 bool should_scroll_on_main_thread_ : 1; 665 bool should_scroll_on_main_thread_ : 1;
645 bool have_wheel_event_handlers_ : 1; 666 bool have_wheel_event_handlers_ : 1;
646 bool have_scroll_event_handlers_ : 1; 667 bool have_scroll_event_handlers_ : 1;
647 bool user_scrollable_horizontal_ : 1; 668 bool user_scrollable_horizontal_ : 1;
648 bool user_scrollable_vertical_ : 1; 669 bool user_scrollable_vertical_ : 1;
649 bool stacking_order_changed_ : 1; 670 bool stacking_order_changed_ : 1;
650 // Whether the "back" of this layer should draw. 671 // Whether the "back" of this layer should draw.
(...skipping 20 matching lines...) Expand all
671 Region touch_event_handler_region_; 692 Region touch_event_handler_region_;
672 SkColor background_color_; 693 SkColor background_color_;
673 694
674 float opacity_; 695 float opacity_;
675 SkXfermode::Mode blend_mode_; 696 SkXfermode::Mode blend_mode_;
676 gfx::PointF position_; 697 gfx::PointF position_;
677 gfx::Transform transform_; 698 gfx::Transform transform_;
678 699
679 LayerPositionConstraint position_constraint_; 700 LayerPositionConstraint position_constraint_;
680 701
681 gfx::Vector2dF scroll_delta_;
682 gfx::Vector2dF sent_scroll_delta_;
683 gfx::ScrollOffset last_scroll_offset_;
684
685 gfx::Vector2dF main_scroll_offset_fractional_part_; 702 gfx::Vector2dF main_scroll_offset_fractional_part_;
686 703
687 int num_descendants_that_draw_content_; 704 int num_descendants_that_draw_content_;
688 705
689 // The global depth value of the center of the layer. This value is used 706 // The global depth value of the center of the layer. This value is used
690 // to sort layers from back to front. 707 // to sort layers from back to front.
691 float draw_depth_; 708 float draw_depth_;
692 709
693 FilterOperations filters_; 710 FilterOperations filters_;
694 FilterOperations background_filters_; 711 FilterOperations background_filters_;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 757
741 std::vector<FrameTimingRequest> frame_timing_requests_; 758 std::vector<FrameTimingRequest> frame_timing_requests_;
742 bool frame_timing_requests_dirty_; 759 bool frame_timing_requests_dirty_;
743 760
744 DISALLOW_COPY_AND_ASSIGN(LayerImpl); 761 DISALLOW_COPY_AND_ASSIGN(LayerImpl);
745 }; 762 };
746 763
747 } // namespace cc 764 } // namespace cc
748 765
749 #endif // CC_LAYERS_LAYER_IMPL_H_ 766 #endif // CC_LAYERS_LAYER_IMPL_H_
OLDNEW
« no previous file with comments | « cc/layers/layer.cc ('k') | cc/layers/layer_impl.cc » ('j') | cc/layers/layer_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698