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_
11 #include "base/lazy_instance.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/threading/thread_local.h"
15 #include "base/time/time.h"
16 #include "gpu/command_buffer/service/in_process_command_buffer.h"
19 class SyncPointManager
;
22 namespace android_webview
{
29 static bool IsAllowed();
32 static base::LazyInstance
<base::ThreadLocalBoolean
> allow_gl
;
34 DISALLOW_COPY_AND_ASSIGN(ScopedAllowGL
);
37 class DeferredGpuCommandService
38 : public gpu::InProcessCommandBuffer::Service
,
39 public base::RefCountedThreadSafe
<DeferredGpuCommandService
> {
41 static void SetInstance();
42 static DeferredGpuCommandService
* GetInstance();
44 void ScheduleTask(const base::Closure
& task
) override
;
45 void ScheduleIdleWork(const base::Closure
& task
) override
;
46 bool UseVirtualizedGLContexts() override
;
47 scoped_refptr
<gpu::gles2::ShaderTranslatorCache
> shader_translator_cache()
49 scoped_refptr
<gpu::gles2::FramebufferCompletenessCache
>
50 framebuffer_completeness_cache() override
;
51 gpu::SyncPointManager
* sync_point_manager() override
;
54 // If |is_idle| is false, this will only run older idle tasks.
55 void PerformIdleWork(bool is_idle
);
56 // Flush the idle queue until it is empty. This is different from
57 // PerformIdleWork(is_idle = true), which does not run any newly scheduled
58 // idle tasks during the idle run.
59 void PerformAllIdleWork();
61 void AddRef() const override
;
62 void Release() const override
;
65 ~DeferredGpuCommandService() override
;
66 friend class base::RefCountedThreadSafe
<DeferredGpuCommandService
>;
69 friend class ScopedAllowGL
;
70 static void RequestProcessGL(bool for_idle
);
72 DeferredGpuCommandService();
73 size_t IdleQueueSize();
75 base::Lock tasks_lock_
;
76 std::queue
<base::Closure
> tasks_
;
77 std::queue
<std::pair
<base::Time
, base::Closure
> > idle_tasks_
;
79 scoped_ptr
<gpu::SyncPointManager
> sync_point_manager_
;
80 scoped_refptr
<gpu::gles2::ShaderTranslatorCache
> shader_translator_cache_
;
81 scoped_refptr
<gpu::gles2::FramebufferCompletenessCache
>
82 framebuffer_completeness_cache_
;
83 DISALLOW_COPY_AND_ASSIGN(DeferredGpuCommandService
);
86 } // namespace android_webview
88 #endif // ANDROID_WEBVIEW_BROWSER_DEFERRED_GPU_COMMAND_SERVICE_H_