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

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, 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/auto_reset.h" 13 #include "base/auto_reset.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/debug/trace_event.h" 15 #include "base/debug/trace_event.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/strings/stringprintf.h" 17 #include "base/strings/stringprintf.h"
18 #include "content/public/browser/android/synchronous_compositor.h" 18 #include "content/public/browser/android/synchronous_compositor.h"
19 #include "content/public/browser/browser_thread.h"
19 #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"
20 #include "skia/ext/refptr.h" 22 #include "skia/ext/refptr.h"
21 #include "third_party/skia/include/core/SkBitmap.h" 23 #include "third_party/skia/include/core/SkBitmap.h"
22 #include "third_party/skia/include/core/SkCanvas.h" 24 #include "third_party/skia/include/core/SkCanvas.h"
23 #include "third_party/skia/include/core/SkDevice.h" 25 #include "third_party/skia/include/core/SkDevice.h"
24 #include "third_party/skia/include/core/SkGraphics.h" 26 #include "third_party/skia/include/core/SkGraphics.h"
25 #include "third_party/skia/include/core/SkPicture.h" 27 #include "third_party/skia/include/core/SkPicture.h"
26 #include "ui/gfx/skia_util.h" 28 #include "ui/gfx/skia_util.h"
27 #include "ui/gfx/transform.h" 29 #include "ui/gfx/transform.h"
28 #include "ui/gfx/vector2d_conversions.h" 30 #include "ui/gfx/vector2d_conversions.h"
29 #include "ui/gfx/vector2d_f.h" 31 #include "ui/gfx/vector2d_f.h"
30 32
31 using base::android::AttachCurrentThread; 33 using base::android::AttachCurrentThread;
32 using base::android::JavaRef; 34 using base::android::JavaRef;
33 using base::android::ScopedJavaLocalRef; 35 using base::android::ScopedJavaLocalRef;
36 using content::BrowserThread;
34 37
35 namespace android_webview { 38 namespace android_webview {
36 39
37 namespace { 40 namespace {
38 41
39 42
40 const void* kUserDataKey = &kUserDataKey; 43 const void* kUserDataKey = &kUserDataKey;
41 44
42 class UserData : public content::WebContents::Data { 45 class UserData : public content::WebContents::Data {
43 public: 46 public:
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 121
119 // Tells if the Skia library versions in Android and Chromium are compatible. 122 // Tells if the Skia library versions in Android and Chromium are compatible.
120 // If they are then it's possible to pass Skia objects like SkPictures to the 123 // If they are then it's possible to pass Skia objects like SkPictures to the
121 // Android glue layer via the SW rendering functions. 124 // Android glue layer via the SW rendering functions.
122 // If they are not, then additional copies and rasterizations are required 125 // If they are not, then additional copies and rasterizations are required
123 // as a fallback mechanism, which will have an important performance impact. 126 // as a fallback mechanism, which will have an important performance impact.
124 bool g_is_skia_version_compatible = false; 127 bool g_is_skia_version_compatible = false;
125 128
126 const int64 kFallbackTickTimeoutInMilliseconds = 500; 129 const int64 kFallbackTickTimeoutInMilliseconds = 500;
127 130
131 class ScopedAllowGL {
132 public:
133 ScopedAllowGL();
134 ~ScopedAllowGL();
135
136 static bool IsAllowed() {
137 return BrowserThread::CurrentlyOn(BrowserThread::UI) && allow_gl;
138 }
139
140 private:
141 static bool allow_gl;
142
143 DISALLOW_COPY_AND_ASSIGN(ScopedAllowGL);
144 };
145
146 ScopedAllowGL::ScopedAllowGL() {
147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
148 DCHECK(!allow_gl);
149 allow_gl = true;
150 }
151
152 ScopedAllowGL::~ScopedAllowGL() {
153 allow_gl = false;
154 }
155
156 bool ScopedAllowGL::allow_gl = false;
157
128 } // namespace 158 } // namespace
129 159
160 // Called from different threads!
161 static void ScheduleGpuWork() {
162 if (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
130 // static 169 // static
131 void BrowserViewRenderer::SetAwDrawSWFunctionTable( 170 void BrowserViewRenderer::SetAwDrawSWFunctionTable(
132 AwDrawSWFunctionTable* table) { 171 AwDrawSWFunctionTable* table) {
133 g_sw_draw_functions = table; 172 g_sw_draw_functions = table;
134 g_is_skia_version_compatible = 173 g_is_skia_version_compatible =
135 g_sw_draw_functions->is_skia_version_compatible(&SkGraphics::GetVersion); 174 g_sw_draw_functions->is_skia_version_compatible(&SkGraphics::GetVersion);
136 LOG_IF(WARNING, !g_is_skia_version_compatible) 175 LOG_IF(WARNING, !g_is_skia_version_compatible)
137 << "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));
138 } 180 }
139 181
140 // static 182 // static
141 AwDrawSWFunctionTable* BrowserViewRenderer::GetAwDrawSWFunctionTable() { 183 AwDrawSWFunctionTable* BrowserViewRenderer::GetAwDrawSWFunctionTable() {
142 return g_sw_draw_functions; 184 return g_sw_draw_functions;
143 } 185 }
144 186
145 // static 187 // static
146 bool BrowserViewRenderer::IsSkiaVersionCompatible() { 188 bool BrowserViewRenderer::IsSkiaVersionCompatible() {
147 DCHECK(g_sw_draw_functions); 189 DCHECK(g_sw_draw_functions);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 // 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
223 // a clean-up in the compositor. 265 // a clean-up in the compositor.
224 EGLContext current_context = eglGetCurrentContext(); 266 EGLContext current_context = eglGetCurrentContext();
225 if (!current_context) { 267 if (!current_context) {
226 TRACE_EVENT_INSTANT0( 268 TRACE_EVENT_INSTANT0(
227 "android_webview", "EarlyOut_NullEGLContext", TRACE_EVENT_SCOPE_THREAD); 269 "android_webview", "EarlyOut_NullEGLContext", TRACE_EVENT_SCOPE_THREAD);
228 return; 270 return;
229 } 271 }
230 272
231 ScopedAppGLStateRestore state_restore(ScopedAppGLStateRestore::MODE_DRAW); 273 ScopedAppGLStateRestore state_restore(ScopedAppGLStateRestore::MODE_DRAW);
274 gpu::InProcessCommandBuffer::ProcessGpuWorkOnCurrentThread();
275 ScopedAllowGL allow_gl;
232 276
233 if (attached_to_window_ && compositor_ && !hardware_initialized_) { 277 if (attached_to_window_ && compositor_ && !hardware_initialized_) {
234 TRACE_EVENT0("android_webview", "InitializeHwDraw"); 278 TRACE_EVENT0("android_webview", "InitializeHwDraw");
235 hardware_failed_ = !compositor_->InitializeHwDraw(); 279 hardware_failed_ = !compositor_->InitializeHwDraw();
236 hardware_initialized_ = true; 280 hardware_initialized_ = true;
237 last_egl_context_ = current_context; 281 last_egl_context_ = current_context;
238 282
239 if (hardware_failed_) 283 if (hardware_failed_)
240 return; 284 return;
241 } 285 }
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 498
455 void InProcessViewRenderer::OnDetachedFromWindow() { 499 void InProcessViewRenderer::OnDetachedFromWindow() {
456 TRACE_EVENT0("android_webview", 500 TRACE_EVENT0("android_webview",
457 "InProcessViewRenderer::OnDetachedFromWindow"); 501 "InProcessViewRenderer::OnDetachedFromWindow");
458 502
459 if (hardware_initialized_) { 503 if (hardware_initialized_) {
460 DCHECK(compositor_); 504 DCHECK(compositor_);
461 505
462 ScopedAppGLStateRestore state_restore( 506 ScopedAppGLStateRestore state_restore(
463 ScopedAppGLStateRestore::MODE_DETACH_FROM_WINDOW); 507 ScopedAppGLStateRestore::MODE_DETACH_FROM_WINDOW);
508 gpu::InProcessCommandBuffer::ProcessGpuWorkOnCurrentThread();
509 ScopedAllowGL allow_gl;
464 compositor_->ReleaseHwDraw(); 510 compositor_->ReleaseHwDraw();
465 hardware_initialized_ = false; 511 hardware_initialized_ = false;
466 } 512 }
467 513
468 attached_to_window_ = false; 514 attached_to_window_ = false;
469 } 515 }
470 516
471 bool InProcessViewRenderer::IsAttachedToWindow() { 517 bool InProcessViewRenderer::IsAttachedToWindow() {
472 return attached_to_window_; 518 return attached_to_window_;
473 } 519 }
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 base::StringAppendF(&str, 719 base::StringAppendF(&str,
674 "surface width height: [%d %d] ", 720 "surface width height: [%d %d] ",
675 draw_info->width, 721 draw_info->width,
676 draw_info->height); 722 draw_info->height);
677 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer); 723 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer);
678 } 724 }
679 return str; 725 return str;
680 } 726 }
681 727
682 } // namespace android_webview 728 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698