Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / android_webview / browser / deferred_gpu_command_service.h
blobc7f230dd0249f355562e6480ea4bd196c41b5018
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_
8 #include <queue>
9 #include <utility>
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"
18 namespace gpu {
19 class SyncPointManager;
22 namespace android_webview {
24 class ScopedAllowGL {
25 public:
26 ScopedAllowGL();
27 ~ScopedAllowGL();
29 static bool IsAllowed();
31 private:
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> {
40 public:
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()
48 override;
49 gpu::SyncPointManager* sync_point_manager() override;
51 void RunTasks();
52 // If |is_idle| is false, this will only run older idle tasks.
53 void PerformIdleWork(bool is_idle);
54 // Flush the idle queue until it is empty. This is different from
55 // PerformIdleWork(is_idle = true), which does not run any newly scheduled
56 // idle tasks during the idle run.
57 void PerformAllIdleWork();
59 void AddRef() const override;
60 void Release() const override;
62 protected:
63 ~DeferredGpuCommandService() override;
64 friend class base::RefCountedThreadSafe<DeferredGpuCommandService>;
66 private:
67 friend class ScopedAllowGL;
68 static void RequestProcessGL(bool for_idle);
70 DeferredGpuCommandService();
71 size_t IdleQueueSize();
73 base::Lock tasks_lock_;
74 std::queue<base::Closure> tasks_;
75 std::queue<std::pair<base::Time, base::Closure> > idle_tasks_;
77 scoped_ptr<gpu::SyncPointManager> sync_point_manager_;
78 scoped_refptr<gpu::gles2::ShaderTranslatorCache> shader_translator_cache_;
79 DISALLOW_COPY_AND_ASSIGN(DeferredGpuCommandService);
82 } // namespace android_webview
84 #endif // ANDROID_WEBVIEW_BROWSER_DEFERRED_GPU_COMMAND_SERVICE_H_