blob: f0ea2c6e8248f7215d3eb7d46d64a6065a082684 [file] [log] [blame]
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +01001// 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.
4
5#ifndef CONTENT_BROWSER_ANDROID_IN_PROCESS_SYNCHRONOUS_COMPOSITOR_IMPL_H_
6#define CONTENT_BROWSER_ANDROID_IN_PROCESS_SYNCHRONOUS_COMPOSITOR_IMPL_H_
7
8#include "base/basictypes.h"
9#include "base/compiler_specific.h"
10#include "base/memory/scoped_ptr.h"
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010011#include "cc/input/layer_scroll_offset_delegate.h"
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010012#include "content/browser/android/in_process/synchronous_compositor_output_surface.h"
13#include "content/port/common/input_event_ack_state.h"
14#include "content/public/browser/android/synchronous_compositor.h"
15#include "content/public/browser/web_contents_user_data.h"
16
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010017namespace cc {
18class InputHandler;
Ben Murdoch9ab55632013-07-18 11:57:30 +010019struct DidOverscrollParams;
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010020}
21
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010022namespace WebKit {
23class WebInputEvent;
24}
25
26namespace content {
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010027class InputHandlerManager;
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010028
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.
34class SynchronousCompositorImpl
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010035 : public cc::LayerScrollOffsetDelegate,
36 public SynchronousCompositor,
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010037 public SynchronousCompositorOutputSurfaceDelegate,
38 public WebContentsUserData<SynchronousCompositorImpl> {
39 public:
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);
45
46 InputEventAckState HandleInputEvent(const WebKit::WebInputEvent& input_event);
47
48 // SynchronousCompositor
49 virtual void SetClient(SynchronousCompositorClient* compositor_client)
50 OVERRIDE;
Ben Murdochbb1529c2013-08-08 10:24:53 +010051 virtual bool InitializeHwDraw(
52 scoped_refptr<gfx::GLSurface> surface) OVERRIDE;
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010053 virtual void ReleaseHwDraw() OVERRIDE;
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010054 virtual bool DemandDrawHw(
55 gfx::Size view_size,
56 const gfx::Transform& transform,
Ben Murdochfb250652013-07-31 11:42:55 +010057 gfx::Rect clip,
58 bool stencil_enabled) OVERRIDE;
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010059 virtual bool DemandDrawSw(SkCanvas* canvas) OVERRIDE;
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010060 virtual void DidChangeRootLayerScrollOffset() OVERRIDE;
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010061
62 // SynchronousCompositorOutputSurfaceDelegate
63 virtual void DidBindOutputSurface(
64 SynchronousCompositorOutputSurface* output_surface) OVERRIDE;
65 virtual void DidDestroySynchronousOutputSurface(
66 SynchronousCompositorOutputSurface* output_surface) OVERRIDE;
67 virtual void SetContinuousInvalidate(bool enable) OVERRIDE;
Torne (Richard Coles)5e3f23d2013-06-11 16:24:11 +010068 virtual void UpdateFrameMetaData(
69 const cc::CompositorFrameMetadata& frame_info) OVERRIDE;
Ben Murdochca12bfa2013-07-23 11:17:05 +010070 virtual void DidActivatePendingTree() OVERRIDE;
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010071
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010072 // LayerScrollOffsetDelegate
73 virtual void SetTotalScrollOffset(gfx::Vector2dF new_value) OVERRIDE;
74 virtual gfx::Vector2dF GetTotalScrollOffset() OVERRIDE;
75
76 void SetInputHandler(cc::InputHandler* input_handler);
Ben Murdoch9ab55632013-07-18 11:57:30 +010077 void DidOverscroll(const cc::DidOverscrollParams& params);
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010078
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010079 private:
80 explicit SynchronousCompositorImpl(WebContents* contents);
81 virtual ~SynchronousCompositorImpl();
82 friend class WebContentsUserData<SynchronousCompositorImpl>;
83
84 void DidCreateSynchronousOutputSurface(
85 SynchronousCompositorOutputSurface* output_surface);
86 bool CalledOnValidThread() const;
87
88 SynchronousCompositorClient* compositor_client_;
89 SynchronousCompositorOutputSurface* output_surface_;
90 WebContents* contents_;
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010091 cc::InputHandler* input_handler_;
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010092
93 DISALLOW_COPY_AND_ASSIGN(SynchronousCompositorImpl);
94};
95
96} // namespace content
97
98#endif // CONTENT_BROWSER_ANDROID_IN_PROCESS_SYNCHRONOUS_COMPOSITOR_IMPL_H_