Changeset 122116 in webkit


Ignore:
Timestamp:
Jul 9, 2012 11:00:11 AM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Make GC3D and E3D more maintainable for GLES platforms
https://bugs.webkit.org/show_bug.cgi?id=90567

Patch by Joshua Netterfield <jnetterfield@rim.com> on 2012-07-09
Reviewed by Rob Buis.

This patch cleans up code for WebGL on OpenGLES platforms which use
GraphicsContext3DOpenGL* and Extensions3DOpenGL*. Although
GraphicsContext3DOpenGL was already split into GraphicsContext3DOpenGL,
GraphicsContext3DOpenGLCommon, and GraphicsContext3DOpenGLES, this patch
is an attempt to refactor this code in a way that will help BlackBerry and
other teams support WebGL on mobile platforms with as little use of
"#IF USE(OPENGL_ES_2)" in common code as possible. Also included is the
separation of Extensions3DOpenGL into Extensions3DOpenGLCommon,
Extensions3DOpenGL, and Extensions3DOpenGLES as well as the introduction
of OpenGLESShims.

This patch is created in large part by Jonathan Feldstein.

No new tests: no new behaviour.

  • PlatformBlackBerry.cmake: Recognize BlackBerry as OPENGL ES, add new files to build
  • Target.pri: Add new Extensions3DOpenGL* to WebGL builds
  • platform/graphics/GraphicsContext3D.h: Add validateDepthStencil, make systemAllowsMultisamplingOnATICards a a member function.

(WebCore):

  • platform/graphics/OpenGLESShims.h: Added.
  • platform/graphics/opengl/Extensions3DOpenGL.cpp: Move code to Extensions3DOpenGLCommon where possible

(WebCore::Extensions3DOpenGL::Extensions3DOpenGL): Reflect that it is now inherits Extensions3DCommon
(WebCore::Extensions3DOpenGL::supportsExtension): Contains OpenGL specific code from supports
(WebCore):
(WebCore::Extensions3DOpenGL::getExtensions): Returns a list of extensions

  • platform/graphics/opengl/Extensions3DOpenGL.h: Remove functions now in Extensions3DOpenGLCommon

(WebCore):
(Extensions3DOpenGL):

  • platform/graphics/opengl/Extensions3DOpenGLCommon.cpp: Added.

(WebCore):
(WebCore::Extensions3DOpenGLCommon::Extensions3DOpenGLCommon):
(WebCore::Extensions3DOpenGLCommon::~Extensions3DOpenGLCommon):
(WebCore::Extensions3DOpenGLCommon::supports):
(WebCore::Extensions3DOpenGLCommon::ensureEnabled):
(WebCore::Extensions3DOpenGLCommon::isEnabled):
(WebCore::Extensions3DOpenGLCommon::getGraphicsResetStatusARB):
(WebCore::Extensions3DOpenGLCommon::getTranslatedShaderSourceANGLE): Existed before, but did nothing. Now does what is says it does.
(WebCore::Extensions3DOpenGLCommon::initializeAvailableExtensions): Moved from Extensions3DOpenGL::supports

  • platform/graphics/opengl/Extensions3DOpenGLCommon.h: Copied from Source/WebCore/platform/graphics/opengl/Extensions3DOpenGL.h.

(WebCore):
(Extensions3DOpenGLCommon):

  • platform/graphics/opengl/Extensions3DOpenGLES.cpp: Added.

(WebCore):
(WebCore::Extensions3DOpenGLES::Extensions3DOpenGLES):
(WebCore::Extensions3DOpenGLES::~Extensions3DOpenGLES):
(WebCore::Extensions3DOpenGLES::framebufferTexture2DMultisampleIMG):
(WebCore::Extensions3DOpenGLES::renderbufferStorageMultisampleIMG):
(WebCore::Extensions3DOpenGLES::createVertexArrayOES):
(WebCore::Extensions3DOpenGLES::deleteVertexArrayOES):
(WebCore::Extensions3DOpenGLES::isVertexArrayOES):
(WebCore::Extensions3DOpenGLES::bindVertexArrayOES):
(WebCore::Extensions3DOpenGLES::supportsExtension): Contains OpenGLES specific code from supports
(WebCore::Extensions3DOpenGLES::getExtensions):

  • platform/graphics/opengl/Extensions3DOpenGLES.h: Copied from Source/WebCore/platform/graphics/opengl/Extensions3DOpenGL.h.

(WebCore):
(Extensions3DOpenGLES):

  • platform/graphics/opengl/GraphicsContext3DOpenGL.cpp:

(WebCore::GraphicsContext3D::validateAttributes):
(WebCore):
(WebCore::GraphicsContext3D::renderbufferStorage):
(WebCore::GraphicsContext3D::texImage2D):
(WebCore::GraphicsContext3D::systemAllowsMultisamplingOnATICards): Now a member function.
(WebCore::GraphicsContext3D::getExtensions):

  • platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp:

(WebCore::GraphicsContext3D::validateDepthStencil):
(WebCore::GraphicsContext3D::clear):
(WebCore::GraphicsContext3D::isTexture):
(WebCore):
(WebCore::GraphicsContext3D::lineWidth):
(WebCore::GraphicsContext3D::linkProgram):
(WebCore::GraphicsContext3D::pixelStorei):
(WebCore::GraphicsContext3D::polygonOffset):
(WebCore::GraphicsContext3D::readPixels):
(WebCore::GraphicsContext3D::deleteBuffer):

  • platform/graphics/opengl/GraphicsContext3DOpenGLES.cpp:

(WebCore::GraphicsContext3D::releaseShaderCompiler):
(WebCore::GraphicsContext3D::readPixelsAndConvertToBGRAIfNecessary):
(WebCore::GraphicsContext3D::validateAttributes):
(WebCore):
(WebCore::GraphicsContext3D::getExtensions):
(WebCore::GraphicsContext3D::systemAllowsMultisamplingOnATICards): Now a member function.

  • platform/graphics/qt/GraphicsContext3DQt.cpp:

(WebCore):
(WebCore::GraphicsContext3D::releaseShaderCompiler):

Location:
trunk/Source/WebCore
Files:
3 added
16 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r122115 r122116  
     12012-07-09  Joshua Netterfield  <jnetterfield@rim.com>
     2        Make GC3D and E3D more maintainable for GLES platforms
     3        https://bugs.webkit.org/show_bug.cgi?id=90567
     4
     5        Reviewed by Rob Buis.
     6
     7        This patch cleans up code for WebGL on OpenGLES platforms which use
     8        GraphicsContext3DOpenGL* and Extensions3DOpenGL*. Although
     9        GraphicsContext3DOpenGL was already split into GraphicsContext3DOpenGL,
     10        GraphicsContext3DOpenGLCommon, and  GraphicsContext3DOpenGLES, this patch
     11        is an attempt to refactor this code in a way that will help BlackBerry and
     12        other teams support WebGL on mobile platforms with as little use of
     13        "#IF USE(OPENGL_ES_2)" in common code as possible. Also included is the
     14        separation of Extensions3DOpenGL into Extensions3DOpenGLCommon,
     15        Extensions3DOpenGL, and Extensions3DOpenGLES as well as the introduction
     16        of OpenGLESShims.
     17
     18        This patch is created in large part by Jonathan Feldstein.
     19
     20        No new tests: no new behaviour.
     21
     22        * PlatformBlackBerry.cmake: Recognize BlackBerry as OPENGL ES, add new files to build
     23        * Target.pri: Add new Extensions3DOpenGL* to WebGL builds
     24        * platform/graphics/GraphicsContext3D.h: Add validateDepthStencil, make systemAllowsMultisamplingOnATICards a a member function.
     25        (WebCore):
     26        * platform/graphics/OpenGLESShims.h: Added.
     27        * platform/graphics/opengl/Extensions3DOpenGL.cpp: Move code to Extensions3DOpenGLCommon where possible
     28        (WebCore::Extensions3DOpenGL::Extensions3DOpenGL): Reflect that it is now inherits Extensions3DCommon
     29        (WebCore::Extensions3DOpenGL::supportsExtension): Contains OpenGL specific code from supports
     30        (WebCore):
     31        (WebCore::Extensions3DOpenGL::getExtensions): Returns a list of extensions
     32        * platform/graphics/opengl/Extensions3DOpenGL.h: Remove functions now in Extensions3DOpenGLCommon
     33        (WebCore):
     34        (Extensions3DOpenGL):
     35        * platform/graphics/opengl/Extensions3DOpenGLCommon.cpp: Added.
     36        (WebCore):
     37        (WebCore::Extensions3DOpenGLCommon::Extensions3DOpenGLCommon):
     38        (WebCore::Extensions3DOpenGLCommon::~Extensions3DOpenGLCommon):
     39        (WebCore::Extensions3DOpenGLCommon::supports):
     40        (WebCore::Extensions3DOpenGLCommon::ensureEnabled):
     41        (WebCore::Extensions3DOpenGLCommon::isEnabled):
     42        (WebCore::Extensions3DOpenGLCommon::getGraphicsResetStatusARB):
     43        (WebCore::Extensions3DOpenGLCommon::getTranslatedShaderSourceANGLE): Existed before, but did nothing. Now does what is says it does.
     44        (WebCore::Extensions3DOpenGLCommon::initializeAvailableExtensions): Moved from Extensions3DOpenGL::supports
     45        * platform/graphics/opengl/Extensions3DOpenGLCommon.h: Copied from Source/WebCore/platform/graphics/opengl/Extensions3DOpenGL.h.
     46        (WebCore):
     47        (Extensions3DOpenGLCommon):
     48        * platform/graphics/opengl/Extensions3DOpenGLES.cpp: Added.
     49        (WebCore):
     50        (WebCore::Extensions3DOpenGLES::Extensions3DOpenGLES):
     51        (WebCore::Extensions3DOpenGLES::~Extensions3DOpenGLES):
     52        (WebCore::Extensions3DOpenGLES::framebufferTexture2DMultisampleIMG):
     53        (WebCore::Extensions3DOpenGLES::renderbufferStorageMultisampleIMG):
     54        (WebCore::Extensions3DOpenGLES::createVertexArrayOES):
     55        (WebCore::Extensions3DOpenGLES::deleteVertexArrayOES):
     56        (WebCore::Extensions3DOpenGLES::isVertexArrayOES):
     57        (WebCore::Extensions3DOpenGLES::bindVertexArrayOES):
     58        (WebCore::Extensions3DOpenGLES::supportsExtension): Contains OpenGLES specific code from supports
     59        (WebCore::Extensions3DOpenGLES::getExtensions):
     60        * platform/graphics/opengl/Extensions3DOpenGLES.h: Copied from Source/WebCore/platform/graphics/opengl/Extensions3DOpenGL.h.
     61        (WebCore):
     62        (Extensions3DOpenGLES):
     63        * platform/graphics/opengl/GraphicsContext3DOpenGL.cpp:
     64        (WebCore::GraphicsContext3D::validateAttributes):
     65        (WebCore):
     66        (WebCore::GraphicsContext3D::renderbufferStorage):
     67        (WebCore::GraphicsContext3D::texImage2D):
     68        (WebCore::GraphicsContext3D::systemAllowsMultisamplingOnATICards): Now a member function.
     69        (WebCore::GraphicsContext3D::getExtensions):
     70        * platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp:
     71        (WebCore::GraphicsContext3D::validateDepthStencil):
     72        (WebCore::GraphicsContext3D::clear):
     73        (WebCore::GraphicsContext3D::isTexture):
     74        (WebCore):
     75        (WebCore::GraphicsContext3D::lineWidth):
     76        (WebCore::GraphicsContext3D::linkProgram):
     77        (WebCore::GraphicsContext3D::pixelStorei):
     78        (WebCore::GraphicsContext3D::polygonOffset):
     79        (WebCore::GraphicsContext3D::readPixels):
     80        (WebCore::GraphicsContext3D::deleteBuffer):
     81        * platform/graphics/opengl/GraphicsContext3DOpenGLES.cpp:
     82        (WebCore::GraphicsContext3D::releaseShaderCompiler):
     83        (WebCore::GraphicsContext3D::readPixelsAndConvertToBGRAIfNecessary):
     84        (WebCore::GraphicsContext3D::validateAttributes):
     85        (WebCore):
     86        (WebCore::GraphicsContext3D::getExtensions):
     87        (WebCore::GraphicsContext3D::systemAllowsMultisamplingOnATICards): Now a member function.
     88        * platform/graphics/qt/GraphicsContext3DQt.cpp:
     89        (WebCore):
     90        (WebCore::GraphicsContext3D::releaseShaderCompiler):
     91
    1922012-07-02  Ryosuke Niwa  <rniwa@webkit.org>
    293
  • trunk/Source/WebCore/GNUmakefile.list.am

    r121900 r122116  
    60556055        Source/WebCore/platform/graphics/OpenGLShims.h \
    60566056        Source/WebCore/platform/graphics/opengl/Extensions3DOpenGL.cpp \
     6057        Source/WebCore/platform/graphics/opengl/Extensions3DOpenGLCommon.cpp \
    60576058        Source/WebCore/platform/graphics/opengl/Extensions3DOpenGL.h \
    60586059        Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGL.cpp \
  • trunk/Source/WebCore/PlatformBlackBerry.cmake

    r121857 r122116  
    219219
    220220if (ENABLE_WEBGL)
     221    ADD_DEFINITIONS (-DWTF_USE_OPENGL_ES_2=1)
    221222    LIST(APPEND WebCore_INCLUDE_DIRECTORIES
    222223        "${WEBCORE_DIR}/platform/graphics/gpu"
     
    226227        platform/graphics/blackberry/DrawingBufferBlackBerry.cpp
    227228        platform/graphics/blackberry/GraphicsContext3DBlackBerry.cpp
     229        platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp
     230        platform/graphics/opengl/GraphicsContext3DOpenGLES.cpp
     231        platform/graphics/opengl/Extensions3DOpenGLCommon.cpp
     232        platform/graphics/opengl/Extensions3DOpenGLES.cpp
     233        platform/graphics/gpu/SharedGraphicsContext3D.cpp
    228234    )
    229235ENDIF ()
  • trunk/Source/WebCore/Target.pri

    r122110 r122116  
    39573957    contains(QT_CONFIG, opengl) | contains(QT_CONFIG, opengles2) {
    39583958        !contains(QT_CONFIG, opengles2) {
    3959             SOURCES += platform/graphics/opengl/GraphicsContext3DOpenGL.cpp
     3959            SOURCES += \
     3960               platform/graphics/opengl/GraphicsContext3DOpenGL.cpp \
     3961               platform/graphics/opengl/Extensions3DOpenGL.cpp
    39603962        } else {
    3961             SOURCES += platform/graphics/opengl/GraphicsContext3DOpenGLES.cpp
     3963            SOURCES += \
     3964               platform/graphics/opengl/GraphicsContext3DOpenGLES.cpp \
     3965               platform/graphics/opengl/Extensions3DOpenGLES.cpp
    39623966        }
    39633967
     
    39653969
    39663970        SOURCES += \
    3967             platform/graphics/opengl/Extensions3DOpenGL.cpp \
     3971            platform/graphics/opengl/Extensions3DOpenGLCommon.cpp \
    39683972            platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp
    39693973
  • trunk/Source/WebCore/WebCore.gypi

    r122110 r122116  
    38083808            'platform/graphics/mac/WebTiledLayer.mm',
    38093809            'platform/graphics/opengl/Extensions3DOpenGL.cpp',
     3810            'platform/graphics/opengl/Extensions3DOpenGLCommon.cpp',
    38103811            'platform/graphics/opengl/Extensions3DOpenGL.h',
    38113812            'platform/graphics/opengl/GraphicsContext3DOpenGL.cpp',
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r122110 r122116  
    11921192                44A28AAC12DFB8AC00AE923B /* MathMLElementFactory.h in Headers */ = {isa = PBXBuildFile; fileRef = 44A28AAB12DFB8AC00AE923B /* MathMLElementFactory.h */; };
    11931193                44A28AAF12DFB8BF00AE923B /* MathMLNames.h in Headers */ = {isa = PBXBuildFile; fileRef = 44A28AAE12DFB8BF00AE923B /* MathMLNames.h */; };
     1194                44DAB5B115A623580097C1E4 /* Extensions3DOpenGLCommon.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 44DAB5AF15A623580097C1E4 /* Extensions3DOpenGLCommon.cpp */; };
     1195                44DAB5B215A623580097C1E4 /* Extensions3DOpenGLCommon.h in Headers */ = {isa = PBXBuildFile; fileRef = 44DAB5B015A623580097C1E4 /* Extensions3DOpenGLCommon.h */; };
    11941196                45099C411370A7800058D513 /* IconURL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 45099C401370A7800058D513 /* IconURL.cpp */; };
    11951197                450CEBF015073BBE002BB149 /* LabelableElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 450CEBEE15073BBE002BB149 /* LabelableElement.cpp */; };
     
    82488250                44D8DA98139545BE00337B75 /* SVGMPathElement.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = SVGMPathElement.idl; sourceTree = "<group>"; };
    82498251                44D8DA9A139545CD00337B75 /* SVGAnimateMotionElement.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = SVGAnimateMotionElement.idl; sourceTree = "<group>"; };
     8252                44DAB5AF15A623580097C1E4 /* Extensions3DOpenGLCommon.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Extensions3DOpenGLCommon.cpp; sourceTree = "<group>"; };
     8253                44DAB5B015A623580097C1E4 /* Extensions3DOpenGLCommon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Extensions3DOpenGLCommon.h; sourceTree = "<group>"; };
    82508254                45099C401370A7800058D513 /* IconURL.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IconURL.cpp; sourceTree = "<group>"; };
    82518255                450CEBEE15073BBE002BB149 /* LabelableElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LabelableElement.cpp; sourceTree = "<group>"; };
     
    2164721651                        isa = PBXGroup;
    2164821652                        children = (
     21653                                44DAB5AF15A623580097C1E4 /* Extensions3DOpenGLCommon.cpp */,
     21654                                44DAB5B015A623580097C1E4 /* Extensions3DOpenGLCommon.h */,
    2164921655                                6E67D2A41280E8A4008758F7 /* Extensions3DOpenGL.cpp */,
    2165021656                                6E67D2A51280E8A4008758F7 /* Extensions3DOpenGL.h */,
     
    2518025186                                A882DA231593848D000115ED /* CSSToStyleMap.h in Headers */,
    2518125187                                1FAFBF1915A5FA7400083A20 /* UTIUtilities.h in Headers */,
     25188                                44DAB5B215A623580097C1E4 /* Extensions3DOpenGLCommon.h in Headers */,
    2518225189                        );
    2518325190                        runOnlyForDeploymentPostprocessing = 0;
     
    2823528242                                A882DA201593846A000115ED /* CSSToStyleMap.cpp in Sources */,
    2823628243                                1FAFBF1815A5FA6E00083A20 /* UTIUtilities.mm in Sources */,
     28244                                44DAB5B115A623580097C1E4 /* Extensions3DOpenGLCommon.cpp in Sources */,
    2823728245                        );
    2823828246                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h

    r121159 r122116  
    2121 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    2222 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
     23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2424 */
    2525
     
    9292#endif
    9393
    94 #if PLATFORM(BLACKBERRY)
    95 #include <GLES2/gl2.h>
    96 #endif
    97 
    9894namespace WebCore {
    9995class DrawingBuffer;
    10096class Extensions3D;
    101 #if PLATFORM(MAC) || PLATFORM(GTK) || PLATFORM(QT) || PLATFORM(EFL)
     97#if USE(OPENGL_ES_2)
     98class Extensions3DOpenGLES;
     99#else
    102100class Extensions3DOpenGL;
    103101#endif
     
    925923    // could not be honored based on the capabilities of the OpenGL
    926924    // implementation.
     925    void validateDepthStencil(const char* packedDepthStencilExtension);
    927926    void validateAttributes();
    928927
     
    956955
    957956    ANGLEWebKitBridge m_compiler;
    958 
     957#endif
     958
     959#if PLATFORM(QT) && defined(QT_OPENGL_ES_2)
     960    friend class Extensions3DQt;
     961    OwnPtr<Extensions3DQt> m_extensions;
     962#elif PLATFORM(BLACKBERRY)
     963    friend class Extensions3DOpenGLES;
     964    OwnPtr<Extensions3DOpenGLES> m_extensions;
     965#elif !PLATFORM(CHROMIUM)
    959966    friend class Extensions3DOpenGL;
    960967    OwnPtr<Extensions3DOpenGL> m_extensions;
     968#endif
     969    friend class Extensions3DOpenGLCommon;
    961970
    962971    Attributes m_attrs;
    963972    Vector<Vector<float> > m_vertexArray;
    964973
    965     GC3Duint m_texture, m_compositorTexture;
     974    GC3Duint m_texture;
     975#if !PLATFORM(BLACKBERRY)
     976    GC3Duint m_compositorTexture;
     977#endif
    966978    GC3Duint m_fbo;
    967 #if USE(OPENGL_ES_2)
     979
     980#if !PLATFORM(BLACKBERRY)
    968981    GC3Duint m_depthBuffer;
    969982    GC3Duint m_stencilBuffer;
     
    986999    // Errors raised by synthesizeGLError().
    9871000    ListHashSet<GC3Denum> m_syntheticErrors;
    988 #endif
    9891001
    9901002    friend class GraphicsContext3DPrivate;
    9911003    OwnPtr<GraphicsContext3DPrivate> m_private;
     1004
     1005    bool systemAllowsMultisamplingOnATICards() const;
    9921006};
    9931007
  • trunk/Source/WebCore/platform/graphics/cairo/GraphicsContext3DCairo.cpp

    r120826 r122116  
    3434#include "GraphicsContext3DPrivate.h"
    3535#include "Image.h"
     36#include "NotImplemented.h"
    3637#include "OpenGLShims.h"
    3738#include "PlatformContextCairo.h"
     
    145146    }
    146147    ::glDeleteFramebuffersEXT(1, &m_fbo);
     148}
     149
     150void GraphicsContext3D::releaseShaderCompiler()
     151{
     152    notImplemented();
    147153}
    148154
  • trunk/Source/WebCore/platform/graphics/clutter/GraphicsContext3DClutter.cpp

    r112141 r122116  
    5757}
    5858
     59void GraphicsContext3D::releaseShaderCompiler()
     60{
     61    notImplemented();
     62}
     63
    5964bool GraphicsContext3D::getImageData(Image* image, unsigned int format, unsigned int type, bool premultiplyAlpha, bool ignoreGammaAndColorProfile, Vector<uint8_t>& outputVector)
    6065{
  • trunk/Source/WebCore/platform/graphics/mac/GraphicsContext3DMac.mm

    r118225 r122116  
    283283}
    284284
     285void GraphicsContext3D::releaseShaderCompiler()
     286{
     287    notImplemented();
     288}
     289
    285290}
    286291
  • trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGL.cpp

    r121055 r122116  
    4343
    4444Extensions3DOpenGL::Extensions3DOpenGL(GraphicsContext3D* context)
    45     : m_initializedAvailableExtensions(false)
     45    : Extensions3DOpenGLCommon(context)
     46    , m_initializedAvailableExtensions(false)
    4647    , m_context(context)
    4748{
     
    5253}
    5354
    54 bool Extensions3DOpenGL::supports(const String& name)
    55 {
    56     // Note on support for BGRA:
    57     //
    58     // For OpenGL ES2.0, requires checking for
    59     // GL_EXT_texture_format_BGRA8888 and GL_EXT_read_format_bgra.
    60     // For desktop GL, BGRA has been supported since OpenGL 1.2.
    61     //
    62     // However, note that the GL ES2 extension requires the
    63     // internalFormat to glTexImage2D() be GL_BGRA, while desktop GL
    64     // will not accept GL_BGRA (must be GL_RGBA), so this must be
    65     // checked on each platform. Desktop GL offers neither
    66     // GL_EXT_texture_format_BGRA8888 or GL_EXT_read_format_bgra, so
    67     // treat them as unsupported here.
    68     if (!m_initializedAvailableExtensions) {
    69         String extensionsString(reinterpret_cast<const char*>(::glGetString(GL_EXTENSIONS)));
    70         Vector<String> availableExtensions;
    71         extensionsString.split(" ", availableExtensions);
    72         for (size_t i = 0; i < availableExtensions.size(); ++i)
    73             m_availableExtensions.add(availableExtensions[i]);
    74         m_initializedAvailableExtensions = true;
    75     }
    76    
    77     // GL_ANGLE_framebuffer_blit and GL_ANGLE_framebuffer_multisample are "fake". They are implemented using other
    78     // extensions. In particular GL_EXT_framebuffer_blit and GL_EXT_framebuffer_multisample
    79     if (name == "GL_ANGLE_framebuffer_blit")
    80         return m_availableExtensions.contains("GL_EXT_framebuffer_blit");
    81     if (name == "GL_ANGLE_framebuffer_multisample")
    82         return m_availableExtensions.contains("GL_EXT_framebuffer_multisample");
    83 
    84     // Desktop GL always supports GL_OES_rgb8_rgba8.
    85     if (name == "GL_OES_rgb8_rgba8")
    86         return true;
    87 
    88     // If GL_ARB_texture_float is available then we report GL_OES_texture_float and
    89     // GL_OES_texture_half_float as available.
    90     if (name == "GL_OES_texture_float" || name == "GL_OES_texture_half_float")
    91         return m_availableExtensions.contains("GL_ARB_texture_float");
    92    
    93     // GL_OES_vertex_array_object
    94     if (name == "GL_OES_vertex_array_object")
    95         return m_availableExtensions.contains("GL_APPLE_vertex_array_object");
    96 
    97     // Desktop GL always supports the standard derivative functions
    98     if (name == "GL_OES_standard_derivatives")
    99         return true;
    100 
    101     if (name == "GL_EXT_texture_filter_anisotropic")
    102         return m_availableExtensions.contains("GL_EXT_texture_filter_anisotropic");
    103 
    104     return m_availableExtensions.contains(name);
    105 }
    106 
    107 void Extensions3DOpenGL::ensureEnabled(const String& name)
    108 {
    109 #if PLATFORM(MAC) || PLATFORM(QT) || PLATFORM(GTK)
    110     if (name == "GL_OES_standard_derivatives") {
    111         // Enable support in ANGLE (if not enabled already)
    112         ANGLEWebKitBridge& compiler = m_context->m_compiler;
    113         ShBuiltInResources ANGLEResources = compiler.getResources();
    114         if (!ANGLEResources.OES_standard_derivatives) {
    115             ANGLEResources.OES_standard_derivatives = 1;
    116             compiler.setResources(ANGLEResources);
    117         }
    118     }
    119 #else
    120     ASSERT_UNUSED(name, supports(name));
    121 #endif
    122 }
    123 
    124 bool Extensions3DOpenGL::isEnabled(const String& name)
    125 {
    126 #if PLATFORM(MAC) || PLATFORM(QT) || PLATFORM(GTK)
    127     if (name == "GL_OES_standard_derivatives") {
    128         ANGLEWebKitBridge& compiler = m_context->m_compiler;
    129         return compiler.getResources().OES_standard_derivatives;
    130     }
    131 #endif
    132     return supports(name);
    133 }
    134 
    135 int Extensions3DOpenGL::getGraphicsResetStatusARB()
    136 {
    137     return GraphicsContext3D::NO_ERROR;
    138 }
    13955
    14056void Extensions3DOpenGL::blitFramebuffer(long srcX0, long srcY0, long srcX1, long srcY1, long dstX0, long dstY0, long dstX1, long dstY1, unsigned long mask, unsigned long filter)
     
    195111}
    196112
    197 String Extensions3DOpenGL::getTranslatedShaderSourceANGLE(Platform3DObject shader)
    198 {
    199     UNUSED_PARAM(shader);
    200     return "";
    201     // FIXME: implement this function and add GL_ANGLE_translated_shader_source in supports().
    202 }
    203 
    204113void Extensions3DOpenGL::copyTextureCHROMIUM(GC3Denum, Platform3DObject, Platform3DObject, GC3Dint, GC3Denum)
    205114{
     
    208117}
    209118
     119bool Extensions3DOpenGL::supportsExtension(const String& name)
     120{
     121    // GL_ANGLE_framebuffer_blit and GL_ANGLE_framebuffer_multisample are "fake". They are implemented using other
     122    // extensions. In particular GL_EXT_framebuffer_blit and GL_EXT_framebuffer_multisample
     123    if (name == "GL_ANGLE_framebuffer_blit")
     124        return m_availableExtensions.contains("GL_EXT_framebuffer_blit");
     125    if (name == "GL_ANGLE_framebuffer_multisample")
     126        return m_availableExtensions.contains("GL_EXT_framebuffer_multisample");
     127
     128    // Desktop GL always supports GL_OES_rgb8_rgba8.
     129    if (name == "GL_OES_rgb8_rgba8")
     130        return true;
     131
     132    // If GL_ARB_texture_float is available then we report GL_OES_texture_float and
     133    // GL_OES_texture_half_float as available.
     134    if (name == "GL_OES_texture_float" || name == "GL_OES_texture_half_float")
     135        return m_availableExtensions.contains("GL_ARB_texture_float");
     136
     137    // GL_OES_vertex_array_object
     138    if (name == "GL_OES_vertex_array_object")
     139        return m_availableExtensions.contains("GL_APPLE_vertex_array_object");
     140
     141    // Desktop GL always supports the standard derivative functions
     142    if (name == "GL_OES_standard_derivatives")
     143        return true;
     144
     145    if (name == "GL_EXT_texture_filter_anisotropic")
     146        return m_availableExtensions.contains("GL_EXT_texture_filter_anisotropic");
     147
     148    return m_availableExtensions.contains(name);
     149}
     150
     151String Extensions3DOpenGL::getExtensions()
     152{
     153    return String(reinterpret_cast<const char*>(::glGetString(GL_EXTENSIONS)));
     154}
     155
    210156} // namespace WebCore
    211157
  • trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGL.h

    r121055 r122116  
    2727#define Extensions3DOpenGL_h
    2828
    29 #include "Extensions3D.h"
     29#include "Extensions3DOpenGLCommon.h"
    3030
    3131#include "GraphicsContext3D.h"
     
    3535namespace WebCore {
    3636
    37 class Extensions3DOpenGL : public Extensions3D {
     37class Extensions3DOpenGL : public Extensions3DOpenGLCommon {
    3838public:
    3939    virtual ~Extensions3DOpenGL();
    4040
    4141    // Extensions3D methods.
    42     virtual bool supports(const String&);
    43     virtual void ensureEnabled(const String&);
    44     virtual bool isEnabled(const String&);
    45     virtual int getGraphicsResetStatusARB();
    4642    virtual void blitFramebuffer(long srcX0, long srcY0, long srcX1, long srcY1, long dstX0, long dstY0, long dstX1, long dstY1, unsigned long mask, unsigned long filter);
    4743    virtual void renderbufferStorageMultisample(unsigned long target, unsigned long samples, unsigned long internalformat, unsigned long width, unsigned long height);
     
    5147    virtual GC3Dboolean isVertexArrayOES(Platform3DObject);
    5248    virtual void bindVertexArrayOES(Platform3DObject);
    53     virtual String getTranslatedShaderSourceANGLE(Platform3DObject);
    5449    virtual void copyTextureCHROMIUM(GC3Denum, Platform3DObject, Platform3DObject, GC3Dint, GC3Denum);
    5550
    56 private:
     51protected:
    5752    // This class only needs to be instantiated by GraphicsContext3D implementations.
    5853    friend class GraphicsContext3D;
    5954    Extensions3DOpenGL(GraphicsContext3D*);
    6055
     56    virtual bool supportsExtension(const WTF::String&);
     57    virtual String getExtensions();
     58
     59private:
    6160    bool m_initializedAvailableExtensions;
    6261    HashSet<String> m_availableExtensions;
  • trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGLCommon.h

    r122115 r122116  
    11/*
    22 * Copyright (C) 2011 Google Inc. All rights reserved.
     3 * Copyright (C) 2012 Research In Motion Limited. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    2425 */
    2526
    26 #ifndef Extensions3DOpenGL_h
    27 #define Extensions3DOpenGL_h
     27#ifndef Extensions3DOpenGLCommon_h
     28#define Extensions3DOpenGLCommon_h
    2829
    2930#include "Extensions3D.h"
     
    3536namespace WebCore {
    3637
    37 class Extensions3DOpenGL : public Extensions3D {
     38class Extensions3DOpenGLCommon : public Extensions3D {
    3839public:
    39     virtual ~Extensions3DOpenGL();
     40    virtual ~Extensions3DOpenGLCommon();
    4041
    4142    // Extensions3D methods.
     
    4445    virtual bool isEnabled(const String&);
    4546    virtual int getGraphicsResetStatusARB();
    46     virtual void blitFramebuffer(long srcX0, long srcY0, long srcX1, long srcY1, long dstX0, long dstY0, long dstX1, long dstY1, unsigned long mask, unsigned long filter);
    47     virtual void renderbufferStorageMultisample(unsigned long target, unsigned long samples, unsigned long internalformat, unsigned long width, unsigned long height);
    48    
    49     virtual Platform3DObject createVertexArrayOES();
    50     virtual void deleteVertexArrayOES(Platform3DObject);
    51     virtual GC3Dboolean isVertexArrayOES(Platform3DObject);
    52     virtual void bindVertexArrayOES(Platform3DObject);
     47
     48    virtual Platform3DObject createVertexArrayOES() = 0;
     49    virtual void deleteVertexArrayOES(Platform3DObject) = 0;
     50    virtual GC3Dboolean isVertexArrayOES(Platform3DObject) = 0;
     51    virtual void bindVertexArrayOES(Platform3DObject) = 0;
     52
    5353    virtual String getTranslatedShaderSourceANGLE(Platform3DObject);
    54     virtual void copyTextureCHROMIUM(GC3Denum, Platform3DObject, Platform3DObject, GC3Dint, GC3Denum);
     54
     55protected:
     56    Extensions3DOpenGLCommon(GraphicsContext3D*);
     57
     58    virtual bool supportsExtension(const String&) = 0;
     59    virtual String getExtensions() = 0;
    5560
    5661private:
    57     // This class only needs to be instantiated by GraphicsContext3D implementations.
    58     friend class GraphicsContext3D;
    59     Extensions3DOpenGL(GraphicsContext3D*);
    60 
     62    virtual void initializeAvailableExtensions();
    6163    bool m_initializedAvailableExtensions;
    6264    HashSet<String> m_availableExtensions;
    63    
     65
    6466    // Weak pointer back to GraphicsContext3D
    6567    GraphicsContext3D* m_context;
     
    6870} // namespace WebCore
    6971
    70 #endif // Extensions3DOpenGL_h
     72#endif // Extensions3DOpenGLCommon_h
  • trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGLES.h

    r122115 r122116  
    11/*
    22 * Copyright (C) 2011 Google Inc. All rights reserved.
     3 * Copyright (C) 2012 Research In Motion Limited. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    2425 */
    2526
    26 #ifndef Extensions3DOpenGL_h
    27 #define Extensions3DOpenGL_h
     27#ifndef Extensions3DOpenGLES_h
     28#define Extensions3DOpenGLES_h
    2829
    29 #include "Extensions3D.h"
     30#include "Extensions3DOpenGLCommon.h"
    3031
    31 #include "GraphicsContext3D.h"
    32 #include <wtf/HashSet.h>
    33 #include <wtf/text/StringHash.h>
     32#include <GLES2/gl2.h>
     33#include <GLES2/gl2ext.h>
    3434
    3535namespace WebCore {
    3636
    37 class Extensions3DOpenGL : public Extensions3D {
     37class Extensions3DOpenGLES : public Extensions3DOpenGLCommon {
    3838public:
    39     virtual ~Extensions3DOpenGL();
     39    virtual ~Extensions3DOpenGLES();
    4040
    41     // Extensions3D methods.
    42     virtual bool supports(const String&);
    43     virtual void ensureEnabled(const String&);
    44     virtual bool isEnabled(const String&);
    45     virtual int getGraphicsResetStatusARB();
    46     virtual void blitFramebuffer(long srcX0, long srcY0, long srcX1, long srcY1, long dstX0, long dstY0, long dstX1, long dstY1, unsigned long mask, unsigned long filter);
    47     virtual void renderbufferStorageMultisample(unsigned long target, unsigned long samples, unsigned long internalformat, unsigned long width, unsigned long height);
    48    
     41    virtual void framebufferTexture2DMultisampleIMG(unsigned long target, unsigned long attachment, unsigned long textarget, unsigned int texture, int level, unsigned long samples);
     42    virtual void renderbufferStorageMultisampleIMG(unsigned long target, unsigned long samples, unsigned long internalformat, unsigned long width, unsigned long height);
     43
    4944    virtual Platform3DObject createVertexArrayOES();
    5045    virtual void deleteVertexArrayOES(Platform3DObject);
    5146    virtual GC3Dboolean isVertexArrayOES(Platform3DObject);
    5247    virtual void bindVertexArrayOES(Platform3DObject);
    53     virtual String getTranslatedShaderSourceANGLE(Platform3DObject);
    54     virtual void copyTextureCHROMIUM(GC3Denum, Platform3DObject, Platform3DObject, GC3Dint, GC3Denum);
    5548
    56 private:
     49protected:
    5750    // This class only needs to be instantiated by GraphicsContext3D implementations.
    5851    friend class GraphicsContext3D;
    59     Extensions3DOpenGL(GraphicsContext3D*);
     52    Extensions3DOpenGLES(GraphicsContext3D*);
    6053
    61     bool m_initializedAvailableExtensions;
    62     HashSet<String> m_availableExtensions;
    63    
    64     // Weak pointer back to GraphicsContext3D
    65     GraphicsContext3D* m_context;
     54    virtual bool supportsExtension(const String&);
     55    virtual String getExtensions();
     56
     57    bool m_supportsOESvertexArrayObject;
     58    bool m_supportsIMGMultisampledRenderToTexture;
     59
     60    PFNGLFRAMEBUFFERTEXTURE2DMULTISAMPLEIMGPROC m_glFramebufferTexture2DMultisampleIMG;
     61    PFNGLRENDERBUFFERSTORAGEMULTISAMPLEIMGPROC m_glRenderbufferStorageMultisampleIMG;
     62    PFNGLBINDVERTEXARRAYOESPROC m_glBindVertexArrayOES;
     63    PFNGLDELETEVERTEXARRAYSOESPROC m_glDeleteVertexArraysOES;
     64    PFNGLGENVERTEXARRAYSOESPROC m_glGenVertexArraysOES;
     65    PFNGLISVERTEXARRAYOESPROC m_glIsVertexArrayOES;
    6666};
    6767
    6868} // namespace WebCore
    6969
    70 #endif // Extensions3DOpenGL_h
     70#endif // Extensions3DOpenGLES_h
  • trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGL.cpp

    r119552 r122116  
    11/*
    22 * Copyright (C) 2010 Apple Inc. All rights reserved.
     3 * Copyright (C) 2011 Google Inc. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    3536#include "NotImplemented.h"
    3637
     38#include <algorithm>
     39#include <cstring>
     40#include <wtf/UnusedParam.h>
     41#include <wtf/text/CString.h>
     42
    3743#if PLATFORM(MAC)
    3844#include <OpenGL/gl.h>
     
    4652{
    4753    ::glReadPixels(x, y, width, height, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, pixels);
     54}
     55
     56void GraphicsContext3D::validateAttributes()
     57{
     58    Extensions3D* extensions = getExtensions();
     59    if (m_attrs.stencil) {
     60        const char* packedDepthStencilExtension = isGLES2Compliant() ? "GL_OES_packed_depth_stencil" : "GL_EXT_packed_depth_stencil";
     61        if (extensions->supports(packedDepthStencilExtension)) {
     62            extensions->ensureEnabled(packedDepthStencilExtension);
     63            // Force depth if stencil is true.
     64            m_attrs.depth = true;
     65        } else
     66            m_attrs.stencil = false;
     67    }
     68    if (m_attrs.antialias) {
     69        bool isValidVendor = true;
     70        // Currently in Mac we only turn on antialias if vendor is NVIDIA,
     71        // or if ATI and on 10.7.2 and above.
     72        const char* vendor = reinterpret_cast<const char*>(::glGetString(GL_VENDOR));
     73        if (!vendor || (!std::strstr(vendor, "NVIDIA") && !(std::strstr(vendor, "ATI") && systemAllowsMultisamplingOnATICards())))
     74            isValidVendor = false;
     75        if (!isValidVendor || !extensions->supports("GL_ANGLE_framebuffer_multisample") || isGLES2Compliant())
     76            m_attrs.antialias = false;
     77        else
     78            extensions->ensureEnabled("GL_ANGLE_framebuffer_multisample");
     79    }
    4880}
    4981
     
    257289}
    258290
     291bool GraphicsContext3D::systemAllowsMultisamplingOnATICards() const
     292{
     293#if PLATFORM(MAC)
     294#if !defined(BUILDING_ON_SNOW_LEOPARD) && !defined(BUILDING_ON_LION)
     295    return true;
     296#else
     297    ASSERT(isMainThread());
     298    static SInt32 version;
     299    if (!version) {
     300        if (Gestalt(gestaltSystemVersion, &version) != noErr)
     301            return false;
     302    }
     303    // See https://bugs.webkit.org/show_bug.cgi?id=77922 for more details
     304    return version >= 0x1072;
     305#endif // SNOW_LEOPARD and LION
     306#else
     307    return false;
     308#endif // PLATFORM(MAC)
     309}
     310
     311Extensions3D* GraphicsContext3D::getExtensions()
     312{
     313    if (!m_extensions)
     314        m_extensions = adoptPtr(new Extensions3DOpenGL(this));
     315    return m_extensions.get();
     316}
     317
    259318}
    260319
  • trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp

    r119552 r122116  
    11/*
    22 * Copyright (C) 2010 Apple Inc. All rights reserved.
     3 * Copyright (C) 2011 Google Inc. All rights reserved.
    34 * Copyright (C) 2012 ChangSeok Oh <shivamidow@gmail.com>
     5 * Copyright (C) 2012 Research In Motion Limited. All rights reserved.
    46 *
    57 * Redistribution and use in source and binary forms, with or without
     
    3133#include "GraphicsContext3D.h"
    3234
     35#include "CanvasRenderingContext.h"
     36#if USE(OPENGL_ES_2)
     37#include "Extensions3DOpenGLES.h"
     38#else
    3339#include "Extensions3DOpenGL.h"
     40#endif
    3441#include "GraphicsContext.h"
    3542#include "ImageBuffer.h"
     
    5057#include <wtf/text/CString.h>
    5158
    52 #if PLATFORM(MAC)
     59#if USE(OPENGL_ES_2)
     60#include "OpenGLESShims.h"
     61#elif PLATFORM(MAC)
    5362#include <OpenGL/gl.h>
    5463#elif PLATFORM(GTK) || PLATFORM(EFL) || PLATFORM(QT)
     
    5665#endif
    5766
     67#if PLATFORM(BLACKBERRY)
     68#include <BlackBerryPlatformLog.h>
     69#endif
     70
    5871namespace WebCore {
    5972
    60 static bool systemAllowsMultisamplingOnATICards()
    61 {
    62 #if PLATFORM(MAC)
    63 #if !defined(BUILDING_ON_SNOW_LEOPARD) && !defined(BUILDING_ON_LION)
    64     return true;
    65 #else
    66     ASSERT(isMainThread());
    67     static SInt32 version;
    68     if (!version) {
    69         if (Gestalt(gestaltSystemVersion, &version) != noErr)
    70             return false;
    71     }
    72     // See https://bugs.webkit.org/show_bug.cgi?id=77922 for more details
    73     return version >= 0x1072;
    74 #endif // SNOW_LEOPARD and LION
    75 #else
    76     return false;
    77 #endif // PLATFORM(MAC)
    78 }
    79 
    80 void GraphicsContext3D::validateAttributes()
     73void GraphicsContext3D::validateDepthStencil(const char* packedDepthStencilExtension)
    8174{
    8275    Extensions3D* extensions = getExtensions();
    8376    if (m_attrs.stencil) {
    84         const char* packedDepthStencilExtension = isGLES2Compliant() ? "GL_OES_packed_depth_stencil" : "GL_EXT_packed_depth_stencil";
    8577        if (extensions->supports(packedDepthStencilExtension)) {
    8678            extensions->ensureEnabled(packedDepthStencilExtension);
     
    440432    makeContextCurrent();
    441433
    442     int GLshaderType;
    443     ANGLEShaderType shaderType;
    444 
    445     glGetShaderiv(shader, SHADER_TYPE, &GLshaderType);
    446    
    447     if (GLshaderType == VERTEX_SHADER)
    448         shaderType = SHADER_TYPE_VERTEX;
    449     else if (GLshaderType == FRAGMENT_SHADER)
    450         shaderType = SHADER_TYPE_FRAGMENT;
    451     else
    452         return; // Invalid shader type.
    453 
    454     HashMap<Platform3DObject, ShaderSourceEntry>::iterator result = m_shaderSourceMap.find(shader);
    455 
    456     if (result == m_shaderSourceMap.end())
     434    String translatedShaderSource = m_extensions->getTranslatedShaderSourceANGLE(shader);
     435
     436    if (!translatedShaderSource.length())
    457437        return;
    458 
    459     ShaderSourceEntry& entry = result->second;
    460 
    461     String translatedShaderSource;
    462     String shaderInfoLog;
    463 
    464     bool isValid = m_compiler.validateShaderSource(entry.source.utf8().data(), shaderType, translatedShaderSource, shaderInfoLog);
    465 
    466     entry.log = shaderInfoLog;
    467     entry.isValid = isValid;
    468 
    469     if (!isValid)
    470         return; // Shader didn't validate, don't move forward with compiling translated source.
    471438
    472439    int translatedShaderLength = translatedShaderSource.length();
     
    802769        ::glFlush();
    803770    }
     771    // Currently only format=RGBA, type=UNSIGNED_BYTE is supported by the specification: http://www.khronos.org/registry/webgl/specs/latest/
     772    // If this ever changes, this code will need to be updated.
     773
     774    // Calculate the strides of our data and canvas
     775    unsigned int formatSize = 4; // RGBA UNSIGNED_BYTE
     776    unsigned int dataStride = width * formatSize;
     777    unsigned int canvasStride = m_currentWidth * formatSize;
     778
     779    // If we are using a pack alignment of 8, then we need to align our strides to 8 byte boundaries
     780    // See: http://en.wikipedia.org/wiki/Data_structure_alignment (computing padding)
     781    int packAlignment;
     782    glGetIntegerv(GL_PACK_ALIGNMENT, &packAlignment);
     783    if (8 == packAlignment) {
     784        dataStride = (dataStride + 7) & ~7;
     785        canvasStride = (canvasStride + 7) & ~7;
     786    }
     787
     788    unsigned char* canvasData = new unsigned char[canvasStride * m_currentHeight];
     789    ::glReadPixels(0, 0, m_currentWidth, m_currentHeight, format, type, canvasData);
     790
     791    // If we failed to read our canvas data due to a GL error, don't continue
     792    int error = glGetError();
     793    if (GL_NO_ERROR != error) {
     794        synthesizeGLError(error);
     795        return;
     796    }
     797
     798    // Clear our data in case some of it lies outside the bounds of our canvas
     799    // TODO: don't do this if all of the data lies inside the bounds of the canvas
     800    memset(data, 0, dataStride * height);
     801
     802    // Calculate the intersection of our canvas and data bounds
     803    IntRect dataRect(x, y, width, height);
     804    IntRect canvasRect(0, 0, m_currentWidth, m_currentHeight);
     805    IntRect nonZeroDataRect = intersection(dataRect, canvasRect);
     806
     807    unsigned int xDataOffset = x < 0 ? -x * formatSize : 0;
     808    unsigned int yDataOffset = y < 0 ? -y * dataStride : 0;
     809    unsigned int xCanvasOffset = nonZeroDataRect.x() * formatSize;
     810    unsigned int yCanvasOffset = nonZeroDataRect.y() * canvasStride;
     811    unsigned char* dst = static_cast<unsigned char*>(data) + xDataOffset + yDataOffset;
     812    unsigned char* src = canvasData + xCanvasOffset + yCanvasOffset;
     813    for (int row = 0; row < nonZeroDataRect.height(); row++) {
     814        memcpy(dst, src, nonZeroDataRect.width() * formatSize);
     815        dst += dataStride;
     816        src += canvasStride;
     817    }
     818
     819    delete [] canvasData;
    804820    ::glReadPixels(x, y, width, height, format, type, data);
     821
    805822    if (m_attrs.antialias && m_boundFBO == m_multisampleFBO)
    806823        ::glBindFramebufferEXT(GraphicsContext3D::FRAMEBUFFER, m_multisampleFBO);
    807 }
    808 
    809 void GraphicsContext3D::releaseShaderCompiler()
    810 {
    811     // FIXME: This is not implemented on desktop OpenGL. We need to have ifdefs for the different GL variants.
    812     makeContextCurrent();
    813     notImplemented();
    814824}
    815825
     
    13871397}
    13881398
    1389 Extensions3D* GraphicsContext3D::getExtensions()
    1390 {
    1391     if (!m_extensions)
    1392         m_extensions = adoptPtr(new Extensions3DOpenGL(this));
    1393     return m_extensions.get();
    1394 }
    1395 
    13961399}
    13971400
  • trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLES.cpp

    r119552 r122116  
    11/*
    22 * Copyright (C) 2010 Apple Inc. All rights reserved.
     3 * Copyright (C) 2011 Google Inc. All rights reserved.
    34 * Copyright (C) 2012 ChangSeok Oh <shivamidow@gmail.com>
     5 * Copyright (C) 2012 Research In Motion Limited. All rights reserved.
    46 *
    57 * Redistribution and use in source and binary forms, with or without
     
    3032
    3133#include "GraphicsContext3D.h"
    32 
    33 #include "Extensions3DOpenGL.h"
     34#include "Extensions3DOpenGLES.h"
    3435#include "IntRect.h"
    3536#include "IntSize.h"
     37#include "LayerWebKitThread.h"
    3638#include "NotImplemented.h"
    37 
    38 #if PLATFORM(GTK) || PLATFORM(QT)
    39 #include "OpenGLShims.h"
    40 #endif
     39#include "OpenGLESShims.h"
    4140
    4241namespace WebCore {
    4342
     43void GraphicsContext3D::releaseShaderCompiler()
     44{
     45    makeContextCurrent();
     46    ::glReleaseShaderCompiler();
     47}
     48
    4449void GraphicsContext3D::readPixelsAndConvertToBGRAIfNecessary(int x, int y, int width, int height, unsigned char* pixels)
    4550{
    46     const int totalBytes = m_currentWidth * m_currentHeight * 4;
    4751    ::glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
    48     for (int i = 0; i < totalBytes; i += 4)
    49         std::swap(pixels[i], pixels[i + 2]); // Convert to BGRA.
    50 }
    51 
    52 bool GraphicsContext3D::reshapeFBOs(const IntSize& size)
    53 {
    54     const int width = size.width();
    55     const int height = size.height();
    56     GLuint colorFormat = 0, pixelDataType = 0;
    57     if (m_attrs.alpha) {
    58         m_internalColorFormat = GL_RGBA;
    59         colorFormat = GL_RGBA;
    60         pixelDataType = GL_UNSIGNED_BYTE;
    61     } else {
    62         m_internalColorFormat = GL_RGB;
    63         colorFormat = GL_RGB;
    64         pixelDataType = GL_UNSIGNED_SHORT_5_6_5;
     52    int totalBytes = width * height * 4;
     53    if (isGLES2Compliant()) {
     54        for (int i = 0; i < totalBytes; i += 4)
     55            std::swap(pixels[i], pixels[i + 2]); // Convert to BGRA.
    6556    }
    66 
    67     // We don't allow the logic where stencil is required and depth is not.
    68     // See GraphicsContext3D::validateAttributes.
    69     bool supportPackedDepthStencilBuffer = (m_attrs.stencil || m_attrs.depth) && getExtensions()->supports("GL_OES_packed_depth_stencil");
    70 
    71     // Resize regular FBO.
    72     bool mustRestoreFBO = false;
    73     if (m_boundFBO != m_fbo) {
    74         mustRestoreFBO = true;
    75         ::glBindFramebufferEXT(GraphicsContext3D::FRAMEBUFFER, m_fbo);
    76     }
    77 
    78     ::glBindTexture(GL_TEXTURE_2D, m_texture);
    79     ::glTexImage2D(GL_TEXTURE_2D, 0, m_internalColorFormat, width, height, 0, colorFormat, pixelDataType, 0);
    80     ::glFramebufferTexture2DEXT(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_texture, 0);
    81 
    82     ::glBindTexture(GL_TEXTURE_2D, m_compositorTexture);
    83     ::glTexImage2D(GL_TEXTURE_2D, 0, m_internalColorFormat, width, height, 0, colorFormat, GL_UNSIGNED_BYTE, 0);
    84     ::glBindTexture(GL_TEXTURE_2D, 0);
    85 
    86     // We don't support antialiasing yet. See GraphicsContext3D::validateAttributes.
    87     ASSERT(!m_attrs.antialias);
    88 
    89     if (m_attrs.stencil || m_attrs.depth) {
    90         // Use a 24 bit depth buffer where we know we have it.
    91         if (supportPackedDepthStencilBuffer) {
    92             ::glBindTexture(GL_TEXTURE_2D, m_depthStencilBuffer);
    93             ::glTexImage2D(GL_TEXTURE_2D, 0, GraphicsContext3D::DEPTH_STENCIL, width, height, 0, GraphicsContext3D::DEPTH_STENCIL, GraphicsContext3D::UNSIGNED_INT_24_8, 0);
    94             if (m_attrs.stencil)
    95                 ::glFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, m_depthStencilBuffer, 0);
    96             if (m_attrs.depth)
    97                 ::glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_depthStencilBuffer, 0);
    98             ::glBindTexture(GL_TEXTURE_2D, 0);
    99         } else {
    100             if (m_attrs.stencil) {
    101                 ::glBindRenderbufferEXT(GraphicsContext3D::RENDERBUFFER, m_stencilBuffer);
    102                 ::glRenderbufferStorageEXT(GraphicsContext3D::RENDERBUFFER, GL_STENCIL_INDEX8, width, height);
    103                 ::glFramebufferRenderbufferEXT(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::STENCIL_ATTACHMENT, GraphicsContext3D::RENDERBUFFER, m_stencilBuffer);
    104             }
    105             if (m_attrs.depth) {
    106                 ::glBindRenderbufferEXT(GraphicsContext3D::RENDERBUFFER, m_depthBuffer);
    107                 ::glRenderbufferStorageEXT(GraphicsContext3D::RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height);
    108                 ::glFramebufferRenderbufferEXT(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::DEPTH_ATTACHMENT, GraphicsContext3D::RENDERBUFFER, m_depthBuffer);
    109             }
    110             ::glBindRenderbufferEXT(GraphicsContext3D::RENDERBUFFER, 0);
    111         }
    112     }
    113     if (glCheckFramebufferStatusEXT(GraphicsContext3D::FRAMEBUFFER) != GraphicsContext3D::FRAMEBUFFER_COMPLETE) {
    114         // FIXME: cleanup
    115         notImplemented();
    116     }
    117 
    118     return mustRestoreFBO;
    11957}
    12058
     
    15795}
    15896
     97void GraphicsContext3D::validateAttributes()
     98{
     99    validateDepthStencil("GL_OES_packed_depth_stencil");
     100
     101    if (m_attrs.antialias) {
     102        Extensions3D* extensions = getExtensions();
     103        if (!extensions->supports("GL_IMG_multisampled_render_to_texture"))
     104            m_attrs.antialias = false;
     105    }
     106}
     107
    159108void GraphicsContext3D::depthRange(GC3Dclampf zNear, GC3Dclampf zFar)
    160109{
     
    169118}
    170119
    171 } // namespace WebCore
     120
     121Extensions3D* GraphicsContext3D::getExtensions()
     122{
     123    if (!m_extensions)
     124        m_extensions = adoptPtr(new Extensions3DOpenGLES(this));
     125    return m_extensions.get();
     126}
     127
     128bool GraphicsContext3D::systemAllowsMultisamplingOnATICards() const
     129{
     130    return false; // not applicable
     131}
     132
     133}
    172134
    173135#endif // ENABLE(WEBGL)
  • trunk/Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp

    r122037 r122116  
    9898#endif
    9999}
     100
     101#if !USE(OPENGL_ES_2)
     102void GraphicsContext3D::releaseShaderCompiler()
     103{
     104    notImplemented();
     105}
     106#endif
    100107
    101108GraphicsContext3DPrivate::GraphicsContext3DPrivate(GraphicsContext3D* context, HostWindow* hostWindow)
Note: See TracChangeset for help on using the changeset viewer.