synchronous_compositor_impl.h revision 7d4cd473f85ac64c3747c96c277f9e506a0d2246
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. 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" 11#include "cc/input/layer_scroll_offset_delegate.h" 12#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 17namespace cc { 18class InputHandler; 19} 20 21namespace WebKit { 22class WebInputEvent; 23} 24 25namespace content { 26class InputHandlerManager; 27 28// The purpose of this class is to act as the intermediary between the various 29// components that make up the 'synchronous compositor mode' implementation and 30// expose their functionality via the SynchronousCompositor interface. 31// This class is created on the main thread but most of the APIs are called 32// from the Compositor thread. 33class SynchronousCompositorImpl 34 : public cc::LayerScrollOffsetDelegate, 35 public SynchronousCompositor, 36 public SynchronousCompositorOutputSurfaceDelegate, 37 public WebContentsUserData<SynchronousCompositorImpl> { 38 public: 39 // When used from browser code, use both |process_id| and |routing_id|. 40 static SynchronousCompositorImpl* FromID(int process_id, int routing_id); 41 // When handling upcalls from renderer code, use this version; the process id 42 // is implicitly that of the in-process renderer. 43 static SynchronousCompositorImpl* FromRoutingID(int routing_id); 44 45 InputEventAckState HandleInputEvent(const WebKit::WebInputEvent& input_event); 46 47 // SynchronousCompositor 48 virtual void SetClient(SynchronousCompositorClient* compositor_client) 49 OVERRIDE; 50 virtual bool InitializeHwDraw() OVERRIDE; 51 virtual bool DemandDrawHw( 52 gfx::Size view_size, 53 const gfx::Transform& transform, 54 gfx::Rect clip) OVERRIDE; 55 virtual bool DemandDrawSw(SkCanvas* canvas) OVERRIDE; 56 virtual void DidChangeRootLayerScrollOffset() OVERRIDE; 57 58 // SynchronousCompositorOutputSurfaceDelegate 59 virtual void DidBindOutputSurface( 60 SynchronousCompositorOutputSurface* output_surface) OVERRIDE; 61 virtual void DidDestroySynchronousOutputSurface( 62 SynchronousCompositorOutputSurface* output_surface) OVERRIDE; 63 virtual void SetContinuousInvalidate(bool enable) OVERRIDE; 64 virtual void UpdateFrameMetaData( 65 const cc::CompositorFrameMetadata& frame_info) OVERRIDE; 66 67 // LayerScrollOffsetDelegate 68 virtual void SetTotalScrollOffset(gfx::Vector2dF new_value) OVERRIDE; 69 virtual gfx::Vector2dF GetTotalScrollOffset() OVERRIDE; 70 71 void SetInputHandler(cc::InputHandler* input_handler); 72 73 private: 74 explicit SynchronousCompositorImpl(WebContents* contents); 75 virtual ~SynchronousCompositorImpl(); 76 friend class WebContentsUserData<SynchronousCompositorImpl>; 77 78 void DidCreateSynchronousOutputSurface( 79 SynchronousCompositorOutputSurface* output_surface); 80 bool CalledOnValidThread() const; 81 82 SynchronousCompositorClient* compositor_client_; 83 SynchronousCompositorOutputSurface* output_surface_; 84 WebContents* contents_; 85 cc::InputHandler* input_handler_; 86 87 DISALLOW_COPY_AND_ASSIGN(SynchronousCompositorImpl); 88}; 89 90} // namespace content 91 92#endif // CONTENT_BROWSER_ANDROID_IN_PROCESS_SYNCHRONOUS_COMPOSITOR_IMPL_H_ 93