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/public/browser/draw_gl.h" | 9 #include "android_webview/public/browser/draw_gl.h" |
10 #include "android_webview/public/browser/draw_sw.h" | 10 #include "android_webview/public/browser/draw_sw.h" |
11 #include "base/android/jni_android.h" | 11 #include "base/android/jni_android.h" |
| 12 #include "base/command_line.h" |
12 #include "base/debug/trace_event.h" | 13 #include "base/debug/trace_event.h" |
13 #include "base/logging.h" | 14 #include "base/logging.h" |
14 #include "content/public/browser/android/content_view_core.h" | 15 #include "content/public/browser/android/content_view_core.h" |
15 #include "content/public/browser/android/synchronous_compositor.h" | 16 #include "content/public/browser/android/synchronous_compositor.h" |
16 #include "content/public/browser/render_view_host.h" | 17 #include "content/public/browser/render_view_host.h" |
17 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
18 #include "third_party/skia/include/core/SkBitmap.h" | 19 #include "third_party/skia/include/core/SkBitmap.h" |
19 #include "third_party/skia/include/core/SkCanvas.h" | 20 #include "third_party/skia/include/core/SkCanvas.h" |
20 #include "third_party/skia/include/core/SkDevice.h" | 21 #include "third_party/skia/include/core/SkDevice.h" |
21 #include "third_party/skia/include/core/SkGraphics.h" | 22 #include "third_party/skia/include/core/SkGraphics.h" |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 } | 310 } |
310 | 311 |
311 void InProcessViewRenderer::WebContentsGone() { | 312 void InProcessViewRenderer::WebContentsGone() { |
312 web_contents_ = NULL; | 313 web_contents_ = NULL; |
313 compositor_ = NULL; | 314 compositor_ = NULL; |
314 } | 315 } |
315 | 316 |
316 bool InProcessViewRenderer::PrepareDrawGL(int x, int y) { | 317 bool InProcessViewRenderer::PrepareDrawGL(int x, int y) { |
317 // No harm in updating |hw_rendering_scroll_| even if we return false. | 318 // No harm in updating |hw_rendering_scroll_| even if we return false. |
318 hw_rendering_scroll_ = gfx::Point(x, y); | 319 hw_rendering_scroll_ = gfx::Point(x, y); |
319 return attached_to_window_ && compositor_ && compositor_->IsHwReady() && | 320 return attached_to_window_ && compositor_ && !hardware_failed_ && |
320 !hardware_failed_; | 321 CommandLine::ForCurrentProcess()->HasSwitch("testing-webview-gl-mode"); |
321 } | 322 } |
322 | 323 |
323 void InProcessViewRenderer::DrawGL(AwDrawGLInfo* draw_info) { | 324 void InProcessViewRenderer::DrawGL(AwDrawGLInfo* draw_info) { |
324 DCHECK(view_visible_); | 325 DCHECK(view_visible_); |
325 | 326 |
326 // We need to watch if the current Android context has changed and enforce | 327 // We need to watch if the current Android context has changed and enforce |
327 // a clean-up in the compositor. | 328 // a clean-up in the compositor. |
328 EGLContext current_context = eglGetCurrentContext(); | 329 EGLContext current_context = eglGetCurrentContext(); |
329 if (!current_context) { | 330 if (!current_context) { |
330 LOG(WARNING) << "No current context attached. Skipping composite."; | 331 LOG(WARNING) << "No current context attached. Skipping composite."; |
331 return; | 332 return; |
332 } | 333 } |
333 | 334 |
334 GLStateRestore state_restore; | 335 GLStateRestore state_restore; |
335 | 336 |
336 if (attached_to_window_ && compositor_ && !hardware_initialized_) { | 337 if (attached_to_window_ && compositor_ && !hardware_initialized_) { |
337 // TODO(boliu): Actually initialize the compositor GL path. | 338 hardware_failed_ = !compositor_->InitializeHwDraw(); |
338 hardware_initialized_ = true; | 339 hardware_initialized_ = true; |
339 egl_context_at_init_ = current_context; | 340 egl_context_at_init_ = current_context; |
| 341 |
| 342 if (hardware_failed_) |
| 343 return; |
340 } | 344 } |
341 | 345 |
342 if (draw_info->mode == AwDrawGLInfo::kModeProcess) | 346 if (draw_info->mode == AwDrawGLInfo::kModeProcess) |
343 return; | 347 return; |
344 | 348 |
345 if (egl_context_at_init_ != current_context) { | 349 if (egl_context_at_init_ != current_context) { |
346 // TODO(boliu): Handle context lost | 350 // TODO(boliu): Handle context lost |
347 } | 351 } |
348 | 352 |
349 // TODO(boliu): Make sure this is not called before compositor is initialized | 353 // TODO(boliu): Make sure this is not called before compositor is initialized |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 // TODO(joth): BrowserViewRendererImpl had a bunch of logic for dpi and page | 580 // TODO(joth): BrowserViewRendererImpl had a bunch of logic for dpi and page |
577 // scale here. Determine what if any needs bringing over to this class. | 581 // scale here. Determine what if any needs bringing over to this class. |
578 return CompositeSW(canvas); | 582 return CompositeSW(canvas); |
579 } | 583 } |
580 | 584 |
581 bool InProcessViewRenderer::CompositeSW(SkCanvas* canvas) { | 585 bool InProcessViewRenderer::CompositeSW(SkCanvas* canvas) { |
582 return compositor_ && compositor_->DemandDrawSw(canvas); | 586 return compositor_ && compositor_->DemandDrawSw(canvas); |
583 } | 587 } |
584 | 588 |
585 } // namespace android_webview | 589 } // namespace android_webview |
OLD | NEW |