Upstream version 11.39.250.0
[platform/framework/web/crosswalk.git] / src / cc / trees / layer_tree_impl.h
index 179b189..0344551 100644 (file)
@@ -6,14 +6,17 @@
 #define CC_TREES_LAYER_TREE_IMPL_H_
 
 #include <list>
+#include <set>
 #include <string>
 #include <vector>
 
 #include "base/containers/hash_tables.h"
 #include "base/values.h"
+#include "cc/base/scoped_ptr_vector.h"
+#include "cc/base/swap_promise.h"
 #include "cc/layers/layer_impl.h"
+#include "cc/output/renderer.h"
 #include "cc/resources/ui_resource_client.h"
-#include "ui/events/latency_info.h"
 
 #if defined(COMPILER_GCC)
 namespace BASE_HASH_NAMESPACE {
@@ -26,24 +29,34 @@ struct hash<cc::LayerImpl*> {
 }  // namespace BASE_HASH_NAMESPACE
 #endif  // COMPILER
 
+namespace base {
+namespace debug {
+class TracedValue;
+}
+}
+
 namespace cc {
 
 class ContextProvider;
 class DebugRectHistory;
 class FrameRateCounter;
 class HeadsUpDisplayLayerImpl;
+class LayerScrollOffsetDelegateProxy;
 class LayerTreeDebugState;
 class LayerTreeHostImpl;
 class LayerTreeImpl;
 class LayerTreeSettings;
 class MemoryHistory;
 class OutputSurface;
+class PageScaleAnimation;
 class PaintTimeCounter;
+class PictureLayerImpl;
 class Proxy;
 class ResourceProvider;
 class TileManager;
 class UIResourceRequest;
 struct RendererCapabilities;
+struct SelectionHandle;
 
 typedef std::list<UIResourceRequest> UIResourceRequestQueue;
 
@@ -55,10 +68,13 @@ class CC_EXPORT LayerTreeImpl {
   }
   virtual ~LayerTreeImpl();
 
+  void Shutdown();
+  void ReleaseResources();
+
   // Methods called by the layer tree that pass-through or access LTHI.
   // ---------------------------------------------------------------------------
   const LayerTreeSettings& settings() const;
-  const RendererCapabilities& GetRendererCapabilities() const;
+  const RendererCapabilitiesImpl& GetRendererCapabilities() const;
   ContextProvider* context_provider() const;
   OutputSurface* output_surface() const;
   ResourceProvider* resource_provider() const;
@@ -66,20 +82,27 @@ class CC_EXPORT LayerTreeImpl {
   FrameRateCounter* frame_rate_counter() const;
   PaintTimeCounter* paint_time_counter() const;
   MemoryHistory* memory_history() const;
-  bool device_viewport_valid_for_tile_management() const;
+  gfx::Size device_viewport_size() const;
   bool IsActiveTree() const;
   bool IsPendingTree() const;
   bool IsRecycleTree() const;
   LayerImpl* FindActiveTreeLayerById(int id);
   LayerImpl* FindPendingTreeLayerById(int id);
-  int MaxTextureSize() const;
+  LayerImpl* FindRecycleTreeLayerById(int id);
   bool PinchGestureActive() const;
-  base::TimeTicks CurrentFrameTimeTicks() const;
-  base::Time CurrentFrameTime() const;
-  base::TimeTicks CurrentPhysicalTimeTicks() const;
+  BeginFrameArgs CurrentBeginFrameArgs() const;
+  base::TimeDelta begin_impl_frame_interval() const;
   void SetNeedsCommit();
+  gfx::Rect DeviceViewport() const;
   gfx::Size DrawViewportSize() const;
-  void StartScrollbarAnimation();
+  const gfx::Rect ViewportRectForTilePriority() const;
+  scoped_ptr<ScrollbarAnimationController> CreateScrollbarAnimationController(
+      LayerImpl* scrolling_layer);
+  void DidAnimateScrollOffset();
+  void InputScrollAnimationFinished();
+  bool use_gpu_rasterization() const;
+  bool create_low_res_tiling() const;
+  BlockingTaskRunner* BlockingMainThreadTaskRunner() const;
 
   // Tree specific methods exposed to layer-impl tree.
   // ---------------------------------------------------------------------------
@@ -90,7 +113,8 @@ class CC_EXPORT LayerTreeImpl {
   const LayerTreeDebugState& debug_state() const;
   float device_scale_factor() const;
   DebugRectHistory* debug_rect_history() const;
-  scoped_ptr<base::Value> AsValue() const;
+  void GetAllTilesForTracing(std::set<const Tile*>* tiles) const;
+  void AsValueInto(base::debug::TracedValue* dict) const;
 
   // Other public methods
   // ---------------------------------------------------------------------------
@@ -110,18 +134,23 @@ class CC_EXPORT LayerTreeImpl {
     hud_layer_ = layer_impl;
   }
 
-  LayerImpl* RootScrollLayer() const;
-  LayerImpl* RootContainerLayer() const;
+  LayerImpl* InnerViewportScrollLayer() const;
+  // This function may return NULL, it is the caller's responsibility to check.
+  LayerImpl* OuterViewportScrollLayer() const;
+  gfx::Vector2dF TotalScrollOffset() const;
+  gfx::Vector2dF TotalMaxScrollOffset() const;
+  gfx::Vector2dF TotalScrollDelta() const;
+
+  LayerImpl* InnerViewportContainerLayer() const;
   LayerImpl* CurrentlyScrollingLayer() const;
   void SetCurrentlyScrollingLayer(LayerImpl* layer);
   void ClearCurrentlyScrollingLayer();
 
-  void FindRootScrollLayer();
-  void UpdateMaxScrollOffset();
   void SetViewportLayersFromIds(int page_scale_layer_id,
                                 int inner_viewport_scroll_layer_id,
                                 int outer_viewport_scroll_layer_id);
   void ClearViewportLayers();
+  LayerImpl* page_scale_layer() { return page_scale_layer_; }
   void ApplySentScrollAndScaleDeltasFromAbortedCommit();
   void ApplyScrollDeltasSinceBeginMainFrame();
 
@@ -138,6 +167,9 @@ class CC_EXPORT LayerTreeImpl {
   void SetPageScaleFactorAndLimits(float page_scale_factor,
       float min_page_scale_factor, float max_page_scale_factor);
   void SetPageScaleDelta(float delta);
+  void SetPageScaleValues(float page_scale_factor,
+      float min_page_scale_factor, float max_page_scale_factor,
+      float page_scale_delta);
   float total_page_scale_factor() const {
     return page_scale_factor_ * page_scale_delta_;
   }
@@ -151,8 +183,8 @@ class CC_EXPORT LayerTreeImpl {
   float sent_page_scale_delta() const { return sent_page_scale_delta_; }
 
   // Updates draw properties and render surface layer list, as well as tile
-  // priorities.
-  void UpdateDrawProperties();
+  // priorities. Returns false if it was unable to update.
+  bool UpdateDrawProperties();
 
   void set_needs_update_draw_properties() {
     needs_update_draw_properties_ = true;
@@ -166,6 +198,11 @@ class CC_EXPORT LayerTreeImpl {
 
   void ForceRedrawNextActivation() { next_activation_forces_redraw_ = true; }
 
+  void set_has_ever_been_drawn(bool has_drawn) {
+    has_ever_been_drawn_ = has_drawn;
+  }
+  bool has_ever_been_drawn() const { return has_ever_been_drawn_; }
+
   void set_ui_resource_request_queue(const UIResourceRequestQueue& queue);
 
   const LayerImplList& RenderSurfaceLayerList() const;
@@ -183,6 +220,8 @@ class CC_EXPORT LayerTreeImpl {
   void RegisterLayer(LayerImpl* layer);
   void UnregisterLayer(LayerImpl* layer);
 
+  size_t NumLayers();
+
   AnimationRegistrar* animationRegistrar() const;
 
   void PushPersistedState(LayerTreeImpl* pending_tree);
@@ -193,6 +232,10 @@ class CC_EXPORT LayerTreeImpl {
   void SetContentsTexturesPurged();
   void ResetContentsTexturesPurged();
 
+  void SetRequiresHighResToDraw();
+  void ResetRequiresHighResToDraw();
+  bool RequiresHighResToDraw() const;
+
   // Set on the active tree when the viewport size recently changed
   // and the active tree's size is now out of date.
   bool ViewportSizeInvalid() const;
@@ -204,10 +247,17 @@ class CC_EXPORT LayerTreeImpl {
 
   void SetRootLayerScrollOffsetDelegate(
       LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate);
+  void UpdateScrollOffsetDelegate();
+  gfx::Vector2dF GetDelegatedScrollOffset(LayerImpl* layer);
 
-  void SetLatencyInfo(const ui::LatencyInfo& latency_info);
-  const ui::LatencyInfo& GetLatencyInfo();
-  void ClearLatencyInfo();
+  // Call this function when you expect there to be a swap buffer.
+  // See swap_promise.h for how to use SwapPromise.
+  void QueueSwapPromise(scoped_ptr<SwapPromise> swap_promise);
+
+  // Take the |new_swap_promise| and append it to |swap_promise_list_|.
+  void PassSwapPromises(ScopedPtrVector<SwapPromise>* new_swap_promise);
+  void FinishSwapPromises(CompositorFrameMetadata* metadata);
+  void BreakSwapPromises(SwapPromise::DidNotSwapReason reason);
 
   void DidModifyTilePriorities();
 
@@ -218,22 +268,80 @@ class CC_EXPORT LayerTreeImpl {
 
   void AddLayerWithCopyOutputRequest(LayerImpl* layer);
   void RemoveLayerWithCopyOutputRequest(LayerImpl* layer);
-  const std::vector<LayerImpl*> LayersWithCopyOutputRequest() const;
+  const std::vector<LayerImpl*>& LayersWithCopyOutputRequest() const;
 
- protected:
-  explicit LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl);
+  int current_render_surface_list_id() const {
+    return render_surface_layer_list_id_;
+  }
+
+  LayerImpl* FindFirstScrollingLayerThatIsHitByPoint(
+      const gfx::PointF& screen_space_point);
+
+  LayerImpl* FindLayerThatIsHitByPoint(const gfx::PointF& screen_space_point);
+
+  LayerImpl* FindLayerThatIsHitByPointInTouchHandlerRegion(
+      const gfx::PointF& screen_space_point);
+
+  void RegisterSelection(const LayerSelectionBound& start,
+                         const LayerSelectionBound& end);
+
+  // Compute the current selection handle location and visbility with respect to
+  // the viewport.
+  void GetViewportSelection(ViewportSelectionBound* start,
+                            ViewportSelectionBound* end);
+
+  void RegisterPictureLayerImpl(PictureLayerImpl* layer);
+  void UnregisterPictureLayerImpl(PictureLayerImpl* layer);
+
+  void set_top_controls_layout_height(float height) {
+    top_controls_layout_height_ = height;
+  }
+  void set_top_controls_content_offset(float offset) {
+    top_controls_content_offset_ = offset;
+  }
+  void set_top_controls_delta(float delta) {
+    top_controls_delta_ = delta;
+  }
+  void set_sent_top_controls_delta(float sent_delta) {
+    sent_top_controls_delta_ = sent_delta;
+  }
+
+  float top_controls_layout_height() const {
+    return top_controls_layout_height_;
+  }
+  float top_controls_content_offset() const {
+    return top_controls_content_offset_;
+  }
+  float top_controls_delta() const {
+    return top_controls_delta_;
+  }
+  float sent_top_controls_delta() const {
+    return sent_top_controls_delta_;
+  }
+  float total_top_controls_content_offset() const {
+    return top_controls_content_offset_ + top_controls_delta_;
+  }
 
-  void UpdateSolidColorScrollbars();
+  void SetPageScaleAnimation(const gfx::Vector2d& target_offset,
+                             bool anchor_point,
+                             float page_scale,
+                             base::TimeDelta duration);
+  scoped_ptr<PageScaleAnimation> TakePageScaleAnimation();
 
-  void UpdateRootScrollLayerSizeDelta();
+ protected:
+  explicit LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl);
+  void ReleaseResourcesRecursive(LayerImpl* current);
 
   LayerTreeHostImpl* layer_tree_host_impl_;
   int source_frame_number_;
   scoped_ptr<LayerImpl> root_layer_;
   HeadsUpDisplayLayerImpl* hud_layer_;
-  LayerImpl* root_scroll_layer_;
   LayerImpl* currently_scrolling_layer_;
   LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate_;
+  scoped_ptr<LayerScrollOffsetDelegateProxy>
+      inner_viewport_scroll_delegate_proxy_;
+  scoped_ptr<LayerScrollOffsetDelegateProxy>
+      outer_viewport_scroll_delegate_proxy_;
   SkColor background_color_;
   bool has_transparent_background_;
 
@@ -241,6 +349,9 @@ class CC_EXPORT LayerTreeImpl {
   LayerImpl* inner_viewport_scroll_layer_;
   LayerImpl* outer_viewport_scroll_layer_;
 
+  LayerSelectionBound selection_start_;
+  LayerSelectionBound selection_end_;
+
   float page_scale_factor_;
   float page_scale_delta_;
   float sent_page_scale_delta_;
@@ -255,11 +366,11 @@ class CC_EXPORT LayerTreeImpl {
   // Persisted state for non-impl-side-painting.
   int scrolling_layer_id_from_previous_tree_;
 
-  // List of visible or hit-testable layers for the most recently prepared
-  // frame. Used for rendering and input event hit testing.
+  // List of visible layers for the most recently prepared frame.
   LayerImplList render_surface_layer_list_;
 
   bool contents_textures_purged_;
+  bool requires_high_res_to_draw_;
   bool viewport_size_invalid_;
   bool needs_update_draw_properties_;
 
@@ -269,10 +380,27 @@ class CC_EXPORT LayerTreeImpl {
 
   bool next_activation_forces_redraw_;
 
-  ui::LatencyInfo latency_info_;
+  bool has_ever_been_drawn_;
+
+  ScopedPtrVector<SwapPromise> swap_promise_list_;
 
   UIResourceRequestQueue ui_resource_request_queue_;
 
+  int render_surface_layer_list_id_;
+
+  // The top controls content offset at the time of the last layout (and thus,
+  // viewport resize) in Blink. i.e. How much the viewport was shrunk by the top
+  // controls.
+  float top_controls_layout_height_;
+
+  // The up-to-date content offset of the top controls, i.e. the amount that the
+  // web contents have been shifted down from the top of the device viewport.
+  float top_controls_content_offset_;
+  float top_controls_delta_;
+  float sent_top_controls_delta_;
+
+  scoped_ptr<PageScaleAnimation> page_scale_animation_;
+
  private:
   DISALLOW_COPY_AND_ASSIGN(LayerTreeImpl);
 };