| Index: android_webview/browser/in_process_view_renderer.cc
|
| diff --git a/android_webview/browser/in_process_view_renderer.cc b/android_webview/browser/in_process_view_renderer.cc
|
| index a714956e08064795b9da15890fab5f8cddc411f6..2887ce8345a69a520268c296ee9b949269b17a98 100644
|
| --- a/android_webview/browser/in_process_view_renderer.cc
|
| +++ b/android_webview/browser/in_process_view_renderer.cc
|
| @@ -6,6 +6,7 @@
|
|
|
| #include <android/bitmap.h>
|
|
|
| +#include "android_webview/browser/aw_gl_surface.h"
|
| #include "android_webview/browser/scoped_app_gl_state_restore.h"
|
| #include "android_webview/common/aw_switches.h"
|
| #include "android_webview/public/browser/draw_gl.h"
|
| @@ -160,6 +161,23 @@ bool ScopedAllowGL::allow_gl = false;
|
|
|
| base::LazyInstance<GLViewRendererManager>::Leaky g_view_renderer_manager;
|
|
|
| +class ScopedSetSurfaceFactory {
|
| + public:
|
| + ScopedSetSurfaceFactory(InProcessViewRenderer* factory);
|
| + ~ScopedSetSurfaceFactory();
|
| +};
|
| +
|
| +ScopedSetSurfaceFactory::ScopedSetSurfaceFactory(
|
| + InProcessViewRenderer* factory) {
|
| + DCHECK(factory);
|
| + DCHECK(!gfx::SurfaceFactoryAndroid::GetInstance());
|
| + gfx::SurfaceFactoryAndroid::SetInstance(factory);
|
| +}
|
| +
|
| +ScopedSetSurfaceFactory::~ScopedSetSurfaceFactory() {
|
| + gfx::SurfaceFactoryAndroid::SetInstance(NULL);
|
| +}
|
| +
|
| } // namespace
|
|
|
| // Called from different threads!
|
| @@ -186,6 +204,8 @@ void BrowserViewRenderer::SetAwDrawSWFunctionTable(
|
|
|
| gpu::InProcessCommandBuffer::SetScheduleCallback(
|
| base::Bind(&ScheduleGpuWork));
|
| +
|
| + DCHECK(!gfx::SurfaceFactoryAndroid::GetInstance());
|
| }
|
|
|
| // static
|
| @@ -289,6 +309,30 @@ bool InProcessViewRenderer::OnDraw(jobject java_canvas,
|
| return result;
|
| }
|
|
|
| +scoped_refptr<gfx::GLSurface>
|
| +InProcessViewRenderer::CreateNonOwnedViewSurface() {
|
| + DCHECK(!hardware_initialized_);
|
| + DCHECK(!gl_surface_);
|
| + gl_surface_ = new AwGLSurface;
|
| + return gl_surface_;
|
| +}
|
| +
|
| +bool InProcessViewRenderer::InitializeHwDraw() {
|
| + TRACE_EVENT0("android_webview", "InitializeHwDraw");
|
| +
|
| + {
|
| + ScopedSetSurfaceFactory setter(this);
|
| + hardware_failed_ = !compositor_->InitializeHwDraw();
|
| + }
|
| +
|
| + hardware_initialized_ = true;
|
| + if (!hardware_failed_) {
|
| + DCHECK(gl_surface_);
|
| + }
|
| +
|
| + return !hardware_failed_;
|
| +}
|
| +
|
| void InProcessViewRenderer::DrawGL(AwDrawGLInfo* draw_info) {
|
| TRACE_EVENT0("android_webview", "InProcessViewRenderer::DrawGL");
|
| DCHECK(visible_);
|
| @@ -309,12 +353,9 @@ void InProcessViewRenderer::DrawGL(AwDrawGLInfo* draw_info) {
|
| ScopedAllowGL allow_gl;
|
|
|
| if (attached_to_window_ && compositor_ && !hardware_initialized_) {
|
| - TRACE_EVENT0("android_webview", "InitializeHwDraw");
|
| - hardware_failed_ = !compositor_->InitializeHwDraw();
|
| - hardware_initialized_ = true;
|
| - last_egl_context_ = current_context;
|
| -
|
| - if (hardware_failed_)
|
| + if (InitializeHwDraw())
|
| + last_egl_context_ = current_context;
|
| + else
|
| return;
|
| }
|
|
|
| @@ -330,7 +371,6 @@ void InProcessViewRenderer::DrawGL(AwDrawGLInfo* draw_info) {
|
| TRACE_EVENT_INSTANT0(
|
| "android_webview", "EGLContextChanged", TRACE_EVENT_SCOPE_THREAD);
|
| }
|
| - last_egl_context_ = current_context;
|
|
|
| if (!compositor_) {
|
| TRACE_EVENT_INSTANT0(
|
| @@ -338,21 +378,26 @@ void InProcessViewRenderer::DrawGL(AwDrawGLInfo* draw_info) {
|
| return;
|
| }
|
|
|
| + DCHECK(gl_surface_);
|
| + gl_surface_->SetBackingFrameBufferObject(
|
| + state_restore.framebuffer_binding_ext());
|
| +
|
| gfx::Transform transform;
|
| transform.matrix().setColMajorf(draw_info->transform);
|
| transform.Translate(scroll_at_start_of_frame_.x(),
|
| scroll_at_start_of_frame_.y());
|
| - // TODO(joth): Check return value.
|
| - block_invalidates_ = true;
|
| gfx::Rect clip_rect(draw_info->clip_left,
|
| draw_info->clip_top,
|
| draw_info->clip_right - draw_info->clip_left,
|
| draw_info->clip_bottom - draw_info->clip_top);
|
| + block_invalidates_ = true;
|
| + // TODO(joth): Check return value.
|
| compositor_->DemandDrawHw(gfx::Size(draw_info->width, draw_info->height),
|
| transform,
|
| clip_rect,
|
| state_restore.stencil_enabled());
|
| block_invalidates_ = false;
|
| + gl_surface_->ResetBackingFrameBufferObject();
|
|
|
| UpdateCachedGlobalVisibleRect();
|
| bool drew_full_visible_rect = clip_rect.Contains(cached_global_visible_rect_);
|
| @@ -552,6 +597,7 @@ void InProcessViewRenderer::OnDetachedFromWindow() {
|
| ScopedAllowGL allow_gl;
|
| compositor_->ReleaseHwDraw();
|
| hardware_initialized_ = false;
|
| + gl_surface_ = NULL;
|
| }
|
|
|
| attached_to_window_ = false;
|
|
|