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"
21 class BeginFrameSource
;
30 class InputHandlerManager
;
31 class SynchronousCompositorExternalBeginFrameSource
;
32 struct DidOverscrollParams
;
34 // The purpose of this class is to act as the intermediary between the various
35 // components that make up the 'synchronous compositor mode' implementation and
36 // expose their functionality via the SynchronousCompositor interface.
37 // This class is created on the main thread but most of the APIs are called
38 // from the Compositor thread.
39 class SynchronousCompositorImpl
40 : public cc::LayerScrollOffsetDelegate
,
41 public SynchronousCompositor
,
42 public WebContentsUserData
<SynchronousCompositorImpl
> {
44 // When used from browser code, use both |process_id| and |routing_id|.
45 static SynchronousCompositorImpl
* FromID(int process_id
, int routing_id
);
46 // When handling upcalls from renderer code, use this version; the process id
47 // is implicitly that of the in-process renderer.
48 static SynchronousCompositorImpl
* FromRoutingID(int routing_id
);
50 InputEventAckState
HandleInputEvent(const blink::WebInputEvent
& input_event
);
52 // Called by SynchronousCompositorRegistry.
53 void DidInitializeRendererObjects(
54 SynchronousCompositorOutputSurface
* output_surface
,
55 SynchronousCompositorExternalBeginFrameSource
* begin_frame_source
);
56 void DidDestroyRendererObjects();
58 // Called by SynchronousCompositorExternalBeginFrameSource.
59 void NeedsBeginFramesChanged() const;
61 // SynchronousCompositor
62 virtual bool InitializeHwDraw() override
;
63 virtual void ReleaseHwDraw() override
;
64 virtual scoped_ptr
<cc::CompositorFrame
> DemandDrawHw(
65 gfx::Size surface_size
,
66 const gfx::Transform
& transform
,
69 gfx::Rect viewport_rect_for_tile_priority
,
70 const gfx::Transform
& transform_for_tile_priority
) override
;
71 virtual bool DemandDrawSw(SkCanvas
* canvas
) override
;
72 virtual void ReturnResources(
73 const cc::CompositorFrameAck
& frame_ack
) override
;
74 virtual void SetMemoryPolicy(size_t bytes_limit
) override
;
75 virtual void DidChangeRootLayerScrollOffset() override
;
77 // LayerScrollOffsetDelegate
78 virtual gfx::ScrollOffset
GetTotalScrollOffset() override
;
79 virtual void UpdateRootLayerState(
80 const gfx::ScrollOffset
& total_scroll_offset
,
81 const gfx::ScrollOffset
& max_scroll_offset
,
82 const gfx::SizeF
& scrollable_size
,
83 float page_scale_factor
,
84 float min_page_scale_factor
,
85 float max_page_scale_factor
) override
;
86 virtual bool IsExternalFlingActive() const override
;
88 void SetInputHandler(cc::InputHandler
* input_handler
);
89 void DidOverscroll(const DidOverscrollParams
& params
);
90 void DidStopFlinging();
93 friend class WebContentsUserData
<SynchronousCompositorImpl
>;
94 friend class SynchronousCompositor
;
95 explicit SynchronousCompositorImpl(WebContents
* contents
);
96 virtual ~SynchronousCompositorImpl();
98 void SetClient(SynchronousCompositorClient
* compositor_client
);
99 void UpdateFrameMetaData(const cc::CompositorFrameMetadata
& frame_info
);
100 void NotifyDidDestroyCompositorToClient();
101 void DidActivatePendingTree();
102 void DeliverMessages();
103 bool CalledOnValidThread() const;
105 SynchronousCompositorClient
* compositor_client_
;
106 SynchronousCompositorOutputSurface
* output_surface_
;
107 SynchronousCompositorExternalBeginFrameSource
* begin_frame_source_
;
108 WebContents
* contents_
;
109 const int routing_id_
;
110 cc::InputHandler
* input_handler_
;
111 bool invoking_composite_
;
113 base::WeakPtrFactory
<SynchronousCompositorImpl
> weak_ptr_factory_
;
115 DISALLOW_COPY_AND_ASSIGN(SynchronousCompositorImpl
);
118 } // namespace content
120 #endif // CONTENT_BROWSER_ANDROID_IN_PROCESS_SYNCHRONOUS_COMPOSITOR_IMPL_H_