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 3 // found in the LICENSE file. 4 5 #ifndef CONTENT_BROWSER_ANDROID_IN_PROCESS_SYNCHRONOUS_COMPOSITOR_IMPL_H_ 6 #define CONTENT_BROWSER_ANDROID_IN_PROCESS_SYNCHRONOUS_COMPOSITOR_IMPL_H_ 7 8 #include "base/basictypes.h" 9 #include "base/compiler_specific.h" 10 #include "base/memory/scoped_ptr.h" 11 #include "cc/input/layer_scroll_offset_delegate.h" 12 #include "content/browser/android/in_process/synchronous_compositor_output_surface.h" 13 #include "content/common/input/input_event_ack_state.h" 14 #include "content/public/browser/android/synchronous_compositor.h" 15 #include "content/public/browser/web_contents_user_data.h" 16 17 namespace cc { 18 class InputHandler; 19 } 20 21 namespace blink { 22 class WebInputEvent; 23 } 24 25 namespace content { 26 class InputHandlerManager; 27 struct DidOverscrollParams; 28 29 // The purpose of this class is to act as the intermediary between the various 30 // components that make up the 'synchronous compositor mode' implementation and 31 // expose their functionality via the SynchronousCompositor interface. 32 // This class is created on the main thread but most of the APIs are called 33 // from the Compositor thread. 34 class SynchronousCompositorImpl 35 : public cc::LayerScrollOffsetDelegate, 36 public SynchronousCompositor, 37 public SynchronousCompositorOutputSurfaceDelegate, 38 public WebContentsUserData<SynchronousCompositorImpl> { 39 public: 40 // When used from browser code, use both |process_id| and |routing_id|. 41 static SynchronousCompositorImpl* FromID(int process_id, int routing_id); 42 // When handling upcalls from renderer code, use this version; the process id 43 // is implicitly that of the in-process renderer. 44 static SynchronousCompositorImpl* FromRoutingID(int routing_id); 45 46 InputEventAckState HandleInputEvent(const blink::WebInputEvent& input_event); 47 48 // SynchronousCompositor 49 virtual void SetClient(SynchronousCompositorClient* compositor_client) 50 OVERRIDE; 51 virtual bool InitializeHwDraw() OVERRIDE; 52 virtual void ReleaseHwDraw() OVERRIDE; 53 virtual gpu::GLInProcessContext* GetShareContext() OVERRIDE; 54 virtual scoped_ptr<cc::CompositorFrame> DemandDrawHw( 55 gfx::Size surface_size, 56 const gfx::Transform& transform, 57 gfx::Rect viewport, 58 gfx::Rect clip, 59 gfx::Rect viewport_rect_for_tile_priority, 60 const gfx::Transform& transform_for_tile_priority) OVERRIDE; 61 virtual bool DemandDrawSw(SkCanvas* canvas) OVERRIDE; 62 virtual void ReturnResources( 63 const cc::CompositorFrameAck& frame_ack) OVERRIDE; 64 virtual void SetMemoryPolicy( 65 const SynchronousCompositorMemoryPolicy& policy) OVERRIDE; 66 virtual void DidChangeRootLayerScrollOffset() OVERRIDE; 67 68 // SynchronousCompositorOutputSurfaceDelegate 69 virtual void DidBindOutputSurface( 70 SynchronousCompositorOutputSurface* output_surface) OVERRIDE; 71 virtual void DidDestroySynchronousOutputSurface( 72 SynchronousCompositorOutputSurface* output_surface) OVERRIDE; 73 virtual void SetContinuousInvalidate(bool enable) OVERRIDE; 74 virtual void DidActivatePendingTree() OVERRIDE; 75 76 // LayerScrollOffsetDelegate 77 virtual gfx::Vector2dF GetTotalScrollOffset() OVERRIDE; 78 virtual void UpdateRootLayerState(const gfx::Vector2dF& total_scroll_offset, 79 const gfx::Vector2dF& max_scroll_offset, 80 const gfx::SizeF& scrollable_size, 81 float page_scale_factor, 82 float min_page_scale_factor, 83 float max_page_scale_factor) OVERRIDE; 84 virtual bool IsExternalFlingActive() const OVERRIDE; 85 86 void SetInputHandler(cc::InputHandler* input_handler); 87 void DidOverscroll(const DidOverscrollParams& params); 88 void DidStopFlinging(); 89 90 private: 91 explicit SynchronousCompositorImpl(WebContents* contents); 92 virtual ~SynchronousCompositorImpl(); 93 friend class WebContentsUserData<SynchronousCompositorImpl>; 94 95 void UpdateFrameMetaData(const cc::CompositorFrameMetadata& frame_info); 96 bool CalledOnValidThread() const; 97 98 SynchronousCompositorClient* compositor_client_; 99 SynchronousCompositorOutputSurface* output_surface_; 100 WebContents* contents_; 101 cc::InputHandler* input_handler_; 102 103 base::WeakPtrFactory<SynchronousCompositorImpl> weak_ptr_factory_; 104 105 DISALLOW_COPY_AND_ASSIGN(SynchronousCompositorImpl); 106 }; 107 108 } // namespace content 109 110 #endif // CONTENT_BROWSER_ANDROID_IN_PROCESS_SYNCHRONOUS_COMPOSITOR_IMPL_H_ 111