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

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: remove tls Created 7 years, 4 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/non_thread_safe.h"
17 #include "content/public/browser/android/synchronous_compositor.h" 19 #include "content/public/browser/android/synchronous_compositor.h"
20 #include "content/public/browser/browser_thread.h"
18 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
22 #include "gpu/command_buffer/service/in_process_command_buffer.h"
19 #include "skia/ext/refptr.h" 23 #include "skia/ext/refptr.h"
20 #include "third_party/skia/include/core/SkBitmap.h" 24 #include "third_party/skia/include/core/SkBitmap.h"
21 #include "third_party/skia/include/core/SkCanvas.h" 25 #include "third_party/skia/include/core/SkCanvas.h"
22 #include "third_party/skia/include/core/SkDevice.h" 26 #include "third_party/skia/include/core/SkDevice.h"
23 #include "third_party/skia/include/core/SkGraphics.h" 27 #include "third_party/skia/include/core/SkGraphics.h"
24 #include "third_party/skia/include/core/SkPicture.h" 28 #include "third_party/skia/include/core/SkPicture.h"
25 #include "ui/gfx/skia_util.h" 29 #include "ui/gfx/skia_util.h"
26 #include "ui/gfx/transform.h" 30 #include "ui/gfx/transform.h"
27 #include "ui/gfx/vector2d_conversions.h" 31 #include "ui/gfx/vector2d_conversions.h"
28 #include "ui/gfx/vector2d_f.h" 32 #include "ui/gfx/vector2d_f.h"
29 33
30 using base::android::AttachCurrentThread; 34 using base::android::AttachCurrentThread;
31 using base::android::JavaRef; 35 using base::android::JavaRef;
32 using base::android::ScopedJavaLocalRef; 36 using base::android::ScopedJavaLocalRef;
37 using content::BrowserThread;
33 38
34 namespace android_webview { 39 namespace android_webview {
35 40
36 namespace { 41 namespace {
37 42
38 43
39 const void* kUserDataKey = &kUserDataKey; 44 const void* kUserDataKey = &kUserDataKey;
40 45
41 class UserData : public content::WebContents::Data { 46 class UserData : public content::WebContents::Data {
42 public: 47 public:
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 122
118 // Tells if the Skia library versions in Android and Chromium are compatible. 123 // 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 124 // If they are then it's possible to pass Skia objects like SkPictures to the
120 // Android glue layer via the SW rendering functions. 125 // Android glue layer via the SW rendering functions.
121 // If they are not, then additional copies and rasterizations are required 126 // If they are not, then additional copies and rasterizations are required
122 // as a fallback mechanism, which will have an important performance impact. 127 // as a fallback mechanism, which will have an important performance impact.
123 bool g_is_skia_version_compatible = false; 128 bool g_is_skia_version_compatible = false;
124 129
125 const int64 kFallbackTickTimeoutInMilliseconds = 500; 130 const int64 kFallbackTickTimeoutInMilliseconds = 500;
126 131
132 class ScopedAllowGL : public base::NonThreadSafe {
joth 2013/07/30 01:13:06 sub-classing NonThreadSafe doesn't do anything unl
no sievers 2013/07/31 18:19:28 Done.
133 public:
134 ScopedAllowGL();
135 virtual ~ScopedAllowGL();
136
137 static bool IsAllowed() { return allow_gl; }
joth 2013/07/30 01:13:06 nit: maybe easier to follow the threading rules if
no sievers 2013/07/31 18:19:28 Done.
138
139 private:
140 static bool allow_gl = false;
joth 2013/07/30 01:13:06 nit: g_allow_gl also remove the "= false" -- you
no sievers 2013/07/31 18:19:28 Done.
141
142 DISALLOW_COPY_AND_ASSIGN(ScopedAllowGL);
143 };
144
145 ScopedAllowGL::ScopedAllowGL() {
146 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
147 DCHECK(!g_allow_gl);
148 g_allow_gl = true;
149 }
150
151 ScopedAllowGL::~ScopedAllowGL() {
152 g_allow_gl = false;
153 }
154
155 bool ScopedAllowGL::allow_gl = false;
156
127 } // namespace 157 } // namespace
128 158
159 // Called from different threads!
160 static void ScheduleGpuWork() {
161 if (BrowserThread::CurrentlyOn(BrowserThread::UI) &&
162 ScopedAllowGL::IsAllowed()) {
163 gpu::InProcessCommandBuffer::ProcessGpuWorkOnCurrentThread();
164 } else {
165 // TODO: We need to request a callback with a GL context current here.
166 }
167 }
168
129 // static 169 // static
130 void BrowserViewRenderer::SetAwDrawSWFunctionTable( 170 void BrowserViewRenderer::SetAwDrawSWFunctionTable(
131 AwDrawSWFunctionTable* table) { 171 AwDrawSWFunctionTable* table) {
132 g_sw_draw_functions = table; 172 g_sw_draw_functions = table;
133 g_is_skia_version_compatible = 173 g_is_skia_version_compatible =
134 g_sw_draw_functions->is_skia_version_compatible(&SkGraphics::GetVersion); 174 g_sw_draw_functions->is_skia_version_compatible(&SkGraphics::GetVersion);
135 LOG_IF(WARNING, !g_is_skia_version_compatible) 175 LOG_IF(WARNING, !g_is_skia_version_compatible)
136 << "Skia versions are not compatible, rendering performance will suffer."; 176 << "Skia versions are not compatible, rendering performance will suffer.";
177
178 gpu::InProcessCommandBuffer::SetScheduleCallback(
179 base::Bind(&ScheduleGpuWork));
137 } 180 }
138 181
139 // static 182 // static
140 AwDrawSWFunctionTable* BrowserViewRenderer::GetAwDrawSWFunctionTable() { 183 AwDrawSWFunctionTable* BrowserViewRenderer::GetAwDrawSWFunctionTable() {
141 return g_sw_draw_functions; 184 return g_sw_draw_functions;
142 } 185 }
143 186
144 // static 187 // static
145 bool BrowserViewRenderer::IsSkiaVersionCompatible() { 188 bool BrowserViewRenderer::IsSkiaVersionCompatible() {
146 DCHECK(g_sw_draw_functions); 189 DCHECK(g_sw_draw_functions);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 // We need to watch if the current Android context has changed and enforce 264 // We need to watch if the current Android context has changed and enforce
222 // a clean-up in the compositor. 265 // a clean-up in the compositor.
223 EGLContext current_context = eglGetCurrentContext(); 266 EGLContext current_context = eglGetCurrentContext();
224 if (!current_context) { 267 if (!current_context) {
225 TRACE_EVENT_INSTANT0( 268 TRACE_EVENT_INSTANT0(
226 "android_webview", "EarlyOut_NullEGLContext", TRACE_EVENT_SCOPE_THREAD); 269 "android_webview", "EarlyOut_NullEGLContext", TRACE_EVENT_SCOPE_THREAD);
227 return; 270 return;
228 } 271 }
229 272
230 ScopedAppGLStateRestore state_restore(ScopedAppGLStateRestore::MODE_DRAW); 273 ScopedAppGLStateRestore state_restore(ScopedAppGLStateRestore::MODE_DRAW);
274 gpu::InProcessCommandBuffer::ProcessGpuWorkOnCurrentThread();
275 ScopedAllowGL allow_gl;
231 276
232 if (attached_to_window_ && compositor_ && !hardware_initialized_) { 277 if (attached_to_window_ && compositor_ && !hardware_initialized_) {
233 TRACE_EVENT0("android_webview", "InitializeHwDraw"); 278 TRACE_EVENT0("android_webview", "InitializeHwDraw");
234 hardware_failed_ = !compositor_->InitializeHwDraw(); 279 hardware_failed_ = !compositor_->InitializeHwDraw();
235 hardware_initialized_ = true; 280 hardware_initialized_ = true;
236 last_egl_context_ = current_context; 281 last_egl_context_ = current_context;
237 282
238 if (hardware_failed_) 283 if (hardware_failed_)
239 return; 284 return;
240 } 285 }
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 497
453 void InProcessViewRenderer::OnDetachedFromWindow() { 498 void InProcessViewRenderer::OnDetachedFromWindow() {
454 TRACE_EVENT0("android_webview", 499 TRACE_EVENT0("android_webview",
455 "InProcessViewRenderer::OnDetachedFromWindow"); 500 "InProcessViewRenderer::OnDetachedFromWindow");
456 501
457 if (hardware_initialized_) { 502 if (hardware_initialized_) {
458 DCHECK(compositor_); 503 DCHECK(compositor_);
459 504
460 ScopedAppGLStateRestore state_restore( 505 ScopedAppGLStateRestore state_restore(
461 ScopedAppGLStateRestore::MODE_DETACH_FROM_WINDOW); 506 ScopedAppGLStateRestore::MODE_DETACH_FROM_WINDOW);
507 gpu::InProcessCommandBuffer::ProcessGpuWorkOnCurrentThread();
508 ScopedAllowGL allow_gl;
462 compositor_->ReleaseHwDraw(); 509 compositor_->ReleaseHwDraw();
463 hardware_initialized_ = false; 510 hardware_initialized_ = false;
464 } 511 }
465 512
466 attached_to_window_ = false; 513 attached_to_window_ = false;
467 } 514 }
468 515
469 bool InProcessViewRenderer::IsAttachedToWindow() { 516 bool InProcessViewRenderer::IsAttachedToWindow() {
470 return attached_to_window_; 517 return attached_to_window_;
471 } 518 }
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 base::StringAppendF(&str, 714 base::StringAppendF(&str,
668 "surface width height: [%d %d] ", 715 "surface width height: [%d %d] ",
669 draw_info->width, 716 draw_info->width,
670 draw_info->height); 717 draw_info->height);
671 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer); 718 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer);
672 } 719 }
673 return str; 720 return str;
674 } 721 }
675 722
676 } // namespace android_webview 723 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698