| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef ANDROID_WEBVIEW_BROWSER_DEFERRED_GPU_COMMAND_SERVICE_H_ | 5 #ifndef ANDROID_WEBVIEW_BROWSER_DEFERRED_GPU_COMMAND_SERVICE_H_ |
| 6 #define ANDROID_WEBVIEW_BROWSER_DEFERRED_GPU_COMMAND_SERVICE_H_ | 6 #define ANDROID_WEBVIEW_BROWSER_DEFERRED_GPU_COMMAND_SERVICE_H_ |
| 7 | 7 |
| 8 #include <queue> | 8 #include <queue> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/threading/thread_local.h" | 14 #include "base/threading/thread_local.h" |
| 14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 15 #include "gpu/command_buffer/service/in_process_command_buffer.h" | 16 #include "gpu/command_buffer/service/in_process_command_buffer.h" |
| 16 | 17 |
| 18 namespace gpu { |
| 19 class SyncPointManager; |
| 20 } |
| 21 |
| 17 namespace android_webview { | 22 namespace android_webview { |
| 18 | 23 |
| 19 class ScopedAllowGL { | 24 class ScopedAllowGL { |
| 20 public: | 25 public: |
| 21 ScopedAllowGL(); | 26 ScopedAllowGL(); |
| 22 ~ScopedAllowGL(); | 27 ~ScopedAllowGL(); |
| 23 | 28 |
| 24 static bool IsAllowed(); | 29 static bool IsAllowed(); |
| 25 | 30 |
| 26 private: | 31 private: |
| 27 static base::LazyInstance<base::ThreadLocalBoolean> allow_gl; | 32 static base::LazyInstance<base::ThreadLocalBoolean> allow_gl; |
| 28 | 33 |
| 29 DISALLOW_COPY_AND_ASSIGN(ScopedAllowGL); | 34 DISALLOW_COPY_AND_ASSIGN(ScopedAllowGL); |
| 30 }; | 35 }; |
| 31 | 36 |
| 32 class DeferredGpuCommandService | 37 class DeferredGpuCommandService |
| 33 : public gpu::InProcessCommandBuffer::Service, | 38 : public gpu::InProcessCommandBuffer::Service, |
| 34 public base::RefCountedThreadSafe<DeferredGpuCommandService> { | 39 public base::RefCountedThreadSafe<DeferredGpuCommandService> { |
| 35 public: | 40 public: |
| 36 static void SetInstance(); | 41 static void SetInstance(); |
| 37 static DeferredGpuCommandService* GetInstance(); | 42 static DeferredGpuCommandService* GetInstance(); |
| 38 | 43 |
| 39 void ScheduleTask(const base::Closure& task) override; | 44 void ScheduleTask(const base::Closure& task) override; |
| 40 void ScheduleIdleWork(const base::Closure& task) override; | 45 void ScheduleIdleWork(const base::Closure& task) override; |
| 41 bool UseVirtualizedGLContexts() override; | 46 bool UseVirtualizedGLContexts() override; |
| 42 scoped_refptr<gpu::gles2::ShaderTranslatorCache> shader_translator_cache() | 47 scoped_refptr<gpu::gles2::ShaderTranslatorCache> shader_translator_cache() |
| 43 override; | 48 override; |
| 49 gpu::SyncPointManager* sync_point_manager() override; |
| 44 | 50 |
| 45 void RunTasks(); | 51 void RunTasks(); |
| 46 // If |is_idle| is false, this will only run older idle tasks. | 52 // If |is_idle| is false, this will only run older idle tasks. |
| 47 void PerformIdleWork(bool is_idle); | 53 void PerformIdleWork(bool is_idle); |
| 48 // Flush the idle queue until it is empty. This is different from | 54 // Flush the idle queue until it is empty. This is different from |
| 49 // PerformIdleWork(is_idle = true), which does not run any newly scheduled | 55 // PerformIdleWork(is_idle = true), which does not run any newly scheduled |
| 50 // idle tasks during the idle run. | 56 // idle tasks during the idle run. |
| 51 void PerformAllIdleWork(); | 57 void PerformAllIdleWork(); |
| 52 | 58 |
| 53 void AddRef() const override; | 59 void AddRef() const override; |
| 54 void Release() const override; | 60 void Release() const override; |
| 55 | 61 |
| 56 protected: | 62 protected: |
| 57 ~DeferredGpuCommandService() override; | 63 ~DeferredGpuCommandService() override; |
| 58 friend class base::RefCountedThreadSafe<DeferredGpuCommandService>; | 64 friend class base::RefCountedThreadSafe<DeferredGpuCommandService>; |
| 59 | 65 |
| 60 private: | 66 private: |
| 61 friend class ScopedAllowGL; | 67 friend class ScopedAllowGL; |
| 62 static void RequestProcessGL(); | 68 static void RequestProcessGL(); |
| 63 | 69 |
| 64 DeferredGpuCommandService(); | 70 DeferredGpuCommandService(); |
| 65 size_t IdleQueueSize(); | 71 size_t IdleQueueSize(); |
| 66 | 72 |
| 67 base::Lock tasks_lock_; | 73 base::Lock tasks_lock_; |
| 68 std::queue<base::Closure> tasks_; | 74 std::queue<base::Closure> tasks_; |
| 69 std::queue<std::pair<base::Time, base::Closure> > idle_tasks_; | 75 std::queue<std::pair<base::Time, base::Closure> > idle_tasks_; |
| 70 | 76 |
| 77 scoped_ptr<gpu::SyncPointManager> sync_point_manager_; |
| 71 scoped_refptr<gpu::gles2::ShaderTranslatorCache> shader_translator_cache_; | 78 scoped_refptr<gpu::gles2::ShaderTranslatorCache> shader_translator_cache_; |
| 72 DISALLOW_COPY_AND_ASSIGN(DeferredGpuCommandService); | 79 DISALLOW_COPY_AND_ASSIGN(DeferredGpuCommandService); |
| 73 }; | 80 }; |
| 74 | 81 |
| 75 } // namespace android_webview | 82 } // namespace android_webview |
| 76 | 83 |
| 77 #endif // ANDROID_WEBVIEW_BROWSER_DEFERRED_GPU_COMMAND_SERVICE_H_ | 84 #endif // ANDROID_WEBVIEW_BROWSER_DEFERRED_GPU_COMMAND_SERVICE_H_ |
| OLD | NEW |