Home | History | Annotate | Download | only in in_process
      1 // Copyright 2014 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_FACTORY_IMPL_H_
      6 #define CONTENT_BROWSER_ANDROID_IN_PROCESS_SYNCHRONOUS_COMPOSITOR_FACTORY_IMPL_H_
      7 
      8 #include "base/synchronization/lock.h"
      9 #include "content/browser/android/in_process/synchronous_input_event_filter.h"
     10 #include "content/renderer/android/synchronous_compositor_factory.h"
     11 #include "content/renderer/media/android/stream_texture_factory_android_synchronous_impl.h"
     12 #include "gpu/command_buffer/service/in_process_command_buffer.h"
     13 
     14 namespace gfx {
     15 class GLSurface;
     16 }
     17 
     18 namespace gpu {
     19 class GLInProcessContext;
     20 }
     21 
     22 namespace webkit {
     23 namespace gpu {
     24 class WebGraphicsContext3DInProcessCommandBufferImpl;
     25 }
     26 }
     27 
     28 namespace content {
     29 
     30 class SynchronousCompositorFactoryImpl : public SynchronousCompositorFactory {
     31  public:
     32   SynchronousCompositorFactoryImpl();
     33   virtual ~SynchronousCompositorFactoryImpl();
     34 
     35   // SynchronousCompositorFactory
     36   virtual scoped_refptr<base::MessageLoopProxy> GetCompositorMessageLoop()
     37       OVERRIDE;
     38   virtual scoped_ptr<cc::OutputSurface> CreateOutputSurface(int routing_id)
     39       OVERRIDE;
     40   virtual InputHandlerManagerClient* GetInputHandlerManagerClient() OVERRIDE;
     41   virtual scoped_refptr<cc::ContextProvider>
     42       GetOffscreenContextProviderForMainThread() OVERRIDE;
     43   // This is called on both renderer main thread (offscreen context creation
     44   // path shared between cross-process and in-process platforms) and renderer
     45   // compositor impl thread (InitializeHwDraw) in order to support Android
     46   // WebView synchronously enable and disable hardware mode multiple times in
     47   // the same task. This is ok because in-process WGC3D creation may happen on
     48   // any thread and is lightweight.
     49   virtual scoped_refptr<cc::ContextProvider>
     50       GetOffscreenContextProviderForCompositorThread() OVERRIDE;
     51   virtual scoped_ptr<StreamTextureFactory> CreateStreamTextureFactory(
     52       int view_id) OVERRIDE;
     53 
     54   SynchronousInputEventFilter* synchronous_input_event_filter() {
     55     return &synchronous_input_event_filter_;
     56   }
     57 
     58   void SetDeferredGpuService(
     59       scoped_refptr<gpu::InProcessCommandBuffer::Service> service);
     60   void CompositorInitializedHardwareDraw();
     61   void CompositorReleasedHardwareDraw();
     62 
     63   scoped_refptr<cc::ContextProvider>
     64       CreateOnscreenContextProviderForCompositorThread(
     65           scoped_refptr<gfx::GLSurface> surface);
     66 
     67  private:
     68   bool CanCreateMainThreadContext();
     69   scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider>
     70       TryCreateStreamTextureFactory();
     71 
     72   SynchronousInputEventFilter synchronous_input_event_filter_;
     73 
     74   // Only guards construction and destruction of
     75   // |offscreen_context_for_compositor_thread_|, not usage.
     76   base::Lock offscreen_context_for_compositor_thread_lock_;
     77   scoped_refptr<cc::ContextProvider> offscreen_context_for_main_thread_;
     78   // This is a pointer to the context owned by
     79   // |offscreen_context_for_main_thread_|.
     80   gpu::GLInProcessContext* wrapped_gl_context_for_main_thread_;
     81   gpu::GLInProcessContext* wrapped_gl_context_for_compositor_thread_;
     82   scoped_refptr<cc::ContextProvider> offscreen_context_for_compositor_thread_;
     83 
     84   scoped_refptr<gpu::InProcessCommandBuffer::Service> service_;
     85   scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider>
     86       video_context_provider_;
     87 
     88   // |num_hardware_compositor_lock_| is updated on UI thread only but can be
     89   // read on renderer main thread.
     90   base::Lock num_hardware_compositor_lock_;
     91   unsigned int num_hardware_compositors_;
     92 };
     93 
     94 }  // namespace content
     95 
     96 #endif  // CONTENT_BROWSER_ANDROID_IN_PROCESS_SYNCHRONOUS_COMPOSITOR_FACTORY_IMPL_H_
     97