| 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 LazyInstance<ThreadLocalBoolean>::Leaky tls_gl_allowed = |
| 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. |
| 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."; |
| 137 } | 167 } |
| 138 | 168 |
| (...skipping 81 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 | 250 // We need to watch if the current Android context has changed and enforce |
| 221 // a clean-up in the compositor. | 251 // a clean-up in the compositor. |
| 222 EGLContext current_context = eglGetCurrentContext(); | 252 EGLContext current_context = eglGetCurrentContext(); |
| 223 if (!current_context) { | 253 if (!current_context) { |
| 224 TRACE_EVENT_INSTANT0( | 254 TRACE_EVENT_INSTANT0( |
| 225 "android_webview", "EarlyOut_NullEGLContext", TRACE_EVENT_SCOPE_THREAD); | 255 "android_webview", "EarlyOut_NullEGLContext", TRACE_EVENT_SCOPE_THREAD); |
| 226 return; | 256 return; |
| 227 } | 257 } |
| 228 | 258 |
| 229 ScopedAppGLStateRestore state_restore(ScopedAppGLStateRestore::MODE_DRAW); | 259 ScopedAppGLStateRestore state_restore(ScopedAppGLStateRestore::MODE_DRAW); |
| 260 gpu::InProcessCommandBuffer::ProcessGpuWorkOnCurrentThread(); |
| 261 ScopedAllowGL allow_gl; |
| 230 | 262 |
| 231 if (attached_to_window_ && compositor_ && !hardware_initialized_) { | 263 if (attached_to_window_ && compositor_ && !hardware_initialized_) { |
| 232 TRACE_EVENT0("android_webview", "InitializeHwDraw"); | 264 TRACE_EVENT0("android_webview", "InitializeHwDraw"); |
| 233 hardware_failed_ = !compositor_->InitializeHwDraw(); | 265 hardware_failed_ = !compositor_->InitializeHwDraw(); |
| 234 hardware_initialized_ = true; | 266 hardware_initialized_ = true; |
| 235 last_egl_context_ = current_context; | 267 last_egl_context_ = current_context; |
| 236 | 268 |
| 237 if (hardware_failed_) | 269 if (hardware_failed_) |
| 238 return; | 270 return; |
| 239 } | 271 } |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 | 482 |
| 451 void InProcessViewRenderer::OnDetachedFromWindow() { | 483 void InProcessViewRenderer::OnDetachedFromWindow() { |
| 452 TRACE_EVENT0("android_webview", | 484 TRACE_EVENT0("android_webview", |
| 453 "InProcessViewRenderer::OnDetachedFromWindow"); | 485 "InProcessViewRenderer::OnDetachedFromWindow"); |
| 454 | 486 |
| 455 if (hardware_initialized_) { | 487 if (hardware_initialized_) { |
| 456 DCHECK(compositor_); | 488 DCHECK(compositor_); |
| 457 | 489 |
| 458 ScopedAppGLStateRestore state_restore( | 490 ScopedAppGLStateRestore state_restore( |
| 459 ScopedAppGLStateRestore::MODE_DETACH_FROM_WINDOW); | 491 ScopedAppGLStateRestore::MODE_DETACH_FROM_WINDOW); |
| 492 gpu::InProcessCommandBuffer::ProcessGpuWorkOnCurrentThread(); |
| 493 ScopedAllowGL allow_gl; |
| 460 compositor_->ReleaseHwDraw(); | 494 compositor_->ReleaseHwDraw(); |
| 461 hardware_initialized_ = false; | 495 hardware_initialized_ = false; |
| 462 } | 496 } |
| 463 | 497 |
| 464 attached_to_window_ = false; | 498 attached_to_window_ = false; |
| 465 } | 499 } |
| 466 | 500 |
| 467 bool InProcessViewRenderer::IsAttachedToWindow() { | 501 bool InProcessViewRenderer::IsAttachedToWindow() { |
| 468 return attached_to_window_; | 502 return attached_to_window_; |
| 469 } | 503 } |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 base::StringAppendF(&str, | 699 base::StringAppendF(&str, |
| 666 "surface width height: [%d %d] ", | 700 "surface width height: [%d %d] ", |
| 667 draw_info->width, | 701 draw_info->width, |
| 668 draw_info->height); | 702 draw_info->height); |
| 669 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer); | 703 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer); |
| 670 } | 704 } |
| 671 return str; | 705 return str; |
| 672 } | 706 } |
| 673 | 707 |
| 674 } // namespace android_webview | 708 } // namespace android_webview |
| OLD | NEW |