Changeset 56294 in webkit


Ignore:
Timestamp:
Mar 19, 2010 8:35:07 PM (14 years ago)
Author:
eric@webkit.org
Message:

2010-03-19 Kenneth Russell <kbr@google.com>

Reviewed by Darin Fisher.

Add GraphicsContext3D abstraction to WebKit API
https://bugs.webkit.org/show_bug.cgi?id=36262

Added WebGraphicsContext3D to the WebKit API and refactored Chromium's
GraphicsContext3D implementation to use it. All of the OpenGL calls have
been moved out of WebKit/chromium/src/GraphicsContext3D.cpp and into the
WebGraphicsContext3D implementation. GraphicsContext3D is still
responsible for the transfer of rendered output from the
WebGraphicsContext3D to the HTMLCanvasElement.

The GraphicsContext3DInternal class, which is a data member of
GraphicsContext3D for the Chromium port, remains. It is possible to
eliminate this class and thereby one level of delegation, but this is
being deferred.

The needed entry point for a Chrome implementation of
WebGraphicsContext3D has been added to WebKitClient, but it is not being
called yet by GraphicsContext3D. It will be once this patch lands and
Chromium is rolled forward to support this entry point.

This is a large patch, but the transformation is almost entirely
mechanical and there is no change in functionality. Nearly all of
GraphicsContext3D and GraphicsContext3DInternal has been moved to
WebGraphicsContext3DDefaultImpl. The only area where the splitting of
logic is less than mechanical is GraphicsContext3D::beginPaint() and its
callees.

Ran all WebGL layout tests and demos from Khronos site in Chromium.

  • WebKit.gyp:
  • public/WebGraphicsContext3D.h: Added. (WebKit::WebGraphicsContext3D::Attributes::Attributes): (WebKit::WebGraphicsContext3D::~WebGraphicsContext3D):
  • public/WebKitClient.h: (WebKit::WebKitClient::createGraphicsContext3D):
  • src/GraphicsContext3D.cpp: (WebCore::GraphicsContext3DInternal::GraphicsContext3DInternal): (WebCore::GraphicsContext3DInternal::~GraphicsContext3DInternal): (WebCore::GraphicsContext3DInternal::initialize): (WebCore::GraphicsContext3DInternal::platformGraphicsContext3D): (WebCore::GraphicsContext3DInternal::platformTexture): (WebCore::GraphicsContext3DInternal::beginPaint): (WebCore::GraphicsContext3DInternal::endPaint): (WebCore::GraphicsContext3DInternal::reshape): (WebCore::GraphicsContext3DInternal::bindAttribLocation): (WebCore::GraphicsContext3DInternal::bindTexture): (WebCore::GraphicsContext3DInternal::bufferData): (WebCore::GraphicsContext3DInternal::bufferSubData): (WebCore::GraphicsContext3DInternal::getActiveAttrib): (WebCore::GraphicsContext3DInternal::getActiveUniform): (WebCore::GraphicsContext3DInternal::getAttribLocation): (WebCore::GraphicsContext3DInternal::getContextAttributes): (WebCore::GraphicsContext3DInternal::getProgramInfoLog): (WebCore::GraphicsContext3DInternal::getShaderInfoLog): (WebCore::GraphicsContext3DInternal::getShaderSource): (WebCore::GraphicsContext3DInternal::getString): (WebCore::GraphicsContext3DInternal::getUniformLocation): (WebCore::GraphicsContext3DInternal::readPixels): (WebCore::GraphicsContext3DInternal::shaderSource): (WebCore::GraphicsContext3DInternal::texImage2D): (WebCore::GraphicsContext3DInternal::texSubImage2D): (WebCore::GraphicsContext3DInternal::uniform1fv): (WebCore::GraphicsContext3DInternal::uniform1iv): (WebCore::GraphicsContext3DInternal::uniform2fv): (WebCore::GraphicsContext3DInternal::uniform2iv): (WebCore::GraphicsContext3DInternal::uniform3fv): (WebCore::GraphicsContext3DInternal::uniform3iv): (WebCore::GraphicsContext3DInternal::uniform4fv): (WebCore::GraphicsContext3DInternal::uniform4iv): (WebCore::GraphicsContext3DInternal::uniformMatrix2fv): (WebCore::GraphicsContext3DInternal::uniformMatrix3fv): (WebCore::GraphicsContext3DInternal::uniformMatrix4fv): (WebCore::GraphicsContext3D::GraphicsContext3D): (WebCore::GraphicsContext3D::~GraphicsContext3D): (WebCore::GraphicsContext3D::create): (WebCore::GraphicsContext3D::platformGraphicsContext3D): (WebCore::GraphicsContext3D::platformTexture): (WebCore::GraphicsContext3D::texImage2D): (WebCore::GraphicsContext3D::texSubImage2D):
  • src/WebGraphicsContext3D.cpp: Added. (WebKit::WebGraphicsContext3D::createDefault):
  • src/WebGraphicsContext3DDefaultImpl.cpp: Added. (WebKit::WebGraphicsContext3DDefaultImpl::GLConnection::create): (WebKit::WebGraphicsContext3DDefaultImpl::GLConnection::~GLConnection): (WebKit::WebGraphicsContext3DDefaultImpl::VertexAttribPointerState::VertexAttribPointerState): (WebKit::WebGraphicsContext3DDefaultImpl::WebGraphicsContext3DDefaultImpl): (WebKit::WebGraphicsContext3DDefaultImpl::~WebGraphicsContext3DDefaultImpl): (WebKit::WebGraphicsContext3DDefaultImpl::initialize): (WebKit::WebGraphicsContext3DDefaultImpl::makeContextCurrent): (WebKit::WebGraphicsContext3DDefaultImpl::width): (WebKit::WebGraphicsContext3DDefaultImpl::height): (WebKit::WebGraphicsContext3DDefaultImpl::sizeInBytes): (WebKit::createTextureObject): (WebKit::WebGraphicsContext3DDefaultImpl::reshape): (WebKit::WebGraphicsContext3DDefaultImpl::flipVertically): (WebKit::WebGraphicsContext3DDefaultImpl::readBackFramebuffer): (WebKit::WebGraphicsContext3DDefaultImpl::activeTexture): (WebKit::WebGraphicsContext3DDefaultImpl::bindBuffer): (WebKit::WebGraphicsContext3DDefaultImpl::bindFramebuffer): (WebKit::WebGraphicsContext3DDefaultImpl::disableVertexAttribArray): (WebKit::WebGraphicsContext3DDefaultImpl::drawElements): (WebKit::WebGraphicsContext3DDefaultImpl::enableVertexAttribArray): (WebKit::WebGraphicsContext3DDefaultImpl::generateMipmap): (WebKit::WebGraphicsContext3DDefaultImpl::getActiveAttrib): (WebKit::WebGraphicsContext3DDefaultImpl::getActiveUniform): (WebKit::WebGraphicsContext3DDefaultImpl::getContextAttributes): (WebKit::WebGraphicsContext3DDefaultImpl::getError): (WebKit::WebGraphicsContext3DDefaultImpl::getProgramInfoLog): (WebKit::WebGraphicsContext3DDefaultImpl::getShaderInfoLog): (WebKit::WebGraphicsContext3DDefaultImpl::getShaderSource): (WebKit::WebGraphicsContext3DDefaultImpl::getString): (WebKit::WebGraphicsContext3DDefaultImpl::getVertexAttribOffset): (WebKit::WebGraphicsContext3DDefaultImpl::releaseShaderCompiler): (WebKit::WebGraphicsContext3DDefaultImpl::shaderSource): (WebKit::WebGraphicsContext3DDefaultImpl::vertexAttribPointer): (WebKit::WebGraphicsContext3DDefaultImpl::createBuffer): (WebKit::WebGraphicsContext3DDefaultImpl::createFramebuffer): (WebKit::WebGraphicsContext3DDefaultImpl::createProgram): (WebKit::WebGraphicsContext3DDefaultImpl::createRenderbuffer): (WebKit::WebGraphicsContext3DDefaultImpl::createTexture): (WebKit::WebGraphicsContext3DDefaultImpl::deleteBuffer): (WebKit::WebGraphicsContext3DDefaultImpl::deleteFramebuffer): (WebKit::WebGraphicsContext3DDefaultImpl::deleteProgram): (WebKit::WebGraphicsContext3DDefaultImpl::deleteRenderbuffer): (WebKit::WebGraphicsContext3DDefaultImpl::deleteShader): (WebKit::WebGraphicsContext3DDefaultImpl::deleteTexture): (WebKit::WebGraphicsContext3DDefaultImpl::synthesizeGLError):
  • src/WebGraphicsContext3DDefaultImpl.h: Added. (WebKit::WebGraphicsContext3DDefaultImpl::): (WebKit::WebGraphicsContext3DDefaultImpl::GLConnection::chooseFBConfig): (WebKit::WebGraphicsContext3DDefaultImpl::GLConnection::createNewContext): (WebKit::WebGraphicsContext3DDefaultImpl::GLConnection::createPbuffer): (WebKit::WebGraphicsContext3DDefaultImpl::GLConnection::destroyPbuffer): (WebKit::WebGraphicsContext3DDefaultImpl::GLConnection::makeCurrent): (WebKit::WebGraphicsContext3DDefaultImpl::GLConnection::destroyContext): (WebKit::WebGraphicsContext3DDefaultImpl::GLConnection::getCurrentContext): (WebKit::WebGraphicsContext3DDefaultImpl::GLConnection::GLConnection):
Location:
trunk/WebKit/chromium
Files:
4 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKit/chromium/ChangeLog

    r56258 r56294  
     12010-03-19  Kenneth Russell  <kbr@google.com>
     2
     3        Reviewed by Darin Fisher.
     4
     5        Add GraphicsContext3D abstraction to WebKit API
     6        https://bugs.webkit.org/show_bug.cgi?id=36262
     7
     8        Added WebGraphicsContext3D to the WebKit API and refactored Chromium's
     9        GraphicsContext3D implementation to use it. All of the OpenGL calls have
     10        been moved out of WebKit/chromium/src/GraphicsContext3D.cpp and into the
     11        WebGraphicsContext3D implementation. GraphicsContext3D is still
     12        responsible for the transfer of rendered output from the
     13        WebGraphicsContext3D to the HTMLCanvasElement.
     14
     15        The GraphicsContext3DInternal class, which is a data member of
     16        GraphicsContext3D for the Chromium port, remains. It is possible to
     17        eliminate this class and thereby one level of delegation, but this is
     18        being deferred.
     19
     20        The needed entry point for a Chrome implementation of
     21        WebGraphicsContext3D has been added to WebKitClient, but it is not being
     22        called yet by GraphicsContext3D. It will be once this patch lands and
     23        Chromium is rolled forward to support this entry point.
     24
     25        This is a large patch, but the transformation is almost entirely
     26        mechanical and there is no change in functionality. Nearly all of
     27        GraphicsContext3D and GraphicsContext3DInternal has been moved to
     28        WebGraphicsContext3DDefaultImpl. The only area where the splitting of
     29        logic is less than mechanical is GraphicsContext3D::beginPaint() and its
     30        callees.
     31
     32        Ran all WebGL layout tests and demos from Khronos site in Chromium.
     33
     34        * WebKit.gyp:
     35        * public/WebGraphicsContext3D.h: Added.
     36        (WebKit::WebGraphicsContext3D::Attributes::Attributes):
     37        (WebKit::WebGraphicsContext3D::~WebGraphicsContext3D):
     38        * public/WebKitClient.h:
     39        (WebKit::WebKitClient::createGraphicsContext3D):
     40        * src/GraphicsContext3D.cpp:
     41        (WebCore::GraphicsContext3DInternal::GraphicsContext3DInternal):
     42        (WebCore::GraphicsContext3DInternal::~GraphicsContext3DInternal):
     43        (WebCore::GraphicsContext3DInternal::initialize):
     44        (WebCore::GraphicsContext3DInternal::platformGraphicsContext3D):
     45        (WebCore::GraphicsContext3DInternal::platformTexture):
     46        (WebCore::GraphicsContext3DInternal::beginPaint):
     47        (WebCore::GraphicsContext3DInternal::endPaint):
     48        (WebCore::GraphicsContext3DInternal::reshape):
     49        (WebCore::GraphicsContext3DInternal::bindAttribLocation):
     50        (WebCore::GraphicsContext3DInternal::bindTexture):
     51        (WebCore::GraphicsContext3DInternal::bufferData):
     52        (WebCore::GraphicsContext3DInternal::bufferSubData):
     53        (WebCore::GraphicsContext3DInternal::getActiveAttrib):
     54        (WebCore::GraphicsContext3DInternal::getActiveUniform):
     55        (WebCore::GraphicsContext3DInternal::getAttribLocation):
     56        (WebCore::GraphicsContext3DInternal::getContextAttributes):
     57        (WebCore::GraphicsContext3DInternal::getProgramInfoLog):
     58        (WebCore::GraphicsContext3DInternal::getShaderInfoLog):
     59        (WebCore::GraphicsContext3DInternal::getShaderSource):
     60        (WebCore::GraphicsContext3DInternal::getString):
     61        (WebCore::GraphicsContext3DInternal::getUniformLocation):
     62        (WebCore::GraphicsContext3DInternal::readPixels):
     63        (WebCore::GraphicsContext3DInternal::shaderSource):
     64        (WebCore::GraphicsContext3DInternal::texImage2D):
     65        (WebCore::GraphicsContext3DInternal::texSubImage2D):
     66        (WebCore::GraphicsContext3DInternal::uniform1fv):
     67        (WebCore::GraphicsContext3DInternal::uniform1iv):
     68        (WebCore::GraphicsContext3DInternal::uniform2fv):
     69        (WebCore::GraphicsContext3DInternal::uniform2iv):
     70        (WebCore::GraphicsContext3DInternal::uniform3fv):
     71        (WebCore::GraphicsContext3DInternal::uniform3iv):
     72        (WebCore::GraphicsContext3DInternal::uniform4fv):
     73        (WebCore::GraphicsContext3DInternal::uniform4iv):
     74        (WebCore::GraphicsContext3DInternal::uniformMatrix2fv):
     75        (WebCore::GraphicsContext3DInternal::uniformMatrix3fv):
     76        (WebCore::GraphicsContext3DInternal::uniformMatrix4fv):
     77        (WebCore::GraphicsContext3D::GraphicsContext3D):
     78        (WebCore::GraphicsContext3D::~GraphicsContext3D):
     79        (WebCore::GraphicsContext3D::create):
     80        (WebCore::GraphicsContext3D::platformGraphicsContext3D):
     81        (WebCore::GraphicsContext3D::platformTexture):
     82        (WebCore::GraphicsContext3D::texImage2D):
     83        (WebCore::GraphicsContext3D::texSubImage2D):
     84        * src/WebGraphicsContext3D.cpp: Added.
     85        (WebKit::WebGraphicsContext3D::createDefault):
     86        * src/WebGraphicsContext3DDefaultImpl.cpp: Added.
     87        (WebKit::WebGraphicsContext3DDefaultImpl::GLConnection::create):
     88        (WebKit::WebGraphicsContext3DDefaultImpl::GLConnection::~GLConnection):
     89        (WebKit::WebGraphicsContext3DDefaultImpl::VertexAttribPointerState::VertexAttribPointerState):
     90        (WebKit::WebGraphicsContext3DDefaultImpl::WebGraphicsContext3DDefaultImpl):
     91        (WebKit::WebGraphicsContext3DDefaultImpl::~WebGraphicsContext3DDefaultImpl):
     92        (WebKit::WebGraphicsContext3DDefaultImpl::initialize):
     93        (WebKit::WebGraphicsContext3DDefaultImpl::makeContextCurrent):
     94        (WebKit::WebGraphicsContext3DDefaultImpl::width):
     95        (WebKit::WebGraphicsContext3DDefaultImpl::height):
     96        (WebKit::WebGraphicsContext3DDefaultImpl::sizeInBytes):
     97        (WebKit::createTextureObject):
     98        (WebKit::WebGraphicsContext3DDefaultImpl::reshape):
     99        (WebKit::WebGraphicsContext3DDefaultImpl::flipVertically):
     100        (WebKit::WebGraphicsContext3DDefaultImpl::readBackFramebuffer):
     101        (WebKit::WebGraphicsContext3DDefaultImpl::activeTexture):
     102        (WebKit::WebGraphicsContext3DDefaultImpl::bindBuffer):
     103        (WebKit::WebGraphicsContext3DDefaultImpl::bindFramebuffer):
     104        (WebKit::WebGraphicsContext3DDefaultImpl::disableVertexAttribArray):
     105        (WebKit::WebGraphicsContext3DDefaultImpl::drawElements):
     106        (WebKit::WebGraphicsContext3DDefaultImpl::enableVertexAttribArray):
     107        (WebKit::WebGraphicsContext3DDefaultImpl::generateMipmap):
     108        (WebKit::WebGraphicsContext3DDefaultImpl::getActiveAttrib):
     109        (WebKit::WebGraphicsContext3DDefaultImpl::getActiveUniform):
     110        (WebKit::WebGraphicsContext3DDefaultImpl::getContextAttributes):
     111        (WebKit::WebGraphicsContext3DDefaultImpl::getError):
     112        (WebKit::WebGraphicsContext3DDefaultImpl::getProgramInfoLog):
     113        (WebKit::WebGraphicsContext3DDefaultImpl::getShaderInfoLog):
     114        (WebKit::WebGraphicsContext3DDefaultImpl::getShaderSource):
     115        (WebKit::WebGraphicsContext3DDefaultImpl::getString):
     116        (WebKit::WebGraphicsContext3DDefaultImpl::getVertexAttribOffset):
     117        (WebKit::WebGraphicsContext3DDefaultImpl::releaseShaderCompiler):
     118        (WebKit::WebGraphicsContext3DDefaultImpl::shaderSource):
     119        (WebKit::WebGraphicsContext3DDefaultImpl::vertexAttribPointer):
     120        (WebKit::WebGraphicsContext3DDefaultImpl::createBuffer):
     121        (WebKit::WebGraphicsContext3DDefaultImpl::createFramebuffer):
     122        (WebKit::WebGraphicsContext3DDefaultImpl::createProgram):
     123        (WebKit::WebGraphicsContext3DDefaultImpl::createRenderbuffer):
     124        (WebKit::WebGraphicsContext3DDefaultImpl::createTexture):
     125        (WebKit::WebGraphicsContext3DDefaultImpl::deleteBuffer):
     126        (WebKit::WebGraphicsContext3DDefaultImpl::deleteFramebuffer):
     127        (WebKit::WebGraphicsContext3DDefaultImpl::deleteProgram):
     128        (WebKit::WebGraphicsContext3DDefaultImpl::deleteRenderbuffer):
     129        (WebKit::WebGraphicsContext3DDefaultImpl::deleteShader):
     130        (WebKit::WebGraphicsContext3DDefaultImpl::deleteTexture):
     131        (WebKit::WebGraphicsContext3DDefaultImpl::synthesizeGLError):
     132        * src/WebGraphicsContext3DDefaultImpl.h: Added.
     133        (WebKit::WebGraphicsContext3DDefaultImpl::):
     134        (WebKit::WebGraphicsContext3DDefaultImpl::GLConnection::chooseFBConfig):
     135        (WebKit::WebGraphicsContext3DDefaultImpl::GLConnection::createNewContext):
     136        (WebKit::WebGraphicsContext3DDefaultImpl::GLConnection::createPbuffer):
     137        (WebKit::WebGraphicsContext3DDefaultImpl::GLConnection::destroyPbuffer):
     138        (WebKit::WebGraphicsContext3DDefaultImpl::GLConnection::makeCurrent):
     139        (WebKit::WebGraphicsContext3DDefaultImpl::GLConnection::destroyContext):
     140        (WebKit::WebGraphicsContext3DDefaultImpl::GLConnection::getCurrentContext):
     141        (WebKit::WebGraphicsContext3DDefaultImpl::GLConnection::GLConnection):
     142
    11432010-03-19  Dimitri Glazkov  <dglazkov@chromium.org>
    2144
  • trunk/WebKit/chromium/WebKit.gyp

    r55820 r56294  
    123123                'public/WebFormElement.h',
    124124                'public/WebGlyphCache.h',
     125                'public/WebGraphicsContext3D.h',
    125126                'public/WebHistoryItem.h',
    126127                'public/WebHTTPBody.h',
     
    313314                'src/WebFrameImpl.h',
    314315                'src/WebGlyphCache.cpp',
     316                'src/WebGraphicsContext3D.cpp',
     317                'src/WebGraphicsContext3DDefaultImpl.cpp',
     318                'src/WebGraphicsContext3DDefaultImpl.h',
    315319                'src/WebHistoryItem.cpp',
    316320                'src/WebHTTPBody.cpp',
  • trunk/WebKit/chromium/public/WebKitClient.h

    r56201 r56294  
    5050class WebClipboard;
    5151class WebCookieJar;
     52class WebGraphicsContext3D;
    5253class WebIndexedDatabase;
    5354class WebMessagePortChannel;
     
    270271    virtual void callOnMainThread(void (*func)()) { }
    271272
     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
    272279protected:
    273280    ~WebKitClient() { }
  • trunk/WebKit/chromium/src/GraphicsContext3D.cpp

    r56127 r56294  
    3535#include "GraphicsContext3D.h"
    3636
     37#include "CString.h"
    3738#include "CachedImage.h"
    38 #include "CString.h"
    3939#include "HTMLCanvasElement.h"
    4040#include "HTMLImageElement.h"
    4141#include "ImageBuffer.h"
    4242#include "ImageData.h"
    43 #include "NotImplemented.h"
    4443#include "WebGLBuffer.h"
    4544#include "WebGLByteArray.h"
     
    5352#include "WebGLTexture.h"
    5453#include "WebGLUnsignedByteArray.h"
     54#include "WebGraphicsContext3D.h"
     55#include "WebGraphicsContext3DDefaultImpl.h"
     56#include "WebKit.h"
     57#include "WebKitClient.h"
    5558
    5659#include <stdio.h>
    5760#include <wtf/FastMalloc.h>
    58 
    59 #if OS(WINDOWS)
    60 #include <windows.h>
    61 #endif
    62 
    63 #include "GL/glew.h"
    6461
    6562#if PLATFORM(CG)
     
    6764#include <CoreGraphics/CGContext.h>
    6865#include <CoreGraphics/CGImage.h>
    69 #include <OpenGL/OpenGL.h>
    70 #else
    71 #define FLIP_FRAMEBUFFER_VERTICALLY
    7266#endif
    7367
    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 
    83 using namespace std;
     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.
    8484
    8585namespace WebCore {
    8686
    87 // GraphicsContext3DInternal -----------------------------------------------------
     87//----------------------------------------------------------------------
     88// GraphicsContext3DInternal
    8889
    8990// Uncomment this to render to a separate window for debugging
     
    9495class GraphicsContext3DInternal {
    9596public:
    96     GraphicsContext3DInternal(GraphicsContext3D::Attributes attrs);
     97    GraphicsContext3DInternal();
    9798    ~GraphicsContext3DInternal();
    9899
    99     bool makeContextCurrent();
     100    bool initialize(GraphicsContext3D::Attributes attrs);
    100101
    101102    PlatformGraphicsContext3D platformGraphicsContext3D() const;
    102103    Platform3DObject platformTexture() const;
    103104
     105    bool makeContextCurrent();
     106
     107    int sizeInBytes(int type);
     108
    104109    void reshape(int width, int height);
    105110
    106111    void beginPaint(WebGLRenderingContext* context);
    107 
    108     bool validateTextureTarget(int target);
    109     bool validateTextureParameter(int param);
    110 
     112    void endPaint();
     113
     114    //----------------------------------------------------------------------
     115    // Entry points for WebGL.
     116    //
    111117    void activeTexture(unsigned long texture);
    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);
     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);
    119150    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);
    120155    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
     172    GraphicsContext3D::Attributes getContextAttributes();
     173
    121174    unsigned long getError();
    122     GraphicsContext3D::Attributes getContextAttributes();
     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);
    123275    void vertexAttribPointer(unsigned long indx, int size, int type, bool normalized,
    124276                             unsigned long stride, unsigned long offset);
    125     void viewportImpl(long x, long y, unsigned long width, unsigned long height);
     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);
    126293
    127294    void synthesizeGLError(unsigned long error);
    128295
    129296private:
    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 
     297    OwnPtr<WebKit::WebGraphicsContext3D> m_impl;
    173298#if PLATFORM(SKIA)
    174299    // If the width and height of the Canvas's backing store don't
     
    180305#endif
    181306
    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;
     307#if PLATFORM(CG)
    190308    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
    278309#endif
    279310};
    280311
    281 bool GraphicsContext3DInternal::s_initializedGLEW = false;
    282 
    283 #if OS(LINUX)
    284 GraphicsContext3DInternal::GLConnection* GraphicsContext3DInternal::s_gl = 0;
    285 
    286 GraphicsContext3DInternal::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 
    330 GraphicsContext3DInternal::GLConnection::~GLConnection()
    331 {
    332     XCloseDisplay(m_display);
    333     dlclose(m_libGL);
    334 }
    335 
    336 #endif // OS(LINUX)
    337 
    338 GraphicsContext3DInternal::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 
    350 GraphicsContext3DInternal::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)
     312GraphicsContext3DInternal::GraphicsContext3DInternal()
    360313#if PLATFORM(SKIA)
    361     , m_resizingBitmap(0)
    362 #endif
    363 #if OS(WINDOWS)
    364     , m_canvasWindow(0)
    365     , m_canvasDC(0)
    366     , m_contextObj(0)
     314    : m_resizingBitmap(0)
    367315#elif PLATFORM(CG)
    368     , m_pbuffer(0)
    369     , m_contextObj(0)
    370     , m_renderOutput(0)
    371 #elif OS(LINUX)
    372     , m_contextObj(0)
    373     , m_pbuffer(0)
     316    : m_renderOutput(0)
    374317#else
    375318#error Must port to your platform
    376319#endif
    377320{
    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 
     321}
     322
     323GraphicsContext3DInternal::~GraphicsContext3DInternal()
     324{
     325#if PLATFORM(SKIA)
     326    if (m_resizingBitmap)
     327        delete m_resizingBitmap;
    457328#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
     329    if (m_renderOutput)
     330        delete[] m_renderOutput;
    554331#endif
    555332
    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     }
    569 }
    570 
    571 GraphicsContext3DInternal::~GraphicsContext3DInternal()
    572 {
    573     makeContextCurrent();
    574 #ifndef RENDER_TO_DEBUGGING_WINDOW
    575     glDeleteRenderbuffersEXT(1, &m_depthBuffer);
    576     glDeleteTextures(1, &m_texture);
    577333#ifdef FLIP_FRAMEBUFFER_VERTICALLY
    578334    if (m_scanline)
    579335        delete[] m_scanline;
    580336#endif
    581     glDeleteFramebuffersEXT(1, &m_fbo);
    582 #endif // !RENDER_TO_DEBUGGING_WINDOW
    583337#if PLATFORM(SKIA)
    584338    if (m_resizingBitmap)
    585339        delete m_resizingBitmap;
    586340#endif
    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 
    608 bool 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;
     341}
     342
     343bool 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;
    626362}
    627363
    628364PlatformGraphicsContext3D GraphicsContext3DInternal::platformGraphicsContext3D() const
    629365{
    630     return m_contextObj;
     366    return 0;
    631367}
    632368
    633369Platform3DObject GraphicsContext3DInternal::platformTexture() const
    634370{
    635     return m_texture;
    636 }
    637 
    638 static 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 
    648 void 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
    721 void 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
     371    return 0;
     372}
    743373
    744374void GraphicsContext3DInternal::beginPaint(WebGLRenderingContext* context)
    745375{
    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 
    758376    HTMLCanvasElement* canvas = context->canvas();
    759377    ImageBuffer* imageBuffer = canvas->buffer();
    760378    unsigned char* pixels = 0;
    761     bool mustRestoreFBO = (m_boundFBO != m_fbo);
    762     if (mustRestoreFBO)
    763         glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
    764379#if PLATFORM(SKIA)
    765380    const SkBitmap* canvasBitmap = imageBuffer->context()->platformContext()->bitmap();
    766381    const SkBitmap* readbackBitmap = 0;
    767382    ASSERT(canvasBitmap->config() == SkBitmap::kARGB_8888_Config);
    768     if (canvasBitmap->width() == m_cachedWidth && canvasBitmap->height() == m_cachedHeight) {
     383    if (canvasBitmap->width() == m_impl->width() && canvasBitmap->height() == m_impl->height()) {
    769384        // This is the fastest and most common case. We read back
    770385        // directly into the canvas's backing store.
     
    778393        // pixel data. We will then use Skia to rescale this bitmap to
    779394        // the size of the canvas's backing store.
    780         if (m_resizingBitmap && (m_resizingBitmap->width() != m_cachedWidth || m_resizingBitmap->height() != m_cachedHeight)) {
     395        if (m_resizingBitmap && (m_resizingBitmap->width() != m_impl->width() || m_resizingBitmap->height() != m_impl->height())) {
    781396            delete m_resizingBitmap;
    782397            m_resizingBitmap = 0;
     
    785400            m_resizingBitmap = new SkBitmap();
    786401            m_resizingBitmap->setConfig(SkBitmap::kARGB_8888_Config,
    787                                         m_cachedWidth,
    788                                         m_cachedHeight);
     402                                        m_impl->width(),
     403                                        m_impl->height());
    789404            if (!m_resizingBitmap->allocPixels()) {
    790405                delete m_resizingBitmap;
     
    799414    SkAutoLockPixels bitmapLock(*readbackBitmap);
    800415    pixels = static_cast<unsigned char*>(readbackBitmap->getPixels());
    801     glReadPixels(0, 0, m_cachedWidth, m_cachedHeight, GL_BGRA, GL_UNSIGNED_BYTE, pixels);
    802416#elif PLATFORM(CG)
    803     if (m_renderOutput) {
     417    if (m_renderOutput)
    804418        pixels = m_renderOutput;
    805         glReadPixels(0, 0, m_cachedWidth, m_cachedHeight, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, pixels);
    806     }
    807419#else
    808420#error Must port to your platform
    809421#endif
    810422
    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
     423    m_impl->readBackFramebuffer(pixels, 4 * m_impl->width() * m_impl->height());
    818424
    819425#if PLATFORM(SKIA)
     
    827433#elif PLATFORM(CG)
    828434    if (m_renderOutput) {
    829         int rowBytes = m_cachedWidth * 4;
    830         CGDataProviderRef dataProvider = CGDataProviderCreateWithData(0, m_renderOutput, rowBytes * m_cachedHeight, 0);
     435        int rowBytes = m_impl->width() * 4;
     436        CGDataProviderRef dataProvider = CGDataProviderCreateWithData(0, m_renderOutput, rowBytes * m_impl->height(), 0);
    831437        CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    832         CGImageRef cgImage = CGImageCreate(m_cachedWidth,
    833                                            m_cachedHeight,
     438        CGImageRef cgImage = CGImageCreate(m_impl->width(),
     439                                           m_impl->height(),
    834440                                           8,
    835441                                           32,
     
    862468#error Must port to your platform
    863469#endif
    864 
    865 #endif  // RENDER_TO_DEBUGGING_WINDOW
    866 }
    867 
    868 void 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.
     470}
     471
     472void GraphicsContext3DInternal::endPaint()
     473{
     474}
     475
     476void GraphicsContext3DInternal::reshape(int width, int height)
     477{
     478    if (width == m_impl->width() && height == m_impl->height())
    873479        return;
    874480
    875     makeContextCurrent();
    876     glActiveTexture(texture);
    877 }
    878 
    879 void 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 
    889 void 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 }
     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) \
     499void GraphicsContext3DInternal::name() \
     500{ \
     501    m_impl->name(); \
     502}
     503
     504#define DELEGATE_TO_IMPL_R(name, rt)           \
     505rt GraphicsContext3DInternal::name() \
     506{ \
     507    return m_impl->name(); \
     508}
     509
     510#define DELEGATE_TO_IMPL_1(name, t1) \
     511void GraphicsContext3DInternal::name(t1 a1) \
     512{ \
     513    m_impl->name(a1); \
     514}
     515
     516#define DELEGATE_TO_IMPL_1_X(name, t1) \
     517void GraphicsContext3DInternal::name(t1 a1) \
     518{ \
     519    m_impl->name(EXTRACT(a1));                  \
     520}
     521
     522#define DELEGATE_TO_IMPL_1R(name, t1, rt)    \
     523rt GraphicsContext3DInternal::name(t1 a1) \
     524{ \
     525    return m_impl->name(a1); \
     526}
     527
     528#define DELEGATE_TO_IMPL_1R_X(name, t1, rt)    \
     529rt GraphicsContext3DInternal::name(t1 a1) \
     530{ \
     531    return m_impl->name(EXTRACT(a1));           \
     532}
     533
     534#define DELEGATE_TO_IMPL_2(name, t1, t2) \
     535void 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) \
     541void 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) \
     547void 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)  \
     553rt 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)   \
     559void 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)   \
     565void 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)   \
     571rt 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)    \
     577void 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)    \
     583void 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)      \
     589void 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)                \
     595void 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)      \
     601rt 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)  \
     607void 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)  \
     613rt 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) \
     619rt 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)       \
     625void 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) \
     631rt 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
     636DELEGATE_TO_IMPL_R(makeContextCurrent, bool)
     637DELEGATE_TO_IMPL_1R(sizeInBytes, int, int)
     638
     639DELEGATE_TO_IMPL_1(activeTexture, unsigned long)
     640DELEGATE_TO_IMPL_2_X12(attachShader, WebGLProgram*, WebGLShader*)
     641
     642void GraphicsContext3DInternal::bindAttribLocation(WebGLProgram* program, unsigned long index, const String& name)
     643{
     644    m_impl->bindAttribLocation(EXTRACT(program), index, name.utf8().data());
     645}
     646
     647DELEGATE_TO_IMPL_2_X2(bindBuffer, unsigned long, WebGLBuffer*)
     648DELEGATE_TO_IMPL_2_X2(bindFramebuffer, unsigned long, WebGLFramebuffer*)
     649DELEGATE_TO_IMPL_2_X2(bindRenderbuffer, unsigned long, WebGLRenderbuffer*)
     650
     651static const int kTextureWrapR = 0x8072;
    899652
    900653// If we didn't have to hack GL_TEXTURE_WRAP_R for cube maps,
    901654// we could just use:
    902 // GL_SAME_METHOD_2_X2(BindTexture, bindTexture, unsigned long, WebGLTexture*)
     655// DELEGATE_TO_IMPL_2_X2(bindTexture, unsigned long, WebGLTexture*)
    903656void GraphicsContext3DInternal::bindTexture(unsigned long target,
    904657                                            WebGLTexture* texture)
    905658{
    906     makeContextCurrent();
    907659    unsigned int textureObject = EXTRACT(texture);
    908660
    909     glBindTexture(target, textureObject);
     661    m_impl->bindTexture(target, textureObject);
    910662
    911663    // FIXME: GL_TEXTURE_WRAP_R isn't exposed in the OpenGL ES 2.0
     
    913665    // set this wrap mode to GL_CLAMP_TO_EDGE to get correct behavior
    914666    // of cube maps.
    915     if (texture) {
    916         if (target == GL_TEXTURE_CUBE_MAP) {
     667    if (texture)
     668        if (target == GraphicsContext3D::TEXTURE_CUBE_MAP) {
    917669            if (!texture->isCubeMapRWrapModeInitialized()) {
    918                 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
     670                m_impl->texParameteri(GraphicsContext3D::TEXTURE_CUBE_MAP, kTextureWrapR, GraphicsContext3D::CLAMP_TO_EDGE);
    919671                texture->setCubeMapRWrapModeInitialized(true);
    920672            }
    921673        } else
    922674            texture->setCubeMapRWrapModeInitialized(false);
    923     }
    924 }
    925 
    926 void 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 
    947 void GraphicsContext3DInternal::disableVertexAttribArray(unsigned long index)
    948 {
    949     makeContextCurrent();
    950     if (index < NumTrackedPointerStates)
    951         m_vertexAttribPointerState[index].enabled = false;
    952     glDisableVertexAttribArray(index);
    953 }
    954 
    955 void GraphicsContext3DInternal::enableVertexAttribArray(unsigned long index)
    956 {
    957     makeContextCurrent();
    958     if (index < NumTrackedPointerStates)
    959         m_vertexAttribPointerState[index].enabled = true;
    960     glEnableVertexAttribArray(index);
    961 }
    962 
    963 unsigned 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 }
     675}
     676
     677DELEGATE_TO_IMPL_4(blendColor, double, double, double, double)
     678DELEGATE_TO_IMPL_1(blendEquation, unsigned long)
     679DELEGATE_TO_IMPL_2(blendEquationSeparate, unsigned long, unsigned long)
     680DELEGATE_TO_IMPL_2(blendFunc, unsigned long, unsigned long)
     681DELEGATE_TO_IMPL_4(blendFuncSeparate, unsigned long, unsigned long, unsigned long, unsigned long)
     682
     683void GraphicsContext3DInternal::bufferData(unsigned long target, int size, unsigned long usage)
     684{
     685    m_impl->bufferData(target, size, 0, usage);
     686}
     687
     688void GraphicsContext3DInternal::bufferData(unsigned long target, WebGLArray* array, unsigned long usage)
     689{
     690    m_impl->bufferData(target, array->byteLength(), array->baseAddress(), usage);
     691}
     692
     693void GraphicsContext3DInternal::bufferSubData(unsigned long target, long offset, WebGLArray* array)
     694{
     695    m_impl->bufferSubData(target, offset, array->byteLength(), array->baseAddress());
     696}
     697
     698DELEGATE_TO_IMPL_1R(checkFramebufferStatus, unsigned long, unsigned long)
     699DELEGATE_TO_IMPL_1(clear, unsigned long)
     700DELEGATE_TO_IMPL_4(clearColor, double, double, double, double)
     701DELEGATE_TO_IMPL_1(clearDepth, double)
     702DELEGATE_TO_IMPL_1(clearStencil, long)
     703DELEGATE_TO_IMPL_4(colorMask, bool, bool, bool, bool)
     704DELEGATE_TO_IMPL_1_X(compileShader, WebGLShader*)
     705
     706DELEGATE_TO_IMPL_8(copyTexImage2D, unsigned long, long, unsigned long, long, long, unsigned long, unsigned long, long)
     707DELEGATE_TO_IMPL_8(copyTexSubImage2D, unsigned long, long, long, long, long, long, unsigned long, unsigned long)
     708DELEGATE_TO_IMPL_1(cullFace, unsigned long)
     709DELEGATE_TO_IMPL_1(depthFunc, unsigned long)
     710DELEGATE_TO_IMPL_1(depthMask, bool)
     711DELEGATE_TO_IMPL_2(depthRange, double, double)
     712DELEGATE_TO_IMPL_2_X12(detachShader, WebGLProgram*, WebGLShader*)
     713DELEGATE_TO_IMPL_1(disable, unsigned long)
     714DELEGATE_TO_IMPL_1(disableVertexAttribArray, unsigned long)
     715DELEGATE_TO_IMPL_3(drawArrays, unsigned long, long, long)
     716DELEGATE_TO_IMPL_4(drawElements, unsigned long, unsigned long, unsigned long, long)
     717
     718DELEGATE_TO_IMPL_1(enable, unsigned long)
     719DELEGATE_TO_IMPL_1(enableVertexAttribArray, unsigned long)
     720DELEGATE_TO_IMPL(finish)
     721DELEGATE_TO_IMPL(flush)
     722DELEGATE_TO_IMPL_4_X4(framebufferRenderbuffer, unsigned long, unsigned long, unsigned long, WebGLRenderbuffer*)
     723DELEGATE_TO_IMPL_5_X4(framebufferTexture2D, unsigned long, unsigned long, unsigned long, WebGLTexture*, long)
     724DELEGATE_TO_IMPL_1(frontFace, unsigned long)
     725DELEGATE_TO_IMPL_1(generateMipmap, unsigned long)
     726
     727bool GraphicsContext3DInternal::getActiveAttrib(WebGLProgram* program, unsigned long index, ActiveInfo& info)
     728{
     729    WebKit::WebGraphicsContext3D::ActiveInfo webInfo;
     730    if (!m_impl->getActiveAttrib(EXTRACT(program), index, webInfo))
     731        return false;
     732    info.name = webInfo.name;
     733    info.type = webInfo.type;
     734    info.size = webInfo.size;
     735    return true;
     736}
     737
     738bool GraphicsContext3DInternal::getActiveUniform(WebGLProgram* program, unsigned long index, ActiveInfo& info)
     739{
     740    WebKit::WebGraphicsContext3D::ActiveInfo webInfo;
     741    if (!m_impl->getActiveUniform(EXTRACT(program), index, webInfo))
     742        return false;
     743    info.name = webInfo.name;
     744    info.type = webInfo.type;
     745    info.size = webInfo.size;
     746    return true;
     747}
     748
     749int GraphicsContext3DInternal::getAttribLocation(WebGLProgram* program, const String& name)
     750{
     751    return m_impl->getAttribLocation(EXTRACT(program), name.utf8().data());
     752}
     753
     754DELEGATE_TO_IMPL_2(getBooleanv, unsigned long, unsigned char*)
     755
     756DELEGATE_TO_IMPL_3(getBufferParameteriv, unsigned long, unsigned long, int*)
    975757
    976758GraphicsContext3D::Attributes GraphicsContext3DInternal::getContextAttributes()
    977759{
    978     return m_attrs;
    979 }
    980 
    981 void 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 
    1007 void GraphicsContext3DInternal::viewportImpl(long x, long y, unsigned long width, unsigned long height)
    1008 {
    1009     glViewport(x, y, width, height);
    1010 }
    1011 
    1012 void 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)                                         \
    1025 void GraphicsContext3D::name()                                                 \
    1026 {                                                                              \
    1027     makeContextCurrent();                                                      \
    1028     gl##glname();                                                              \
    1029 }
    1030 
    1031 #define GL_SAME_METHOD_1(glname, name, t1)                                     \
    1032 void GraphicsContext3D::name(t1 a1)                                            \
    1033 {                                                                              \
    1034     makeContextCurrent();                                                      \
    1035     gl##glname(a1);                                                            \
    1036 }
    1037 
    1038 #define GL_SAME_METHOD_1_X(glname, name, t1)                                   \
    1039 void GraphicsContext3D::name(t1 a1)                                            \
    1040 {                                                                              \
    1041     makeContextCurrent();                                                      \
    1042     gl##glname(EXTRACT(a1));                                                   \
    1043 }
    1044 
    1045 #define GL_SAME_METHOD_2(glname, name, t1, t2)                                 \
    1046 void 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)                             \
    1053 void 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)                              \
    1060 void 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)                             \
    1067 void 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)                         \
    1074 void 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)                          \
    1081 void 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)                         \
    1088 void 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)                      \
    1095 void 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)                     \
    1102 void 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)                  \
    1109 void 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)                 \
    1116 void 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)         \
    1123 void 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);                                \
     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
     770DELEGATE_TO_IMPL_R(getError, unsigned long)
     771
     772DELEGATE_TO_IMPL_2(getFloatv, unsigned long, float*)
     773
     774DELEGATE_TO_IMPL_4(getFramebufferAttachmentParameteriv, unsigned long, unsigned long, unsigned long, int*)
     775
     776DELEGATE_TO_IMPL_2(getIntegerv, unsigned long, int*)
     777
     778DELEGATE_TO_IMPL_3_X1(getProgramiv, WebGLProgram*, unsigned long, int*)
     779
     780String GraphicsContext3DInternal::getProgramInfoLog(WebGLProgram* program)
     781{
     782    return m_impl->getProgramInfoLog(EXTRACT(program));
     783}
     784
     785DELEGATE_TO_IMPL_3(getRenderbufferParameteriv, unsigned long, unsigned long, int*)
     786
     787DELEGATE_TO_IMPL_3_X1(getShaderiv, WebGLShader*, unsigned long, int*)
     788
     789String GraphicsContext3DInternal::getShaderInfoLog(WebGLShader* shader)
     790{
     791    return m_impl->getShaderInfoLog(EXTRACT(shader));
     792}
     793
     794String GraphicsContext3DInternal::getShaderSource(WebGLShader* shader)
     795{
     796    return m_impl->getShaderSource(EXTRACT(shader));
     797}
     798
     799String GraphicsContext3DInternal::getString(unsigned long name)
     800{
     801    return m_impl->getString(name);
     802}
     803
     804DELEGATE_TO_IMPL_3(getTexParameterfv, unsigned long, unsigned long, float*)
     805DELEGATE_TO_IMPL_3(getTexParameteriv, unsigned long, unsigned long, int*)
     806
     807DELEGATE_TO_IMPL_3_X1(getUniformfv, WebGLProgram*, long, float*)
     808DELEGATE_TO_IMPL_3_X1(getUniformiv, WebGLProgram*, long, int*)
     809
     810long GraphicsContext3DInternal::getUniformLocation(WebGLProgram* program, const String& name)
     811{
     812    return m_impl->getUniformLocation(EXTRACT(program), name.utf8().data());
     813}
     814
     815DELEGATE_TO_IMPL_3(getVertexAttribfv, unsigned long, unsigned long, float*)
     816DELEGATE_TO_IMPL_3(getVertexAttribiv, unsigned long, unsigned long, int*)
     817
     818DELEGATE_TO_IMPL_2R(getVertexAttribOffset, unsigned long, unsigned long, long)
     819
     820DELEGATE_TO_IMPL_2(hint, unsigned long, unsigned long)
     821DELEGATE_TO_IMPL_1R_X(isBuffer, WebGLBuffer*, bool)
     822DELEGATE_TO_IMPL_1R(isEnabled, unsigned long, bool)
     823DELEGATE_TO_IMPL_1R_X(isFramebuffer, WebGLFramebuffer*, bool)
     824DELEGATE_TO_IMPL_1R_X(isProgram, WebGLProgram*, bool)
     825DELEGATE_TO_IMPL_1R_X(isRenderbuffer, WebGLRenderbuffer*, bool)
     826DELEGATE_TO_IMPL_1R_X(isShader, WebGLShader*, bool)
     827DELEGATE_TO_IMPL_1R_X(isTexture, WebGLTexture*, bool)
     828DELEGATE_TO_IMPL_1(lineWidth, double)
     829DELEGATE_TO_IMPL_1_X(linkProgram, WebGLProgram*)
     830DELEGATE_TO_IMPL_2(pixelStorei, unsigned long, long)
     831DELEGATE_TO_IMPL_2(polygonOffset, double, double)
     832
     833PassRefPtr<WebGLArray> GraphicsContext3DInternal::readPixels(long x, long y, unsigned long width, unsigned long height, unsigned long format, unsigned long type)
     834{
     835    // FIXME: take into account pack alignment.
     836    RefPtr<WebGLUnsignedByteArray> array = WebGLUnsignedByteArray::create(width * height * 4);
     837    m_impl->readPixels(x, y, width, height, format, type, array->baseAddress());
     838    return array;
     839}
     840
     841DELEGATE_TO_IMPL(releaseShaderCompiler)
     842DELEGATE_TO_IMPL_4(renderbufferStorage, unsigned long, unsigned long, unsigned long, unsigned long)
     843DELEGATE_TO_IMPL_2(sampleCoverage, double, bool)
     844DELEGATE_TO_IMPL_4(scissor, long, long, unsigned long, unsigned long)
     845
     846void GraphicsContext3DInternal::shaderSource(WebGLShader* shader, const String& string)
     847{
     848    m_impl->shaderSource(EXTRACT(shader), string.utf8().data());
     849}
     850
     851DELEGATE_TO_IMPL_3(stencilFunc, unsigned long, long, unsigned long)
     852DELEGATE_TO_IMPL_4(stencilFuncSeparate, unsigned long, unsigned long, long, unsigned long)
     853DELEGATE_TO_IMPL_1(stencilMask, unsigned long)
     854DELEGATE_TO_IMPL_2(stencilMaskSeparate, unsigned long, unsigned long)
     855DELEGATE_TO_IMPL_3(stencilOp, unsigned long, unsigned long, unsigned long)
     856DELEGATE_TO_IMPL_4(stencilOpSeparate, unsigned long, unsigned long, unsigned long, unsigned long)
     857
     858int 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);
     861    return 0;
     862}
     863
     864DELEGATE_TO_IMPL_3(texParameterf, unsigned, unsigned, float)
     865DELEGATE_TO_IMPL_3(texParameteri, unsigned, unsigned, int)
     866
     867int 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
     873DELEGATE_TO_IMPL_2(uniform1f, long, float)
     874
     875void GraphicsContext3DInternal::uniform1fv(long location, float* v, int size)
     876{
     877    m_impl->uniform1fv(location, size, v);
     878}
     879
     880DELEGATE_TO_IMPL_2(uniform1i, long, int)
     881
     882void GraphicsContext3DInternal::uniform1iv(long location, int* v, int size)
     883{
     884    m_impl->uniform1iv(location, size, v);
     885}
     886
     887DELEGATE_TO_IMPL_3(uniform2f, long, float, float)
     888
     889void GraphicsContext3DInternal::uniform2fv(long location, float* v, int size)
     890{
     891    m_impl->uniform2fv(location, size, v);
     892}
     893
     894DELEGATE_TO_IMPL_3(uniform2i, long, int, int)
     895
     896void GraphicsContext3DInternal::uniform2iv(long location, int* v, int size)
     897{
     898    m_impl->uniform2iv(location, size, v);
     899}
     900
     901DELEGATE_TO_IMPL_4(uniform3f, long, float, float, float)
     902
     903void GraphicsContext3DInternal::uniform3fv(long location, float* v, int size)
     904{
     905    m_impl->uniform3fv(location, size, v);
     906}
     907
     908DELEGATE_TO_IMPL_4(uniform3i, long, int, int, int)
     909
     910void GraphicsContext3DInternal::uniform3iv(long location, int* v, int size)
     911{
     912    m_impl->uniform3iv(location, size, v);
     913}
     914
     915DELEGATE_TO_IMPL_5(uniform4f, long, float, float, float, float)
     916
     917void GraphicsContext3DInternal::uniform4fv(long location, float* v, int size)
     918{
     919    m_impl->uniform4fv(location, size, v);
     920}
     921
     922DELEGATE_TO_IMPL_5(uniform4i, long, int, int, int, int)
     923
     924void GraphicsContext3DInternal::uniform4iv(long location, int* v, int size)
     925{
     926    m_impl->uniform4iv(location, size, v);
     927}
     928
     929void GraphicsContext3DInternal::uniformMatrix2fv(long location, bool transpose, float* value, int size)
     930{
     931    m_impl->uniformMatrix2fv(location, size, transpose, value);
     932}
     933
     934void GraphicsContext3DInternal::uniformMatrix3fv(long location, bool transpose, float* value, int size)
     935{
     936    m_impl->uniformMatrix3fv(location, size, transpose, value);
     937}
     938
     939void GraphicsContext3DInternal::uniformMatrix4fv(long location, bool transpose, float* value, int size)
     940{
     941    m_impl->uniformMatrix4fv(location, size, transpose, value);
     942}
     943
     944DELEGATE_TO_IMPL_1_X(useProgram, WebGLProgram*)
     945DELEGATE_TO_IMPL_1_X(validateProgram, WebGLProgram*)
     946
     947DELEGATE_TO_IMPL_2(vertexAttrib1f, unsigned long, float)
     948DELEGATE_TO_IMPL_2(vertexAttrib1fv, unsigned long, float*)
     949DELEGATE_TO_IMPL_3(vertexAttrib2f, unsigned long, float, float)
     950DELEGATE_TO_IMPL_2(vertexAttrib2fv, unsigned long, float*)
     951DELEGATE_TO_IMPL_4(vertexAttrib3f, unsigned long, float, float, float)
     952DELEGATE_TO_IMPL_2(vertexAttrib3fv, unsigned long, float*)
     953DELEGATE_TO_IMPL_5(vertexAttrib4f, unsigned long, float, float, float, float)
     954DELEGATE_TO_IMPL_2(vertexAttrib4fv, unsigned long, float*)
     955DELEGATE_TO_IMPL_6(vertexAttribPointer, unsigned long, int, int, bool, unsigned long, unsigned long)
     956
     957DELEGATE_TO_IMPL_4(viewport, long, long, unsigned long, unsigned long)
     958
     959DELEGATE_TO_IMPL_R(createBuffer, unsigned)
     960DELEGATE_TO_IMPL_R(createFramebuffer, unsigned)
     961DELEGATE_TO_IMPL_R(createProgram, unsigned)
     962DELEGATE_TO_IMPL_R(createRenderbuffer, unsigned)
     963DELEGATE_TO_IMPL_1R(createShader, unsigned long, unsigned)
     964DELEGATE_TO_IMPL_R(createTexture, unsigned)
     965
     966DELEGATE_TO_IMPL_1(deleteBuffer, unsigned)
     967DELEGATE_TO_IMPL_1(deleteFramebuffer, unsigned)
     968DELEGATE_TO_IMPL_1(deleteProgram, unsigned)
     969DELEGATE_TO_IMPL_1(deleteRenderbuffer, unsigned)
     970DELEGATE_TO_IMPL_1(deleteShader, unsigned)
     971DELEGATE_TO_IMPL_1(deleteTexture, unsigned)
     972
     973DELEGATE_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) \
     983void GraphicsContext3D::name() \
     984{ \
     985    m_internal->name(); \
     986}
     987
     988#define DELEGATE_TO_INTERNAL_R(name, rt)           \
     989rt GraphicsContext3D::name() \
     990{ \
     991    return m_internal->name(); \
     992}
     993
     994#define DELEGATE_TO_INTERNAL_1(name, t1) \
     995void GraphicsContext3D::name(t1 a1) \
     996{ \
     997    m_internal->name(a1); \
     998}
     999
     1000#define DELEGATE_TO_INTERNAL_1R(name, t1, rt)    \
     1001rt GraphicsContext3D::name(t1 a1) \
     1002{ \
     1003    return m_internal->name(a1); \
     1004}
     1005
     1006#define DELEGATE_TO_INTERNAL_2(name, t1, t2) \
     1007void 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)  \
     1013rt 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)   \
     1019void 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)   \
     1025rt 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)    \
     1031void 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)      \
     1037void 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)  \
     1043void 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)  \
     1049rt 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) \
     1055rt 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)       \
     1061void 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) \
     1067rt 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
     1072GraphicsContext3D::GraphicsContext3D(GraphicsContext3D::Attributes attrs)
     1073{
     1074}
     1075
     1076GraphicsContext3D::~GraphicsContext3D()
     1077{
    11271078}
    11281079
    11291080PassOwnPtr<GraphicsContext3D> GraphicsContext3D::create(GraphicsContext3D::Attributes attrs)
    11301081{
    1131     PassOwnPtr<GraphicsContext3D> context = new GraphicsContext3D(attrs);
    1132     // FIXME: add error checking
    1133     return context;
    1134 }
    1135 
    1136 GraphicsContext3D::GraphicsContext3D(GraphicsContext3D::Attributes attrs)
    1137     : m_currentWidth(0)
    1138     , m_currentHeight(0)
    1139     , m_internal(new GraphicsContext3DInternal(attrs))
    1140 {
    1141 }
    1142 
    1143 GraphicsContext3D::~GraphicsContext3D()
    1144 {
    1145 }
    1146 
    1147 PlatformGraphicsContext3D GraphicsContext3D::platformGraphicsContext3D() const
    1148 {
    1149     return m_internal->platformGraphicsContext3D();
    1150 }
    1151 
    1152 Platform3DObject GraphicsContext3D::platformTexture() const
    1153 {
    1154     return m_internal->platformTexture();
    1155 }
    1156 
    1157 void GraphicsContext3D::makeContextCurrent()
    1158 {
    1159     m_internal->makeContextCurrent();
    1160 }
    1161 
    1162 void 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 
    1173 void GraphicsContext3D::beginPaint(WebGLRenderingContext* context)
    1174 {
    1175     m_internal->beginPaint(context);
    1176 }
    1177 
    1178 void GraphicsContext3D::endPaint()
    1179 {
    1180 }
    1181 
    1182 int 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.
     1082    GraphicsContext3DInternal* internal = new GraphicsContext3DInternal();
     1083    if (!internal->initialize(attrs)) {
     1084        delete internal;
    12001085        return 0;
    12011086    }
    1202 }
    1203 
    1204 unsigned GraphicsContext3D::createBuffer()
    1205 {
    1206     makeContextCurrent();
    1207     GLuint o;
    1208     glGenBuffers(1, &o);
    1209     return o;
    1210 }
    1211 
    1212 unsigned GraphicsContext3D::createFramebuffer()
    1213 {
    1214     makeContextCurrent();
    1215     GLuint o = 0;
    1216     glGenFramebuffersEXT(1, &o);
    1217     return o;
    1218 }
    1219 
    1220 unsigned GraphicsContext3D::createProgram()
    1221 {
    1222     makeContextCurrent();
    1223     return glCreateProgram();
    1224 }
    1225 
    1226 unsigned GraphicsContext3D::createRenderbuffer()
    1227 {
    1228     makeContextCurrent();
    1229     GLuint o;
    1230     glGenRenderbuffersEXT(1, &o);
    1231     return o;
    1232 }
    1233 
    1234 unsigned GraphicsContext3D::createShader(unsigned long type)
    1235 {
    1236     makeContextCurrent();
    1237     return glCreateShader((type == FRAGMENT_SHADER) ? GL_FRAGMENT_SHADER : GL_VERTEX_SHADER);
    1238 }
    1239 
    1240 unsigned GraphicsContext3D::createTexture()
    1241 {
    1242     makeContextCurrent();
    1243     GLuint o;
    1244     glGenTextures(1, &o);
    1245     return o;
    1246 }
    1247 
    1248 void GraphicsContext3D::deleteBuffer(unsigned buffer)
    1249 {
    1250     makeContextCurrent();
    1251     glDeleteBuffers(1, &buffer);
    1252 }
    1253 
    1254 void GraphicsContext3D::deleteFramebuffer(unsigned framebuffer)
    1255 {
    1256     makeContextCurrent();
    1257     glDeleteFramebuffersEXT(1, &framebuffer);
    1258 }
    1259 
    1260 void GraphicsContext3D::deleteProgram(unsigned program)
    1261 {
    1262     makeContextCurrent();
    1263     glDeleteProgram(program);
    1264 }
    1265 
    1266 void GraphicsContext3D::deleteRenderbuffer(unsigned renderbuffer)
    1267 {
    1268     makeContextCurrent();
    1269     glDeleteRenderbuffersEXT(1, &renderbuffer);
    1270 }
    1271 
    1272 void GraphicsContext3D::deleteShader(unsigned shader)
    1273 {
    1274     makeContextCurrent();
    1275     glDeleteShader(shader);
    1276 }
    1277 
    1278 void GraphicsContext3D::deleteTexture(unsigned texture)
    1279 {
    1280     makeContextCurrent();
    1281     glDeleteTextures(1, &texture);
    1282 }
    1283 
    1284 void GraphicsContext3D::activeTexture(unsigned long texture)
    1285 {
    1286     m_internal->activeTexture(texture);
    1287 }
    1288 
    1289 GL_SAME_METHOD_2_X12(AttachShader, attachShader, WebGLProgram*, WebGLShader*)
    1290 
    1291 void 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 
    1301 void GraphicsContext3D::bindBuffer(unsigned long target,
    1302                                    WebGLBuffer* buffer)
    1303 {
    1304     m_internal->bindBuffer(target, buffer);
    1305 }
    1306 
    1307 void GraphicsContext3D::bindFramebuffer(unsigned long target, WebGLFramebuffer* framebuffer)
    1308 {
    1309     m_internal->bindFramebuffer(target, framebuffer);
    1310 }
    1311 
    1312 GL_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*)
    1317 void GraphicsContext3D::bindTexture(unsigned long target,
    1318                                     WebGLTexture* texture)
    1319 {
    1320     m_internal->bindTexture(target, texture);
    1321 }
    1322 
    1323 GL_SAME_METHOD_4(BlendColor, blendColor, double, double, double, double)
    1324 
    1325 GL_SAME_METHOD_1(BlendEquation, blendEquation, unsigned long)
    1326 
    1327 GL_SAME_METHOD_2(BlendEquationSeparate, blendEquationSeparate, unsigned long, unsigned long)
    1328 
    1329 GL_SAME_METHOD_2(BlendFunc, blendFunc, unsigned long, unsigned long)
    1330 
    1331 GL_SAME_METHOD_4(BlendFuncSeparate, blendFuncSeparate, unsigned long, unsigned long, unsigned long, unsigned long)
    1332 
    1333 void GraphicsContext3D::bufferData(unsigned long target, int size, unsigned long usage)
    1334 {
    1335     m_internal->bufferDataImpl(target, size, 0, usage);
    1336 }
    1337 
    1338 void GraphicsContext3D::bufferData(unsigned long target, WebGLArray* array, unsigned long usage)
    1339 {
    1340     m_internal->bufferDataImpl(target, array->byteLength(), array->baseAddress(), usage);
    1341 }
    1342 
    1343 void 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 
    1363 unsigned long GraphicsContext3D::checkFramebufferStatus(unsigned long target)
    1364 {
    1365     makeContextCurrent();
    1366     return glCheckFramebufferStatusEXT(target);
    1367 }
    1368 
    1369 GL_SAME_METHOD_1(Clear, clear, unsigned long)
    1370 
    1371 GL_SAME_METHOD_4(ClearColor, clearColor, double, double, double, double)
    1372 
    1373 GL_SAME_METHOD_1(ClearDepth, clearDepth, double)
    1374 
    1375 GL_SAME_METHOD_1(ClearStencil, clearStencil, long)
    1376 
    1377 GL_SAME_METHOD_4(ColorMask, colorMask, bool, bool, bool, bool)
    1378 
    1379 GL_SAME_METHOD_1_X(CompileShader, compileShader, WebGLShader*)
    1380 
    1381 GL_SAME_METHOD_8(CopyTexImage2D, copyTexImage2D, unsigned long, long, unsigned long, long, long, unsigned long, unsigned long, long)
    1382 
    1383 GL_SAME_METHOD_8(CopyTexSubImage2D, copyTexSubImage2D, unsigned long, long, long, long, long, long, unsigned long, unsigned long)
    1384 
    1385 GL_SAME_METHOD_1(CullFace, cullFace, unsigned long)
    1386 
    1387 GL_SAME_METHOD_1(DepthFunc, depthFunc, unsigned long)
    1388 
    1389 GL_SAME_METHOD_1(DepthMask, depthMask, bool)
    1390 
    1391 GL_SAME_METHOD_2(DepthRange, depthRange, double, double)
    1392 
    1393 void GraphicsContext3D::detachShader(WebGLProgram* program, WebGLShader* shader)
    1394 {
    1395     if (!program || !shader)
    1396         return;
    1397 
    1398     makeContextCurrent();
    1399     glDetachShader(EXTRACT(program), EXTRACT(shader));
    1400 }
    1401 
    1402 GL_SAME_METHOD_1(Disable, disable, unsigned long)
    1403 
    1404 void GraphicsContext3D::disableVertexAttribArray(unsigned long index)
    1405 {
    1406     m_internal->disableVertexAttribArray(index);
    1407 }
    1408 
    1409 void 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 
    1442 void 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 
    1458 GL_SAME_METHOD_1(Enable, enable, unsigned long)
    1459 
    1460 void GraphicsContext3D::enableVertexAttribArray(unsigned long index)
    1461 {
    1462     m_internal->enableVertexAttribArray(index);
    1463 }
    1464 
    1465 GL_SAME_METHOD_0(Finish, finish)
    1466 
    1467 GL_SAME_METHOD_0(Flush, flush)
    1468 
    1469 GL_SAME_METHOD_4_X4(FramebufferRenderbufferEXT, framebufferRenderbuffer, unsigned long, unsigned long, unsigned long, WebGLRenderbuffer*)
    1470 
    1471 GL_SAME_METHOD_5_X4(FramebufferTexture2DEXT, framebufferTexture2D, unsigned long, unsigned long, unsigned long, WebGLTexture*, long)
    1472 
    1473 GL_SAME_METHOD_1(FrontFace, frontFace, unsigned long)
    1474 
    1475 void 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 
    1485 bool GraphicsContext3D::getActiveAttrib(WebGLProgram* program, unsigned long index, ActiveInfo& info)
    1486 {
    1487     if (!program) {
    1488         synthesizeGLError(INVALID_VALUE);
    1489         return false;
    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);
    1513     return true;
    1514 }
    1515 
    1516 bool GraphicsContext3D::getActiveUniform(WebGLProgram* program, unsigned long index, ActiveInfo& info)
    1517 {
    1518     if (!program) {
    1519         synthesizeGLError(INVALID_VALUE);
    1520         return false;
    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);
    1544     return true;
    1545 }
    1546 
    1547 int 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 
    1556 void GraphicsContext3D::getBooleanv(unsigned long pname, unsigned char* value)
    1557 {
    1558     makeContextCurrent();
    1559     glGetBooleanv(pname, value);
    1560 }
    1561 
    1562 void GraphicsContext3D::getBufferParameteriv(unsigned long target, unsigned long pname, int* value)
    1563 {
    1564     makeContextCurrent();
    1565     glGetBufferParameteriv(target, pname, value);
    1566 }
    1567 
    1568 GraphicsContext3D::Attributes GraphicsContext3D::getContextAttributes()
    1569 {
    1570     return m_internal->getContextAttributes();
    1571 }
    1572 
    1573 unsigned long GraphicsContext3D::getError()
    1574 {
    1575     return m_internal->getError();
    1576 }
    1577 
    1578 void GraphicsContext3D::getFloatv(unsigned long pname, float* value)
    1579 {
    1580     makeContextCurrent();
    1581     glGetFloatv(pname, value);
    1582 }
    1583 
    1584 void 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 
    1593 void GraphicsContext3D::getIntegerv(unsigned long pname, int* value)
    1594 {
    1595     makeContextCurrent();
    1596     glGetIntegerv(pname, value);
    1597 }
    1598 
    1599 void GraphicsContext3D::getProgramiv(WebGLProgram* program,
    1600                                      unsigned long pname,
    1601                                      int* value)
    1602 {
    1603     makeContextCurrent();
    1604     glGetProgramiv(EXTRACT(program), pname, value);
    1605 }
    1606 
    1607 String 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 
    1626 void GraphicsContext3D::getRenderbufferParameteriv(unsigned long target,
    1627                                                    unsigned long pname,
    1628                                                    int* value)
    1629 {
    1630     makeContextCurrent();
    1631     glGetRenderbufferParameterivEXT(target, pname, value);
    1632 }
    1633 
    1634 void GraphicsContext3D::getShaderiv(WebGLShader* shader,
    1635                                     unsigned long pname,
    1636                                     int* value)
    1637 {
    1638     makeContextCurrent();
    1639     glGetShaderiv(EXTRACT(shader), pname, value);
    1640 }
    1641 
    1642 String 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 
    1661 String 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 
    1680 String GraphicsContext3D::getString(unsigned long name)
    1681 {
    1682     makeContextCurrent();
    1683     return String(reinterpret_cast<const char*>(glGetString(name)));
    1684 }
    1685 
    1686 void GraphicsContext3D::getTexParameterfv(unsigned long target, unsigned long pname, float* value)
    1687 {
    1688     makeContextCurrent();
    1689     glGetTexParameterfv(target, pname, value);
    1690 }
    1691 
    1692 void GraphicsContext3D::getTexParameteriv(unsigned long target, unsigned long pname, int* value)
    1693 {
    1694     makeContextCurrent();
    1695     glGetTexParameteriv(target, pname, value);
    1696 }
    1697 
    1698 void GraphicsContext3D::getUniformfv(WebGLProgram* program, long location, float* value)
    1699 {
    1700     makeContextCurrent();
    1701     glGetUniformfv(EXTRACT(program), location, value);
    1702 }
    1703 
    1704 void GraphicsContext3D::getUniformiv(WebGLProgram* program, long location, int* value)
    1705 {
    1706     makeContextCurrent();
    1707     glGetUniformiv(EXTRACT(program), location, value);
    1708 }
    1709 
    1710 long 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 
    1719 void GraphicsContext3D::getVertexAttribfv(unsigned long index,
    1720                                           unsigned long pname,
    1721                                           float* value)
    1722 {
    1723     makeContextCurrent();
    1724     glGetVertexAttribfv(index, pname, value);
    1725 }
    1726 
    1727 void GraphicsContext3D::getVertexAttribiv(unsigned long index,
    1728                                           unsigned long pname,
    1729                                           int* value)
    1730 {
    1731     makeContextCurrent();
    1732     glGetVertexAttribiv(index, pname, value);
    1733 }
    1734 
    1735 long GraphicsContext3D::getVertexAttribOffset(unsigned long index, unsigned long pname)
    1736 {
    1737     // FIXME: implement.
    1738     notImplemented();
    1739     return 0;
    1740 }
    1741 
    1742 GL_SAME_METHOD_2(Hint, hint, unsigned long, unsigned long);
    1743 
    1744 bool GraphicsContext3D::isBuffer(WebGLBuffer* buffer)
    1745 {
    1746     makeContextCurrent();
    1747     return glIsBuffer(EXTRACT(buffer));
    1748 }
    1749 
    1750 bool GraphicsContext3D::isEnabled(unsigned long cap)
    1751 {
    1752     makeContextCurrent();
    1753     return glIsEnabled(cap);
    1754 }
    1755 
    1756 bool GraphicsContext3D::isFramebuffer(WebGLFramebuffer* framebuffer)
    1757 {
    1758     makeContextCurrent();
    1759     return glIsFramebufferEXT(EXTRACT(framebuffer));
    1760 }
    1761 
    1762 bool GraphicsContext3D::isProgram(WebGLProgram* program)
    1763 {
    1764     makeContextCurrent();
    1765     return glIsProgram(EXTRACT(program));
    1766 }
    1767 
    1768 bool GraphicsContext3D::isRenderbuffer(WebGLRenderbuffer* renderbuffer)
    1769 {
    1770     makeContextCurrent();
    1771     return glIsRenderbufferEXT(EXTRACT(renderbuffer));
    1772 }
    1773 
    1774 bool GraphicsContext3D::isShader(WebGLShader* shader)
    1775 {
    1776     makeContextCurrent();
    1777     return glIsShader(EXTRACT(shader));
    1778 }
    1779 
    1780 bool GraphicsContext3D::isTexture(WebGLTexture* texture)
    1781 {
    1782     makeContextCurrent();
    1783     return glIsTexture(EXTRACT(texture));
    1784 }
    1785 
    1786 GL_SAME_METHOD_1(LineWidth, lineWidth, double)
    1787 
    1788 GL_SAME_METHOD_1_X(LinkProgram, linkProgram, WebGLProgram*)
    1789 
    1790 void 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 
    1801 GL_SAME_METHOD_2(PolygonOffset, polygonOffset, double, double)
    1802 
    1803 PassRefPtr<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 
    1810     // FIXME: take into account pack alignment.
    1811     RefPtr<WebGLUnsignedByteArray> array = WebGLUnsignedByteArray::create(width * height * 4);
    1812     glReadPixels(x, y, width, height, format, type, array->baseAddress());
    1813     return array;
    1814 }
    1815 
    1816 void GraphicsContext3D::releaseShaderCompiler()
    1817 {
    1818 }
    1819 
    1820 GL_SAME_METHOD_4(RenderbufferStorageEXT, renderbufferStorage, unsigned long, unsigned long, unsigned long, unsigned long)
    1821 
    1822 GL_SAME_METHOD_2(SampleCoverage, sampleCoverage, double, bool)
    1823 
    1824 GL_SAME_METHOD_4(Scissor, scissor, long, long, unsigned long, unsigned long)
    1825 
    1826 void 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 
    1835 GL_SAME_METHOD_3(StencilFunc, stencilFunc, unsigned long, long, unsigned long)
    1836 
    1837 GL_SAME_METHOD_4(StencilFuncSeparate, stencilFuncSeparate, unsigned long, unsigned long, long, unsigned long)
    1838 
    1839 GL_SAME_METHOD_1(StencilMask, stencilMask, unsigned long)
    1840 
    1841 GL_SAME_METHOD_2(StencilMaskSeparate, stencilMaskSeparate, unsigned long, unsigned long)
    1842 
    1843 GL_SAME_METHOD_3(StencilOp, stencilOp, unsigned long, unsigned long, unsigned long)
    1844 
    1845 GL_SAME_METHOD_4(StencilOpSeparate, stencilOpSeparate, unsigned long, unsigned long, unsigned long, unsigned long)
    1846 
    1847 void GraphicsContext3D::synthesizeGLError(unsigned long error)
    1848 {
    1849     m_internal->synthesizeGLError(error);
    1850 }
    1851 
    1852 int 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);
    1873     return 0;
    1874 }
     1087    PassOwnPtr<GraphicsContext3D> result = new GraphicsContext3D(attrs);
     1088    result->m_internal.set(internal);
     1089    return result;
     1090}
     1091
     1092PlatformGraphicsContext3D GraphicsContext3D::platformGraphicsContext3D() const
     1093{
     1094    return m_internal->platformGraphicsContext3D();
     1095}
     1096
     1097Platform3DObject GraphicsContext3D::platformTexture() const
     1098{
     1099    return m_internal->platformTexture();
     1100}
     1101
     1102DELEGATE_TO_INTERNAL(makeContextCurrent)
     1103DELEGATE_TO_INTERNAL_1R(sizeInBytes, int, int)
     1104DELEGATE_TO_INTERNAL_2(reshape, int, int)
     1105
     1106DELEGATE_TO_INTERNAL_1(activeTexture, unsigned long)
     1107DELEGATE_TO_INTERNAL_2(attachShader, WebGLProgram*, WebGLShader*)
     1108DELEGATE_TO_INTERNAL_3(bindAttribLocation, WebGLProgram*, unsigned long, const String&)
     1109
     1110DELEGATE_TO_INTERNAL_2(bindBuffer, unsigned long, WebGLBuffer*)
     1111DELEGATE_TO_INTERNAL_2(bindFramebuffer, unsigned long, WebGLFramebuffer*)
     1112DELEGATE_TO_INTERNAL_2(bindRenderbuffer, unsigned long, WebGLRenderbuffer*)
     1113DELEGATE_TO_INTERNAL_2(bindTexture, unsigned long, WebGLTexture*)
     1114DELEGATE_TO_INTERNAL_4(blendColor, double, double, double, double)
     1115DELEGATE_TO_INTERNAL_1(blendEquation, unsigned long)
     1116DELEGATE_TO_INTERNAL_2(blendEquationSeparate, unsigned long, unsigned long)
     1117DELEGATE_TO_INTERNAL_2(blendFunc, unsigned long, unsigned long)
     1118DELEGATE_TO_INTERNAL_4(blendFuncSeparate, unsigned long, unsigned long, unsigned long, unsigned long)
     1119
     1120DELEGATE_TO_INTERNAL_3(bufferData, unsigned long, int, unsigned long)
     1121DELEGATE_TO_INTERNAL_3(bufferData, unsigned long, WebGLArray*, unsigned long)
     1122DELEGATE_TO_INTERNAL_3(bufferSubData, unsigned long, long, WebGLArray*)
     1123
     1124DELEGATE_TO_INTERNAL_1R(checkFramebufferStatus, unsigned long, unsigned long)
     1125DELEGATE_TO_INTERNAL_1(clear, unsigned long)
     1126DELEGATE_TO_INTERNAL_4(clearColor, double, double, double, double)
     1127DELEGATE_TO_INTERNAL_1(clearDepth, double)
     1128DELEGATE_TO_INTERNAL_1(clearStencil, long)
     1129DELEGATE_TO_INTERNAL_4(colorMask, bool, bool, bool, bool)
     1130DELEGATE_TO_INTERNAL_1(compileShader, WebGLShader*)
     1131
     1132DELEGATE_TO_INTERNAL_8(copyTexImage2D, unsigned long, long, unsigned long, long, long, unsigned long, unsigned long, long)
     1133DELEGATE_TO_INTERNAL_8(copyTexSubImage2D, unsigned long, long, long, long, long, long, unsigned long, unsigned long)
     1134DELEGATE_TO_INTERNAL_1(cullFace, unsigned long)
     1135DELEGATE_TO_INTERNAL_1(depthFunc, unsigned long)
     1136DELEGATE_TO_INTERNAL_1(depthMask, bool)
     1137DELEGATE_TO_INTERNAL_2(depthRange, double, double)
     1138DELEGATE_TO_INTERNAL_2(detachShader, WebGLProgram*, WebGLShader*)
     1139DELEGATE_TO_INTERNAL_1(disable, unsigned long)
     1140DELEGATE_TO_INTERNAL_1(disableVertexAttribArray, unsigned long)
     1141DELEGATE_TO_INTERNAL_3(drawArrays, unsigned long, long, long)
     1142DELEGATE_TO_INTERNAL_4(drawElements, unsigned long, unsigned long, unsigned long, long)
     1143
     1144DELEGATE_TO_INTERNAL_1(enable, unsigned long)
     1145DELEGATE_TO_INTERNAL_1(enableVertexAttribArray, unsigned long)
     1146DELEGATE_TO_INTERNAL(finish)
     1147DELEGATE_TO_INTERNAL(flush)
     1148DELEGATE_TO_INTERNAL_4(framebufferRenderbuffer, unsigned long, unsigned long, unsigned long, WebGLRenderbuffer*)
     1149DELEGATE_TO_INTERNAL_5(framebufferTexture2D, unsigned long, unsigned long, unsigned long, WebGLTexture*, long)
     1150DELEGATE_TO_INTERNAL_1(frontFace, unsigned long)
     1151DELEGATE_TO_INTERNAL_1(generateMipmap, unsigned long)
     1152
     1153DELEGATE_TO_INTERNAL_3R(getActiveAttrib, WebGLProgram*, unsigned long, ActiveInfo&, bool)
     1154DELEGATE_TO_INTERNAL_3R(getActiveUniform, WebGLProgram*, unsigned long, ActiveInfo&, bool)
     1155
     1156DELEGATE_TO_INTERNAL_2R(getAttribLocation, WebGLProgram*, const String&, int)
     1157
     1158DELEGATE_TO_INTERNAL_2(getBooleanv, unsigned long, unsigned char*)
     1159
     1160DELEGATE_TO_INTERNAL_3(getBufferParameteriv, unsigned long, unsigned long, int*)
     1161
     1162DELEGATE_TO_INTERNAL_R(getContextAttributes, GraphicsContext3D::Attributes)
     1163
     1164DELEGATE_TO_INTERNAL_R(getError, unsigned long)
     1165
     1166DELEGATE_TO_INTERNAL_2(getFloatv, unsigned long, float*)
     1167
     1168DELEGATE_TO_INTERNAL_4(getFramebufferAttachmentParameteriv, unsigned long, unsigned long, unsigned long, int*)
     1169
     1170DELEGATE_TO_INTERNAL_2(getIntegerv, unsigned long, int*)
     1171
     1172DELEGATE_TO_INTERNAL_3(getProgramiv, WebGLProgram*, unsigned long, int*)
     1173
     1174DELEGATE_TO_INTERNAL_1R(getProgramInfoLog, WebGLProgram*, String)
     1175
     1176DELEGATE_TO_INTERNAL_3(getRenderbufferParameteriv, unsigned long, unsigned long, int*)
     1177
     1178DELEGATE_TO_INTERNAL_3(getShaderiv, WebGLShader*, unsigned long, int*)
     1179
     1180DELEGATE_TO_INTERNAL_1R(getShaderInfoLog, WebGLShader*, String)
     1181
     1182DELEGATE_TO_INTERNAL_1R(getShaderSource, WebGLShader*, String)
     1183DELEGATE_TO_INTERNAL_1R(getString, unsigned long, String)
     1184
     1185DELEGATE_TO_INTERNAL_3(getTexParameterfv, unsigned long, unsigned long, float*)
     1186DELEGATE_TO_INTERNAL_3(getTexParameteriv, unsigned long, unsigned long, int*)
     1187
     1188DELEGATE_TO_INTERNAL_3(getUniformfv, WebGLProgram*, long, float*)
     1189DELEGATE_TO_INTERNAL_3(getUniformiv, WebGLProgram*, long, int*)
     1190
     1191DELEGATE_TO_INTERNAL_2R(getUniformLocation, WebGLProgram*, const String&, long)
     1192
     1193DELEGATE_TO_INTERNAL_3(getVertexAttribfv, unsigned long, unsigned long, float*)
     1194DELEGATE_TO_INTERNAL_3(getVertexAttribiv, unsigned long, unsigned long, int*)
     1195
     1196DELEGATE_TO_INTERNAL_2R(getVertexAttribOffset, unsigned long, unsigned long, long)
     1197
     1198DELEGATE_TO_INTERNAL_2(hint, unsigned long, unsigned long)
     1199DELEGATE_TO_INTERNAL_1R(isBuffer, WebGLBuffer*, bool)
     1200DELEGATE_TO_INTERNAL_1R(isEnabled, unsigned long, bool)
     1201DELEGATE_TO_INTERNAL_1R(isFramebuffer, WebGLFramebuffer*, bool)
     1202DELEGATE_TO_INTERNAL_1R(isProgram, WebGLProgram*, bool)
     1203DELEGATE_TO_INTERNAL_1R(isRenderbuffer, WebGLRenderbuffer*, bool)
     1204DELEGATE_TO_INTERNAL_1R(isShader, WebGLShader*, bool)
     1205DELEGATE_TO_INTERNAL_1R(isTexture, WebGLTexture*, bool)
     1206DELEGATE_TO_INTERNAL_1(lineWidth, double)
     1207DELEGATE_TO_INTERNAL_1(linkProgram, WebGLProgram*)
     1208DELEGATE_TO_INTERNAL_2(pixelStorei, unsigned long, long)
     1209DELEGATE_TO_INTERNAL_2(polygonOffset, double, double)
     1210
     1211DELEGATE_TO_INTERNAL_6R(readPixels, long, long, unsigned long, unsigned long, unsigned long, unsigned long, PassRefPtr<WebGLArray>)
     1212
     1213DELEGATE_TO_INTERNAL(releaseShaderCompiler)
     1214DELEGATE_TO_INTERNAL_4(renderbufferStorage, unsigned long, unsigned long, unsigned long, unsigned long)
     1215DELEGATE_TO_INTERNAL_2(sampleCoverage, double, bool)
     1216DELEGATE_TO_INTERNAL_4(scissor, long, long, unsigned long, unsigned long)
     1217DELEGATE_TO_INTERNAL_2(shaderSource, WebGLShader*, const String&)
     1218DELEGATE_TO_INTERNAL_3(stencilFunc, unsigned long, long, unsigned long)
     1219DELEGATE_TO_INTERNAL_4(stencilFuncSeparate, unsigned long, unsigned long, long, unsigned long)
     1220DELEGATE_TO_INTERNAL_1(stencilMask, unsigned long)
     1221DELEGATE_TO_INTERNAL_2(stencilMaskSeparate, unsigned long, unsigned long)
     1222DELEGATE_TO_INTERNAL_3(stencilOp, unsigned long, unsigned long, unsigned long)
     1223DELEGATE_TO_INTERNAL_4(stencilOpSeparate, unsigned long, unsigned long, unsigned long, unsigned long)
     1224
     1225DELEGATE_TO_INTERNAL_9R(texImage2D, unsigned, unsigned, unsigned, unsigned, unsigned, unsigned, unsigned, unsigned, void*, int)
    18751226
    18761227int GraphicsContext3D::texImage2D(unsigned target, unsigned level, Image* image,
     
    18811232    if (!extractImageData(image, flipY, premultiplyAlpha, imageData, &format, &internalFormat))
    18821233        return -1;
    1883     glTexImage2D(target, level, internalFormat,
    1884                  image->width(), image->height(), 0,
    1885                  format, GL_UNSIGNED_BYTE, imageData.data());
    1886     return 0;
    1887 }
    1888 
    1889 GL_SAME_METHOD_3(TexParameterf, texParameterf, unsigned, unsigned, float);
    1890 
    1891 GL_SAME_METHOD_3(TexParameteri, texParameteri, unsigned, unsigned, int);
    1892 
    1893 int 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 }
     1234    return m_internal->texImage2D(target, level, internalFormat,
     1235                                  image->width(), image->height(), 0,
     1236                                  format, UNSIGNED_BYTE, imageData.data());
     1237}
     1238
     1239DELEGATE_TO_INTERNAL_3(texParameterf, unsigned, unsigned, float)
     1240DELEGATE_TO_INTERNAL_3(texParameteri, unsigned, unsigned, int)
     1241
     1242DELEGATE_TO_INTERNAL_9R(texSubImage2D, unsigned, unsigned, unsigned, unsigned, unsigned, unsigned, unsigned, unsigned, void*, int)
    19061243
    19071244int GraphicsContext3D::texSubImage2D(unsigned target,
     
    19171254    if (!extractImageData(image, flipY, premultiplyAlpha, imageData, &format, &internalFormat))
    19181255        return -1;
    1919     glTexSubImage2D(target, level, xoffset, yoffset,
    1920                     image->width(), image->height(),
    1921                     format, GL_UNSIGNED_BYTE, imageData.data());
    1922     return 0;
    1923 }
    1924 
    1925 GL_SAME_METHOD_2(Uniform1f, uniform1f, long, float)
    1926 
    1927 void GraphicsContext3D::uniform1fv(long location, float* v, int size)
    1928 {
    1929     makeContextCurrent();
    1930     glUniform1fv(location, size, v);
    1931 }
    1932 
    1933 GL_SAME_METHOD_2(Uniform1i, uniform1i, long, int)
    1934 
    1935 void GraphicsContext3D::uniform1iv(long location, int* v, int size)
    1936 {
    1937     makeContextCurrent();
    1938     glUniform1iv(location, size, v);
    1939 }
    1940 
    1941 GL_SAME_METHOD_3(Uniform2f, uniform2f, long, float, float)
    1942 
    1943 void GraphicsContext3D::uniform2fv(long location, float* v, int size)
    1944 {
    1945     makeContextCurrent();
    1946     glUniform2fv(location, size, v);
    1947 }
    1948 
    1949 GL_SAME_METHOD_3(Uniform2i, uniform2i, long, int, int)
    1950 
    1951 void GraphicsContext3D::uniform2iv(long location, int* v, int size)
    1952 {
    1953     makeContextCurrent();
    1954     glUniform2iv(location, size, v);
    1955 }
    1956 
    1957 GL_SAME_METHOD_4(Uniform3f, uniform3f, long, float, float, float)
    1958 
    1959 void GraphicsContext3D::uniform3fv(long location, float* v, int size)
    1960 {
    1961     makeContextCurrent();
    1962     glUniform3fv(location, size, v);
    1963 }
    1964 
    1965 GL_SAME_METHOD_4(Uniform3i, uniform3i, long, int, int, int)
    1966 
    1967 void GraphicsContext3D::uniform3iv(long location, int* v, int size)
    1968 {
    1969     makeContextCurrent();
    1970     glUniform3iv(location, size, v);
    1971 }
    1972 
    1973 GL_SAME_METHOD_5(Uniform4f, uniform4f, long, float, float, float, float)
    1974 
    1975 void GraphicsContext3D::uniform4fv(long location, float* v, int size)
    1976 {
    1977     makeContextCurrent();
    1978     glUniform4fv(location, size, v);
    1979 }
    1980 
    1981 GL_SAME_METHOD_5(Uniform4i, uniform4i, long, int, int, int, int)
    1982 
    1983 void GraphicsContext3D::uniform4iv(long location, int* v, int size)
    1984 {
    1985     makeContextCurrent();
    1986     glUniform4iv(location, size, v);
    1987 }
    1988 
    1989 void GraphicsContext3D::uniformMatrix2fv(long location, bool transpose, float* value, int size)
    1990 {
    1991     makeContextCurrent();
    1992     glUniformMatrix2fv(location, size, transpose, value);
    1993 }
    1994 
    1995 void GraphicsContext3D::uniformMatrix3fv(long location, bool transpose, float* value, int size)
    1996 {
    1997     makeContextCurrent();
    1998     glUniformMatrix3fv(location, size, transpose, value);
    1999 }
    2000 
    2001 void GraphicsContext3D::uniformMatrix4fv(long location, bool transpose, float* value, int size)
    2002 {
    2003     makeContextCurrent();
    2004     glUniformMatrix4fv(location, size, transpose, value);
    2005 }
    2006 
    2007 GL_SAME_METHOD_1_X(UseProgram, useProgram, WebGLProgram*)
    2008 
    2009 GL_SAME_METHOD_1_X(ValidateProgram, validateProgram, WebGLProgram*)
    2010 
    2011 GL_SAME_METHOD_2(VertexAttrib1f, vertexAttrib1f, unsigned long, float)
    2012 
    2013 void GraphicsContext3D::vertexAttrib1fv(unsigned long indx, float* values)
    2014 {
    2015     makeContextCurrent();
    2016     glVertexAttrib1fv(indx, values);
    2017 }
    2018 
    2019 GL_SAME_METHOD_3(VertexAttrib2f, vertexAttrib2f, unsigned long, float, float)
    2020 
    2021 void GraphicsContext3D::vertexAttrib2fv(unsigned long indx, float* values)
    2022 {
    2023     makeContextCurrent();
    2024     glVertexAttrib2fv(indx, values);
    2025 }
    2026 
    2027 GL_SAME_METHOD_4(VertexAttrib3f, vertexAttrib3f, unsigned long, float, float, float)
    2028 
    2029 void GraphicsContext3D::vertexAttrib3fv(unsigned long indx, float* values)
    2030 {
    2031     makeContextCurrent();
    2032     glVertexAttrib3fv(indx, values);
    2033 }
    2034 
    2035 GL_SAME_METHOD_5(VertexAttrib4f, vertexAttrib4f, unsigned long, float, float, float, float)
    2036 
    2037 void GraphicsContext3D::vertexAttrib4fv(unsigned long indx, float* values)
    2038 {
    2039     makeContextCurrent();
    2040     glVertexAttrib4fv(indx, values);
    2041 }
    2042 
    2043 void 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 
    2049 void 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 }
     1256    return m_internal->texSubImage2D(target, level, xoffset, yoffset,
     1257                                     image->width(), image->height(),
     1258                                     format, UNSIGNED_BYTE, imageData.data());
     1259}
     1260
     1261DELEGATE_TO_INTERNAL_2(uniform1f, long, float)
     1262DELEGATE_TO_INTERNAL_3(uniform1fv, long, float*, int)
     1263DELEGATE_TO_INTERNAL_2(uniform1i, long, int)
     1264DELEGATE_TO_INTERNAL_3(uniform1iv, long, int*, int)
     1265DELEGATE_TO_INTERNAL_3(uniform2f, long, float, float)
     1266DELEGATE_TO_INTERNAL_3(uniform2fv, long, float*, int)
     1267DELEGATE_TO_INTERNAL_3(uniform2i, long, int, int)
     1268DELEGATE_TO_INTERNAL_3(uniform2iv, long, int*, int)
     1269DELEGATE_TO_INTERNAL_4(uniform3f, long, float, float, float)
     1270DELEGATE_TO_INTERNAL_3(uniform3fv, long, float*, int)
     1271DELEGATE_TO_INTERNAL_4(uniform3i, long, int, int, int)
     1272DELEGATE_TO_INTERNAL_3(uniform3iv, long, int*, int)
     1273DELEGATE_TO_INTERNAL_5(uniform4f, long, float, float, float, float)
     1274DELEGATE_TO_INTERNAL_3(uniform4fv, long, float*, int)
     1275DELEGATE_TO_INTERNAL_5(uniform4i, long, int, int, int, int)
     1276DELEGATE_TO_INTERNAL_3(uniform4iv, long, int*, int)
     1277DELEGATE_TO_INTERNAL_4(uniformMatrix2fv, long, bool, float*, int)
     1278DELEGATE_TO_INTERNAL_4(uniformMatrix3fv, long, bool, float*, int)
     1279DELEGATE_TO_INTERNAL_4(uniformMatrix4fv, long, bool, float*, int)
     1280
     1281DELEGATE_TO_INTERNAL_1(useProgram, WebGLProgram*)
     1282DELEGATE_TO_INTERNAL_1(validateProgram, WebGLProgram*)
     1283
     1284DELEGATE_TO_INTERNAL_2(vertexAttrib1f, unsigned long, float)
     1285DELEGATE_TO_INTERNAL_2(vertexAttrib1fv, unsigned long, float*)
     1286DELEGATE_TO_INTERNAL_3(vertexAttrib2f, unsigned long, float, float)
     1287DELEGATE_TO_INTERNAL_2(vertexAttrib2fv, unsigned long, float*)
     1288DELEGATE_TO_INTERNAL_4(vertexAttrib3f, unsigned long, float, float, float)
     1289DELEGATE_TO_INTERNAL_2(vertexAttrib3fv, unsigned long, float*)
     1290DELEGATE_TO_INTERNAL_5(vertexAttrib4f, unsigned long, float, float, float, float)
     1291DELEGATE_TO_INTERNAL_2(vertexAttrib4fv, unsigned long, float*)
     1292DELEGATE_TO_INTERNAL_6(vertexAttribPointer, unsigned long, int, int, bool, unsigned long, unsigned long)
     1293
     1294DELEGATE_TO_INTERNAL_4(viewport, long, long, unsigned long, unsigned long)
     1295
     1296DELEGATE_TO_INTERNAL_1(beginPaint, WebGLRenderingContext*)
     1297DELEGATE_TO_INTERNAL(endPaint)
     1298
     1299DELEGATE_TO_INTERNAL_R(createBuffer, unsigned)
     1300DELEGATE_TO_INTERNAL_R(createFramebuffer, unsigned)
     1301DELEGATE_TO_INTERNAL_R(createProgram, unsigned)
     1302DELEGATE_TO_INTERNAL_R(createRenderbuffer, unsigned)
     1303DELEGATE_TO_INTERNAL_1R(createShader, unsigned long, unsigned)
     1304DELEGATE_TO_INTERNAL_R(createTexture, unsigned)
     1305
     1306DELEGATE_TO_INTERNAL_1(deleteBuffer, unsigned)
     1307DELEGATE_TO_INTERNAL_1(deleteFramebuffer, unsigned)
     1308DELEGATE_TO_INTERNAL_1(deleteProgram, unsigned)
     1309DELEGATE_TO_INTERNAL_1(deleteRenderbuffer, unsigned)
     1310DELEGATE_TO_INTERNAL_1(deleteShader, unsigned)
     1311DELEGATE_TO_INTERNAL_1(deleteTexture, unsigned)
     1312
     1313DELEGATE_TO_INTERNAL_1(synthesizeGLError, unsigned long)
     1314
     1315} // namespace WebCore
    20561316
    20571317#endif // ENABLE(3D_CANVAS)
Note: See TracChangeset for help on using the changeset viewer.