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_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "cc/input/layer_scroll_offset_delegate.h"
12 #include "content/browser/android/in_process/synchronous_compositor_output_surface.h"
13 #include "content/common/input/input_event_ack_state.h"
14 #include "content/public/browser/android/synchronous_compositor.h"
15 #include "content/public/browser/web_contents_user_data.h"
26 class InputHandlerManager;
27 struct DidOverscrollParams;
29 // The purpose of this class is to act as the intermediary between the various
30 // components that make up the 'synchronous compositor mode' implementation and
31 // expose their functionality via the SynchronousCompositor interface.
32 // This class is created on the main thread but most of the APIs are called
33 // from the Compositor thread.
34 class SynchronousCompositorImpl
35 : public cc::LayerScrollOffsetDelegate,
36 public SynchronousCompositor,
37 public SynchronousCompositorOutputSurfaceDelegate,
38 public WebContentsUserData<SynchronousCompositorImpl> {
40 // When used from browser code, use both |process_id| and |routing_id|.
41 static SynchronousCompositorImpl* FromID(int process_id, int routing_id);
42 // When handling upcalls from renderer code, use this version; the process id
43 // is implicitly that of the in-process renderer.
44 static SynchronousCompositorImpl* FromRoutingID(int routing_id);
46 InputEventAckState HandleInputEvent(const blink::WebInputEvent& input_event);
48 // SynchronousCompositor
49 virtual void SetClient(SynchronousCompositorClient* compositor_client)
51 virtual bool InitializeHwDraw(
52 scoped_refptr<gfx::GLSurface> surface) OVERRIDE;
53 virtual void ReleaseHwDraw() OVERRIDE;
54 virtual bool DemandDrawHw(
55 gfx::Size surface_size,
56 const gfx::Transform& transform,
59 bool stencil_enabled) OVERRIDE;
60 virtual bool DemandDrawSw(SkCanvas* canvas) OVERRIDE;
61 virtual void SetMemoryPolicy(
62 const SynchronousCompositorMemoryPolicy& policy) OVERRIDE;
63 virtual void DidChangeRootLayerScrollOffset() OVERRIDE;
65 // SynchronousCompositorOutputSurfaceDelegate
66 virtual void DidBindOutputSurface(
67 SynchronousCompositorOutputSurface* output_surface) OVERRIDE;
68 virtual void DidDestroySynchronousOutputSurface(
69 SynchronousCompositorOutputSurface* output_surface) OVERRIDE;
70 virtual void SetContinuousInvalidate(bool enable) OVERRIDE;
71 virtual void UpdateFrameMetaData(
72 const cc::CompositorFrameMetadata& frame_info) OVERRIDE;
73 virtual void DidActivatePendingTree() OVERRIDE;
75 // LayerScrollOffsetDelegate
76 virtual void SetMaxScrollOffset(
77 const gfx::Vector2dF& max_scroll_offset) OVERRIDE;
78 virtual void SetTotalScrollOffset(const gfx::Vector2dF& new_value) OVERRIDE;
79 virtual gfx::Vector2dF GetTotalScrollOffset() OVERRIDE;
80 virtual bool IsExternalFlingActive() const OVERRIDE;
81 virtual void SetTotalPageScaleFactorAndLimits(
82 float page_scale_factor,
83 float min_page_scale_factor,
84 float max_page_scale_factor) OVERRIDE;
85 virtual void SetScrollableSize(const gfx::SizeF& scrollable_size) OVERRIDE;
87 void SetInputHandler(cc::InputHandler* input_handler);
88 void DidOverscroll(const DidOverscrollParams& params);
89 void DidStopFlinging();
92 explicit SynchronousCompositorImpl(WebContents* contents);
93 virtual ~SynchronousCompositorImpl();
94 friend class WebContentsUserData<SynchronousCompositorImpl>;
96 void DidCreateSynchronousOutputSurface(
97 SynchronousCompositorOutputSurface* output_surface);
98 bool CalledOnValidThread() const;
100 SynchronousCompositorClient* compositor_client_;
101 SynchronousCompositorOutputSurface* output_surface_;
102 WebContents* contents_;
103 cc::InputHandler* input_handler_;
105 DISALLOW_COPY_AND_ASSIGN(SynchronousCompositorImpl);
108 } // namespace content
110 #endif // CONTENT_BROWSER_ANDROID_IN_PROCESS_SYNCHRONOUS_COMPOSITOR_IMPL_H_