diff options
5 files changed, 57 insertions, 26 deletions
diff --git a/content/renderer/renderer_webkitplatformsupport_impl.cc b/content/renderer/renderer_webkitplatformsupport_impl.cc index 7bbd8da..b950713 100644 --- a/content/renderer/renderer_webkitplatformsupport_impl.cc +++ b/content/renderer/renderer_webkitplatformsupport_impl.cc @@ -554,7 +554,8 @@ RendererWebKitPlatformSupportImpl::createGraphicsContext3D() { // layout tests (though not through this code) as well as for // debugging and bringing up new ports. if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessWebGL)) { - return new webkit::gpu::WebGraphicsContext3DInProcessImpl(); + return new webkit::gpu::WebGraphicsContext3DInProcessImpl( + gfx::kNullPluginWindow); } else { #if defined(ENABLE_GPU) return new WebGraphicsContext3DCommandBufferImpl(); diff --git a/webkit/gpu/webgraphicscontext3d_in_process_impl.cc b/webkit/gpu/webgraphicscontext3d_in_process_impl.cc index ae8c4c5..b602616 100644 --- a/webkit/gpu/webgraphicscontext3d_in_process_impl.cc +++ b/webkit/gpu/webgraphicscontext3d_in_process_impl.cc @@ -42,7 +42,8 @@ struct WebGraphicsContext3DInProcessImpl::ShaderSourceEntry { bool is_valid; }; -WebGraphicsContext3DInProcessImpl::WebGraphicsContext3DInProcessImpl() +WebGraphicsContext3DInProcessImpl::WebGraphicsContext3DInProcessImpl( + gfx::PluginWindowHandle window) : initialized_(false), render_directly_to_web_view_(false), is_gles2_(false), @@ -64,7 +65,8 @@ WebGraphicsContext3DInProcessImpl::WebGraphicsContext3DInProcessImpl() scanline_(0), #endif fragment_compiler_(0), - vertex_compiler_(0) { + vertex_compiler_(0), + window_(window) { } WebGraphicsContext3DInProcessImpl::~WebGraphicsContext3DInProcessImpl() { @@ -129,14 +131,19 @@ bool WebGraphicsContext3DInProcessImpl::initialize( is_gles2_ = gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2; - // This implementation always renders offscreen regardless of - // whether render_directly_to_web_view is true. Both DumpRenderTree - // and test_shell paint first to an intermediate offscreen buffer - // and from there to the window, and WebViewImpl::paint already - // correctly handles the case where the compositor is active but - // the output needs to go to a WebCanvas. - gl_surface_ = gfx::GLSurface::CreateOffscreenGLSurface(false, - gfx::Size(1, 1)); + if (window_ != gfx::kNullPluginWindow) { + gl_surface_ = gfx::GLSurface::CreateViewGLSurface(false, window_); + } else { + // This implementation always renders offscreen regardless of + // whether render_directly_to_web_view is true. Both DumpRenderTree + // and test_shell paint first to an intermediate offscreen buffer + // and from there to the window, and WebViewImpl::paint already + // correctly handles the case where the compositor is active but + // the output needs to go to a WebCanvas. + gl_surface_ = gfx::GLSurface::CreateOffscreenGLSurface(false, + gfx::Size(1, 1)); + } + if (!gl_surface_.get()) { if (!is_gles2_) return false; @@ -311,7 +318,9 @@ WebGLId WebGraphicsContext3DInProcessImpl::getPlatformTextureId() { } void WebGraphicsContext3DInProcessImpl::prepareTexture() { - if (!render_directly_to_web_view_) { + if (window_ != gfx::kNullPluginWindow) { + gl_surface_->SwapBuffers(); + } else if (!render_directly_to_web_view_) { // We need to prepare our rendering results for the compositor. makeContextCurrent(); ResolveMultisampledFramebuffer(0, 0, cached_width_, cached_height_); @@ -336,6 +345,26 @@ void WebGraphicsContext3DInProcessImpl::reshape(int width, int height) { cached_height_ = height; makeContextCurrent(); + bool must_restore_fbo = false; + if (window_ == gfx::kNullPluginWindow) + must_restore_fbo = AllocateOffscreenFrameBuffer(width, height); + + ClearRenderTarget(); + + if (must_restore_fbo) + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, bound_fbo_); + +#ifdef FLIP_FRAMEBUFFER_VERTICALLY + if (scanline_) { + delete[] scanline_; + scanline_ = 0; + } + scanline_ = new unsigned char[width * 4]; +#endif // FLIP_FRAMEBUFFER_VERTICALLY +} + +bool WebGraphicsContext3DInProcessImpl::AllocateOffscreenFrameBuffer( + int width, int height) { GLenum target = GL_TEXTURE_2D; if (!texture_) { @@ -499,7 +528,10 @@ void WebGraphicsContext3DInProcessImpl::reshape(int width, int height) { if (bound_fbo_ == multisample_fbo_) must_restore_fbo = false; } + return must_restore_fbo; +} +void WebGraphicsContext3DInProcessImpl::ClearRenderTarget() { // Initialize renderbuffers to 0. GLfloat clearColor[] = {0, 0, 0, 0}, clearDepth = 0; GLint clearStencil = 0; @@ -553,17 +585,6 @@ void WebGraphicsContext3DInProcessImpl::reshape(int width, int height) { glEnable(GL_DITHER); else glDisable(GL_DITHER); - - if (must_restore_fbo) - glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, bound_fbo_); - -#ifdef FLIP_FRAMEBUFFER_VERTICALLY - if (scanline_) { - delete[] scanline_; - scanline_ = 0; - } - scanline_ = new unsigned char[width * 4]; -#endif // FLIP_FRAMEBUFFER_VERTICALLY } #ifdef FLIP_FRAMEBUFFER_VERTICALLY diff --git a/webkit/gpu/webgraphicscontext3d_in_process_impl.h b/webkit/gpu/webgraphicscontext3d_in_process_impl.h index eb7cc5d..1bc447f 100644 --- a/webkit/gpu/webgraphicscontext3d_in_process_impl.h +++ b/webkit/gpu/webgraphicscontext3d_in_process_impl.h @@ -13,6 +13,7 @@ #include "third_party/angle/include/GLSLANG/ShaderLang.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebGraphicsContext3D.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" +#include "ui/gfx/native_widget_types.h" #if !defined(OS_MACOSX) #define FLIP_FRAMEBUFFER_VERTICALLY @@ -51,7 +52,9 @@ namespace gpu { class WebGraphicsContext3DInProcessImpl : public WebGraphicsContext3D { public: - WebGraphicsContext3DInProcessImpl(); + // Creates a WebGraphicsContext3DInProcessImpl for a given window. If window + // is gfx::kNullPluginWindow, then it creates an offscreen context. + WebGraphicsContext3DInProcessImpl(gfx::PluginWindowHandle window); virtual ~WebGraphicsContext3DInProcessImpl(); //---------------------------------------------------------------------- @@ -423,6 +426,9 @@ class WebGraphicsContext3DInProcessImpl : public WebGraphicsContext3D { typedef base::hash_map<WebGLId, ShaderSourceEntry*> ShaderSourceMap; + bool AllocateOffscreenFrameBuffer(int width, int height); + void ClearRenderTarget(); + #ifdef FLIP_FRAMEBUFFER_VERTICALLY void FlipVertically(unsigned char* framebuffer, unsigned int width, @@ -484,6 +490,7 @@ class WebGraphicsContext3DInProcessImpl : public WebGraphicsContext3D { ShHandle fragment_compiler_; ShHandle vertex_compiler_; + gfx::PluginWindowHandle window_; }; } // namespace gpu diff --git a/webkit/support/test_webkit_platform_support.cc b/webkit/support/test_webkit_platform_support.cc index eceebaf..07eeec6b 100644 --- a/webkit/support/test_webkit_platform_support.cc +++ b/webkit/support/test_webkit_platform_support.cc @@ -372,7 +372,8 @@ WebKit::WebGraphicsContext3D* TestWebKitPlatformSupport::createGraphicsContext3D() { switch (webkit_support::GetGraphicsContext3DImplementation()) { case webkit_support::IN_PROCESS: - return new webkit::gpu::WebGraphicsContext3DInProcessImpl(); + return new webkit::gpu::WebGraphicsContext3DInProcessImpl( + gfx::kNullPluginWindow); case webkit_support::IN_PROCESS_COMMAND_BUFFER: return new webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl(); default: diff --git a/webkit/tools/test_shell/test_shell_webkit_init.cc b/webkit/tools/test_shell/test_shell_webkit_init.cc index 0d2e448..5b275f6 100644 --- a/webkit/tools/test_shell/test_shell_webkit_init.cc +++ b/webkit/tools/test_shell/test_shell_webkit_init.cc @@ -297,5 +297,6 @@ TestShellWebKitInit::sharedWorkerRepository() { } WebKit::WebGraphicsContext3D* TestShellWebKitInit::createGraphicsContext3D() { - return new webkit::gpu::WebGraphicsContext3DInProcessImpl(); + return new webkit::gpu::WebGraphicsContext3DInProcessImpl( + gfx::kNullPluginWindow); } |