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 scoped_ptr<cc::CompositorFrame> DemandDrawHw(
57 gfx::Size surface_size,
58 const gfx::Transform& transform,
61 gfx::Rect viewport_rect_for_tile_priority,
62 const gfx::Transform& transform_for_tile_priority) override;
63 virtual bool DemandDrawSw(SkCanvas* canvas) override;
64 virtual void ReturnResources(
65 const cc::CompositorFrameAck& frame_ack) override;
66 virtual void SetMemoryPolicy(size_t bytes_limit) override;
67 virtual void DidChangeRootLayerScrollOffset() override;
69 // SynchronousCompositorOutputSurfaceDelegate
70 virtual void DidBindOutputSurface(
71 SynchronousCompositorOutputSurface* output_surface) override;
72 virtual void DidDestroySynchronousOutputSurface(
73 SynchronousCompositorOutputSurface* output_surface) override;
74 virtual void SetContinuousInvalidate(bool enable) override;
75 virtual void DidActivatePendingTree() 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 explicit SynchronousCompositorImpl(WebContents* contents);
94 virtual ~SynchronousCompositorImpl();
95 friend class WebContentsUserData<SynchronousCompositorImpl>;
97 void UpdateFrameMetaData(const cc::CompositorFrameMetadata& frame_info);
98 void DeliverMessages();
99 bool CalledOnValidThread() const;
101 SynchronousCompositorClient* compositor_client_;
102 SynchronousCompositorOutputSurface* output_surface_;
103 WebContents* contents_;
104 cc::InputHandler* input_handler_;
106 base::WeakPtrFactory<SynchronousCompositorImpl> weak_ptr_factory_;
108 DISALLOW_COPY_AND_ASSIGN(SynchronousCompositorImpl);
111 } // namespace content
113 #endif // CONTENT_BROWSER_ANDROID_IN_PROCESS_SYNCHRONOUS_COMPOSITOR_IMPL_H_