summaryrefslogtreecommitdiffstats
path: root/android_webview
diff options
context:
space:
mode:
authorboliu@chromium.org <boliu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-07 09:46:09 +0000
committerboliu@chromium.org <boliu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-07 09:46:09 +0000
commit6172484f197a643af32ea749794de3b91de7ce3a (patch)
treea23ec373428f624ac90a0423d2df367fc032f471 /android_webview
parentddafdb6aaae19e7ad2b46422023ae2e11154aea4 (diff)
downloadchromium_src-6172484f197a643af32ea749794de3b91de7ce3a.zip
chromium_src-6172484f197a643af32ea749794de3b91de7ce3a.tar.gz
chromium_src-6172484f197a643af32ea749794de3b91de7ce3a.tar.bz2
Add AwGLSurface and use it in WGC3D
Android can put the webview into an FBO, and compositor should draw into the FBO instead of directly on screen. Use AwGLSurface and explicitly set the FBO at the beginning of each hardware draw. Add new APIs in GLInProcessContext and WGC3DIPCBI to allow the underlying GLSurface to be created separately. BUG=251501 Review URL: https://chromiumcodereview.appspot.com/22277004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@216136 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'android_webview')
-rw-r--r--android_webview/android_webview.gyp2
-rw-r--r--android_webview/browser/aw_gl_surface.cc48
-rw-r--r--android_webview/browser/aw_gl_surface.h42
-rw-r--r--android_webview/browser/in_process_view_renderer.cc35
-rw-r--r--android_webview/browser/in_process_view_renderer.h5
-rw-r--r--android_webview/browser/scoped_app_gl_state_restore.cc2
-rw-r--r--android_webview/browser/scoped_app_gl_state_restore.h3
7 files changed, 128 insertions, 9 deletions
diff --git a/android_webview/android_webview.gyp b/android_webview/android_webview.gyp
index c2f23a3..237712a 100644
--- a/android_webview/android_webview.gyp
+++ b/android_webview/android_webview.gyp
@@ -111,6 +111,8 @@
'browser/aw_download_manager_delegate.h',
'browser/aw_form_database_service.cc',
'browser/aw_form_database_service.h',
+ 'browser/aw_gl_surface.cc',
+ 'browser/aw_gl_surface.h',
'browser/aw_http_auth_handler_base.cc',
'browser/aw_http_auth_handler_base.h',
'browser/aw_javascript_dialog_manager.cc',
diff --git a/android_webview/browser/aw_gl_surface.cc b/android_webview/browser/aw_gl_surface.cc
new file mode 100644
index 0000000..5ff9272
--- /dev/null
+++ b/android_webview/browser/aw_gl_surface.cc
@@ -0,0 +1,48 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "android_webview/browser/aw_gl_surface.h"
+
+namespace android_webview {
+
+AwGLSurface::AwGLSurface() : fbo_(0) {}
+
+AwGLSurface::~AwGLSurface() {}
+
+void AwGLSurface::Destroy() {
+}
+
+bool AwGLSurface::IsOffscreen() {
+ return false;
+}
+
+unsigned int AwGLSurface::GetBackingFrameBufferObject() {
+ return fbo_;
+}
+
+bool AwGLSurface::SwapBuffers() {
+ return true;
+}
+
+gfx::Size AwGLSurface::GetSize() {
+ return gfx::Size(1, 1);
+}
+
+void* AwGLSurface::GetHandle() {
+ return NULL;
+}
+
+void* AwGLSurface::GetDisplay() {
+ return NULL;
+}
+
+void AwGLSurface::SetBackingFrameBufferObject(unsigned int fbo) {
+ fbo_ = fbo;
+}
+
+void AwGLSurface::ResetBackingFrameBufferObject() {
+ fbo_ = 0;
+}
+
+} // namespace android_webview
diff --git a/android_webview/browser/aw_gl_surface.h b/android_webview/browser/aw_gl_surface.h
new file mode 100644
index 0000000..99b8a1d
--- /dev/null
+++ b/android_webview/browser/aw_gl_surface.h
@@ -0,0 +1,42 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ANDROID_WEBVIEW_BROWSER_AW_GL_SURFACE_H_
+#define ANDROID_WEBVIEW_BROWSER_AW_GL_SURFACE_H_
+
+#include "ui/gl/gl_surface.h"
+
+namespace android_webview {
+
+// This surface is used to represent the underlying surface provided by the App
+// inside a hardware draw. Note that offscreen contexts will not be using this
+// GLSurface.
+class GL_EXPORT AwGLSurface : public gfx::GLSurface {
+ public:
+ AwGLSurface();
+
+ // Implement GLSurface.
+ virtual void Destroy() OVERRIDE;
+ virtual bool IsOffscreen() OVERRIDE;
+ virtual unsigned int GetBackingFrameBufferObject() OVERRIDE;
+ virtual bool SwapBuffers() OVERRIDE;
+ virtual gfx::Size GetSize() OVERRIDE;
+ virtual void* GetHandle() OVERRIDE;
+ virtual void* GetDisplay() OVERRIDE;
+
+ void SetBackingFrameBufferObject(unsigned int fbo);
+ void ResetBackingFrameBufferObject();
+
+ protected:
+ virtual ~AwGLSurface();
+
+ private:
+ unsigned int fbo_;
+
+ DISALLOW_COPY_AND_ASSIGN(AwGLSurface);
+};
+
+} // namespace android_webview
+
+#endif // ANDROID_WEBVIEW_BROWSER_AW_GL_SURFACE_H_
diff --git a/android_webview/browser/in_process_view_renderer.cc b/android_webview/browser/in_process_view_renderer.cc
index a714956..3e25680 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"
@@ -289,6 +290,19 @@ bool InProcessViewRenderer::OnDraw(jobject java_canvas,
return result;
}
+bool InProcessViewRenderer::InitializeHwDraw() {
+ TRACE_EVENT0("android_webview", "InitializeHwDraw");
+ DCHECK(!gl_surface_);
+ gl_surface_ = new AwGLSurface;
+ hardware_failed_ = !compositor_->InitializeHwDraw(gl_surface_);
+ hardware_initialized_ = true;
+
+ if (hardware_failed_)
+ gl_surface_ = NULL;
+
+ return !hardware_failed_;
+}
+
void InProcessViewRenderer::DrawGL(AwDrawGLInfo* draw_info) {
TRACE_EVENT0("android_webview", "InProcessViewRenderer::DrawGL");
DCHECK(visible_);
@@ -309,13 +323,11 @@ 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;
+ }
}
if (draw_info->mode == AwDrawGLInfo::kModeProcess)
@@ -330,7 +342,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 +349,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_);
@@ -554,6 +570,7 @@ void InProcessViewRenderer::OnDetachedFromWindow() {
hardware_initialized_ = false;
}
+ gl_surface_ = NULL;
attached_to_window_ = false;
}
diff --git a/android_webview/browser/in_process_view_renderer.h b/android_webview/browser/in_process_view_renderer.h
index 6e66a84..8bb2c60 100644
--- a/android_webview/browser/in_process_view_renderer.h
+++ b/android_webview/browser/in_process_view_renderer.h
@@ -23,6 +23,8 @@ class SkCanvas;
namespace android_webview {
+class AwGLSurface;
+
// Provides RenderViewHost wrapper functionality for sending WebView-specific
// IPC messages to the renderer and from there to WebKit.
class InProcessViewRenderer : public BrowserViewRenderer,
@@ -93,6 +95,8 @@ class InProcessViewRenderer : public BrowserViewRenderer,
void NoLongerExpectsDrawGL();
+ bool InitializeHwDraw();
+
// For debug tracing or logging. Return the string representation of this
// view renderer's state and the |draw_info| if provided.
std::string ToString(AwDrawGLInfo* draw_info) const;
@@ -127,6 +131,7 @@ class InProcessViewRenderer : public BrowserViewRenderer,
bool attached_to_window_;
bool hardware_initialized_;
bool hardware_failed_;
+ scoped_refptr<AwGLSurface> gl_surface_;
// Used only for detecting Android View System context changes.
// Not to be used between draw calls.
diff --git a/android_webview/browser/scoped_app_gl_state_restore.cc b/android_webview/browser/scoped_app_gl_state_restore.cc
index cb8d128..e0c8fed 100644
--- a/android_webview/browser/scoped_app_gl_state_restore.cc
+++ b/android_webview/browser/scoped_app_gl_state_restore.cc
@@ -132,6 +132,7 @@ ScopedAppGLStateRestore::ScopedAppGLStateRestore(CallMode mode) : mode_(mode) {
glGetIntegerv(GL_STENCIL_VALUE_MASK, &stencil_mask_);
glGetIntegerv(GL_STENCIL_REF, &stencil_ref_);
+ glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &framebuffer_binding_ext_);
if (!g_gl_max_texture_units) {
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &g_gl_max_texture_units);
@@ -155,6 +156,7 @@ ScopedAppGLStateRestore::~ScopedAppGLStateRestore() {
TRACE_EVENT0("android_webview", "AppGLStateRestore");
MakeAppContextCurrent();
+ glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer_binding_ext_);
glBindBuffer(GL_ARRAY_BUFFER, vertex_array_buffer_binding_);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_array_buffer_binding_);
diff --git a/android_webview/browser/scoped_app_gl_state_restore.h b/android_webview/browser/scoped_app_gl_state_restore.h
index 7840fbf..93b5ad5 100644
--- a/android_webview/browser/scoped_app_gl_state_restore.h
+++ b/android_webview/browser/scoped_app_gl_state_restore.h
@@ -25,6 +25,7 @@ class ScopedAppGLStateRestore {
~ScopedAppGLStateRestore();
bool stencil_enabled() const { return stencil_test_; }
+ GLint framebuffer_binding_ext() const { return framebuffer_binding_ext_; }
private:
const CallMode mode_;
@@ -83,6 +84,8 @@ class ScopedAppGLStateRestore {
GLint stencil_mask_;
GLint stencil_ref_;
+ GLint framebuffer_binding_ext_;
+
struct TextureBindings {
GLint texture_2d;
GLint texture_cube_map;