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 "content/browser/android/in_process/synchronous_compositor_output_surface.h"
14 #include "content/common/input/input_event_ack_state.h"
15 #include "content/public/browser/android/synchronous_compositor.h"
16 #include "content/public/browser/web_contents_user_data.h"
17 #include "content/renderer/input/synchronous_input_handler_proxy.h"
18 #include "ipc/ipc_message.h"
21 struct BeginFrameArgs
;
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 SynchronousInputHandler
,
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 SynchronousInputHandlerProxy
* synchronous_input_handler_proxy
);
57 void DidDestroyRendererObjects();
59 // Called by SynchronousCompositorExternalBeginFrameSource.
60 void OnNeedsBeginFramesChange(bool needs_begin_frames
);
62 // Called by SynchronousCompositorOutputSurface.
63 void PostInvalidate();
65 // Called by RenderWidgetHostViewAndroid.
66 void BeginFrame(const cc::BeginFrameArgs
& args
);
68 // SynchronousCompositor
69 scoped_ptr
<cc::CompositorFrame
> DemandDrawHw(
70 gfx::Size surface_size
,
71 const gfx::Transform
& transform
,
74 gfx::Rect viewport_rect_for_tile_priority
,
75 const gfx::Transform
& transform_for_tile_priority
) override
;
76 bool DemandDrawSw(SkCanvas
* canvas
) override
;
77 void ReturnResources(const cc::CompositorFrameAck
& frame_ack
) override
;
78 void SetMemoryPolicy(size_t bytes_limit
) override
;
79 void DidChangeRootLayerScrollOffset(
80 const gfx::ScrollOffset
& root_offset
) override
;
81 void SetIsActive(bool is_active
) override
;
82 void OnComputeScroll(base::TimeTicks animation_time
) override
;
84 // SynchronousInputHandler
85 void SetNeedsSynchronousAnimateInput() override
;
86 void UpdateRootLayerState(const gfx::ScrollOffset
& total_scroll_offset
,
87 const gfx::ScrollOffset
& max_scroll_offset
,
88 const gfx::SizeF
& scrollable_size
,
89 float page_scale_factor
,
90 float min_page_scale_factor
,
91 float max_page_scale_factor
) override
;
93 void DidOverscroll(const DidOverscrollParams
& params
);
94 void DidStopFlinging();
97 friend class WebContentsUserData
<SynchronousCompositorImpl
>;
98 friend class SynchronousCompositor
;
99 explicit SynchronousCompositorImpl(WebContents
* contents
);
100 ~SynchronousCompositorImpl() override
;
102 void SetClient(SynchronousCompositorClient
* compositor_client
);
103 void RegisterWithClient();
104 void UpdateFrameMetaData(const cc::CompositorFrameMetadata
& frame_info
);
105 void DidActivatePendingTree();
106 void DeliverMessages();
107 bool CalledOnValidThread() const;
108 void UpdateNeedsBeginFrames();
110 SynchronousCompositorClient
* compositor_client_
;
111 SynchronousCompositorOutputSurface
* output_surface_
;
112 SynchronousCompositorExternalBeginFrameSource
* begin_frame_source_
;
113 WebContents
* contents_
;
114 const int routing_id_
;
115 SynchronousInputHandlerProxy
* synchronous_input_handler_proxy_
;
116 bool registered_with_client_
;
118 bool renderer_needs_begin_frames_
;
119 bool need_animate_input_
;
121 base::WeakPtrFactory
<SynchronousCompositorImpl
> weak_ptr_factory_
;
123 DISALLOW_COPY_AND_ASSIGN(SynchronousCompositorImpl
);
126 } // namespace content
128 #endif // CONTENT_BROWSER_ANDROID_IN_PROCESS_SYNCHRONOUS_COMPOSITOR_IMPL_H_