| Differences between
and this patch
- Source/WebCore/ChangeLog +25 lines
Lines 1-3 Source/WebCore/ChangeLog_sec1
1
2013-02-09  Kondapally Kalyan  <kalyan.kondapally@intel.com>
2
3
        [EFL] [WebGL] Add support for bliting texture contents to FBO.
4
        https://bugs.webkit.org/show_bug.cgi?id=106508
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        Covered by existing WebGL tests.
9
10
        We currently rely on EXT_framebuffer_blit to blit texture contents to the surface.
11
        This extension is not exposed on GLES2.0. This patch address this by making use
12
        of TextureMapperGL to draw texture contents to the surface on both GL and GLES.
13
14
        * platform/graphics/opengl/GLPlatformSurface.cpp:
15
        (ScopedStateSaver):
16
        (WebCore::ScopedStateSaver::ScopedStateSaver):
17
        (WebCore::ScopedStateSaver::~ScopedStateSaver):
18
        (WebCore):
19
        Used to save and restore current bound Array Buffer.
20
        (WebCore::GLPlatformSurface::GLPlatformSurface):
21
        (WebCore::GLPlatformSurface::updateContents):
22
        (WebCore::GLPlatformSurface::destroy):
23
        * platform/graphics/opengl/GLPlatformSurface.h:
24
        (GLPlatformSurface):
25
1
2013-02-09  Kent Tamura  <tkent@chromium.org>
26
2013-02-09  Kent Tamura  <tkent@chromium.org>
- Source/WebCore/platform/graphics/efl/GraphicsContext3DPrivate.cpp -3 / +4 lines
Lines 140-149 uint32_t GraphicsContext3DPrivate::copyToGraphicsSurface() Source/WebCore/platform/graphics/efl/GraphicsContext3DPrivate.cpp_sec1
140
        m_platformSurface->setGeometry(IntRect(0, 0, m_context->m_currentWidth, m_context->m_currentHeight));
140
        m_platformSurface->setGeometry(IntRect(0, 0, m_context->m_currentWidth, m_context->m_currentHeight));
141
    }
141
    }
142
142
143
    int width = m_context->m_currentWidth;
144
    int height = m_context->m_currentHeight;
145
143
    if (m_context->m_attrs.antialias) {
146
    if (m_context->m_attrs.antialias) {
144
        bool enableScissorTest = false;
147
        bool enableScissorTest = false;
145
        int width = m_context->m_currentWidth;
146
        int height = m_context->m_currentHeight;
147
        // We should copy the full buffer, and not respect the current scissor bounds.
148
        // We should copy the full buffer, and not respect the current scissor bounds.
148
        // FIXME: It would be more efficient to track the state of the scissor test.
149
        // FIXME: It would be more efficient to track the state of the scissor test.
149
        if (m_context->isEnabled(GraphicsContext3D::SCISSOR_TEST)) {
150
        if (m_context->isEnabled(GraphicsContext3D::SCISSOR_TEST)) {
Lines 161-167 uint32_t GraphicsContext3DPrivate::copyToGraphicsSurface() Source/WebCore/platform/graphics/efl/GraphicsContext3DPrivate.cpp_sec2
161
            m_context->enable(GraphicsContext3D::SCISSOR_TEST);
162
            m_context->enable(GraphicsContext3D::SCISSOR_TEST);
162
    }
163
    }
163
164
164
    m_platformSurface->updateContents(m_context->m_texture, m_context->m_boundFBO, m_context->m_boundTexture0);
165
    m_platformSurface->updateContents(m_context->m_texture, IntSize(width, height), m_context->m_boundFBO, m_context->m_boundTexture0);
165
166
166
    return 0;
167
    return 0;
167
}
168
}
- Source/WebCore/platform/graphics/opengl/GLPlatformSurface.cpp -26 / +62 lines
Lines 28-34 Source/WebCore/platform/graphics/opengl/GLPlatformSurface.cpp_sec1
28
28
29
#if USE(ACCELERATED_COMPOSITING)
29
#if USE(ACCELERATED_COMPOSITING)
30
30
31
#if HAVE(GLX)
31
#if USE(GLX)
32
#include "GLXSurface.h"
32
#include "GLXSurface.h"
33
#endif
33
#endif
34
34
Lines 68-79 PassOwnPtr<GLPlatformSurface> GLPlatformSurface::createTransportSurface() Source/WebCore/platform/graphics/opengl/GLPlatformSurface.cpp_sec2
68
    return nullptr;
68
    return nullptr;
69
}
69
}
70
70
71
class ScopedStateSaver {
72
    WTF_MAKE_NONCOPYABLE(ScopedStateSaver);
73
74
public:
75
    ScopedStateSaver()
76
    {
77
        ::glGetIntegerv(GL_ACTIVE_TEXTURE, &m_boundTexUnit);
78
        ::glGetVertexAttribiv(0, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &m_attribEnabled);
79
        ::glGetVertexAttribiv(0, GL_VERTEX_ATTRIB_ARRAY_SIZE, &m_attribSize);
80
        ::glGetVertexAttribiv(0, GL_VERTEX_ATTRIB_ARRAY_STRIDE, &m_attribStride);
81
        ::glGetVertexAttribiv(0, GL_VERTEX_ATTRIB_ARRAY_TYPE, &m_attribType);
82
        ::glGetVertexAttribiv(0, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, &m_attribNormalized);
83
        ::glGetVertexAttribiv(0, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, &m_attribBufferBinding);
84
        ::glGetVertexAttribPointerv(0, GL_VERTEX_ATTRIB_ARRAY_POINTER, &m_attribPointer);
85
        ::glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &m_currentArrayBufferBinding);
86
        ::glActiveTexture(GL_TEXTURE0);
87
    }
88
89
    ~ScopedStateSaver()
90
    {
91
        if (m_attribEnabled)
92
            ::glEnableVertexAttribArray(0);
93
94
        ::glBindBuffer(GL_ARRAY_BUFFER, m_attribBufferBinding);
95
        ::glVertexAttribPointer(0, m_attribSize, m_attribType, m_attribNormalized, m_attribStride, m_attribPointer);
96
        ::glBindBuffer(GL_ARRAY_BUFFER, m_currentArrayBufferBinding);
97
        ::glActiveTexture(m_boundTexUnit);
98
    }
99
100
private:
101
    GLint m_boundTexUnit;
102
    GLint m_boundProgram;
103
    GLint m_currentArrayBufferBinding;
104
    GLint m_attribEnabled;
105
    GLint m_attribSize;
106
    GLint m_attribStride;
107
    GLint m_attribType;
108
    GLint m_attribNormalized;
109
    GLint m_attribBufferBinding;
110
    void* m_attribPointer;
111
};
112
71
GLPlatformSurface::GLPlatformSurface()
113
GLPlatformSurface::GLPlatformSurface()
72
    : m_restoreNeeded(true)
114
    : m_sharedDisplay(0)
73
    , m_fboId(0)
74
    , m_sharedDisplay(0)
75
    , m_drawable(0)
115
    , m_drawable(0)
76
    , m_bufferHandle(0)
116
    , m_bufferHandle(0)
117
    , m_restoreNeeded(true)
77
{
118
{
78
}
119
}
79
120
Lines 111-138 void GLPlatformSurface::swapBuffers() Source/WebCore/platform/graphics/opengl/GLPlatformSurface.cpp_sec3
111
    notImplemented();
152
    notImplemented();
112
}
153
}
113
154
114
void GLPlatformSurface::updateContents(const uint32_t texture, const GLuint bindFboId, const uint32_t bindTexture)
155
void GLPlatformSurface::updateContents(const uint32_t texture, const IntSize& textureSize, const GLuint bindFboId, const uint32_t bindTexture)
115
{
156
{
116
    if (!m_fboId)
157
    if (!m_textureBlitter) {
117
        glGenFramebuffers(1, &m_fboId);
158
        m_textureBlitter = TextureMapperGL::create();
159
        m_flags = TextureMapperGL::ShouldFlipTexture;
160
    }
118
161
119
    m_restoreNeeded = false;
162
    m_restoreNeeded = false;
120
163
121
    int x = 0;
164
    // Save any current bound vertex array to restore after updating surface with texture content.
122
    int y = 0;
165
    // This is needed as TextureMapperGL doesn't track and restore current bound vertex array.
123
    int width = m_rect.width();
166
    ScopedStateSaver stateSaver;
124
    int height = m_rect.height();
167
    ::glBindFramebuffer(GL_FRAMEBUFFER, 0);
125
168
126
    glBindFramebuffer(GL_READ_FRAMEBUFFER, m_fboId);
169
    m_textureBlitter->beginPainting();
127
    glBindTexture(GL_TEXTURE_2D, texture);
170
    m_textureBlitter->drawTexture(texture, m_flags, textureSize, m_rect, m_identityMatrix, 1.0, 0);
128
    glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
171
    m_textureBlitter->endPainting();
129
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
172
130
    // Use NEAREST as no scale is performed during the blit.
173
    ::glFlush();
131
    glBlitFramebuffer(x, y, width, height, x, y, width, height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
132
    swapBuffers();
174
    swapBuffers();
133
    glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
175
    ::glBindTexture(GL_TEXTURE_2D, bindTexture);
134
    glBindTexture(GL_TEXTURE_2D, bindTexture);
176
    ::glBindFramebuffer(GL_FRAMEBUFFER, bindFboId);
135
    glBindFramebuffer(GL_FRAMEBUFFER, bindFboId);
136
}
177
}
137
178
138
void GLPlatformSurface::setGeometry(const IntRect& newRect)
179
void GLPlatformSurface::setGeometry(const IntRect& newRect)
Lines 143-153 void GLPlatformSurface::setGeometry(const IntRect& newRect) Source/WebCore/platform/graphics/opengl/GLPlatformSurface.cpp_sec4
143
void GLPlatformSurface::destroy()
184
void GLPlatformSurface::destroy()
144
{
185
{
145
    m_rect = IntRect();
186
    m_rect = IntRect();
146
147
    if (m_fboId)
148
        glDeleteFramebuffers(1, &m_fboId);
149
150
    m_fboId = 0;
151
}
187
}
152
188
153
}
189
}
- Source/WebCore/platform/graphics/opengl/GLPlatformSurface.h -4 / +7 lines
Lines 30-35 Source/WebCore/platform/graphics/opengl/GLPlatformSurface.h_sec1
30
30
31
#include "GLDefs.h"
31
#include "GLDefs.h"
32
#include "IntRect.h"
32
#include "IntRect.h"
33
#include <texmap/TextureMapperGL.h>
33
#include <wtf/Noncopyable.h>
34
#include <wtf/Noncopyable.h>
34
#include <wtf/PassOwnPtr.h>
35
#include <wtf/PassOwnPtr.h>
35
36
Lines 66-72 public: Source/WebCore/platform/graphics/opengl/GLPlatformSurface.h_sec2
66
    // a) Blits texture contents to back buffer.
67
    // a) Blits texture contents to back buffer.
67
    // b) Calls Swap Buffers.
68
    // b) Calls Swap Buffers.
68
    // c) Sets current FBO as bindFboId.
69
    // c) Sets current FBO as bindFboId.
69
    virtual void updateContents(const uint32_t texture, const GLuint bindFboId, const uint32_t bindTexture);
70
    virtual void updateContents(const uint32_t texture, const IntSize&, const GLuint bindFboId, const uint32_t bindTexture);
70
71
71
    virtual void setGeometry(const IntRect& newRect);
72
    virtual void setGeometry(const IntRect& newRect);
72
73
Lines 76-87 public: Source/WebCore/platform/graphics/opengl/GLPlatformSurface.h_sec3
76
77
77
protected:
78
protected:
78
    GLPlatformSurface();
79
    GLPlatformSurface();
79
    bool m_restoreNeeded;
80
    IntRect m_rect;
81
    GLuint m_fboId;
82
    PlatformDisplay m_sharedDisplay;
80
    PlatformDisplay m_sharedDisplay;
83
    PlatformDrawable m_drawable;
81
    PlatformDrawable m_drawable;
84
    PlatformBufferHandle m_bufferHandle;
82
    PlatformBufferHandle m_bufferHandle;
83
    OwnPtr<TextureMapperGL> m_textureBlitter;
84
    bool m_restoreNeeded :1;
85
    IntRect m_rect;
86
    TransformationMatrix m_identityMatrix;
87
    TextureMapperGL::Flags m_flags;
85
};
88
};
86
89
87
}
90
}

Return to Bug 106508