| 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_HARDWARE_RENDERER_H_ | 5 #ifndef ANDROID_WEBVIEW_BROWSER_DEFERRED_GPU_COMMAND_SERVICE_H_ |
| 6 #define ANDROID_WEBVIEW_BROWSER_HARDWARE_RENDERER_H_ | 6 #define ANDROID_WEBVIEW_BROWSER_DEFERRED_GPU_COMMAND_SERVICE_H_ |
| 7 | 7 |
| 8 #include <queue> | 8 #include <queue> |
| 9 | 9 |
| 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" | 10 #include "base/lazy_instance.h" |
| 13 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 14 #include "base/threading/thread_local.h" | 12 #include "base/threading/thread_local.h" |
| 15 | 13 #include "gpu/command_buffer/service/in_process_command_buffer.h" |
| 16 struct AwDrawGLInfo; | |
| 17 | 14 |
| 18 namespace android_webview { | 15 namespace android_webview { |
| 19 | 16 |
| 20 class AwGLSurface; | |
| 21 class BrowserViewRendererClient; | |
| 22 | |
| 23 namespace internal { | |
| 24 class DeferredGpuCommandService; | |
| 25 } // namespace internal | |
| 26 | |
| 27 class HardwareRenderer { | |
| 28 public: | |
| 29 explicit HardwareRenderer(SharedRendererState* state); | |
| 30 ~HardwareRenderer(); | |
| 31 | |
| 32 bool DrawGL(AwDrawGLInfo* draw_info, DrawGLResult* result); | |
| 33 | |
| 34 private: | |
| 35 friend class internal::DeferredGpuCommandService; | |
| 36 | |
| 37 void SetCompositorMemoryPolicy(); | |
| 38 | |
| 39 SharedRendererState* shared_renderer_state_; | |
| 40 | |
| 41 typedef void* EGLContext; | |
| 42 EGLContext last_egl_context_; | |
| 43 | |
| 44 scoped_refptr<AwGLSurface> gl_surface_; | |
| 45 | |
| 46 GLViewRendererManager::Key renderer_manager_key_; | |
| 47 | |
| 48 DISALLOW_COPY_AND_ASSIGN(HardwareRenderer); | |
| 49 }; | |
| 50 | |
| 51 namespace internal { | |
| 52 | |
| 53 class ScopedAllowGL { | 17 class ScopedAllowGL { |
| 54 public: | 18 public: |
| 55 ScopedAllowGL(); | 19 ScopedAllowGL(); |
| 56 ~ScopedAllowGL(); | 20 ~ScopedAllowGL(); |
| 57 | 21 |
| 58 static bool IsAllowed(); | 22 static bool IsAllowed(); |
| 59 | 23 |
| 60 private: | 24 private: |
| 61 static base::LazyInstance<base::ThreadLocalBoolean> allow_gl; | 25 static base::LazyInstance<base::ThreadLocalBoolean> allow_gl; |
| 62 | 26 |
| 63 DISALLOW_COPY_AND_ASSIGN(ScopedAllowGL); | 27 DISALLOW_COPY_AND_ASSIGN(ScopedAllowGL); |
| 64 }; | 28 }; |
| 65 | 29 |
| 66 // TODO(boliu): Teach this class about RT. | 30 // TODO(boliu): Teach this class about RT. |
| 67 class DeferredGpuCommandService | 31 class DeferredGpuCommandService |
| 68 : public gpu::InProcessCommandBuffer::Service, | 32 : public gpu::InProcessCommandBuffer::Service, |
| 69 public base::RefCountedThreadSafe<DeferredGpuCommandService> { | 33 public base::RefCountedThreadSafe<DeferredGpuCommandService> { |
| 70 public: | 34 public: |
| 71 DeferredGpuCommandService(); | 35 static void SetInstance(); |
| 72 | 36 |
| 73 virtual void ScheduleTask(const base::Closure& task) OVERRIDE; | 37 virtual void ScheduleTask(const base::Closure& task) OVERRIDE; |
| 74 virtual void ScheduleIdleWork(const base::Closure& task) OVERRIDE; | 38 virtual void ScheduleIdleWork(const base::Closure& task) OVERRIDE; |
| 75 virtual bool UseVirtualizedGLContexts() OVERRIDE; | 39 virtual bool UseVirtualizedGLContexts() OVERRIDE; |
| 76 virtual scoped_refptr<gpu::gles2::ShaderTranslatorCache> | 40 virtual scoped_refptr<gpu::gles2::ShaderTranslatorCache> |
| 77 shader_translator_cache() OVERRIDE; | 41 shader_translator_cache() OVERRIDE; |
| 78 | 42 |
| 79 void RunTasks(); | 43 void RunTasks(); |
| 80 | 44 |
| 81 virtual void AddRef() const OVERRIDE; | 45 virtual void AddRef() const OVERRIDE; |
| 82 virtual void Release() const OVERRIDE; | 46 virtual void Release() const OVERRIDE; |
| 83 | 47 |
| 84 protected: | 48 protected: |
| 85 virtual ~DeferredGpuCommandService(); | 49 virtual ~DeferredGpuCommandService(); |
| 86 friend class base::RefCountedThreadSafe<DeferredGpuCommandService>; | 50 friend class base::RefCountedThreadSafe<DeferredGpuCommandService>; |
| 87 | 51 |
| 88 private: | 52 private: |
| 89 static void RequestProcessGLOnUIThread(); | 53 static void RequestProcessGLOnUIThread(); |
| 90 | 54 |
| 55 DeferredGpuCommandService(); |
| 56 |
| 91 base::Lock tasks_lock_; | 57 base::Lock tasks_lock_; |
| 92 std::queue<base::Closure> tasks_; | 58 std::queue<base::Closure> tasks_; |
| 93 | 59 |
| 94 scoped_refptr<gpu::gles2::ShaderTranslatorCache> shader_translator_cache_; | 60 scoped_refptr<gpu::gles2::ShaderTranslatorCache> shader_translator_cache_; |
| 95 DISALLOW_COPY_AND_ASSIGN(DeferredGpuCommandService); | 61 DISALLOW_COPY_AND_ASSIGN(DeferredGpuCommandService); |
| 96 }; | 62 }; |
| 97 | 63 |
| 98 } // namespace internal | |
| 99 | |
| 100 } // namespace android_webview | 64 } // namespace android_webview |
| 101 | 65 |
| 102 #endif // ANDROID_WEBVIEW_BROWSER_HARDWARE_RENDERER_H_ | 66 #endif // ANDROID_WEBVIEW_BROWSER_DEFERRED_GPU_COMMAND_SERVICE_H_ |
| OLD | NEW |