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.
5 #ifndef CONTENT_BROWSER_ANDROID_IN_PROCESS_SYNCHRONOUS_COMPOSITOR_FACTORY_IMPL_H_
6 #define CONTENT_BROWSER_ANDROID_IN_PROCESS_SYNCHRONOUS_COMPOSITOR_FACTORY_IMPL_H_
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"
20 class GLInProcessContext;
25 class WebGraphicsContext3DInProcessCommandBufferImpl;
31 class SynchronousCompositorFactoryImpl : public SynchronousCompositorFactory {
33 SynchronousCompositorFactoryImpl();
34 virtual ~SynchronousCompositorFactoryImpl();
36 // SynchronousCompositorFactory
37 virtual scoped_refptr<base::MessageLoopProxy> GetCompositorMessageLoop()
39 virtual scoped_ptr<cc::OutputSurface> CreateOutputSurface(int routing_id)
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;
55 SynchronousInputEventFilter* synchronous_input_event_filter() {
56 return &synchronous_input_event_filter_;
59 void SetDeferredGpuService(
60 scoped_refptr<gpu::InProcessCommandBuffer::Service> service);
61 void CompositorInitializedHardwareDraw();
62 void CompositorReleasedHardwareDraw();
64 scoped_refptr<cc::ContextProvider>
65 CreateOnscreenContextProviderForCompositorThread(
66 scoped_refptr<gfx::GLSurface> surface);
69 bool CanCreateMainThreadContext();
70 scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider>
71 TryCreateStreamTextureFactory();
73 SynchronousInputEventFilter synchronous_input_event_filter_;
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_;
86 scoped_refptr<gpu::InProcessCommandBuffer::Service> service_;
87 scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider>
88 video_context_provider_;
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_;
96 } // namespace content
98 #endif // CONTENT_BROWSER_ANDROID_IN_PROCESS_SYNCHRONOUS_COMPOSITOR_FACTORY_IMPL_H_