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 #include "android_webview/browser/deferred_gpu_command_service.h" | 5 #include "android_webview/browser/deferred_gpu_command_service.h" |
6 | 6 |
7 #include "android_webview/browser/gl_view_renderer_manager.h" | 7 #include "android_webview/browser/gl_view_renderer_manager.h" |
8 #include "android_webview/browser/shared_renderer_state.h" | 8 #include "android_webview/browser/shared_renderer_state.h" |
9 #include "content/public/browser/android/synchronous_compositor.h" | 9 #include "content/public/browser/android/synchronous_compositor.h" |
10 #include "gpu/command_buffer/service/shader_translator_cache.h" | 10 #include "gpu/command_buffer/service/shader_translator_cache.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 ScopedAllowGL::~ScopedAllowGL() { allow_gl.Get().Set(false); } | 34 ScopedAllowGL::~ScopedAllowGL() { allow_gl.Get().Set(false); } |
35 | 35 |
36 // static | 36 // static |
37 void DeferredGpuCommandService::SetInstance() { | 37 void DeferredGpuCommandService::SetInstance() { |
38 if (!g_service.Get()) { | 38 if (!g_service.Get()) { |
39 g_service.Get() = new DeferredGpuCommandService; | 39 g_service.Get() = new DeferredGpuCommandService; |
40 content::SynchronousCompositor::SetGpuService(g_service.Get()); | 40 content::SynchronousCompositor::SetGpuService(g_service.Get()); |
41 } | 41 } |
42 } | 42 } |
43 | 43 |
| 44 // static |
| 45 DeferredGpuCommandService* DeferredGpuCommandService::GetInstance() { |
| 46 DCHECK(g_service.Get().get()); |
| 47 return g_service.Get().get(); |
| 48 } |
| 49 |
44 DeferredGpuCommandService::DeferredGpuCommandService() {} | 50 DeferredGpuCommandService::DeferredGpuCommandService() {} |
45 | 51 |
46 DeferredGpuCommandService::~DeferredGpuCommandService() { | 52 DeferredGpuCommandService::~DeferredGpuCommandService() { |
47 base::AutoLock lock(tasks_lock_); | 53 base::AutoLock lock(tasks_lock_); |
48 DCHECK(tasks_.empty()); | 54 DCHECK(tasks_.empty()); |
49 } | 55 } |
50 | 56 |
51 // static | 57 // static |
52 void DeferredGpuCommandService::RequestProcessGLOnUIThread() { | 58 void DeferredGpuCommandService::RequestProcessGLOnUIThread() { |
53 SharedRendererState* renderer_state = | 59 SharedRendererState* renderer_state = |
54 GLViewRendererManager::GetInstance()->GetMostRecentlyDrawn(); | 60 GLViewRendererManager::GetInstance()->GetMostRecentlyDrawn(); |
55 if (!renderer_state) { | 61 if (!renderer_state) { |
56 LOG(ERROR) << "No hardware renderer. Deadlock likely"; | 62 LOG(ERROR) << "No hardware renderer. Deadlock likely"; |
57 return; | 63 return; |
58 } | 64 } |
59 renderer_state->ClientRequestDrawGL(); | 65 renderer_state->ClientRequestDrawGL(); |
60 } | 66 } |
61 | 67 |
62 // Called from different threads! | 68 // Called from different threads! |
63 void DeferredGpuCommandService::ScheduleTask(const base::Closure& task) { | 69 void DeferredGpuCommandService::ScheduleTask(const base::Closure& task) { |
64 { | 70 { |
65 base::AutoLock lock(tasks_lock_); | 71 base::AutoLock lock(tasks_lock_); |
66 tasks_.push(task); | 72 tasks_.push(task); |
67 } | 73 } |
68 if (ScopedAllowGL::IsAllowed()) { | 74 if (ScopedAllowGL::IsAllowed()) { |
69 RunTasks(); | 75 RunTasks(); |
70 } else { | 76 } else { |
| 77 // TODO(boliu): Improve this to avoid PostTask storm. |
71 RequestProcessGLOnUIThread(); | 78 RequestProcessGLOnUIThread(); |
72 } | 79 } |
73 } | 80 } |
74 | 81 |
75 void DeferredGpuCommandService::ScheduleIdleWork( | 82 void DeferredGpuCommandService::ScheduleIdleWork( |
76 const base::Closure& callback) { | 83 const base::Closure& callback) { |
77 // TODO(sievers): Should this do anything? | 84 // TODO(sievers): Should this do anything? |
78 } | 85 } |
79 | 86 |
80 bool DeferredGpuCommandService::UseVirtualizedGLContexts() { return true; } | 87 bool DeferredGpuCommandService::UseVirtualizedGLContexts() { return true; } |
(...skipping 29 matching lines...) Expand all Loading... |
110 | 117 |
111 void DeferredGpuCommandService::AddRef() const { | 118 void DeferredGpuCommandService::AddRef() const { |
112 base::RefCountedThreadSafe<DeferredGpuCommandService>::AddRef(); | 119 base::RefCountedThreadSafe<DeferredGpuCommandService>::AddRef(); |
113 } | 120 } |
114 | 121 |
115 void DeferredGpuCommandService::Release() const { | 122 void DeferredGpuCommandService::Release() const { |
116 base::RefCountedThreadSafe<DeferredGpuCommandService>::Release(); | 123 base::RefCountedThreadSafe<DeferredGpuCommandService>::Release(); |
117 } | 124 } |
118 | 125 |
119 } // namespace android_webview | 126 } // namespace android_webview |
OLD | NEW |