Changeset 122250 in webkit


Ignore:
Timestamp:
Jul 10, 2012 12:52:36 PM (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-10
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:
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r122244 r122250  
     12012-07-10  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-06  David Hyatt  <hyatt@apple.com>
    293
  • trunk/Source/WebCore/GNUmakefile.list.am

    r122159 r122250  
    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

    r122156 r122250  
    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

    r122195 r122250  
    39613961        platform/graphics/gpu/DrawingBuffer.cpp \
    39623962        platform/graphics/gpu/qt/DrawingBufferQt.cpp \
    3963         platform/graphics/opengl/Extensions3DOpenGL.cpp \
    39643963        platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp \
     3964        platform/graphics/opengl/Extensions3DOpenGLCommon.cpp \
    39653965        platform/graphics/qt/GraphicsContext3DQt.cpp \
    39663966        platform/graphics/texmap/TextureMapperGL.cpp \
    39673967        platform/graphics/texmap/TextureMapperShaderManager.cpp
    39683968
    3969     contains(QT_CONFIG, opengles2) {
    3970         SOURCES += platform/graphics/opengl/GraphicsContext3DOpenGLES.cpp
    3971     } else {
    3972         SOURCES += platform/graphics/opengl/GraphicsContext3DOpenGL.cpp
     3969    INCLUDEPATH += $$PWD/platform/graphics/gpu
     3970
     3971    contains(QT_CONFIG, opengl) | contains(QT_CONFIG, opengles2) {
     3972        !contains(QT_CONFIG, opengles2) {
     3973            SOURCES += \
     3974               platform/graphics/opengl/GraphicsContext3DOpenGL.cpp \
     3975               platform/graphics/opengl/Extensions3DOpenGL.cpp
     3976        } else {
     3977            SOURCES += \
     3978               platform/graphics/opengl/GraphicsContext3DOpenGLES.cpp \
     3979               platform/graphics/opengl/Extensions3DOpenGLES.cpp
     3980        }
     3981
     3982        HEADERS += platform/graphics/opengl/Extensions3DOpenGL.h
     3983
     3984        SOURCES += \
     3985            platform/graphics/opengl/Extensions3DOpenGLCommon.cpp \
     3986            platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp
    39733987    }
    39743988
  • trunk/Source/WebCore/WebCore.gypi

    r122195 r122250  
    38093809            'platform/graphics/mac/WebTiledLayer.mm',
    38103810            'platform/graphics/opengl/Extensions3DOpenGL.cpp',
     3811            'platform/graphics/opengl/Extensions3DOpenGLCommon.cpp',
    38113812            'platform/graphics/opengl/Extensions3DOpenGL.h',
    38123813            'platform/graphics/opengl/GraphicsContext3DOpenGL.cpp',
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r122195 r122250  
    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 */; };
     
    82538255                44D8DA98139545BE00337B75 /* SVGMPathElement.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = SVGMPathElement.idl; sourceTree = "<group>"; };
    82548256                44D8DA9A139545CD00337B75 /* SVGAnimateMotionElement.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = SVGAnimateMotionElement.idl; sourceTree = "<group>"; };
     8257                44DAB5AF15A623580097C1E4 /* Extensions3DOpenGLCommon.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Extensions3DOpenGLCommon.cpp; sourceTree = "<group>"; };
     8258                44DAB5B015A623580097C1E4 /* Extensions3DOpenGLCommon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Extensions3DOpenGLCommon.h; sourceTree = "<group>"; };
    82558259                45099C401370A7800058D513 /* IconURL.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IconURL.cpp; sourceTree = "<group>"; };
    82568260                450CEBEE15073BBE002BB149 /* LabelableElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LabelableElement.cpp; sourceTree = "<group>"; };
     
    2166221666                        isa = PBXGroup;
    2166321667                        children = (
     21668                                44DAB5AF15A623580097C1E4 /* Extensions3DOpenGLCommon.cpp */,
     21669                                44DAB5B015A623580097C1E4 /* Extensions3DOpenGLCommon.h */,
    2166421670                                6E67D2A41280E8A4008758F7 /* Extensions3DOpenGL.cpp */,
    2166521671                                6E67D2A51280E8A4008758F7 /* Extensions3DOpenGL.h */,
     
    2519725203                                76808B50159DADFA002B5233 /* JSHTMLDialogElement.h in Headers */,
    2519825204                                1FAFBF1915A5FA7400083A20 /* UTIUtilities.h in Headers */,
     25205                                44DAB5B215A623580097C1E4 /* Extensions3DOpenGLCommon.h in Headers */,
    2519925206                        );
    2520025207                        runOnlyForDeploymentPostprocessing = 0;
     
    2825428261                                76808B4F159DADFA002B5233 /* JSHTMLDialogElement.cpp in Sources */,
    2825528262                                1FAFBF1815A5FA6E00083A20 /* UTIUtilities.mm in Sources */,
     28263                                44DAB5B115A623580097C1E4 /* Extensions3DOpenGLCommon.cpp in Sources */,
    2825628264                        );
    2825728265                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h

    r122156 r122250  
    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/OpenGLESShims.h

    r122156 r122250  
     1/*
     2 * Copyright (C) 2012 Research In Motion Limited. All rights reserved.
     3
     4 * Redistribution and use in source and binary forms, with or without
     5 * modification, are permitted provided that the following conditions
     6 * are met:
     7 * 1. Redistributions of source code must retain the above copyright
     8 *    notice, this list of conditions and the following disclaimer.
     9 * 2. Redistributions in binary form must reproduce the above copyright
     10 *    notice, this list of conditions and the following disclaimer in the
     11 *    documentation and/or other materials provided with the distribution.
     12 *
     13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
     14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     16 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
     17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
     21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     22 * (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.
     24 */
     25
     26#ifndef OpenGLESShims_h
     27#define OpenGLESShims_h
     28
     29#if PLATFORM(BLACKBERRY)
     30#define glBindFramebufferEXT glBindFramebuffer
     31#define glFramebufferTexture2DEXT glFramebufferTexture2D
     32#define glBindRenderbufferEXT glBindRenderbuffer
     33#define glRenderbufferStorageEXT glRenderbufferStorage
     34#define glFramebufferRenderbufferEXT glFramebufferRenderbuffer
     35#define GL_RENDERBUFFER_EXT GL_RENDERBUFFER
     36#define GL_STENCIL_ATTACHMENT_EXT GL_STENCIL_ATTACHMENT
     37#define glCheckFramebufferStatusEXT glCheckFramebufferStatus
     38#define glDeleteFramebuffersEXT glDeleteFramebuffers
     39#define glDeleteRenderbuffersEXT glDeleteRenderbuffers
     40#define glGenRenderbuffersEXT glGenRenderbuffers
     41#define glGenFramebuffersEXT glGenFramebuffers
     42#define glGetFramebufferAttachmentParameterivEXT glGetFramebufferAttachmentParameteriv
     43#define glGetRenderbufferParameterivEXT glGetRenderbufferParameteriv
     44#define glIsRenderbufferEXT glIsRenderbuffer
     45#define glIsFramebufferEXT glIsFramebuffer
     46#define glGenerateMipmapEXT glGenerateMipmap
     47#define GL_COLOR_ATTACHMENT0_EXT GL_COLOR_ATTACHMENT0
     48#define GL_DEPTH_ATTACHMENT_EXT GL_DEPTH_ATTACHMENT
     49#define GL_FRAMEBUFFER_COMPLETE_EXT GL_FRAMEBUFFER_COMPLETE
     50#define GL_FRAMEBUFFER_EXT GL_FRAMEBUFFER
     51#define GL_DEPTH24_STENCIL8_EXT GL_DEPTH24_STENCIL8_OES
     52#define GL_RGBA8 GL_RGBA8_OES
     53#define GL_RGB8 GL_RGB8_OES
     54#define GL_READ_FRAMEBUFFER_EXT 0x8CA8
     55#define GL_DRAW_FRAMEBUFFER_EXT 0x8CA9
     56#define FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT 0x9134
     57#define GL_MAX_SAMPLES_EXT 0x8D57
     58#endif // PLATFORM(BLACKBERRY)
     59
     60#endif // OpenGLESShims_h
     61
  • trunk/Source/WebCore/platform/graphics/cairo/GraphicsContext3DCairo.cpp

    r122175 r122250  
    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

    r122175 r122250  
    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

    r122175 r122250  
    283283}
    284284
     285void GraphicsContext3D::releaseShaderCompiler()
     286{
     287    makeContextCurrent();
     288    notImplemented();
     289}
     290
    285291}
    286292
  • trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGL.cpp

    r122175 r122250  
    4343
    4444Extensions3DOpenGL::Extensions3DOpenGL(GraphicsContext3D* context)
    45     : m_initializedAvailableExtensions(false)
    46     , m_context(context)
     45    : Extensions3DOpenGLCommon(context)
    4746{
    4847}
     
    5251}
    5352
    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 }
    13953
    14054void Extensions3DOpenGL::blitFramebuffer(long srcX0, long srcY0, long srcX1, long srcY1, long dstX0, long dstY0, long dstX1, long dstY1, unsigned long mask, unsigned long filter)
     
    195109}
    196110
    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 
    204111void Extensions3DOpenGL::copyTextureCHROMIUM(GC3Denum, Platform3DObject, Platform3DObject, GC3Dint, GC3Denum)
    205112{
     
    208115}
    209116
     117bool Extensions3DOpenGL::supportsExtension(const String& name)
     118{
     119    // GL_ANGLE_framebuffer_blit and GL_ANGLE_framebuffer_multisample are "fake". They are implemented using other
     120    // extensions. In particular GL_EXT_framebuffer_blit and GL_EXT_framebuffer_multisample
     121    if (name == "GL_ANGLE_framebuffer_blit")
     122        return m_availableExtensions.contains("GL_EXT_framebuffer_blit");
     123    if (name == "GL_ANGLE_framebuffer_multisample")
     124        return m_availableExtensions.contains("GL_EXT_framebuffer_multisample");
     125
     126    // Desktop GL always supports GL_OES_rgb8_rgba8.
     127    if (name == "GL_OES_rgb8_rgba8")
     128        return true;
     129
     130    // If GL_ARB_texture_float is available then we report GL_OES_texture_float and
     131    // GL_OES_texture_half_float as available.
     132    if (name == "GL_OES_texture_float" || name == "GL_OES_texture_half_float")
     133        return m_availableExtensions.contains("GL_ARB_texture_float");
     134
     135    // GL_OES_vertex_array_object
     136    if (name == "GL_OES_vertex_array_object")
     137        return m_availableExtensions.contains("GL_APPLE_vertex_array_object");
     138
     139    // Desktop GL always supports the standard derivative functions
     140    if (name == "GL_OES_standard_derivatives")
     141        return true;
     142
     143    if (name == "GL_EXT_texture_filter_anisotropic")
     144        return m_availableExtensions.contains("GL_EXT_texture_filter_anisotropic");
     145
     146    return m_availableExtensions.contains(name);
     147}
     148
     149String Extensions3DOpenGL::getExtensions()
     150{
     151    return String(reinterpret_cast<const char*>(::glGetString(GL_EXTENSIONS)));
     152}
     153
    210154} // namespace WebCore
    211155
  • trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGL.h

    r122156 r122250  
    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
    61     bool m_initializedAvailableExtensions;
    62     HashSet<String> m_availableExtensions;
    63    
    64     // Weak pointer back to GraphicsContext3D
    65     GraphicsContext3D* m_context;
     56    virtual bool supportsExtension(const WTF::String&);
     57    virtual String getExtensions();
    6658};
    6759
  • trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGLCommon.cpp

    r122156 r122250  
     1/*
     2 * Copyright (C) 2011 Google Inc. All rights reserved.
     3 * Copyright (C) 2012 Research In Motion Limited. All rights reserved.
     4 *
     5 * Redistribution and use in source and binary forms, with or without
     6 * modification, are permitted provided that the following conditions
     7 * are met:
     8 *
     9 * 1.  Redistributions of source code must retain the above copyright
     10 *     notice, this list of conditions and the following disclaimer.
     11 * 2.  Redistributions in binary form must reproduce the above copyright
     12 *     notice, this list of conditions and the following disclaimer in the
     13 *     documentation and/or other materials provided with the distribution.
     14 *
     15 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
     16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     18 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
     19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     22 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     25 */
     26
     27#include "config.h"
     28
     29#if ENABLE(WEBGL)
     30#include "Extensions3DOpenGLCommon.h"
     31
     32#include "ANGLEWebKitBridge.h"
     33#include "GraphicsContext3D.h"
     34
     35#if PLATFORM(BLACKBERRY)
     36#include <BlackBerryPlatformLog.h>
     37#endif
     38
     39#if USE(OPENGL_ES_2)
     40#include "OpenGLESShims.h"
     41#include <GLES2/gl2.h>
     42#include <GLES2/gl2ext.h>
     43#elif PLATFORM(MAC)
     44#include <OpenGL/gl.h>
     45#elif PLATFORM(GTK) || PLATFORM(EFL) || PLATFORM(QT)
     46#include "OpenGLShims.h"
     47#endif
     48
     49#include <wtf/Vector.h>
     50
     51namespace WebCore {
     52
     53Extensions3DOpenGLCommon::Extensions3DOpenGLCommon(GraphicsContext3D* context)
     54    : m_initializedAvailableExtensions(false)
     55    , m_context(context)
     56{
     57}
     58
     59Extensions3DOpenGLCommon::~Extensions3DOpenGLCommon()
     60{
     61}
     62
     63bool Extensions3DOpenGLCommon::supports(const String& name)
     64{
     65    if (!m_initializedAvailableExtensions)
     66        initializeAvailableExtensions();
     67
     68    return supportsExtension(name);
     69}
     70
     71void Extensions3DOpenGLCommon::ensureEnabled(const String& name)
     72{
     73    if (name == "GL_OES_standard_derivatives") {
     74        // Enable support in ANGLE (if not enabled already)
     75        ANGLEWebKitBridge& compiler = m_context->m_compiler;
     76        ShBuiltInResources ANGLEResources = compiler.getResources();
     77        if (!ANGLEResources.OES_standard_derivatives) {
     78            ANGLEResources.OES_standard_derivatives = 1;
     79            compiler.setResources(ANGLEResources);
     80        }
     81    }
     82}
     83
     84bool Extensions3DOpenGLCommon::isEnabled(const String& name)
     85{
     86    if (name == "GL_OES_standard_derivatives") {
     87        ANGLEWebKitBridge& compiler = m_context->m_compiler;
     88        return compiler.getResources().OES_standard_derivatives;
     89    }
     90    return supports(name);
     91}
     92
     93int Extensions3DOpenGLCommon::getGraphicsResetStatusARB()
     94{
     95    return GraphicsContext3D::NO_ERROR;
     96}
     97
     98String Extensions3DOpenGLCommon::getTranslatedShaderSourceANGLE(Platform3DObject shader)
     99{
     100    ASSERT(shader);
     101    int GLshaderType;
     102    ANGLEShaderType shaderType;
     103
     104    ANGLEWebKitBridge& compiler = m_context->m_compiler;
     105
     106    m_context->getShaderiv(shader, GraphicsContext3D::SHADER_TYPE, &GLshaderType);
     107
     108    if (GLshaderType == GraphicsContext3D::VERTEX_SHADER)
     109        shaderType = SHADER_TYPE_VERTEX;
     110    else if (GLshaderType == GraphicsContext3D::FRAGMENT_SHADER)
     111        shaderType = SHADER_TYPE_FRAGMENT;
     112    else
     113        return ""; // Invalid shader type.
     114
     115    HashMap<Platform3DObject, GraphicsContext3D::ShaderSourceEntry>::iterator result = m_context->m_shaderSourceMap.find(shader);
     116
     117    if (result == m_context->m_shaderSourceMap.end())
     118        return "";
     119
     120    GraphicsContext3D::ShaderSourceEntry& entry = result->second;
     121
     122    String translatedShaderSource;
     123    String shaderInfoLog;
     124
     125    bool isValid = compiler.validateShaderSource(entry.source.utf8().data(), shaderType, translatedShaderSource, shaderInfoLog);
     126
     127    entry.log = shaderInfoLog;
     128    entry.isValid = isValid;
     129
     130    if (!isValid)
     131        return "";
     132
     133    return translatedShaderSource;
     134}
     135
     136void Extensions3DOpenGLCommon::initializeAvailableExtensions()
     137{
     138    String extensionsString = getExtensions();
     139    Vector<String> availableExtensions;
     140    extensionsString.split(" ", availableExtensions);
     141    for (size_t i = 0; i < availableExtensions.size(); ++i)
     142        m_availableExtensions.add(availableExtensions[i]);
     143    m_initializedAvailableExtensions = true;
     144}
     145
     146} // namespace WebCore
     147
     148#endif // ENABLE(WEBGL)
  • trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGLCommon.h

    r122156 r122250  
     1/*
     2 * Copyright (C) 2011 Google Inc. All rights reserved.
     3 * Copyright (C) 2012 Research In Motion Limited. All rights reserved.
     4 *
     5 * Redistribution and use in source and binary forms, with or without
     6 * modification, are permitted provided that the following conditions
     7 * are met:
     8 *
     9 * 1.  Redistributions of source code must retain the above copyright
     10 *     notice, this list of conditions and the following disclaimer.
     11 * 2.  Redistributions in binary form must reproduce the above copyright
     12 *     notice, this list of conditions and the following disclaimer in the
     13 *     documentation and/or other materials provided with the distribution.
     14 *
     15 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
     16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     18 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
     19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     22 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     25 */
     26
     27#ifndef Extensions3DOpenGLCommon_h
     28#define Extensions3DOpenGLCommon_h
     29
     30#include "Extensions3D.h"
     31
     32#include "GraphicsContext3D.h"
     33#include <wtf/HashSet.h>
     34#include <wtf/text/StringHash.h>
     35
     36namespace WebCore {
     37
     38class Extensions3DOpenGLCommon : public Extensions3D {
     39public:
     40    virtual ~Extensions3DOpenGLCommon();
     41
     42    // Extensions3D methods.
     43    virtual bool supports(const String&);
     44    virtual void ensureEnabled(const String&);
     45    virtual bool isEnabled(const String&);
     46    virtual int getGraphicsResetStatusARB();
     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
     53    virtual String getTranslatedShaderSourceANGLE(Platform3DObject);
     54
     55protected:
     56    Extensions3DOpenGLCommon(GraphicsContext3D*);
     57
     58    virtual bool supportsExtension(const String&) = 0;
     59    virtual String getExtensions() = 0;
     60
     61    virtual void initializeAvailableExtensions();
     62
     63    bool m_initializedAvailableExtensions;
     64    HashSet<String> m_availableExtensions;
     65
     66    // Weak pointer back to GraphicsContext3D
     67    GraphicsContext3D* m_context;
     68};
     69
     70} // namespace WebCore
     71
     72#endif // Extensions3DOpenGLCommon_h
  • trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGLES.cpp

    r122156 r122250  
     1/*
     2 * Copyright (C) 2011 Google Inc. All rights reserved.
     3 * Copyright (C) 2012 Research In Motion Limited. All rights reserved.
     4 *
     5 * Redistribution and use in source and binary forms, with or without
     6 * modification, are permitted provided that the following conditions
     7 * are met:
     8 *
     9 * 1.  Redistributions of source code must retain the above copyright
     10 *     notice, this list of conditions and the following disclaimer.
     11 * 2.  Redistributions in binary form must reproduce the above copyright
     12 *     notice, this list of conditions and the following disclaimer in the
     13 *     documentation and/or other materials provided with the distribution.
     14 *
     15 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
     16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     18 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
     19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     22 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     25 */
     26
     27#include "config.h"
     28#if ENABLE(WEBGL)
     29#include "Extensions3DOpenGLES.h"
     30
     31#include "GraphicsContext3D.h"
     32#include <EGL/egl.h>
     33#include <wtf/Vector.h>
     34
     35
     36namespace WebCore {
     37
     38Extensions3DOpenGLES::Extensions3DOpenGLES(GraphicsContext3D* context)
     39    : Extensions3DOpenGLCommon(context)
     40    , m_supportsOESvertexArrayObject(false)
     41    , m_supportsIMGMultisampledRenderToTexture(false)
     42    , m_glFramebufferTexture2DMultisampleIMG(0)
     43    , m_glRenderbufferStorageMultisampleIMG(0)
     44    , m_glBindVertexArrayOES(0)
     45    , m_glDeleteVertexArraysOES(0)
     46    , m_glGenVertexArraysOES(0)
     47    , m_glIsVertexArrayOES(0)
     48{
     49}
     50
     51Extensions3DOpenGLES::~Extensions3DOpenGLES()
     52{
     53}
     54
     55void Extensions3DOpenGLES::framebufferTexture2DMultisampleIMG(unsigned long target, unsigned long attachment, unsigned long textarget, unsigned int texture, int level, unsigned long samples)
     56{
     57    if (m_glFramebufferTexture2DMultisampleIMG)
     58        m_glFramebufferTexture2DMultisampleIMG(target, attachment, textarget, texture, level, samples);
     59    else
     60        m_context->synthesizeGLError(GL_INVALID_OPERATION);
     61}
     62
     63void Extensions3DOpenGLES::renderbufferStorageMultisampleIMG(unsigned long target, unsigned long samples, unsigned long internalformat, unsigned long width, unsigned long height)
     64{
     65    if (m_glRenderbufferStorageMultisampleIMG)
     66        m_glRenderbufferStorageMultisampleIMG(target, samples, internalformat, width, height);
     67    else
     68        m_context->synthesizeGLError(GL_INVALID_OPERATION);
     69}
     70
     71Platform3DObject Extensions3DOpenGLES::createVertexArrayOES()
     72{
     73    m_context->makeContextCurrent();
     74    if (m_glGenVertexArraysOES) {
     75        GLuint array = 0;
     76        m_glGenVertexArraysOES(1, &array);
     77        return array;
     78    }
     79
     80    m_context->synthesizeGLError(GL_INVALID_OPERATION);
     81    return 0;
     82}
     83
     84void Extensions3DOpenGLES::deleteVertexArrayOES(Platform3DObject array)
     85{
     86    if (!array)
     87        return;
     88
     89    m_context->makeContextCurrent();
     90    if (m_glDeleteVertexArraysOES)
     91        m_glDeleteVertexArraysOES(1, &array);
     92    else
     93        m_context->synthesizeGLError(GL_INVALID_OPERATION);
     94}
     95
     96GC3Dboolean Extensions3DOpenGLES::isVertexArrayOES(Platform3DObject array)
     97{
     98    if (!array)
     99        return GL_FALSE;
     100
     101    m_context->makeContextCurrent();
     102    if (m_glIsVertexArrayOES)
     103        return m_glIsVertexArrayOES(array);
     104
     105    m_context->synthesizeGLError(GL_INVALID_OPERATION);
     106    return false;
     107}
     108
     109void Extensions3DOpenGLES::bindVertexArrayOES(Platform3DObject array)
     110{
     111    if (!array)
     112        return;
     113
     114    m_context->makeContextCurrent();
     115    if (m_glBindVertexArrayOES)
     116        m_glBindVertexArrayOES(array);
     117    else
     118        m_context->synthesizeGLError(GL_INVALID_OPERATION);
     119}
     120
     121
     122bool Extensions3DOpenGLES::supportsExtension(const String& name)
     123{
     124    if (m_availableExtensions.contains(name)) {
     125        if (name == "GL_OES_vertex_array_object" && !m_supportsOESvertexArrayObject) {
     126            m_glBindVertexArrayOES = reinterpret_cast<PFNGLBINDVERTEXARRAYOESPROC>(eglGetProcAddress("glBindVertexArrayOES"));
     127            m_glGenVertexArraysOES = reinterpret_cast<PFNGLGENVERTEXARRAYSOESPROC>(eglGetProcAddress("glGenVertexArraysOES"));
     128            m_glDeleteVertexArraysOES = reinterpret_cast<PFNGLDELETEVERTEXARRAYSOESPROC>(eglGetProcAddress("glDeleteVertexArraysOES"));
     129            m_glIsVertexArrayOES = reinterpret_cast<PFNGLISVERTEXARRAYOESPROC>(eglGetProcAddress("glIsVertexArrayOES"));
     130            m_supportsOESvertexArrayObject = true;
     131        } else if (name == "GL_IMG_multisampled_render_to_texture" && !m_supportsIMGMultisampledRenderToTexture) {
     132            m_glFramebufferTexture2DMultisampleIMG = reinterpret_cast<PFNGLFRAMEBUFFERTEXTURE2DMULTISAMPLEIMGPROC>(eglGetProcAddress("glFramebufferTexture2DMultisampleIMG"));
     133            m_glRenderbufferStorageMultisampleIMG = reinterpret_cast<PFNGLRENDERBUFFERSTORAGEMULTISAMPLEIMGPROC>(eglGetProcAddress("glRenderbufferStorageMultisampleIMG"));
     134            m_supportsIMGMultisampledRenderToTexture = true;
     135        }
     136        return true;
     137    }
     138
     139    return false;
     140}
     141
     142String Extensions3DOpenGLES::getExtensions()
     143{
     144    return String(reinterpret_cast<const char*>(::glGetString(GL_EXTENSIONS)));
     145}
     146
     147} // namespace WebCore
     148
     149#endif // ENABLE(WEBGL)
  • trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGLES.h

    r122156 r122250  
     1/*
     2 * Copyright (C) 2011 Google Inc. All rights reserved.
     3 * Copyright (C) 2012 Research In Motion Limited. All rights reserved.
     4 *
     5 * Redistribution and use in source and binary forms, with or without
     6 * modification, are permitted provided that the following conditions
     7 * are met:
     8 *
     9 * 1.  Redistributions of source code must retain the above copyright
     10 *     notice, this list of conditions and the following disclaimer.
     11 * 2.  Redistributions in binary form must reproduce the above copyright
     12 *     notice, this list of conditions and the following disclaimer in the
     13 *     documentation and/or other materials provided with the distribution.
     14 *
     15 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
     16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     18 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
     19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     22 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     25 */
     26
     27#ifndef Extensions3DOpenGLES_h
     28#define Extensions3DOpenGLES_h
     29
     30#include "Extensions3DOpenGLCommon.h"
     31
     32#include <GLES2/gl2.h>
     33#include <GLES2/gl2ext.h>
     34
     35namespace WebCore {
     36
     37class Extensions3DOpenGLES : public Extensions3DOpenGLCommon {
     38public:
     39    virtual ~Extensions3DOpenGLES();
     40
     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
     44    virtual Platform3DObject createVertexArrayOES();
     45    virtual void deleteVertexArrayOES(Platform3DObject);
     46    virtual GC3Dboolean isVertexArrayOES(Platform3DObject);
     47    virtual void bindVertexArrayOES(Platform3DObject);
     48
     49protected:
     50    // This class only needs to be instantiated by GraphicsContext3D implementations.
     51    friend class GraphicsContext3D;
     52    Extensions3DOpenGLES(GraphicsContext3D*);
     53
     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;
     66};
     67
     68} // namespace WebCore
     69
     70#endif // Extensions3DOpenGLES_h
  • trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGL.cpp

    r122175 r122250  
    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/MainThread.h>
     41#include <wtf/UnusedParam.h>
     42#include <wtf/text/CString.h>
     43
    3744#if PLATFORM(MAC)
    3845#include <OpenGL/gl.h>
     
    4653{
    4754    ::glReadPixels(x, y, width, height, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, pixels);
     55}
     56
     57void GraphicsContext3D::validateAttributes()
     58{
     59    Extensions3D* extensions = getExtensions();
     60    validateDepthStencil("GL_EXT_packed_depth_stencil");
     61    if (m_attrs.antialias) {
     62        bool isValidVendor = true;
     63        // Currently in Mac we only turn on antialias if vendor is NVIDIA,
     64        // or if ATI and on 10.7.2 and above.
     65        const char* vendor = reinterpret_cast<const char*>(::glGetString(GL_VENDOR));
     66        if (!vendor || (!std::strstr(vendor, "NVIDIA") && !(std::strstr(vendor, "ATI") && systemAllowsMultisamplingOnATICards())))
     67            isValidVendor = false;
     68        if (!isValidVendor || !extensions->supports("GL_ANGLE_framebuffer_multisample") || isGLES2Compliant())
     69            m_attrs.antialias = false;
     70        else
     71            extensions->ensureEnabled("GL_ANGLE_framebuffer_multisample");
     72    }
    4873}
    4974
     
    257282}
    258283
     284bool GraphicsContext3D::systemAllowsMultisamplingOnATICards() const
     285{
     286#if PLATFORM(MAC)
     287#if !defined(BUILDING_ON_SNOW_LEOPARD) && !defined(BUILDING_ON_LION)
     288    return true;
     289#else
     290    ASSERT(isMainThread());
     291    static SInt32 version;
     292    if (!version) {
     293        if (Gestalt(gestaltSystemVersion, &version) != noErr)
     294            return false;
     295    }
     296    // See https://bugs.webkit.org/show_bug.cgi?id=77922 for more details
     297    return version >= 0x1072;
     298#endif // SNOW_LEOPARD and LION
     299#else
     300    return false;
     301#endif // PLATFORM(MAC)
     302}
     303
     304Extensions3D* GraphicsContext3D::getExtensions()
     305{
     306    if (!m_extensions)
     307        m_extensions = adoptPtr(new Extensions3DOpenGL(this));
     308    return m_extensions.get();
     309}
     310
     311void GraphicsContext3D::readPixels(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, void* data)
     312{
     313    // FIXME: remove the two glFlush calls when the driver bug is fixed, i.e.,
     314    // all previous rendering calls should be done before reading pixels.
     315    makeContextCurrent();
     316    ::glFlush();
     317    if (m_attrs.antialias && m_boundFBO == m_multisampleFBO) {
     318        resolveMultisamplingIfNecessary(IntRect(x, y, width, height));
     319        ::glBindFramebufferEXT(GraphicsContext3D::FRAMEBUFFER, m_fbo);
     320        ::glFlush();
     321    }
     322    ::glReadPixels(x, y, width, height, format, type, data);
     323    if (m_attrs.antialias && m_boundFBO == m_multisampleFBO)
     324        ::glBindFramebufferEXT(GraphicsContext3D::FRAMEBUFFER, m_multisampleFBO);
     325}
     326
    259327}
    260328
  • trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp

    r122175 r122250  
    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();
     
    789756    makeContextCurrent();
    790757    ::glPolygonOffset(factor, units);
    791 }
    792 
    793 void GraphicsContext3D::readPixels(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, void* data)
    794 {
    795     // FIXME: remove the two glFlush calls when the driver bug is fixed, i.e.,
    796     // all previous rendering calls should be done before reading pixels.
    797     makeContextCurrent();
    798     ::glFlush();
    799     if (m_attrs.antialias && m_boundFBO == m_multisampleFBO) {
    800         resolveMultisamplingIfNecessary(IntRect(x, y, width, height));
    801         ::glBindFramebufferEXT(GraphicsContext3D::FRAMEBUFFER, m_fbo);
    802         ::glFlush();
    803     }
    804     ::glReadPixels(x, y, width, height, format, type, data);
    805     if (m_attrs.antialias && m_boundFBO == m_multisampleFBO)
    806         ::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();
    814758}
    815759
     
    13871331}
    13881332
    1389 Extensions3D* GraphicsContext3D::getExtensions()
    1390 {
    1391     if (!m_extensions)
    1392         m_extensions = adoptPtr(new Extensions3DOpenGL(this));
    1393     return m_extensions.get();
    1394 }
    1395 
    13961333}
    13971334
  • trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLES.cpp

    r122175 r122250  
    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
     49void GraphicsContext3D::readPixels(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, void* data)
     50{
     51    // Currently only format=RGBA, type=UNSIGNED_BYTE is supported by the specification: http://www.khronos.org/registry/webgl/specs/latest/
     52    // If this ever changes, this code will need to be updated.
     53
     54    // Calculate the strides of our data and canvas
     55    unsigned int formatSize = 4; // RGBA UNSIGNED_BYTE
     56    unsigned int dataStride = width * formatSize;
     57    unsigned int canvasStride = m_currentWidth * formatSize;
     58
     59    // If we are using a pack alignment of 8, then we need to align our strides to 8 byte boundaries
     60    // See: http://en.wikipedia.org/wiki/Data_structure_alignment (computing padding)
     61    int packAlignment;
     62    glGetIntegerv(GL_PACK_ALIGNMENT, &packAlignment);
     63    if (8 == packAlignment) {
     64        dataStride = (dataStride + 7) & ~7;
     65        canvasStride = (canvasStride + 7) & ~7;
     66    }
     67
     68    unsigned char* canvasData = new unsigned char[canvasStride * m_currentHeight];
     69    ::glReadPixels(0, 0, m_currentWidth, m_currentHeight, format, type, canvasData);
     70
     71    // If we failed to read our canvas data due to a GL error, don't continue
     72    int error = glGetError();
     73    if (GL_NO_ERROR != error) {
     74        synthesizeGLError(error);
     75        return;
     76    }
     77
     78    // Clear our data in case some of it lies outside the bounds of our canvas
     79    // TODO: don't do this if all of the data lies inside the bounds of the canvas
     80    memset(data, 0, dataStride * height);
     81
     82    // Calculate the intersection of our canvas and data bounds
     83    IntRect dataRect(x, y, width, height);
     84    IntRect canvasRect(0, 0, m_currentWidth, m_currentHeight);
     85    IntRect nonZeroDataRect = intersection(dataRect, canvasRect);
     86
     87    unsigned int xDataOffset = x < 0 ? -x * formatSize : 0;
     88    unsigned int yDataOffset = y < 0 ? -y * dataStride : 0;
     89    unsigned int xCanvasOffset = nonZeroDataRect.x() * formatSize;
     90    unsigned int yCanvasOffset = nonZeroDataRect.y() * canvasStride;
     91    unsigned char* dst = static_cast<unsigned char*>(data) + xDataOffset + yDataOffset;
     92    unsigned char* src = canvasData + xCanvasOffset + yCanvasOffset;
     93    for (int row = 0; row < nonZeroDataRect.height(); row++) {
     94        memcpy(dst, src, nonZeroDataRect.width() * formatSize);
     95        dst += dataStride;
     96        src += canvasStride;
     97    }
     98
     99    delete [] canvasData;
     100    ::glReadPixels(x, y, width, height, format, type, data);
     101
     102    if (m_attrs.antialias && m_boundFBO == m_multisampleFBO)
     103        ::glBindFramebufferEXT(GraphicsContext3D::FRAMEBUFFER, m_multisampleFBO);
     104}
     105
    44106void GraphicsContext3D::readPixelsAndConvertToBGRAIfNecessary(int x, int y, int width, int height, unsigned char* pixels)
    45107{
    46     const int totalBytes = m_currentWidth * m_currentHeight * 4;
    47108    ::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;
     109    int totalBytes = width * height * 4;
     110    if (isGLES2Compliant()) {
     111        for (int i = 0; i < totalBytes; i += 4)
     112            std::swap(pixels[i], pixels[i + 2]); // Convert to BGRA.
    65113    }
    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;
    119114}
    120115
     
    157152}
    158153
     154void GraphicsContext3D::validateAttributes()
     155{
     156    validateDepthStencil("GL_OES_packed_depth_stencil");
     157
     158    if (m_attrs.antialias) {
     159        Extensions3D* extensions = getExtensions();
     160        if (!extensions->supports("GL_IMG_multisampled_render_to_texture"))
     161            m_attrs.antialias = false;
     162    }
     163}
     164
    159165void GraphicsContext3D::depthRange(GC3Dclampf zNear, GC3Dclampf zFar)
    160166{
     
    169175}
    170176
    171 } // namespace WebCore
     177
     178Extensions3D* GraphicsContext3D::getExtensions()
     179{
     180    if (!m_extensions)
     181        m_extensions = adoptPtr(new Extensions3DOpenGLES(this));
     182    return m_extensions.get();
     183}
     184
     185bool GraphicsContext3D::systemAllowsMultisamplingOnATICards() const
     186{
     187    return false; // not applicable
     188}
     189
     190}
    172191
    173192#endif // USE(3D_GRAPHICS)
  • trunk/Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp

    r122175 r122250  
    9494#endif
    9595}
     96
     97#if !USE(OPENGL_ES_2)
     98void GraphicsContext3D::releaseShaderCompiler()
     99{
     100    notImplemented();
     101}
     102#endif
    96103
    97104GraphicsContext3DPrivate::GraphicsContext3DPrivate(GraphicsContext3D* context, HostWindow* hostWindow)
Note: See TracChangeset for help on using the changeset viewer.