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 ANDROID_WEBVIEW_BROWSER_HARDWARE_RENDERER_H_
6 #define ANDROID_WEBVIEW_BROWSER_HARDWARE_RENDERER_H_
10 #include "android_webview/browser/gl_view_renderer_manager.h"
11 #include "android_webview/browser/shared_renderer_state.h"
12 #include "base/lazy_instance.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/threading/thread_local.h"
18 namespace android_webview
{
21 class BrowserViewRendererClient
;
24 class DeferredGpuCommandService
;
25 } // namespace internal
27 class HardwareRenderer
{
29 explicit HardwareRenderer(SharedRendererState
* state
);
32 bool DrawGL(AwDrawGLInfo
* draw_info
, DrawGLResult
* result
);
35 friend class internal::DeferredGpuCommandService
;
37 void SetCompositorMemoryPolicy();
39 SharedRendererState
* shared_renderer_state_
;
41 typedef void* EGLContext
;
42 EGLContext last_egl_context_
;
44 scoped_refptr
<AwGLSurface
> gl_surface_
;
46 GLViewRendererManager::Key renderer_manager_key_
;
48 DISALLOW_COPY_AND_ASSIGN(HardwareRenderer
);
58 static bool IsAllowed();
61 static base::LazyInstance
<base::ThreadLocalBoolean
> allow_gl
;
63 DISALLOW_COPY_AND_ASSIGN(ScopedAllowGL
);
66 // TODO(boliu): Teach this class about RT.
67 class DeferredGpuCommandService
68 : public gpu::InProcessCommandBuffer::Service
,
69 public base::RefCountedThreadSafe
<DeferredGpuCommandService
> {
71 DeferredGpuCommandService();
73 virtual void ScheduleTask(const base::Closure
& task
) OVERRIDE
;
74 virtual void ScheduleIdleWork(const base::Closure
& task
) OVERRIDE
;
75 virtual bool UseVirtualizedGLContexts() OVERRIDE
;
76 virtual scoped_refptr
<gpu::gles2::ShaderTranslatorCache
>
77 shader_translator_cache() OVERRIDE
;
81 virtual void AddRef() const OVERRIDE
;
82 virtual void Release() const OVERRIDE
;
85 virtual ~DeferredGpuCommandService();
86 friend class base::RefCountedThreadSafe
<DeferredGpuCommandService
>;
89 static void RequestProcessGLOnUIThread();
91 base::Lock tasks_lock_
;
92 std::queue
<base::Closure
> tasks_
;
94 scoped_refptr
<gpu::gles2::ShaderTranslatorCache
> shader_translator_cache_
;
95 DISALLOW_COPY_AND_ASSIGN(DeferredGpuCommandService
);
98 } // namespace internal
100 } // namespace android_webview
102 #endif // ANDROID_WEBVIEW_BROWSER_HARDWARE_RENDERER_H_