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