| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 CONTENT_BROWSER_ANDROID_IN_PROCESS_SYNCHRONOUS_COMPOSITOR_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_ANDROID_IN_PROCESS_SYNCHRONOUS_COMPOSITOR_IMPL_H_ |
| 6 #define CONTENT_BROWSER_ANDROID_IN_PROCESS_SYNCHRONOUS_COMPOSITOR_IMPL_H_ | 6 #define CONTENT_BROWSER_ANDROID_IN_PROCESS_SYNCHRONOUS_COMPOSITOR_IMPL_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "content/common/input/input_event_ack_state.h" | 13 #include "content/browser/android/synchronous_compositor_base.h" |
| 14 #include "content/public/browser/android/synchronous_compositor.h" | |
| 15 #include "content/renderer/android/synchronous_compositor_external_begin_frame_s
ource.h" | 14 #include "content/renderer/android/synchronous_compositor_external_begin_frame_s
ource.h" |
| 16 #include "content/renderer/android/synchronous_compositor_output_surface.h" | 15 #include "content/renderer/android/synchronous_compositor_output_surface.h" |
| 17 #include "content/renderer/input/synchronous_input_handler_proxy.h" | 16 #include "content/renderer/input/synchronous_input_handler_proxy.h" |
| 18 #include "ipc/ipc_message.h" | 17 #include "ipc/ipc_message.h" |
| 19 | 18 |
| 20 namespace cc { | 19 namespace cc { |
| 21 struct BeginFrameArgs; | |
| 22 class InputHandler; | 20 class InputHandler; |
| 23 } | 21 } |
| 24 | 22 |
| 25 namespace blink { | |
| 26 class WebInputEvent; | |
| 27 } | |
| 28 | |
| 29 namespace content { | 23 namespace content { |
| 30 class InputHandlerManager; | 24 class InputHandlerManager; |
| 31 class RenderWidgetHostViewAndroid; | 25 class RenderWidgetHostViewAndroid; |
| 32 class SynchronousCompositorExternalBeginFrameSource; | 26 class SynchronousCompositorExternalBeginFrameSource; |
| 33 struct DidOverscrollParams; | 27 struct DidOverscrollParams; |
| 34 | 28 |
| 35 // The purpose of this class is to act as the intermediary between the various | 29 // The purpose of this class is to act as the intermediary between the various |
| 36 // components that make up the 'synchronous compositor mode' implementation and | 30 // components that make up the 'synchronous compositor mode' implementation and |
| 37 // expose their functionality via the SynchronousCompositor interface. | 31 // expose their functionality via the SynchronousCompositor interface. |
| 38 // This class is created on the main thread but most of the APIs are called | 32 // This class is created on the main thread but most of the APIs are called |
| 39 // from the Compositor thread. | 33 // from the Compositor thread. |
| 40 class SynchronousCompositorImpl | 34 class SynchronousCompositorImpl |
| 41 : public SynchronousInputHandler, | 35 : public SynchronousInputHandler, |
| 42 public SynchronousCompositor, | 36 public SynchronousCompositorBase, |
| 43 public SynchronousCompositorExternalBeginFrameSourceClient, | 37 public SynchronousCompositorExternalBeginFrameSourceClient, |
| 44 public SynchronousCompositorOutputSurfaceClient { | 38 public SynchronousCompositorOutputSurfaceClient { |
| 45 public: | 39 public: |
| 46 // For handling upcalls from renderer code; the process id | 40 // For handling upcalls from renderer code; the process id |
| 47 // is implicitly that of the in-process renderer. | 41 // is implicitly that of the in-process renderer. |
| 48 static SynchronousCompositorImpl* FromRoutingID(int routing_id); | 42 static SynchronousCompositorImpl* FromRoutingID(int routing_id); |
| 49 | 43 |
| 50 static scoped_ptr<SynchronousCompositorImpl> Create( | 44 static void SetGpuServiceInProc( |
| 51 RenderWidgetHostViewAndroid* rwhva, | 45 scoped_refptr<gpu::InProcessCommandBuffer::Service> service); |
| 52 WebContents* web_contents); | 46 |
| 53 ~SynchronousCompositorImpl() override; | 47 ~SynchronousCompositorImpl() override; |
| 54 | 48 |
| 55 InputEventAckState HandleInputEvent(const blink::WebInputEvent& input_event); | |
| 56 | |
| 57 // Called by SynchronousCompositorRegistry. | 49 // Called by SynchronousCompositorRegistry. |
| 58 void DidInitializeRendererObjects( | 50 void DidInitializeRendererObjects( |
| 59 SynchronousCompositorOutputSurface* output_surface, | 51 SynchronousCompositorOutputSurface* output_surface, |
| 60 SynchronousCompositorExternalBeginFrameSource* begin_frame_source, | 52 SynchronousCompositorExternalBeginFrameSource* begin_frame_source, |
| 61 SynchronousInputHandlerProxy* synchronous_input_handler_proxy); | 53 SynchronousInputHandlerProxy* synchronous_input_handler_proxy); |
| 62 void DidDestroyRendererObjects(); | 54 void DidDestroyRendererObjects(); |
| 63 | 55 |
| 64 // SynchronousCompositorExternalBeginFrameSourceClient overrides. | 56 // SynchronousCompositorExternalBeginFrameSourceClient overrides. |
| 65 void OnNeedsBeginFramesChange(bool needs_begin_frames) override; | 57 void OnNeedsBeginFramesChange(bool needs_begin_frames) override; |
| 66 | 58 |
| 67 // SynchronousCompositorOutputSurfaceClient overrides. | 59 // SynchronousCompositorOutputSurfaceClient overrides. |
| 68 void Invalidate() override; | 60 void Invalidate() override; |
| 69 | 61 |
| 70 // Called by RenderWidgetHostViewAndroid. | 62 // SynchronousCompositor overrides. |
| 71 void BeginFrame(const cc::BeginFrameArgs& args); | |
| 72 | |
| 73 // SynchronousCompositor | |
| 74 scoped_ptr<cc::CompositorFrame> DemandDrawHw( | 63 scoped_ptr<cc::CompositorFrame> DemandDrawHw( |
| 75 const gfx::Size& surface_size, | 64 const gfx::Size& surface_size, |
| 76 const gfx::Transform& transform, | 65 const gfx::Transform& transform, |
| 77 const gfx::Rect& viewport, | 66 const gfx::Rect& viewport, |
| 78 const gfx::Rect& clip, | 67 const gfx::Rect& clip, |
| 79 const gfx::Rect& viewport_rect_for_tile_priority, | 68 const gfx::Rect& viewport_rect_for_tile_priority, |
| 80 const gfx::Transform& transform_for_tile_priority) override; | 69 const gfx::Transform& transform_for_tile_priority) override; |
| 81 bool DemandDrawSw(SkCanvas* canvas) override; | 70 bool DemandDrawSw(SkCanvas* canvas) override; |
| 82 void ReturnResources(const cc::CompositorFrameAck& frame_ack) override; | 71 void ReturnResources(const cc::CompositorFrameAck& frame_ack) override; |
| 83 void SetMemoryPolicy(size_t bytes_limit) override; | 72 void SetMemoryPolicy(size_t bytes_limit) override; |
| 84 void DidChangeRootLayerScrollOffset( | 73 void DidChangeRootLayerScrollOffset( |
| 85 const gfx::ScrollOffset& root_offset) override; | 74 const gfx::ScrollOffset& root_offset) override; |
| 86 void SetIsActive(bool is_active) override; | 75 void SetIsActive(bool is_active) override; |
| 87 void OnComputeScroll(base::TimeTicks animation_time) override; | 76 void OnComputeScroll(base::TimeTicks animation_time) override; |
| 88 | 77 |
| 78 // SynchronousCompositorBase overrides. |
| 79 void BeginFrame(const cc::BeginFrameArgs& args) override; |
| 80 InputEventAckState HandleInputEvent( |
| 81 const blink::WebInputEvent& input_event) override; |
| 82 bool OnMessageReceived(const IPC::Message& message) override; |
| 83 |
| 89 // SynchronousInputHandler | 84 // SynchronousInputHandler |
| 90 void SetNeedsSynchronousAnimateInput() override; | 85 void SetNeedsSynchronousAnimateInput() override; |
| 91 void UpdateRootLayerState(const gfx::ScrollOffset& total_scroll_offset, | 86 void UpdateRootLayerState(const gfx::ScrollOffset& total_scroll_offset, |
| 92 const gfx::ScrollOffset& max_scroll_offset, | 87 const gfx::ScrollOffset& max_scroll_offset, |
| 93 const gfx::SizeF& scrollable_size, | 88 const gfx::SizeF& scrollable_size, |
| 94 float page_scale_factor, | 89 float page_scale_factor, |
| 95 float min_page_scale_factor, | 90 float min_page_scale_factor, |
| 96 float max_page_scale_factor) override; | 91 float max_page_scale_factor) override; |
| 97 | 92 |
| 98 void DidOverscroll(const DidOverscrollParams& params); | 93 void DidOverscroll(const DidOverscrollParams& params); |
| 99 void DidStopFlinging(); | 94 void DidStopFlinging(); |
| 100 | 95 |
| 101 private: | 96 private: |
| 97 friend class SynchronousCompositorBase; |
| 102 SynchronousCompositorImpl(RenderWidgetHostViewAndroid* rwhva, | 98 SynchronousCompositorImpl(RenderWidgetHostViewAndroid* rwhva, |
| 103 SynchronousCompositorClient* client); | 99 SynchronousCompositorClient* client); |
| 104 void RegisterWithClient(); | 100 void RegisterWithClient(); |
| 105 void UpdateFrameMetaData(const cc::CompositorFrameMetadata& frame_info); | 101 void UpdateFrameMetaData(const cc::CompositorFrameMetadata& frame_info); |
| 106 void DidActivatePendingTree(); | 102 void DidActivatePendingTree(); |
| 107 void DeliverMessages(); | 103 void DeliverMessages(); |
| 108 bool CalledOnValidThread() const; | 104 bool CalledOnValidThread() const; |
| 109 void UpdateNeedsBeginFrames(); | 105 void UpdateNeedsBeginFrames(); |
| 110 | 106 |
| 111 RenderWidgetHostViewAndroid* const rwhva_; | 107 RenderWidgetHostViewAndroid* const rwhva_; |
| 112 const int routing_id_; | 108 const int routing_id_; |
| 113 SynchronousCompositorClient* const compositor_client_; | 109 SynchronousCompositorClient* const compositor_client_; |
| 114 SynchronousCompositorOutputSurface* output_surface_; | 110 SynchronousCompositorOutputSurface* output_surface_; |
| 115 SynchronousCompositorExternalBeginFrameSource* begin_frame_source_; | 111 SynchronousCompositorExternalBeginFrameSource* begin_frame_source_; |
| 116 SynchronousInputHandlerProxy* synchronous_input_handler_proxy_; | 112 SynchronousInputHandlerProxy* synchronous_input_handler_proxy_; |
| 117 bool registered_with_client_; | 113 bool registered_with_client_; |
| 118 bool is_active_; | 114 bool is_active_; |
| 119 bool renderer_needs_begin_frames_; | 115 bool renderer_needs_begin_frames_; |
| 120 bool need_animate_input_; | 116 bool need_animate_input_; |
| 121 | 117 |
| 122 base::WeakPtrFactory<SynchronousCompositorImpl> weak_ptr_factory_; | 118 base::WeakPtrFactory<SynchronousCompositorImpl> weak_ptr_factory_; |
| 123 | 119 |
| 124 DISALLOW_COPY_AND_ASSIGN(SynchronousCompositorImpl); | 120 DISALLOW_COPY_AND_ASSIGN(SynchronousCompositorImpl); |
| 125 }; | 121 }; |
| 126 | 122 |
| 127 } // namespace content | 123 } // namespace content |
| 128 | 124 |
| 129 #endif // CONTENT_BROWSER_ANDROID_IN_PROCESS_SYNCHRONOUS_COMPOSITOR_IMPL_H_ | 125 #endif // CONTENT_BROWSER_ANDROID_IN_PROCESS_SYNCHRONOUS_COMPOSITOR_IMPL_H_ |
| OLD | NEW |