Changeset 56303 in webkit


Ignore:
Timestamp:
Mar 20, 2010 9:31:29 AM (14 years ago)
Author:
Dimitri Glazkov
Message:

2010-03-20 Dimitri Glazkov <Dimitri Glazkov>

No review, rolling out r56294.
http://trac.webkit.org/changeset/56294
https://bugs.webkit.org/show_bug.cgi?id=36262

Broke compile on Chromium canaries.

  • WebKit.gyp:
  • public/WebGraphicsContext3D.h: Removed.
  • public/WebKitClient.h:
  • src/GraphicsContext3D.cpp: (WebCore::GraphicsContext3DInternal::): (WebCore::GraphicsContext3DInternal::GLConnection::chooseFBConfig): (WebCore::GraphicsContext3DInternal::GLConnection::createNewContext): (WebCore::GraphicsContext3DInternal::GLConnection::createPbuffer): (WebCore::GraphicsContext3DInternal::GLConnection::destroyPbuffer): (WebCore::GraphicsContext3DInternal::GLConnection::makeCurrent): (WebCore::GraphicsContext3DInternal::GLConnection::destroyContext): (WebCore::GraphicsContext3DInternal::GLConnection::getCurrentContext): (WebCore::GraphicsContext3DInternal::GLConnection::GLConnection): (WebCore::GraphicsContext3DInternal::GLConnection::create): (WebCore::GraphicsContext3DInternal::GLConnection::~GLConnection): (WebCore::GraphicsContext3DInternal::VertexAttribPointerState::VertexAttribPointerState): (WebCore::GraphicsContext3DInternal::GraphicsContext3DInternal): (WebCore::GraphicsContext3DInternal::~GraphicsContext3DInternal): (WebCore::GraphicsContext3DInternal::makeContextCurrent): (WebCore::GraphicsContext3DInternal::platformGraphicsContext3D): (WebCore::GraphicsContext3DInternal::platformTexture): (WebCore::createTextureObject): (WebCore::GraphicsContext3DInternal::reshape): (WebCore::GraphicsContext3DInternal::flipVertically): (WebCore::GraphicsContext3DInternal::beginPaint): (WebCore::GraphicsContext3DInternal::activeTexture): (WebCore::GraphicsContext3DInternal::bindBuffer): (WebCore::GraphicsContext3DInternal::bindFramebuffer): (WebCore::GraphicsContext3DInternal::bindTexture): (WebCore::GraphicsContext3DInternal::bufferDataImpl): (WebCore::GraphicsContext3DInternal::disableVertexAttribArray): (WebCore::GraphicsContext3DInternal::enableVertexAttribArray): (WebCore::GraphicsContext3DInternal::getError): (WebCore::GraphicsContext3DInternal::getContextAttributes): (WebCore::GraphicsContext3DInternal::vertexAttribPointer): (WebCore::GraphicsContext3DInternal::viewportImpl): (WebCore::GraphicsContext3DInternal::synthesizeGLError): (WebCore::GraphicsContext3D::create): (WebCore::GraphicsContext3D::GraphicsContext3D): (WebCore::GraphicsContext3D::~GraphicsContext3D): (WebCore::GraphicsContext3D::platformGraphicsContext3D): (WebCore::GraphicsContext3D::platformTexture): (WebCore::GraphicsContext3D::makeContextCurrent): (WebCore::GraphicsContext3D::reshape): (WebCore::GraphicsContext3D::beginPaint): (WebCore::GraphicsContext3D::endPaint): (WebCore::GraphicsContext3D::sizeInBytes): (WebCore::GraphicsContext3D::createBuffer): (WebCore::GraphicsContext3D::createFramebuffer): (WebCore::GraphicsContext3D::createProgram): (WebCore::GraphicsContext3D::createRenderbuffer): (WebCore::GraphicsContext3D::createShader): (WebCore::GraphicsContext3D::createTexture): (WebCore::GraphicsContext3D::deleteBuffer): (WebCore::GraphicsContext3D::deleteFramebuffer): (WebCore::GraphicsContext3D::deleteProgram): (WebCore::GraphicsContext3D::deleteRenderbuffer): (WebCore::GraphicsContext3D::deleteShader): (WebCore::GraphicsContext3D::deleteTexture): (WebCore::GraphicsContext3D::activeTexture): (WebCore::GraphicsContext3D::bindAttribLocation): (WebCore::GraphicsContext3D::bindBuffer): (WebCore::GraphicsContext3D::bindFramebuffer): (WebCore::GraphicsContext3D::bindTexture): (WebCore::GraphicsContext3D::bufferData): (WebCore::GraphicsContext3D::bufferSubData): (WebCore::GraphicsContext3D::checkFramebufferStatus): (WebCore::GraphicsContext3D::detachShader): (WebCore::GraphicsContext3D::disableVertexAttribArray): (WebCore::GraphicsContext3D::drawArrays): (WebCore::GraphicsContext3D::drawElements): (WebCore::GraphicsContext3D::enableVertexAttribArray): (WebCore::GraphicsContext3D::generateMipmap): (WebCore::GraphicsContext3D::getActiveAttrib): (WebCore::GraphicsContext3D::getActiveUniform): (WebCore::GraphicsContext3D::getAttribLocation): (WebCore::GraphicsContext3D::getBooleanv): (WebCore::GraphicsContext3D::getBufferParameteriv): (WebCore::GraphicsContext3D::getContextAttributes): (WebCore::GraphicsContext3D::getError): (WebCore::GraphicsContext3D::getFloatv): (WebCore::GraphicsContext3D::getFramebufferAttachmentParameteriv): (WebCore::GraphicsContext3D::getIntegerv): (WebCore::GraphicsContext3D::getProgramiv): (WebCore::GraphicsContext3D::getProgramInfoLog): (WebCore::GraphicsContext3D::getRenderbufferParameteriv): (WebCore::GraphicsContext3D::getShaderiv): (WebCore::GraphicsContext3D::getShaderInfoLog): (WebCore::GraphicsContext3D::getShaderSource): (WebCore::GraphicsContext3D::getString): (WebCore::GraphicsContext3D::getTexParameterfv): (WebCore::GraphicsContext3D::getTexParameteriv): (WebCore::GraphicsContext3D::getUniformfv): (WebCore::GraphicsContext3D::getUniformiv): (WebCore::GraphicsContext3D::getUniformLocation): (WebCore::GraphicsContext3D::getVertexAttribfv): (WebCore::GraphicsContext3D::getVertexAttribiv): (WebCore::GraphicsContext3D::getVertexAttribOffset): (WebCore::GraphicsContext3D::isBuffer): (WebCore::GraphicsContext3D::isEnabled): (WebCore::GraphicsContext3D::isFramebuffer): (WebCore::GraphicsContext3D::isProgram): (WebCore::GraphicsContext3D::isRenderbuffer): (WebCore::GraphicsContext3D::isShader): (WebCore::GraphicsContext3D::isTexture): (WebCore::GraphicsContext3D::pixelStorei): (WebCore::GraphicsContext3D::readPixels): (WebCore::GraphicsContext3D::releaseShaderCompiler): (WebCore::GraphicsContext3D::shaderSource): (WebCore::GraphicsContext3D::synthesizeGLError): (WebCore::GraphicsContext3D::texImage2D): (WebCore::GraphicsContext3D::texSubImage2D): (WebCore::GraphicsContext3D::uniform1fv): (WebCore::GraphicsContext3D::uniform1iv): (WebCore::GraphicsContext3D::uniform2fv): (WebCore::GraphicsContext3D::uniform2iv): (WebCore::GraphicsContext3D::uniform3fv): (WebCore::GraphicsContext3D::uniform3iv): (WebCore::GraphicsContext3D::uniform4fv): (WebCore::GraphicsContext3D::uniform4iv): (WebCore::GraphicsContext3D::uniformMatrix2fv): (WebCore::GraphicsContext3D::uniformMatrix3fv): (WebCore::GraphicsContext3D::uniformMatrix4fv): (WebCore::GraphicsContext3D::vertexAttrib1fv): (WebCore::GraphicsContext3D::vertexAttrib2fv): (WebCore::GraphicsContext3D::vertexAttrib3fv): (WebCore::GraphicsContext3D::vertexAttrib4fv): (WebCore::GraphicsContext3D::vertexAttribPointer): (WebCore::GraphicsContext3D::viewport):
  • src/WebGraphicsContext3D.cpp: Removed.
  • src/WebGraphicsContext3DDefaultImpl.cpp: Removed.
  • src/WebGraphicsContext3DDefaultImpl.h: Removed.
Location:
trunk/WebKit/chromium
Files:
4 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKit/chromium/ChangeLog

    r56294 r56303  
     12010-03-20  Dimitri Glazkov  <dglazkov@chromium.org>
     2
     3        No review, rolling out r56294.
     4        http://trac.webkit.org/changeset/56294
     5        https://bugs.webkit.org/show_bug.cgi?id=36262
     6
     7        Broke compile on Chromium canaries.
     8
     9        * WebKit.gyp:
     10        * public/WebGraphicsContext3D.h: Removed.
     11        * public/WebKitClient.h:
     12        * src/GraphicsContext3D.cpp:
     13        (WebCore::GraphicsContext3DInternal::):
     14        (WebCore::GraphicsContext3DInternal::GLConnection::chooseFBConfig):
     15        (WebCore::GraphicsContext3DInternal::GLConnection::createNewContext):
     16        (WebCore::GraphicsContext3DInternal::GLConnection::createPbuffer):
     17        (WebCore::GraphicsContext3DInternal::GLConnection::destroyPbuffer):
     18        (WebCore::GraphicsContext3DInternal::GLConnection::makeCurrent):
     19        (WebCore::GraphicsContext3DInternal::GLConnection::destroyContext):
     20        (WebCore::GraphicsContext3DInternal::GLConnection::getCurrentContext):
     21        (WebCore::GraphicsContext3DInternal::GLConnection::GLConnection):
     22        (WebCore::GraphicsContext3DInternal::GLConnection::create):
     23        (WebCore::GraphicsContext3DInternal::GLConnection::~GLConnection):
     24        (WebCore::GraphicsContext3DInternal::VertexAttribPointerState::VertexAttribPointerState):
     25        (WebCore::GraphicsContext3DInternal::GraphicsContext3DInternal):
     26        (WebCore::GraphicsContext3DInternal::~GraphicsContext3DInternal):
     27        (WebCore::GraphicsContext3DInternal::makeContextCurrent):
     28        (WebCore::GraphicsContext3DInternal::platformGraphicsContext3D):
     29        (WebCore::GraphicsContext3DInternal::platformTexture):
     30        (WebCore::createTextureObject):
     31        (WebCore::GraphicsContext3DInternal::reshape):
     32        (WebCore::GraphicsContext3DInternal::flipVertically):
     33        (WebCore::GraphicsContext3DInternal::beginPaint):
     34        (WebCore::GraphicsContext3DInternal::activeTexture):
     35        (WebCore::GraphicsContext3DInternal::bindBuffer):
     36        (WebCore::GraphicsContext3DInternal::bindFramebuffer):
     37        (WebCore::GraphicsContext3DInternal::bindTexture):
     38        (WebCore::GraphicsContext3DInternal::bufferDataImpl):
     39        (WebCore::GraphicsContext3DInternal::disableVertexAttribArray):
     40        (WebCore::GraphicsContext3DInternal::enableVertexAttribArray):
     41        (WebCore::GraphicsContext3DInternal::getError):
     42        (WebCore::GraphicsContext3DInternal::getContextAttributes):
     43        (WebCore::GraphicsContext3DInternal::vertexAttribPointer):
     44        (WebCore::GraphicsContext3DInternal::viewportImpl):
     45        (WebCore::GraphicsContext3DInternal::synthesizeGLError):
     46        (WebCore::GraphicsContext3D::create):
     47        (WebCore::GraphicsContext3D::GraphicsContext3D):
     48        (WebCore::GraphicsContext3D::~GraphicsContext3D):
     49        (WebCore::GraphicsContext3D::platformGraphicsContext3D):
     50        (WebCore::GraphicsContext3D::platformTexture):
     51        (WebCore::GraphicsContext3D::makeContextCurrent):
     52        (WebCore::GraphicsContext3D::reshape):
     53        (WebCore::GraphicsContext3D::beginPaint):
     54        (WebCore::GraphicsContext3D::endPaint):
     55        (WebCore::GraphicsContext3D::sizeInBytes):
     56        (WebCore::GraphicsContext3D::createBuffer):
     57        (WebCore::GraphicsContext3D::createFramebuffer):
     58        (WebCore::GraphicsContext3D::createProgram):
     59        (WebCore::GraphicsContext3D::createRenderbuffer):
     60        (WebCore::GraphicsContext3D::createShader):
     61        (WebCore::GraphicsContext3D::createTexture):
     62        (WebCore::GraphicsContext3D::deleteBuffer):
     63        (WebCore::GraphicsContext3D::deleteFramebuffer):
     64        (WebCore::GraphicsContext3D::deleteProgram):
     65        (WebCore::GraphicsContext3D::deleteRenderbuffer):
     66        (WebCore::GraphicsContext3D::deleteShader):
     67        (WebCore::GraphicsContext3D::deleteTexture):
     68        (WebCore::GraphicsContext3D::activeTexture):
     69        (WebCore::GraphicsContext3D::bindAttribLocation):
     70        (WebCore::GraphicsContext3D::bindBuffer):
     71        (WebCore::GraphicsContext3D::bindFramebuffer):
     72        (WebCore::GraphicsContext3D::bindTexture):
     73        (WebCore::GraphicsContext3D::bufferData):
     74        (WebCore::GraphicsContext3D::bufferSubData):
     75        (WebCore::GraphicsContext3D::checkFramebufferStatus):
     76        (WebCore::GraphicsContext3D::detachShader):
     77        (WebCore::GraphicsContext3D::disableVertexAttribArray):
     78        (WebCore::GraphicsContext3D::drawArrays):
     79        (WebCore::GraphicsContext3D::drawElements):
     80        (WebCore::GraphicsContext3D::enableVertexAttribArray):
     81        (WebCore::GraphicsContext3D::generateMipmap):
     82        (WebCore::GraphicsContext3D::getActiveAttrib):
     83        (WebCore::GraphicsContext3D::getActiveUniform):
     84        (WebCore::GraphicsContext3D::getAttribLocation):
     85        (WebCore::GraphicsContext3D::getBooleanv):
     86        (WebCore::GraphicsContext3D::getBufferParameteriv):
     87        (WebCore::GraphicsContext3D::getContextAttributes):
     88        (WebCore::GraphicsContext3D::getError):
     89        (WebCore::GraphicsContext3D::getFloatv):
     90        (WebCore::GraphicsContext3D::getFramebufferAttachmentParameteriv):
     91        (WebCore::GraphicsContext3D::getIntegerv):
     92        (WebCore::GraphicsContext3D::getProgramiv):
     93        (WebCore::GraphicsContext3D::getProgramInfoLog):
     94        (WebCore::GraphicsContext3D::getRenderbufferParameteriv):
     95        (WebCore::GraphicsContext3D::getShaderiv):
     96        (WebCore::GraphicsContext3D::getShaderInfoLog):
     97        (WebCore::GraphicsContext3D::getShaderSource):
     98        (WebCore::GraphicsContext3D::getString):
     99        (WebCore::GraphicsContext3D::getTexParameterfv):
     100        (WebCore::GraphicsContext3D::getTexParameteriv):
     101        (WebCore::GraphicsContext3D::getUniformfv):
     102        (WebCore::GraphicsContext3D::getUniformiv):
     103        (WebCore::GraphicsContext3D::getUniformLocation):
     104        (WebCore::GraphicsContext3D::getVertexAttribfv):
     105        (WebCore::GraphicsContext3D::getVertexAttribiv):
     106        (WebCore::GraphicsContext3D::getVertexAttribOffset):
     107        (WebCore::GraphicsContext3D::isBuffer):
     108        (WebCore::GraphicsContext3D::isEnabled):
     109        (WebCore::GraphicsContext3D::isFramebuffer):
     110        (WebCore::GraphicsContext3D::isProgram):
     111        (WebCore::GraphicsContext3D::isRenderbuffer):
     112        (WebCore::GraphicsContext3D::isShader):
     113        (WebCore::GraphicsContext3D::isTexture):
     114        (WebCore::GraphicsContext3D::pixelStorei):
     115        (WebCore::GraphicsContext3D::readPixels):
     116        (WebCore::GraphicsContext3D::releaseShaderCompiler):
     117        (WebCore::GraphicsContext3D::shaderSource):
     118        (WebCore::GraphicsContext3D::synthesizeGLError):
     119        (WebCore::GraphicsContext3D::texImage2D):
     120        (WebCore::GraphicsContext3D::texSubImage2D):
     121        (WebCore::GraphicsContext3D::uniform1fv):
     122        (WebCore::GraphicsContext3D::uniform1iv):
     123        (WebCore::GraphicsContext3D::uniform2fv):
     124        (WebCore::GraphicsContext3D::uniform2iv):
     125        (WebCore::GraphicsContext3D::uniform3fv):
     126        (WebCore::GraphicsContext3D::uniform3iv):
     127        (WebCore::GraphicsContext3D::uniform4fv):
     128        (WebCore::GraphicsContext3D::uniform4iv):
     129        (WebCore::GraphicsContext3D::uniformMatrix2fv):
     130        (WebCore::GraphicsContext3D::uniformMatrix3fv):
     131        (WebCore::GraphicsContext3D::uniformMatrix4fv):
     132        (WebCore::GraphicsContext3D::vertexAttrib1fv):
     133        (WebCore::GraphicsContext3D::vertexAttrib2fv):
     134        (WebCore::GraphicsContext3D::vertexAttrib3fv):
     135        (WebCore::GraphicsContext3D::vertexAttrib4fv):
     136        (WebCore::GraphicsContext3D::vertexAttribPointer):
     137        (WebCore::GraphicsContext3D::viewport):
     138        * src/WebGraphicsContext3D.cpp: Removed.
     139        * src/WebGraphicsContext3DDefaultImpl.cpp: Removed.
     140        * src/WebGraphicsContext3DDefaultImpl.h: Removed.
     141
    11422010-03-19  Kenneth Russell  <kbr@google.com>
    2143
  • trunk/WebKit/chromium/WebKit.gyp

    r56294 r56303  
    123123                'public/WebFormElement.h',
    124124                'public/WebGlyphCache.h',
    125                 'public/WebGraphicsContext3D.h',
    126125                'public/WebHistoryItem.h',
    127126                'public/WebHTTPBody.h',
     
    314313                'src/WebFrameImpl.h',
    315314                'src/WebGlyphCache.cpp',
    316                 'src/WebGraphicsContext3D.cpp',
    317                 'src/WebGraphicsContext3DDefaultImpl.cpp',
    318                 'src/WebGraphicsContext3DDefaultImpl.h',
    319315                'src/WebHistoryItem.cpp',
    320316                'src/WebHTTPBody.cpp',
  • trunk/WebKit/chromium/public/WebKitClient.h

    r56294 r56303  
    5050class WebClipboard;
    5151class WebCookieJar;
    52 class WebGraphicsContext3D;
    5352class WebIndexedDatabase;
    5453class WebMessagePortChannel;
     
    271270    virtual void callOnMainThread(void (*func)()) { }
    272271
    273     // WebGL --------------------------------------------------------------
    274 
    275     // May return null if WebGL is not supported.
    276     // Returns newly allocated WebGraphicsContext3D instance.
    277     virtual WebGraphicsContext3D* createGraphicsContext3D() { return 0; }
    278 
    279272protected:
    280273    ~WebKitClient() { }
  • trunk/WebKit/chromium/src/GraphicsContext3D.cpp

    r56294 r56303  
    3535#include "GraphicsContext3D.h"
    3636
     37#include "CachedImage.h"
    3738#include "CString.h"
    38 #include "CachedImage.h"
    3939#include "HTMLCanvasElement.h"
    4040#include "HTMLImageElement.h"
    4141#include "ImageBuffer.h"
    4242#include "ImageData.h"
     43#include "NotImplemented.h"
    4344#include "WebGLBuffer.h"
    4445#include "WebGLByteArray.h"
     
    5253#include "WebGLTexture.h"
    5354#include "WebGLUnsignedByteArray.h"
    54 #include "WebGraphicsContext3D.h"
    55 #include "WebGraphicsContext3DDefaultImpl.h"
    56 #include "WebKit.h"
    57 #include "WebKitClient.h"
    5855
    5956#include <stdio.h>
    6057#include <wtf/FastMalloc.h>
     58
     59#if OS(WINDOWS)
     60#include <windows.h>
     61#endif
     62
     63#include "GL/glew.h"
    6164
    6265#if PLATFORM(CG)
     
    6467#include <CoreGraphics/CGContext.h>
    6568#include <CoreGraphics/CGImage.h>
     69#include <OpenGL/OpenGL.h>
     70#else
     71#define FLIP_FRAMEBUFFER_VERTICALLY
    6672#endif
    6773
    68 // using namespace std;
    69 
    70 // There are two levels of delegation in this file:
    71 //
    72 //   1. GraphicsContext3D delegates to GraphicsContext3DInternal. This is done
    73 //      so that we have some place to store data members common among
    74 //      implementations; GraphicsContext3D only provides us the m_internal
    75 //      pointer. We always delegate to the GraphicsContext3DInternal. While we
    76 //      could sidestep it and go directly to the WebGraphicsContext3D in some
    77 //      cases, it is better for consistency to always delegate through it.
    78 //
    79 //   2. GraphicsContext3DInternal delegates to an implementation of
    80 //      WebGraphicsContext3D. This is done so we have a place to inject an
    81 //      implementation which remotes the OpenGL calls across processes.
    82 //
    83 // The legacy, in-process, implementation uses WebGraphicsContext3DDefaultImpl.
     74#if OS(DARWIN)
     75#define USE_TEXTURE_RECTANGLE_FOR_FRAMEBUFFER
     76#endif
     77
     78#if OS(LINUX)
     79#include <dlfcn.h>
     80#include "GL/glxew.h"
     81#endif
     82
     83using namespace std;
    8484
    8585namespace WebCore {
    8686
    87 //----------------------------------------------------------------------
    88 // GraphicsContext3DInternal
     87// GraphicsContext3DInternal -----------------------------------------------------
    8988
    9089// Uncomment this to render to a separate window for debugging
     
    9594class GraphicsContext3DInternal {
    9695public:
    97     GraphicsContext3DInternal();
     96    GraphicsContext3DInternal(GraphicsContext3D::Attributes attrs);
    9897    ~GraphicsContext3DInternal();
    9998
    100     bool initialize(GraphicsContext3D::Attributes attrs);
     99    bool makeContextCurrent();
    101100
    102101    PlatformGraphicsContext3D platformGraphicsContext3D() const;
    103102    Platform3DObject platformTexture() const;
    104103
    105     bool makeContextCurrent();
    106 
    107     int sizeInBytes(int type);
    108 
    109104    void reshape(int width, int height);
    110105
    111106    void beginPaint(WebGLRenderingContext* context);
    112     void endPaint();
    113 
    114     //----------------------------------------------------------------------
    115     // Entry points for WebGL.
    116     //
     107
     108    bool validateTextureTarget(int target);
     109    bool validateTextureParameter(int param);
     110
    117111    void activeTexture(unsigned long texture);
    118     void attachShader(WebGLProgram* program, WebGLShader* shader);
    119     void bindAttribLocation(WebGLProgram*, unsigned long index, const String& name);
    120     void bindBuffer(unsigned long target, WebGLBuffer*);
    121     void bindFramebuffer(unsigned long target, WebGLFramebuffer*);
    122     void bindRenderbuffer(unsigned long target, WebGLRenderbuffer*);
    123     void bindTexture(unsigned long target, WebGLTexture* texture);
    124     void blendColor(double red, double green, double blue, double alpha);
    125     void blendEquation(unsigned long mode);
    126     void blendEquationSeparate(unsigned long modeRGB, unsigned long modeAlpha);
    127     void blendFunc(unsigned long sfactor, unsigned long dfactor);
    128     void blendFuncSeparate(unsigned long srcRGB, unsigned long dstRGB, unsigned long srcAlpha, unsigned long dstAlpha);
    129 
    130     void bufferData(unsigned long target, int size, unsigned long usage);
    131     void bufferData(unsigned long target, WebGLArray* data, unsigned long usage);
    132     void bufferSubData(unsigned long target, long offset, WebGLArray* data);
    133 
    134     unsigned long checkFramebufferStatus(unsigned long target);
    135     void clear(unsigned long mask);
    136     void clearColor(double red, double green, double blue, double alpha);
    137     void clearDepth(double depth);
    138     void clearStencil(long s);
    139     void colorMask(bool red, bool green, bool blue, bool alpha);
    140     void compileShader(WebGLShader*);
    141 
    142     void copyTexImage2D(unsigned long target, long level, unsigned long internalformat, long x, long y, unsigned long width, unsigned long height, long border);
    143     void copyTexSubImage2D(unsigned long target, long level, long xoffset, long yoffset, long x, long y, unsigned long width, unsigned long height);
    144     void cullFace(unsigned long mode);
    145     void depthFunc(unsigned long func);
    146     void depthMask(bool flag);
    147     void depthRange(double zNear, double zFar);
    148     void detachShader(WebGLProgram*, WebGLShader*);
    149     void disable(unsigned long cap);
     112    void bindBuffer(unsigned long target,
     113                    WebGLBuffer* buffer);
     114    void bindFramebuffer(unsigned long target,
     115                         WebGLFramebuffer* framebuffer);
     116    void bindTexture(unsigned long target,
     117                     WebGLTexture* texture);
     118    void bufferDataImpl(unsigned long target, int size, const void* data, unsigned long usage);
    150119    void disableVertexAttribArray(unsigned long index);
    151     void drawArrays(unsigned long mode, long first, long count);
    152     void drawElements(unsigned long mode, unsigned long count, unsigned long type, long offset);
    153 
    154     void enable(unsigned long cap);
    155120    void enableVertexAttribArray(unsigned long index);
    156     void finish();
    157     void flush();
    158     void framebufferRenderbuffer(unsigned long target, unsigned long attachment, unsigned long renderbuffertarget, WebGLRenderbuffer*);
    159     void framebufferTexture2D(unsigned long target, unsigned long attachment, unsigned long textarget, WebGLTexture*, long level);
    160     void frontFace(unsigned long mode);
    161     void generateMipmap(unsigned long target);
    162 
    163     bool getActiveAttrib(WebGLProgram* program, unsigned long index, ActiveInfo&);
    164     bool getActiveUniform(WebGLProgram* program, unsigned long index, ActiveInfo&);
    165 
    166     int  getAttribLocation(WebGLProgram*, const String& name);
    167 
    168     void getBooleanv(unsigned long pname, unsigned char* value);
    169 
    170     void getBufferParameteriv(unsigned long target, unsigned long pname, int* value);
    171 
     121    unsigned long getError();
    172122    GraphicsContext3D::Attributes getContextAttributes();
    173 
    174     unsigned long getError();
    175 
    176     void getFloatv(unsigned long pname, float* value);
    177 
    178     void getFramebufferAttachmentParameteriv(unsigned long target, unsigned long attachment, unsigned long pname, int* value);
    179 
    180     void getIntegerv(unsigned long pname, int* value);
    181 
    182     void getProgramiv(WebGLProgram* program, unsigned long pname, int* value);
    183 
    184     String getProgramInfoLog(WebGLProgram*);
    185 
    186     void getRenderbufferParameteriv(unsigned long target, unsigned long pname, int* value);
    187 
    188     void getShaderiv(WebGLShader*, unsigned long pname, int* value);
    189 
    190     String getShaderInfoLog(WebGLShader*);
    191 
    192     String getShaderSource(WebGLShader*);
    193     String getString(unsigned long name);
    194 
    195     void getTexParameterfv(unsigned long target, unsigned long pname, float* value);
    196     void getTexParameteriv(unsigned long target, unsigned long pname, int* value);
    197 
    198     void getUniformfv(WebGLProgram* program, long location, float* value);
    199     void getUniformiv(WebGLProgram* program, long location, int* value);
    200 
    201     long getUniformLocation(WebGLProgram*, const String& name);
    202 
    203     void getVertexAttribfv(unsigned long index, unsigned long pname, float* value);
    204     void getVertexAttribiv(unsigned long index, unsigned long pname, int* value);
    205 
    206     long getVertexAttribOffset(unsigned long index, unsigned long pname);
    207 
    208     void hint(unsigned long target, unsigned long mode);
    209     bool isBuffer(WebGLBuffer*);
    210     bool isEnabled(unsigned long cap);
    211     bool isFramebuffer(WebGLFramebuffer*);
    212     bool isProgram(WebGLProgram*);
    213     bool isRenderbuffer(WebGLRenderbuffer*);
    214     bool isShader(WebGLShader*);
    215     bool isTexture(WebGLTexture*);
    216     void lineWidth(double);
    217     void linkProgram(WebGLProgram*);
    218     void pixelStorei(unsigned long pname, long param);
    219     void polygonOffset(double factor, double units);
    220 
    221     PassRefPtr<WebGLArray> readPixels(long x, long y, unsigned long width, unsigned long height, unsigned long format, unsigned long type);
    222 
    223     void releaseShaderCompiler();
    224     void renderbufferStorage(unsigned long target, unsigned long internalformat, unsigned long width, unsigned long height);
    225     void sampleCoverage(double value, bool invert);
    226     void scissor(long x, long y, unsigned long width, unsigned long height);
    227     void shaderSource(WebGLShader*, const String& string);
    228     void stencilFunc(unsigned long func, long ref, unsigned long mask);
    229     void stencilFuncSeparate(unsigned long face, unsigned long func, long ref, unsigned long mask);
    230     void stencilMask(unsigned long mask);
    231     void stencilMaskSeparate(unsigned long face, unsigned long mask);
    232     void stencilOp(unsigned long fail, unsigned long zfail, unsigned long zpass);
    233     void stencilOpSeparate(unsigned long face, unsigned long fail, unsigned long zfail, unsigned long zpass);
    234 
    235     // These next several functions return an error code (0 if no errors) rather than using an ExceptionCode.
    236     // Currently they return -1 on any error.
    237     int texImage2D(unsigned target, unsigned level, unsigned internalformat, unsigned width, unsigned height, unsigned border, unsigned format, unsigned type, void* pixels);
    238 
    239     void texParameterf(unsigned target, unsigned pname, float param);
    240     void texParameteri(unsigned target, unsigned pname, int param);
    241 
    242     int texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, unsigned width, unsigned height, unsigned format, unsigned type, void* pixels);
    243 
    244     void uniform1f(long location, float x);
    245     void uniform1fv(long location, float* v, int size);
    246     void uniform1i(long location, int x);
    247     void uniform1iv(long location, int* v, int size);
    248     void uniform2f(long location, float x, float y);
    249     void uniform2fv(long location, float* v, int size);
    250     void uniform2i(long location, int x, int y);
    251     void uniform2iv(long location, int* v, int size);
    252     void uniform3f(long location, float x, float y, float z);
    253     void uniform3fv(long location, float* v, int size);
    254     void uniform3i(long location, int x, int y, int z);
    255     void uniform3iv(long location, int* v, int size);
    256     void uniform4f(long location, float x, float y, float z, float w);
    257     void uniform4fv(long location, float* v, int size);
    258     void uniform4i(long location, int x, int y, int z, int w);
    259     void uniform4iv(long location, int* v, int size);
    260     void uniformMatrix2fv(long location, bool transpose, float* value, int size);
    261     void uniformMatrix3fv(long location, bool transpose, float* value, int size);
    262     void uniformMatrix4fv(long location, bool transpose, float* value, int size);
    263 
    264     void useProgram(WebGLProgram*);
    265     void validateProgram(WebGLProgram*);
    266 
    267     void vertexAttrib1f(unsigned long indx, float x);
    268     void vertexAttrib1fv(unsigned long indx, float* values);
    269     void vertexAttrib2f(unsigned long indx, float x, float y);
    270     void vertexAttrib2fv(unsigned long indx, float* values);
    271     void vertexAttrib3f(unsigned long indx, float x, float y, float z);
    272     void vertexAttrib3fv(unsigned long indx, float* values);
    273     void vertexAttrib4f(unsigned long indx, float x, float y, float z, float w);
    274     void vertexAttrib4fv(unsigned long indx, float* values);
    275123    void vertexAttribPointer(unsigned long indx, int size, int type, bool normalized,
    276124                             unsigned long stride, unsigned long offset);
    277 
    278     void viewport(long x, long y, unsigned long width, unsigned long height);
    279 
    280     unsigned createBuffer();
    281     unsigned createFramebuffer();
    282     unsigned createProgram();
    283     unsigned createRenderbuffer();
    284     unsigned createShader(unsigned long);
    285     unsigned createTexture();
    286 
    287     void deleteBuffer(unsigned);
    288     void deleteFramebuffer(unsigned);
    289     void deleteProgram(unsigned);
    290     void deleteRenderbuffer(unsigned);
    291     void deleteShader(unsigned);
    292     void deleteTexture(unsigned);
     125    void viewportImpl(long x, long y, unsigned long width, unsigned long height);
    293126
    294127    void synthesizeGLError(unsigned long error);
    295128
    296129private:
    297     OwnPtr<WebKit::WebGraphicsContext3D> m_impl;
     130    GraphicsContext3D::Attributes m_attrs;
     131
     132    unsigned int m_texture;
     133    unsigned int m_fbo;
     134    unsigned int m_depthBuffer;
     135    unsigned int m_cachedWidth, m_cachedHeight;
     136
     137    // For tracking which FBO is bound
     138    unsigned int m_boundFBO;
     139
     140#ifdef FLIP_FRAMEBUFFER_VERTICALLY
     141    unsigned char* m_scanline;
     142    void flipVertically(unsigned char* framebuffer,
     143                        unsigned int width,
     144                        unsigned int height);
     145#endif
     146
     147    // Note: we aren't currently using this information, but we will
     148    // need to in order to verify that all enabled vertex arrays have
     149    // a valid buffer bound -- to avoid crashes on certain cards.
     150    unsigned int m_boundArrayBuffer;
     151    class VertexAttribPointerState {
     152    public:
     153        VertexAttribPointerState();
     154
     155        bool enabled;
     156        unsigned long buffer;
     157        unsigned long indx;
     158        int size;
     159        int type;
     160        bool normalized;
     161        unsigned long stride;
     162        unsigned long offset;
     163    };
     164
     165    enum {
     166        NumTrackedPointerStates = 2
     167    };
     168    VertexAttribPointerState m_vertexAttribPointerState[NumTrackedPointerStates];
     169
     170    // Errors raised by synthesizeGLError().
     171    ListHashSet<unsigned long> m_syntheticErrors;
     172
    298173#if PLATFORM(SKIA)
    299174    // If the width and height of the Canvas's backing store don't
     
    305180#endif
    306181
    307 #if PLATFORM(CG)
     182    static bool s_initializedGLEW;
     183#if OS(WINDOWS)
     184    HWND  m_canvasWindow;
     185    HDC   m_canvasDC;
     186    HGLRC m_contextObj;
     187#elif PLATFORM(CG)
     188    CGLPBufferObj m_pbuffer;
     189    CGLContextObj m_contextObj;
    308190    unsigned char* m_renderOutput;
     191#elif OS(LINUX)
     192    GLXContext m_contextObj;
     193    GLXPbuffer m_pbuffer;
     194
     195    // In order to avoid problems caused by linking against libGL, we
     196    // dynamically look up all the symbols we need.
     197    // http://code.google.com/p/chromium/issues/detail?id=16800
     198    class GLConnection {
     199      public:
     200        ~GLConnection();
     201
     202        static GLConnection* create();
     203
     204        GLXFBConfig* chooseFBConfig(int screen, const int *attrib_list, int *nelements)
     205        {
     206            return m_glXChooseFBConfig(m_display, screen, attrib_list, nelements);
     207        }
     208
     209        GLXContext createNewContext(GLXFBConfig config, int renderType, GLXContext shareList, Bool direct)
     210        {
     211            return m_glXCreateNewContext(m_display, config, renderType, shareList, direct);
     212        }
     213
     214        GLXPbuffer createPbuffer(GLXFBConfig config, const int *attribList)
     215        {
     216            return m_glXCreatePbuffer(m_display, config, attribList);
     217        }
     218
     219        void destroyPbuffer(GLXPbuffer pbuf)
     220        {
     221            m_glXDestroyPbuffer(m_display, pbuf);
     222        }
     223
     224        Bool makeCurrent(GLXDrawable drawable, GLXContext ctx)
     225        {
     226            return m_glXMakeCurrent(m_display, drawable, ctx);
     227        }
     228
     229        void destroyContext(GLXContext ctx)
     230        {
     231            m_glXDestroyContext(m_display, ctx);
     232        }
     233
     234        GLXContext getCurrentContext()
     235        {
     236            return m_glXGetCurrentContext();
     237        }
     238
     239      private:
     240        Display* m_display;
     241        void* m_libGL;
     242        PFNGLXCHOOSEFBCONFIGPROC m_glXChooseFBConfig;
     243        PFNGLXCREATENEWCONTEXTPROC m_glXCreateNewContext;
     244        PFNGLXCREATEPBUFFERPROC m_glXCreatePbuffer;
     245        PFNGLXDESTROYPBUFFERPROC m_glXDestroyPbuffer;
     246        typedef Bool (* PFNGLXMAKECURRENTPROC)(Display* dpy, GLXDrawable drawable, GLXContext ctx);
     247        PFNGLXMAKECURRENTPROC m_glXMakeCurrent;
     248        typedef void (* PFNGLXDESTROYCONTEXTPROC)(Display* dpy, GLXContext ctx);
     249        PFNGLXDESTROYCONTEXTPROC m_glXDestroyContext;
     250        typedef GLXContext (* PFNGLXGETCURRENTCONTEXTPROC)(void);
     251        PFNGLXGETCURRENTCONTEXTPROC m_glXGetCurrentContext;
     252
     253        GLConnection(Display* display,
     254                     void* libGL,
     255                     PFNGLXCHOOSEFBCONFIGPROC chooseFBConfig,
     256                     PFNGLXCREATENEWCONTEXTPROC createNewContext,
     257                     PFNGLXCREATEPBUFFERPROC createPbuffer,
     258                     PFNGLXDESTROYPBUFFERPROC destroyPbuffer,
     259                     PFNGLXMAKECURRENTPROC makeCurrent,
     260                     PFNGLXDESTROYCONTEXTPROC destroyContext,
     261                     PFNGLXGETCURRENTCONTEXTPROC getCurrentContext)
     262            : m_libGL(libGL)
     263            , m_display(display)
     264            , m_glXChooseFBConfig(chooseFBConfig)
     265            , m_glXCreateNewContext(createNewContext)
     266            , m_glXCreatePbuffer(createPbuffer)
     267            , m_glXDestroyPbuffer(destroyPbuffer)
     268            , m_glXMakeCurrent(makeCurrent)
     269            , m_glXDestroyContext(destroyContext)
     270            , m_glXGetCurrentContext(getCurrentContext)
     271        {
     272        }
     273    };
     274
     275    static GLConnection* s_gl;
     276#else
     277    #error Must port GraphicsContext3D to your platform
    309278#endif
    310279};
    311280
    312 GraphicsContext3DInternal::GraphicsContext3DInternal()
     281bool GraphicsContext3DInternal::s_initializedGLEW = false;
     282
     283#if OS(LINUX)
     284GraphicsContext3DInternal::GLConnection* GraphicsContext3DInternal::s_gl = 0;
     285
     286GraphicsContext3DInternal::GLConnection* GraphicsContext3DInternal::GLConnection::create()
     287{
     288    Display* dpy = XOpenDisplay(0);
     289    if (!dpy) {
     290        printf("GraphicsContext3D: error opening X display\n");
     291        return 0;
     292    }
     293
     294    // We use RTLD_GLOBAL semantics so that GLEW initialization works;
     295    // GLEW expects to be able to open the current process's handle
     296    // and do dlsym's of GL entry points from there.
     297    void* libGL = dlopen("libGL.so.1", RTLD_LAZY | RTLD_GLOBAL);
     298    if (!libGL) {
     299        XCloseDisplay(dpy);
     300        printf("GraphicsContext3D: error opening libGL.so.1: %s\n", dlerror());
     301        return 0;
     302    }
     303
     304    PFNGLXCHOOSEFBCONFIGPROC chooseFBConfig = (PFNGLXCHOOSEFBCONFIGPROC) dlsym(libGL, "glXChooseFBConfig");
     305    PFNGLXCREATENEWCONTEXTPROC createNewContext = (PFNGLXCREATENEWCONTEXTPROC) dlsym(libGL, "glXCreateNewContext");
     306    PFNGLXCREATEPBUFFERPROC createPbuffer = (PFNGLXCREATEPBUFFERPROC) dlsym(libGL, "glXCreatePbuffer");
     307    PFNGLXDESTROYPBUFFERPROC destroyPbuffer = (PFNGLXDESTROYPBUFFERPROC) dlsym(libGL, "glXDestroyPbuffer");
     308    PFNGLXMAKECURRENTPROC makeCurrent = (PFNGLXMAKECURRENTPROC) dlsym(libGL, "glXMakeCurrent");
     309    PFNGLXDESTROYCONTEXTPROC destroyContext = (PFNGLXDESTROYCONTEXTPROC) dlsym(libGL, "glXDestroyContext");
     310    PFNGLXGETCURRENTCONTEXTPROC getCurrentContext = (PFNGLXGETCURRENTCONTEXTPROC) dlsym(libGL, "glXGetCurrentContext");
     311    if (!chooseFBConfig || !createNewContext || !createPbuffer
     312        || !destroyPbuffer || !makeCurrent || !destroyContext
     313        || !getCurrentContext) {
     314        XCloseDisplay(dpy);
     315        dlclose(libGL);
     316        printf("GraphicsContext3D: error looking up bootstrapping entry points\n");
     317        return 0;
     318    }
     319    return new GLConnection(dpy,
     320                            libGL,
     321                            chooseFBConfig,
     322                            createNewContext,
     323                            createPbuffer,
     324                            destroyPbuffer,
     325                            makeCurrent,
     326                            destroyContext,
     327                            getCurrentContext);
     328}
     329
     330GraphicsContext3DInternal::GLConnection::~GLConnection()
     331{
     332    XCloseDisplay(m_display);
     333    dlclose(m_libGL);
     334}
     335
     336#endif // OS(LINUX)
     337
     338GraphicsContext3DInternal::VertexAttribPointerState::VertexAttribPointerState()
     339    : enabled(false)
     340    , buffer(0)
     341    , indx(0)
     342    , size(0)
     343    , type(0)
     344    , normalized(false)
     345    , stride(0)
     346    , offset(0)
     347{
     348}
     349
     350GraphicsContext3DInternal::GraphicsContext3DInternal(GraphicsContext3D::Attributes attrs)
     351    : m_attrs(attrs)
     352    , m_texture(0)
     353    , m_fbo(0)
     354    , m_depthBuffer(0)
     355    , m_boundFBO(0)
     356#ifdef FLIP_FRAMEBUFFER_VERTICALLY
     357    , m_scanline(0)
     358#endif
     359    , m_boundArrayBuffer(0)
    313360#if PLATFORM(SKIA)
    314     : m_resizingBitmap(0)
     361    , m_resizingBitmap(0)
     362#endif
     363#if OS(WINDOWS)
     364    , m_canvasWindow(0)
     365    , m_canvasDC(0)
     366    , m_contextObj(0)
    315367#elif PLATFORM(CG)
    316     : m_renderOutput(0)
     368    , m_pbuffer(0)
     369    , m_contextObj(0)
     370    , m_renderOutput(0)
     371#elif OS(LINUX)
     372    , m_contextObj(0)
     373    , m_pbuffer(0)
    317374#else
    318375#error Must port to your platform
    319376#endif
    320377{
     378    // FIXME: we need to take into account the user's requested
     379    // context creation attributes, in particular stencil and
     380    // antialias, and determine which could and could not be honored
     381    // based on the capabilities of the OpenGL implementation.
     382    m_attrs.alpha = true;
     383    m_attrs.depth = true;
     384    m_attrs.stencil = false;
     385    m_attrs.antialias = false;
     386    m_attrs.premultipliedAlpha = true;
     387
     388#if OS(WINDOWS)
     389    WNDCLASS wc;
     390    if (!GetClassInfo(GetModuleHandle(0), L"CANVASGL", &wc)) {
     391        ZeroMemory(&wc, sizeof(WNDCLASS));
     392        wc.style = CS_OWNDC;
     393        wc.hInstance = GetModuleHandle(0);
     394        wc.lpfnWndProc = DefWindowProc;
     395        wc.lpszClassName = L"CANVASGL";
     396
     397        if (!RegisterClass(&wc)) {
     398            printf("GraphicsContext3D: RegisterClass failed\n");
     399            return;
     400        }
     401    }
     402
     403    m_canvasWindow = CreateWindow(L"CANVASGL", L"CANVASGL",
     404                                  WS_CAPTION,
     405                                  CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
     406                                  CW_USEDEFAULT, 0, 0, GetModuleHandle(0), 0);
     407    if (!m_canvasWindow) {
     408        printf("GraphicsContext3DInternal: CreateWindow failed\n");
     409        return;
     410    }
     411
     412    // get the device context
     413    m_canvasDC = GetDC(m_canvasWindow);
     414    if (!m_canvasDC) {
     415        printf("GraphicsContext3DInternal: GetDC failed\n");
     416        return;
     417    }
     418
     419    // find default pixel format
     420    PIXELFORMATDESCRIPTOR pfd;
     421    ZeroMemory(&pfd, sizeof(PIXELFORMATDESCRIPTOR));
     422    pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
     423    pfd.nVersion = 1;
     424    pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL
     425#ifdef RENDER_TO_DEBUGGING_WINDOW
     426        | PFD_DOUBLEBUFFER
     427#endif // RENDER_TO_DEBUGGING_WINDOW
     428        ;
     429    int pixelformat = ChoosePixelFormat(m_canvasDC, &pfd);
     430
     431    // set the pixel format for the dc
     432    if (!SetPixelFormat(m_canvasDC, pixelformat, &pfd)) {
     433        printf("GraphicsContext3D: SetPixelFormat failed\n");
     434        return;
     435    }
     436
     437    // create rendering context
     438    m_contextObj = wglCreateContext(m_canvasDC);
     439    if (!m_contextObj) {
     440        printf("GraphicsContext3D: wglCreateContext failed\n");
     441        return;
     442    }
     443
     444    if (!wglMakeCurrent(m_canvasDC, m_contextObj)) {
     445        printf("GraphicsContext3D: wglMakeCurrent failed\n");
     446        return;
     447    }
     448
     449#ifdef RENDER_TO_DEBUGGING_WINDOW
     450    typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC) (int interval);
     451    PFNWGLSWAPINTERVALEXTPROC setSwapInterval = 0;
     452    setSwapInterval = (PFNWGLSWAPINTERVALEXTPROC) wglGetProcAddress("wglSwapIntervalEXT");
     453    if (setSwapInterval)
     454        setSwapInterval(1);
     455#endif // RENDER_TO_DEBUGGING_WINDOW
     456
     457#elif PLATFORM(CG)
     458    // Create a 1x1 pbuffer and associated context to bootstrap things
     459    CGLPixelFormatAttribute attribs[] = {
     460        (CGLPixelFormatAttribute) kCGLPFAPBuffer,
     461        (CGLPixelFormatAttribute) 0
     462    };
     463    CGLPixelFormatObj pixelFormat;
     464    GLint numPixelFormats;
     465    if (CGLChoosePixelFormat(attribs, &pixelFormat, &numPixelFormats) != kCGLNoError) {
     466        printf("GraphicsContext3D: error choosing pixel format\n");
     467        return;
     468    }
     469    if (!pixelFormat) {
     470        printf("GraphicsContext3D: no pixel format selected\n");
     471        return;
     472    }
     473    CGLContextObj context;
     474    CGLError res = CGLCreateContext(pixelFormat, 0, &context);
     475    CGLDestroyPixelFormat(pixelFormat);
     476    if (res != kCGLNoError) {
     477        printf("GraphicsContext3D: error creating context\n");
     478        return;
     479    }
     480    CGLPBufferObj pbuffer;
     481    if (CGLCreatePBuffer(1, 1, GL_TEXTURE_2D, GL_RGBA, 0, &pbuffer) != kCGLNoError) {
     482        CGLDestroyContext(context);
     483        printf("GraphicsContext3D: error creating pbuffer\n");
     484        return;
     485    }
     486    if (CGLSetPBuffer(context, pbuffer, 0, 0, 0) != kCGLNoError) {
     487        CGLDestroyContext(context);
     488        CGLDestroyPBuffer(pbuffer);
     489        printf("GraphicsContext3D: error attaching pbuffer to context\n");
     490        return;
     491    }
     492    if (CGLSetCurrentContext(context) != kCGLNoError) {
     493        CGLDestroyContext(context);
     494        CGLDestroyPBuffer(pbuffer);
     495        printf("GraphicsContext3D: error making context current\n");
     496        return;
     497    }
     498    m_pbuffer = pbuffer;
     499    m_contextObj = context;
     500#elif OS(LINUX)
     501    if (!s_gl) {
     502        s_gl = GLConnection::create();
     503        if (!s_gl)
     504            return;
     505    }
     506
     507    int configAttrs[] = {
     508        GLX_DRAWABLE_TYPE,
     509        GLX_PBUFFER_BIT,
     510        GLX_RENDER_TYPE,
     511        GLX_RGBA_BIT,
     512        GLX_DOUBLEBUFFER,
     513        0,
     514        0
     515    };
     516    int nelements = 0;
     517    GLXFBConfig* config = s_gl->chooseFBConfig(0, configAttrs, &nelements);
     518    if (!config) {
     519        printf("GraphicsContext3D: glXChooseFBConfig failed\n");
     520        return;
     521    }
     522    if (!nelements) {
     523        printf("GraphicsContext3D: glXChooseFBConfig returned 0 elements\n");
     524        XFree(config);
     525        return;
     526    }
     527    GLXContext context = s_gl->createNewContext(config[0], GLX_RGBA_TYPE, 0, True);
     528    if (!context) {
     529        printf("GraphicsContext3D: glXCreateNewContext failed\n");
     530        XFree(config);
     531        return;
     532    }
     533    int pbufferAttrs[] = {
     534        GLX_PBUFFER_WIDTH,
     535        1,
     536        GLX_PBUFFER_HEIGHT,
     537        1,
     538        0
     539    };
     540    GLXPbuffer pbuffer = s_gl->createPbuffer(config[0], pbufferAttrs);
     541    XFree(config);
     542    if (!pbuffer) {
     543        printf("GraphicsContext3D: glxCreatePbuffer failed\n");
     544        return;
     545    }
     546    if (!s_gl->makeCurrent(pbuffer, context)) {
     547        printf("GraphicsContext3D: glXMakeCurrent failed\n");
     548        return;
     549    }
     550    m_contextObj = context;
     551    m_pbuffer = pbuffer;
     552#else
     553#error Must port to your platform
     554#endif
     555
     556    if (!s_initializedGLEW) {
     557        // Initialize GLEW and check for GL 2.0 support by the drivers.
     558        GLenum glewInitResult = glewInit();
     559        if (glewInitResult != GLEW_OK) {
     560            printf("GraphicsContext3D: GLEW initialization failed\n");
     561            return;
     562        }
     563        if (!glewIsSupported("GL_VERSION_2_0")) {
     564            printf("GraphicsContext3D: OpenGL 2.0 not supported\n");
     565            return;
     566        }
     567        s_initializedGLEW = true;
     568    }
    321569}
    322570
    323571GraphicsContext3DInternal::~GraphicsContext3DInternal()
    324572{
    325 #if PLATFORM(SKIA)
    326     if (m_resizingBitmap)
    327         delete m_resizingBitmap;
    328 #elif PLATFORM(CG)
    329     if (m_renderOutput)
    330         delete[] m_renderOutput;
    331 #endif
    332 
     573    makeContextCurrent();
     574#ifndef RENDER_TO_DEBUGGING_WINDOW
     575    glDeleteRenderbuffersEXT(1, &m_depthBuffer);
     576    glDeleteTextures(1, &m_texture);
    333577#ifdef FLIP_FRAMEBUFFER_VERTICALLY
    334578    if (m_scanline)
    335579        delete[] m_scanline;
    336580#endif
     581    glDeleteFramebuffersEXT(1, &m_fbo);
     582#endif // !RENDER_TO_DEBUGGING_WINDOW
    337583#if PLATFORM(SKIA)
    338584    if (m_resizingBitmap)
    339585        delete m_resizingBitmap;
    340586#endif
    341 }
    342 
    343 bool GraphicsContext3DInternal::initialize(GraphicsContext3D::Attributes attrs)
    344 {
    345     WebKit::WebGraphicsContext3D::Attributes webAttributes;
    346     webAttributes.alpha = attrs.alpha;
    347     webAttributes.depth = attrs.depth;
    348     webAttributes.stencil = attrs.stencil;
    349     webAttributes.antialias = attrs.antialias;
    350     webAttributes.premultipliedAlpha = attrs.premultipliedAlpha;
    351     // FIXME: once the Chromium portion of the WebKitClient changes has landed,
    352     // change this to call WebKit::webKitClient()->createGraphicsContext3D().
    353     WebKit::WebGraphicsContext3D* webContext = WebKit::WebGraphicsContext3D::createDefault();
    354     if (!webContext)
    355         return false;
    356     if (!webContext->initialize(webAttributes)) {
    357         delete webContext;
    358         return false;
    359     }
    360     m_impl.set(webContext);
    361     return true;
     587#if OS(WINDOWS)
     588    wglMakeCurrent(0, 0);
     589    wglDeleteContext(m_contextObj);
     590    ReleaseDC(m_canvasWindow, m_canvasDC);
     591    DestroyWindow(m_canvasWindow);
     592#elif PLATFORM(CG)
     593    CGLSetCurrentContext(0);
     594    CGLDestroyContext(m_contextObj);
     595    CGLDestroyPBuffer(m_pbuffer);
     596    if (m_renderOutput)
     597        delete[] m_renderOutput;
     598#elif OS(LINUX)
     599    s_gl->makeCurrent(0, 0);
     600    s_gl->destroyContext(m_contextObj);
     601    s_gl->destroyPbuffer(m_pbuffer);
     602#else
     603#error Must port to your platform
     604#endif
     605    m_contextObj = 0;
     606}
     607
     608bool GraphicsContext3DInternal::makeContextCurrent()
     609{
     610#if OS(WINDOWS)
     611    if (wglGetCurrentContext() != m_contextObj)
     612        if (wglMakeCurrent(m_canvasDC, m_contextObj))
     613            return true;
     614#elif PLATFORM(CG)
     615    if (CGLGetCurrentContext() != m_contextObj)
     616        if (CGLSetCurrentContext(m_contextObj) == kCGLNoError)
     617            return true;
     618#elif OS(LINUX)
     619    if (s_gl->getCurrentContext() != m_contextObj)
     620        if (s_gl->makeCurrent(m_pbuffer, m_contextObj))
     621            return true;
     622#else
     623#error Must port to your platform
     624#endif
     625    return false;
    362626}
    363627
    364628PlatformGraphicsContext3D GraphicsContext3DInternal::platformGraphicsContext3D() const
    365629{
    366     return 0;
     630    return m_contextObj;
    367631}
    368632
    369633Platform3DObject GraphicsContext3DInternal::platformTexture() const
    370634{
    371     return 0;
    372 }
     635    return m_texture;
     636}
     637
     638static int createTextureObject(GLenum target)
     639{
     640    GLuint texture = 0;
     641    glGenTextures(1, &texture);
     642    glBindTexture(target, texture);
     643    glTexParameterf(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
     644    glTexParameterf(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
     645    return texture;
     646}
     647
     648void GraphicsContext3DInternal::reshape(int width, int height)
     649{
     650#ifdef RENDER_TO_DEBUGGING_WINDOW
     651    SetWindowPos(m_canvasWindow, HWND_TOP, 0, 0, width, height,
     652                 SWP_NOMOVE);
     653    ShowWindow(m_canvasWindow, SW_SHOW);
     654#endif
     655
     656    m_cachedWidth = width;
     657    m_cachedHeight = height;
     658    makeContextCurrent();
     659
     660#ifndef RENDER_TO_DEBUGGING_WINDOW
     661#ifdef USE_TEXTURE_RECTANGLE_FOR_FRAMEBUFFER
     662    // GL_TEXTURE_RECTANGLE_ARB is the best supported render target on Mac OS X
     663    GLenum target = GL_TEXTURE_RECTANGLE_ARB;
     664#else
     665    GLenum target = GL_TEXTURE_2D;
     666#endif
     667    if (!m_texture) {
     668        // Generate the texture object
     669        m_texture = createTextureObject(target);
     670        // Generate the framebuffer object
     671        glGenFramebuffersEXT(1, &m_fbo);
     672        // Generate the depth buffer
     673        glGenRenderbuffersEXT(1, &m_depthBuffer);
     674    }
     675
     676    // Reallocate the color and depth buffers
     677    glBindTexture(target, m_texture);
     678    glTexImage2D(target, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
     679    glBindTexture(target, 0);
     680
     681    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
     682    m_boundFBO = m_fbo;
     683    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_depthBuffer);
     684    glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, width, height);
     685    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
     686
     687    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, target, m_texture, 0);
     688    glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_depthBuffer);
     689    GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
     690    if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
     691        printf("GraphicsContext3D: framebuffer was incomplete\n");
     692
     693        // FIXME: cleanup.
     694        notImplemented();
     695    }
     696#endif  // RENDER_TO_DEBUGGING_WINDOW
     697
     698#ifdef FLIP_FRAMEBUFFER_VERTICALLY
     699    if (m_scanline) {
     700        delete[] m_scanline;
     701        m_scanline = 0;
     702    }
     703    m_scanline = new unsigned char[width * 4];
     704#endif  // FLIP_FRAMEBUFFER_VERTICALLY
     705
     706    glClear(GL_COLOR_BUFFER_BIT);
     707
     708#if PLATFORM(CG)
     709    // Need to reallocate the client-side backing store.
     710    // FIXME: make this more efficient.
     711    if (m_renderOutput) {
     712        delete[] m_renderOutput;
     713        m_renderOutput = 0;
     714    }
     715    int rowBytes = width * 4;
     716    m_renderOutput = new unsigned char[height * rowBytes];
     717#endif  // PLATFORM(CG)
     718}
     719
     720#ifdef FLIP_FRAMEBUFFER_VERTICALLY
     721void GraphicsContext3DInternal::flipVertically(unsigned char* framebuffer,
     722                                               unsigned int width,
     723                                               unsigned int height)
     724{
     725    unsigned char* scanline = m_scanline;
     726    if (!scanline)
     727        return;
     728    unsigned int rowBytes = width * 4;
     729    unsigned int count = height / 2;
     730    for (unsigned int i = 0; i < count; i++) {
     731        unsigned char* rowA = framebuffer + i * rowBytes;
     732        unsigned char* rowB = framebuffer + (height - i - 1) * rowBytes;
     733        // FIXME: this is where the multiplication of the alpha
     734        // channel into the color buffer will need to occur if the
     735        // user specifies the "premultiplyAlpha" flag in the context
     736        // creation attributes.
     737        memcpy(scanline, rowB, rowBytes);
     738        memcpy(rowB, rowA, rowBytes);
     739        memcpy(rowA, scanline, rowBytes);
     740    }
     741}
     742#endif
    373743
    374744void GraphicsContext3DInternal::beginPaint(WebGLRenderingContext* context)
    375745{
     746    makeContextCurrent();
     747
     748#ifdef RENDER_TO_DEBUGGING_WINDOW
     749    SwapBuffers(m_canvasDC);
     750#else
     751    // Earlier versions of this code used the GPU to flip the
     752    // framebuffer vertically before reading it back for compositing
     753    // via software. This code was quite complicated, used a lot of
     754    // GPU memory, and didn't provide an obvious speedup. Since this
     755    // vertical flip is only a temporary solution anyway until Chrome
     756    // is fully GPU composited, it wasn't worth the complexity.
     757
    376758    HTMLCanvasElement* canvas = context->canvas();
    377759    ImageBuffer* imageBuffer = canvas->buffer();
    378760    unsigned char* pixels = 0;
     761    bool mustRestoreFBO = (m_boundFBO != m_fbo);
     762    if (mustRestoreFBO)
     763        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
    379764#if PLATFORM(SKIA)
    380765    const SkBitmap* canvasBitmap = imageBuffer->context()->platformContext()->bitmap();
    381766    const SkBitmap* readbackBitmap = 0;
    382767    ASSERT(canvasBitmap->config() == SkBitmap::kARGB_8888_Config);
    383     if (canvasBitmap->width() == m_impl->width() && canvasBitmap->height() == m_impl->height()) {
     768    if (canvasBitmap->width() == m_cachedWidth && canvasBitmap->height() == m_cachedHeight) {
    384769        // This is the fastest and most common case. We read back
    385770        // directly into the canvas's backing store.
     
    393778        // pixel data. We will then use Skia to rescale this bitmap to
    394779        // the size of the canvas's backing store.
    395         if (m_resizingBitmap && (m_resizingBitmap->width() != m_impl->width() || m_resizingBitmap->height() != m_impl->height())) {
     780        if (m_resizingBitmap && (m_resizingBitmap->width() != m_cachedWidth || m_resizingBitmap->height() != m_cachedHeight)) {
    396781            delete m_resizingBitmap;
    397782            m_resizingBitmap = 0;
     
    400785            m_resizingBitmap = new SkBitmap();
    401786            m_resizingBitmap->setConfig(SkBitmap::kARGB_8888_Config,
    402                                         m_impl->width(),
    403                                         m_impl->height());
     787                                        m_cachedWidth,
     788                                        m_cachedHeight);
    404789            if (!m_resizingBitmap->allocPixels()) {
    405790                delete m_resizingBitmap;
     
    414799    SkAutoLockPixels bitmapLock(*readbackBitmap);
    415800    pixels = static_cast<unsigned char*>(readbackBitmap->getPixels());
     801    glReadPixels(0, 0, m_cachedWidth, m_cachedHeight, GL_BGRA, GL_UNSIGNED_BYTE, pixels);
    416802#elif PLATFORM(CG)
    417     if (m_renderOutput)
     803    if (m_renderOutput) {
    418804        pixels = m_renderOutput;
     805        glReadPixels(0, 0, m_cachedWidth, m_cachedHeight, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, pixels);
     806    }
    419807#else
    420808#error Must port to your platform
    421809#endif
    422810
    423     m_impl->readBackFramebuffer(pixels, 4 * m_impl->width() * m_impl->height());
     811    if (mustRestoreFBO)
     812        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_boundFBO);
     813
     814#ifdef FLIP_FRAMEBUFFER_VERTICALLY
     815    if (pixels)
     816        flipVertically(pixels, m_cachedWidth, m_cachedHeight);
     817#endif
    424818
    425819#if PLATFORM(SKIA)
     
    433827#elif PLATFORM(CG)
    434828    if (m_renderOutput) {
    435         int rowBytes = m_impl->width() * 4;
    436         CGDataProviderRef dataProvider = CGDataProviderCreateWithData(0, m_renderOutput, rowBytes * m_impl->height(), 0);
     829        int rowBytes = m_cachedWidth * 4;
     830        CGDataProviderRef dataProvider = CGDataProviderCreateWithData(0, m_renderOutput, rowBytes * m_cachedHeight, 0);
    437831        CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    438         CGImageRef cgImage = CGImageCreate(m_impl->width(),
    439                                            m_impl->height(),
     832        CGImageRef cgImage = CGImageCreate(m_cachedWidth,
     833                                           m_cachedHeight,
    440834                                           8,
    441835                                           32,
     
    468862#error Must port to your platform
    469863#endif
    470 }
    471 
    472 void GraphicsContext3DInternal::endPaint()
    473 {
    474 }
    475 
    476 void GraphicsContext3DInternal::reshape(int width, int height)
    477 {
    478     if (width == m_impl->width() && height == m_impl->height())
    479         return;
    480 
    481     m_impl->reshape(width, height);
    482 
    483 #if PLATFORM(CG)
    484     // Need to reallocate the client-side backing store.
    485     // FIXME: make this more efficient.
    486     if (m_renderOutput) {
    487         delete[] m_renderOutput;
    488         m_renderOutput = 0;
    489     }
    490     int rowBytes = width * 4;
    491     m_renderOutput = new unsigned char[height * rowBytes];
    492 #endif // PLATFORM(CG)
    493 }
    494 
    495 // Macros to assist in delegating from GraphicsContext3DInternal to
    496 // WebGraphicsContext3D.
    497 
    498 #define DELEGATE_TO_IMPL(name) \
    499 void GraphicsContext3DInternal::name() \
    500 { \
    501     m_impl->name(); \
    502 }
    503 
    504 #define DELEGATE_TO_IMPL_R(name, rt)           \
    505 rt GraphicsContext3DInternal::name() \
    506 { \
    507     return m_impl->name(); \
    508 }
    509 
    510 #define DELEGATE_TO_IMPL_1(name, t1) \
    511 void GraphicsContext3DInternal::name(t1 a1) \
    512 { \
    513     m_impl->name(a1); \
    514 }
    515 
    516 #define DELEGATE_TO_IMPL_1_X(name, t1) \
    517 void GraphicsContext3DInternal::name(t1 a1) \
    518 { \
    519     m_impl->name(EXTRACT(a1));                  \
    520 }
    521 
    522 #define DELEGATE_TO_IMPL_1R(name, t1, rt)    \
    523 rt GraphicsContext3DInternal::name(t1 a1) \
    524 { \
    525     return m_impl->name(a1); \
    526 }
    527 
    528 #define DELEGATE_TO_IMPL_1R_X(name, t1, rt)    \
    529 rt GraphicsContext3DInternal::name(t1 a1) \
    530 { \
    531     return m_impl->name(EXTRACT(a1));           \
    532 }
    533 
    534 #define DELEGATE_TO_IMPL_2(name, t1, t2) \
    535 void GraphicsContext3DInternal::name(t1 a1, t2 a2) \
    536 { \
    537     m_impl->name(a1, a2); \
    538 }
    539 
    540 #define DELEGATE_TO_IMPL_2_X12(name, t1, t2) \
    541 void GraphicsContext3DInternal::name(t1 a1, t2 a2) \
    542 { \
    543     m_impl->name(EXTRACT(a1), EXTRACT(a2));     \
    544 }
    545 
    546 #define DELEGATE_TO_IMPL_2_X2(name, t1, t2) \
    547 void GraphicsContext3DInternal::name(t1 a1, t2 a2) \
    548 { \
    549     m_impl->name(a1, EXTRACT(a2));     \
    550 }
    551 
    552 #define DELEGATE_TO_IMPL_2R(name, t1, t2, rt)  \
    553 rt GraphicsContext3DInternal::name(t1 a1, t2 a2) \
    554 { \
    555     return m_impl->name(a1, a2); \
    556 }
    557 
    558 #define DELEGATE_TO_IMPL_3(name, t1, t2, t3)   \
    559 void GraphicsContext3DInternal::name(t1 a1, t2 a2, t3 a3)    \
    560 { \
    561     m_impl->name(a1, a2, a3);                  \
    562 }
    563 
    564 #define DELEGATE_TO_IMPL_3_X1(name, t1, t2, t3)   \
    565 void GraphicsContext3DInternal::name(t1 a1, t2 a2, t3 a3)    \
    566 { \
    567     m_impl->name(EXTRACT(a1), a2, a3);          \
    568 }
    569 
    570 #define DELEGATE_TO_IMPL_3R(name, t1, t2, t3, rt)   \
    571 rt GraphicsContext3DInternal::name(t1 a1, t2 a2, t3 a3)    \
    572 { \
    573     return m_impl->name(a1, a2, a3);                  \
    574 }
    575 
    576 #define DELEGATE_TO_IMPL_4(name, t1, t2, t3, t4)    \
    577 void GraphicsContext3DInternal::name(t1 a1, t2 a2, t3 a3, t4 a4)  \
    578 { \
    579     m_impl->name(a1, a2, a3, a4);              \
    580 }
    581 
    582 #define DELEGATE_TO_IMPL_4_X4(name, t1, t2, t3, t4)    \
    583 void GraphicsContext3DInternal::name(t1 a1, t2 a2, t3 a3, t4 a4)  \
    584 { \
    585     m_impl->name(a1, a2, a3, EXTRACT(a4));      \
    586 }
    587 
    588 #define DELEGATE_TO_IMPL_5(name, t1, t2, t3, t4, t5)      \
    589 void GraphicsContext3DInternal::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5)        \
    590 { \
    591     m_impl->name(a1, a2, a3, a4, a5);   \
    592 }
    593 
    594 #define DELEGATE_TO_IMPL_5_X4(name, t1, t2, t3, t4, t5)                \
    595 void GraphicsContext3DInternal::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5)        \
    596 { \
    597     m_impl->name(a1, a2, a3, EXTRACT(a4), a5);  \
    598 }
    599 
    600 #define DELEGATE_TO_IMPL_5R(name, t1, t2, t3, t4, t5, rt)      \
    601 rt GraphicsContext3DInternal::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5)        \
    602 { \
    603     return m_impl->name(a1, a2, a3, a4, a5);   \
    604 }
    605 
    606 #define DELEGATE_TO_IMPL_6(name, t1, t2, t3, t4, t5, t6)  \
    607 void GraphicsContext3DInternal::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6) \
    608 { \
    609     m_impl->name(a1, a2, a3, a4, a5, a6);       \
    610 }
    611 
    612 #define DELEGATE_TO_IMPL_6R(name, t1, t2, t3, t4, t5, t6, rt)  \
    613 rt GraphicsContext3DInternal::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6) \
    614 { \
    615     return m_impl->name(a1, a2, a3, a4, a5, a6);       \
    616 }
    617 
    618 #define DELEGATE_TO_IMPL_7R(name, t1, t2, t3, t4, t5, t6, t7, rt) \
    619 rt GraphicsContext3DInternal::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7) \
    620 { \
    621     return m_impl->name(a1, a2, a3, a4, a5, a6, a7);   \
    622 }
    623 
    624 #define DELEGATE_TO_IMPL_8(name, t1, t2, t3, t4, t5, t6, t7, t8)       \
    625 void GraphicsContext3DInternal::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8 a8) \
    626 { \
    627     m_impl->name(a1, a2, a3, a4, a5, a6, a7, a8);      \
    628 }
    629 
    630 #define DELEGATE_TO_IMPL_9R(name, t1, t2, t3, t4, t5, t6, t7, t8, t9, rt) \
    631 rt GraphicsContext3DInternal::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8 a8, t9 a9) \
    632 { \
    633     return m_impl->name(a1, a2, a3, a4, a5, a6, a7, a8, a9);   \
    634 }
    635 
    636 DELEGATE_TO_IMPL_R(makeContextCurrent, bool)
    637 DELEGATE_TO_IMPL_1R(sizeInBytes, int, int)
    638 
    639 DELEGATE_TO_IMPL_1(activeTexture, unsigned long)
    640 DELEGATE_TO_IMPL_2_X12(attachShader, WebGLProgram*, WebGLShader*)
    641 
    642 void GraphicsContext3DInternal::bindAttribLocation(WebGLProgram* program, unsigned long index, const String& name)
    643 {
    644     m_impl->bindAttribLocation(EXTRACT(program), index, name.utf8().data());
    645 }
    646 
    647 DELEGATE_TO_IMPL_2_X2(bindBuffer, unsigned long, WebGLBuffer*)
    648 DELEGATE_TO_IMPL_2_X2(bindFramebuffer, unsigned long, WebGLFramebuffer*)
    649 DELEGATE_TO_IMPL_2_X2(bindRenderbuffer, unsigned long, WebGLRenderbuffer*)
    650 
    651 static const int kTextureWrapR = 0x8072;
     864
     865#endif  // RENDER_TO_DEBUGGING_WINDOW
     866}
     867
     868void GraphicsContext3DInternal::activeTexture(unsigned long texture)
     869{
     870    // FIXME: query number of textures available.
     871    if (texture < GL_TEXTURE0 || texture > GL_TEXTURE0+32)
     872        // FIXME: raise exception.
     873        return;
     874
     875    makeContextCurrent();
     876    glActiveTexture(texture);
     877}
     878
     879void GraphicsContext3DInternal::bindBuffer(unsigned long target,
     880                                           WebGLBuffer* buffer)
     881{
     882    makeContextCurrent();
     883    GLuint bufID = EXTRACT(buffer);
     884    if (target == GL_ARRAY_BUFFER)
     885        m_boundArrayBuffer = bufID;
     886    glBindBuffer(target, bufID);
     887}
     888
     889void GraphicsContext3DInternal::bindFramebuffer(unsigned long target,
     890                                                WebGLFramebuffer* framebuffer)
     891{
     892    makeContextCurrent();
     893    GLuint id = EXTRACT(framebuffer);
     894    if (!id)
     895        id = m_fbo;
     896    glBindFramebufferEXT(target, id);
     897    m_boundFBO = id;
     898}
    652899
    653900// If we didn't have to hack GL_TEXTURE_WRAP_R for cube maps,
    654901// we could just use:
    655 // DELEGATE_TO_IMPL_2_X2(bindTexture, unsigned long, WebGLTexture*)
     902// GL_SAME_METHOD_2_X2(BindTexture, bindTexture, unsigned long, WebGLTexture*)
    656903void GraphicsContext3DInternal::bindTexture(unsigned long target,
    657904                                            WebGLTexture* texture)
    658905{
     906    makeContextCurrent();
    659907    unsigned int textureObject = EXTRACT(texture);
    660908
    661     m_impl->bindTexture(target, textureObject);
     909    glBindTexture(target, textureObject);
    662910
    663911    // FIXME: GL_TEXTURE_WRAP_R isn't exposed in the OpenGL ES 2.0
     
    665913    // set this wrap mode to GL_CLAMP_TO_EDGE to get correct behavior
    666914    // of cube maps.
    667     if (texture)
    668         if (target == GraphicsContext3D::TEXTURE_CUBE_MAP) {
     915    if (texture) {
     916        if (target == GL_TEXTURE_CUBE_MAP) {
    669917            if (!texture->isCubeMapRWrapModeInitialized()) {
    670                 m_impl->texParameteri(GraphicsContext3D::TEXTURE_CUBE_MAP, kTextureWrapR, GraphicsContext3D::CLAMP_TO_EDGE);
     918                glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
    671919                texture->setCubeMapRWrapModeInitialized(true);
    672920            }
    673921        } else
    674922            texture->setCubeMapRWrapModeInitialized(false);
    675 }
    676 
    677 DELEGATE_TO_IMPL_4(blendColor, double, double, double, double)
    678 DELEGATE_TO_IMPL_1(blendEquation, unsigned long)
    679 DELEGATE_TO_IMPL_2(blendEquationSeparate, unsigned long, unsigned long)
    680 DELEGATE_TO_IMPL_2(blendFunc, unsigned long, unsigned long)
    681 DELEGATE_TO_IMPL_4(blendFuncSeparate, unsigned long, unsigned long, unsigned long, unsigned long)
    682 
    683 void GraphicsContext3DInternal::bufferData(unsigned long target, int size, unsigned long usage)
    684 {
    685     m_impl->bufferData(target, size, 0, usage);
    686 }
    687 
    688 void GraphicsContext3DInternal::bufferData(unsigned long target, WebGLArray* array, unsigned long usage)
    689 {
    690     m_impl->bufferData(target, array->byteLength(), array->baseAddress(), usage);
    691 }
    692 
    693 void GraphicsContext3DInternal::bufferSubData(unsigned long target, long offset, WebGLArray* array)
    694 {
    695     m_impl->bufferSubData(target, offset, array->byteLength(), array->baseAddress());
    696 }
    697 
    698 DELEGATE_TO_IMPL_1R(checkFramebufferStatus, unsigned long, unsigned long)
    699 DELEGATE_TO_IMPL_1(clear, unsigned long)
    700 DELEGATE_TO_IMPL_4(clearColor, double, double, double, double)
    701 DELEGATE_TO_IMPL_1(clearDepth, double)
    702 DELEGATE_TO_IMPL_1(clearStencil, long)
    703 DELEGATE_TO_IMPL_4(colorMask, bool, bool, bool, bool)
    704 DELEGATE_TO_IMPL_1_X(compileShader, WebGLShader*)
    705 
    706 DELEGATE_TO_IMPL_8(copyTexImage2D, unsigned long, long, unsigned long, long, long, unsigned long, unsigned long, long)
    707 DELEGATE_TO_IMPL_8(copyTexSubImage2D, unsigned long, long, long, long, long, long, unsigned long, unsigned long)
    708 DELEGATE_TO_IMPL_1(cullFace, unsigned long)
    709 DELEGATE_TO_IMPL_1(depthFunc, unsigned long)
    710 DELEGATE_TO_IMPL_1(depthMask, bool)
    711 DELEGATE_TO_IMPL_2(depthRange, double, double)
    712 DELEGATE_TO_IMPL_2_X12(detachShader, WebGLProgram*, WebGLShader*)
    713 DELEGATE_TO_IMPL_1(disable, unsigned long)
    714 DELEGATE_TO_IMPL_1(disableVertexAttribArray, unsigned long)
    715 DELEGATE_TO_IMPL_3(drawArrays, unsigned long, long, long)
    716 DELEGATE_TO_IMPL_4(drawElements, unsigned long, unsigned long, unsigned long, long)
    717 
    718 DELEGATE_TO_IMPL_1(enable, unsigned long)
    719 DELEGATE_TO_IMPL_1(enableVertexAttribArray, unsigned long)
    720 DELEGATE_TO_IMPL(finish)
    721 DELEGATE_TO_IMPL(flush)
    722 DELEGATE_TO_IMPL_4_X4(framebufferRenderbuffer, unsigned long, unsigned long, unsigned long, WebGLRenderbuffer*)
    723 DELEGATE_TO_IMPL_5_X4(framebufferTexture2D, unsigned long, unsigned long, unsigned long, WebGLTexture*, long)
    724 DELEGATE_TO_IMPL_1(frontFace, unsigned long)
    725 DELEGATE_TO_IMPL_1(generateMipmap, unsigned long)
    726 
    727 bool GraphicsContext3DInternal::getActiveAttrib(WebGLProgram* program, unsigned long index, ActiveInfo& info)
    728 {
    729     WebKit::WebGraphicsContext3D::ActiveInfo webInfo;
    730     if (!m_impl->getActiveAttrib(EXTRACT(program), index, webInfo))
     923    }
     924}
     925
     926void GraphicsContext3DInternal::bufferDataImpl(unsigned long target, int size, const void* data, unsigned long usage)
     927{
     928    makeContextCurrent();
     929    // FIXME: make this verification more efficient.
     930    GLint binding = 0;
     931    GLenum binding_target = GL_ARRAY_BUFFER_BINDING;
     932    if (target == GL_ELEMENT_ARRAY_BUFFER)
     933        binding_target = GL_ELEMENT_ARRAY_BUFFER_BINDING;
     934    glGetIntegerv(binding_target, &binding);
     935    if (binding <= 0) {
     936        // FIXME: raise exception.
     937        // LogMessagef(("bufferData: no buffer bound"));
     938        return;
     939    }
     940
     941    glBufferData(target,
     942                   size,
     943                   data,
     944                   usage);
     945}
     946
     947void GraphicsContext3DInternal::disableVertexAttribArray(unsigned long index)
     948{
     949    makeContextCurrent();
     950    if (index < NumTrackedPointerStates)
     951        m_vertexAttribPointerState[index].enabled = false;
     952    glDisableVertexAttribArray(index);
     953}
     954
     955void GraphicsContext3DInternal::enableVertexAttribArray(unsigned long index)
     956{
     957    makeContextCurrent();
     958    if (index < NumTrackedPointerStates)
     959        m_vertexAttribPointerState[index].enabled = true;
     960    glEnableVertexAttribArray(index);
     961}
     962
     963unsigned long GraphicsContext3DInternal::getError()
     964{
     965    if (m_syntheticErrors.size() > 0) {
     966        ListHashSet<unsigned long>::iterator iter = m_syntheticErrors.begin();
     967        unsigned long err = *iter;
     968        m_syntheticErrors.remove(iter);
     969        return err;
     970    }
     971
     972    makeContextCurrent();
     973    return glGetError();
     974}
     975
     976GraphicsContext3D::Attributes GraphicsContext3DInternal::getContextAttributes()
     977{
     978    return m_attrs;
     979}
     980
     981void GraphicsContext3DInternal::vertexAttribPointer(unsigned long indx, int size, int type, bool normalized,
     982                                                    unsigned long stride, unsigned long offset)
     983{
     984    makeContextCurrent();
     985
     986    if (m_boundArrayBuffer <= 0) {
     987        // FIXME: raise exception.
     988        // LogMessagef(("bufferData: no buffer bound"));
     989        return;
     990    }
     991
     992    if (indx < NumTrackedPointerStates) {
     993        VertexAttribPointerState& state = m_vertexAttribPointerState[indx];
     994        state.buffer = m_boundArrayBuffer;
     995        state.indx = indx;
     996        state.size = size;
     997        state.type = type;
     998        state.normalized = normalized;
     999        state.stride = stride;
     1000        state.offset = offset;
     1001    }
     1002
     1003    glVertexAttribPointer(indx, size, type, normalized, stride,
     1004                          reinterpret_cast<void*>(static_cast<intptr_t>(offset)));
     1005}
     1006
     1007void GraphicsContext3DInternal::viewportImpl(long x, long y, unsigned long width, unsigned long height)
     1008{
     1009    glViewport(x, y, width, height);
     1010}
     1011
     1012void GraphicsContext3DInternal::synthesizeGLError(unsigned long error)
     1013{
     1014    m_syntheticErrors.add(error);
     1015}
     1016
     1017// GraphicsContext3D -----------------------------------------------------
     1018
     1019/* Helper macros for when we're just wrapping a gl method, so that
     1020 * we can avoid having to type this 500 times.  Note that these MUST
     1021 * NOT BE USED if we need to check any of the parameters.
     1022 */
     1023
     1024#define GL_SAME_METHOD_0(glname, name)                                         \
     1025void GraphicsContext3D::name()                                                 \
     1026{                                                                              \
     1027    makeContextCurrent();                                                      \
     1028    gl##glname();                                                              \
     1029}
     1030
     1031#define GL_SAME_METHOD_1(glname, name, t1)                                     \
     1032void GraphicsContext3D::name(t1 a1)                                            \
     1033{                                                                              \
     1034    makeContextCurrent();                                                      \
     1035    gl##glname(a1);                                                            \
     1036}
     1037
     1038#define GL_SAME_METHOD_1_X(glname, name, t1)                                   \
     1039void GraphicsContext3D::name(t1 a1)                                            \
     1040{                                                                              \
     1041    makeContextCurrent();                                                      \
     1042    gl##glname(EXTRACT(a1));                                                   \
     1043}
     1044
     1045#define GL_SAME_METHOD_2(glname, name, t1, t2)                                 \
     1046void GraphicsContext3D::name(t1 a1, t2 a2)                                     \
     1047{                                                                              \
     1048    makeContextCurrent();                                                      \
     1049    gl##glname(a1, a2);                                                        \
     1050}
     1051
     1052#define GL_SAME_METHOD_2_X12(glname, name, t1, t2)                             \
     1053void GraphicsContext3D::name(t1 a1, t2 a2)                                     \
     1054{                                                                              \
     1055    makeContextCurrent();                                                      \
     1056    gl##glname(EXTRACT(a1), EXTRACT(a2));                                      \
     1057}
     1058
     1059#define GL_SAME_METHOD_2_X2(glname, name, t1, t2)                              \
     1060void GraphicsContext3D::name(t1 a1, t2 a2)                                     \
     1061{                                                                              \
     1062    makeContextCurrent();                                                      \
     1063    gl##glname(a1, EXTRACT(a2));                                               \
     1064}
     1065
     1066#define GL_SAME_METHOD_3(glname, name, t1, t2, t3)                             \
     1067void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3)                              \
     1068{                                                                              \
     1069    makeContextCurrent();                                                      \
     1070    gl##glname(a1, a2, a3);                                                    \
     1071}
     1072
     1073#define GL_SAME_METHOD_3_X12(glname, name, t1, t2, t3)                         \
     1074void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3)                              \
     1075{                                                                              \
     1076    makeContextCurrent();                                                      \
     1077    gl##glname(EXTRACT(a1), EXTRACT(a2), a3);                                  \
     1078}
     1079
     1080#define GL_SAME_METHOD_3_X2(glname, name, t1, t2, t3)                          \
     1081void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3)                              \
     1082{                                                                              \
     1083    makeContextCurrent();                                                      \
     1084    gl##glname(a1, EXTRACT(a2), a3);                                           \
     1085}
     1086
     1087#define GL_SAME_METHOD_4(glname, name, t1, t2, t3, t4)                         \
     1088void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4)                       \
     1089{                                                                              \
     1090    makeContextCurrent();                                                      \
     1091    gl##glname(a1, a2, a3, a4);                                                \
     1092}
     1093
     1094#define GL_SAME_METHOD_4_X4(glname, name, t1, t2, t3, t4)                      \
     1095void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4)                       \
     1096{                                                                              \
     1097    makeContextCurrent();                                                      \
     1098    gl##glname(a1, a2, a3, EXTRACT(a4));                                       \
     1099}
     1100
     1101#define GL_SAME_METHOD_5(glname, name, t1, t2, t3, t4, t5)                     \
     1102void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5)                \
     1103{                                                                              \
     1104    makeContextCurrent();                                                      \
     1105    gl##glname(a1, a2, a3, a4, a5);                                            \
     1106}
     1107
     1108#define GL_SAME_METHOD_5_X4(glname, name, t1, t2, t3, t4, t5)                  \
     1109void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5)                \
     1110{                                                                              \
     1111    makeContextCurrent();                                                      \
     1112    gl##glname(a1, a2, a3, EXTRACT(a4), a5);                                   \
     1113}
     1114
     1115#define GL_SAME_METHOD_6(glname, name, t1, t2, t3, t4, t5, t6)                 \
     1116void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6)         \
     1117{                                                                              \
     1118    makeContextCurrent();                                                      \
     1119    gl##glname(a1, a2, a3, a4, a5, a6);                                        \
     1120}
     1121
     1122#define GL_SAME_METHOD_8(glname, name, t1, t2, t3, t4, t5, t6, t7, t8)         \
     1123void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8 a8)   \
     1124{                                                                              \
     1125    makeContextCurrent();                                                      \
     1126    gl##glname(a1, a2, a3, a4, a5, a6, a7, a8);                                \
     1127}
     1128
     1129PassOwnPtr<GraphicsContext3D> GraphicsContext3D::create(GraphicsContext3D::Attributes attrs)
     1130{
     1131    PassOwnPtr<GraphicsContext3D> context = new GraphicsContext3D(attrs);
     1132    // FIXME: add error checking
     1133    return context;
     1134}
     1135
     1136GraphicsContext3D::GraphicsContext3D(GraphicsContext3D::Attributes attrs)
     1137    : m_currentWidth(0)
     1138    , m_currentHeight(0)
     1139    , m_internal(new GraphicsContext3DInternal(attrs))
     1140{
     1141}
     1142
     1143GraphicsContext3D::~GraphicsContext3D()
     1144{
     1145}
     1146
     1147PlatformGraphicsContext3D GraphicsContext3D::platformGraphicsContext3D() const
     1148{
     1149    return m_internal->platformGraphicsContext3D();
     1150}
     1151
     1152Platform3DObject GraphicsContext3D::platformTexture() const
     1153{
     1154    return m_internal->platformTexture();
     1155}
     1156
     1157void GraphicsContext3D::makeContextCurrent()
     1158{
     1159    m_internal->makeContextCurrent();
     1160}
     1161
     1162void GraphicsContext3D::reshape(int width, int height)
     1163{
     1164    if (width == m_currentWidth && height == m_currentHeight)
     1165        return;
     1166
     1167    m_currentWidth = width;
     1168    m_currentHeight = height;
     1169
     1170    m_internal->reshape(width, height);
     1171}
     1172
     1173void GraphicsContext3D::beginPaint(WebGLRenderingContext* context)
     1174{
     1175    m_internal->beginPaint(context);
     1176}
     1177
     1178void GraphicsContext3D::endPaint()
     1179{
     1180}
     1181
     1182int GraphicsContext3D::sizeInBytes(int type)
     1183{
     1184    switch (type) {
     1185    case GL_BYTE:
     1186        return sizeof(GLbyte);
     1187    case GL_UNSIGNED_BYTE:
     1188        return sizeof(GLubyte);
     1189    case GL_SHORT:
     1190        return sizeof(GLshort);
     1191    case GL_UNSIGNED_SHORT:
     1192        return sizeof(GLushort);
     1193    case GL_INT:
     1194        return sizeof(GLint);
     1195    case GL_UNSIGNED_INT:
     1196        return sizeof(GLuint);
     1197    case GL_FLOAT:
     1198        return sizeof(GLfloat);
     1199    default: // FIXME: default cases are discouraged in WebKit.
     1200        return 0;
     1201    }
     1202}
     1203
     1204unsigned GraphicsContext3D::createBuffer()
     1205{
     1206    makeContextCurrent();
     1207    GLuint o;
     1208    glGenBuffers(1, &o);
     1209    return o;
     1210}
     1211
     1212unsigned GraphicsContext3D::createFramebuffer()
     1213{
     1214    makeContextCurrent();
     1215    GLuint o = 0;
     1216    glGenFramebuffersEXT(1, &o);
     1217    return o;
     1218}
     1219
     1220unsigned GraphicsContext3D::createProgram()
     1221{
     1222    makeContextCurrent();
     1223    return glCreateProgram();
     1224}
     1225
     1226unsigned GraphicsContext3D::createRenderbuffer()
     1227{
     1228    makeContextCurrent();
     1229    GLuint o;
     1230    glGenRenderbuffersEXT(1, &o);
     1231    return o;
     1232}
     1233
     1234unsigned GraphicsContext3D::createShader(unsigned long type)
     1235{
     1236    makeContextCurrent();
     1237    return glCreateShader((type == FRAGMENT_SHADER) ? GL_FRAGMENT_SHADER : GL_VERTEX_SHADER);
     1238}
     1239
     1240unsigned GraphicsContext3D::createTexture()
     1241{
     1242    makeContextCurrent();
     1243    GLuint o;
     1244    glGenTextures(1, &o);
     1245    return o;
     1246}
     1247
     1248void GraphicsContext3D::deleteBuffer(unsigned buffer)
     1249{
     1250    makeContextCurrent();
     1251    glDeleteBuffers(1, &buffer);
     1252}
     1253
     1254void GraphicsContext3D::deleteFramebuffer(unsigned framebuffer)
     1255{
     1256    makeContextCurrent();
     1257    glDeleteFramebuffersEXT(1, &framebuffer);
     1258}
     1259
     1260void GraphicsContext3D::deleteProgram(unsigned program)
     1261{
     1262    makeContextCurrent();
     1263    glDeleteProgram(program);
     1264}
     1265
     1266void GraphicsContext3D::deleteRenderbuffer(unsigned renderbuffer)
     1267{
     1268    makeContextCurrent();
     1269    glDeleteRenderbuffersEXT(1, &renderbuffer);
     1270}
     1271
     1272void GraphicsContext3D::deleteShader(unsigned shader)
     1273{
     1274    makeContextCurrent();
     1275    glDeleteShader(shader);
     1276}
     1277
     1278void GraphicsContext3D::deleteTexture(unsigned texture)
     1279{
     1280    makeContextCurrent();
     1281    glDeleteTextures(1, &texture);
     1282}
     1283
     1284void GraphicsContext3D::activeTexture(unsigned long texture)
     1285{
     1286    m_internal->activeTexture(texture);
     1287}
     1288
     1289GL_SAME_METHOD_2_X12(AttachShader, attachShader, WebGLProgram*, WebGLShader*)
     1290
     1291void GraphicsContext3D::bindAttribLocation(WebGLProgram* program,
     1292                                           unsigned long index,
     1293                                           const String& name)
     1294{
     1295    if (!program)
     1296        return;
     1297    makeContextCurrent();
     1298    glBindAttribLocation(EXTRACT(program), index, name.utf8().data());
     1299}
     1300
     1301void GraphicsContext3D::bindBuffer(unsigned long target,
     1302                                   WebGLBuffer* buffer)
     1303{
     1304    m_internal->bindBuffer(target, buffer);
     1305}
     1306
     1307void GraphicsContext3D::bindFramebuffer(unsigned long target, WebGLFramebuffer* framebuffer)
     1308{
     1309    m_internal->bindFramebuffer(target, framebuffer);
     1310}
     1311
     1312GL_SAME_METHOD_2_X2(BindRenderbufferEXT, bindRenderbuffer, unsigned long, WebGLRenderbuffer*)
     1313
     1314// If we didn't have to hack GL_TEXTURE_WRAP_R for cube maps,
     1315// we could just use:
     1316// GL_SAME_METHOD_2_X2(BindTexture, bindTexture, unsigned long, WebGLTexture*)
     1317void GraphicsContext3D::bindTexture(unsigned long target,
     1318                                    WebGLTexture* texture)
     1319{
     1320    m_internal->bindTexture(target, texture);
     1321}
     1322
     1323GL_SAME_METHOD_4(BlendColor, blendColor, double, double, double, double)
     1324
     1325GL_SAME_METHOD_1(BlendEquation, blendEquation, unsigned long)
     1326
     1327GL_SAME_METHOD_2(BlendEquationSeparate, blendEquationSeparate, unsigned long, unsigned long)
     1328
     1329GL_SAME_METHOD_2(BlendFunc, blendFunc, unsigned long, unsigned long)
     1330
     1331GL_SAME_METHOD_4(BlendFuncSeparate, blendFuncSeparate, unsigned long, unsigned long, unsigned long, unsigned long)
     1332
     1333void GraphicsContext3D::bufferData(unsigned long target, int size, unsigned long usage)
     1334{
     1335    m_internal->bufferDataImpl(target, size, 0, usage);
     1336}
     1337
     1338void GraphicsContext3D::bufferData(unsigned long target, WebGLArray* array, unsigned long usage)
     1339{
     1340    m_internal->bufferDataImpl(target, array->byteLength(), array->baseAddress(), usage);
     1341}
     1342
     1343void GraphicsContext3D::bufferSubData(unsigned long target, long offset, WebGLArray* array)
     1344{
     1345    if (!array || !array->length())
     1346        return;
     1347
     1348    makeContextCurrent();
     1349    // FIXME: make this verification more efficient.
     1350    GLint binding = 0;
     1351    GLenum binding_target = GL_ARRAY_BUFFER_BINDING;
     1352    if (target == GL_ELEMENT_ARRAY_BUFFER)
     1353        binding_target = GL_ELEMENT_ARRAY_BUFFER_BINDING;
     1354    glGetIntegerv(binding_target, &binding);
     1355    if (binding <= 0) {
     1356        // FIXME: raise exception.
     1357        // LogMessagef(("bufferSubData: no buffer bound"));
     1358        return;
     1359    }
     1360    glBufferSubData(target, offset, array->byteLength(), array->baseAddress());
     1361}
     1362
     1363unsigned long GraphicsContext3D::checkFramebufferStatus(unsigned long target)
     1364{
     1365    makeContextCurrent();
     1366    return glCheckFramebufferStatusEXT(target);
     1367}
     1368
     1369GL_SAME_METHOD_1(Clear, clear, unsigned long)
     1370
     1371GL_SAME_METHOD_4(ClearColor, clearColor, double, double, double, double)
     1372
     1373GL_SAME_METHOD_1(ClearDepth, clearDepth, double)
     1374
     1375GL_SAME_METHOD_1(ClearStencil, clearStencil, long)
     1376
     1377GL_SAME_METHOD_4(ColorMask, colorMask, bool, bool, bool, bool)
     1378
     1379GL_SAME_METHOD_1_X(CompileShader, compileShader, WebGLShader*)
     1380
     1381GL_SAME_METHOD_8(CopyTexImage2D, copyTexImage2D, unsigned long, long, unsigned long, long, long, unsigned long, unsigned long, long)
     1382
     1383GL_SAME_METHOD_8(CopyTexSubImage2D, copyTexSubImage2D, unsigned long, long, long, long, long, long, unsigned long, unsigned long)
     1384
     1385GL_SAME_METHOD_1(CullFace, cullFace, unsigned long)
     1386
     1387GL_SAME_METHOD_1(DepthFunc, depthFunc, unsigned long)
     1388
     1389GL_SAME_METHOD_1(DepthMask, depthMask, bool)
     1390
     1391GL_SAME_METHOD_2(DepthRange, depthRange, double, double)
     1392
     1393void GraphicsContext3D::detachShader(WebGLProgram* program, WebGLShader* shader)
     1394{
     1395    if (!program || !shader)
     1396        return;
     1397
     1398    makeContextCurrent();
     1399    glDetachShader(EXTRACT(program), EXTRACT(shader));
     1400}
     1401
     1402GL_SAME_METHOD_1(Disable, disable, unsigned long)
     1403
     1404void GraphicsContext3D::disableVertexAttribArray(unsigned long index)
     1405{
     1406    m_internal->disableVertexAttribArray(index);
     1407}
     1408
     1409void GraphicsContext3D::drawArrays(unsigned long mode, long first, long count)
     1410{
     1411    switch (mode) {
     1412    case GL_TRIANGLES:
     1413    case GL_TRIANGLE_STRIP:
     1414    case GL_TRIANGLE_FAN:
     1415    case GL_POINTS:
     1416    case GL_LINE_STRIP:
     1417    case GL_LINE_LOOP:
     1418    case GL_LINES:
     1419        break;
     1420    default: // FIXME: default cases are discouraged in WebKit.
     1421        // FIXME: output log message, raise exception.
     1422        // LogMessage(NS_LITERAL_CSTRING("drawArrays: invalid mode"));
     1423        // return NS_ERROR_DOM_SYNTAX_ERR;
     1424        return;
     1425    }
     1426
     1427    if (first+count < first || first+count < count) {
     1428        // FIXME: output log message, raise exception.
     1429        // LogMessage(NS_LITERAL_CSTRING("drawArrays: overflow in first+count"));
     1430        // return NS_ERROR_INVALID_ARG;
     1431        return;
     1432    }
     1433
     1434    // FIXME: validate against currently bound buffer.
     1435    // if (!ValidateBuffers(first+count))
     1436    //     return NS_ERROR_INVALID_ARG;
     1437
     1438    makeContextCurrent();
     1439    glDrawArrays(mode, first, count);
     1440}
     1441
     1442void GraphicsContext3D::drawElements(unsigned long mode, unsigned long count, unsigned long type, long offset)
     1443{
     1444    makeContextCurrent();
     1445    // FIXME: make this verification more efficient.
     1446    GLint binding = 0;
     1447    GLenum binding_target = GL_ELEMENT_ARRAY_BUFFER_BINDING;
     1448    glGetIntegerv(binding_target, &binding);
     1449    if (binding <= 0) {
     1450        // FIXME: raise exception.
     1451        // LogMessagef(("bufferData: no buffer bound"));
     1452        return;
     1453    }
     1454    glDrawElements(mode, count, type,
     1455                   reinterpret_cast<void*>(static_cast<intptr_t>(offset)));
     1456}
     1457
     1458GL_SAME_METHOD_1(Enable, enable, unsigned long)
     1459
     1460void GraphicsContext3D::enableVertexAttribArray(unsigned long index)
     1461{
     1462    m_internal->enableVertexAttribArray(index);
     1463}
     1464
     1465GL_SAME_METHOD_0(Finish, finish)
     1466
     1467GL_SAME_METHOD_0(Flush, flush)
     1468
     1469GL_SAME_METHOD_4_X4(FramebufferRenderbufferEXT, framebufferRenderbuffer, unsigned long, unsigned long, unsigned long, WebGLRenderbuffer*)
     1470
     1471GL_SAME_METHOD_5_X4(FramebufferTexture2DEXT, framebufferTexture2D, unsigned long, unsigned long, unsigned long, WebGLTexture*, long)
     1472
     1473GL_SAME_METHOD_1(FrontFace, frontFace, unsigned long)
     1474
     1475void GraphicsContext3D::generateMipmap(unsigned long target)
     1476{
     1477    makeContextCurrent();
     1478    if (glGenerateMipmapEXT)
     1479        glGenerateMipmapEXT(target);
     1480    // FIXME: provide alternative code path? This will be unpleasant
     1481    // to implement if glGenerateMipmapEXT is not available -- it will
     1482    // require a texture readback and re-upload.
     1483}
     1484
     1485bool GraphicsContext3D::getActiveAttrib(WebGLProgram* program, unsigned long index, ActiveInfo& info)
     1486{
     1487    if (!program) {
     1488        synthesizeGLError(INVALID_VALUE);
    7311489        return false;
    732     info.name = webInfo.name;
    733     info.type = webInfo.type;
    734     info.size = webInfo.size;
     1490    }
     1491    GLint maxNameLength = -1;
     1492    glGetProgramiv(EXTRACT(program), GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxNameLength);
     1493    if (maxNameLength < 0)
     1494        return false;
     1495    GLchar* name = 0;
     1496    if (!tryFastMalloc(maxNameLength * sizeof(GLchar)).getValue(name)) {
     1497        synthesizeGLError(OUT_OF_MEMORY);
     1498        return false;
     1499    }
     1500    GLsizei length = 0;
     1501    GLint size = -1;
     1502    GLenum type = 0;
     1503    glGetActiveAttrib(EXTRACT(program), index, maxNameLength,
     1504                      &length, &size, &type, name);
     1505    if (size < 0) {
     1506        fastFree(name);
     1507        return false;
     1508    }
     1509    info.name = String(name, length);
     1510    info.type = type;
     1511    info.size = size;
     1512    fastFree(name);
    7351513    return true;
    7361514}
    7371515
    738 bool GraphicsContext3DInternal::getActiveUniform(WebGLProgram* program, unsigned long index, ActiveInfo& info)
    739 {
    740     WebKit::WebGraphicsContext3D::ActiveInfo webInfo;
    741     if (!m_impl->getActiveUniform(EXTRACT(program), index, webInfo))
     1516bool GraphicsContext3D::getActiveUniform(WebGLProgram* program, unsigned long index, ActiveInfo& info)
     1517{
     1518    if (!program) {
     1519        synthesizeGLError(INVALID_VALUE);
    7421520        return false;
    743     info.name = webInfo.name;
    744     info.type = webInfo.type;
    745     info.size = webInfo.size;
     1521    }
     1522    GLint maxNameLength = -1;
     1523    glGetProgramiv(EXTRACT(program), GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxNameLength);
     1524    if (maxNameLength < 0)
     1525        return false;
     1526    GLchar* name = 0;
     1527    if (!tryFastMalloc(maxNameLength * sizeof(GLchar)).getValue(name)) {
     1528        synthesizeGLError(OUT_OF_MEMORY);
     1529        return false;
     1530    }
     1531    GLsizei length = 0;
     1532    GLint size = -1;
     1533    GLenum type = 0;
     1534    glGetActiveUniform(EXTRACT(program), index, maxNameLength,
     1535                       &length, &size, &type, name);
     1536    if (size < 0) {
     1537        fastFree(name);
     1538        return false;
     1539    }
     1540    info.name = String(name, length);
     1541    info.type = type;
     1542    info.size = size;
     1543    fastFree(name);
    7461544    return true;
    7471545}
    7481546
    749 int GraphicsContext3DInternal::getAttribLocation(WebGLProgram* program, const String& name)
    750 {
    751     return m_impl->getAttribLocation(EXTRACT(program), name.utf8().data());
    752 }
    753 
    754 DELEGATE_TO_IMPL_2(getBooleanv, unsigned long, unsigned char*)
    755 
    756 DELEGATE_TO_IMPL_3(getBufferParameteriv, unsigned long, unsigned long, int*)
    757 
    758 GraphicsContext3D::Attributes GraphicsContext3DInternal::getContextAttributes()
    759 {
    760     WebKit::WebGraphicsContext3D::Attributes webAttributes = m_impl->getContextAttributes();
    761     GraphicsContext3D::Attributes attributes;
    762     attributes.alpha = webAttributes.alpha;
    763     attributes.depth = webAttributes.depth;
    764     attributes.stencil = webAttributes.stencil;
    765     attributes.antialias = webAttributes.antialias;
    766     attributes.premultipliedAlpha = webAttributes.premultipliedAlpha;
    767     return attributes;
    768 }
    769 
    770 DELEGATE_TO_IMPL_R(getError, unsigned long)
    771 
    772 DELEGATE_TO_IMPL_2(getFloatv, unsigned long, float*)
    773 
    774 DELEGATE_TO_IMPL_4(getFramebufferAttachmentParameteriv, unsigned long, unsigned long, unsigned long, int*)
    775 
    776 DELEGATE_TO_IMPL_2(getIntegerv, unsigned long, int*)
    777 
    778 DELEGATE_TO_IMPL_3_X1(getProgramiv, WebGLProgram*, unsigned long, int*)
    779 
    780 String GraphicsContext3DInternal::getProgramInfoLog(WebGLProgram* program)
    781 {
    782     return m_impl->getProgramInfoLog(EXTRACT(program));
    783 }
    784 
    785 DELEGATE_TO_IMPL_3(getRenderbufferParameteriv, unsigned long, unsigned long, int*)
    786 
    787 DELEGATE_TO_IMPL_3_X1(getShaderiv, WebGLShader*, unsigned long, int*)
    788 
    789 String GraphicsContext3DInternal::getShaderInfoLog(WebGLShader* shader)
    790 {
    791     return m_impl->getShaderInfoLog(EXTRACT(shader));
    792 }
    793 
    794 String GraphicsContext3DInternal::getShaderSource(WebGLShader* shader)
    795 {
    796     return m_impl->getShaderSource(EXTRACT(shader));
    797 }
    798 
    799 String GraphicsContext3DInternal::getString(unsigned long name)
    800 {
    801     return m_impl->getString(name);
    802 }
    803 
    804 DELEGATE_TO_IMPL_3(getTexParameterfv, unsigned long, unsigned long, float*)
    805 DELEGATE_TO_IMPL_3(getTexParameteriv, unsigned long, unsigned long, int*)
    806 
    807 DELEGATE_TO_IMPL_3_X1(getUniformfv, WebGLProgram*, long, float*)
    808 DELEGATE_TO_IMPL_3_X1(getUniformiv, WebGLProgram*, long, int*)
    809 
    810 long GraphicsContext3DInternal::getUniformLocation(WebGLProgram* program, const String& name)
    811 {
    812     return m_impl->getUniformLocation(EXTRACT(program), name.utf8().data());
    813 }
    814 
    815 DELEGATE_TO_IMPL_3(getVertexAttribfv, unsigned long, unsigned long, float*)
    816 DELEGATE_TO_IMPL_3(getVertexAttribiv, unsigned long, unsigned long, int*)
    817 
    818 DELEGATE_TO_IMPL_2R(getVertexAttribOffset, unsigned long, unsigned long, long)
    819 
    820 DELEGATE_TO_IMPL_2(hint, unsigned long, unsigned long)
    821 DELEGATE_TO_IMPL_1R_X(isBuffer, WebGLBuffer*, bool)
    822 DELEGATE_TO_IMPL_1R(isEnabled, unsigned long, bool)
    823 DELEGATE_TO_IMPL_1R_X(isFramebuffer, WebGLFramebuffer*, bool)
    824 DELEGATE_TO_IMPL_1R_X(isProgram, WebGLProgram*, bool)
    825 DELEGATE_TO_IMPL_1R_X(isRenderbuffer, WebGLRenderbuffer*, bool)
    826 DELEGATE_TO_IMPL_1R_X(isShader, WebGLShader*, bool)
    827 DELEGATE_TO_IMPL_1R_X(isTexture, WebGLTexture*, bool)
    828 DELEGATE_TO_IMPL_1(lineWidth, double)
    829 DELEGATE_TO_IMPL_1_X(linkProgram, WebGLProgram*)
    830 DELEGATE_TO_IMPL_2(pixelStorei, unsigned long, long)
    831 DELEGATE_TO_IMPL_2(polygonOffset, double, double)
    832 
    833 PassRefPtr<WebGLArray> GraphicsContext3DInternal::readPixels(long x, long y, unsigned long width, unsigned long height, unsigned long format, unsigned long type)
    834 {
     1547int GraphicsContext3D::getAttribLocation(WebGLProgram* program, const String& name)
     1548{
     1549    if (!program)
     1550        return -1;
     1551
     1552    makeContextCurrent();
     1553    return glGetAttribLocation(EXTRACT(program), name.utf8().data());
     1554}
     1555
     1556void GraphicsContext3D::getBooleanv(unsigned long pname, unsigned char* value)
     1557{
     1558    makeContextCurrent();
     1559    glGetBooleanv(pname, value);
     1560}
     1561
     1562void GraphicsContext3D::getBufferParameteriv(unsigned long target, unsigned long pname, int* value)
     1563{
     1564    makeContextCurrent();
     1565    glGetBufferParameteriv(target, pname, value);
     1566}
     1567
     1568GraphicsContext3D::Attributes GraphicsContext3D::getContextAttributes()
     1569{
     1570    return m_internal->getContextAttributes();
     1571}
     1572
     1573unsigned long GraphicsContext3D::getError()
     1574{
     1575    return m_internal->getError();
     1576}
     1577
     1578void GraphicsContext3D::getFloatv(unsigned long pname, float* value)
     1579{
     1580    makeContextCurrent();
     1581    glGetFloatv(pname, value);
     1582}
     1583
     1584void GraphicsContext3D::getFramebufferAttachmentParameteriv(unsigned long target,
     1585                                                            unsigned long attachment,
     1586                                                            unsigned long pname,
     1587                                                            int* value)
     1588{
     1589    makeContextCurrent();
     1590    glGetFramebufferAttachmentParameterivEXT(target, attachment, pname, value);
     1591}
     1592
     1593void GraphicsContext3D::getIntegerv(unsigned long pname, int* value)
     1594{
     1595    makeContextCurrent();
     1596    glGetIntegerv(pname, value);
     1597}
     1598
     1599void GraphicsContext3D::getProgramiv(WebGLProgram* program,
     1600                                     unsigned long pname,
     1601                                     int* value)
     1602{
     1603    makeContextCurrent();
     1604    glGetProgramiv(EXTRACT(program), pname, value);
     1605}
     1606
     1607String GraphicsContext3D::getProgramInfoLog(WebGLProgram* program)
     1608{
     1609    makeContextCurrent();
     1610    GLuint programID = EXTRACT(program);
     1611    GLint logLength;
     1612    glGetProgramiv(programID, GL_INFO_LOG_LENGTH, &logLength);
     1613    if (!logLength)
     1614        return String();
     1615    GLchar* log = 0;
     1616    if (!tryFastMalloc(logLength * sizeof(GLchar)).getValue(log))
     1617        return String();
     1618    GLsizei returnedLogLength;
     1619    glGetProgramInfoLog(programID, logLength, &returnedLogLength, log);
     1620    ASSERT(logLength == returnedLogLength + 1);
     1621    String res = String(log, returnedLogLength);
     1622    fastFree(log);
     1623    return res;
     1624}
     1625
     1626void GraphicsContext3D::getRenderbufferParameteriv(unsigned long target,
     1627                                                   unsigned long pname,
     1628                                                   int* value)
     1629{
     1630    makeContextCurrent();
     1631    glGetRenderbufferParameterivEXT(target, pname, value);
     1632}
     1633
     1634void GraphicsContext3D::getShaderiv(WebGLShader* shader,
     1635                                    unsigned long pname,
     1636                                    int* value)
     1637{
     1638    makeContextCurrent();
     1639    glGetShaderiv(EXTRACT(shader), pname, value);
     1640}
     1641
     1642String GraphicsContext3D::getShaderInfoLog(WebGLShader* shader)
     1643{
     1644    makeContextCurrent();
     1645    GLuint shaderID = EXTRACT(shader);
     1646    GLint logLength;
     1647    glGetShaderiv(shaderID, GL_INFO_LOG_LENGTH, &logLength);
     1648    if (!logLength)
     1649        return String();
     1650    GLchar* log = 0;
     1651    if (!tryFastMalloc(logLength * sizeof(GLchar)).getValue(log))
     1652        return String();
     1653    GLsizei returnedLogLength;
     1654    glGetShaderInfoLog(shaderID, logLength, &returnedLogLength, log);
     1655    ASSERT(logLength == returnedLogLength + 1);
     1656    String res = String(log, returnedLogLength);
     1657    fastFree(log);
     1658    return res;
     1659}
     1660
     1661String GraphicsContext3D::getShaderSource(WebGLShader* shader)
     1662{
     1663    makeContextCurrent();
     1664    GLuint shaderID = EXTRACT(shader);
     1665    GLint logLength;
     1666    glGetShaderiv(shaderID, GL_SHADER_SOURCE_LENGTH, &logLength);
     1667    if (!logLength)
     1668        return String();
     1669    GLchar* log = 0;
     1670    if (!tryFastMalloc(logLength * sizeof(GLchar)).getValue(log))
     1671        return String();
     1672    GLsizei returnedLogLength;
     1673    glGetShaderSource(shaderID, logLength, &returnedLogLength, log);
     1674    ASSERT(logLength == returnedLogLength + 1);
     1675    String res = String(log, returnedLogLength);
     1676    fastFree(log);
     1677    return res;
     1678}
     1679
     1680String GraphicsContext3D::getString(unsigned long name)
     1681{
     1682    makeContextCurrent();
     1683    return String(reinterpret_cast<const char*>(glGetString(name)));
     1684}
     1685
     1686void GraphicsContext3D::getTexParameterfv(unsigned long target, unsigned long pname, float* value)
     1687{
     1688    makeContextCurrent();
     1689    glGetTexParameterfv(target, pname, value);
     1690}
     1691
     1692void GraphicsContext3D::getTexParameteriv(unsigned long target, unsigned long pname, int* value)
     1693{
     1694    makeContextCurrent();
     1695    glGetTexParameteriv(target, pname, value);
     1696}
     1697
     1698void GraphicsContext3D::getUniformfv(WebGLProgram* program, long location, float* value)
     1699{
     1700    makeContextCurrent();
     1701    glGetUniformfv(EXTRACT(program), location, value);
     1702}
     1703
     1704void GraphicsContext3D::getUniformiv(WebGLProgram* program, long location, int* value)
     1705{
     1706    makeContextCurrent();
     1707    glGetUniformiv(EXTRACT(program), location, value);
     1708}
     1709
     1710long GraphicsContext3D::getUniformLocation(WebGLProgram* program, const String& name)
     1711{
     1712    if (!program)
     1713        return -1;
     1714
     1715    makeContextCurrent();
     1716    return glGetUniformLocation(EXTRACT(program), name.utf8().data());
     1717}
     1718
     1719void GraphicsContext3D::getVertexAttribfv(unsigned long index,
     1720                                          unsigned long pname,
     1721                                          float* value)
     1722{
     1723    makeContextCurrent();
     1724    glGetVertexAttribfv(index, pname, value);
     1725}
     1726
     1727void GraphicsContext3D::getVertexAttribiv(unsigned long index,
     1728                                          unsigned long pname,
     1729                                          int* value)
     1730{
     1731    makeContextCurrent();
     1732    glGetVertexAttribiv(index, pname, value);
     1733}
     1734
     1735long GraphicsContext3D::getVertexAttribOffset(unsigned long index, unsigned long pname)
     1736{
     1737    // FIXME: implement.
     1738    notImplemented();
     1739    return 0;
     1740}
     1741
     1742GL_SAME_METHOD_2(Hint, hint, unsigned long, unsigned long);
     1743
     1744bool GraphicsContext3D::isBuffer(WebGLBuffer* buffer)
     1745{
     1746    makeContextCurrent();
     1747    return glIsBuffer(EXTRACT(buffer));
     1748}
     1749
     1750bool GraphicsContext3D::isEnabled(unsigned long cap)
     1751{
     1752    makeContextCurrent();
     1753    return glIsEnabled(cap);
     1754}
     1755
     1756bool GraphicsContext3D::isFramebuffer(WebGLFramebuffer* framebuffer)
     1757{
     1758    makeContextCurrent();
     1759    return glIsFramebufferEXT(EXTRACT(framebuffer));
     1760}
     1761
     1762bool GraphicsContext3D::isProgram(WebGLProgram* program)
     1763{
     1764    makeContextCurrent();
     1765    return glIsProgram(EXTRACT(program));
     1766}
     1767
     1768bool GraphicsContext3D::isRenderbuffer(WebGLRenderbuffer* renderbuffer)
     1769{
     1770    makeContextCurrent();
     1771    return glIsRenderbufferEXT(EXTRACT(renderbuffer));
     1772}
     1773
     1774bool GraphicsContext3D::isShader(WebGLShader* shader)
     1775{
     1776    makeContextCurrent();
     1777    return glIsShader(EXTRACT(shader));
     1778}
     1779
     1780bool GraphicsContext3D::isTexture(WebGLTexture* texture)
     1781{
     1782    makeContextCurrent();
     1783    return glIsTexture(EXTRACT(texture));
     1784}
     1785
     1786GL_SAME_METHOD_1(LineWidth, lineWidth, double)
     1787
     1788GL_SAME_METHOD_1_X(LinkProgram, linkProgram, WebGLProgram*)
     1789
     1790void GraphicsContext3D::pixelStorei(unsigned long pname, long param)
     1791{
     1792    if (pname != GL_PACK_ALIGNMENT && pname != GL_UNPACK_ALIGNMENT) {
     1793        // FIXME: Create a fake GL error and throw an exception.
     1794        return;
     1795    }
     1796
     1797    makeContextCurrent();
     1798    glPixelStorei(pname, param);
     1799}
     1800
     1801GL_SAME_METHOD_2(PolygonOffset, polygonOffset, double, double)
     1802
     1803PassRefPtr<WebGLArray> GraphicsContext3D::readPixels(long x, long y,
     1804                                                      unsigned long width, unsigned long height,
     1805                                                      unsigned long format, unsigned long type) {
     1806    // FIXME: support more pixel formats and types.
     1807    if (!((format == GL_RGBA) && (type == GL_UNSIGNED_BYTE)))
     1808        return 0;
     1809
    8351810    // FIXME: take into account pack alignment.
    8361811    RefPtr<WebGLUnsignedByteArray> array = WebGLUnsignedByteArray::create(width * height * 4);
    837     m_impl->readPixels(x, y, width, height, format, type, array->baseAddress());
     1812    glReadPixels(x, y, width, height, format, type, array->baseAddress());
    8381813    return array;
    8391814}
    8401815
    841 DELEGATE_TO_IMPL(releaseShaderCompiler)
    842 DELEGATE_TO_IMPL_4(renderbufferStorage, unsigned long, unsigned long, unsigned long, unsigned long)
    843 DELEGATE_TO_IMPL_2(sampleCoverage, double, bool)
    844 DELEGATE_TO_IMPL_4(scissor, long, long, unsigned long, unsigned long)
    845 
    846 void GraphicsContext3DInternal::shaderSource(WebGLShader* shader, const String& string)
    847 {
    848     m_impl->shaderSource(EXTRACT(shader), string.utf8().data());
    849 }
    850 
    851 DELEGATE_TO_IMPL_3(stencilFunc, unsigned long, long, unsigned long)
    852 DELEGATE_TO_IMPL_4(stencilFuncSeparate, unsigned long, unsigned long, long, unsigned long)
    853 DELEGATE_TO_IMPL_1(stencilMask, unsigned long)
    854 DELEGATE_TO_IMPL_2(stencilMaskSeparate, unsigned long, unsigned long)
    855 DELEGATE_TO_IMPL_3(stencilOp, unsigned long, unsigned long, unsigned long)
    856 DELEGATE_TO_IMPL_4(stencilOpSeparate, unsigned long, unsigned long, unsigned long, unsigned long)
    857 
    858 int GraphicsContext3DInternal::texImage2D(unsigned target, unsigned level, unsigned internalformat, unsigned width, unsigned height, unsigned border, unsigned format, unsigned type, void* pixels)
    859 {
    860     m_impl->texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
     1816void GraphicsContext3D::releaseShaderCompiler()
     1817{
     1818}
     1819
     1820GL_SAME_METHOD_4(RenderbufferStorageEXT, renderbufferStorage, unsigned long, unsigned long, unsigned long, unsigned long)
     1821
     1822GL_SAME_METHOD_2(SampleCoverage, sampleCoverage, double, bool)
     1823
     1824GL_SAME_METHOD_4(Scissor, scissor, long, long, unsigned long, unsigned long)
     1825
     1826void GraphicsContext3D::shaderSource(WebGLShader* shader, const String& source)
     1827{
     1828    makeContextCurrent();
     1829    CString str = source.utf8();
     1830    const char* data = str.data();
     1831    GLint length = str.length();
     1832    glShaderSource(EXTRACT(shader), 1, &data, &length);
     1833}
     1834
     1835GL_SAME_METHOD_3(StencilFunc, stencilFunc, unsigned long, long, unsigned long)
     1836
     1837GL_SAME_METHOD_4(StencilFuncSeparate, stencilFuncSeparate, unsigned long, unsigned long, long, unsigned long)
     1838
     1839GL_SAME_METHOD_1(StencilMask, stencilMask, unsigned long)
     1840
     1841GL_SAME_METHOD_2(StencilMaskSeparate, stencilMaskSeparate, unsigned long, unsigned long)
     1842
     1843GL_SAME_METHOD_3(StencilOp, stencilOp, unsigned long, unsigned long, unsigned long)
     1844
     1845GL_SAME_METHOD_4(StencilOpSeparate, stencilOpSeparate, unsigned long, unsigned long, unsigned long, unsigned long)
     1846
     1847void GraphicsContext3D::synthesizeGLError(unsigned long error)
     1848{
     1849    m_internal->synthesizeGLError(error);
     1850}
     1851
     1852int GraphicsContext3D::texImage2D(unsigned target,
     1853                                  unsigned level,
     1854                                  unsigned internalformat,
     1855                                  unsigned width,
     1856                                  unsigned height,
     1857                                  unsigned border,
     1858                                  unsigned format,
     1859                                  unsigned type,
     1860                                  void* pixels)
     1861{
     1862    // FIXME: must do validation similar to JOGL's to ensure that
     1863    // the incoming array is of the appropriate length.
     1864    glTexImage2D(target,
     1865                 level,
     1866                 internalformat,
     1867                 width,
     1868                 height,
     1869                 border,
     1870                 format,
     1871                 type,
     1872                 pixels);
    8611873    return 0;
    8621874}
    863 
    864 DELEGATE_TO_IMPL_3(texParameterf, unsigned, unsigned, float)
    865 DELEGATE_TO_IMPL_3(texParameteri, unsigned, unsigned, int)
    866 
    867 int GraphicsContext3DInternal::texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, unsigned width, unsigned height, unsigned format, unsigned type, void* pixels)
    868 {
    869     m_impl->texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
    870     return 0;
    871 }
    872 
    873 DELEGATE_TO_IMPL_2(uniform1f, long, float)
    874 
    875 void GraphicsContext3DInternal::uniform1fv(long location, float* v, int size)
    876 {
    877     m_impl->uniform1fv(location, size, v);
    878 }
    879 
    880 DELEGATE_TO_IMPL_2(uniform1i, long, int)
    881 
    882 void GraphicsContext3DInternal::uniform1iv(long location, int* v, int size)
    883 {
    884     m_impl->uniform1iv(location, size, v);
    885 }
    886 
    887 DELEGATE_TO_IMPL_3(uniform2f, long, float, float)
    888 
    889 void GraphicsContext3DInternal::uniform2fv(long location, float* v, int size)
    890 {
    891     m_impl->uniform2fv(location, size, v);
    892 }
    893 
    894 DELEGATE_TO_IMPL_3(uniform2i, long, int, int)
    895 
    896 void GraphicsContext3DInternal::uniform2iv(long location, int* v, int size)
    897 {
    898     m_impl->uniform2iv(location, size, v);
    899 }
    900 
    901 DELEGATE_TO_IMPL_4(uniform3f, long, float, float, float)
    902 
    903 void GraphicsContext3DInternal::uniform3fv(long location, float* v, int size)
    904 {
    905     m_impl->uniform3fv(location, size, v);
    906 }
    907 
    908 DELEGATE_TO_IMPL_4(uniform3i, long, int, int, int)
    909 
    910 void GraphicsContext3DInternal::uniform3iv(long location, int* v, int size)
    911 {
    912     m_impl->uniform3iv(location, size, v);
    913 }
    914 
    915 DELEGATE_TO_IMPL_5(uniform4f, long, float, float, float, float)
    916 
    917 void GraphicsContext3DInternal::uniform4fv(long location, float* v, int size)
    918 {
    919     m_impl->uniform4fv(location, size, v);
    920 }
    921 
    922 DELEGATE_TO_IMPL_5(uniform4i, long, int, int, int, int)
    923 
    924 void GraphicsContext3DInternal::uniform4iv(long location, int* v, int size)
    925 {
    926     m_impl->uniform4iv(location, size, v);
    927 }
    928 
    929 void GraphicsContext3DInternal::uniformMatrix2fv(long location, bool transpose, float* value, int size)
    930 {
    931     m_impl->uniformMatrix2fv(location, size, transpose, value);
    932 }
    933 
    934 void GraphicsContext3DInternal::uniformMatrix3fv(long location, bool transpose, float* value, int size)
    935 {
    936     m_impl->uniformMatrix3fv(location, size, transpose, value);
    937 }
    938 
    939 void GraphicsContext3DInternal::uniformMatrix4fv(long location, bool transpose, float* value, int size)
    940 {
    941     m_impl->uniformMatrix4fv(location, size, transpose, value);
    942 }
    943 
    944 DELEGATE_TO_IMPL_1_X(useProgram, WebGLProgram*)
    945 DELEGATE_TO_IMPL_1_X(validateProgram, WebGLProgram*)
    946 
    947 DELEGATE_TO_IMPL_2(vertexAttrib1f, unsigned long, float)
    948 DELEGATE_TO_IMPL_2(vertexAttrib1fv, unsigned long, float*)
    949 DELEGATE_TO_IMPL_3(vertexAttrib2f, unsigned long, float, float)
    950 DELEGATE_TO_IMPL_2(vertexAttrib2fv, unsigned long, float*)
    951 DELEGATE_TO_IMPL_4(vertexAttrib3f, unsigned long, float, float, float)
    952 DELEGATE_TO_IMPL_2(vertexAttrib3fv, unsigned long, float*)
    953 DELEGATE_TO_IMPL_5(vertexAttrib4f, unsigned long, float, float, float, float)
    954 DELEGATE_TO_IMPL_2(vertexAttrib4fv, unsigned long, float*)
    955 DELEGATE_TO_IMPL_6(vertexAttribPointer, unsigned long, int, int, bool, unsigned long, unsigned long)
    956 
    957 DELEGATE_TO_IMPL_4(viewport, long, long, unsigned long, unsigned long)
    958 
    959 DELEGATE_TO_IMPL_R(createBuffer, unsigned)
    960 DELEGATE_TO_IMPL_R(createFramebuffer, unsigned)
    961 DELEGATE_TO_IMPL_R(createProgram, unsigned)
    962 DELEGATE_TO_IMPL_R(createRenderbuffer, unsigned)
    963 DELEGATE_TO_IMPL_1R(createShader, unsigned long, unsigned)
    964 DELEGATE_TO_IMPL_R(createTexture, unsigned)
    965 
    966 DELEGATE_TO_IMPL_1(deleteBuffer, unsigned)
    967 DELEGATE_TO_IMPL_1(deleteFramebuffer, unsigned)
    968 DELEGATE_TO_IMPL_1(deleteProgram, unsigned)
    969 DELEGATE_TO_IMPL_1(deleteRenderbuffer, unsigned)
    970 DELEGATE_TO_IMPL_1(deleteShader, unsigned)
    971 DELEGATE_TO_IMPL_1(deleteTexture, unsigned)
    972 
    973 DELEGATE_TO_IMPL_1(synthesizeGLError, unsigned long)
    974 
    975 //----------------------------------------------------------------------
    976 // GraphicsContext3D
    977 //
    978 
    979 // Macros to assist in delegating from GraphicsContext3D to
    980 // GraphicsContext3DInternal.
    981 
    982 #define DELEGATE_TO_INTERNAL(name) \
    983 void GraphicsContext3D::name() \
    984 { \
    985     m_internal->name(); \
    986 }
    987 
    988 #define DELEGATE_TO_INTERNAL_R(name, rt)           \
    989 rt GraphicsContext3D::name() \
    990 { \
    991     return m_internal->name(); \
    992 }
    993 
    994 #define DELEGATE_TO_INTERNAL_1(name, t1) \
    995 void GraphicsContext3D::name(t1 a1) \
    996 { \
    997     m_internal->name(a1); \
    998 }
    999 
    1000 #define DELEGATE_TO_INTERNAL_1R(name, t1, rt)    \
    1001 rt GraphicsContext3D::name(t1 a1) \
    1002 { \
    1003     return m_internal->name(a1); \
    1004 }
    1005 
    1006 #define DELEGATE_TO_INTERNAL_2(name, t1, t2) \
    1007 void GraphicsContext3D::name(t1 a1, t2 a2) \
    1008 { \
    1009     m_internal->name(a1, a2); \
    1010 }
    1011 
    1012 #define DELEGATE_TO_INTERNAL_2R(name, t1, t2, rt)  \
    1013 rt GraphicsContext3D::name(t1 a1, t2 a2) \
    1014 { \
    1015     return m_internal->name(a1, a2); \
    1016 }
    1017 
    1018 #define DELEGATE_TO_INTERNAL_3(name, t1, t2, t3)   \
    1019 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3)    \
    1020 { \
    1021     m_internal->name(a1, a2, a3);                  \
    1022 }
    1023 
    1024 #define DELEGATE_TO_INTERNAL_3R(name, t1, t2, t3, rt)   \
    1025 rt GraphicsContext3D::name(t1 a1, t2 a2, t3 a3)    \
    1026 { \
    1027     return m_internal->name(a1, a2, a3);                  \
    1028 }
    1029 
    1030 #define DELEGATE_TO_INTERNAL_4(name, t1, t2, t3, t4)    \
    1031 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4)  \
    1032 { \
    1033     m_internal->name(a1, a2, a3, a4);              \
    1034 }
    1035 
    1036 #define DELEGATE_TO_INTERNAL_5(name, t1, t2, t3, t4, t5)      \
    1037 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5)        \
    1038 { \
    1039     m_internal->name(a1, a2, a3, a4, a5);   \
    1040 }
    1041 
    1042 #define DELEGATE_TO_INTERNAL_6(name, t1, t2, t3, t4, t5, t6)  \
    1043 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6) \
    1044 { \
    1045     m_internal->name(a1, a2, a3, a4, a5, a6);   \
    1046 }
    1047 
    1048 #define DELEGATE_TO_INTERNAL_6R(name, t1, t2, t3, t4, t5, t6, rt)  \
    1049 rt GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6) \
    1050 { \
    1051     return m_internal->name(a1, a2, a3, a4, a5, a6);       \
    1052 }
    1053 
    1054 #define DELEGATE_TO_INTERNAL_7R(name, t1, t2, t3, t4, t5, t6, t7, rt) \
    1055 rt GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7) \
    1056 { \
    1057     return m_internal->name(a1, a2, a3, a4, a5, a6, a7);   \
    1058 }
    1059 
    1060 #define DELEGATE_TO_INTERNAL_8(name, t1, t2, t3, t4, t5, t6, t7, t8)       \
    1061 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8 a8) \
    1062 { \
    1063     m_internal->name(a1, a2, a3, a4, a5, a6, a7, a8);      \
    1064 }
    1065 
    1066 #define DELEGATE_TO_INTERNAL_9R(name, t1, t2, t3, t4, t5, t6, t7, t8, t9, rt) \
    1067 rt GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8 a8, t9 a9) \
    1068 { \
    1069     return m_internal->name(a1, a2, a3, a4, a5, a6, a7, a8, a9);   \
    1070 }
    1071 
    1072 GraphicsContext3D::GraphicsContext3D(GraphicsContext3D::Attributes attrs)
    1073 {
    1074 }
    1075 
    1076 GraphicsContext3D::~GraphicsContext3D()
    1077 {
    1078 }
    1079 
    1080 PassOwnPtr<GraphicsContext3D> GraphicsContext3D::create(GraphicsContext3D::Attributes attrs)
    1081 {
    1082     GraphicsContext3DInternal* internal = new GraphicsContext3DInternal();
    1083     if (!internal->initialize(attrs)) {
    1084         delete internal;
    1085         return 0;
    1086     }
    1087     PassOwnPtr<GraphicsContext3D> result = new GraphicsContext3D(attrs);
    1088     result->m_internal.set(internal);
    1089     return result;
    1090 }
    1091 
    1092 PlatformGraphicsContext3D GraphicsContext3D::platformGraphicsContext3D() const
    1093 {
    1094     return m_internal->platformGraphicsContext3D();
    1095 }
    1096 
    1097 Platform3DObject GraphicsContext3D::platformTexture() const
    1098 {
    1099     return m_internal->platformTexture();
    1100 }
    1101 
    1102 DELEGATE_TO_INTERNAL(makeContextCurrent)
    1103 DELEGATE_TO_INTERNAL_1R(sizeInBytes, int, int)
    1104 DELEGATE_TO_INTERNAL_2(reshape, int, int)
    1105 
    1106 DELEGATE_TO_INTERNAL_1(activeTexture, unsigned long)
    1107 DELEGATE_TO_INTERNAL_2(attachShader, WebGLProgram*, WebGLShader*)
    1108 DELEGATE_TO_INTERNAL_3(bindAttribLocation, WebGLProgram*, unsigned long, const String&)
    1109 
    1110 DELEGATE_TO_INTERNAL_2(bindBuffer, unsigned long, WebGLBuffer*)
    1111 DELEGATE_TO_INTERNAL_2(bindFramebuffer, unsigned long, WebGLFramebuffer*)
    1112 DELEGATE_TO_INTERNAL_2(bindRenderbuffer, unsigned long, WebGLRenderbuffer*)
    1113 DELEGATE_TO_INTERNAL_2(bindTexture, unsigned long, WebGLTexture*)
    1114 DELEGATE_TO_INTERNAL_4(blendColor, double, double, double, double)
    1115 DELEGATE_TO_INTERNAL_1(blendEquation, unsigned long)
    1116 DELEGATE_TO_INTERNAL_2(blendEquationSeparate, unsigned long, unsigned long)
    1117 DELEGATE_TO_INTERNAL_2(blendFunc, unsigned long, unsigned long)
    1118 DELEGATE_TO_INTERNAL_4(blendFuncSeparate, unsigned long, unsigned long, unsigned long, unsigned long)
    1119 
    1120 DELEGATE_TO_INTERNAL_3(bufferData, unsigned long, int, unsigned long)
    1121 DELEGATE_TO_INTERNAL_3(bufferData, unsigned long, WebGLArray*, unsigned long)
    1122 DELEGATE_TO_INTERNAL_3(bufferSubData, unsigned long, long, WebGLArray*)
    1123 
    1124 DELEGATE_TO_INTERNAL_1R(checkFramebufferStatus, unsigned long, unsigned long)
    1125 DELEGATE_TO_INTERNAL_1(clear, unsigned long)
    1126 DELEGATE_TO_INTERNAL_4(clearColor, double, double, double, double)
    1127 DELEGATE_TO_INTERNAL_1(clearDepth, double)
    1128 DELEGATE_TO_INTERNAL_1(clearStencil, long)
    1129 DELEGATE_TO_INTERNAL_4(colorMask, bool, bool, bool, bool)
    1130 DELEGATE_TO_INTERNAL_1(compileShader, WebGLShader*)
    1131 
    1132 DELEGATE_TO_INTERNAL_8(copyTexImage2D, unsigned long, long, unsigned long, long, long, unsigned long, unsigned long, long)
    1133 DELEGATE_TO_INTERNAL_8(copyTexSubImage2D, unsigned long, long, long, long, long, long, unsigned long, unsigned long)
    1134 DELEGATE_TO_INTERNAL_1(cullFace, unsigned long)
    1135 DELEGATE_TO_INTERNAL_1(depthFunc, unsigned long)
    1136 DELEGATE_TO_INTERNAL_1(depthMask, bool)
    1137 DELEGATE_TO_INTERNAL_2(depthRange, double, double)
    1138 DELEGATE_TO_INTERNAL_2(detachShader, WebGLProgram*, WebGLShader*)
    1139 DELEGATE_TO_INTERNAL_1(disable, unsigned long)
    1140 DELEGATE_TO_INTERNAL_1(disableVertexAttribArray, unsigned long)
    1141 DELEGATE_TO_INTERNAL_3(drawArrays, unsigned long, long, long)
    1142 DELEGATE_TO_INTERNAL_4(drawElements, unsigned long, unsigned long, unsigned long, long)
    1143 
    1144 DELEGATE_TO_INTERNAL_1(enable, unsigned long)
    1145 DELEGATE_TO_INTERNAL_1(enableVertexAttribArray, unsigned long)
    1146 DELEGATE_TO_INTERNAL(finish)
    1147 DELEGATE_TO_INTERNAL(flush)
    1148 DELEGATE_TO_INTERNAL_4(framebufferRenderbuffer, unsigned long, unsigned long, unsigned long, WebGLRenderbuffer*)
    1149 DELEGATE_TO_INTERNAL_5(framebufferTexture2D, unsigned long, unsigned long, unsigned long, WebGLTexture*, long)
    1150 DELEGATE_TO_INTERNAL_1(frontFace, unsigned long)
    1151 DELEGATE_TO_INTERNAL_1(generateMipmap, unsigned long)
    1152 
    1153 DELEGATE_TO_INTERNAL_3R(getActiveAttrib, WebGLProgram*, unsigned long, ActiveInfo&, bool)
    1154 DELEGATE_TO_INTERNAL_3R(getActiveUniform, WebGLProgram*, unsigned long, ActiveInfo&, bool)
    1155 
    1156 DELEGATE_TO_INTERNAL_2R(getAttribLocation, WebGLProgram*, const String&, int)
    1157 
    1158 DELEGATE_TO_INTERNAL_2(getBooleanv, unsigned long, unsigned char*)
    1159 
    1160 DELEGATE_TO_INTERNAL_3(getBufferParameteriv, unsigned long, unsigned long, int*)
    1161 
    1162 DELEGATE_TO_INTERNAL_R(getContextAttributes, GraphicsContext3D::Attributes)
    1163 
    1164 DELEGATE_TO_INTERNAL_R(getError, unsigned long)
    1165 
    1166 DELEGATE_TO_INTERNAL_2(getFloatv, unsigned long, float*)
    1167 
    1168 DELEGATE_TO_INTERNAL_4(getFramebufferAttachmentParameteriv, unsigned long, unsigned long, unsigned long, int*)
    1169 
    1170 DELEGATE_TO_INTERNAL_2(getIntegerv, unsigned long, int*)
    1171 
    1172 DELEGATE_TO_INTERNAL_3(getProgramiv, WebGLProgram*, unsigned long, int*)
    1173 
    1174 DELEGATE_TO_INTERNAL_1R(getProgramInfoLog, WebGLProgram*, String)
    1175 
    1176 DELEGATE_TO_INTERNAL_3(getRenderbufferParameteriv, unsigned long, unsigned long, int*)
    1177 
    1178 DELEGATE_TO_INTERNAL_3(getShaderiv, WebGLShader*, unsigned long, int*)
    1179 
    1180 DELEGATE_TO_INTERNAL_1R(getShaderInfoLog, WebGLShader*, String)
    1181 
    1182 DELEGATE_TO_INTERNAL_1R(getShaderSource, WebGLShader*, String)
    1183 DELEGATE_TO_INTERNAL_1R(getString, unsigned long, String)
    1184 
    1185 DELEGATE_TO_INTERNAL_3(getTexParameterfv, unsigned long, unsigned long, float*)
    1186 DELEGATE_TO_INTERNAL_3(getTexParameteriv, unsigned long, unsigned long, int*)
    1187 
    1188 DELEGATE_TO_INTERNAL_3(getUniformfv, WebGLProgram*, long, float*)
    1189 DELEGATE_TO_INTERNAL_3(getUniformiv, WebGLProgram*, long, int*)
    1190 
    1191 DELEGATE_TO_INTERNAL_2R(getUniformLocation, WebGLProgram*, const String&, long)
    1192 
    1193 DELEGATE_TO_INTERNAL_3(getVertexAttribfv, unsigned long, unsigned long, float*)
    1194 DELEGATE_TO_INTERNAL_3(getVertexAttribiv, unsigned long, unsigned long, int*)
    1195 
    1196 DELEGATE_TO_INTERNAL_2R(getVertexAttribOffset, unsigned long, unsigned long, long)
    1197 
    1198 DELEGATE_TO_INTERNAL_2(hint, unsigned long, unsigned long)
    1199 DELEGATE_TO_INTERNAL_1R(isBuffer, WebGLBuffer*, bool)
    1200 DELEGATE_TO_INTERNAL_1R(isEnabled, unsigned long, bool)
    1201 DELEGATE_TO_INTERNAL_1R(isFramebuffer, WebGLFramebuffer*, bool)
    1202 DELEGATE_TO_INTERNAL_1R(isProgram, WebGLProgram*, bool)
    1203 DELEGATE_TO_INTERNAL_1R(isRenderbuffer, WebGLRenderbuffer*, bool)
    1204 DELEGATE_TO_INTERNAL_1R(isShader, WebGLShader*, bool)
    1205 DELEGATE_TO_INTERNAL_1R(isTexture, WebGLTexture*, bool)
    1206 DELEGATE_TO_INTERNAL_1(lineWidth, double)
    1207 DELEGATE_TO_INTERNAL_1(linkProgram, WebGLProgram*)
    1208 DELEGATE_TO_INTERNAL_2(pixelStorei, unsigned long, long)
    1209 DELEGATE_TO_INTERNAL_2(polygonOffset, double, double)
    1210 
    1211 DELEGATE_TO_INTERNAL_6R(readPixels, long, long, unsigned long, unsigned long, unsigned long, unsigned long, PassRefPtr<WebGLArray>)
    1212 
    1213 DELEGATE_TO_INTERNAL(releaseShaderCompiler)
    1214 DELEGATE_TO_INTERNAL_4(renderbufferStorage, unsigned long, unsigned long, unsigned long, unsigned long)
    1215 DELEGATE_TO_INTERNAL_2(sampleCoverage, double, bool)
    1216 DELEGATE_TO_INTERNAL_4(scissor, long, long, unsigned long, unsigned long)
    1217 DELEGATE_TO_INTERNAL_2(shaderSource, WebGLShader*, const String&)
    1218 DELEGATE_TO_INTERNAL_3(stencilFunc, unsigned long, long, unsigned long)
    1219 DELEGATE_TO_INTERNAL_4(stencilFuncSeparate, unsigned long, unsigned long, long, unsigned long)
    1220 DELEGATE_TO_INTERNAL_1(stencilMask, unsigned long)
    1221 DELEGATE_TO_INTERNAL_2(stencilMaskSeparate, unsigned long, unsigned long)
    1222 DELEGATE_TO_INTERNAL_3(stencilOp, unsigned long, unsigned long, unsigned long)
    1223 DELEGATE_TO_INTERNAL_4(stencilOpSeparate, unsigned long, unsigned long, unsigned long, unsigned long)
    1224 
    1225 DELEGATE_TO_INTERNAL_9R(texImage2D, unsigned, unsigned, unsigned, unsigned, unsigned, unsigned, unsigned, unsigned, void*, int)
    12261875
    12271876int GraphicsContext3D::texImage2D(unsigned target, unsigned level, Image* image,
     
    12321881    if (!extractImageData(image, flipY, premultiplyAlpha, imageData, &format, &internalFormat))
    12331882        return -1;
    1234     return m_internal->texImage2D(target, level, internalFormat,
    1235                                   image->width(), image->height(), 0,
    1236                                   format, UNSIGNED_BYTE, imageData.data());
    1237 }
    1238 
    1239 DELEGATE_TO_INTERNAL_3(texParameterf, unsigned, unsigned, float)
    1240 DELEGATE_TO_INTERNAL_3(texParameteri, unsigned, unsigned, int)
    1241 
    1242 DELEGATE_TO_INTERNAL_9R(texSubImage2D, unsigned, unsigned, unsigned, unsigned, unsigned, unsigned, unsigned, unsigned, void*, int)
     1883    glTexImage2D(target, level, internalFormat,
     1884                 image->width(), image->height(), 0,
     1885                 format, GL_UNSIGNED_BYTE, imageData.data());
     1886    return 0;
     1887}
     1888
     1889GL_SAME_METHOD_3(TexParameterf, texParameterf, unsigned, unsigned, float);
     1890
     1891GL_SAME_METHOD_3(TexParameteri, texParameteri, unsigned, unsigned, int);
     1892
     1893int GraphicsContext3D::texSubImage2D(unsigned target,
     1894                                     unsigned level,
     1895                                     unsigned xoffset,
     1896                                     unsigned yoffset,
     1897                                     unsigned width,
     1898                                     unsigned height,
     1899                                     unsigned format,
     1900                                     unsigned type,
     1901                                     void* pixels)
     1902{
     1903    glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
     1904    return 0;
     1905}
    12431906
    12441907int GraphicsContext3D::texSubImage2D(unsigned target,
     
    12541917    if (!extractImageData(image, flipY, premultiplyAlpha, imageData, &format, &internalFormat))
    12551918        return -1;
    1256     return m_internal->texSubImage2D(target, level, xoffset, yoffset,
    1257                                      image->width(), image->height(),
    1258                                      format, UNSIGNED_BYTE, imageData.data());
    1259 }
    1260 
    1261 DELEGATE_TO_INTERNAL_2(uniform1f, long, float)
    1262 DELEGATE_TO_INTERNAL_3(uniform1fv, long, float*, int)
    1263 DELEGATE_TO_INTERNAL_2(uniform1i, long, int)
    1264 DELEGATE_TO_INTERNAL_3(uniform1iv, long, int*, int)
    1265 DELEGATE_TO_INTERNAL_3(uniform2f, long, float, float)
    1266 DELEGATE_TO_INTERNAL_3(uniform2fv, long, float*, int)
    1267 DELEGATE_TO_INTERNAL_3(uniform2i, long, int, int)
    1268 DELEGATE_TO_INTERNAL_3(uniform2iv, long, int*, int)
    1269 DELEGATE_TO_INTERNAL_4(uniform3f, long, float, float, float)
    1270 DELEGATE_TO_INTERNAL_3(uniform3fv, long, float*, int)
    1271 DELEGATE_TO_INTERNAL_4(uniform3i, long, int, int, int)
    1272 DELEGATE_TO_INTERNAL_3(uniform3iv, long, int*, int)
    1273 DELEGATE_TO_INTERNAL_5(uniform4f, long, float, float, float, float)
    1274 DELEGATE_TO_INTERNAL_3(uniform4fv, long, float*, int)
    1275 DELEGATE_TO_INTERNAL_5(uniform4i, long, int, int, int, int)
    1276 DELEGATE_TO_INTERNAL_3(uniform4iv, long, int*, int)
    1277 DELEGATE_TO_INTERNAL_4(uniformMatrix2fv, long, bool, float*, int)
    1278 DELEGATE_TO_INTERNAL_4(uniformMatrix3fv, long, bool, float*, int)
    1279 DELEGATE_TO_INTERNAL_4(uniformMatrix4fv, long, bool, float*, int)
    1280 
    1281 DELEGATE_TO_INTERNAL_1(useProgram, WebGLProgram*)
    1282 DELEGATE_TO_INTERNAL_1(validateProgram, WebGLProgram*)
    1283 
    1284 DELEGATE_TO_INTERNAL_2(vertexAttrib1f, unsigned long, float)
    1285 DELEGATE_TO_INTERNAL_2(vertexAttrib1fv, unsigned long, float*)
    1286 DELEGATE_TO_INTERNAL_3(vertexAttrib2f, unsigned long, float, float)
    1287 DELEGATE_TO_INTERNAL_2(vertexAttrib2fv, unsigned long, float*)
    1288 DELEGATE_TO_INTERNAL_4(vertexAttrib3f, unsigned long, float, float, float)
    1289 DELEGATE_TO_INTERNAL_2(vertexAttrib3fv, unsigned long, float*)
    1290 DELEGATE_TO_INTERNAL_5(vertexAttrib4f, unsigned long, float, float, float, float)
    1291 DELEGATE_TO_INTERNAL_2(vertexAttrib4fv, unsigned long, float*)
    1292 DELEGATE_TO_INTERNAL_6(vertexAttribPointer, unsigned long, int, int, bool, unsigned long, unsigned long)
    1293 
    1294 DELEGATE_TO_INTERNAL_4(viewport, long, long, unsigned long, unsigned long)
    1295 
    1296 DELEGATE_TO_INTERNAL_1(beginPaint, WebGLRenderingContext*)
    1297 DELEGATE_TO_INTERNAL(endPaint)
    1298 
    1299 DELEGATE_TO_INTERNAL_R(createBuffer, unsigned)
    1300 DELEGATE_TO_INTERNAL_R(createFramebuffer, unsigned)
    1301 DELEGATE_TO_INTERNAL_R(createProgram, unsigned)
    1302 DELEGATE_TO_INTERNAL_R(createRenderbuffer, unsigned)
    1303 DELEGATE_TO_INTERNAL_1R(createShader, unsigned long, unsigned)
    1304 DELEGATE_TO_INTERNAL_R(createTexture, unsigned)
    1305 
    1306 DELEGATE_TO_INTERNAL_1(deleteBuffer, unsigned)
    1307 DELEGATE_TO_INTERNAL_1(deleteFramebuffer, unsigned)
    1308 DELEGATE_TO_INTERNAL_1(deleteProgram, unsigned)
    1309 DELEGATE_TO_INTERNAL_1(deleteRenderbuffer, unsigned)
    1310 DELEGATE_TO_INTERNAL_1(deleteShader, unsigned)
    1311 DELEGATE_TO_INTERNAL_1(deleteTexture, unsigned)
    1312 
    1313 DELEGATE_TO_INTERNAL_1(synthesizeGLError, unsigned long)
    1314 
    1315 } // namespace WebCore
     1919    glTexSubImage2D(target, level, xoffset, yoffset,
     1920                    image->width(), image->height(),
     1921                    format, GL_UNSIGNED_BYTE, imageData.data());
     1922    return 0;
     1923}
     1924
     1925GL_SAME_METHOD_2(Uniform1f, uniform1f, long, float)
     1926
     1927void GraphicsContext3D::uniform1fv(long location, float* v, int size)
     1928{
     1929    makeContextCurrent();
     1930    glUniform1fv(location, size, v);
     1931}
     1932
     1933GL_SAME_METHOD_2(Uniform1i, uniform1i, long, int)
     1934
     1935void GraphicsContext3D::uniform1iv(long location, int* v, int size)
     1936{
     1937    makeContextCurrent();
     1938    glUniform1iv(location, size, v);
     1939}
     1940
     1941GL_SAME_METHOD_3(Uniform2f, uniform2f, long, float, float)
     1942
     1943void GraphicsContext3D::uniform2fv(long location, float* v, int size)
     1944{
     1945    makeContextCurrent();
     1946    glUniform2fv(location, size, v);
     1947}
     1948
     1949GL_SAME_METHOD_3(Uniform2i, uniform2i, long, int, int)
     1950
     1951void GraphicsContext3D::uniform2iv(long location, int* v, int size)
     1952{
     1953    makeContextCurrent();
     1954    glUniform2iv(location, size, v);
     1955}
     1956
     1957GL_SAME_METHOD_4(Uniform3f, uniform3f, long, float, float, float)
     1958
     1959void GraphicsContext3D::uniform3fv(long location, float* v, int size)
     1960{
     1961    makeContextCurrent();
     1962    glUniform3fv(location, size, v);
     1963}
     1964
     1965GL_SAME_METHOD_4(Uniform3i, uniform3i, long, int, int, int)
     1966
     1967void GraphicsContext3D::uniform3iv(long location, int* v, int size)
     1968{
     1969    makeContextCurrent();
     1970    glUniform3iv(location, size, v);
     1971}
     1972
     1973GL_SAME_METHOD_5(Uniform4f, uniform4f, long, float, float, float, float)
     1974
     1975void GraphicsContext3D::uniform4fv(long location, float* v, int size)
     1976{
     1977    makeContextCurrent();
     1978    glUniform4fv(location, size, v);
     1979}
     1980
     1981GL_SAME_METHOD_5(Uniform4i, uniform4i, long, int, int, int, int)
     1982
     1983void GraphicsContext3D::uniform4iv(long location, int* v, int size)
     1984{
     1985    makeContextCurrent();
     1986    glUniform4iv(location, size, v);
     1987}
     1988
     1989void GraphicsContext3D::uniformMatrix2fv(long location, bool transpose, float* value, int size)
     1990{
     1991    makeContextCurrent();
     1992    glUniformMatrix2fv(location, size, transpose, value);
     1993}
     1994
     1995void GraphicsContext3D::uniformMatrix3fv(long location, bool transpose, float* value, int size)
     1996{
     1997    makeContextCurrent();
     1998    glUniformMatrix3fv(location, size, transpose, value);
     1999}
     2000
     2001void GraphicsContext3D::uniformMatrix4fv(long location, bool transpose, float* value, int size)
     2002{
     2003    makeContextCurrent();
     2004    glUniformMatrix4fv(location, size, transpose, value);
     2005}
     2006
     2007GL_SAME_METHOD_1_X(UseProgram, useProgram, WebGLProgram*)
     2008
     2009GL_SAME_METHOD_1_X(ValidateProgram, validateProgram, WebGLProgram*)
     2010
     2011GL_SAME_METHOD_2(VertexAttrib1f, vertexAttrib1f, unsigned long, float)
     2012
     2013void GraphicsContext3D::vertexAttrib1fv(unsigned long indx, float* values)
     2014{
     2015    makeContextCurrent();
     2016    glVertexAttrib1fv(indx, values);
     2017}
     2018
     2019GL_SAME_METHOD_3(VertexAttrib2f, vertexAttrib2f, unsigned long, float, float)
     2020
     2021void GraphicsContext3D::vertexAttrib2fv(unsigned long indx, float* values)
     2022{
     2023    makeContextCurrent();
     2024    glVertexAttrib2fv(indx, values);
     2025}
     2026
     2027GL_SAME_METHOD_4(VertexAttrib3f, vertexAttrib3f, unsigned long, float, float, float)
     2028
     2029void GraphicsContext3D::vertexAttrib3fv(unsigned long indx, float* values)
     2030{
     2031    makeContextCurrent();
     2032    glVertexAttrib3fv(indx, values);
     2033}
     2034
     2035GL_SAME_METHOD_5(VertexAttrib4f, vertexAttrib4f, unsigned long, float, float, float, float)
     2036
     2037void GraphicsContext3D::vertexAttrib4fv(unsigned long indx, float* values)
     2038{
     2039    makeContextCurrent();
     2040    glVertexAttrib4fv(indx, values);
     2041}
     2042
     2043void GraphicsContext3D::vertexAttribPointer(unsigned long indx, int size, int type, bool normalized,
     2044                                            unsigned long stride, unsigned long offset)
     2045{
     2046    m_internal->vertexAttribPointer(indx, size, type, normalized, stride, offset);
     2047}
     2048
     2049void GraphicsContext3D::viewport(long x, long y, unsigned long width, unsigned long height)
     2050{
     2051    makeContextCurrent();
     2052    m_internal->viewportImpl(x, y, width, height);
     2053}
     2054
     2055}
    13162056
    13172057#endif // ENABLE(3D_CANVAS)
Note: See TracChangeset for help on using the changeset viewer.