Title: [137211] trunk/Source/WebCore
Revision
137211
Author
[email protected]
Date
2012-12-10 15:01:20 -0800 (Mon, 10 Dec 2012)

Log Message

[EFL][WebGL] Minor Refactoring in GraphicsContext3DEfl.
https://bugs.webkit.org/show_bug.cgi?id=104553.

Patch by Kondapally Kalyan <[email protected]> on 2012-12-10
Reviewed by Kenneth Rohde Christiansen.

We use different FBO for canvas and offscreen surface of our platform layer.
Thus we need to manage any bound buffers while copying contents to the surface. Currently, Surface
always uses double buffering but in future we should be able to configure it to use either
double or single buffer. For these use cases, it would be handy to bind buffers directly to
FBO used by the surface. This patch does the needed changes in GraphicsContext3DEfl and
PlatformSurface. Also, removes some unused code.

Covered by existing tests.

Relevant changes in GraphicsContext3DEfl to obtain FBO id from PlatformSurface.
* platform/graphics/efl/GraphicsContext3DEfl.cpp:
(WebCore::GraphicsContext3D::GraphicsContext3D):
(WebCore::GraphicsContext3D::~GraphicsContext3D):

Renamed createGraphicsSurface to didResizeCanvas.
(WebCore::GraphicsContext3D::createGraphicsSurfaces):
* platform/graphics/efl/GraphicsContext3DPrivate.cpp:
(GraphicsContext3DPrivate::didResizeCanvas):
(GraphicsContext3DPrivate::copyToGraphicsSurface):
* platform/graphics/efl/GraphicsContext3DPrivate.h:
(GraphicsContext3DPrivate):

Header cleanup.
* platform/graphics/opengl/GLDefs.h:
* platform/graphics/opengl/GLPlatformContext.cpp:
(WebCore::GLPlatformContext::createContext):
* platform/graphics/opengl/GLPlatformContext.h:

Added initialize method to expose FBO id of the surface.
Removed unused code.
* platform/graphics/opengl/GLPlatformSurface.cpp:
(WebCore::GLPlatformSurface::initialize):
(WebCore):
(WebCore::GLPlatformSurface::updateContents):
* platform/graphics/opengl/GLPlatformSurface.h:
(GLPlatformSurface):
* platform/graphics/surfaces/glx/GLXSurface.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (137210 => 137211)


--- trunk/Source/WebCore/ChangeLog	2012-12-10 22:57:42 UTC (rev 137210)
+++ trunk/Source/WebCore/ChangeLog	2012-12-10 23:01:20 UTC (rev 137211)
@@ -1,3 +1,48 @@
+2012-12-10  Kondapally Kalyan  <[email protected]>
+
+        [EFL][WebGL] Minor Refactoring in GraphicsContext3DEfl.
+        https://bugs.webkit.org/show_bug.cgi?id=104553.
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        We use different FBO for canvas and offscreen surface of our platform layer.
+        Thus we need to manage any bound buffers while copying contents to the surface. Currently, Surface
+        always uses double buffering but in future we should be able to configure it to use either
+        double or single buffer. For these use cases, it would be handy to bind buffers directly to
+        FBO used by the surface. This patch does the needed changes in GraphicsContext3DEfl and
+        PlatformSurface. Also, removes some unused code.
+
+        Covered by existing tests.
+
+        Relevant changes in GraphicsContext3DEfl to obtain FBO id from PlatformSurface.
+        * platform/graphics/efl/GraphicsContext3DEfl.cpp:
+        (WebCore::GraphicsContext3D::GraphicsContext3D):
+        (WebCore::GraphicsContext3D::~GraphicsContext3D):
+
+        Renamed createGraphicsSurface to didResizeCanvas.
+        (WebCore::GraphicsContext3D::createGraphicsSurfaces):
+        * platform/graphics/efl/GraphicsContext3DPrivate.cpp:
+        (GraphicsContext3DPrivate::didResizeCanvas):
+        (GraphicsContext3DPrivate::copyToGraphicsSurface):
+        * platform/graphics/efl/GraphicsContext3DPrivate.h:
+        (GraphicsContext3DPrivate):
+
+        Header cleanup.
+        * platform/graphics/opengl/GLDefs.h:
+        * platform/graphics/opengl/GLPlatformContext.cpp:
+        (WebCore::GLPlatformContext::createContext):
+        * platform/graphics/opengl/GLPlatformContext.h:
+
+        Added initialize method to expose FBO id of the surface.
+        Removed unused code.
+        * platform/graphics/opengl/GLPlatformSurface.cpp:
+        (WebCore::GLPlatformSurface::initialize):
+        (WebCore):
+        (WebCore::GLPlatformSurface::updateContents):
+        * platform/graphics/opengl/GLPlatformSurface.h:
+        (GLPlatformSurface):
+        * platform/graphics/surfaces/glx/GLXSurface.h:
+
 2012-12-07  Simon Fraser  <[email protected]>
 
         Tidy up the tiled scrolling indicator, fix with zooming

Modified: trunk/Source/WebCore/platform/graphics/efl/GraphicsContext3DEfl.cpp (137210 => 137211)


--- trunk/Source/WebCore/platform/graphics/efl/GraphicsContext3DEfl.cpp	2012-12-10 22:57:42 UTC (rev 137210)
+++ trunk/Source/WebCore/platform/graphics/efl/GraphicsContext3DEfl.cpp	2012-12-10 23:01:20 UTC (rev 137211)
@@ -80,7 +80,7 @@
 
     if (renderStyle == RenderOffscreen) {
         // Create buffers for the canvas FBO.
-        glGenFramebuffers(/* count */ 1, &m_fbo);
+        m_private->m_platformSurface->initialize(&m_fbo);
 
         // Create a texture to render into.
         glGenTextures(1, &m_texture);
@@ -134,7 +134,8 @@
     glEnable(GL_POINT_SPRITE);
     glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
 #endif
-    glClearColor(0.0, 0.0, 0.0, 0.0);
+    if (renderStyle != RenderToCurrentGLContext)
+        glClearColor(0.0, 0.0, 0.0, 0.0);
 }
 
 GraphicsContext3D::~GraphicsContext3D()
@@ -142,11 +143,6 @@
     if (!m_private || !makeContextCurrent())
         return;
 
-    if (!m_fbo) {
-        m_private->releaseResources();
-        return;
-    }
-
     glDeleteTextures(1, &m_texture);
 
     if (m_attrs.antialias) {
@@ -167,7 +163,6 @@
         glDeleteRenderbuffers(1, &m_depthStencilBuffer);
     }
 
-    glDeleteFramebuffers(1, &m_fbo);
     m_private->releaseResources();
 }
 
@@ -236,9 +231,9 @@
 }
 
 #if USE(GRAPHICS_SURFACE)
-void GraphicsContext3D::createGraphicsSurfaces(const IntSize& size)
+void GraphicsContext3D::createGraphicsSurfaces(const IntSize&)
 {
-    m_private->createGraphicsSurfaces(size);
+    m_private->didResizeCanvas();
 }
 #endif
 

Modified: trunk/Source/WebCore/platform/graphics/efl/GraphicsContext3DPrivate.cpp (137210 => 137211)


--- trunk/Source/WebCore/platform/graphics/efl/GraphicsContext3DPrivate.cpp	2012-12-10 22:57:42 UTC (rev 137210)
+++ trunk/Source/WebCore/platform/graphics/efl/GraphicsContext3DPrivate.cpp	2012-12-10 23:01:20 UTC (rev 137211)
@@ -25,15 +25,7 @@
 
 #include "HostWindow.h"
 #include "NotImplemented.h"
-#include "PlatformContextCairo.h"
 
-#if USE(OPENGL_ES_2)
-#include <GLES2/gl2.h>
-#include <GLES2/gl2ext.h>
-#else
-#include "OpenGLShims.h"
-#endif
-
 namespace WebCore {
 
 GraphicsContext3DPrivate::GraphicsContext3DPrivate(GraphicsContext3D* context, HostWindow* hostWindow, GraphicsContext3D::RenderStyle renderStyle)
@@ -131,7 +123,7 @@
 #endif
 
 #if USE(GRAPHICS_SURFACE)
-void GraphicsContext3DPrivate::createGraphicsSurfaces(const IntSize&)
+void GraphicsContext3DPrivate::didResizeCanvas()
 {
     m_pendingSurfaceResize = true;
 }
@@ -146,15 +138,31 @@
         m_platformSurface->setGeometry(IntRect(0, 0, m_context->m_currentWidth, m_context->m_currentHeight));
     }
 
+    bool enableScissorTest = false;
+    int width = m_context->m_currentWidth;
+    int height = m_context->m_currentHeight;
+
+    // We should copy the full buffer, and not respect the current scissor bounds.
+    // FIXME: It would be more efficient to track the state of the scissor test.
+    if (m_context->isEnabled(GraphicsContext3D::SCISSOR_TEST)) {
+        enableScissorTest = true;
+        m_context->disable(GraphicsContext3D::SCISSOR_TEST);
+    }
+
     if (m_context->m_attrs.antialias) {
-#if !USE(OPENGL_ES_2)
+
         glBindFramebuffer(GL_READ_FRAMEBUFFER_EXT, m_context->m_multisampleFBO);
         glBindFramebuffer(GL_DRAW_FRAMEBUFFER_EXT, m_context->m_fbo);
-        glBlitFramebuffer(0, 0, m_context->m_currentWidth, m_context->m_currentHeight, 0, 0, m_context->m_currentWidth, m_context->m_currentHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR);
-#endif
+
+        // Use NEAREST as no scale is performed during the blit.
+        glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GraphicsContext3D::COLOR_BUFFER_BIT, GraphicsContext3D::NEAREST);
     }
 
-    m_platformSurface->updateContents(m_context->m_texture, IntRect(0, 0, m_context->m_currentWidth, m_context->m_currentHeight), m_context->m_boundFBO, m_context->m_boundTexture0);
+    m_platformSurface->updateContents(m_context->m_boundFBO);
+
+    if (enableScissorTest)
+        m_context->enable(GraphicsContext3D::SCISSOR_TEST);
+
     return 0;
 }
 

Modified: trunk/Source/WebCore/platform/graphics/efl/GraphicsContext3DPrivate.h (137210 => 137211)


--- trunk/Source/WebCore/platform/graphics/efl/GraphicsContext3DPrivate.h	2012-12-10 22:57:42 UTC (rev 137210)
+++ trunk/Source/WebCore/platform/graphics/efl/GraphicsContext3DPrivate.h	2012-12-10 23:01:20 UTC (rev 137211)
@@ -56,7 +56,7 @@
 #if USE(GRAPHICS_SURFACE)
     virtual uint32_t copyToGraphicsSurface();
     virtual GraphicsSurfaceToken graphicsSurfaceToken() const;
-    void createGraphicsSurfaces(const IntSize&);
+    void didResizeCanvas();
 #endif
     bool makeContextCurrent();
     void releaseResources();

Modified: trunk/Source/WebCore/platform/graphics/opengl/GLDefs.h (137210 => 137211)


--- trunk/Source/WebCore/platform/graphics/opengl/GLDefs.h	2012-12-10 22:57:42 UTC (rev 137210)
+++ trunk/Source/WebCore/platform/graphics/opengl/GLDefs.h	2012-12-10 23:01:20 UTC (rev 137211)
@@ -28,16 +28,16 @@
 
 #if USE(ACCELERATED_COMPOSITING)
 
+#include "OpenGLShims.h"
+
 #if USE(OPENGL_ES_2)
-#include "Extensions3DOpenGLES.h"
+#include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
 #else
-#include "Extensions3DOpenGL.h"
+#include <GL/gl.h>
+#include <GL/glext.h>
 #endif
 
-#include "OpenGLShims.h"
-
-#include <GL/gl.h>
-#include <GL/glext.h>
 #if HAVE(GLX)
 #include <GL/glx.h>
 #endif

Modified: trunk/Source/WebCore/platform/graphics/opengl/GLPlatformContext.cpp (137210 => 137211)


--- trunk/Source/WebCore/platform/graphics/opengl/GLPlatformContext.cpp	2012-12-10 22:57:42 UTC (rev 137210)
+++ trunk/Source/WebCore/platform/graphics/opengl/GLPlatformContext.cpp	2012-12-10 23:01:20 UTC (rev 137211)
@@ -41,18 +41,15 @@
 
 PassOwnPtr<GLPlatformContext> GLPlatformContext::createContext(GraphicsContext3D::RenderStyle renderStyle)
 {
-    static bool initializedShims = false;
+    if (!initializeOpenGLShims())
+        return nullptr;
 
-    if (!initializedShims) {
-        initializedShims = initializeOpenGLShims();
+    if (!glGetGraphicsResetStatusARB) {
 #if HAVE(GLX)
         glGetGraphicsResetStatusARB = reinterpret_cast<PFNGLGETGRAPHICSRESETSTATUSARBPROC>(glXGetProcAddressARB(reinterpret_cast<const GLubyte*>("glGetGraphicsResetStatusARB")));
 #endif
     }
 
-    if (!initializedShims)
-        return nullptr;
-
     switch (renderStyle) {
     case GraphicsContext3D::RenderOffscreen:
         if (OwnPtr<GLPlatformContext> glxContext = GLPlatformContext::createOffScreenContext())

Modified: trunk/Source/WebCore/platform/graphics/opengl/GLPlatformContext.h (137210 => 137211)


--- trunk/Source/WebCore/platform/graphics/opengl/GLPlatformContext.h	2012-12-10 22:57:42 UTC (rev 137210)
+++ trunk/Source/WebCore/platform/graphics/opengl/GLPlatformContext.h	2012-12-10 23:01:20 UTC (rev 137211)
@@ -30,6 +30,7 @@
 
 #include "GLDefs.h"
 #include "GLPlatformSurface.h"
+#include "GraphicsContext3D.h"
 #include <wtf/Noncopyable.h>
 #include <wtf/PassOwnPtr.h>
 

Modified: trunk/Source/WebCore/platform/graphics/opengl/GLPlatformSurface.cpp (137210 => 137211)


--- trunk/Source/WebCore/platform/graphics/opengl/GLPlatformSurface.cpp	2012-12-10 22:57:42 UTC (rev 137210)
+++ trunk/Source/WebCore/platform/graphics/opengl/GLPlatformSurface.cpp	2012-12-10 23:01:20 UTC (rev 137211)
@@ -72,6 +72,14 @@
 {
 }
 
+void GLPlatformSurface::initialize(GLuint* frameBufferId)
+{
+    if (!m_fboId)
+        glGenFramebuffers(1, &m_fboId);
+
+    *frameBufferId = m_fboId;
+}
+
 PlatformSurface GLPlatformSurface::handle() const
 {
     return m_drawable;
@@ -97,58 +105,23 @@
     notImplemented();
 }
 
-void GLPlatformSurface::copyTexture(uint32_t texture, const IntRect& sourceRect)
+void GLPlatformSurface::updateContents(const GLuint bindFboId)
 {
     if (!m_fboId)
-        glGenFramebuffers(1, &m_fboId);
+        return;
 
-    m_restoreNeeded = true;
-    int x = sourceRect.x();
-    int y = sourceRect.y();
-    int width = sourceRect.width();
-    int height = sourceRect.height();
-
-    glPushAttrib(GL_COLOR_BUFFER_BIT);
-
-    GLint previousFBO;
-    glGetIntegerv(GL_FRAMEBUFFER_BINDING, &previousFBO);
-
-    glBindFramebuffer(GL_READ_FRAMEBUFFER, m_fboId);
-
-    glBindTexture(GL_TEXTURE_2D, texture);
-    glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
-
-    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
-
-    glBlitFramebuffer(x, y, width, height, x, y, width, height, GL_COLOR_BUFFER_BIT, GL_LINEAR);
-
-    glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
-    glBindTexture(GL_TEXTURE_2D, 0);
-    glBindFramebuffer(GL_FRAMEBUFFER, previousFBO);
-
-    glPopAttrib();
-}
-
-void GLPlatformSurface::updateContents(const uint32_t texture, const IntRect& sourceRect, const GLuint bindFboId, const uint32_t bindTexture)
-{
     m_restoreNeeded = false;
 
-    if (!m_fboId)
-        glGenFramebuffers(1, &m_fboId);
+    int x = 0;
+    int y = 0;
+    int width = m_rect.width();
+    int height = m_rect.height();
 
-    int x = sourceRect.x();
-    int y = sourceRect.y();
-    int width = sourceRect.width();
-    int height = sourceRect.height();
-
     glBindFramebuffer(GL_READ_FRAMEBUFFER, m_fboId);
-    glBindTexture(GL_TEXTURE_2D, texture);
-    glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
     glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
-    glBlitFramebuffer(x, y, width, height, x, y, width, height, GL_COLOR_BUFFER_BIT, GL_LINEAR);
+    // Use NEAREST as no scale is performed during the blit.
+    glBlitFramebuffer(x, y, width, height, x, y, width, height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
     swapBuffers();
-    glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
-    glBindTexture(GL_TEXTURE_2D, bindTexture);
     glBindFramebuffer(GL_FRAMEBUFFER, bindFboId);
 }
 

Modified: trunk/Source/WebCore/platform/graphics/opengl/GLPlatformSurface.h (137210 => 137211)


--- trunk/Source/WebCore/platform/graphics/opengl/GLPlatformSurface.h	2012-12-10 22:57:42 UTC (rev 137210)
+++ trunk/Source/WebCore/platform/graphics/opengl/GLPlatformSurface.h	2012-12-10 23:01:20 UTC (rev 137211)
@@ -29,6 +29,7 @@
 #if USE(ACCELERATED_COMPOSITING)
 
 #include "GLDefs.h"
+#include "IntRect.h"
 #include <wtf/Noncopyable.h>
 #include <wtf/PassOwnPtr.h>
 
@@ -51,6 +52,9 @@
 
     const IntRect& geometry() const;
 
+    // Creates FBO used by the surface. Buffers can be bound to this FBO.
+    void initialize(GLuint* frameBufferId);
+
     // Get the underlying platform specific surface handle.
     PlatformSurface handle() const;
 
@@ -58,14 +62,12 @@
 
     virtual void swapBuffers();
 
-    virtual void copyTexture(uint32_t texture, const IntRect& sourceRect);
-
-    // Convenience Function to update surface backbuffer with texture contents, restore current FBO and Texture.
+    // Convenience Function to update surface contents.
     // Function does the following(in order):
-    // a)Blits texture contents to back buffer.
-    // b)Calls Swap Buffers.
-    // c)Sets current FBO as bindFboId and binds texture to bindTexture.
-    virtual void updateContents(const uint32_t texture, const IntRect& sourceRect, const GLuint bindFboId, const uint32_t bindTexture);
+    // a) Blits back buffer contents to front buffer.
+    // b) Calls Swap Buffers.
+    // c) Sets current FBO as bindFboId.
+    virtual void updateContents(const GLuint bindFboId);
 
     virtual void setGeometry(const IntRect& newRect);
 

Modified: trunk/Source/WebCore/platform/graphics/surfaces/glx/GLXSurface.h (137210 => 137211)


--- trunk/Source/WebCore/platform/graphics/surfaces/glx/GLXSurface.h	2012-12-10 22:57:42 UTC (rev 137210)
+++ trunk/Source/WebCore/platform/graphics/surfaces/glx/GLXSurface.h	2012-12-10 23:01:20 UTC (rev 137211)
@@ -34,6 +34,7 @@
 #include <X11/extensions/Xrender.h>
 #endif
 #include <wtf/Noncopyable.h>
+#include <wtf/RefCounted.h>
 
 namespace WebCore {
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to