Chromium Code Reviews| 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/hardware_renderer.h" | 5 #include "android_webview/browser/hardware_renderer.h" |
| 6 | 6 |
| 7 #include "android_webview/browser/aw_gl_surface.h" | 7 #include "android_webview/browser/aw_gl_surface.h" |
| 8 #include "android_webview/browser/browser_view_renderer_client.h" | 8 #include "android_webview/browser/browser_view_renderer_client.h" |
| 9 #include "android_webview/browser/gl_view_renderer_manager.h" | 9 #include "android_webview/browser/gl_view_renderer_manager.h" |
| 10 #include "android_webview/browser/gpu_memory_manager.h" | |
| 10 #include "android_webview/browser/scoped_app_gl_state_restore.h" | 11 #include "android_webview/browser/scoped_app_gl_state_restore.h" |
| 11 #include "android_webview/public/browser/draw_gl.h" | 12 #include "android_webview/public/browser/draw_gl.h" |
| 12 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 13 #include "base/debug/trace_event.h" | 14 #include "base/debug/trace_event.h" |
| 14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/common/content_switches.h" | 17 #include "content/public/common/content_switches.h" |
| 17 #include "gpu/command_buffer/service/shader_translator_cache.h" | 18 #include "gpu/command_buffer/service/shader_translator_cache.h" |
| 18 #include "ui/gfx/transform.h" | 19 #include "ui/gfx/transform.h" |
| 19 | 20 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 33 g_service = LAZY_INSTANCE_INITIALIZER; | 34 g_service = LAZY_INSTANCE_INITIALIZER; |
| 34 | 35 |
| 35 } // namespace | 36 } // namespace |
| 36 | 37 |
| 37 HardwareRenderer::HardwareRenderer(SharedRendererState* state) | 38 HardwareRenderer::HardwareRenderer(SharedRendererState* state) |
| 38 : shared_renderer_state_(state), | 39 : shared_renderer_state_(state), |
| 39 last_egl_context_(eglGetCurrentContext()), | 40 last_egl_context_(eglGetCurrentContext()), |
| 40 manager_key_(GLViewRendererManager::GetInstance()->PushBack( | 41 manager_key_(GLViewRendererManager::GetInstance()->PushBack( |
| 41 shared_renderer_state_)) { | 42 shared_renderer_state_)) { |
| 42 DCHECK(last_egl_context_); | 43 DCHECK(last_egl_context_); |
| 44 | |
| 43 if (!g_service.Get()) { | 45 if (!g_service.Get()) { |
| 44 g_service.Get() = new internal::DeferredGpuCommandService; | 46 g_service.Get() = new internal::DeferredGpuCommandService; |
| 45 content::SynchronousCompositor::SetGpuService(g_service.Get()); | 47 content::SynchronousCompositor::SetGpuService(g_service.Get()); |
| 46 } | 48 } |
| 47 | 49 |
| 48 ScopedAppGLStateRestore state_restore( | 50 ScopedAppGLStateRestore state_restore( |
| 49 ScopedAppGLStateRestore::MODE_RESOURCE_MANAGEMENT); | 51 ScopedAppGLStateRestore::MODE_RESOURCE_MANAGEMENT); |
| 50 internal::ScopedAllowGL allow_gl; | 52 internal::ScopedAllowGL allow_gl; |
| 51 | 53 |
| 52 gl_surface_ = new AwGLSurface; | 54 gl_surface_ = new AwGLSurface; |
| 53 bool success = | 55 bool success = |
| 54 shared_renderer_state_->GetCompositor()-> | 56 shared_renderer_state_->GetCompositor()-> |
| 55 InitializeHwDraw(gl_surface_); | 57 InitializeHwDraw(gl_surface_); |
| 56 DCHECK(success); | 58 DCHECK(success); |
| 57 } | 59 } |
| 58 | 60 |
| 59 HardwareRenderer::~HardwareRenderer() { | 61 HardwareRenderer::~HardwareRenderer() { |
| 60 GLViewRendererManager* mru = GLViewRendererManager::GetInstance(); | 62 GLViewRendererManager* mru = GLViewRendererManager::GetInstance(); |
| 61 mru->Remove(manager_key_); | 63 mru->Remove(manager_key_); |
| 62 | 64 |
| 65 content::SynchronousCompositorMemoryPolicy zero_policy; | |
| 66 SetMemoryPolicy(zero_policy); | |
| 67 | |
| 63 ScopedAppGLStateRestore state_restore( | 68 ScopedAppGLStateRestore state_restore( |
| 64 ScopedAppGLStateRestore::MODE_RESOURCE_MANAGEMENT); | 69 ScopedAppGLStateRestore::MODE_RESOURCE_MANAGEMENT); |
| 65 internal::ScopedAllowGL allow_gl; | 70 internal::ScopedAllowGL allow_gl; |
| 66 | 71 |
| 67 shared_renderer_state_->GetCompositor()->ReleaseHwDraw(); | 72 shared_renderer_state_->GetCompositor()->ReleaseHwDraw(); |
| 68 gl_surface_ = NULL; | 73 gl_surface_ = NULL; |
| 69 } | 74 } |
| 70 | 75 |
| 71 bool HardwareRenderer::DrawGL(AwDrawGLInfo* draw_info, DrawGLResult* result) { | 76 bool HardwareRenderer::DrawGL(AwDrawGLInfo* draw_info, DrawGLResult* result) { |
| 72 TRACE_EVENT0("android_webview", "HardwareRenderer::DrawGL"); | 77 TRACE_EVENT0("android_webview", "HardwareRenderer::DrawGL"); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 | 156 |
| 152 if (!eglGetCurrentContext()) { | 157 if (!eglGetCurrentContext()) { |
| 153 NOTREACHED(); | 158 NOTREACHED(); |
| 154 return false; | 159 return false; |
| 155 } | 160 } |
| 156 | 161 |
| 157 DCHECK_EQ(last_egl_context_, eglGetCurrentContext()); | 162 DCHECK_EQ(last_egl_context_, eglGetCurrentContext()); |
| 158 | 163 |
| 159 // Just set the memory limit to 0 and drop all tiles. This will be reset to | 164 // Just set the memory limit to 0 and drop all tiles. This will be reset to |
| 160 // normal levels in the next DrawGL call. | 165 // normal levels in the next DrawGL call. |
| 161 content::SynchronousCompositorMemoryPolicy policy; | 166 content::SynchronousCompositorMemoryPolicy current_policy, zero_policy; |
| 162 policy.bytes_limit = 0; | 167 current_policy = GetMemoryPolicy(); |
| 163 policy.num_resources_limit = 0; | 168 if (current_policy == zero_policy) |
| 164 if (memory_policy_ == policy) | |
| 165 return false; | 169 return false; |
| 166 | 170 |
| 167 TRACE_EVENT0("android_webview", "HardwareRenderer::TrimMemory"); | 171 TRACE_EVENT0("android_webview", "HardwareRenderer::TrimMemory"); |
| 168 ScopedAppGLStateRestore state_restore( | 172 ScopedAppGLStateRestore state_restore( |
| 169 ScopedAppGLStateRestore::MODE_RESOURCE_MANAGEMENT); | 173 ScopedAppGLStateRestore::MODE_RESOURCE_MANAGEMENT); |
| 170 internal::ScopedAllowGL allow_gl; | 174 internal::ScopedAllowGL allow_gl; |
| 171 | 175 |
| 172 SetMemoryPolicy(policy); | 176 SetMemoryPolicy(zero_policy); |
| 173 return true; | 177 return true; |
| 174 } | 178 } |
| 175 | 179 |
| 176 void HardwareRenderer::SetMemoryPolicy( | 180 void HardwareRenderer::SetMemoryPolicy( |
| 177 content::SynchronousCompositorMemoryPolicy& new_policy) { | 181 content::SynchronousCompositorMemoryPolicy& new_policy) { |
| 178 if (memory_policy_ == new_policy) | 182 content::SynchronousCompositorMemoryPolicy current_policy; |
| 183 current_policy = GetMemoryPolicy(); | |
| 184 | |
| 185 if (current_policy == new_policy) | |
| 179 return; | 186 return; |
| 180 | 187 |
| 181 memory_policy_ = new_policy; | 188 GpuMemoryManager::GetInstance()->UpdateResources( |
| 189 current_policy, new_policy, manager_key_); | |
|
boliu
2014/04/08 03:06:45
Too aggressive and not stable? And I think it does
| |
| 190 | |
| 182 shared_renderer_state_->GetCompositor()-> | 191 shared_renderer_state_->GetCompositor()-> |
| 183 SetMemoryPolicy(memory_policy_); | 192 SetMemoryPolicy(new_policy); |
| 193 } | |
| 194 | |
| 195 const content::SynchronousCompositorMemoryPolicy& | |
| 196 HardwareRenderer::GetMemoryPolicy() const { | |
| 197 return shared_renderer_state_->GetCompositor()->GetMemoryPolicy(); | |
| 184 } | 198 } |
| 185 | 199 |
| 186 // static | 200 // static |
| 187 void HardwareRenderer::CalculateTileMemoryPolicy() { | 201 void HardwareRenderer::CalculateTileMemoryPolicy() { |
| 188 CommandLine* cl = CommandLine::ForCurrentProcess(); | 202 CommandLine* cl = CommandLine::ForCurrentProcess(); |
| 189 | 203 |
| 190 const char kDefaultTileSize[] = "384"; | 204 const char kDefaultTileSize[] = "384"; |
| 191 if (!cl->HasSwitch(switches::kDefaultTileWidth)) | 205 if (!cl->HasSwitch(switches::kDefaultTileWidth)) |
| 192 cl->AppendSwitchASCII(switches::kDefaultTileWidth, kDefaultTileSize); | 206 cl->AppendSwitchASCII(switches::kDefaultTileWidth, kDefaultTileSize); |
| 193 | 207 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 286 base::RefCountedThreadSafe<DeferredGpuCommandService>::AddRef(); | 300 base::RefCountedThreadSafe<DeferredGpuCommandService>::AddRef(); |
| 287 } | 301 } |
| 288 | 302 |
| 289 void DeferredGpuCommandService::Release() const { | 303 void DeferredGpuCommandService::Release() const { |
| 290 base::RefCountedThreadSafe<DeferredGpuCommandService>::Release(); | 304 base::RefCountedThreadSafe<DeferredGpuCommandService>::Release(); |
| 291 } | 305 } |
| 292 | 306 |
| 293 } // namespace internal | 307 } // namespace internal |
| 294 | 308 |
| 295 } // namespace android_webview | 309 } // namespace android_webview |
| OLD | NEW |