Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/in_process_view_renderer.h" | 5 #include "android_webview/browser/in_process_view_renderer.h" |
| 6 | 6 |
| 7 #include <android/bitmap.h> | 7 #include <android/bitmap.h> |
| 8 | 8 |
| 9 #include "android_webview/browser/scoped_app_gl_state_restore.h" | 9 #include "android_webview/browser/scoped_app_gl_state_restore.h" |
| 10 #include "android_webview/public/browser/draw_gl.h" | 10 #include "android_webview/public/browser/draw_gl.h" |
| 11 #include "android_webview/public/browser/draw_sw.h" | 11 #include "android_webview/public/browser/draw_sw.h" |
| 12 #include "base/android/jni_android.h" | 12 #include "base/android/jni_android.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/debug/trace_event.h" | 14 #include "base/debug/trace_event.h" |
| 15 #include "base/lazy_instance.h" | |
| 15 #include "base/logging.h" | 16 #include "base/logging.h" |
| 16 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 18 #include "base/threading/thread_local.h" | |
| 17 #include "content/public/browser/android/synchronous_compositor.h" | 19 #include "content/public/browser/android/synchronous_compositor.h" |
| 18 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 21 #include "gpu/command_buffer/service/in_process_command_buffer.h" | |
| 19 #include "skia/ext/refptr.h" | 22 #include "skia/ext/refptr.h" |
| 20 #include "third_party/skia/include/core/SkBitmap.h" | 23 #include "third_party/skia/include/core/SkBitmap.h" |
| 21 #include "third_party/skia/include/core/SkCanvas.h" | 24 #include "third_party/skia/include/core/SkCanvas.h" |
| 22 #include "third_party/skia/include/core/SkDevice.h" | 25 #include "third_party/skia/include/core/SkDevice.h" |
| 23 #include "third_party/skia/include/core/SkGraphics.h" | 26 #include "third_party/skia/include/core/SkGraphics.h" |
| 24 #include "third_party/skia/include/core/SkPicture.h" | 27 #include "third_party/skia/include/core/SkPicture.h" |
| 25 #include "ui/gfx/skia_util.h" | 28 #include "ui/gfx/skia_util.h" |
| 26 #include "ui/gfx/transform.h" | 29 #include "ui/gfx/transform.h" |
| 27 #include "ui/gfx/vector2d_conversions.h" | 30 #include "ui/gfx/vector2d_conversions.h" |
| 28 #include "ui/gfx/vector2d_f.h" | 31 #include "ui/gfx/vector2d_f.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 | 120 |
| 118 // Tells if the Skia library versions in Android and Chromium are compatible. | 121 // Tells if the Skia library versions in Android and Chromium are compatible. |
| 119 // If they are then it's possible to pass Skia objects like SkPictures to the | 122 // If they are then it's possible to pass Skia objects like SkPictures to the |
| 120 // Android glue layer via the SW rendering functions. | 123 // Android glue layer via the SW rendering functions. |
| 121 // If they are not, then additional copies and rasterizations are required | 124 // If they are not, then additional copies and rasterizations are required |
| 122 // as a fallback mechanism, which will have an important performance impact. | 125 // as a fallback mechanism, which will have an important performance impact. |
| 123 bool g_is_skia_version_compatible = false; | 126 bool g_is_skia_version_compatible = false; |
| 124 | 127 |
| 125 const int64 kFallbackTickTimeoutInMilliseconds = 500; | 128 const int64 kFallbackTickTimeoutInMilliseconds = 500; |
| 126 | 129 |
| 130 base::LazyInstance<ThreadLocalBoolean>::Leaky tls_gl_allowed = | |
|
joth
2013/07/27 02:24:32
does this need to be TLS? there's (currently) a li
no sievers
2013/07/30 00:55:34
Done.
| |
| 131 LAZY_INSTANCE_INITIALIZER; | |
| 132 | |
| 133 class ScopedAllowGL { | |
| 134 public: | |
| 135 ScopedAllowGL(); | |
| 136 ~ScopedAllowGL(); | |
| 137 }; | |
| 138 | |
| 139 ScopedAllowGL::ScopedAllowGL() { | |
| 140 DCHECK(!tls_gl_allowed.Get().Get()); | |
| 141 tls_gl_allowed.Get().Set(true); | |
| 142 } | |
| 143 | |
| 144 ScopedAllowGL::~ScopedAllowGL() { | |
| 145 tls_gl_allowed.Get().Set(false); | |
| 146 } | |
| 147 | |
| 127 } // namespace | 148 } // namespace |
| 128 | 149 |
| 150 // Called from different threads! | |
| 151 static void ScheduleGpuWork() { | |
| 152 if (tls_gl_allowed.Get().Get()) { | |
| 153 gpu::InProcessCommandBuffer::ProcessGpuWorkOnCurrentThread(); | |
| 154 } else { | |
| 155 // TODO: We need to request a callback with a GL context current here. | |
|
joth
2013/07/27 02:24:32
this is pretty important right - is there a bug fo
no sievers
2013/07/30 00:55:34
I think Bo might already be working on a patch for
| |
| 156 } | |
| 157 } | |
| 158 | |
| 129 // static | 159 // static |
| 130 void BrowserViewRenderer::SetAwDrawSWFunctionTable( | 160 void BrowserViewRenderer::SetAwDrawSWFunctionTable( |
| 131 AwDrawSWFunctionTable* table) { | 161 AwDrawSWFunctionTable* table) { |
| 132 g_sw_draw_functions = table; | 162 g_sw_draw_functions = table; |
| 133 g_is_skia_version_compatible = | 163 g_is_skia_version_compatible = |
| 134 g_sw_draw_functions->is_skia_version_compatible(&SkGraphics::GetVersion); | 164 g_sw_draw_functions->is_skia_version_compatible(&SkGraphics::GetVersion); |
| 135 LOG_IF(WARNING, !g_is_skia_version_compatible) | 165 LOG_IF(WARNING, !g_is_skia_version_compatible) |
| 136 << "Skia versions are not compatible, rendering performance will suffer."; | 166 << "Skia versions are not compatible, rendering performance will suffer."; |
| 167 | |
| 168 gpu::InProcessCommandBuffer::SetScheduleCallback( | |
| 169 base::Bind(&ScheduleGpuWork)); | |
| 137 } | 170 } |
| 138 | 171 |
| 139 // static | 172 // static |
| 140 AwDrawSWFunctionTable* BrowserViewRenderer::GetAwDrawSWFunctionTable() { | 173 AwDrawSWFunctionTable* BrowserViewRenderer::GetAwDrawSWFunctionTable() { |
| 141 return g_sw_draw_functions; | 174 return g_sw_draw_functions; |
| 142 } | 175 } |
| 143 | 176 |
| 144 // static | 177 // static |
| 145 bool BrowserViewRenderer::IsSkiaVersionCompatible() { | 178 bool BrowserViewRenderer::IsSkiaVersionCompatible() { |
| 146 DCHECK(g_sw_draw_functions); | 179 DCHECK(g_sw_draw_functions); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 // We need to watch if the current Android context has changed and enforce | 253 // We need to watch if the current Android context has changed and enforce |
| 221 // a clean-up in the compositor. | 254 // a clean-up in the compositor. |
| 222 EGLContext current_context = eglGetCurrentContext(); | 255 EGLContext current_context = eglGetCurrentContext(); |
| 223 if (!current_context) { | 256 if (!current_context) { |
| 224 TRACE_EVENT_INSTANT0( | 257 TRACE_EVENT_INSTANT0( |
| 225 "android_webview", "EarlyOut_NullEGLContext", TRACE_EVENT_SCOPE_THREAD); | 258 "android_webview", "EarlyOut_NullEGLContext", TRACE_EVENT_SCOPE_THREAD); |
| 226 return; | 259 return; |
| 227 } | 260 } |
| 228 | 261 |
| 229 ScopedAppGLStateRestore state_restore(ScopedAppGLStateRestore::MODE_DRAW); | 262 ScopedAppGLStateRestore state_restore(ScopedAppGLStateRestore::MODE_DRAW); |
| 263 gpu::InProcessCommandBuffer::ProcessGpuWorkOnCurrentThread(); | |
| 264 ScopedAllowGL allow_gl; | |
| 230 | 265 |
| 231 if (attached_to_window_ && compositor_ && !hardware_initialized_) { | 266 if (attached_to_window_ && compositor_ && !hardware_initialized_) { |
| 232 TRACE_EVENT0("android_webview", "InitializeHwDraw"); | 267 TRACE_EVENT0("android_webview", "InitializeHwDraw"); |
| 233 hardware_failed_ = !compositor_->InitializeHwDraw(); | 268 hardware_failed_ = !compositor_->InitializeHwDraw(); |
| 234 hardware_initialized_ = true; | 269 hardware_initialized_ = true; |
| 235 last_egl_context_ = current_context; | 270 last_egl_context_ = current_context; |
| 236 | 271 |
| 237 if (hardware_failed_) | 272 if (hardware_failed_) |
| 238 return; | 273 return; |
| 239 } | 274 } |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 450 | 485 |
| 451 void InProcessViewRenderer::OnDetachedFromWindow() { | 486 void InProcessViewRenderer::OnDetachedFromWindow() { |
| 452 TRACE_EVENT0("android_webview", | 487 TRACE_EVENT0("android_webview", |
| 453 "InProcessViewRenderer::OnDetachedFromWindow"); | 488 "InProcessViewRenderer::OnDetachedFromWindow"); |
| 454 | 489 |
| 455 if (hardware_initialized_) { | 490 if (hardware_initialized_) { |
| 456 DCHECK(compositor_); | 491 DCHECK(compositor_); |
| 457 | 492 |
| 458 ScopedAppGLStateRestore state_restore( | 493 ScopedAppGLStateRestore state_restore( |
| 459 ScopedAppGLStateRestore::MODE_DETACH_FROM_WINDOW); | 494 ScopedAppGLStateRestore::MODE_DETACH_FROM_WINDOW); |
| 495 gpu::InProcessCommandBuffer::ProcessGpuWorkOnCurrentThread(); | |
| 496 ScopedAllowGL allow_gl; | |
| 460 compositor_->ReleaseHwDraw(); | 497 compositor_->ReleaseHwDraw(); |
| 461 hardware_initialized_ = false; | 498 hardware_initialized_ = false; |
| 462 } | 499 } |
| 463 | 500 |
| 464 attached_to_window_ = false; | 501 attached_to_window_ = false; |
| 465 } | 502 } |
| 466 | 503 |
| 467 bool InProcessViewRenderer::IsAttachedToWindow() { | 504 bool InProcessViewRenderer::IsAttachedToWindow() { |
| 468 return attached_to_window_; | 505 return attached_to_window_; |
| 469 } | 506 } |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 665 base::StringAppendF(&str, | 702 base::StringAppendF(&str, |
| 666 "surface width height: [%d %d] ", | 703 "surface width height: [%d %d] ", |
| 667 draw_info->width, | 704 draw_info->width, |
| 668 draw_info->height); | 705 draw_info->height); |
| 669 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer); | 706 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer); |
| 670 } | 707 } |
| 671 return str; | 708 return str; |
| 672 } | 709 } |
| 673 | 710 |
| 674 } // namespace android_webview | 711 } // namespace android_webview |
| OLD | NEW |