Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: android_webview/browser/in_process_view_renderer.cc

Issue 19522006: GLInProcessContext: support async flushes and dedicated GPU thread (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 // Called from different threads!
134 static void ScheduleGpuWork() {
135 if (tls_gl_allowed.Get().Get())
136 gpu::InProcessCommandBuffer::ProcessGpuWorkOnCurrentThread();
piman 2013/07/23 01:57:14 Should this DCHECK if GL is allowed? I'm worried t
no sievers 2013/07/25 00:41:23 I put a TODO. I'll have to figure this out with Bo
137 }
138
139 class ScopedAllowGL {
140 public:
141 ScopedAllowGL();
142 ~ScopedAllowGL();
143
piman 2013/07/23 01:57:14 nit: no need for blank line.
no sievers 2013/07/25 00:41:23 Done.
144 };
145
146 ScopedAllowGL::ScopedAllowGL() {
147 DCHECK(!tls_gl_allowed.Get().Get());
148 tls_gl_allowed.Get().Set(true);
149 }
150
151 ScopedAllowGL::~ScopedAllowGL() {
152 tls_gl_allowed.Get().Set(false);
153 }
154
127 } // namespace 155 } // namespace
128 156
129 // static 157 // static
130 void BrowserViewRenderer::SetAwDrawSWFunctionTable( 158 void BrowserViewRenderer::SetAwDrawSWFunctionTable(
131 AwDrawSWFunctionTable* table) { 159 AwDrawSWFunctionTable* table) {
132 g_sw_draw_functions = table; 160 g_sw_draw_functions = table;
133 g_is_skia_version_compatible = 161 g_is_skia_version_compatible =
134 g_sw_draw_functions->is_skia_version_compatible(&SkGraphics::GetVersion); 162 g_sw_draw_functions->is_skia_version_compatible(&SkGraphics::GetVersion);
135 LOG_IF(WARNING, !g_is_skia_version_compatible) 163 LOG_IF(WARNING, !g_is_skia_version_compatible)
136 << "Skia versions are not compatible, rendering performance will suffer."; 164 << "Skia versions are not compatible, rendering performance will suffer.";
165
166 // TODO: There is probably a better place to do this.
167 gpu::InProcessCommandBuffer::SetScheduleCallback(
168 base::Bind(&ScheduleGpuWork));
137 } 169 }
138 170
139 // static 171 // static
140 AwDrawSWFunctionTable* BrowserViewRenderer::GetAwDrawSWFunctionTable() { 172 AwDrawSWFunctionTable* BrowserViewRenderer::GetAwDrawSWFunctionTable() {
141 return g_sw_draw_functions; 173 return g_sw_draw_functions;
142 } 174 }
143 175
144 // static 176 // static
145 bool BrowserViewRenderer::IsSkiaVersionCompatible() { 177 bool BrowserViewRenderer::IsSkiaVersionCompatible() {
146 DCHECK(g_sw_draw_functions); 178 DCHECK(g_sw_draw_functions);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 // We need to watch if the current Android context has changed and enforce 252 // We need to watch if the current Android context has changed and enforce
221 // a clean-up in the compositor. 253 // a clean-up in the compositor.
222 EGLContext current_context = eglGetCurrentContext(); 254 EGLContext current_context = eglGetCurrentContext();
223 if (!current_context) { 255 if (!current_context) {
224 TRACE_EVENT_INSTANT0( 256 TRACE_EVENT_INSTANT0(
225 "android_webview", "EarlyOut_NullEGLContext", TRACE_EVENT_SCOPE_THREAD); 257 "android_webview", "EarlyOut_NullEGLContext", TRACE_EVENT_SCOPE_THREAD);
226 return; 258 return;
227 } 259 }
228 260
229 ScopedAppGLStateRestore state_restore(ScopedAppGLStateRestore::MODE_DRAW); 261 ScopedAppGLStateRestore state_restore(ScopedAppGLStateRestore::MODE_DRAW);
262 gpu::InProcessCommandBuffer::ProcessGpuWorkOnCurrentThread();
263 ScopedAllowGL allow_gl;
230 264
231 if (attached_to_window_ && compositor_ && !hardware_initialized_) { 265 if (attached_to_window_ && compositor_ && !hardware_initialized_) {
232 TRACE_EVENT0("android_webview", "InitializeHwDraw"); 266 TRACE_EVENT0("android_webview", "InitializeHwDraw");
233 hardware_failed_ = !compositor_->InitializeHwDraw(); 267 hardware_failed_ = !compositor_->InitializeHwDraw();
234 hardware_initialized_ = true; 268 hardware_initialized_ = true;
235 last_egl_context_ = current_context; 269 last_egl_context_ = current_context;
236 270
237 if (hardware_failed_) 271 if (hardware_failed_)
238 return; 272 return;
239 } 273 }
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 484
451 void InProcessViewRenderer::OnDetachedFromWindow() { 485 void InProcessViewRenderer::OnDetachedFromWindow() {
452 TRACE_EVENT0("android_webview", 486 TRACE_EVENT0("android_webview",
453 "InProcessViewRenderer::OnDetachedFromWindow"); 487 "InProcessViewRenderer::OnDetachedFromWindow");
454 488
455 if (hardware_initialized_) { 489 if (hardware_initialized_) {
456 DCHECK(compositor_); 490 DCHECK(compositor_);
457 491
458 ScopedAppGLStateRestore state_restore( 492 ScopedAppGLStateRestore state_restore(
459 ScopedAppGLStateRestore::MODE_DETACH_FROM_WINDOW); 493 ScopedAppGLStateRestore::MODE_DETACH_FROM_WINDOW);
494 gpu::InProcessCommandBuffer::ProcessGpuWorkOnCurrentThread();
495 ScopedAllowGL allow_gl;
460 compositor_->ReleaseHwDraw(); 496 compositor_->ReleaseHwDraw();
461 hardware_initialized_ = false; 497 hardware_initialized_ = false;
462 } 498 }
463 499
464 attached_to_window_ = false; 500 attached_to_window_ = false;
465 } 501 }
466 502
467 bool InProcessViewRenderer::IsAttachedToWindow() { 503 bool InProcessViewRenderer::IsAttachedToWindow() {
468 return attached_to_window_; 504 return attached_to_window_;
469 } 505 }
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 base::StringAppendF(&str, 701 base::StringAppendF(&str,
666 "surface width height: [%d %d] ", 702 "surface width height: [%d %d] ",
667 draw_info->width, 703 draw_info->width,
668 draw_info->height); 704 draw_info->height);
669 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer); 705 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer);
670 } 706 }
671 return str; 707 return str;
672 } 708 }
673 709
674 } // namespace android_webview 710 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698