Upstream version 11.39.250.0
[platform/framework/web/crosswalk.git] / src / cc / trees / layer_tree_host_impl.h
index 796f603..0e6fa45 100644 (file)
@@ -31,7 +31,7 @@
 #include "cc/quads/render_pass.h"
 #include "cc/resources/resource_provider.h"
 #include "cc/resources/tile_manager.h"
-#include "cc/scheduler/draw_swap_readback_result.h"
+#include "cc/scheduler/draw_result.h"
 #include "skia/ext/refptr.h"
 #include "third_party/skia/include/core/SkColor.h"
 #include "ui/gfx/rect.h"
@@ -41,6 +41,7 @@ namespace cc {
 class CompletionEvent;
 class CompositorFrameMetadata;
 class DebugRectHistory;
+class EvictionTilePriorityQueue;
 class FrameRateCounter;
 class LayerImpl;
 class LayerTreeHostImplTimeSourceAdapter;
@@ -48,6 +49,8 @@ class LayerTreeImpl;
 class MemoryHistory;
 class PageScaleAnimation;
 class PaintTimeCounter;
+class PictureLayerImpl;
+class RasterTilePriorityQueue;
 class RasterWorkerPool;
 class RenderPassDrawQuad;
 class RenderingStatsInstrumentation;
@@ -88,13 +91,12 @@ class LayerTreeHostImplClient {
   virtual bool ReduceContentsTextureMemoryOnImplThread(
       size_t limit_bytes,
       int priority_cutoff) = 0;
-  virtual void SendManagedMemoryStats() = 0;
   virtual bool IsInsideDraw() = 0;
   virtual void RenewTreePriority() = 0;
   virtual void PostDelayedScrollbarFadeOnImplThread(
       const base::Closure& start_fade,
       base::TimeDelta delay) = 0;
-  virtual void DidActivatePendingTree() = 0;
+  virtual void DidActivateSyncTree() = 0;
   virtual void DidManageTiles() = 0;
 
  protected:
@@ -126,6 +128,9 @@ class CC_EXPORT LayerTreeHostImpl
   virtual InputHandler::ScrollStatus ScrollBegin(
       const gfx::Point& viewport_point,
       InputHandler::ScrollInputType type) OVERRIDE;
+  virtual InputHandler::ScrollStatus ScrollAnimated(
+      const gfx::Point& viewport_point,
+      const gfx::Vector2dF& scroll_delta) OVERRIDE;
   virtual bool ScrollBy(const gfx::Point& viewport_point,
                         const gfx::Vector2dF& scroll_delta) OVERRIDE;
   virtual bool ScrollVerticallyByPage(const gfx::Point& viewport_point,
@@ -140,10 +145,6 @@ class CC_EXPORT LayerTreeHostImpl
   virtual void PinchGestureUpdate(float magnify_delta,
                                   const gfx::Point& anchor) OVERRIDE;
   virtual void PinchGestureEnd() OVERRIDE;
-  virtual void StartPageScaleAnimation(const gfx::Vector2d& target_offset,
-                                       bool anchor_point,
-                                       float page_scale,
-                                       base::TimeDelta duration) OVERRIDE;
   virtual void SetNeedsAnimate() OVERRIDE;
   virtual bool IsCurrentlyScrollingLayerAt(
       const gfx::Point& viewport_point,
@@ -154,13 +155,15 @@ class CC_EXPORT LayerTreeHostImpl
       ui::LatencyInfo* latency) OVERRIDE;
 
   // TopControlsManagerClient implementation.
+  virtual void SetControlsTopOffset(float offset) OVERRIDE;
+  virtual float ControlsTopOffset() const OVERRIDE;
   virtual void DidChangeTopControlsPosition() OVERRIDE;
   virtual bool HaveRootScrollLayer() const OVERRIDE;
 
   struct CC_EXPORT FrameData : public RenderPassSink {
     FrameData();
     virtual ~FrameData();
-    scoped_ptr<base::Value> AsValue() const;
+    void AsValueInto(base::debug::TracedValue* value) const;
 
     std::vector<gfx::Rect> occluding_screen_space_rects;
     std::vector<gfx::Rect> non_occluding_screen_space_rects;
@@ -188,13 +191,11 @@ class CC_EXPORT LayerTreeHostImpl
 
   virtual void ManageTiles();
 
-  // Returns false if problems occured preparing the frame, and we should try
-  // to avoid displaying the frame. If PrepareToDraw is called, DidDrawAllLayers
-  // must also be called, regardless of whether DrawLayers is called between the
-  // two.
-  virtual DrawSwapReadbackResult::DrawResult PrepareToDraw(
-      FrameData* frame,
-      const gfx::Rect& damage_rect);
+  // Returns DRAW_SUCCESS unless problems occured preparing the frame, and we
+  // should try to avoid displaying the frame. If PrepareToDraw is called,
+  // DidDrawAllLayers must also be called, regardless of whether DrawLayers is
+  // called between the two.
+  virtual DrawResult PrepareToDraw(FrameData* frame);
   virtual void DrawLayers(FrameData* frame, base::TimeTicks frame_begin_time);
   // Must be called if and only if PrepareToDraw was called.
   void DidDrawAllLayers(const FrameData& frame);
@@ -212,26 +213,31 @@ class CC_EXPORT LayerTreeHostImpl
   // This allows us to inject DidInitializeVisibleTile events for testing.
   void DidInitializeVisibleTileForTesting();
 
-  bool device_viewport_valid_for_tile_management() const {
-    return device_viewport_valid_for_tile_management_;
-  }
+  // Resets all of the trees to an empty state.
+  void ResetTreesForTesting();
+  void ResetRecycleTreeForTesting();
+
+  DrawMode GetDrawMode() const;
 
   // Viewport size in draw space: this size is in physical pixels and is used
   // for draw properties, tilings, quads and render passes.
   gfx::Size DrawViewportSize() const;
 
-  // Viewport size for scrolling and fixed-position compensation. This value
-  // excludes the URL bar and non-overlay scrollbars and is in DIP (and
-  // invariant relative to page scale).
-  gfx::SizeF UnscaledScrollableViewportSize() const;
-  float VerticalAdjust() const;
+  // Viewport rect in view space used for tiling prioritization.
+  const gfx::Rect ViewportRectForTilePriority() const;
 
   // RendererClient implementation.
   virtual void SetFullRootLayerDamage() OVERRIDE;
 
   // TileManagerClient implementation.
+  virtual const std::vector<PictureLayerImpl*>& GetPictureLayers()
+      const OVERRIDE;
   virtual void NotifyReadyToActivate() OVERRIDE;
-  virtual void NotifyTileInitialized(const Tile* tile) OVERRIDE;
+  virtual void NotifyTileStateChanged(const Tile* tile) OVERRIDE;
+  virtual void BuildRasterQueue(RasterTilePriorityQueue* queue,
+                                TreePriority tree_priority) OVERRIDE;
+  virtual void BuildEvictionQueue(EvictionTilePriorityQueue* queue,
+                                  TreePriority tree_priority) OVERRIDE;
 
   // ScrollbarAnimationControllerClient implementation.
   virtual void PostDelayedScrollbarFade(const base::Closure& start_fade,
@@ -245,11 +251,14 @@ class CC_EXPORT LayerTreeHostImpl
                                      base::TimeDelta interval) OVERRIDE;
   virtual void SetNeedsRedrawRect(const gfx::Rect& rect) OVERRIDE;
   virtual void BeginFrame(const BeginFrameArgs& args) OVERRIDE;
+
   virtual void SetExternalDrawConstraints(
       const gfx::Transform& transform,
       const gfx::Rect& viewport,
       const gfx::Rect& clip,
-      bool valid_for_tile_management) OVERRIDE;
+      const gfx::Rect& viewport_rect_for_tile_priority,
+      const gfx::Transform& transform_for_tile_priority,
+      bool resourceless_software_draw) OVERRIDE;
   virtual void DidLoseOutputSurface() OVERRIDE;
   virtual void DidSwapBuffers() OVERRIDE;
   virtual void DidSwapBuffersComplete() OVERRIDE;
@@ -262,6 +271,7 @@ class CC_EXPORT LayerTreeHostImpl
   void OnCanDrawStateChangedForTree();
 
   // Implementation.
+  int id() const { return id_; }
   bool CanDraw() const;
   OutputSurface* output_surface() const { return output_surface_.get(); }
 
@@ -271,8 +281,12 @@ class CC_EXPORT LayerTreeHostImpl
   int SourceAnimationFrameNumber() const;
 
   virtual bool InitializeRenderer(scoped_ptr<OutputSurface> output_surface);
-  bool IsContextLost();
   TileManager* tile_manager() { return tile_manager_.get(); }
+  void SetUseGpuRasterization(bool use_gpu);
+  bool use_gpu_rasterization() const { return use_gpu_rasterization_; }
+  bool create_low_res_tiling() const {
+    return settings_.create_low_res_tiling && !use_gpu_rasterization_;
+  }
   ResourcePool* resource_pool() { return resource_pool_.get(); }
   Renderer* renderer() { return renderer_.get(); }
   const RendererCapabilitiesImpl& GetRendererCapabilities() const;
@@ -282,16 +296,19 @@ class CC_EXPORT LayerTreeHostImpl
   virtual void WillBeginImplFrame(const BeginFrameArgs& args);
   void DidModifyTilePriorities();
 
-  void Readback(void* pixels, const gfx::Rect& rect_in_device_viewport);
-
   LayerTreeImpl* active_tree() { return active_tree_.get(); }
   const LayerTreeImpl* active_tree() const { return active_tree_.get(); }
   LayerTreeImpl* pending_tree() { return pending_tree_.get(); }
   const LayerTreeImpl* pending_tree() const { return pending_tree_.get(); }
+  LayerTreeImpl* recycle_tree() { return recycle_tree_.get(); }
   const LayerTreeImpl* recycle_tree() const { return recycle_tree_.get(); }
+  // Returns the tree LTH synchronizes with.
+  LayerTreeImpl* sync_tree() {
+    return pending_tree_ ? pending_tree_.get() : active_tree_.get();
+  }
   virtual void CreatePendingTree();
   virtual void UpdateVisibleTiles();
-  virtual void ActivatePendingTree();
+  virtual void ActivateSyncTree();
 
   // Shortcuts to layers on the active tree.
   LayerImpl* RootLayer() const;
@@ -305,8 +322,10 @@ class CC_EXPORT LayerTreeHostImpl
   bool scroll_affects_scroll_handler() const {
     return scroll_affects_scroll_handler_;
   }
+  void QueueSwapPromiseForMainThreadScrollUpdate(
+      scoped_ptr<SwapPromise> swap_promise);
 
-  bool IsCurrentlyScrolling() const;
+  bool IsActivelyScrolling() const;
 
   virtual void SetVisible(bool visible);
   bool visible() const { return visible_; }
@@ -322,9 +341,6 @@ class CC_EXPORT LayerTreeHostImpl
   void SetViewportSize(const gfx::Size& device_viewport_size);
   gfx::Size device_viewport_size() const { return device_viewport_size_; }
 
-  void SetOverdrawBottomHeight(float overdraw_bottom_height);
-  float overdraw_bottom_height() const { return overdraw_bottom_height_; }
-
   void SetOverhangUIResource(UIResourceId overhang_ui_resource_id,
                              const gfx::Size& overhang_ui_resource_size);
 
@@ -339,11 +355,6 @@ class CC_EXPORT LayerTreeHostImpl
     return !animation_registrar_->active_animation_controllers().empty();
   }
 
-  void SendManagedMemoryStats(
-      size_t memory_visible_bytes,
-      size_t memory_visible_and_nearby_bytes,
-      size_t memory_use_bytes);
-
   void set_max_memory_needed_bytes(size_t bytes) {
     max_memory_needed_bytes_ = bytes;
   }
@@ -380,7 +391,7 @@ class CC_EXPORT LayerTreeHostImpl
   const LayerTreeDebugState& debug_state() const { return debug_state_; }
 
   class CC_EXPORT CullRenderPassesWithNoQuads {
- public:
  public:
     bool ShouldRemoveRenderPass(const RenderPassDrawQuad& quad,
                                 const FrameData& frame) const;
 
@@ -404,18 +415,26 @@ class CC_EXPORT LayerTreeHostImpl
 
   void SetTreePriority(TreePriority priority);
 
-  void UpdateCurrentFrameTime();
-  void ResetCurrentFrameTimeForNextFrame();
-  virtual base::TimeTicks CurrentFrameTimeTicks();
+  void UpdateCurrentBeginFrameArgs(const BeginFrameArgs& args);
+  void ResetCurrentBeginFrameArgsForNextFrame();
+  virtual BeginFrameArgs CurrentBeginFrameArgs() const;
 
   // Expected time between two begin impl frame calls.
   base::TimeDelta begin_impl_frame_interval() const {
     return begin_impl_frame_interval_;
   }
 
-  scoped_ptr<base::Value> AsValue() const { return AsValueWithFrame(NULL); }
-  scoped_ptr<base::Value> AsValueWithFrame(FrameData* frame) const;
-  scoped_ptr<base::Value> ActivationStateAsValue() const;
+  void AsValueInto(base::debug::TracedValue* value) const {
+    return AsValueWithFrameInto(NULL, value);
+  }
+  void AsValueWithFrameInto(FrameData* frame,
+                            base::debug::TracedValue* value) const;
+  scoped_refptr<base::debug::ConvertableToTraceFormat> AsValue() const;
+  scoped_refptr<base::debug::ConvertableToTraceFormat> AsValueWithFrame(
+      FrameData* frame) const;
+  scoped_refptr<base::debug::ConvertableToTraceFormat> ActivationStateAsValue()
+      const;
+  void ActivationStateAsValueInto(base::debug::TracedValue* value) const;
 
   bool page_scale_animation_active() const { return !!page_scale_animation_; }
 
@@ -453,6 +472,14 @@ class CC_EXPORT LayerTreeHostImpl
   void InsertSwapPromiseMonitor(SwapPromiseMonitor* monitor);
   void RemoveSwapPromiseMonitor(SwapPromiseMonitor* monitor);
 
+  void RegisterPictureLayerImpl(PictureLayerImpl* layer);
+  void UnregisterPictureLayerImpl(PictureLayerImpl* layer);
+
+  void GetPictureLayerImplPairs(
+      std::vector<PictureLayerImpl::Pair>* layers) const;
+
+  void SetTopControlsLayoutHeight(float height);
+
  protected:
   LayerTreeHostImpl(
       const LayerTreeSettings& settings,
@@ -462,7 +489,6 @@ class CC_EXPORT LayerTreeHostImpl
       SharedBitmapManager* manager,
       int id);
 
-  gfx::SizeF ComputeInnerViewportContainerSize() const;
   void UpdateInnerViewportContainerSize();
 
   // Virtual for testing.
@@ -482,18 +508,16 @@ class CC_EXPORT LayerTreeHostImpl
   Proxy* proxy_;
 
  private:
-  void CreateAndSetRenderer(
-      OutputSurface* output_surface,
-      ResourceProvider* resource_provider,
-      bool skip_gl_renderer);
-  void CreateAndSetTileManager(ResourceProvider* resource_provider,
-                               ContextProvider* context_provider,
-                               bool use_zero_copy,
-                               bool use_one_copy,
-                               bool allow_rasterize_on_demand);
+  void CreateAndSetRenderer();
+  void CreateAndSetTileManager();
+  void DestroyTileManager();
   void ReleaseTreeResources();
   void EnforceZeroBudget(bool zero_budget);
 
+  bool UsePendingTreeForSync() const;
+  bool UseZeroCopyRasterizer() const;
+  bool UseOneCopyRasterizer() const;
+
   void ScrollViewportBy(gfx::Vector2dF scroll_delta);
   void AnimatePageScale(base::TimeTicks monotonic_time);
   void AnimateScrollbars(base::TimeTicks monotonic_time);
@@ -514,9 +538,8 @@ class CC_EXPORT LayerTreeHostImpl
   // This function should only be called from PrepareToDraw, as DidDrawAllLayers
   // must be called if this helper function is called.  Returns DRAW_SUCCESS if
   // the frame should be drawn.
-  DrawSwapReadbackResult::DrawResult CalculateRenderPasses(FrameData* frame);
+  DrawResult CalculateRenderPasses(FrameData* frame);
 
-  bool EnsureRenderSurfaceLayerList();
   void ClearCurrentlyScrollingLayer();
 
   bool HandleMouseOverScrollbar(LayerImpl* layer_impl,
@@ -543,6 +566,7 @@ class CC_EXPORT LayerTreeHostImpl
   void MarkUIResourceNotEvicted(UIResourceId uid);
 
   void NotifySwapPromiseMonitorsOfSetNeedsRedraw();
+  void NotifySwapPromiseMonitorsOfForwardingToMainThread();
 
   typedef base::hash_map<UIResourceId, UIResourceData>
       UIResourceMap;
@@ -554,14 +578,13 @@ class CC_EXPORT LayerTreeHostImpl
   std::set<UIResourceId> evicted_ui_resources_;
 
   scoped_ptr<OutputSurface> output_surface_;
-  scoped_refptr<ContextProvider> offscreen_context_provider_;
 
   // |resource_provider_| and |tile_manager_| can be NULL, e.g. when using tile-
   // free rendering - see OutputSurface::ForcedDrawToSoftwareDevice().
   scoped_ptr<ResourceProvider> resource_provider_;
   scoped_ptr<TileManager> tile_manager_;
+  bool use_gpu_rasterization_;
   scoped_ptr<RasterWorkerPool> raster_worker_pool_;
-  scoped_ptr<RasterWorkerPool> direct_raster_worker_pool_;
   scoped_ptr<ResourcePool> resource_pool_;
   scoped_ptr<ResourcePool> staging_resource_pool_;
   scoped_ptr<Renderer> renderer_;
@@ -585,6 +608,7 @@ class CC_EXPORT LayerTreeHostImpl
   bool wheel_scrolling_;
   bool scroll_affects_scroll_handler_;
   int scroll_layer_id_when_mouse_over_scrollbar_;
+  ScopedPtrVector<SwapPromise> swap_promises_for_main_thread_scroll_update_;
 
   bool tile_priorities_dirty_;
 
@@ -619,9 +643,6 @@ class CC_EXPORT LayerTreeHostImpl
   // manager, if there were no limit on memory usage.
   size_t max_memory_needed_bytes_;
 
-  size_t last_sent_memory_visible_bytes_;
-  size_t last_sent_memory_visible_and_nearby_bytes_;
-  size_t last_sent_memory_use_bytes_;
   bool zero_budget_;
 
   // Viewport size passed in from the main thread, in physical pixels.  This
@@ -638,25 +659,22 @@ class CC_EXPORT LayerTreeHostImpl
   UIResourceId overhang_ui_resource_id_;
   gfx::Size overhang_ui_resource_size_;
 
-  // Vertical amount of the viewport size that's known to covered by a
-  // browser-side UI element, such as an on-screen-keyboard.  This affects
-  // scrollable size since we want to still be able to scroll to the bottom of
-  // the page when the keyboard is up.
-  float overdraw_bottom_height_;
-
   // Optional top-level constraints that can be set by the OutputSurface.
   // - external_transform_ applies a transform above the root layer
   // - external_viewport_ is used DrawProperties, tile management and
   // glViewport/window projection matrix.
   // - external_clip_ specifies a top-level clip rect
+  // - viewport_rect_for_tile_priority_ is the rect in view space used for
+  // tiling priority.
   gfx::Transform external_transform_;
   gfx::Rect external_viewport_;
   gfx::Rect external_clip_;
-  bool device_viewport_valid_for_tile_management_;
+  gfx::Rect viewport_rect_for_tile_priority_;
+  bool resourceless_software_draw_;
 
   gfx::Rect viewport_damage_rect_;
 
-  base::TimeTicks current_frame_timeticks_;
+  BeginFrameArgs current_begin_frame_args_;
 
   // Expected time between two begin impl frame calls.
   base::TimeDelta begin_impl_frame_interval_;
@@ -667,9 +685,6 @@ class CC_EXPORT LayerTreeHostImpl
   MicroBenchmarkControllerImpl micro_benchmark_controller_;
 
   bool need_to_update_visible_tiles_before_draw_;
-#if DCHECK_IS_ON
-  bool did_lose_called_;
-#endif
 
   // Optional callback to notify of new tree activations.
   base::Closure tree_activation_callback_;
@@ -679,7 +694,8 @@ class CC_EXPORT LayerTreeHostImpl
 
   std::set<SwapPromiseMonitor*> swap_promise_monitor_;
 
-  size_t transfer_buffer_memory_limit_;
+  std::vector<PictureLayerImpl*> picture_layers_;
+  std::vector<PictureLayerImpl::Pair> picture_layer_pairs_;
 
   DISALLOW_COPY_AND_ASSIGN(LayerTreeHostImpl);
 };