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_DEFERRED_GPU_COMMAND_SERVICE_H_
6 #define ANDROID_WEBVIEW_BROWSER_DEFERRED_GPU_COMMAND_SERVICE_H_
10 #include "base/lazy_instance.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/threading/thread_local.h"
13 #include "gpu/command_buffer/service/in_process_command_buffer.h"
15 namespace android_webview
{
22 static bool IsAllowed();
25 static base::LazyInstance
<base::ThreadLocalBoolean
> allow_gl
;
27 DISALLOW_COPY_AND_ASSIGN(ScopedAllowGL
);
30 class DeferredGpuCommandService
31 : public gpu::InProcessCommandBuffer::Service
,
32 public base::RefCountedThreadSafe
<DeferredGpuCommandService
> {
34 static void SetInstance();
35 static DeferredGpuCommandService
* GetInstance();
37 virtual void ScheduleTask(const base::Closure
& task
) OVERRIDE
;
38 virtual void ScheduleIdleWork(const base::Closure
& task
) OVERRIDE
;
39 virtual bool UseVirtualizedGLContexts() OVERRIDE
;
40 virtual scoped_refptr
<gpu::gles2::ShaderTranslatorCache
>
41 shader_translator_cache() OVERRIDE
;
45 virtual void AddRef() const OVERRIDE
;
46 virtual void Release() const OVERRIDE
;
49 virtual ~DeferredGpuCommandService();
50 friend class base::RefCountedThreadSafe
<DeferredGpuCommandService
>;
53 static void RequestProcessGL();
55 DeferredGpuCommandService();
57 base::Lock tasks_lock_
;
58 std::queue
<base::Closure
> tasks_
;
60 scoped_refptr
<gpu::gles2::ShaderTranslatorCache
> shader_translator_cache_
;
61 DISALLOW_COPY_AND_ASSIGN(DeferredGpuCommandService
);
64 } // namespace android_webview
66 #endif // ANDROID_WEBVIEW_BROWSER_DEFERRED_GPU_COMMAND_SERVICE_H_