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 "content/renderer/input/synchronous_input_handler_proxy.h"
19 #include "ipc/ipc_message.h"
22 struct BeginFrameArgs
;
31 class InputHandlerManager
;
32 class SynchronousCompositorExternalBeginFrameSource
;
33 struct DidOverscrollParams
;
35 // 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
37 // expose their functionality via the SynchronousCompositor interface.
38 // This class is created on the main thread but most of the APIs are called
39 // from the Compositor thread.
40 class SynchronousCompositorImpl
41 : public cc::LayerScrollOffsetDelegate
,
42 public SynchronousInputHandler
,
43 public SynchronousCompositor
,
44 public WebContentsUserData
<SynchronousCompositorImpl
> {
46 // When used from browser code, use both |process_id| and |routing_id|.
47 static SynchronousCompositorImpl
* FromID(int process_id
, int routing_id
);
48 // When handling upcalls from renderer code, use this version; the process id
49 // is implicitly that of the in-process renderer.
50 static SynchronousCompositorImpl
* FromRoutingID(int routing_id
);
52 InputEventAckState
HandleInputEvent(const blink::WebInputEvent
& input_event
);
54 // Called by SynchronousCompositorRegistry.
55 void DidInitializeRendererObjects(
56 SynchronousCompositorOutputSurface
* output_surface
,
57 SynchronousCompositorExternalBeginFrameSource
* begin_frame_source
,
58 cc::InputHandler
* input_handler
,
59 SynchronousInputHandlerProxy
* synchronous_input_handler_proxy
);
60 void DidDestroyRendererObjects();
62 // Called by SynchronousCompositorExternalBeginFrameSource.
63 void OnNeedsBeginFramesChange(bool needs_begin_frames
);
65 // Called by SynchronousCompositorOutputSurface.
66 void PostInvalidate();
68 // Called by RenderWidgetHostViewAndroid.
69 void BeginFrame(const cc::BeginFrameArgs
& args
);
71 // SynchronousCompositor
72 scoped_ptr
<cc::CompositorFrame
> DemandDrawHw(
73 gfx::Size surface_size
,
74 const gfx::Transform
& transform
,
77 gfx::Rect viewport_rect_for_tile_priority
,
78 const gfx::Transform
& transform_for_tile_priority
) override
;
79 bool DemandDrawSw(SkCanvas
* canvas
) override
;
80 void ReturnResources(const cc::CompositorFrameAck
& frame_ack
) override
;
81 void SetMemoryPolicy(size_t bytes_limit
) override
;
82 void DidChangeRootLayerScrollOffset(
83 const gfx::ScrollOffset
& root_offset
) override
;
84 void SetIsActive(bool is_active
) override
;
85 void OnComputeScroll(base::TimeTicks animation_time
) override
;
87 // SynchronousInputHandler
88 void SetNeedsSynchronousAnimateInput() override
;
90 // LayerScrollOffsetDelegate
91 void UpdateRootLayerState(const gfx::ScrollOffset
& total_scroll_offset
,
92 const gfx::ScrollOffset
& max_scroll_offset
,
93 const gfx::SizeF
& scrollable_size
,
94 float page_scale_factor
,
95 float min_page_scale_factor
,
96 float max_page_scale_factor
) override
;
98 void DidOverscroll(const DidOverscrollParams
& params
);
99 void DidStopFlinging();
102 friend class WebContentsUserData
<SynchronousCompositorImpl
>;
103 friend class SynchronousCompositor
;
104 explicit SynchronousCompositorImpl(WebContents
* contents
);
105 ~SynchronousCompositorImpl() override
;
107 void SetClient(SynchronousCompositorClient
* compositor_client
);
108 void RegisterWithClient();
109 void UpdateFrameMetaData(const cc::CompositorFrameMetadata
& frame_info
);
110 void DidActivatePendingTree();
111 void DeliverMessages();
112 bool CalledOnValidThread() const;
113 void UpdateNeedsBeginFrames();
115 SynchronousCompositorClient
* compositor_client_
;
116 SynchronousCompositorOutputSurface
* output_surface_
;
117 SynchronousCompositorExternalBeginFrameSource
* begin_frame_source_
;
118 WebContents
* contents_
;
119 const int routing_id_
;
120 cc::InputHandler
* input_handler_
;
121 SynchronousInputHandlerProxy
* synchronous_input_handler_proxy_
;
122 bool registered_with_client_
;
124 bool renderer_needs_begin_frames_
;
125 bool need_animate_input_
;
127 base::WeakPtrFactory
<SynchronousCompositorImpl
> weak_ptr_factory_
;
129 DISALLOW_COPY_AND_ASSIGN(SynchronousCompositorImpl
);
132 } // namespace content
134 #endif // CONTENT_BROWSER_ANDROID_IN_PROCESS_SYNCHRONOUS_COMPOSITOR_IMPL_H_