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