Changeset 64767 in webkit


Ignore:
Timestamp:
Aug 5, 2010 11:33:48 AM (14 years ago)
Author:
kbr@google.com
Message:

2010-08-04 Kenneth Russell <kbr@google.com>

Reviewed by Dimitri Glazkov.

Style cleanups in WebGL
https://bugs.webkit.org/show_bug.cgi?id=38761

Cleaned up all style violations in WebGL-related files reported by
check-webkit-style. No logic or other changes. Built WebKit and
Chromium and ran WebGL layout tests.

  • src/GraphicsContext3D.cpp: (WebCore::GraphicsContext3DInternal::paintRenderingResultsToCanvas):
  • src/WebGraphicsContext3DDefaultImpl.cpp:
  • src/WebGraphicsContext3DDefaultImpl.h:

2010-08-04 Kenneth Russell <kbr@google.com>

Reviewed by Dimitri Glazkov.

Style cleanups in WebGL
https://bugs.webkit.org/show_bug.cgi?id=38761

Cleaned up all style violations in WebGL-related files reported by
check-webkit-style. No logic or other changes. Built WebKit and
Chromium and ran WebGL layout tests.

  • html/canvas/ArrayBuffer.cpp: (WebCore::ArrayBuffer::ArrayBuffer): (WebCore::ArrayBuffer::data): (WebCore::ArrayBuffer::byteLength): (WebCore::ArrayBuffer::~ArrayBuffer): (WebCore::ArrayBuffer::tryAllocate):
  • html/canvas/ArrayBufferView.cpp: (WebCore::ArrayBufferView::setImpl):
  • html/canvas/ArrayBufferView.h:
  • html/canvas/TypedArrayBase.h:
  • html/canvas/WebGLBuffer.cpp: (WebCore::WebGLBuffer::deleteObjectImpl): (WebCore::WebGLBuffer::associateBufferData):
  • html/canvas/WebGLBuffer.h: (WebCore::WebGLBuffer::~WebGLBuffer): (WebCore::WebGLBuffer::elementArrayBuffer): (WebCore::WebGLBuffer::getTarget): (WebCore::WebGLBuffer::isBuffer):
  • html/canvas/WebGLFramebuffer.cpp: (WebCore::WebGLFramebuffer::deleteObjectImpl):
  • html/canvas/WebGLFramebuffer.h: (WebCore::WebGLFramebuffer::~WebGLFramebuffer): (WebCore::WebGLFramebuffer::isDepthAttached): (WebCore::WebGLFramebuffer::isStencilAttached): (WebCore::WebGLFramebuffer::isDepthStencilAttached): (WebCore::WebGLFramebuffer::isFramebuffer):
  • html/canvas/WebGLGetInfo.cpp:
  • html/canvas/WebGLGetInfo.h:
  • html/canvas/WebGLObject.cpp: (WebCore::WebGLObject::deleteObject):
  • html/canvas/WebGLObject.h: (WebCore::WebGLObject::object): (WebCore::WebGLObject::detachContext): (WebCore::WebGLObject::context): (WebCore::WebGLObject::isBuffer): (WebCore::WebGLObject::isFramebuffer): (WebCore::WebGLObject::isProgram): (WebCore::WebGLObject::isRenderbuffer): (WebCore::WebGLObject::isShader): (WebCore::WebGLObject::isTexture):
  • html/canvas/WebGLProgram.cpp: (WebCore::WebGLProgram::deleteObjectImpl):
  • html/canvas/WebGLProgram.h: (WebCore::WebGLProgram::~WebGLProgram): (WebCore::WebGLProgram::isLinkFailureFlagSet): (WebCore::WebGLProgram::setLinkFailureFlag): (WebCore::WebGLProgram::isProgram):
  • html/canvas/WebGLRenderbuffer.cpp: (WebCore::WebGLRenderbuffer::deleteObjectImpl):
  • html/canvas/WebGLRenderbuffer.h: (WebCore::WebGLRenderbuffer::~WebGLRenderbuffer): (WebCore::WebGLRenderbuffer::setInternalFormat): (WebCore::WebGLRenderbuffer::getInternalFormat): (WebCore::WebGLRenderbuffer::isInitialized): (WebCore::WebGLRenderbuffer::setInitialized): (WebCore::WebGLRenderbuffer::isRenderbuffer):
  • html/canvas/WebGLRenderingContext.cpp: (WebCore::WebGLRenderingContext::beginPaint): (WebCore::WebGLRenderingContext::blendEquation): (WebCore::WebGLRenderingContext::getActiveAttrib): (WebCore::WebGLRenderingContext::getActiveUniform): (WebCore::WebGLRenderingContext::getBufferParameter): (WebCore::WebGLRenderingContext::getFramebufferAttachmentParameter): (WebCore::WebGLRenderingContext::vertexAttribPointer):
  • html/canvas/WebGLRenderingContext.h: (WebCore::WebGLRenderingContext::is3d): (WebCore::WebGLRenderingContext::isAccelerated): (WebCore::WebGLRenderingContext::graphicsContext3D): (WebCore::WebGLRenderingContext::cleanupAfterGraphicsCall): (WebCore::WebGLRenderingContext::VertexAttribState::VertexAttribState): (WebCore::WebGLRenderingContext::VertexAttribState::initValue):
  • html/canvas/WebGLShader.cpp: (WebCore::WebGLShader::deleteObjectImpl):
  • html/canvas/WebGLShader.h: (WebCore::WebGLShader::~WebGLShader): (WebCore::WebGLShader::getType): (WebCore::WebGLShader::isShader):
  • html/canvas/WebGLTexture.cpp: (WebCore::WebGLTexture::deleteObjectImpl):
  • html/canvas/WebGLTexture.h: (WebCore::WebGLTexture::~WebGLTexture): (WebCore::WebGLTexture::isCubeMapRWrapModeInitialized): (WebCore::WebGLTexture::setCubeMapRWrapModeInitialized): (WebCore::WebGLTexture::isTexture): (WebCore::WebGLTexture::LevelInfo::LevelInfo): (WebCore::WebGLTexture::LevelInfo::setInfo):
  • platform/graphics/GraphicsContext3D.h: (WebCore::GraphicsContext3D::): (WebCore::GraphicsContext3D::Attributes::Attributes): (WebCore::GraphicsContext3D::platformGraphicsContext3D): (WebCore::GraphicsContext3D::platformTexture): (WebCore::GraphicsContext3D::platformLayer):
Location:
trunk
Files:
28 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r64764 r64767  
     12010-08-04  Kenneth Russell  <kbr@google.com>
     2
     3        Reviewed by Dimitri Glazkov.
     4
     5        Style cleanups in WebGL
     6        https://bugs.webkit.org/show_bug.cgi?id=38761
     7
     8        Cleaned up all style violations in WebGL-related files reported by
     9        check-webkit-style. No logic or other changes. Built WebKit and
     10        Chromium and ran WebGL layout tests.
     11
     12        * html/canvas/ArrayBuffer.cpp:
     13        (WebCore::ArrayBuffer::ArrayBuffer):
     14        (WebCore::ArrayBuffer::data):
     15        (WebCore::ArrayBuffer::byteLength):
     16        (WebCore::ArrayBuffer::~ArrayBuffer):
     17        (WebCore::ArrayBuffer::tryAllocate):
     18        * html/canvas/ArrayBufferView.cpp:
     19        (WebCore::ArrayBufferView::setImpl):
     20        * html/canvas/ArrayBufferView.h:
     21        * html/canvas/TypedArrayBase.h:
     22        * html/canvas/WebGLBuffer.cpp:
     23        (WebCore::WebGLBuffer::deleteObjectImpl):
     24        (WebCore::WebGLBuffer::associateBufferData):
     25        * html/canvas/WebGLBuffer.h:
     26        (WebCore::WebGLBuffer::~WebGLBuffer):
     27        (WebCore::WebGLBuffer::elementArrayBuffer):
     28        (WebCore::WebGLBuffer::getTarget):
     29        (WebCore::WebGLBuffer::isBuffer):
     30        * html/canvas/WebGLFramebuffer.cpp:
     31        (WebCore::WebGLFramebuffer::deleteObjectImpl):
     32        * html/canvas/WebGLFramebuffer.h:
     33        (WebCore::WebGLFramebuffer::~WebGLFramebuffer):
     34        (WebCore::WebGLFramebuffer::isDepthAttached):
     35        (WebCore::WebGLFramebuffer::isStencilAttached):
     36        (WebCore::WebGLFramebuffer::isDepthStencilAttached):
     37        (WebCore::WebGLFramebuffer::isFramebuffer):
     38        * html/canvas/WebGLGetInfo.cpp:
     39        * html/canvas/WebGLGetInfo.h:
     40        * html/canvas/WebGLObject.cpp:
     41        (WebCore::WebGLObject::deleteObject):
     42        * html/canvas/WebGLObject.h:
     43        (WebCore::WebGLObject::object):
     44        (WebCore::WebGLObject::detachContext):
     45        (WebCore::WebGLObject::context):
     46        (WebCore::WebGLObject::isBuffer):
     47        (WebCore::WebGLObject::isFramebuffer):
     48        (WebCore::WebGLObject::isProgram):
     49        (WebCore::WebGLObject::isRenderbuffer):
     50        (WebCore::WebGLObject::isShader):
     51        (WebCore::WebGLObject::isTexture):
     52        * html/canvas/WebGLProgram.cpp:
     53        (WebCore::WebGLProgram::deleteObjectImpl):
     54        * html/canvas/WebGLProgram.h:
     55        (WebCore::WebGLProgram::~WebGLProgram):
     56        (WebCore::WebGLProgram::isLinkFailureFlagSet):
     57        (WebCore::WebGLProgram::setLinkFailureFlag):
     58        (WebCore::WebGLProgram::isProgram):
     59        * html/canvas/WebGLRenderbuffer.cpp:
     60        (WebCore::WebGLRenderbuffer::deleteObjectImpl):
     61        * html/canvas/WebGLRenderbuffer.h:
     62        (WebCore::WebGLRenderbuffer::~WebGLRenderbuffer):
     63        (WebCore::WebGLRenderbuffer::setInternalFormat):
     64        (WebCore::WebGLRenderbuffer::getInternalFormat):
     65        (WebCore::WebGLRenderbuffer::isInitialized):
     66        (WebCore::WebGLRenderbuffer::setInitialized):
     67        (WebCore::WebGLRenderbuffer::isRenderbuffer):
     68        * html/canvas/WebGLRenderingContext.cpp:
     69        (WebCore::WebGLRenderingContext::beginPaint):
     70        (WebCore::WebGLRenderingContext::blendEquation):
     71        (WebCore::WebGLRenderingContext::getActiveAttrib):
     72        (WebCore::WebGLRenderingContext::getActiveUniform):
     73        (WebCore::WebGLRenderingContext::getBufferParameter):
     74        (WebCore::WebGLRenderingContext::getFramebufferAttachmentParameter):
     75        (WebCore::WebGLRenderingContext::vertexAttribPointer):
     76        * html/canvas/WebGLRenderingContext.h:
     77        (WebCore::WebGLRenderingContext::is3d):
     78        (WebCore::WebGLRenderingContext::isAccelerated):
     79        (WebCore::WebGLRenderingContext::graphicsContext3D):
     80        (WebCore::WebGLRenderingContext::cleanupAfterGraphicsCall):
     81        (WebCore::WebGLRenderingContext::VertexAttribState::VertexAttribState):
     82        (WebCore::WebGLRenderingContext::VertexAttribState::initValue):
     83        * html/canvas/WebGLShader.cpp:
     84        (WebCore::WebGLShader::deleteObjectImpl):
     85        * html/canvas/WebGLShader.h:
     86        (WebCore::WebGLShader::~WebGLShader):
     87        (WebCore::WebGLShader::getType):
     88        (WebCore::WebGLShader::isShader):
     89        * html/canvas/WebGLTexture.cpp:
     90        (WebCore::WebGLTexture::deleteObjectImpl):
     91        * html/canvas/WebGLTexture.h:
     92        (WebCore::WebGLTexture::~WebGLTexture):
     93        (WebCore::WebGLTexture::isCubeMapRWrapModeInitialized):
     94        (WebCore::WebGLTexture::setCubeMapRWrapModeInitialized):
     95        (WebCore::WebGLTexture::isTexture):
     96        (WebCore::WebGLTexture::LevelInfo::LevelInfo):
     97        (WebCore::WebGLTexture::LevelInfo::setInfo):
     98        * platform/graphics/GraphicsContext3D.h:
     99        (WebCore::GraphicsContext3D::):
     100        (WebCore::GraphicsContext3D::Attributes::Attributes):
     101        (WebCore::GraphicsContext3D::platformGraphicsContext3D):
     102        (WebCore::GraphicsContext3D::platformTexture):
     103        (WebCore::GraphicsContext3D::platformLayer):
     104
    11052010-08-05  Kenneth Rohde Christiansen  <kenneth.christiansen@openbossa.org>
    2106
  • trunk/WebCore/html/canvas/ArrayBuffer.cpp

    r59499 r64767  
    5454ArrayBuffer::ArrayBuffer(void* data, unsigned sizeInBytes)
    5555    : m_sizeInBytes(sizeInBytes)
    56     , m_data(data) {
     56    , m_data(data)
     57{
    5758}
    5859
    59 void* ArrayBuffer::data() {
     60void* ArrayBuffer::data()
     61{
    6062    return m_data;
    6163}
    6264
    63 const void* ArrayBuffer::data() const {
     65const void* ArrayBuffer::data() const
     66{
    6467    return m_data;
    6568}
    6669
    67 unsigned ArrayBuffer::byteLength() const {
     70unsigned ArrayBuffer::byteLength() const
     71{
    6872    return m_sizeInBytes;
    6973}
    7074
    71 ArrayBuffer::~ArrayBuffer() {
     75ArrayBuffer::~ArrayBuffer()
     76{
    7277    WTF::fastFree(m_data);
    7378}
    7479
    75 void* ArrayBuffer::tryAllocate(unsigned numElements, unsigned elementByteSize) {
     80void* ArrayBuffer::tryAllocate(unsigned numElements, unsigned elementByteSize)
     81{
    7682    void* result;
    7783    // Do not allow 32-bit overflow of the total size
  • trunk/WebCore/html/canvas/ArrayBufferView.cpp

    r59499 r64767  
    2929
    3030#include "ArrayBufferView.h"
     31
    3132#include "ArrayBuffer.h"
    3233
     
    4748void ArrayBufferView::setImpl(ArrayBufferView* array, unsigned byteOffset, ExceptionCode& ec)
    4849{
    49     if (byteOffset > byteLength() ||
    50         byteOffset + array->byteLength() > byteLength() ||
    51         byteOffset + array->byteLength() < byteOffset) {
     50    if (byteOffset > byteLength()
     51        || byteOffset + array->byteLength() > byteLength()
     52        || byteOffset + array->byteLength() < byteOffset) {
    5253        // Out of range offset or overflow
    5354        ec = INDEX_SIZE_ERR;
  • trunk/WebCore/html/canvas/ArrayBufferView.h

    r59499 r64767  
    2727#define ArrayBufferView_h
    2828
     29#include "ArrayBuffer.h"
     30#include "ExceptionCode.h"
     31
    2932#include <algorithm>
    30 #include "ExceptionCode.h"
    3133#include <limits.h>
    3234#include <wtf/PassRefPtr.h>
    3335#include <wtf/RefCounted.h>
    3436#include <wtf/RefPtr.h>
    35 #include "ArrayBuffer.h"
    3637
    3738namespace WebCore {
  • trunk/WebCore/html/canvas/TypedArrayBase.h

    r61339 r64767  
    2828#define TypedArrayBase_h
    2929
     30#include "ArrayBuffer.h"
    3031#include "ArrayBufferView.h"
    31 #include "ArrayBuffer.h"
    3232
    3333namespace WebCore {
  • trunk/WebCore/html/canvas/WebGLBuffer.cpp

    r64685 r64767  
    2929
    3030#include "WebGLBuffer.h"
     31
    3132#include "WebGLRenderingContext.h"
    3233
     
    4849}
    4950
    50 void WebGLBuffer::_deleteObject(Platform3DObject object)
     51void WebGLBuffer::deleteObjectImpl(Platform3DObject object)
    5152{
    5253    context()->graphicsContext3D()->deleteBuffer(object);
     
    6768        }
    6869        return true;
    69     } else if (m_target == GraphicsContext3D::ARRAY_BUFFER) {
     70    }
     71
     72    if (m_target == GraphicsContext3D::ARRAY_BUFFER) {
    7073        m_byteLength = size;
    7174        return true;
  • trunk/WebCore/html/canvas/WebGLBuffer.h

    r64685 r64767  
    2727#define WebGLBuffer_h
    2828
     29#include "ArrayBuffer.h"
    2930#include "WebGLObject.h"
    30 #include "ArrayBuffer.h"
    3131
    3232#include <wtf/PassRefPtr.h>
     
    3434
    3535namespace WebCore {
    36    
    37     class WebGLBuffer : public WebGLObject {
    38     public:
    39         virtual ~WebGLBuffer() { deleteObject(); }
    40        
    41         static PassRefPtr<WebGLBuffer> create(WebGLRenderingContext*);
    4236
    43         bool associateBufferData(int size);
    44         bool associateBufferData(ArrayBuffer* array);
    45         bool associateBufferData(ArrayBufferView* array);
    46         bool associateBufferSubData(long offset, ArrayBuffer* array);
    47         bool associateBufferSubData(long offset, ArrayBufferView* array);
    48        
    49         unsigned byteLength() const;
    50         const ArrayBuffer* elementArrayBuffer() const { return m_elementArrayBuffer.get(); }
    51                        
    52         // Gets the cached max index for the given type. Returns -1 if
    53         // none has been set.
    54         long getCachedMaxIndex(unsigned long type);
    55         // Sets the cached max index for the given type.
    56         void setCachedMaxIndex(unsigned long type, long value);
     37class WebGLBuffer : public WebGLObject {
     38public:
     39    virtual ~WebGLBuffer() { deleteObject(); }
    5740
    58         unsigned long getTarget() const { return m_target; }
    59         void setTarget(unsigned long);
     41    static PassRefPtr<WebGLBuffer> create(WebGLRenderingContext*);
    6042
    61     protected:
    62         WebGLBuffer(WebGLRenderingContext*);
     43    bool associateBufferData(int size);
     44    bool associateBufferData(ArrayBuffer* array);
     45    bool associateBufferData(ArrayBufferView* array);
     46    bool associateBufferSubData(long offset, ArrayBuffer* array);
     47    bool associateBufferSubData(long offset, ArrayBufferView* array);
    6348
    64         virtual void _deleteObject(Platform3DObject o);
    65    
    66     private:
    67         virtual bool isBuffer() const { return true; }
     49    unsigned byteLength() const;
     50    const ArrayBuffer* elementArrayBuffer() const { return m_elementArrayBuffer.get(); }
    6851
    69         unsigned long m_target;
     52    // Gets the cached max index for the given type. Returns -1 if
     53    // none has been set.
     54    long getCachedMaxIndex(unsigned long type);
     55    // Sets the cached max index for the given type.
     56    void setCachedMaxIndex(unsigned long type, long value);
    7057
    71         RefPtr<ArrayBuffer> m_elementArrayBuffer;
    72         unsigned m_byteLength;
     58    unsigned long getTarget() const { return m_target; }
     59    void setTarget(unsigned long);
    7360
    74         // Optimization for index validation. For each type of index
    75         // (i.e., UNSIGNED_SHORT), cache the maximum index in the
    76         // entire buffer.
    77         //
    78         // This is sufficient to eliminate a lot of work upon each
    79         // draw call as long as all bound array buffers are at least
    80         // that size.
    81         struct MaxIndexCacheEntry {
    82             unsigned long type;
    83             long maxIndex;
    84         };
    85         // OpenGL ES 2.0 only has two valid index types (UNSIGNED_BYTE
    86         // and UNSIGNED_SHORT), but might as well leave open the
    87         // possibility of adding others.
    88         MaxIndexCacheEntry m_maxIndexCache[4];
    89         unsigned m_nextAvailableCacheEntry;
     61protected:
     62    WebGLBuffer(WebGLRenderingContext*);
    9063
    91         // Clears all of the cached max indices.
    92         void clearCachedMaxIndices();
     64    virtual void deleteObjectImpl(Platform3DObject o);
     65
     66private:
     67    virtual bool isBuffer() const { return true; }
     68
     69    unsigned long m_target;
     70
     71    RefPtr<ArrayBuffer> m_elementArrayBuffer;
     72    unsigned m_byteLength;
     73
     74    // Optimization for index validation. For each type of index
     75    // (i.e., UNSIGNED_SHORT), cache the maximum index in the
     76    // entire buffer.
     77    //
     78    // This is sufficient to eliminate a lot of work upon each
     79    // draw call as long as all bound array buffers are at least
     80    // that size.
     81    struct MaxIndexCacheEntry {
     82        unsigned long type;
     83        long maxIndex;
    9384    };
    94    
     85    // OpenGL ES 2.0 only has two valid index types (UNSIGNED_BYTE
     86    // and UNSIGNED_SHORT), but might as well leave open the
     87    // possibility of adding others.
     88    MaxIndexCacheEntry m_maxIndexCache[4];
     89    unsigned m_nextAvailableCacheEntry;
     90
     91    // Clears all of the cached max indices.
     92    void clearCachedMaxIndices();
     93};
     94
    9595} // namespace WebCore
    9696
  • trunk/WebCore/html/canvas/WebGLFramebuffer.cpp

    r64685 r64767  
    2929
    3030#include "WebGLFramebuffer.h"
     31
    3132#include "WebGLRenderingContext.h"
    3233
     
    106107}
    107108
    108 void WebGLFramebuffer::_deleteObject(Platform3DObject object)
     109void WebGLFramebuffer::deleteObjectImpl(Platform3DObject object)
    109110{
    110111    context()->graphicsContext3D()->deleteFramebuffer(object);
  • trunk/WebCore/html/canvas/WebGLFramebuffer.h

    r64685 r64767  
    3434namespace WebCore {
    3535
    36     class WebGLFramebuffer : public WebGLObject {
    37     public:
    38         virtual ~WebGLFramebuffer() { deleteObject(); }
    39        
    40         static PassRefPtr<WebGLFramebuffer> create(WebGLRenderingContext*);
     36class WebGLFramebuffer : public WebGLObject {
     37public:
     38    virtual ~WebGLFramebuffer() { deleteObject(); }
    4139
    42         bool isDepthAttached() const { return (m_depthAttachment && m_depthAttachment->object()); }
    43         bool isStencilAttached() const { return (m_stencilAttachment && m_stencilAttachment->object()); }
    44         bool isDepthStencilAttached() const { return (m_depthStencilAttachment && m_depthStencilAttachment->object()); }
     40    static PassRefPtr<WebGLFramebuffer> create(WebGLRenderingContext*);
    4541
    46         void setAttachment(unsigned long, WebGLObject*);
     42    bool isDepthAttached() const { return (m_depthAttachment && m_depthAttachment->object()); }
     43    bool isStencilAttached() const { return (m_stencilAttachment && m_stencilAttachment->object()); }
     44    bool isDepthStencilAttached() const { return (m_depthStencilAttachment && m_depthStencilAttachment->object()); }
    4745
    48         // This function is called right after a framebuffer is bound.
    49         // Because renderbuffers and textures attached to the framebuffer might
    50         // have changed and the framebuffer might have become complete when it
    51         // isn't bound, so we need to clear un-initialized renderbuffers.
    52         void onBind();
     46    void setAttachment(unsigned long, WebGLObject*);
    5347
    54         // When a texture or a renderbuffer changes, we need to check the
    55         // current bound framebuffer; if the newly changed object is attached
    56         // to the framebuffer and the framebuffer becomes complete, we need to
    57         // clear un-initialized renderbuffers.
    58         void onAttachedObjectChange(WebGLObject*);
     48    // This function is called right after a framebuffer is bound.
     49    // Because renderbuffers and textures attached to the framebuffer might
     50    // have changed and the framebuffer might have become complete when it
     51    // isn't bound, so we need to clear un-initialized renderbuffers.
     52    void onBind();
    5953
    60         unsigned long getColorBufferFormat();
     54    // When a texture or a renderbuffer changes, we need to check the
     55    // current bound framebuffer; if the newly changed object is attached
     56    // to the framebuffer and the framebuffer becomes complete, we need to
     57    // clear un-initialized renderbuffers.
     58    void onAttachedObjectChange(WebGLObject*);
    6159
    62     protected:
    63         WebGLFramebuffer(WebGLRenderingContext*);
    64        
    65         virtual void _deleteObject(Platform3DObject);
     60    unsigned long getColorBufferFormat();
    6661
    67     private:
    68         virtual bool isFramebuffer() const { return true; }
     62protected:
     63    WebGLFramebuffer(WebGLRenderingContext*);
    6964
    70         bool isUninitialized(WebGLObject*);
    71         void setInitialized(WebGLObject*);
    72         void initializeRenderbuffers();
     65    virtual void deleteObjectImpl(Platform3DObject);
    7366
    74         // These objects are kept alive by the global table in
    75         // WebGLRenderingContext.
    76         WebGLObject* m_colorAttachment;
    77         WebGLObject* m_depthAttachment;
    78         WebGLObject* m_stencilAttachment;
    79         WebGLObject* m_depthStencilAttachment;
    80     };
    81    
     67private:
     68    virtual bool isFramebuffer() const { return true; }
     69
     70    bool isUninitialized(WebGLObject*);
     71    void setInitialized(WebGLObject*);
     72    void initializeRenderbuffers();
     73
     74    // These objects are kept alive by the global table in
     75    // WebGLRenderingContext.
     76    WebGLObject* m_colorAttachment;
     77    WebGLObject* m_depthAttachment;
     78    WebGLObject* m_stencilAttachment;
     79    WebGLObject* m_depthStencilAttachment;
     80};
     81
    8282} // namespace WebCore
    8383
  • trunk/WebCore/html/canvas/WebGLGetInfo.cpp

    r61910 r64767  
    3030
    3131#include "WebGLGetInfo.h"
     32
     33#include "Float32Array.h"
     34#include "Int32Array.h"
     35#include "Uint8Array.h"
    3236#include "WebGLBuffer.h"
    33 #include "Float32Array.h"
    3437#include "WebGLFramebuffer.h"
    35 #include "Int32Array.h"
    3638#include "WebGLProgram.h"
    3739#include "WebGLRenderbuffer.h"
    3840#include "WebGLTexture.h"
    39 #include "Uint8Array.h"
    4041
    4142namespace WebCore {
  • trunk/WebCore/html/canvas/WebGLGetInfo.h

    r61910 r64767  
    2828#define WebGLGetInfo_h
    2929
    30 #include "wtf/PassRefPtr.h"
    31 #include "wtf/RefPtr.h"
     30#include "Float32Array.h"
     31#include "Int32Array.h"
    3232#include "PlatformString.h"
    33 
     33#include "Uint8Array.h"
    3434#include "WebGLBuffer.h"
    35 #include "Float32Array.h"
    3635#include "WebGLFramebuffer.h"
    37 #include "Int32Array.h"
    38 // FIXME: implement WebGLObjectArray
    39 //#include "WebGLObjectArray.h"
    4036#include "WebGLProgram.h"
    4137#include "WebGLRenderbuffer.h"
    4238#include "WebGLTexture.h"
    43 #include "Uint8Array.h"
     39
     40#include <wtf/PassRefPtr.h>
     41#include <wtf/RefPtr.h>
    4442
    4543namespace WebCore {
     
    7573    WebGLGetInfo(float value);
    7674    WebGLGetInfo(long value);
    77     // Represents the NULL value and type
     75    // Represents the null value and type.
    7876    WebGLGetInfo();
    7977    WebGLGetInfo(const String& value);
     
    133131} // namespace WebCore
    134132
    135 #endif  // WebGLGetInfo_h
     133#endif // WebGLGetInfo_h
  • trunk/WebCore/html/canvas/WebGLObject.cpp

    r64685 r64767  
    2929
    3030#include "WebGLObject.h"
     31
    3132#include "WebGLRenderingContext.h"
    3233
     
    6263            if (m_context) {
    6364                m_context->graphicsContext3D()->makeContextCurrent();
    64                 _deleteObject(m_object);
     65                deleteObjectImpl(m_object);
    6566            }
    6667        m_object = 0;
  • trunk/WebCore/html/canvas/WebGLObject.h

    r64685 r64767  
    2727#define WebGLObject_h
    2828
     29#include "GraphicsContext3D.h"
     30
    2931#include <wtf/PassRefPtr.h>
    3032#include <wtf/RefCounted.h>
    3133
    32 #include "GraphicsContext3D.h"
    33 
    3434namespace WebCore {
    3535
    36     class WebGLRenderingContext;
    37    
    38     class WebGLObject : public RefCounted<WebGLObject> {
    39     public:
    40         virtual ~WebGLObject();
    41        
    42         Platform3DObject object() const { return m_object; }
    43         void setObject(Platform3DObject, bool shouldDeleteObject = true);
    44         void deleteObject();
    45        
    46         void detachContext()
    47         {
    48             deleteObject();
    49             m_context = 0;
    50         }
     36class WebGLRenderingContext;
    5137
    52         WebGLRenderingContext* context() const { return m_context; }
     38class WebGLObject : public RefCounted<WebGLObject> {
     39public:
     40    virtual ~WebGLObject();
    5341
    54         virtual bool isBuffer() const { return false; }
    55         virtual bool isFramebuffer() const { return false; }
    56         virtual bool isProgram() const { return false; }
    57         virtual bool isRenderbuffer() const { return false; }
    58         virtual bool isShader() const { return false; }
    59         virtual bool isTexture() const { return false; }
     42    Platform3DObject object() const { return m_object; }
     43    void setObject(Platform3DObject, bool shouldDeleteObject = true);
     44    void deleteObject();
    6045
    61     protected:
    62         WebGLObject(WebGLRenderingContext*);
    63         virtual void _deleteObject(Platform3DObject) = 0;
    64    
    65     private:
    66         Platform3DObject m_object;
    67         // The shouldDeleteObject flag indicates whether this wrapper
    68         // owns the underlying resource and should delete it when the
    69         // wrapper is unreferenced for the last time and deleted. It
    70         // is only set to false for certain objects returned from get
    71         // queries. FIXME: should consider canonicalizing all of these
    72         // objects in the future.
    73         bool m_shouldDeleteObject;
    74         WebGLRenderingContext* m_context;
    75     };
    76    
     46    void detachContext()
     47    {
     48        deleteObject();
     49        m_context = 0;
     50    }
     51
     52    WebGLRenderingContext* context() const { return m_context; }
     53
     54    virtual bool isBuffer() const { return false; }
     55    virtual bool isFramebuffer() const { return false; }
     56    virtual bool isProgram() const { return false; }
     57    virtual bool isRenderbuffer() const { return false; }
     58    virtual bool isShader() const { return false; }
     59    virtual bool isTexture() const { return false; }
     60
     61protected:
     62    WebGLObject(WebGLRenderingContext*);
     63    virtual void deleteObjectImpl(Platform3DObject) = 0;
     64
     65private:
     66    Platform3DObject m_object;
     67    // The shouldDeleteObject flag indicates whether this wrapper
     68    // owns the underlying resource and should delete it when the
     69    // wrapper is unreferenced for the last time and deleted. It
     70    // is only set to false for certain objects returned from get
     71    // queries. FIXME: should consider canonicalizing all of these
     72    // objects in the future.
     73    bool m_shouldDeleteObject;
     74    WebGLRenderingContext* m_context;
     75};
     76
    7777} // namespace WebCore
    7878
  • trunk/WebCore/html/canvas/WebGLProgram.cpp

    r64685 r64767  
    2929
    3030#include "WebGLProgram.h"
     31
    3132#include "WebGLRenderingContext.h"
    3233
     
    4546}
    4647
    47 void WebGLProgram::_deleteObject(Platform3DObject object)
     48void WebGLProgram::deleteObjectImpl(Platform3DObject object)
    4849{
    4950    context()->graphicsContext3D()->deleteProgram(object);
  • trunk/WebCore/html/canvas/WebGLProgram.h

    r64685 r64767  
    3434
    3535namespace WebCore {
    36    
    37     class WebGLProgram : public WebGLObject {
    38     public:
    39         virtual ~WebGLProgram() { deleteObject(); }
    40        
    41         static PassRefPtr<WebGLProgram> create(WebGLRenderingContext*);
    4236
    43         // cacheActiveAttribLocation() is only called once after linkProgram()
    44         // succeeds.
    45         bool cacheActiveAttribLocations();
    46         int numActiveAttribLocations() const;
    47         int getActiveAttribLocation(int index) const;
     37class WebGLProgram : public WebGLObject {
     38public:
     39    virtual ~WebGLProgram() { deleteObject(); }
    4840
    49         bool isUsingVertexAttrib0() const;
     41    static PassRefPtr<WebGLProgram> create(WebGLRenderingContext*);
    5042
    51         // Return true means getProgramParameter(LINK_STATUS) should return
    52         // false; return false means we should actually call
    53         // getProgramParameter(LINK_STATUS) to find out.
    54         bool isLinkFailureFlagSet() const { return m_linkFailure; }
    55         void setLinkFailureFlag(bool failed) { m_linkFailure = failed; }
     43    // cacheActiveAttribLocation() is only called once after linkProgram()
     44    // succeeds.
     45    bool cacheActiveAttribLocations();
     46    int numActiveAttribLocations() const;
     47    int getActiveAttribLocation(int index) const;
    5648
    57     protected:
    58         WebGLProgram(WebGLRenderingContext*);
    59        
    60         virtual void _deleteObject(Platform3DObject);
     49    bool isUsingVertexAttrib0() const;
    6150
    62     private:
    63         virtual bool isProgram() const { return true; }
     51    // Return true means getProgramParameter(LINK_STATUS) should return
     52    // false; return false means we should actually call
     53    // getProgramParameter(LINK_STATUS) to find out.
     54    bool isLinkFailureFlagSet() const { return m_linkFailure; }
     55    void setLinkFailureFlag(bool failed) { m_linkFailure = failed; }
    6456
    65         Vector<int> m_activeAttribLocations;
     57protected:
     58    WebGLProgram(WebGLRenderingContext*);
    6659
    67         bool m_linkFailure;
    68     };
    69    
     60    virtual void deleteObjectImpl(Platform3DObject);
     61
     62private:
     63    virtual bool isProgram() const { return true; }
     64
     65    Vector<int> m_activeAttribLocations;
     66
     67    bool m_linkFailure;
     68};
     69
    7070} // namespace WebCore
    7171
  • trunk/WebCore/html/canvas/WebGLRenderbuffer.cpp

    r64685 r64767  
    2929
    3030#include "WebGLRenderbuffer.h"
     31
    3132#include "WebGLRenderingContext.h"
    3233
     
    4647}
    4748
    48 void WebGLRenderbuffer::_deleteObject(Platform3DObject object)
     49void WebGLRenderbuffer::deleteObjectImpl(Platform3DObject object)
    4950{
    5051    context()->graphicsContext3D()->deleteRenderbuffer(object);
  • trunk/WebCore/html/canvas/WebGLRenderbuffer.h

    r64685 r64767  
    3333
    3434namespace WebCore {
    35    
    36     class WebGLRenderbuffer : public WebGLObject {
    37     public:
    38         virtual ~WebGLRenderbuffer() { deleteObject(); }
    39        
    40         static PassRefPtr<WebGLRenderbuffer> create(WebGLRenderingContext*);
    4135
    42         void setInternalFormat(unsigned long internalformat) { m_internalFormat = internalformat; }
    43         unsigned long getInternalFormat() const { return m_internalFormat; }
     36class WebGLRenderbuffer : public WebGLObject {
     37public:
     38    virtual ~WebGLRenderbuffer() { deleteObject(); }
    4439
    45         bool isInitialized() const { return m_initialized; }
    46         void setInitialized() { m_initialized = true; }
     40    static PassRefPtr<WebGLRenderbuffer> create(WebGLRenderingContext*);
    4741
    48     protected:
    49         WebGLRenderbuffer(WebGLRenderingContext*);
    50        
    51         virtual void _deleteObject(Platform3DObject);
     42    void setInternalFormat(unsigned long internalformat) { m_internalFormat = internalformat; }
     43    unsigned long getInternalFormat() const { return m_internalFormat; }
    5244
    53     private:
    54         virtual bool isRenderbuffer() const { return true; }
     45    bool isInitialized() const { return m_initialized; }
     46    void setInitialized() { m_initialized = true; }
    5547
    56         unsigned long m_internalFormat;
    57         bool m_initialized;
    58     };
    59    
     48protected:
     49    WebGLRenderbuffer(WebGLRenderingContext*);
     50
     51    virtual void deleteObjectImpl(Platform3DObject);
     52
     53private:
     54    virtual bool isRenderbuffer() const { return true; }
     55
     56    unsigned long m_internalFormat;
     57    bool m_initialized;
     58};
     59
    6060} // namespace WebCore
    6161
  • trunk/WebCore/html/canvas/WebGLRenderingContext.cpp

    r64685 r64767  
    3030#include "WebGLRenderingContext.h"
    3131
     32#include "CanvasPixelArray.h"
    3233#include "CheckedInt.h"
    33 #include "CanvasPixelArray.h"
    3434#include "Console.h"
    3535#include "DOMWindow.h"
     
    4242#include "RenderBox.h"
    4343#include "RenderLayer.h"
     44#include "Uint16Array.h"
    4445#include "WebGLActiveInfo.h"
    45 #include "Uint16Array.h"
    4646#include "WebGLBuffer.h"
    4747#include "WebGLContextAttributes.h"
     
    4949#include "WebGLProgram.h"
    5050#include "WebGLRenderbuffer.h"
     51#include "WebGLShader.h"
    5152#include "WebGLTexture.h"
    52 #include "WebGLShader.h"
    5353#include "WebGLUniformLocation.h"
    5454
     
    172172void WebGLRenderingContext::beginPaint()
    173173{
    174     if (m_markedCanvasDirty) {
     174    if (m_markedCanvasDirty)
    175175        m_context->beginPaint(this);
    176     }
    177176}
    178177
     
    351350}
    352351
    353 void WebGLRenderingContext::blendEquation( unsigned long mode )
     352void WebGLRenderingContext::blendEquation(unsigned long mode)
    354353{
    355354    if (!isGLES2Compliant()) {
     
    11441143    if (!validateWebGLObject(program))
    11451144        return 0;
    1146     if (!m_context->getActiveAttrib(objectOrZero(program), index, info)) {
     1145    if (!m_context->getActiveAttrib(objectOrZero(program), index, info))
    11471146        return 0;
    1148     }
    11491147    return WebGLActiveInfo::create(info.name, info.type, info.size);
    11501148}
     
    11561154    if (!validateWebGLObject(program))
    11571155        return 0;
    1158     if (!m_context->getActiveUniform(objectOrZero(program), index, info)) {
     1156    if (!m_context->getActiveUniform(objectOrZero(program), index, info))
    11591157        return 0;
    1160     }
    1161     if (!isGLES2Compliant()) {
     1158    if (!isGLES2Compliant())
    11621159        if (info.size > 1 && !info.name.endsWith("[0]"))
    11631160            info.name.append("[0]");
    1164     }
    11651161    return WebGLActiveInfo::create(info.name, info.type, info.size);
    11661162}
     
    12161212    if (pname == GraphicsContext3D::BUFFER_SIZE)
    12171213        return WebGLGetInfo(static_cast<long>(value));
    1218     else
    1219         return WebGLGetInfo(static_cast<unsigned long>(value));
     1214    return WebGLGetInfo(static_cast<unsigned long>(value));
    12201215}
    12211216
     
    12591254        if (pname == GraphicsContext3D::FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)
    12601255            return WebGLGetInfo(static_cast<unsigned long>(value));
    1261         else
    1262             return WebGLGetInfo(static_cast<long>(value));
    1263     } else {
    1264         WebGLStateRestorer(this, false);
    1265         int type = 0;
    1266         m_context->getFramebufferAttachmentParameteriv(target, attachment, GraphicsContext3D::FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &type);
    1267         int value = 0;
    1268         m_context->getFramebufferAttachmentParameteriv(target, attachment, GraphicsContext3D::FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &value);
    1269         switch (type) {
    1270         case GraphicsContext3D::RENDERBUFFER:
    1271             return WebGLGetInfo(PassRefPtr<WebGLRenderbuffer>(findRenderbuffer(static_cast<Platform3DObject>(value))));
    1272         case GraphicsContext3D::TEXTURE:
    1273             return WebGLGetInfo(PassRefPtr<WebGLTexture>(findTexture(static_cast<Platform3DObject>(value))));
    1274         default:
    1275             // FIXME: raise exception?
    1276             return WebGLGetInfo();
    1277         }
     1256        return WebGLGetInfo(static_cast<long>(value));
     1257    }
     1258
     1259    WebGLStateRestorer(this, false);
     1260    int type = 0;
     1261    m_context->getFramebufferAttachmentParameteriv(target, attachment, GraphicsContext3D::FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &type);
     1262    int value = 0;
     1263    m_context->getFramebufferAttachmentParameteriv(target, attachment, GraphicsContext3D::FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &value);
     1264    switch (type) {
     1265    case GraphicsContext3D::RENDERBUFFER:
     1266        return WebGLGetInfo(PassRefPtr<WebGLRenderbuffer>(findRenderbuffer(static_cast<Platform3DObject>(value))));
     1267    case GraphicsContext3D::TEXTURE:
     1268        return WebGLGetInfo(PassRefPtr<WebGLTexture>(findTexture(static_cast<Platform3DObject>(value))));
     1269    default:
     1270        // FIXME: raise exception?
     1271        return WebGLGetInfo();
    12781272    }
    12791273}
     
    30513045
    30523046    long validatedStride = bytesPerElement;
    3053     if (stride != 0) {
     3047    if (stride) {
    30543048        if ((long) stride < bytesPerElement) {
    30553049            m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE);
  • trunk/WebCore/html/canvas/WebGLRenderingContext.h

    r64685 r64767  
    3030#include "ExceptionCode.h"
    3131#include "Float32Array.h"
     32#include "GraphicsContext3D.h"
     33#include "Int32Array.h"
     34#include "PlatformString.h"
     35#include "Uint8Array.h"
    3236#include "WebGLGetInfo.h"
    33 #include "Int32Array.h"
    34 #include "Uint8Array.h"
    35 #include "GraphicsContext3D.h"
    36 #include "PlatformString.h"
    3737
    3838namespace WebCore {
     
    5353class WebKitCSSMatrix;
    5454
    55     class WebGLRenderingContext : public CanvasRenderingContext {
     55class WebGLRenderingContext : public CanvasRenderingContext {
     56public:
     57    static PassOwnPtr<WebGLRenderingContext> create(HTMLCanvasElement*, WebGLContextAttributes*);
     58    virtual ~WebGLRenderingContext();
     59
     60    virtual bool is3d() const { return true; }
     61    virtual bool isAccelerated() const { return true; }
     62
     63    // Helper to return the size in bytes of OpenGL data types
     64    // like GL_FLOAT, GL_INT, etc.
     65    int sizeInBytes(int type, ExceptionCode& ec);
     66
     67    void activeTexture(unsigned long texture, ExceptionCode& ec);
     68    void attachShader(WebGLProgram*, WebGLShader*, ExceptionCode& ec);
     69    void bindAttribLocation(WebGLProgram*, unsigned long index, const String& name, ExceptionCode& ec);
     70    void bindBuffer(unsigned long target, WebGLBuffer*, ExceptionCode& ec);
     71    void bindFramebuffer(unsigned long target, WebGLFramebuffer*, ExceptionCode& ec);
     72    void bindRenderbuffer(unsigned long target, WebGLRenderbuffer*, ExceptionCode& ec);
     73    void bindTexture(unsigned long target, WebGLTexture*, ExceptionCode& ec);
     74    void blendColor(double red, double green, double blue, double alpha);
     75    void blendEquation(unsigned long mode);
     76    void blendEquationSeparate(unsigned long modeRGB, unsigned long modeAlpha);
     77    void blendFunc(unsigned long sfactor, unsigned long dfactor);
     78    void blendFuncSeparate(unsigned long srcRGB, unsigned long dstRGB, unsigned long srcAlpha, unsigned long dstAlpha);
     79
     80    void bufferData(unsigned long target, int size, unsigned long usage, ExceptionCode&);
     81    void bufferData(unsigned long target, ArrayBuffer* data, unsigned long usage, ExceptionCode&);
     82    void bufferData(unsigned long target, ArrayBufferView* data, unsigned long usage, ExceptionCode&);
     83    void bufferSubData(unsigned long target, long offset, ArrayBuffer* data, ExceptionCode&);
     84    void bufferSubData(unsigned long target, long offset, ArrayBufferView* data, ExceptionCode&);
     85
     86    unsigned long checkFramebufferStatus(unsigned long target);
     87    void clear(unsigned long mask);
     88    void clearColor(double red, double green, double blue, double alpha);
     89    void clearDepth(double);
     90    void clearStencil(long);
     91    void colorMask(bool red, bool green, bool blue, bool alpha);
     92    void compileShader(WebGLShader*, ExceptionCode& ec);
     93
     94    // void compressedTexImage2D(unsigned long target, long level, unsigned long internalformat, unsigned long width, unsigned long height, long border, unsigned long imageSize, const void* data);
     95    // void compressedTexSubImage2D(unsigned long target, long level, long xoffset, long yoffset, unsigned long width, unsigned long height, unsigned long format, unsigned long imageSize, const void* data);
     96
     97    void copyTexImage2D(unsigned long target, long level, unsigned long internalformat, long x, long y, unsigned long width, unsigned long height, long border);
     98    void copyTexSubImage2D(unsigned long target, long level, long xoffset, long yoffset, long x, long y, unsigned long width, unsigned long height);
     99
     100    PassRefPtr<WebGLBuffer> createBuffer();
     101    PassRefPtr<WebGLFramebuffer> createFramebuffer();
     102    PassRefPtr<WebGLProgram> createProgram();
     103    PassRefPtr<WebGLRenderbuffer> createRenderbuffer();
     104    PassRefPtr<WebGLShader> createShader(unsigned long type, ExceptionCode&);
     105    PassRefPtr<WebGLTexture> createTexture();
     106
     107    void cullFace(unsigned long mode);
     108
     109    void deleteBuffer(WebGLBuffer*);
     110    void deleteFramebuffer(WebGLFramebuffer*);
     111    void deleteProgram(WebGLProgram*);
     112    void deleteRenderbuffer(WebGLRenderbuffer*);
     113    void deleteShader(WebGLShader*);
     114    void deleteTexture(WebGLTexture*);
     115
     116    void depthFunc(unsigned long);
     117    void depthMask(bool);
     118    void depthRange(double zNear, double zFar);
     119    void detachShader(WebGLProgram*, WebGLShader*, ExceptionCode&);
     120    void disable(unsigned long cap);
     121    void disableVertexAttribArray(unsigned long index, ExceptionCode&);
     122    void drawArrays(unsigned long mode, long first, long count, ExceptionCode&);
     123    void drawElements(unsigned long mode, long count, unsigned long type, long offset, ExceptionCode&);
     124
     125    void enable(unsigned long cap);
     126    void enableVertexAttribArray(unsigned long index, ExceptionCode&);
     127    void finish();
     128    void flush();
     129    void framebufferRenderbuffer(unsigned long target, unsigned long attachment, unsigned long renderbuffertarget, WebGLRenderbuffer*, ExceptionCode& ec);
     130    void framebufferTexture2D(unsigned long target, unsigned long attachment, unsigned long textarget, WebGLTexture*, long level, ExceptionCode& ec);
     131    void frontFace(unsigned long mode);
     132    void generateMipmap(unsigned long target);
     133
     134    PassRefPtr<WebGLActiveInfo> getActiveAttrib(WebGLProgram*, unsigned long index, ExceptionCode&);
     135    PassRefPtr<WebGLActiveInfo> getActiveUniform(WebGLProgram*, unsigned long index, ExceptionCode&);
     136
     137    bool getAttachedShaders(WebGLProgram*, Vector<WebGLShader*>&, ExceptionCode&);
     138
     139    int getAttribLocation(WebGLProgram*, const String& name);
     140
     141    WebGLGetInfo getBufferParameter(unsigned long target, unsigned long pname, ExceptionCode&);
     142
     143    PassRefPtr<WebGLContextAttributes> getContextAttributes();
     144
     145    unsigned long getError();
     146
     147    WebGLGetInfo getFramebufferAttachmentParameter(unsigned long target, unsigned long attachment, unsigned long pname, ExceptionCode&);
     148
     149    WebGLGetInfo getParameter(unsigned long pname, ExceptionCode&);
     150
     151    WebGLGetInfo getProgramParameter(WebGLProgram*, unsigned long pname, ExceptionCode&);
     152
     153    String getProgramInfoLog(WebGLProgram*, ExceptionCode& ec);
     154
     155    WebGLGetInfo getRenderbufferParameter(unsigned long target, unsigned long pname, ExceptionCode&);
     156
     157    WebGLGetInfo getShaderParameter(WebGLShader*, unsigned long pname, ExceptionCode& ec);
     158
     159    String getShaderInfoLog(WebGLShader*, ExceptionCode& ec);
     160
     161    // TBD
     162    // void glGetShaderPrecisionFormat (GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision);
     163
     164    String getShaderSource(WebGLShader*, ExceptionCode&);
     165    String getString(unsigned long name);
     166
     167    WebGLGetInfo getTexParameter(unsigned long target, unsigned long pname, ExceptionCode&);
     168
     169    WebGLGetInfo getUniform(WebGLProgram*, const WebGLUniformLocation*, ExceptionCode&);
     170
     171    PassRefPtr<WebGLUniformLocation> getUniformLocation(WebGLProgram*, const String&, ExceptionCode&);
     172
     173    WebGLGetInfo getVertexAttrib(unsigned long index, unsigned long pname, ExceptionCode&);
     174
     175    long getVertexAttribOffset(unsigned long index, unsigned long pname);
     176
     177    void hint(unsigned long target, unsigned long mode);
     178    bool isBuffer(WebGLBuffer*);
     179    bool isEnabled(unsigned long cap);
     180    bool isFramebuffer(WebGLFramebuffer*);
     181    bool isProgram(WebGLProgram*);
     182    bool isRenderbuffer(WebGLRenderbuffer*);
     183    bool isShader(WebGLShader*);
     184    bool isTexture(WebGLTexture*);
     185    void lineWidth(double);
     186    void linkProgram(WebGLProgram*, ExceptionCode&);
     187    void pixelStorei(unsigned long pname, long param);
     188    void polygonOffset(double factor, double units);
     189    void readPixels(long x, long y, long width, long height, unsigned long format, unsigned long type, ArrayBufferView* pixels);
     190    void releaseShaderCompiler();
     191    void renderbufferStorage(unsigned long target, unsigned long internalformat, unsigned long width, unsigned long height);
     192    void sampleCoverage(double value, bool invert);
     193    void scissor(long x, long y, unsigned long width, unsigned long height);
     194    void shaderSource(WebGLShader*, const String&, ExceptionCode&);
     195    void stencilFunc(unsigned long func, long ref, unsigned long mask);
     196    void stencilFuncSeparate(unsigned long face, unsigned long func, long ref, unsigned long mask);
     197    void stencilMask(unsigned long);
     198    void stencilMaskSeparate(unsigned long face, unsigned long mask);
     199    void stencilOp(unsigned long fail, unsigned long zfail, unsigned long zpass);
     200    void stencilOpSeparate(unsigned long face, unsigned long fail, unsigned long zfail, unsigned long zpass);
     201
     202    void texImage2D(unsigned target, unsigned level, unsigned internalformat,
     203                    unsigned width, unsigned height, unsigned border,
     204                    unsigned format, unsigned type, ArrayBufferView* pixels, ExceptionCode&);
     205    void texImage2D(unsigned target, unsigned level, unsigned internalformat,
     206                    unsigned format, unsigned type, ImageData* pixels, ExceptionCode&);
     207    void texImage2D(unsigned target, unsigned level, unsigned internalformat,
     208                    unsigned format, unsigned type, HTMLImageElement* image, ExceptionCode&);
     209    void texImage2D(unsigned target, unsigned level, unsigned internalformat,
     210                    unsigned format, unsigned type, HTMLCanvasElement* canvas, ExceptionCode&);
     211    void texImage2D(unsigned target, unsigned level, unsigned internalformat,
     212                    unsigned format, unsigned type, HTMLVideoElement* video, ExceptionCode&);
     213    // Obsolete entry points -- to be removed shortly. (FIXME)
     214    void texImage2D(unsigned target, unsigned level, ImageData* pixels, ExceptionCode&);
     215    void texImage2D(unsigned target, unsigned level, ImageData* pixels, bool flipY, ExceptionCode&);
     216    void texImage2D(unsigned target, unsigned level, ImageData* pixels, bool flipY, bool premultiplyAlpha, ExceptionCode&);
     217    void texImage2D(unsigned target, unsigned level, HTMLImageElement* image, ExceptionCode&);
     218    void texImage2D(unsigned target, unsigned level, HTMLImageElement* image, bool flipY, ExceptionCode&);
     219    void texImage2D(unsigned target, unsigned level, HTMLImageElement* image, bool flipY, bool premultiplyAlpha, ExceptionCode&);
     220    void texImage2D(unsigned target, unsigned level, HTMLCanvasElement* canvas, ExceptionCode&);
     221    void texImage2D(unsigned target, unsigned level, HTMLCanvasElement* canvas, bool flipY, ExceptionCode&);
     222    void texImage2D(unsigned target, unsigned level, HTMLCanvasElement* canvas, bool flipY, bool premultiplyAlpha, ExceptionCode&);
     223    void texImage2D(unsigned target, unsigned level, HTMLVideoElement* video, ExceptionCode&);
     224    void texImage2D(unsigned target, unsigned level, HTMLVideoElement* video, bool flipY, ExceptionCode&);
     225    void texImage2D(unsigned target, unsigned level, HTMLVideoElement* video, bool flipY, bool premultiplyAlpha, ExceptionCode&);
     226
     227    void texParameterf(unsigned target, unsigned pname, float param);
     228    void texParameteri(unsigned target, unsigned pname, int param);
     229
     230    void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
     231                       unsigned width, unsigned height,
     232                       unsigned format, unsigned type, ArrayBufferView* pixels, ExceptionCode&);
     233    void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
     234                       unsigned format, unsigned type, ImageData* pixels, ExceptionCode&);
     235    void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
     236                       unsigned format, unsigned type, HTMLImageElement* image, ExceptionCode&);
     237    void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
     238                       unsigned format, unsigned type, HTMLCanvasElement* canvas, ExceptionCode&);
     239    void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
     240                       unsigned format, unsigned type, HTMLVideoElement* video, ExceptionCode&);
     241    // Obsolete entry points -- to be removed shortly. (FIXME)
     242    void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, ImageData* pixels, ExceptionCode&);
     243    void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, ImageData* pixels, bool flipY, ExceptionCode&);
     244    void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, ImageData* pixels, bool flipY, bool premultiplyAlpha, ExceptionCode&);
     245    void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLImageElement* image, ExceptionCode&);
     246    void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLImageElement* image, bool flipY, ExceptionCode&);
     247    void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLImageElement* image, bool flipY, bool premultiplyAlpha, ExceptionCode&);
     248    void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLCanvasElement* canvas, ExceptionCode&);
     249    void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLCanvasElement* canvas, bool flipY, ExceptionCode&);
     250    void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLCanvasElement* canvas, bool flipY, bool premultiplyAlpha, ExceptionCode&);
     251    void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLVideoElement* video, ExceptionCode&);
     252    void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLVideoElement* video, bool flipY, ExceptionCode&);
     253    void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLVideoElement* video, bool flipY, bool premultiplyAlpha, ExceptionCode&);
     254
     255    void uniform1f(const WebGLUniformLocation* location, float x, ExceptionCode&);
     256    void uniform1fv(const WebGLUniformLocation* location, Float32Array* v, ExceptionCode&);
     257    void uniform1fv(const WebGLUniformLocation* location, float* v, int size, ExceptionCode&);
     258    void uniform1i(const WebGLUniformLocation* location, int x, ExceptionCode&);
     259    void uniform1iv(const WebGLUniformLocation* location, Int32Array* v, ExceptionCode&);
     260    void uniform1iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode&);
     261    void uniform2f(const WebGLUniformLocation* location, float x, float y, ExceptionCode&);
     262    void uniform2fv(const WebGLUniformLocation* location, Float32Array* v, ExceptionCode&);
     263    void uniform2fv(const WebGLUniformLocation* location, float* v, int size, ExceptionCode&);
     264    void uniform2i(const WebGLUniformLocation* location, int x, int y, ExceptionCode&);
     265    void uniform2iv(const WebGLUniformLocation* location, Int32Array* v, ExceptionCode&);
     266    void uniform2iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode&);
     267    void uniform3f(const WebGLUniformLocation* location, float x, float y, float z, ExceptionCode&);
     268    void uniform3fv(const WebGLUniformLocation* location, Float32Array* v, ExceptionCode&);
     269    void uniform3fv(const WebGLUniformLocation* location, float* v, int size, ExceptionCode&);
     270    void uniform3i(const WebGLUniformLocation* location, int x, int y, int z, ExceptionCode&);
     271    void uniform3iv(const WebGLUniformLocation* location, Int32Array* v, ExceptionCode&);
     272    void uniform3iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode&);
     273    void uniform4f(const WebGLUniformLocation* location, float x, float y, float z, float w, ExceptionCode&);
     274    void uniform4fv(const WebGLUniformLocation* location, Float32Array* v, ExceptionCode&);
     275    void uniform4fv(const WebGLUniformLocation* location, float* v, int size, ExceptionCode&);
     276    void uniform4i(const WebGLUniformLocation* location, int x, int y, int z, int w, ExceptionCode&);
     277    void uniform4iv(const WebGLUniformLocation* location, Int32Array* v, ExceptionCode&);
     278    void uniform4iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode&);
     279    void uniformMatrix2fv(const WebGLUniformLocation* location, bool transpose, Float32Array* value, ExceptionCode&);
     280    void uniformMatrix2fv(const WebGLUniformLocation* location, bool transpose, float* value, int size, ExceptionCode&);
     281    void uniformMatrix3fv(const WebGLUniformLocation* location, bool transpose, Float32Array* value, ExceptionCode&);
     282    void uniformMatrix3fv(const WebGLUniformLocation* location, bool transpose, float* value, int size, ExceptionCode&);
     283    void uniformMatrix4fv(const WebGLUniformLocation* location, bool transpose, Float32Array* value, ExceptionCode&);
     284    void uniformMatrix4fv(const WebGLUniformLocation* location, bool transpose, float* value, int size, ExceptionCode&);
     285
     286    void useProgram(WebGLProgram*, ExceptionCode&);
     287    void validateProgram(WebGLProgram*, ExceptionCode&);
     288
     289    void vertexAttrib1f(unsigned long index, float x);
     290    void vertexAttrib1fv(unsigned long index, Float32Array* values);
     291    void vertexAttrib1fv(unsigned long index, float* values, int size);
     292    void vertexAttrib2f(unsigned long index, float x, float y);
     293    void vertexAttrib2fv(unsigned long index, Float32Array* values);
     294    void vertexAttrib2fv(unsigned long index, float* values, int size);
     295    void vertexAttrib3f(unsigned long index, float x, float y, float z);
     296    void vertexAttrib3fv(unsigned long index, Float32Array* values);
     297    void vertexAttrib3fv(unsigned long index, float* values, int size);
     298    void vertexAttrib4f(unsigned long index, float x, float y, float z, float w);
     299    void vertexAttrib4fv(unsigned long index, Float32Array* values);
     300    void vertexAttrib4fv(unsigned long index, float* values, int size);
     301    void vertexAttribPointer(unsigned long index, long size, unsigned long type, bool normalized,
     302                             long stride, long offset, ExceptionCode&);
     303
     304    void viewport(long x, long y, unsigned long width, unsigned long height);
     305
     306    virtual GraphicsContext3D* graphicsContext3D() const { return m_context.get(); }
     307
     308    void reshape(int width, int height);
     309
     310    // Return value true indicates canvas is updated during the call,
     311    // false indicates no updates.
     312    bool paintRenderingResultsToCanvas();
     313
     314    // Helpers for notification about paint events.
     315    void beginPaint();
     316    void endPaint();
     317
     318    void removeObject(WebGLObject*);
     319
     320  private:
     321    friend class WebGLObject;
     322
     323    WebGLRenderingContext(HTMLCanvasElement*, PassOwnPtr<GraphicsContext3D>);
     324
     325    void addObject(WebGLObject*);
     326    void detachAndRemoveAllObjects();
     327    WebGLTexture* findTexture(Platform3DObject);
     328    WebGLRenderbuffer* findRenderbuffer(Platform3DObject);
     329    WebGLBuffer* findBuffer(Platform3DObject);
     330    WebGLShader* findShader(Platform3DObject);
     331
     332    void markContextChanged();
     333    void cleanupAfterGraphicsCall(bool changed)
     334    {
     335        if (changed)
     336            markContextChanged();
     337    }
     338
     339    bool isGLES2Compliant();
     340
     341    // Basic validation of count and offset against number of elements in element array buffer
     342    bool validateElementArraySize(unsigned long count, unsigned long type, long offset);
     343
     344    // Conservative but quick index validation
     345    bool validateIndexArrayConservative(unsigned long type, long& numElementsRequired);
     346
     347    // Precise but slow index validation -- only done if conservative checks fail
     348    bool validateIndexArrayPrecise(unsigned long count, unsigned long type, long offset, long& numElementsRequired);
     349    bool validateRenderingState(long numElements);
     350
     351    bool validateWebGLObject(WebGLObject* object);
     352
     353    OwnPtr<GraphicsContext3D> m_context;
     354    bool m_needsUpdate;
     355    bool m_markedCanvasDirty;
     356    // FIXME: I think this is broken -- it does not increment any
     357    // reference counts, so may refer to destroyed objects.
     358    HashSet<RefPtr<WebGLObject> > m_canvasObjects;
     359
     360    // List of bound VBO's. Used to maintain info about sizes for ARRAY_BUFFER and stored values for ELEMENT_ARRAY_BUFFER
     361    RefPtr<WebGLBuffer> m_boundArrayBuffer;
     362    RefPtr<WebGLBuffer> m_boundElementArrayBuffer;
     363
     364    // Cached values for vertex attrib range checks
     365    class VertexAttribState {
    56366    public:
    57         static PassOwnPtr<WebGLRenderingContext> create(HTMLCanvasElement*, WebGLContextAttributes*);
    58         virtual ~WebGLRenderingContext();
    59 
    60         virtual bool is3d() const { return true; }
    61         virtual bool isAccelerated() const { return true; }
    62 
    63         // Helper to return the size in bytes of OpenGL data types
    64         // like GL_FLOAT, GL_INT, etc.
    65         int sizeInBytes(int type, ExceptionCode& ec);
    66 
    67         void activeTexture(unsigned long texture, ExceptionCode& ec);
    68         void attachShader(WebGLProgram*, WebGLShader*, ExceptionCode& ec);
    69         void bindAttribLocation(WebGLProgram*, unsigned long index, const String& name, ExceptionCode& ec);
    70         void bindBuffer(unsigned long target, WebGLBuffer*, ExceptionCode& ec);
    71         void bindFramebuffer(unsigned long target, WebGLFramebuffer*, ExceptionCode& ec);
    72         void bindRenderbuffer(unsigned long target, WebGLRenderbuffer*, ExceptionCode& ec);
    73         void bindTexture(unsigned long target, WebGLTexture*, ExceptionCode& ec);
    74         void blendColor(double red, double green, double blue, double alpha);
    75         void blendEquation(unsigned long mode);
    76         void blendEquationSeparate(unsigned long modeRGB, unsigned long modeAlpha);
    77         void blendFunc(unsigned long sfactor, unsigned long dfactor);
    78         void blendFuncSeparate(unsigned long srcRGB, unsigned long dstRGB, unsigned long srcAlpha, unsigned long dstAlpha);
    79 
    80         void bufferData(unsigned long target, int size, unsigned long usage, ExceptionCode&);
    81         void bufferData(unsigned long target, ArrayBuffer* data, unsigned long usage, ExceptionCode&);
    82         void bufferData(unsigned long target, ArrayBufferView* data, unsigned long usage, ExceptionCode&);
    83         void bufferSubData(unsigned long target, long offset, ArrayBuffer* data, ExceptionCode&);
    84         void bufferSubData(unsigned long target, long offset, ArrayBufferView* data, ExceptionCode&);
    85 
    86         unsigned long checkFramebufferStatus(unsigned long target);
    87         void clear(unsigned long mask);
    88         void clearColor(double red, double green, double blue, double alpha);
    89         void clearDepth(double);
    90         void clearStencil(long);
    91         void colorMask(bool red, bool green, bool blue, bool alpha);
    92         void compileShader(WebGLShader*, ExceptionCode& ec);
    93        
    94         //void compressedTexImage2D(unsigned long target, long level, unsigned long internalformat, unsigned long width, unsigned long height, long border, unsigned long imageSize, const void* data);
    95         //void compressedTexSubImage2D(unsigned long target, long level, long xoffset, long yoffset, unsigned long width, unsigned long height, unsigned long format, unsigned long imageSize, const void* data);
    96        
    97         void copyTexImage2D(unsigned long target, long level, unsigned long internalformat, long x, long y, unsigned long width, unsigned long height, long border);
    98         void copyTexSubImage2D(unsigned long target, long level, long xoffset, long yoffset, long x, long y, unsigned long width, unsigned long height);
    99 
    100         PassRefPtr<WebGLBuffer> createBuffer();
    101         PassRefPtr<WebGLFramebuffer> createFramebuffer();
    102         PassRefPtr<WebGLProgram> createProgram();
    103         PassRefPtr<WebGLRenderbuffer> createRenderbuffer();
    104         PassRefPtr<WebGLShader> createShader(unsigned long type, ExceptionCode&);
    105         PassRefPtr<WebGLTexture> createTexture();
    106 
    107         void cullFace(unsigned long mode);
    108 
    109         void deleteBuffer(WebGLBuffer*);
    110         void deleteFramebuffer(WebGLFramebuffer*);
    111         void deleteProgram(WebGLProgram*);
    112         void deleteRenderbuffer(WebGLRenderbuffer*);
    113         void deleteShader(WebGLShader*);
    114         void deleteTexture(WebGLTexture*);
    115        
    116         void depthFunc(unsigned long);
    117         void depthMask(bool);
    118         void depthRange(double zNear, double zFar);
    119         void detachShader(WebGLProgram*, WebGLShader*, ExceptionCode&);
    120         void disable(unsigned long cap);
    121         void disableVertexAttribArray(unsigned long index, ExceptionCode&);
    122         void drawArrays(unsigned long mode, long first, long count, ExceptionCode&);
    123         void drawElements(unsigned long mode, long count, unsigned long type, long offset, ExceptionCode&);
    124 
    125         void enable(unsigned long cap);
    126         void enableVertexAttribArray(unsigned long index, ExceptionCode&);
    127         void finish();
    128         void flush();
    129         void framebufferRenderbuffer(unsigned long target, unsigned long attachment, unsigned long renderbuffertarget, WebGLRenderbuffer*, ExceptionCode& ec);
    130         void framebufferTexture2D(unsigned long target, unsigned long attachment, unsigned long textarget, WebGLTexture*, long level, ExceptionCode& ec);
    131         void frontFace(unsigned long mode);
    132         void generateMipmap(unsigned long target);
    133 
    134         PassRefPtr<WebGLActiveInfo> getActiveAttrib(WebGLProgram*, unsigned long index, ExceptionCode&);
    135         PassRefPtr<WebGLActiveInfo> getActiveUniform(WebGLProgram*, unsigned long index, ExceptionCode&);
    136 
    137         bool getAttachedShaders(WebGLProgram*, Vector<WebGLShader*>&, ExceptionCode&);
    138 
    139         int  getAttribLocation(WebGLProgram*, const String& name);
    140 
    141         WebGLGetInfo getBufferParameter(unsigned long target, unsigned long pname, ExceptionCode&);
    142 
    143         PassRefPtr<WebGLContextAttributes> getContextAttributes();
    144 
    145         unsigned long getError();
    146 
    147         WebGLGetInfo getFramebufferAttachmentParameter(unsigned long target, unsigned long attachment, unsigned long pname, ExceptionCode&);
    148 
    149         WebGLGetInfo getParameter(unsigned long pname, ExceptionCode&);
    150 
    151         WebGLGetInfo getProgramParameter(WebGLProgram*, unsigned long pname, ExceptionCode&);
    152 
    153         String getProgramInfoLog(WebGLProgram*, ExceptionCode& ec);
    154 
    155         WebGLGetInfo getRenderbufferParameter(unsigned long target, unsigned long pname, ExceptionCode&);
    156 
    157         WebGLGetInfo getShaderParameter(WebGLShader*, unsigned long pname, ExceptionCode& ec);
    158 
    159         String getShaderInfoLog(WebGLShader*, ExceptionCode& ec);
    160 
    161         // TBD
    162         // void glGetShaderPrecisionFormat (GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision);
    163 
    164         String getShaderSource(WebGLShader*, ExceptionCode&);
    165         String getString(unsigned long name);
    166 
    167         WebGLGetInfo getTexParameter(unsigned long target, unsigned long pname, ExceptionCode&);
    168 
    169         WebGLGetInfo getUniform(WebGLProgram*, const WebGLUniformLocation*, ExceptionCode&);
    170 
    171         PassRefPtr<WebGLUniformLocation> getUniformLocation(WebGLProgram*, const String&, ExceptionCode&);
    172 
    173         WebGLGetInfo getVertexAttrib(unsigned long index, unsigned long pname, ExceptionCode&);
    174 
    175         long getVertexAttribOffset(unsigned long index, unsigned long pname);
    176 
    177         void hint(unsigned long target, unsigned long mode);
    178         bool isBuffer(WebGLBuffer*);
    179         bool isEnabled(unsigned long cap);
    180         bool isFramebuffer(WebGLFramebuffer*);
    181         bool isProgram(WebGLProgram*);
    182         bool isRenderbuffer(WebGLRenderbuffer*);
    183         bool isShader(WebGLShader*);
    184         bool isTexture(WebGLTexture*);
    185         void lineWidth(double);
    186         void linkProgram(WebGLProgram*, ExceptionCode&);
    187         void pixelStorei(unsigned long pname, long param);
    188         void polygonOffset(double factor, double units);
    189         void readPixels(long x, long y, long width, long height, unsigned long format, unsigned long type, ArrayBufferView* pixels);
    190         void releaseShaderCompiler();
    191         void renderbufferStorage(unsigned long target, unsigned long internalformat, unsigned long width, unsigned long height);
    192         void sampleCoverage(double value, bool invert);
    193         void scissor(long x, long y, unsigned long width, unsigned long height);
    194         void shaderSource(WebGLShader*, const String&, ExceptionCode&);
    195         void stencilFunc(unsigned long func, long ref, unsigned long mask);
    196         void stencilFuncSeparate(unsigned long face, unsigned long func, long ref, unsigned long mask);
    197         void stencilMask(unsigned long);
    198         void stencilMaskSeparate(unsigned long face, unsigned long mask);
    199         void stencilOp(unsigned long fail, unsigned long zfail, unsigned long zpass);
    200         void stencilOpSeparate(unsigned long face, unsigned long fail, unsigned long zfail, unsigned long zpass);
    201 
    202         void texImage2D(unsigned target, unsigned level, unsigned internalformat,
     367        VertexAttribState()
     368            : enabled(false)
     369            , bytesPerElement(0)
     370            , size(4)
     371            , type(GraphicsContext3D::FLOAT)
     372            , normalized(false)
     373            , stride(16)
     374            , originalStride(0)
     375            , offset(0)
     376        {
     377            initValue();
     378        }
     379
     380        void initValue()
     381        {
     382            value[0] = 0.0f;
     383            value[1] = 0.0f;
     384            value[2] = 0.0f;
     385            value[3] = 1.0f;
     386        }
     387
     388        bool enabled;
     389        RefPtr<WebGLBuffer> bufferBinding;
     390        long bytesPerElement;
     391        long size;
     392        unsigned long type;
     393        bool normalized;
     394        long stride;
     395        long originalStride;
     396        long offset;
     397        float value[4];
     398    };
     399
     400    Vector<VertexAttribState> m_vertexAttribState;
     401    unsigned m_maxVertexAttribs;
     402    RefPtr<WebGLBuffer> m_vertexAttrib0Buffer;
     403    long m_vertexAttrib0BufferSize;
     404    float m_vertexAttrib0BufferValue[4];
     405
     406    RefPtr<WebGLProgram> m_currentProgram;
     407    RefPtr<WebGLFramebuffer> m_framebufferBinding;
     408    RefPtr<WebGLRenderbuffer> m_renderbufferBinding;
     409    class TextureUnitState {
     410    public:
     411        RefPtr<WebGLTexture> m_texture2DBinding;
     412        RefPtr<WebGLTexture> m_textureCubeMapBinding;
     413    };
     414    Vector<TextureUnitState> m_textureUnits;
     415    unsigned long m_activeTextureUnit;
     416
     417    RefPtr<WebGLTexture> m_blackTexture2D;
     418    RefPtr<WebGLTexture> m_blackTextureCubeMap;
     419
     420    int m_maxTextureSize;
     421    int m_maxCubeMapTextureSize;
     422    int m_maxTextureLevel;
     423    int m_maxCubeMapTextureLevel;
     424
     425    int m_packAlignment;
     426    int m_unpackAlignment;
     427    unsigned long m_implementationColorReadFormat;
     428    unsigned long m_implementationColorReadType;
     429    bool m_unpackFlipY;
     430    bool m_unpackPremultiplyAlpha;
     431
     432    // Helpers for getParameter and others
     433    WebGLGetInfo getBooleanParameter(unsigned long pname);
     434    WebGLGetInfo getBooleanArrayParameter(unsigned long pname);
     435    WebGLGetInfo getFloatParameter(unsigned long pname);
     436    WebGLGetInfo getIntParameter(unsigned long pname);
     437    WebGLGetInfo getLongParameter(unsigned long pname);
     438    WebGLGetInfo getUnsignedLongParameter(unsigned long pname);
     439    WebGLGetInfo getWebGLFloatArrayParameter(unsigned long pname);
     440    WebGLGetInfo getWebGLIntArrayParameter(unsigned long pname);
     441
     442    void texImage2DBase(unsigned target, unsigned level, unsigned internalformat,
    203443                        unsigned width, unsigned height, unsigned border,
    204                         unsigned format, unsigned type, ArrayBufferView* pixels, ExceptionCode&);
    205         void texImage2D(unsigned target, unsigned level, unsigned internalformat,
    206                         unsigned format, unsigned type, ImageData* pixels, ExceptionCode&);
    207         void texImage2D(unsigned target, unsigned level, unsigned internalformat,
    208                         unsigned format, unsigned type, HTMLImageElement* image, ExceptionCode&);
    209         void texImage2D(unsigned target, unsigned level, unsigned internalformat,
    210                         unsigned format, unsigned type, HTMLCanvasElement* canvas, ExceptionCode&);
    211         void texImage2D(unsigned target, unsigned level, unsigned internalformat,
    212                         unsigned format, unsigned type, HTMLVideoElement* video, ExceptionCode&);
    213         // Obsolete entry points -- to be removed shortly. (FIXME)
    214         void texImage2D(unsigned target, unsigned level, ImageData* pixels, ExceptionCode&);
    215         void texImage2D(unsigned target, unsigned level, ImageData* pixels, bool flipY, ExceptionCode&);
    216         void texImage2D(unsigned target, unsigned level, ImageData* pixels, bool flipY, bool premultiplyAlpha, ExceptionCode&);
    217         void texImage2D(unsigned target, unsigned level, HTMLImageElement* image, ExceptionCode&);
    218         void texImage2D(unsigned target, unsigned level, HTMLImageElement* image, bool flipY, ExceptionCode&);
    219         void texImage2D(unsigned target, unsigned level, HTMLImageElement* image, bool flipY, bool premultiplyAlpha, ExceptionCode&);
    220         void texImage2D(unsigned target, unsigned level, HTMLCanvasElement* canvas, ExceptionCode&);
    221         void texImage2D(unsigned target, unsigned level, HTMLCanvasElement* canvas, bool flipY, ExceptionCode&);
    222         void texImage2D(unsigned target, unsigned level, HTMLCanvasElement* canvas, bool flipY, bool premultiplyAlpha, ExceptionCode&);
    223         void texImage2D(unsigned target, unsigned level, HTMLVideoElement* video, ExceptionCode&);
    224         void texImage2D(unsigned target, unsigned level, HTMLVideoElement* video, bool flipY, ExceptionCode&);
    225         void texImage2D(unsigned target, unsigned level, HTMLVideoElement* video, bool flipY, bool premultiplyAlpha, ExceptionCode&);
    226 
    227         void texParameterf(unsigned target, unsigned pname, float param);
    228         void texParameteri(unsigned target, unsigned pname, int param);
    229 
    230         void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
     444                        unsigned format, unsigned type, void* pixels, ExceptionCode&);
     445    void texImage2DImpl(unsigned target, unsigned level, unsigned internalformat,
     446                        unsigned format, unsigned type, Image* image,
     447                        bool flipY, bool premultiplyAlpha, ExceptionCode&);
     448    void texSubImage2DBase(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
    231449                           unsigned width, unsigned height,
    232                            unsigned format, unsigned type, ArrayBufferView* pixels, ExceptionCode&);
    233         void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
    234                            unsigned format, unsigned type, ImageData* pixels, ExceptionCode&);
    235         void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
    236                            unsigned format, unsigned type, HTMLImageElement* image, ExceptionCode&);
    237         void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
    238                            unsigned format, unsigned type, HTMLCanvasElement* canvas, ExceptionCode&);
    239         void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
    240                            unsigned format, unsigned type, HTMLVideoElement* video, ExceptionCode&);
    241         // Obsolete entry points -- to be removed shortly. (FIXME)
    242         void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, ImageData* pixels, ExceptionCode&);
    243         void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, ImageData* pixels, bool flipY, ExceptionCode&);
    244         void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, ImageData* pixels, bool flipY, bool premultiplyAlpha, ExceptionCode&);
    245         void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLImageElement* image, ExceptionCode&);
    246         void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLImageElement* image, bool flipY, ExceptionCode&);
    247         void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLImageElement* image, bool flipY, bool premultiplyAlpha, ExceptionCode&);
    248         void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLCanvasElement* canvas, ExceptionCode&);
    249         void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLCanvasElement* canvas, bool flipY, ExceptionCode&);
    250         void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLCanvasElement* canvas, bool flipY, bool premultiplyAlpha, ExceptionCode&);
    251         void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLVideoElement* video, ExceptionCode&);
    252         void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLVideoElement* video, bool flipY, ExceptionCode&);
    253         void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLVideoElement* video, bool flipY, bool premultiplyAlpha, ExceptionCode&);
    254 
    255         void uniform1f(const WebGLUniformLocation* location, float x, ExceptionCode&);
    256         void uniform1fv(const WebGLUniformLocation* location, Float32Array* v, ExceptionCode&);
    257         void uniform1fv(const WebGLUniformLocation* location, float* v, int size, ExceptionCode&);
    258         void uniform1i(const WebGLUniformLocation* location, int x, ExceptionCode&);
    259         void uniform1iv(const WebGLUniformLocation* location, Int32Array* v, ExceptionCode&);
    260         void uniform1iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode&);
    261         void uniform2f(const WebGLUniformLocation* location, float x, float y, ExceptionCode&);
    262         void uniform2fv(const WebGLUniformLocation* location, Float32Array* v, ExceptionCode&);
    263         void uniform2fv(const WebGLUniformLocation* location, float* v, int size, ExceptionCode&);
    264         void uniform2i(const WebGLUniformLocation* location, int x, int y, ExceptionCode&);
    265         void uniform2iv(const WebGLUniformLocation* location, Int32Array* v, ExceptionCode&);
    266         void uniform2iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode&);
    267         void uniform3f(const WebGLUniformLocation* location, float x, float y, float z, ExceptionCode&);
    268         void uniform3fv(const WebGLUniformLocation* location, Float32Array* v, ExceptionCode&);
    269         void uniform3fv(const WebGLUniformLocation* location, float* v, int size, ExceptionCode&);
    270         void uniform3i(const WebGLUniformLocation* location, int x, int y, int z, ExceptionCode&);
    271         void uniform3iv(const WebGLUniformLocation* location, Int32Array* v, ExceptionCode&);
    272         void uniform3iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode&);
    273         void uniform4f(const WebGLUniformLocation* location, float x, float y, float z, float w, ExceptionCode&);
    274         void uniform4fv(const WebGLUniformLocation* location, Float32Array* v, ExceptionCode&);
    275         void uniform4fv(const WebGLUniformLocation* location, float* v, int size, ExceptionCode&);
    276         void uniform4i(const WebGLUniformLocation* location, int x, int y, int z, int w, ExceptionCode&);
    277         void uniform4iv(const WebGLUniformLocation* location, Int32Array* v, ExceptionCode&);
    278         void uniform4iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode&);
    279         void uniformMatrix2fv(const WebGLUniformLocation* location, bool transpose, Float32Array* value, ExceptionCode&);
    280         void uniformMatrix2fv(const WebGLUniformLocation* location, bool transpose, float* value, int size, ExceptionCode&);
    281         void uniformMatrix3fv(const WebGLUniformLocation* location, bool transpose, Float32Array* value, ExceptionCode&);
    282         void uniformMatrix3fv(const WebGLUniformLocation* location, bool transpose, float* value, int size, ExceptionCode&);
    283         void uniformMatrix4fv(const WebGLUniformLocation* location, bool transpose, Float32Array* value, ExceptionCode&);
    284         void uniformMatrix4fv(const WebGLUniformLocation* location, bool transpose, float* value, int size, ExceptionCode&);
    285 
    286         void useProgram(WebGLProgram*, ExceptionCode&);
    287         void validateProgram(WebGLProgram*, ExceptionCode&);
    288 
    289         void vertexAttrib1f(unsigned long index, float x);
    290         void vertexAttrib1fv(unsigned long index, Float32Array* values);
    291         void vertexAttrib1fv(unsigned long index, float* values, int size);
    292         void vertexAttrib2f(unsigned long index, float x, float y);
    293         void vertexAttrib2fv(unsigned long index, Float32Array* values);
    294         void vertexAttrib2fv(unsigned long index, float* values, int size);
    295         void vertexAttrib3f(unsigned long index, float x, float y, float z);
    296         void vertexAttrib3fv(unsigned long index, Float32Array* values);
    297         void vertexAttrib3fv(unsigned long index, float* values, int size);
    298         void vertexAttrib4f(unsigned long index, float x, float y, float z, float w);
    299         void vertexAttrib4fv(unsigned long index, Float32Array* values);
    300         void vertexAttrib4fv(unsigned long index, float* values, int size);
    301         void vertexAttribPointer(unsigned long index, long size, unsigned long type, bool normalized,
    302                                  long stride, long offset, ExceptionCode&);
    303 
    304         void viewport(long x, long y, unsigned long width, unsigned long height);
    305 
    306         virtual GraphicsContext3D* graphicsContext3D() const { return m_context.get(); }
    307    
    308         void reshape(int width, int height);
    309 
    310         // Return value true indicates canvas is updated during the call,
    311         // false indicates no updates.
    312         bool paintRenderingResultsToCanvas();
    313 
    314         // Helpers for notification about paint events.
    315         void beginPaint();
    316         void endPaint();
    317        
    318         void removeObject(WebGLObject*);
    319        
    320     private:
    321         friend class WebGLObject;
    322 
    323         WebGLRenderingContext(HTMLCanvasElement*, PassOwnPtr<GraphicsContext3D>);
    324 
    325         void addObject(WebGLObject*);
    326         void detachAndRemoveAllObjects();
    327         WebGLTexture* findTexture(Platform3DObject);
    328         WebGLRenderbuffer* findRenderbuffer(Platform3DObject);
    329         WebGLBuffer* findBuffer(Platform3DObject);
    330         WebGLShader* findShader(Platform3DObject);
    331 
    332         void markContextChanged();
    333         void cleanupAfterGraphicsCall(bool changed)
    334         {
    335             if (changed)
    336                 markContextChanged();
    337         }
    338 
    339         bool isGLES2Compliant();
    340        
    341         // Basic validation of count and offset against number of elements in element array buffer
    342         bool validateElementArraySize(unsigned long count, unsigned long type, long offset);
    343 
    344         // Conservative but quick index validation
    345         bool validateIndexArrayConservative(unsigned long type, long& numElementsRequired);
    346 
    347         // Precise but slow index validation -- only done if conservative checks fail
    348         bool validateIndexArrayPrecise(unsigned long count, unsigned long type, long offset, long& numElementsRequired);
    349         bool validateRenderingState(long numElements);
    350 
    351         bool validateWebGLObject(WebGLObject* object);
    352 
    353         OwnPtr<GraphicsContext3D> m_context;
    354         bool m_needsUpdate;
    355         bool m_markedCanvasDirty;
    356         // FIXME: I think this is broken -- it does not increment any
    357         // reference counts, so may refer to destroyed objects.
    358         HashSet<RefPtr<WebGLObject> > m_canvasObjects;
    359        
    360         // List of bound VBO's. Used to maintain info about sizes for ARRAY_BUFFER and stored values for ELEMENT_ARRAY_BUFFER
    361         RefPtr<WebGLBuffer> m_boundArrayBuffer;
    362         RefPtr<WebGLBuffer> m_boundElementArrayBuffer;
    363    
    364         // Cached values for vertex attrib range checks
    365         class VertexAttribState {
    366         public:
    367             VertexAttribState()
    368                 : enabled(false)
    369                 , bytesPerElement(0)
    370                 , size(4)
    371                 , type(GraphicsContext3D::FLOAT)
    372                 , normalized(false)
    373                 , stride(16)
    374                 , originalStride(0)
    375                 , offset(0)
    376             {
    377                 initValue();
    378             }
    379 
    380             void initValue()
    381             {
    382                 value[0] = 0.0f;
    383                 value[1] = 0.0f;
    384                 value[2] = 0.0f;
    385                 value[3] = 1.0f;
    386             }
    387 
    388             bool enabled;
    389             RefPtr<WebGLBuffer> bufferBinding;
    390             long bytesPerElement;
    391             long size;
    392             unsigned long type;
    393             bool normalized;
    394             long stride;
    395             long originalStride;
    396             long offset;
    397             float value[4];
    398         };
    399        
    400         Vector<VertexAttribState> m_vertexAttribState;
    401         unsigned m_maxVertexAttribs;
    402         RefPtr<WebGLBuffer> m_vertexAttrib0Buffer;
    403         long m_vertexAttrib0BufferSize;
    404         float m_vertexAttrib0BufferValue[4];
    405 
    406         RefPtr<WebGLProgram> m_currentProgram;
    407         RefPtr<WebGLFramebuffer> m_framebufferBinding;
    408         RefPtr<WebGLRenderbuffer> m_renderbufferBinding;
    409         class TextureUnitState {
    410         public:
    411             RefPtr<WebGLTexture> m_texture2DBinding;
    412             RefPtr<WebGLTexture> m_textureCubeMapBinding;
    413         };
    414         Vector<TextureUnitState> m_textureUnits;
    415         unsigned long m_activeTextureUnit;
    416 
    417         RefPtr<WebGLTexture> m_blackTexture2D;
    418         RefPtr<WebGLTexture> m_blackTextureCubeMap;
    419 
    420         int m_maxTextureSize;
    421         int m_maxCubeMapTextureSize;
    422         int m_maxTextureLevel;
    423         int m_maxCubeMapTextureLevel;
    424 
    425         int m_packAlignment;
    426         int m_unpackAlignment;
    427         unsigned long m_implementationColorReadFormat;
    428         unsigned long m_implementationColorReadType;
    429         bool m_unpackFlipY;
    430         bool m_unpackPremultiplyAlpha;
    431 
    432         // Helpers for getParameter and others
    433         WebGLGetInfo getBooleanParameter(unsigned long pname);
    434         WebGLGetInfo getBooleanArrayParameter(unsigned long pname);
    435         WebGLGetInfo getFloatParameter(unsigned long pname);
    436         WebGLGetInfo getIntParameter(unsigned long pname);
    437         WebGLGetInfo getLongParameter(unsigned long pname);
    438         WebGLGetInfo getUnsignedLongParameter(unsigned long pname);
    439         WebGLGetInfo getWebGLFloatArrayParameter(unsigned long pname);
    440         WebGLGetInfo getWebGLIntArrayParameter(unsigned long pname);
    441 
    442         void texImage2DBase(unsigned target, unsigned level, unsigned internalformat,
    443                             unsigned width, unsigned height, unsigned border,
    444                             unsigned format, unsigned type, void* pixels, ExceptionCode&);
    445         void texImage2DImpl(unsigned target, unsigned level, unsigned internalformat,
    446                             unsigned format, unsigned type, Image* image,
    447                             bool flipY, bool premultiplyAlpha, ExceptionCode&);
    448         void texSubImage2DBase(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
    449                                unsigned width, unsigned height,
    450                                unsigned format, unsigned type, void* pixels, ExceptionCode&);
    451         void texSubImage2DImpl(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
    452                                unsigned format, unsigned type,
    453                                Image* image, bool flipY, bool premultiplyAlpha, ExceptionCode&);
    454 
    455         void handleNPOTTextures(bool prepareToDraw);
    456 
    457         void createFallbackBlackTextures1x1();
    458 
    459         // Helper function for copyTex{Sub}Image, check whether the internalformat
    460         // and the color buffer format of the current bound framebuffer combination
    461         // is valid.
    462         bool isTexInternalFormatColorBufferCombinationValid(unsigned long texInternalFormat,
    463                                                             unsigned long colorBufferFormat);
    464 
    465         // Helper function to get the current bound texture.
    466         WebGLTexture* getTextureBinding(unsigned long target);
    467 
    468         // Helper function to check input format/type for functions {copy}Tex{Sub}Image.
    469         // Generates GL error and returns false if parameters are invalid.
    470         bool validateTexFuncFormatAndType(unsigned long format, unsigned long type);
    471 
    472         // Helper function to check input parameters for functions {copy}Tex{Sub}Image.
    473         // Generates GL error and returns false if parameters are invalid.
    474         bool validateTexFuncParameters(unsigned long target, long level,
    475                                        unsigned long internalformat,
    476                                        long width, long height, long border,
    477                                        unsigned long format, unsigned long type);
    478 
    479         // Helper function to validate that the given ArrayBufferView
    480         // is of the correct type and contains enough data for the texImage call.
    481         // Generates GL error and returns false if parameters are invalid.
    482         bool validateTexFuncData(long width, long height,
    483                                  unsigned long format, unsigned long type,
    484                                  ArrayBufferView* pixels);
    485 
    486         // Helper function to validate mode for draw{Arrays/Elements}.
    487         bool validateDrawMode(unsigned long);
    488 
    489         // Helper function for texParameterf and texParameteri.
    490         void texParameter(unsigned long target, unsigned long pname, float parami, int paramf, bool isFloat);
    491 
    492         // Helper function to print warnings to console. Currently
    493         // used only to warn about use of obsolete functions.
    494         void printWarningToConsole(const String& message);
    495 
    496         // Helper function to validate input parameters for framebuffer functions.
    497         // Generate GL error if parameters are illegal.
    498         bool validateFramebufferFuncParameters(unsigned long target, unsigned long attachment);
    499 
    500         // Helper function to validate blend equation mode.
    501         bool validateBlendEquation(unsigned long);
    502 
    503         // Helper function to validate a GL capability.
    504         bool validateCapability(unsigned long);
    505 
    506         // Helper function to validate input parameters for uniform functions.
    507         bool validateUniformParameters(const WebGLUniformLocation* location, Float32Array* v, int mod);
    508         bool validateUniformParameters(const WebGLUniformLocation* location, Int32Array* v, int mod);
    509         bool validateUniformParameters(const WebGLUniformLocation* location, void* v, int size, int mod);
    510         bool validateUniformMatrixParameters(const WebGLUniformLocation* location, bool transpose, Float32Array* v, int mod);
    511         bool validateUniformMatrixParameters(const WebGLUniformLocation* location, bool transpose, void* v, int size, int mod);
    512 
    513         // Helper function to validate parameters for bufferData.
    514         // Return the current bound buffer to target, or 0 if parameters are invalid.
    515         WebGLBuffer* validateBufferDataParameters(unsigned long target, unsigned long usage);
    516 
    517         // Helper functions for vertexAttribNf{v}.
    518         void vertexAttribfImpl(unsigned long index, int expectedSize, float v0, float v1, float v2, float v3);
    519         void vertexAttribfvImpl(unsigned long index, Float32Array* v, int expectedSize);
    520         void vertexAttribfvImpl(unsigned long index, float* v, int size, int expectedSize);
    521 
    522         // Helpers for simulating vertexAttrib0
    523         void initVertexAttrib0();
    524         bool simulateVertexAttrib0(long numVertex);
    525         void restoreStatesAfterVertexAttrib0Simulation();
    526 
    527         friend class WebGLStateRestorer;
    528     };
     450                           unsigned format, unsigned type, void* pixels, ExceptionCode&);
     451    void texSubImage2DImpl(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
     452                           unsigned format, unsigned type,
     453                           Image* image, bool flipY, bool premultiplyAlpha, ExceptionCode&);
     454
     455    void handleNPOTTextures(bool prepareToDraw);
     456
     457    void createFallbackBlackTextures1x1();
     458
     459    // Helper function for copyTex{Sub}Image, check whether the internalformat
     460    // and the color buffer format of the current bound framebuffer combination
     461    // is valid.
     462    bool isTexInternalFormatColorBufferCombinationValid(unsigned long texInternalFormat,
     463                                                        unsigned long colorBufferFormat);
     464
     465    // Helper function to get the current bound texture.
     466    WebGLTexture* getTextureBinding(unsigned long target);
     467
     468    // Helper function to check input format/type for functions {copy}Tex{Sub}Image.
     469    // Generates GL error and returns false if parameters are invalid.
     470    bool validateTexFuncFormatAndType(unsigned long format, unsigned long type);
     471
     472    // Helper function to check input parameters for functions {copy}Tex{Sub}Image.
     473    // Generates GL error and returns false if parameters are invalid.
     474    bool validateTexFuncParameters(unsigned long target, long level,
     475                                   unsigned long internalformat,
     476                                   long width, long height, long border,
     477                                   unsigned long format, unsigned long type);
     478
     479    // Helper function to validate that the given ArrayBufferView
     480    // is of the correct type and contains enough data for the texImage call.
     481    // Generates GL error and returns false if parameters are invalid.
     482    bool validateTexFuncData(long width, long height,
     483                             unsigned long format, unsigned long type,
     484                             ArrayBufferView* pixels);
     485
     486    // Helper function to validate mode for draw{Arrays/Elements}.
     487    bool validateDrawMode(unsigned long);
     488
     489    // Helper function for texParameterf and texParameteri.
     490    void texParameter(unsigned long target, unsigned long pname, float parami, int paramf, bool isFloat);
     491
     492    // Helper function to print warnings to console. Currently
     493    // used only to warn about use of obsolete functions.
     494    void printWarningToConsole(const String& message);
     495
     496    // Helper function to validate input parameters for framebuffer functions.
     497    // Generate GL error if parameters are illegal.
     498    bool validateFramebufferFuncParameters(unsigned long target, unsigned long attachment);
     499
     500    // Helper function to validate blend equation mode.
     501    bool validateBlendEquation(unsigned long);
     502
     503    // Helper function to validate a GL capability.
     504    bool validateCapability(unsigned long);
     505
     506    // Helper function to validate input parameters for uniform functions.
     507    bool validateUniformParameters(const WebGLUniformLocation* location, Float32Array* v, int mod);
     508    bool validateUniformParameters(const WebGLUniformLocation* location, Int32Array* v, int mod);
     509    bool validateUniformParameters(const WebGLUniformLocation* location, void* v, int size, int mod);
     510    bool validateUniformMatrixParameters(const WebGLUniformLocation* location, bool transpose, Float32Array* v, int mod);
     511    bool validateUniformMatrixParameters(const WebGLUniformLocation* location, bool transpose, void* v, int size, int mod);
     512
     513    // Helper function to validate parameters for bufferData.
     514    // Return the current bound buffer to target, or 0 if parameters are invalid.
     515    WebGLBuffer* validateBufferDataParameters(unsigned long target, unsigned long usage);
     516
     517    // Helper functions for vertexAttribNf{v}.
     518    void vertexAttribfImpl(unsigned long index, int expectedSize, float v0, float v1, float v2, float v3);
     519    void vertexAttribfvImpl(unsigned long index, Float32Array* v, int expectedSize);
     520    void vertexAttribfvImpl(unsigned long index, float* v, int size, int expectedSize);
     521
     522    // Helpers for simulating vertexAttrib0
     523    void initVertexAttrib0();
     524    bool simulateVertexAttrib0(long numVertex);
     525    void restoreStatesAfterVertexAttrib0Simulation();
     526
     527    friend class WebGLStateRestorer;
     528};
    529529
    530530} // namespace WebCore
  • trunk/WebCore/html/canvas/WebGLShader.cpp

    r64685 r64767  
    2929
    3030#include "WebGLShader.h"
     31
    3132#include "WebGLRenderingContext.h"
    3233
     
    4546}
    4647
    47 void WebGLShader::_deleteObject(Platform3DObject object)
     48void WebGLShader::deleteObjectImpl(Platform3DObject object)
    4849{
    4950    context()->graphicsContext3D()->deleteShader(object);
  • trunk/WebCore/html/canvas/WebGLShader.h

    r64685 r64767  
    3333
    3434namespace WebCore {
    35    
    36     class WebGLShader : public WebGLObject {
    37     public:
    38         virtual ~WebGLShader() { deleteObject(); }
    39        
    40         static PassRefPtr<WebGLShader> create(WebGLRenderingContext*, GraphicsContext3D::WebGLEnumType);
    4135
    42         GraphicsContext3D::WebGLEnumType getType() const { return m_type; }
     36class WebGLShader : public WebGLObject {
     37public:
     38    virtual ~WebGLShader() { deleteObject(); }
    4339
    44     private:
    45         WebGLShader(WebGLRenderingContext*, GraphicsContext3D::WebGLEnumType);
     40    static PassRefPtr<WebGLShader> create(WebGLRenderingContext*, GraphicsContext3D::WebGLEnumType);
    4641
    47         virtual void _deleteObject(Platform3DObject);
     42    GraphicsContext3D::WebGLEnumType getType() const { return m_type; }
    4843
    49         virtual bool isShader() const { return true; }
     44private:
     45    WebGLShader(WebGLRenderingContext*, GraphicsContext3D::WebGLEnumType);
    5046
    51         GraphicsContext3D::WebGLEnumType m_type;
    52     };
    53    
     47    virtual void deleteObjectImpl(Platform3DObject);
     48
     49    virtual bool isShader() const { return true; }
     50
     51    GraphicsContext3D::WebGLEnumType m_type;
     52};
     53
    5454} // namespace WebCore
    5555
  • trunk/WebCore/html/canvas/WebGLTexture.cpp

    r64685 r64767  
    2929
    3030#include "WebGLTexture.h"
     31
    3132#include "WebGLRenderingContext.h"
    3233
     
    198199}
    199200
    200 void WebGLTexture::_deleteObject(Platform3DObject object)
     201void WebGLTexture::deleteObjectImpl(Platform3DObject object)
    201202{
    202203    context()->graphicsContext3D()->deleteTexture(object);
  • trunk/WebCore/html/canvas/WebGLTexture.h

    r64685 r64767  
    3434
    3535namespace WebCore {
    36    
    37     class WebGLTexture : public WebGLObject {
     36
     37class WebGLTexture : public WebGLObject {
     38public:
     39    virtual ~WebGLTexture() { deleteObject(); }
     40
     41    static PassRefPtr<WebGLTexture> create(WebGLRenderingContext*);
     42
     43    bool isCubeMapRWrapModeInitialized()
     44    {
     45        return cubeMapRWrapModeInitialized;
     46    }
     47
     48    void setCubeMapRWrapModeInitialized(bool initialized)
     49    {
     50        cubeMapRWrapModeInitialized = initialized;
     51    }
     52
     53    void setTarget(unsigned long target, int maxLevel);
     54    void setParameteri(unsigned long pname, int param);
     55    void setParameterf(unsigned long pname, float param);
     56
     57    void setLevelInfo(unsigned long target, int level, unsigned long internalFormat, int width, int height, unsigned long type);
     58
     59    bool canGenerateMipmaps();
     60    // Generate all level information.
     61    void generateMipmapLevelInfo();
     62
     63    unsigned long getInternalFormat() const;
     64
     65    // Whether width/height is NotPowerOfTwo.
     66    static bool isNPOT(unsigned, unsigned);
     67
     68    bool isNPOT() const;
     69    // Determine if texture sampling should always return [0, 0, 0, 1] (OpenGL ES 2.0 Sec 3.8.2).
     70    bool needToUseBlackTexture() const;
     71
     72    static int computeLevelCount(int width, int height);
     73
     74protected:
     75    WebGLTexture(WebGLRenderingContext*);
     76
     77    virtual void deleteObjectImpl(Platform3DObject);
     78
     79private:
     80    virtual bool isTexture() const { return true; }
     81
     82    void update();
     83
     84    int mapTargetToIndex(unsigned long);
     85
     86    bool cubeMapRWrapModeInitialized;
     87
     88    unsigned long m_target;
     89
     90    int m_minFilter;
     91    int m_magFilter;
     92    int m_wrapS;
     93    int m_wrapT;
     94
     95    class LevelInfo {
    3896    public:
    39         virtual ~WebGLTexture() { deleteObject(); }
    40        
    41         static PassRefPtr<WebGLTexture> create(WebGLRenderingContext*);
    42 
    43         bool isCubeMapRWrapModeInitialized() {
    44             return cubeMapRWrapModeInitialized;
     97        LevelInfo()
     98            : valid(false)
     99            , internalFormat(0)
     100            , width(0)
     101            , height(0)
     102            , type(0)
     103        {
    45104        }
    46105
    47         void setCubeMapRWrapModeInitialized(bool initialized) {
    48             cubeMapRWrapModeInitialized = initialized;
     106        void setInfo(unsigned long internalFmt, int w, int h, unsigned long tp)
     107        {
     108            valid = true;
     109            internalFormat = internalFmt;
     110            width = w;
     111            height = h;
     112            type = tp;
    49113        }
    50114
    51         void setTarget(unsigned long target, int maxLevel);
    52         void setParameteri(unsigned long pname, int param);
    53         void setParameterf(unsigned long pname, float param);
     115        bool valid;
     116        unsigned long internalFormat;
     117        int width;
     118        int height;
     119        unsigned long type;
     120    };
    54121
    55         void setLevelInfo(unsigned long target, int level, unsigned long internalFormat, int width, int height, unsigned long type);
     122    Vector<Vector<LevelInfo> > m_info;
    56123
    57         bool canGenerateMipmaps();
    58         // Generate all level information.
    59         void generateMipmapLevelInfo();
     124    bool m_isNPOT;
     125    bool m_isComplete;
     126    bool m_needToUseBlackTexture;
     127};
    60128
    61         unsigned long getInternalFormat() const;
    62 
    63         // Whether width/height is NotPowerOfTwo.
    64         static bool isNPOT(unsigned, unsigned);
    65 
    66         bool isNPOT() const;
    67         // Determine if texture sampling should always return [0, 0, 0, 1] (OpenGL ES 2.0 Sec 3.8.2).
    68         bool needToUseBlackTexture() const;
    69 
    70         static int computeLevelCount(int width, int height);
    71 
    72     protected:
    73         WebGLTexture(WebGLRenderingContext*);
    74 
    75         virtual void _deleteObject(Platform3DObject);
    76 
    77     private:
    78         virtual bool isTexture() const { return true; }
    79 
    80         void update();
    81 
    82         int mapTargetToIndex(unsigned long);
    83 
    84         bool cubeMapRWrapModeInitialized;
    85 
    86         unsigned long m_target;
    87 
    88         int m_minFilter;
    89         int m_magFilter;
    90         int m_wrapS;
    91         int m_wrapT;
    92 
    93         class LevelInfo {
    94         public:
    95             LevelInfo()
    96                 : valid(false)
    97                 , internalFormat(0)
    98                 , width(0)
    99                 , height(0)
    100                 , type(0)
    101             {
    102             }
    103 
    104             void setInfo(unsigned long internalFmt, int w, int h, unsigned long tp)
    105             {
    106                 valid = true;
    107                 internalFormat = internalFmt;
    108                 width = w;
    109                 height = h;
    110                 type = tp;
    111             }
    112 
    113             bool valid;
    114             unsigned long internalFormat;
    115             int width;
    116             int height;
    117             unsigned long type;
    118         };
    119 
    120         Vector<Vector<LevelInfo> > m_info;
    121 
    122         bool m_isNPOT;
    123         bool m_isComplete;
    124         bool m_needToUseBlackTexture;
    125     };
    126    
    127129} // namespace WebCore
    128130
  • trunk/WebCore/platform/graphics/GraphicsContext3D.h

    r64582 r64767  
    4444
    4545typedef CGLContextObj PlatformGraphicsContext3D;
    46 const  PlatformGraphicsContext3D NullPlatformGraphicsContext3D = 0;
     46const PlatformGraphicsContext3D NullPlatformGraphicsContext3D = 0;
    4747typedef GLuint Platform3DObject;
    4848const Platform3DObject NullPlatform3DObject = 0;
     
    5959class QRect;
    6060typedef void* PlatformGraphicsContext3D;
    61 const  PlatformGraphicsContext3D NullPlatformGraphicsContext3D = 0;
     61const PlatformGraphicsContext3D NullPlatformGraphicsContext3D = 0;
    6262typedef int Platform3DObject;
    6363const Platform3DObject NullPlatform3DObject = 0;
    6464#else
    6565typedef void* PlatformGraphicsContext3D;
    66 const  PlatformGraphicsContext3D NullPlatformGraphicsContext3D = 0;
     66const PlatformGraphicsContext3D NullPlatformGraphicsContext3D = 0;
    6767typedef int Platform3DObject;
    6868const Platform3DObject NullPlatform3DObject = 0;
     
    7474
    7575namespace WebCore {
    76     class ArrayBuffer;
    77     class ArrayBufferView;
    78     class CanvasRenderingContext;
    79     class Float32Array;
    80     class HostWindow;
    81     class Image;
    82     class ImageData;
    83     class Int32Array;
    84     class Uint8Array;
    85     class WebGLActiveInfo;
    86 
    87     struct ActiveInfo {
    88         String name;
    89         unsigned type;
    90         int size;
     76class ArrayBuffer;
     77class ArrayBufferView;
     78class CanvasRenderingContext;
     79class Float32Array;
     80class HostWindow;
     81class Image;
     82class ImageData;
     83class Int32Array;
     84class Uint8Array;
     85class WebGLActiveInfo;
     86
     87struct ActiveInfo {
     88    String name;
     89    unsigned type;
     90    int size;
     91};
     92
     93// FIXME: ideally this would be used on all platforms.
     94#if PLATFORM(CHROMIUM) || PLATFORM(QT)
     95class GraphicsContext3DInternal;
     96#endif
     97
     98class GraphicsContext3D : public Noncopyable {
     99public:
     100    enum WebGLEnumType {
     101        DEPTH_BUFFER_BIT = 0x00000100,
     102        STENCIL_BUFFER_BIT = 0x00000400,
     103        COLOR_BUFFER_BIT = 0x00004000,
     104        POINTS = 0x0000,
     105        LINES = 0x0001,
     106        LINE_LOOP = 0x0002,
     107        LINE_STRIP = 0x0003,
     108        TRIANGLES = 0x0004,
     109        TRIANGLE_STRIP = 0x0005,
     110        TRIANGLE_FAN = 0x0006,
     111        ZERO = 0,
     112        ONE = 1,
     113        SRC_COLOR = 0x0300,
     114        ONE_MINUS_SRC_COLOR = 0x0301,
     115        SRC_ALPHA = 0x0302,
     116        ONE_MINUS_SRC_ALPHA = 0x0303,
     117        DST_ALPHA = 0x0304,
     118        ONE_MINUS_DST_ALPHA = 0x0305,
     119        DST_COLOR = 0x0306,
     120        ONE_MINUS_DST_COLOR = 0x0307,
     121        SRC_ALPHA_SATURATE = 0x0308,
     122        FUNC_ADD = 0x8006,
     123        BLEND_EQUATION = 0x8009,
     124        BLEND_EQUATION_RGB = 0x8009,
     125        BLEND_EQUATION_ALPHA = 0x883D,
     126        FUNC_SUBTRACT = 0x800A,
     127        FUNC_REVERSE_SUBTRACT = 0x800B,
     128        BLEND_DST_RGB = 0x80C8,
     129        BLEND_SRC_RGB = 0x80C9,
     130        BLEND_DST_ALPHA = 0x80CA,
     131        BLEND_SRC_ALPHA = 0x80CB,
     132        CONSTANT_COLOR = 0x8001,
     133        ONE_MINUS_CONSTANT_COLOR = 0x8002,
     134        CONSTANT_ALPHA = 0x8003,
     135        ONE_MINUS_CONSTANT_ALPHA = 0x8004,
     136        BLEND_COLOR = 0x8005,
     137        ARRAY_BUFFER = 0x8892,
     138        ELEMENT_ARRAY_BUFFER = 0x8893,
     139        ARRAY_BUFFER_BINDING = 0x8894,
     140        ELEMENT_ARRAY_BUFFER_BINDING = 0x8895,
     141        STREAM_DRAW = 0x88E0,
     142        STATIC_DRAW = 0x88E4,
     143        DYNAMIC_DRAW = 0x88E8,
     144        BUFFER_SIZE = 0x8764,
     145        BUFFER_USAGE = 0x8765,
     146        CURRENT_VERTEX_ATTRIB = 0x8626,
     147        FRONT = 0x0404,
     148        BACK = 0x0405,
     149        FRONT_AND_BACK = 0x0408,
     150        TEXTURE_2D = 0x0DE1,
     151        CULL_FACE = 0x0B44,
     152        BLEND = 0x0BE2,
     153        DITHER = 0x0BD0,
     154        STENCIL_TEST = 0x0B90,
     155        DEPTH_TEST = 0x0B71,
     156        SCISSOR_TEST = 0x0C11,
     157        POLYGON_OFFSET_FILL = 0x8037,
     158        SAMPLE_ALPHA_TO_COVERAGE = 0x809E,
     159        SAMPLE_COVERAGE = 0x80A0,
     160        NO_ERROR = 0,
     161        INVALID_ENUM = 0x0500,
     162        INVALID_VALUE = 0x0501,
     163        INVALID_OPERATION = 0x0502,
     164        OUT_OF_MEMORY = 0x0505,
     165        CW = 0x0900,
     166        CCW = 0x0901,
     167        LINE_WIDTH = 0x0B21,
     168        ALIASED_POINT_SIZE_RANGE = 0x846D,
     169        ALIASED_LINE_WIDTH_RANGE = 0x846E,
     170        CULL_FACE_MODE = 0x0B45,
     171        FRONT_FACE = 0x0B46,
     172        DEPTH_RANGE = 0x0B70,
     173        DEPTH_WRITEMASK = 0x0B72,
     174        DEPTH_CLEAR_VALUE = 0x0B73,
     175        DEPTH_FUNC = 0x0B74,
     176        STENCIL_CLEAR_VALUE = 0x0B91,
     177        STENCIL_FUNC = 0x0B92,
     178        STENCIL_FAIL = 0x0B94,
     179        STENCIL_PASS_DEPTH_FAIL = 0x0B95,
     180        STENCIL_PASS_DEPTH_PASS = 0x0B96,
     181        STENCIL_REF = 0x0B97,
     182        STENCIL_VALUE_MASK = 0x0B93,
     183        STENCIL_WRITEMASK = 0x0B98,
     184        STENCIL_BACK_FUNC = 0x8800,
     185        STENCIL_BACK_FAIL = 0x8801,
     186        STENCIL_BACK_PASS_DEPTH_FAIL = 0x8802,
     187        STENCIL_BACK_PASS_DEPTH_PASS = 0x8803,
     188        STENCIL_BACK_REF = 0x8CA3,
     189        STENCIL_BACK_VALUE_MASK = 0x8CA4,
     190        STENCIL_BACK_WRITEMASK = 0x8CA5,
     191        VIEWPORT = 0x0BA2,
     192        SCISSOR_BOX = 0x0C10,
     193        COLOR_CLEAR_VALUE = 0x0C22,
     194        COLOR_WRITEMASK = 0x0C23,
     195        UNPACK_ALIGNMENT = 0x0CF5,
     196        PACK_ALIGNMENT = 0x0D05,
     197        MAX_TEXTURE_SIZE = 0x0D33,
     198        MAX_VIEWPORT_DIMS = 0x0D3A,
     199        SUBPIXEL_BITS = 0x0D50,
     200        RED_BITS = 0x0D52,
     201        GREEN_BITS = 0x0D53,
     202        BLUE_BITS = 0x0D54,
     203        ALPHA_BITS = 0x0D55,
     204        DEPTH_BITS = 0x0D56,
     205        STENCIL_BITS = 0x0D57,
     206        POLYGON_OFFSET_UNITS = 0x2A00,
     207        POLYGON_OFFSET_FACTOR = 0x8038,
     208        TEXTURE_BINDING_2D = 0x8069,
     209        SAMPLE_BUFFERS = 0x80A8,
     210        SAMPLES = 0x80A9,
     211        SAMPLE_COVERAGE_VALUE = 0x80AA,
     212        SAMPLE_COVERAGE_INVERT = 0x80AB,
     213        NUM_COMPRESSED_TEXTURE_FORMATS = 0x86A2,
     214        COMPRESSED_TEXTURE_FORMATS = 0x86A3,
     215        DONT_CARE = 0x1100,
     216        FASTEST = 0x1101,
     217        NICEST = 0x1102,
     218        GENERATE_MIPMAP_HINT = 0x8192,
     219        BYTE = 0x1400,
     220        UNSIGNED_BYTE = 0x1401,
     221        SHORT = 0x1402,
     222        UNSIGNED_SHORT = 0x1403,
     223        INT = 0x1404,
     224        UNSIGNED_INT = 0x1405,
     225        FLOAT = 0x1406,
     226        FIXED = 0x140C,
     227        DEPTH_COMPONENT = 0x1902,
     228        ALPHA = 0x1906,
     229        RGB = 0x1907,
     230        RGBA = 0x1908,
     231        LUMINANCE = 0x1909,
     232        LUMINANCE_ALPHA = 0x190A,
     233        UNSIGNED_SHORT_4_4_4_4 = 0x8033,
     234        UNSIGNED_SHORT_5_5_5_1 = 0x8034,
     235        UNSIGNED_SHORT_5_6_5 = 0x8363,
     236        FRAGMENT_SHADER = 0x8B30,
     237        VERTEX_SHADER = 0x8B31,
     238        MAX_VERTEX_ATTRIBS = 0x8869,
     239        MAX_VERTEX_UNIFORM_VECTORS = 0x8DFB,
     240        MAX_VARYING_VECTORS = 0x8DFC,
     241        MAX_COMBINED_TEXTURE_IMAGE_UNITS = 0x8B4D,
     242        MAX_VERTEX_TEXTURE_IMAGE_UNITS = 0x8B4C,
     243        MAX_TEXTURE_IMAGE_UNITS = 0x8872,
     244        MAX_FRAGMENT_UNIFORM_VECTORS = 0x8DFD,
     245        SHADER_TYPE = 0x8B4F,
     246        DELETE_STATUS = 0x8B80,
     247        LINK_STATUS = 0x8B82,
     248        VALIDATE_STATUS = 0x8B83,
     249        ATTACHED_SHADERS = 0x8B85,
     250        ACTIVE_UNIFORMS = 0x8B86,
     251        ACTIVE_UNIFORM_MAX_LENGTH = 0x8B87,
     252        ACTIVE_ATTRIBUTES = 0x8B89,
     253        ACTIVE_ATTRIBUTE_MAX_LENGTH = 0x8B8A,
     254        SHADING_LANGUAGE_VERSION = 0x8B8C,
     255        CURRENT_PROGRAM = 0x8B8D,
     256        NEVER = 0x0200,
     257        LESS = 0x0201,
     258        EQUAL = 0x0202,
     259        LEQUAL = 0x0203,
     260        GREATER = 0x0204,
     261        NOTEQUAL = 0x0205,
     262        GEQUAL = 0x0206,
     263        ALWAYS = 0x0207,
     264        KEEP = 0x1E00,
     265        REPLACE = 0x1E01,
     266        INCR = 0x1E02,
     267        DECR = 0x1E03,
     268        INVERT = 0x150A,
     269        INCR_WRAP = 0x8507,
     270        DECR_WRAP = 0x8508,
     271        VENDOR = 0x1F00,
     272        RENDERER = 0x1F01,
     273        VERSION = 0x1F02,
     274        EXTENSIONS = 0x1F03,
     275        NEAREST = 0x2600,
     276        LINEAR = 0x2601,
     277        NEAREST_MIPMAP_NEAREST = 0x2700,
     278        LINEAR_MIPMAP_NEAREST = 0x2701,
     279        NEAREST_MIPMAP_LINEAR = 0x2702,
     280        LINEAR_MIPMAP_LINEAR = 0x2703,
     281        TEXTURE_MAG_FILTER = 0x2800,
     282        TEXTURE_MIN_FILTER = 0x2801,
     283        TEXTURE_WRAP_S = 0x2802,
     284        TEXTURE_WRAP_T = 0x2803,
     285        TEXTURE = 0x1702,
     286        TEXTURE_CUBE_MAP = 0x8513,
     287        TEXTURE_BINDING_CUBE_MAP = 0x8514,
     288        TEXTURE_CUBE_MAP_POSITIVE_X = 0x8515,
     289        TEXTURE_CUBE_MAP_NEGATIVE_X = 0x8516,
     290        TEXTURE_CUBE_MAP_POSITIVE_Y = 0x8517,
     291        TEXTURE_CUBE_MAP_NEGATIVE_Y = 0x8518,
     292        TEXTURE_CUBE_MAP_POSITIVE_Z = 0x8519,
     293        TEXTURE_CUBE_MAP_NEGATIVE_Z = 0x851A,
     294        MAX_CUBE_MAP_TEXTURE_SIZE = 0x851C,
     295        TEXTURE0 = 0x84C0,
     296        TEXTURE1 = 0x84C1,
     297        TEXTURE2 = 0x84C2,
     298        TEXTURE3 = 0x84C3,
     299        TEXTURE4 = 0x84C4,
     300        TEXTURE5 = 0x84C5,
     301        TEXTURE6 = 0x84C6,
     302        TEXTURE7 = 0x84C7,
     303        TEXTURE8 = 0x84C8,
     304        TEXTURE9 = 0x84C9,
     305        TEXTURE10 = 0x84CA,
     306        TEXTURE11 = 0x84CB,
     307        TEXTURE12 = 0x84CC,
     308        TEXTURE13 = 0x84CD,
     309        TEXTURE14 = 0x84CE,
     310        TEXTURE15 = 0x84CF,
     311        TEXTURE16 = 0x84D0,
     312        TEXTURE17 = 0x84D1,
     313        TEXTURE18 = 0x84D2,
     314        TEXTURE19 = 0x84D3,
     315        TEXTURE20 = 0x84D4,
     316        TEXTURE21 = 0x84D5,
     317        TEXTURE22 = 0x84D6,
     318        TEXTURE23 = 0x84D7,
     319        TEXTURE24 = 0x84D8,
     320        TEXTURE25 = 0x84D9,
     321        TEXTURE26 = 0x84DA,
     322        TEXTURE27 = 0x84DB,
     323        TEXTURE28 = 0x84DC,
     324        TEXTURE29 = 0x84DD,
     325        TEXTURE30 = 0x84DE,
     326        TEXTURE31 = 0x84DF,
     327        ACTIVE_TEXTURE = 0x84E0,
     328        REPEAT = 0x2901,
     329        CLAMP_TO_EDGE = 0x812F,
     330        MIRRORED_REPEAT = 0x8370,
     331        FLOAT_VEC2 = 0x8B50,
     332        FLOAT_VEC3 = 0x8B51,
     333        FLOAT_VEC4 = 0x8B52,
     334        INT_VEC2 = 0x8B53,
     335        INT_VEC3 = 0x8B54,
     336        INT_VEC4 = 0x8B55,
     337        BOOL = 0x8B56,
     338        BOOL_VEC2 = 0x8B57,
     339        BOOL_VEC3 = 0x8B58,
     340        BOOL_VEC4 = 0x8B59,
     341        FLOAT_MAT2 = 0x8B5A,
     342        FLOAT_MAT3 = 0x8B5B,
     343        FLOAT_MAT4 = 0x8B5C,
     344        SAMPLER_2D = 0x8B5E,
     345        SAMPLER_CUBE = 0x8B60,
     346        VERTEX_ATTRIB_ARRAY_ENABLED = 0x8622,
     347        VERTEX_ATTRIB_ARRAY_SIZE = 0x8623,
     348        VERTEX_ATTRIB_ARRAY_STRIDE = 0x8624,
     349        VERTEX_ATTRIB_ARRAY_TYPE = 0x8625,
     350        VERTEX_ATTRIB_ARRAY_NORMALIZED = 0x886A,
     351        VERTEX_ATTRIB_ARRAY_POINTER = 0x8645,
     352        VERTEX_ATTRIB_ARRAY_BUFFER_BINDING = 0x889F,
     353        IMPLEMENTATION_COLOR_READ_TYPE = 0x8B9A,
     354        IMPLEMENTATION_COLOR_READ_FORMAT = 0x8B9B,
     355        COMPILE_STATUS = 0x8B81,
     356        INFO_LOG_LENGTH = 0x8B84,
     357        SHADER_SOURCE_LENGTH = 0x8B88,
     358        SHADER_COMPILER = 0x8DFA,
     359        SHADER_BINARY_FORMATS = 0x8DF8,
     360        NUM_SHADER_BINARY_FORMATS = 0x8DF9,
     361        LOW_FLOAT = 0x8DF0,
     362        MEDIUM_FLOAT = 0x8DF1,
     363        HIGH_FLOAT = 0x8DF2,
     364        LOW_INT = 0x8DF3,
     365        MEDIUM_INT = 0x8DF4,
     366        HIGH_INT = 0x8DF5,
     367        FRAMEBUFFER = 0x8D40,
     368        RENDERBUFFER = 0x8D41,
     369        RGBA4 = 0x8056,
     370        RGB5_A1 = 0x8057,
     371        RGB565 = 0x8D62,
     372        DEPTH_COMPONENT16 = 0x81A5,
     373        STENCIL_INDEX = 0x1901,
     374        STENCIL_INDEX8 = 0x8D48,
     375        DEPTH_STENCIL = 0x84F9,
     376        RENDERBUFFER_WIDTH = 0x8D42,
     377        RENDERBUFFER_HEIGHT = 0x8D43,
     378        RENDERBUFFER_INTERNAL_FORMAT = 0x8D44,
     379        RENDERBUFFER_RED_SIZE = 0x8D50,
     380        RENDERBUFFER_GREEN_SIZE = 0x8D51,
     381        RENDERBUFFER_BLUE_SIZE = 0x8D52,
     382        RENDERBUFFER_ALPHA_SIZE = 0x8D53,
     383        RENDERBUFFER_DEPTH_SIZE = 0x8D54,
     384        RENDERBUFFER_STENCIL_SIZE = 0x8D55,
     385        FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE = 0x8CD0,
     386        FRAMEBUFFER_ATTACHMENT_OBJECT_NAME = 0x8CD1,
     387        FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL = 0x8CD2,
     388        FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE = 0x8CD3,
     389        COLOR_ATTACHMENT0 = 0x8CE0,
     390        DEPTH_ATTACHMENT = 0x8D00,
     391        STENCIL_ATTACHMENT = 0x8D20,
     392        DEPTH_STENCIL_ATTACHMENT = 0x821A,
     393        NONE = 0,
     394        FRAMEBUFFER_COMPLETE = 0x8CD5,
     395        FRAMEBUFFER_INCOMPLETE_ATTACHMENT = 0x8CD6,
     396        FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT = 0x8CD7,
     397        FRAMEBUFFER_INCOMPLETE_DIMENSIONS = 0x8CD9,
     398        FRAMEBUFFER_UNSUPPORTED = 0x8CDD,
     399        FRAMEBUFFER_BINDING = 0x8CA6,
     400        RENDERBUFFER_BINDING = 0x8CA7,
     401        MAX_RENDERBUFFER_SIZE = 0x84E8,
     402        INVALID_FRAMEBUFFER_OPERATION = 0x0506,
     403
     404        // WebGL-specific enums
     405        UNPACK_FLIP_Y_WEBGL = 0x9240,
     406        UNPACK_PREMULTIPLY_ALPHA_WEBGL = 0x9241
    91407    };
     408
     409    // Context creation attributes.
     410    struct Attributes {
     411        Attributes()
     412            : alpha(true)
     413            , depth(true)
     414            , stencil(false)
     415            , antialias(true)
     416            , premultipliedAlpha(true)
     417        {
     418        }
     419
     420        bool alpha;
     421        bool depth;
     422        bool stencil;
     423        bool antialias;
     424        bool premultipliedAlpha;
     425    };
     426
     427    static PassOwnPtr<GraphicsContext3D> create(Attributes attrs, HostWindow* hostWindow);
     428    virtual ~GraphicsContext3D();
     429
     430#if PLATFORM(MAC)
     431    PlatformGraphicsContext3D platformGraphicsContext3D() const { return m_contextObj; }
     432    Platform3DObject platformTexture() const { return m_texture; }
     433    CALayer* platformLayer() const { return static_cast<CALayer*>(m_webGLLayer.get()); }
     434#elif PLATFORM(CHROMIUM)
     435    PlatformGraphicsContext3D platformGraphicsContext3D() const;
     436    Platform3DObject platformTexture() const;
     437#if USE(ACCELERATED_COMPOSITING)
     438    PlatformLayer* platformLayer() const;
     439#endif
     440#elif PLATFORM(QT)
     441    PlatformGraphicsContext3D platformGraphicsContext3D();
     442    Platform3DObject platformTexture() const;
     443#if USE(ACCELERATED_COMPOSITING)
     444    PlatformLayer* platformLayer() const { return 0; }
     445#endif
     446#else
     447    PlatformGraphicsContext3D platformGraphicsContext3D() const { return NullPlatformGraphicsContext3D; }
     448    Platform3DObject platformTexture() const { return NullPlatform3DObject; }
     449#if USE(ACCELERATED_COMPOSITING)
     450    PlatformLayer* platformLayer() const { return 0; }
     451#endif
     452#endif
     453    void makeContextCurrent();
     454
     455#if PLATFORM(MAC) || PLATFORM(CHROMIUM)
     456    // With multisampling on, blit from multisampleFBO to regular FBO.
     457    void prepareTexture();
     458#endif
     459
     460    // Helper to return the size in bytes of OpenGL data types
     461    // like GL_FLOAT, GL_INT, etc.
     462    int sizeInBytes(int type);
     463
     464    bool isGLES2Compliant() const;
     465
     466    //----------------------------------------------------------------------
     467    // Helpers for texture uploading and pixel readback.
     468    //
     469
     470    // Computes the components per pixel and bytes per component
     471    // for the given format and type combination. Returns false if
     472    // either was an invalid enum.
     473    bool computeFormatAndTypeParameters(unsigned int format,
     474                                        unsigned int type,
     475                                        unsigned long* componentsPerPixel,
     476                                        unsigned long* bytesPerComponent);
     477
     478    // Extracts the contents of the given Image into the passed Vector,
     479    // packing the pixel data according to the given format and type,
     480    // and obeying the flipY and premultiplyAlpha flags. Returns true
     481    // upon success.
     482    bool extractImageData(Image* image,
     483                          unsigned int format,
     484                          unsigned int type,
     485                          bool flipY,
     486                          bool premultiplyAlpha,
     487                          Vector<uint8_t>& data);
     488
     489    // Extracts the contents of the given ImageData into the passed Vector,
     490    // packing the pixel data according to the given format and type,
     491    // and obeying the flipY and premultiplyAlpha flags. Returns true
     492    // upon success.
     493    bool extractImageData(ImageData*,
     494                          unsigned int format,
     495                          unsigned int type,
     496                          bool flipY,
     497                          bool premultiplyAlpha,
     498                          Vector<uint8_t>& data);
     499
     500    // Helper function which extracts the user-supplied texture
     501    // data, applying the flipY and premultiplyAlpha parameters.
     502    // If the data is not tightly packed according to the passed
     503    // unpackAlignment, the output data will be tightly packed.
     504    // Returns true if successful, false if any error occurred.
     505    bool extractTextureData(unsigned int width, unsigned int height,
     506                            unsigned int format, unsigned int type,
     507                            unsigned int unpackAlignment,
     508                            bool flipY, bool premultiplyAlpha,
     509                            ArrayBufferView* pixels,
     510                            Vector<uint8_t>& data);
     511
     512    // Flips the given image data vertically, in-place.
     513    void flipVertically(void* imageData,
     514                        unsigned int width,
     515                        unsigned int height,
     516                        unsigned int bytesPerPixel,
     517                        unsigned int unpackAlignment);
     518
     519    // Attempt to enumerate all possible native image formats to
     520    // reduce the amount of temporary allocations during texture
     521    // uploading. This enum must be public because it is accessed
     522    // by non-member functions.
     523    enum SourceDataFormat {
     524        kSourceFormatRGBA8,
     525        kSourceFormatRGB8,
     526        kSourceFormatBGRA8,
     527        kSourceFormatRGBA5551,
     528        kSourceFormatRGBA4444,
     529        kSourceFormatRGB565,
     530        kSourceFormatR8,
     531        kSourceFormatRA8,
     532        kSourceFormatA8
     533    };
     534
     535    //----------------------------------------------------------------------
     536    // Entry points for WebGL.
     537    //
     538
     539    void activeTexture(unsigned long texture);
     540    void attachShader(Platform3DObject program, Platform3DObject shader);
     541    void bindAttribLocation(Platform3DObject, unsigned long index, const String& name);
     542    void bindBuffer(unsigned long target, Platform3DObject);
     543    void bindFramebuffer(unsigned long target, Platform3DObject);
     544    void bindRenderbuffer(unsigned long target, Platform3DObject);
     545    void bindTexture(unsigned long target, Platform3DObject texture);
     546    void blendColor(double red, double green, double blue, double alpha);
     547    void blendEquation(unsigned long mode);
     548    void blendEquationSeparate(unsigned long modeRGB, unsigned long modeAlpha);
     549    void blendFunc(unsigned long sfactor, unsigned long dfactor);
     550    void blendFuncSeparate(unsigned long srcRGB, unsigned long dstRGB, unsigned long srcAlpha, unsigned long dstAlpha);
     551
     552    void bufferData(unsigned long target, int size, unsigned long usage);
     553    void bufferData(unsigned long target, ArrayBuffer* data, unsigned long usage);
     554    void bufferData(unsigned long target, ArrayBufferView* data, unsigned long usage);
     555    void bufferSubData(unsigned long target, long offset, ArrayBuffer* data);
     556    void bufferSubData(unsigned long target, long offset, ArrayBufferView* data);
     557
     558    unsigned long checkFramebufferStatus(unsigned long target);
     559    void clear(unsigned long mask);
     560    void clearColor(double red, double green, double blue, double alpha);
     561    void clearDepth(double depth);
     562    void clearStencil(long s);
     563    void colorMask(bool red, bool green, bool blue, bool alpha);
     564    void compileShader(Platform3DObject);
     565
     566    // void compressedTexImage2D(unsigned long target, long level, unsigned long internalformat, unsigned long width, unsigned long height, long border, unsigned long imageSize, const void* data);
     567    // void compressedTexSubImage2D(unsigned long target, long level, long xoffset, long yoffset, unsigned long width, unsigned long height, unsigned long format, unsigned long imageSize, const void* data);
     568
     569    void copyTexImage2D(unsigned long target, long level, unsigned long internalformat, long x, long y, unsigned long width, unsigned long height, long border);
     570    void copyTexSubImage2D(unsigned long target, long level, long xoffset, long yoffset, long x, long y, unsigned long width, unsigned long height);
     571    void cullFace(unsigned long mode);
     572    void depthFunc(unsigned long func);
     573    void depthMask(bool flag);
     574    void depthRange(double zNear, double zFar);
     575    void detachShader(Platform3DObject, Platform3DObject);
     576    void disable(unsigned long cap);
     577    void disableVertexAttribArray(unsigned long index);
     578    void drawArrays(unsigned long mode, long first, long count);
     579    void drawElements(unsigned long mode, unsigned long count, unsigned long type, long offset);
     580
     581    void enable(unsigned long cap);
     582    void enableVertexAttribArray(unsigned long index);
     583    void finish();
     584    void flush();
     585    void framebufferRenderbuffer(unsigned long target, unsigned long attachment, unsigned long renderbuffertarget, Platform3DObject);
     586    void framebufferTexture2D(unsigned long target, unsigned long attachment, unsigned long textarget, Platform3DObject, long level);
     587    void frontFace(unsigned long mode);
     588    void generateMipmap(unsigned long target);
     589
     590    bool getActiveAttrib(Platform3DObject program, unsigned long index, ActiveInfo&);
     591    bool getActiveUniform(Platform3DObject program, unsigned long index, ActiveInfo&);
     592
     593    void getAttachedShaders(Platform3DObject program, int maxCount, int* count, unsigned int* shaders);
     594
     595    int getAttribLocation(Platform3DObject, const String& name);
     596
     597    void getBooleanv(unsigned long pname, unsigned char* value);
     598
     599    void getBufferParameteriv(unsigned long target, unsigned long pname, int* value);
     600
     601    Attributes getContextAttributes();
     602
     603    unsigned long getError();
     604
     605    void getFloatv(unsigned long pname, float* value);
     606
     607    void getFramebufferAttachmentParameteriv(unsigned long target, unsigned long attachment, unsigned long pname, int* value);
     608
     609    void getIntegerv(unsigned long pname, int* value);
     610
     611    void getProgramiv(Platform3DObject program, unsigned long pname, int* value);
     612
     613    String getProgramInfoLog(Platform3DObject);
     614
     615    void getRenderbufferParameteriv(unsigned long target, unsigned long pname, int* value);
     616
     617    void getShaderiv(Platform3DObject, unsigned long pname, int* value);
     618
     619    String getShaderInfoLog(Platform3DObject);
     620
     621    // TBD
     622    // void glGetShaderPrecisionFormat (GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision);
     623
     624    String getShaderSource(Platform3DObject);
     625    String getString(unsigned long name);
     626
     627    void getTexParameterfv(unsigned long target, unsigned long pname, float* value);
     628    void getTexParameteriv(unsigned long target, unsigned long pname, int* value);
     629
     630    void getUniformfv(Platform3DObject program, long location, float* value);
     631    void getUniformiv(Platform3DObject program, long location, int* value);
     632
     633    long getUniformLocation(Platform3DObject, const String& name);
     634
     635    void getVertexAttribfv(unsigned long index, unsigned long pname, float* value);
     636    void getVertexAttribiv(unsigned long index, unsigned long pname, int* value);
     637
     638    long getVertexAttribOffset(unsigned long index, unsigned long pname);
     639
     640    void hint(unsigned long target, unsigned long mode);
     641    bool isBuffer(Platform3DObject);
     642    bool isEnabled(unsigned long cap);
     643    bool isFramebuffer(Platform3DObject);
     644    bool isProgram(Platform3DObject);
     645    bool isRenderbuffer(Platform3DObject);
     646    bool isShader(Platform3DObject);
     647    bool isTexture(Platform3DObject);
     648    void lineWidth(double);
     649    void linkProgram(Platform3DObject);
     650    void pixelStorei(unsigned long pname, long param);
     651    void polygonOffset(double factor, double units);
     652
     653    void readPixels(long x, long y, unsigned long width, unsigned long height, unsigned long format, unsigned long type, void* data);
     654
     655    void releaseShaderCompiler();
     656    void renderbufferStorage(unsigned long target, unsigned long internalformat, unsigned long width, unsigned long height);
     657    void sampleCoverage(double value, bool invert);
     658    void scissor(long x, long y, unsigned long width, unsigned long height);
     659    void shaderSource(Platform3DObject, const String& string);
     660    void stencilFunc(unsigned long func, long ref, unsigned long mask);
     661    void stencilFuncSeparate(unsigned long face, unsigned long func, long ref, unsigned long mask);
     662    void stencilMask(unsigned long mask);
     663    void stencilMaskSeparate(unsigned long face, unsigned long mask);
     664    void stencilOp(unsigned long fail, unsigned long zfail, unsigned long zpass);
     665    void stencilOpSeparate(unsigned long face, unsigned long fail, unsigned long zfail, unsigned long zpass);
     666
     667    int texImage2D(unsigned target, unsigned level, unsigned internalformat, unsigned width, unsigned height, unsigned border, unsigned format, unsigned type, void* pixels);
     668
     669    void texParameterf(unsigned target, unsigned pname, float param);
     670    void texParameteri(unsigned target, unsigned pname, int param);
     671
     672    int texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, unsigned width, unsigned height, unsigned format, unsigned type, void* pixels);
     673
     674    void uniform1f(long location, float x);
     675    void uniform1fv(long location, float* v, int size);
     676    void uniform1i(long location, int x);
     677    void uniform1iv(long location, int* v, int size);
     678    void uniform2f(long location, float x, float y);
     679    void uniform2fv(long location, float* v, int size);
     680    void uniform2i(long location, int x, int y);
     681    void uniform2iv(long location, int* v, int size);
     682    void uniform3f(long location, float x, float y, float z);
     683    void uniform3fv(long location, float* v, int size);
     684    void uniform3i(long location, int x, int y, int z);
     685    void uniform3iv(long location, int* v, int size);
     686    void uniform4f(long location, float x, float y, float z, float w);
     687    void uniform4fv(long location, float* v, int size);
     688    void uniform4i(long location, int x, int y, int z, int w);
     689    void uniform4iv(long location, int* v, int size);
     690    void uniformMatrix2fv(long location, bool transpose, float* value, int size);
     691    void uniformMatrix3fv(long location, bool transpose, float* value, int size);
     692    void uniformMatrix4fv(long location, bool transpose, float* value, int size);
     693
     694    void useProgram(Platform3DObject);
     695    void validateProgram(Platform3DObject);
     696
     697    void vertexAttrib1f(unsigned long indx, float x);
     698    void vertexAttrib1fv(unsigned long indx, float* values);
     699    void vertexAttrib2f(unsigned long indx, float x, float y);
     700    void vertexAttrib2fv(unsigned long indx, float* values);
     701    void vertexAttrib3f(unsigned long indx, float x, float y, float z);
     702    void vertexAttrib3fv(unsigned long indx, float* values);
     703    void vertexAttrib4f(unsigned long indx, float x, float y, float z, float w);
     704    void vertexAttrib4fv(unsigned long indx, float* values);
     705    void vertexAttribPointer(unsigned long indx, int size, int type, bool normalized,
     706                             unsigned long stride, unsigned long offset);
     707
     708    void viewport(long x, long y, unsigned long width, unsigned long height);
     709
     710    void reshape(int width, int height);
     711
     712#if PLATFORM(CG)
     713    void paintToCanvas(const unsigned char* imagePixels, int imageWidth, int imageHeight,
     714                       int canvasWidth, int canvasHeight, CGContextRef context);
     715#endif
     716
     717    void paintRenderingResultsToCanvas(CanvasRenderingContext* context);
     718
     719    // Helpers for notification about paint events
     720    void beginPaint(CanvasRenderingContext* context);
     721    void endPaint();
     722#if PLATFORM(QT)
     723    void paint(QPainter* painter, const QRect& rect) const;
     724#endif
     725
     726    // Support for buffer creation and deletion
     727    unsigned createBuffer();
     728    unsigned createFramebuffer();
     729    unsigned createProgram();
     730    unsigned createRenderbuffer();
     731    unsigned createShader(unsigned long);
     732    unsigned createTexture();
     733
     734    void deleteBuffer(unsigned);
     735    void deleteFramebuffer(unsigned);
     736    void deleteProgram(unsigned);
     737    void deleteRenderbuffer(unsigned);
     738    void deleteShader(unsigned);
     739    void deleteTexture(unsigned);
     740
     741    // Synthesizes an OpenGL error which will be returned from a
     742    // later call to getError. This is used to emulate OpenGL ES
     743    // 2.0 behavior on the desktop and to enforce additional error
     744    // checking mandated by WebGL.
     745    //
     746    // Per the behavior of glGetError, this stores at most one
     747    // instance of any given error, and returns them from calls to
     748    // getError in the order they were added.
     749    void synthesizeGLError(unsigned long error);
     750
     751  private:
     752    GraphicsContext3D(Attributes attrs, HostWindow* hostWindow);
     753
     754    // Each platform must provide an implementation of this method.
     755    //
     756    // Gets the data for the given Image into outputVector in the
     757    // format specified by the (OpenGL-style) format and type
     758    // arguments. Despite the fact that the outputVector contains
     759    // uint8_t, if the format and type specify packed pixels, then
     760    // it will essentially contain uint16_t after the extraction
     761    // process.
     762    //
     763    // If premultiplyAlpha is true, the alpha channel, if any,
     764    // will be multiplied into the color channels during the
     765    // extraction process. This premultiplication occurs before
     766    // any packing of pixel data.
     767    //
     768    // No vertical flip of the image data is performed by this
     769    // method.
     770    bool getImageData(Image* image,
     771                      unsigned int format,
     772                      unsigned int type,
     773                      bool premultiplyAlpha,
     774                      Vector<uint8_t>& outputVector);
     775
     776    // Possible alpha operations that may need to occur during
     777    // pixel packing. FIXME: kAlphaDoUnmultiply is lossy and must
     778    // be removed.
     779    enum AlphaOp {
     780        kAlphaDoNothing = 0,
     781        kAlphaDoPremultiply = 1,
     782        kAlphaDoUnmultiply = 2
     783    };
     784
     785    // Helper for getImageData which implements packing of pixel
     786    // data into the specified OpenGL destination format and type.
     787    // A sourceUnpackAlignment of zero indicates that the source
     788    // data is tightly packed. Non-zero values may take a slow path.
     789    // Destination data will have no gaps between rows.
     790    bool packPixels(const uint8_t* sourceData,
     791                    SourceDataFormat sourceDataFormat,
     792                    unsigned int width,
     793                    unsigned int height,
     794                    unsigned int sourceUnpackAlignment,
     795                    unsigned int destinationFormat,
     796                    unsigned int destinationType,
     797                    AlphaOp alphaOp,
     798                    void* destinationData);
     799
     800#if PLATFORM(MAC)
     801    // Take into account the user's requested context creation attributes,
     802    // in particular stencil and antialias, and determine which could or
     803    // could not be honored based on the capabilities of the OpenGL
     804    // implementation.
     805    void validateAttributes();
     806#endif
     807
     808    int m_currentWidth, m_currentHeight;
     809
     810#if PLATFORM(MAC)
     811    Attributes m_attrs;
     812    Vector<Vector<float> > m_vertexArray;
     813
     814    CGLContextObj m_contextObj;
     815    RetainPtr<WebGLLayer> m_webGLLayer;
     816    GLuint m_texture;
     817    GLuint m_fbo;
     818    GLuint m_depthStencilBuffer;
     819
     820    // For tracking which FBO is bound
     821    GLuint m_boundFBO;
     822
     823    // For multisampling
     824    GLuint m_multisampleFBO;
     825    GLuint m_multisampleDepthStencilBuffer;
     826    GLuint m_multisampleColorBuffer;
     827
     828    // Errors raised by synthesizeGLError().
     829    ListHashSet<unsigned long> m_syntheticErrors;
     830#endif
    92831
    93832    // FIXME: ideally this would be used on all platforms.
    94833#if PLATFORM(CHROMIUM) || PLATFORM(QT)
    95     class GraphicsContext3DInternal;
    96 #endif
    97 
    98     class GraphicsContext3D : public Noncopyable {
    99     public:
    100         enum WebGLEnumType {
    101             DEPTH_BUFFER_BIT = 0x00000100,
    102             STENCIL_BUFFER_BIT = 0x00000400,
    103             COLOR_BUFFER_BIT = 0x00004000,
    104             POINTS = 0x0000,
    105             LINES = 0x0001,
    106             LINE_LOOP = 0x0002,
    107             LINE_STRIP = 0x0003,
    108             TRIANGLES = 0x0004,
    109             TRIANGLE_STRIP = 0x0005,
    110             TRIANGLE_FAN = 0x0006,
    111             ZERO = 0,
    112             ONE = 1,
    113             SRC_COLOR = 0x0300,
    114             ONE_MINUS_SRC_COLOR = 0x0301,
    115             SRC_ALPHA = 0x0302,
    116             ONE_MINUS_SRC_ALPHA = 0x0303,
    117             DST_ALPHA = 0x0304,
    118             ONE_MINUS_DST_ALPHA = 0x0305,
    119             DST_COLOR = 0x0306,
    120             ONE_MINUS_DST_COLOR = 0x0307,
    121             SRC_ALPHA_SATURATE = 0x0308,
    122             FUNC_ADD = 0x8006,
    123             BLEND_EQUATION = 0x8009,
    124             BLEND_EQUATION_RGB = 0x8009,
    125             BLEND_EQUATION_ALPHA = 0x883D,
    126             FUNC_SUBTRACT = 0x800A,
    127             FUNC_REVERSE_SUBTRACT = 0x800B,
    128             BLEND_DST_RGB = 0x80C8,
    129             BLEND_SRC_RGB = 0x80C9,
    130             BLEND_DST_ALPHA = 0x80CA,
    131             BLEND_SRC_ALPHA = 0x80CB,
    132             CONSTANT_COLOR = 0x8001,
    133             ONE_MINUS_CONSTANT_COLOR = 0x8002,
    134             CONSTANT_ALPHA = 0x8003,
    135             ONE_MINUS_CONSTANT_ALPHA = 0x8004,
    136             BLEND_COLOR = 0x8005,
    137             ARRAY_BUFFER = 0x8892,
    138             ELEMENT_ARRAY_BUFFER = 0x8893,
    139             ARRAY_BUFFER_BINDING = 0x8894,
    140             ELEMENT_ARRAY_BUFFER_BINDING = 0x8895,
    141             STREAM_DRAW = 0x88E0,
    142             STATIC_DRAW = 0x88E4,
    143             DYNAMIC_DRAW = 0x88E8,
    144             BUFFER_SIZE = 0x8764,
    145             BUFFER_USAGE = 0x8765,
    146             CURRENT_VERTEX_ATTRIB = 0x8626,
    147             FRONT = 0x0404,
    148             BACK = 0x0405,
    149             FRONT_AND_BACK = 0x0408,
    150             TEXTURE_2D = 0x0DE1,
    151             CULL_FACE = 0x0B44,
    152             BLEND = 0x0BE2,
    153             DITHER = 0x0BD0,
    154             STENCIL_TEST = 0x0B90,
    155             DEPTH_TEST = 0x0B71,
    156             SCISSOR_TEST = 0x0C11,
    157             POLYGON_OFFSET_FILL = 0x8037,
    158             SAMPLE_ALPHA_TO_COVERAGE = 0x809E,
    159             SAMPLE_COVERAGE = 0x80A0,
    160             NO_ERROR = 0,
    161             INVALID_ENUM = 0x0500,
    162             INVALID_VALUE = 0x0501,
    163             INVALID_OPERATION = 0x0502,
    164             OUT_OF_MEMORY = 0x0505,
    165             CW = 0x0900,
    166             CCW = 0x0901,
    167             LINE_WIDTH = 0x0B21,
    168             ALIASED_POINT_SIZE_RANGE = 0x846D,
    169             ALIASED_LINE_WIDTH_RANGE = 0x846E,
    170             CULL_FACE_MODE = 0x0B45,
    171             FRONT_FACE = 0x0B46,
    172             DEPTH_RANGE = 0x0B70,
    173             DEPTH_WRITEMASK = 0x0B72,
    174             DEPTH_CLEAR_VALUE = 0x0B73,
    175             DEPTH_FUNC = 0x0B74,
    176             STENCIL_CLEAR_VALUE = 0x0B91,
    177             STENCIL_FUNC = 0x0B92,
    178             STENCIL_FAIL = 0x0B94,
    179             STENCIL_PASS_DEPTH_FAIL = 0x0B95,
    180             STENCIL_PASS_DEPTH_PASS = 0x0B96,
    181             STENCIL_REF = 0x0B97,
    182             STENCIL_VALUE_MASK = 0x0B93,
    183             STENCIL_WRITEMASK = 0x0B98,
    184             STENCIL_BACK_FUNC = 0x8800,
    185             STENCIL_BACK_FAIL = 0x8801,
    186             STENCIL_BACK_PASS_DEPTH_FAIL = 0x8802,
    187             STENCIL_BACK_PASS_DEPTH_PASS = 0x8803,
    188             STENCIL_BACK_REF = 0x8CA3,
    189             STENCIL_BACK_VALUE_MASK = 0x8CA4,
    190             STENCIL_BACK_WRITEMASK = 0x8CA5,
    191             VIEWPORT = 0x0BA2,
    192             SCISSOR_BOX = 0x0C10,
    193             COLOR_CLEAR_VALUE = 0x0C22,
    194             COLOR_WRITEMASK = 0x0C23,
    195             UNPACK_ALIGNMENT = 0x0CF5,
    196             PACK_ALIGNMENT = 0x0D05,
    197             MAX_TEXTURE_SIZE = 0x0D33,
    198             MAX_VIEWPORT_DIMS = 0x0D3A,
    199             SUBPIXEL_BITS = 0x0D50,
    200             RED_BITS = 0x0D52,
    201             GREEN_BITS = 0x0D53,
    202             BLUE_BITS = 0x0D54,
    203             ALPHA_BITS = 0x0D55,
    204             DEPTH_BITS = 0x0D56,
    205             STENCIL_BITS = 0x0D57,
    206             POLYGON_OFFSET_UNITS = 0x2A00,
    207             POLYGON_OFFSET_FACTOR = 0x8038,
    208             TEXTURE_BINDING_2D = 0x8069,
    209             SAMPLE_BUFFERS = 0x80A8,
    210             SAMPLES = 0x80A9,
    211             SAMPLE_COVERAGE_VALUE = 0x80AA,
    212             SAMPLE_COVERAGE_INVERT = 0x80AB,
    213             NUM_COMPRESSED_TEXTURE_FORMATS = 0x86A2,
    214             COMPRESSED_TEXTURE_FORMATS = 0x86A3,
    215             DONT_CARE = 0x1100,
    216             FASTEST = 0x1101,
    217             NICEST = 0x1102,
    218             GENERATE_MIPMAP_HINT = 0x8192,
    219             BYTE = 0x1400,
    220             UNSIGNED_BYTE = 0x1401,
    221             SHORT = 0x1402,
    222             UNSIGNED_SHORT = 0x1403,
    223             INT = 0x1404,
    224             UNSIGNED_INT = 0x1405,
    225             FLOAT = 0x1406,
    226             FIXED = 0x140C,
    227             DEPTH_COMPONENT = 0x1902,
    228             ALPHA = 0x1906,
    229             RGB = 0x1907,
    230             RGBA = 0x1908,
    231             LUMINANCE = 0x1909,
    232             LUMINANCE_ALPHA = 0x190A,
    233             UNSIGNED_SHORT_4_4_4_4 = 0x8033,
    234             UNSIGNED_SHORT_5_5_5_1 = 0x8034,
    235             UNSIGNED_SHORT_5_6_5 = 0x8363,
    236             FRAGMENT_SHADER = 0x8B30,
    237             VERTEX_SHADER = 0x8B31,
    238             MAX_VERTEX_ATTRIBS = 0x8869,
    239             MAX_VERTEX_UNIFORM_VECTORS = 0x8DFB,
    240             MAX_VARYING_VECTORS = 0x8DFC,
    241             MAX_COMBINED_TEXTURE_IMAGE_UNITS = 0x8B4D,
    242             MAX_VERTEX_TEXTURE_IMAGE_UNITS = 0x8B4C,
    243             MAX_TEXTURE_IMAGE_UNITS = 0x8872,
    244             MAX_FRAGMENT_UNIFORM_VECTORS = 0x8DFD,
    245             SHADER_TYPE = 0x8B4F,
    246             DELETE_STATUS = 0x8B80,
    247             LINK_STATUS = 0x8B82,
    248             VALIDATE_STATUS = 0x8B83,
    249             ATTACHED_SHADERS = 0x8B85,
    250             ACTIVE_UNIFORMS = 0x8B86,
    251             ACTIVE_UNIFORM_MAX_LENGTH = 0x8B87,
    252             ACTIVE_ATTRIBUTES = 0x8B89,
    253             ACTIVE_ATTRIBUTE_MAX_LENGTH = 0x8B8A,
    254             SHADING_LANGUAGE_VERSION = 0x8B8C,
    255             CURRENT_PROGRAM = 0x8B8D,
    256             NEVER = 0x0200,
    257             LESS = 0x0201,
    258             EQUAL = 0x0202,
    259             LEQUAL = 0x0203,
    260             GREATER = 0x0204,
    261             NOTEQUAL = 0x0205,
    262             GEQUAL = 0x0206,
    263             ALWAYS = 0x0207,
    264             KEEP = 0x1E00,
    265             REPLACE = 0x1E01,
    266             INCR = 0x1E02,
    267             DECR = 0x1E03,
    268             INVERT = 0x150A,
    269             INCR_WRAP = 0x8507,
    270             DECR_WRAP = 0x8508,
    271             VENDOR = 0x1F00,
    272             RENDERER = 0x1F01,
    273             VERSION = 0x1F02,
    274             EXTENSIONS = 0x1F03,
    275             NEAREST = 0x2600,
    276             LINEAR = 0x2601,
    277             NEAREST_MIPMAP_NEAREST = 0x2700,
    278             LINEAR_MIPMAP_NEAREST = 0x2701,
    279             NEAREST_MIPMAP_LINEAR = 0x2702,
    280             LINEAR_MIPMAP_LINEAR = 0x2703,
    281             TEXTURE_MAG_FILTER = 0x2800,
    282             TEXTURE_MIN_FILTER = 0x2801,
    283             TEXTURE_WRAP_S = 0x2802,
    284             TEXTURE_WRAP_T = 0x2803,
    285             TEXTURE = 0x1702,
    286             TEXTURE_CUBE_MAP = 0x8513,
    287             TEXTURE_BINDING_CUBE_MAP = 0x8514,
    288             TEXTURE_CUBE_MAP_POSITIVE_X = 0x8515,
    289             TEXTURE_CUBE_MAP_NEGATIVE_X = 0x8516,
    290             TEXTURE_CUBE_MAP_POSITIVE_Y = 0x8517,
    291             TEXTURE_CUBE_MAP_NEGATIVE_Y = 0x8518,
    292             TEXTURE_CUBE_MAP_POSITIVE_Z = 0x8519,
    293             TEXTURE_CUBE_MAP_NEGATIVE_Z = 0x851A,
    294             MAX_CUBE_MAP_TEXTURE_SIZE = 0x851C,
    295             TEXTURE0 = 0x84C0,
    296             TEXTURE1 = 0x84C1,
    297             TEXTURE2 = 0x84C2,
    298             TEXTURE3 = 0x84C3,
    299             TEXTURE4 = 0x84C4,
    300             TEXTURE5 = 0x84C5,
    301             TEXTURE6 = 0x84C6,
    302             TEXTURE7 = 0x84C7,
    303             TEXTURE8 = 0x84C8,
    304             TEXTURE9 = 0x84C9,
    305             TEXTURE10 = 0x84CA,
    306             TEXTURE11 = 0x84CB,
    307             TEXTURE12 = 0x84CC,
    308             TEXTURE13 = 0x84CD,
    309             TEXTURE14 = 0x84CE,
    310             TEXTURE15 = 0x84CF,
    311             TEXTURE16 = 0x84D0,
    312             TEXTURE17 = 0x84D1,
    313             TEXTURE18 = 0x84D2,
    314             TEXTURE19 = 0x84D3,
    315             TEXTURE20 = 0x84D4,
    316             TEXTURE21 = 0x84D5,
    317             TEXTURE22 = 0x84D6,
    318             TEXTURE23 = 0x84D7,
    319             TEXTURE24 = 0x84D8,
    320             TEXTURE25 = 0x84D9,
    321             TEXTURE26 = 0x84DA,
    322             TEXTURE27 = 0x84DB,
    323             TEXTURE28 = 0x84DC,
    324             TEXTURE29 = 0x84DD,
    325             TEXTURE30 = 0x84DE,
    326             TEXTURE31 = 0x84DF,
    327             ACTIVE_TEXTURE = 0x84E0,
    328             REPEAT = 0x2901,
    329             CLAMP_TO_EDGE = 0x812F,
    330             MIRRORED_REPEAT = 0x8370,
    331             FLOAT_VEC2 = 0x8B50,
    332             FLOAT_VEC3 = 0x8B51,
    333             FLOAT_VEC4 = 0x8B52,
    334             INT_VEC2 = 0x8B53,
    335             INT_VEC3 = 0x8B54,
    336             INT_VEC4 = 0x8B55,
    337             BOOL = 0x8B56,
    338             BOOL_VEC2 = 0x8B57,
    339             BOOL_VEC3 = 0x8B58,
    340             BOOL_VEC4 = 0x8B59,
    341             FLOAT_MAT2 = 0x8B5A,
    342             FLOAT_MAT3 = 0x8B5B,
    343             FLOAT_MAT4 = 0x8B5C,
    344             SAMPLER_2D = 0x8B5E,
    345             SAMPLER_CUBE = 0x8B60,
    346             VERTEX_ATTRIB_ARRAY_ENABLED = 0x8622,
    347             VERTEX_ATTRIB_ARRAY_SIZE = 0x8623,
    348             VERTEX_ATTRIB_ARRAY_STRIDE = 0x8624,
    349             VERTEX_ATTRIB_ARRAY_TYPE = 0x8625,
    350             VERTEX_ATTRIB_ARRAY_NORMALIZED = 0x886A,
    351             VERTEX_ATTRIB_ARRAY_POINTER = 0x8645,
    352             VERTEX_ATTRIB_ARRAY_BUFFER_BINDING = 0x889F,
    353             IMPLEMENTATION_COLOR_READ_TYPE = 0x8B9A,
    354             IMPLEMENTATION_COLOR_READ_FORMAT = 0x8B9B,
    355             COMPILE_STATUS = 0x8B81,
    356             INFO_LOG_LENGTH = 0x8B84,
    357             SHADER_SOURCE_LENGTH = 0x8B88,
    358             SHADER_COMPILER = 0x8DFA,
    359             SHADER_BINARY_FORMATS = 0x8DF8,
    360             NUM_SHADER_BINARY_FORMATS = 0x8DF9,
    361             LOW_FLOAT = 0x8DF0,
    362             MEDIUM_FLOAT = 0x8DF1,
    363             HIGH_FLOAT = 0x8DF2,
    364             LOW_INT = 0x8DF3,
    365             MEDIUM_INT = 0x8DF4,
    366             HIGH_INT = 0x8DF5,
    367             FRAMEBUFFER = 0x8D40,
    368             RENDERBUFFER = 0x8D41,
    369             RGBA4 = 0x8056,
    370             RGB5_A1 = 0x8057,
    371             RGB565 = 0x8D62,
    372             DEPTH_COMPONENT16 = 0x81A5,
    373             STENCIL_INDEX = 0x1901,
    374             STENCIL_INDEX8 = 0x8D48,
    375             DEPTH_STENCIL = 0x84F9,
    376             RENDERBUFFER_WIDTH = 0x8D42,
    377             RENDERBUFFER_HEIGHT = 0x8D43,
    378             RENDERBUFFER_INTERNAL_FORMAT = 0x8D44,
    379             RENDERBUFFER_RED_SIZE = 0x8D50,
    380             RENDERBUFFER_GREEN_SIZE = 0x8D51,
    381             RENDERBUFFER_BLUE_SIZE = 0x8D52,
    382             RENDERBUFFER_ALPHA_SIZE = 0x8D53,
    383             RENDERBUFFER_DEPTH_SIZE = 0x8D54,
    384             RENDERBUFFER_STENCIL_SIZE = 0x8D55,
    385             FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE = 0x8CD0,
    386             FRAMEBUFFER_ATTACHMENT_OBJECT_NAME = 0x8CD1,
    387             FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL = 0x8CD2,
    388             FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE = 0x8CD3,
    389             COLOR_ATTACHMENT0 = 0x8CE0,
    390             DEPTH_ATTACHMENT = 0x8D00,
    391             STENCIL_ATTACHMENT = 0x8D20,
    392             DEPTH_STENCIL_ATTACHMENT = 0x821A,
    393             NONE = 0,
    394             FRAMEBUFFER_COMPLETE = 0x8CD5,
    395             FRAMEBUFFER_INCOMPLETE_ATTACHMENT = 0x8CD6,
    396             FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT = 0x8CD7,
    397             FRAMEBUFFER_INCOMPLETE_DIMENSIONS = 0x8CD9,
    398             FRAMEBUFFER_UNSUPPORTED = 0x8CDD,
    399             FRAMEBUFFER_BINDING = 0x8CA6,
    400             RENDERBUFFER_BINDING = 0x8CA7,
    401             MAX_RENDERBUFFER_SIZE = 0x84E8,
    402             INVALID_FRAMEBUFFER_OPERATION = 0x0506,
    403 
    404             // WebGL-specific enums
    405             UNPACK_FLIP_Y_WEBGL = 0x9240,
    406             UNPACK_PREMULTIPLY_ALPHA_WEBGL = 0x9241
    407         };
    408        
    409         // Context creation attributes.
    410         struct Attributes {
    411             Attributes()
    412                 : alpha(true)
    413                 , depth(true)
    414                 , stencil(false)
    415                 , antialias(true)
    416                 , premultipliedAlpha(true)
    417             {
    418             }
    419 
    420             bool alpha;
    421             bool depth;
    422             bool stencil;
    423             bool antialias;
    424             bool premultipliedAlpha;
    425         };
    426 
    427         static PassOwnPtr<GraphicsContext3D> create(Attributes attrs, HostWindow* hostWindow);
    428         virtual ~GraphicsContext3D();
    429 
    430 #if PLATFORM(MAC)
    431         PlatformGraphicsContext3D platformGraphicsContext3D() const { return m_contextObj; }
    432         Platform3DObject platformTexture() const { return m_texture; }
    433         CALayer* platformLayer() const { return static_cast<CALayer*>(m_webGLLayer.get()); }
    434 #elif PLATFORM(CHROMIUM)
    435         PlatformGraphicsContext3D platformGraphicsContext3D() const;
    436         Platform3DObject platformTexture() const;
    437 #if USE(ACCELERATED_COMPOSITING)
    438         PlatformLayer* platformLayer() const;
    439 #endif
    440 #elif PLATFORM(QT)
    441         PlatformGraphicsContext3D platformGraphicsContext3D();
    442         Platform3DObject platformTexture() const;
    443 #if USE(ACCELERATED_COMPOSITING)
    444         PlatformLayer* platformLayer() const { return 0; }
    445 #endif
    446 #else
    447         PlatformGraphicsContext3D platformGraphicsContext3D() const { return NullPlatformGraphicsContext3D; }
    448         Platform3DObject platformTexture() const { return NullPlatform3DObject; }
    449 #if USE(ACCELERATED_COMPOSITING)
    450         PlatformLayer* platformLayer() const { return 0; }
    451 #endif
    452 #endif
    453         void makeContextCurrent();
    454 
    455 #if PLATFORM(MAC) || PLATFORM(CHROMIUM)
    456         // With multisampling on, blit from multisampleFBO to regular FBO.
    457         void prepareTexture();
    458 #endif
    459 
    460         // Helper to return the size in bytes of OpenGL data types
    461         // like GL_FLOAT, GL_INT, etc.
    462         int sizeInBytes(int type);
    463 
    464         bool isGLES2Compliant() const;
    465 
    466         //----------------------------------------------------------------------
    467         // Helpers for texture uploading and pixel readback.
    468         //
    469 
    470         // Computes the components per pixel and bytes per component
    471         // for the given format and type combination. Returns false if
    472         // either was an invalid enum.
    473         bool computeFormatAndTypeParameters(unsigned int format,
    474                                             unsigned int type,
    475                                             unsigned long* componentsPerPixel,
    476                                             unsigned long* bytesPerComponent);
    477 
    478         // Extracts the contents of the given Image into the passed Vector,
    479         // packing the pixel data according to the given format and type,
    480         // and obeying the flipY and premultiplyAlpha flags. Returns true
    481         // upon success.
    482         bool extractImageData(Image* image,
    483                               unsigned int format,
    484                               unsigned int type,
    485                               bool flipY,
    486                               bool premultiplyAlpha,
    487                               Vector<uint8_t>& data);
    488 
    489         // Extracts the contents of the given ImageData into the passed Vector,
    490         // packing the pixel data according to the given format and type,
    491         // and obeying the flipY and premultiplyAlpha flags. Returns true
    492         // upon success.
    493         bool extractImageData(ImageData*,
    494                               unsigned int format,
    495                               unsigned int type,
    496                               bool flipY,
    497                               bool premultiplyAlpha,
    498                               Vector<uint8_t>& data);
    499 
    500         // Helper function which extracts the user-supplied texture
    501         // data, applying the flipY and premultiplyAlpha parameters.
    502         // If the data is not tightly packed according to the passed
    503         // unpackAlignment, the output data will be tightly packed.
    504         // Returns true if successful, false if any error occurred.
    505         bool extractTextureData(unsigned int width, unsigned int height,
    506                                 unsigned int format, unsigned int type,
    507                                 unsigned int unpackAlignment,
    508                                 bool flipY, bool premultiplyAlpha,
    509                                 ArrayBufferView* pixels,
    510                                 Vector<uint8_t>& data);
    511 
    512         // Flips the given image data vertically, in-place.
    513         void flipVertically(void* imageData,
    514                             unsigned int width,
    515                             unsigned int height,
    516                             unsigned int bytesPerPixel,
    517                             unsigned int unpackAlignment);
    518 
    519         // Attempt to enumerate all possible native image formats to
    520         // reduce the amount of temporary allocations during texture
    521         // uploading. This enum must be public because it is accessed
    522         // by non-member functions.
    523         enum SourceDataFormat {
    524             kSourceFormatRGBA8,
    525             kSourceFormatRGB8,
    526             kSourceFormatBGRA8,
    527             kSourceFormatRGBA5551,
    528             kSourceFormatRGBA4444,
    529             kSourceFormatRGB565,
    530             kSourceFormatR8,
    531             kSourceFormatRA8,
    532             kSourceFormatA8
    533         };
    534 
    535         //----------------------------------------------------------------------
    536         // Entry points for WebGL.
    537         //
    538 
    539         void activeTexture(unsigned long texture);
    540         void attachShader(Platform3DObject program, Platform3DObject shader);
    541         void bindAttribLocation(Platform3DObject, unsigned long index, const String& name);
    542         void bindBuffer(unsigned long target, Platform3DObject);
    543         void bindFramebuffer(unsigned long target, Platform3DObject);
    544         void bindRenderbuffer(unsigned long target, Platform3DObject);
    545         void bindTexture(unsigned long target, Platform3DObject texture);
    546         void blendColor(double red, double green, double blue, double alpha);
    547         void blendEquation(unsigned long mode);
    548         void blendEquationSeparate(unsigned long modeRGB, unsigned long modeAlpha);
    549         void blendFunc(unsigned long sfactor, unsigned long dfactor);
    550         void blendFuncSeparate(unsigned long srcRGB, unsigned long dstRGB, unsigned long srcAlpha, unsigned long dstAlpha);
    551 
    552         void bufferData(unsigned long target, int size, unsigned long usage);
    553         void bufferData(unsigned long target, ArrayBuffer* data, unsigned long usage);
    554         void bufferData(unsigned long target, ArrayBufferView* data, unsigned long usage);
    555         void bufferSubData(unsigned long target, long offset, ArrayBuffer* data);
    556         void bufferSubData(unsigned long target, long offset, ArrayBufferView* data);
    557 
    558         unsigned long checkFramebufferStatus(unsigned long target);
    559         void clear(unsigned long mask);
    560         void clearColor(double red, double green, double blue, double alpha);
    561         void clearDepth(double depth);
    562         void clearStencil(long s);
    563         void colorMask(bool red, bool green, bool blue, bool alpha);
    564         void compileShader(Platform3DObject);
    565        
    566         //void compressedTexImage2D(unsigned long target, long level, unsigned long internalformat, unsigned long width, unsigned long height, long border, unsigned long imageSize, const void* data);
    567         //void compressedTexSubImage2D(unsigned long target, long level, long xoffset, long yoffset, unsigned long width, unsigned long height, unsigned long format, unsigned long imageSize, const void* data);
    568        
    569         void copyTexImage2D(unsigned long target, long level, unsigned long internalformat, long x, long y, unsigned long width, unsigned long height, long border);
    570         void copyTexSubImage2D(unsigned long target, long level, long xoffset, long yoffset, long x, long y, unsigned long width, unsigned long height);
    571         void cullFace(unsigned long mode);
    572         void depthFunc(unsigned long func);
    573         void depthMask(bool flag);
    574         void depthRange(double zNear, double zFar);
    575         void detachShader(Platform3DObject, Platform3DObject);
    576         void disable(unsigned long cap);
    577         void disableVertexAttribArray(unsigned long index);
    578         void drawArrays(unsigned long mode, long first, long count);
    579         void drawElements(unsigned long mode, unsigned long count, unsigned long type, long offset);
    580 
    581         void enable(unsigned long cap);
    582         void enableVertexAttribArray(unsigned long index);
    583         void finish();
    584         void flush();
    585         void framebufferRenderbuffer(unsigned long target, unsigned long attachment, unsigned long renderbuffertarget, Platform3DObject);
    586         void framebufferTexture2D(unsigned long target, unsigned long attachment, unsigned long textarget, Platform3DObject, long level);
    587         void frontFace(unsigned long mode);
    588         void generateMipmap(unsigned long target);
    589 
    590         bool getActiveAttrib(Platform3DObject program, unsigned long index, ActiveInfo&);
    591         bool getActiveUniform(Platform3DObject program, unsigned long index, ActiveInfo&);
    592 
    593         void getAttachedShaders(Platform3DObject program, int maxCount, int* count, unsigned int* shaders);
    594 
    595         int getAttribLocation(Platform3DObject, const String& name);
    596 
    597         void getBooleanv(unsigned long pname, unsigned char* value);
    598 
    599         void getBufferParameteriv(unsigned long target, unsigned long pname, int* value);
    600 
    601         Attributes getContextAttributes();
    602 
    603         unsigned long getError();
    604 
    605         void getFloatv(unsigned long pname, float* value);
    606 
    607         void getFramebufferAttachmentParameteriv(unsigned long target, unsigned long attachment, unsigned long pname, int* value);
    608 
    609         void getIntegerv(unsigned long pname, int* value);
    610 
    611         void getProgramiv(Platform3DObject program, unsigned long pname, int* value);
    612 
    613         String getProgramInfoLog(Platform3DObject);
    614 
    615         void getRenderbufferParameteriv(unsigned long target, unsigned long pname, int* value);
    616 
    617         void getShaderiv(Platform3DObject, unsigned long pname, int* value);
    618 
    619         String getShaderInfoLog(Platform3DObject);
    620 
    621         // TBD
    622         // void glGetShaderPrecisionFormat (GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision);
    623 
    624         String getShaderSource(Platform3DObject);
    625         String getString(unsigned long name);
    626 
    627         void getTexParameterfv(unsigned long target, unsigned long pname, float* value);
    628         void getTexParameteriv(unsigned long target, unsigned long pname, int* value);
    629 
    630         void getUniformfv(Platform3DObject program, long location, float* value);
    631         void getUniformiv(Platform3DObject program, long location, int* value);
    632 
    633         long getUniformLocation(Platform3DObject, const String& name);
    634 
    635         void getVertexAttribfv(unsigned long index, unsigned long pname, float* value);
    636         void getVertexAttribiv(unsigned long index, unsigned long pname, int* value);
    637 
    638         long getVertexAttribOffset(unsigned long index, unsigned long pname);
    639 
    640         void hint(unsigned long target, unsigned long mode);
    641         bool isBuffer(Platform3DObject);
    642         bool isEnabled(unsigned long cap);
    643         bool isFramebuffer(Platform3DObject);
    644         bool isProgram(Platform3DObject);
    645         bool isRenderbuffer(Platform3DObject);
    646         bool isShader(Platform3DObject);
    647         bool isTexture(Platform3DObject);
    648         void lineWidth(double);
    649         void linkProgram(Platform3DObject);
    650         void pixelStorei(unsigned long pname, long param);
    651         void polygonOffset(double factor, double units);
    652        
    653         void readPixels(long x, long y, unsigned long width, unsigned long height, unsigned long format, unsigned long type, void* data);
    654        
    655         void releaseShaderCompiler();
    656         void renderbufferStorage(unsigned long target, unsigned long internalformat, unsigned long width, unsigned long height);
    657         void sampleCoverage(double value, bool invert);
    658         void scissor(long x, long y, unsigned long width, unsigned long height);
    659         void shaderSource(Platform3DObject, const String& string);
    660         void stencilFunc(unsigned long func, long ref, unsigned long mask);
    661         void stencilFuncSeparate(unsigned long face, unsigned long func, long ref, unsigned long mask);
    662         void stencilMask(unsigned long mask);
    663         void stencilMaskSeparate(unsigned long face, unsigned long mask);
    664         void stencilOp(unsigned long fail, unsigned long zfail, unsigned long zpass);
    665         void stencilOpSeparate(unsigned long face, unsigned long fail, unsigned long zfail, unsigned long zpass);
    666 
    667         int texImage2D(unsigned target, unsigned level, unsigned internalformat, unsigned width, unsigned height, unsigned border, unsigned format, unsigned type, void* pixels);
    668 
    669         void texParameterf(unsigned target, unsigned pname, float param);
    670         void texParameteri(unsigned target, unsigned pname, int param);
    671 
    672         int texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, unsigned width, unsigned height, unsigned format, unsigned type, void* pixels);
    673 
    674         void uniform1f(long location, float x);
    675         void uniform1fv(long location, float* v, int size);
    676         void uniform1i(long location, int x);
    677         void uniform1iv(long location, int* v, int size);
    678         void uniform2f(long location, float x, float y);
    679         void uniform2fv(long location, float* v, int size);
    680         void uniform2i(long location, int x, int y);
    681         void uniform2iv(long location, int* v, int size);
    682         void uniform3f(long location, float x, float y, float z);
    683         void uniform3fv(long location, float* v, int size);
    684         void uniform3i(long location, int x, int y, int z);
    685         void uniform3iv(long location, int* v, int size);
    686         void uniform4f(long location, float x, float y, float z, float w);
    687         void uniform4fv(long location, float* v, int size);
    688         void uniform4i(long location, int x, int y, int z, int w);
    689         void uniform4iv(long location, int* v, int size);
    690         void uniformMatrix2fv(long location, bool transpose, float* value, int size);
    691         void uniformMatrix3fv(long location, bool transpose, float* value, int size);
    692         void uniformMatrix4fv(long location, bool transpose, float* value, int size);
    693 
    694         void useProgram(Platform3DObject);
    695         void validateProgram(Platform3DObject);
    696 
    697         void vertexAttrib1f(unsigned long indx, float x);
    698         void vertexAttrib1fv(unsigned long indx, float* values);
    699         void vertexAttrib2f(unsigned long indx, float x, float y);
    700         void vertexAttrib2fv(unsigned long indx, float* values);
    701         void vertexAttrib3f(unsigned long indx, float x, float y, float z);
    702         void vertexAttrib3fv(unsigned long indx, float* values);
    703         void vertexAttrib4f(unsigned long indx, float x, float y, float z, float w);
    704         void vertexAttrib4fv(unsigned long indx, float* values);
    705         void vertexAttribPointer(unsigned long indx, int size, int type, bool normalized,
    706                                  unsigned long stride, unsigned long offset);
    707 
    708         void viewport(long x, long y, unsigned long width, unsigned long height);
    709 
    710         void reshape(int width, int height);
    711 
    712 #if PLATFORM(CG)
    713         void paintToCanvas(const unsigned char* imagePixels, int imageWidth, int imageHeight,
    714                            int canvasWidth, int canvasHeight, CGContextRef context);
    715 #endif
    716 
    717         void paintRenderingResultsToCanvas(CanvasRenderingContext* context);
    718 
    719         // Helpers for notification about paint events
    720         void beginPaint(CanvasRenderingContext* context);
    721         void endPaint();
    722 #if PLATFORM(QT)
    723         void paint(QPainter* painter, const QRect& rect) const;
    724 #endif
    725 
    726         // Support for buffer creation and deletion
    727         unsigned createBuffer();
    728         unsigned createFramebuffer();
    729         unsigned createProgram();
    730         unsigned createRenderbuffer();
    731         unsigned createShader(unsigned long);
    732         unsigned createTexture();
    733        
    734         void deleteBuffer(unsigned);
    735         void deleteFramebuffer(unsigned);
    736         void deleteProgram(unsigned);
    737         void deleteRenderbuffer(unsigned);
    738         void deleteShader(unsigned);
    739         void deleteTexture(unsigned);       
    740        
    741         // Synthesizes an OpenGL error which will be returned from a
    742         // later call to getError. This is used to emulate OpenGL ES
    743         // 2.0 behavior on the desktop and to enforce additional error
    744         // checking mandated by WebGL.
    745         //
    746         // Per the behavior of glGetError, this stores at most one
    747         // instance of any given error, and returns them from calls to
    748         // getError in the order they were added.
    749         void synthesizeGLError(unsigned long error);
    750 
    751     private:       
    752         GraphicsContext3D(Attributes attrs, HostWindow* hostWindow);
    753 
    754         // Each platform must provide an implementation of this method.
    755         //
    756         // Gets the data for the given Image into outputVector in the
    757         // format specified by the (OpenGL-style) format and type
    758         // arguments. Despite the fact that the outputVector contains
    759         // uint8_t, if the format and type specify packed pixels, then
    760         // it will essentially contain uint16_t after the extraction
    761         // process.
    762         //
    763         // If premultiplyAlpha is true, the alpha channel, if any,
    764         // will be multiplied into the color channels during the
    765         // extraction process. This premultiplication occurs before
    766         // any packing of pixel data.
    767         //
    768         // No vertical flip of the image data is performed by this
    769         // method.
    770         bool getImageData(Image* image,
    771                           unsigned int format,
    772                           unsigned int type,
    773                           bool premultiplyAlpha,
    774                           Vector<uint8_t>& outputVector);
    775 
    776         // Possible alpha operations that may need to occur during
    777         // pixel packing. FIXME: kAlphaDoUnmultiply is lossy and must
    778         // be removed.
    779         enum AlphaOp {
    780             kAlphaDoNothing = 0,
    781             kAlphaDoPremultiply = 1,
    782             kAlphaDoUnmultiply = 2
    783         };
    784 
    785         // Helper for getImageData which implements packing of pixel
    786         // data into the specified OpenGL destination format and type.
    787         // A sourceUnpackAlignment of zero indicates that the source
    788         // data is tightly packed. Non-zero values may take a slow path.
    789         // Destination data will have no gaps between rows.
    790         bool packPixels(const uint8_t* sourceData,
    791                         SourceDataFormat sourceDataFormat,
    792                         unsigned int width,
    793                         unsigned int height,
    794                         unsigned int sourceUnpackAlignment,
    795                         unsigned int destinationFormat,
    796                         unsigned int destinationType,
    797                         AlphaOp alphaOp,
    798                         void* destinationData);
    799 
    800 #if PLATFORM(MAC)
    801         // Take into account the user's requested context creation attributes,
    802         // in particular stencil and antialias, and determine which could or
    803         // could not be honored based on the capabilities of the OpenGL
    804         // implementation.
    805         void validateAttributes();
    806 #endif
    807 
    808         int m_currentWidth, m_currentHeight;
    809        
    810 #if PLATFORM(MAC)
    811         Attributes m_attrs;
    812         Vector<Vector<float> > m_vertexArray;
    813        
    814         CGLContextObj m_contextObj;
    815         RetainPtr<WebGLLayer> m_webGLLayer;
    816         GLuint m_texture;
    817         GLuint m_fbo;
    818         GLuint m_depthStencilBuffer;
    819 
    820         // For tracking which FBO is bound
    821         GLuint m_boundFBO;
    822 
    823         // For multisampling
    824         GLuint m_multisampleFBO;
    825         GLuint m_multisampleDepthStencilBuffer;
    826         GLuint m_multisampleColorBuffer;
    827 
    828         // Errors raised by synthesizeGLError().
    829         ListHashSet<unsigned long> m_syntheticErrors;
    830 #endif       
    831 
    832         // FIXME: ideally this would be used on all platforms.
    833 #if PLATFORM(CHROMIUM) || PLATFORM(QT)
    834         friend class GraphicsContext3DInternal;
    835         OwnPtr<GraphicsContext3DInternal> m_internal;
    836 #endif
    837     };
     834    friend class GraphicsContext3DInternal;
     835    OwnPtr<GraphicsContext3DInternal> m_internal;
     836#endif
     837};
    838838
    839839} // namespace WebCore
  • trunk/WebKit/chromium/ChangeLog

    r64763 r64767  
     12010-08-04  Kenneth Russell  <kbr@google.com>
     2
     3        Reviewed by Dimitri Glazkov.
     4
     5        Style cleanups in WebGL
     6        https://bugs.webkit.org/show_bug.cgi?id=38761
     7
     8        Cleaned up all style violations in WebGL-related files reported by
     9        check-webkit-style. No logic or other changes. Built WebKit and
     10        Chromium and ran WebGL layout tests.
     11
     12        * src/GraphicsContext3D.cpp:
     13        (WebCore::GraphicsContext3DInternal::paintRenderingResultsToCanvas):
     14        * src/WebGraphicsContext3DDefaultImpl.cpp:
     15        * src/WebGraphicsContext3DDefaultImpl.h:
     16
    1172010-08-05  Jian Li  <jianli@chromium.org>
    218
  • trunk/WebKit/chromium/src/GraphicsContext3D.cpp

    r64582 r64767  
    3939#include "Chrome.h"
    4040#include "ChromeClientImpl.h"
     41#include "Float32Array.h"
    4142#include "HTMLCanvasElement.h"
    4243#include "HTMLImageElement.h"
    4344#include "ImageBuffer.h"
    4445#include "ImageData.h"
     46#include "Int32Array.h"
    4547#include "Int8Array.h"
    46 #include "Float32Array.h"
    47 #include "Int32Array.h"
    4848#include "Uint8Array.h"
    4949#include "WebGLLayerChromium.h"
     
    415415                                       m_impl->width(),
    416416                                       m_impl->height());
    417             if (!m_resizingBitmap.allocPixels()) {
     417            if (!m_resizingBitmap.allocPixels())
    418418                return;
    419             }
    420419        }
    421420        readbackBitmap = &m_resizingBitmap;
  • trunk/WebKit/chromium/src/WebGraphicsContext3DDefaultImpl.cpp

    r63705 r64767  
    3333#if ENABLE(3D_CANVAS)
    3434
     35#include "WebGraphicsContext3DDefaultImpl.h"
     36
     37#include "NotImplemented.h"
     38
    3539#include <stdio.h>
    3640#include <string.h>
    37 
    38 #include "WebGraphicsContext3DDefaultImpl.h"
    39 
    40 #include "NotImplemented.h"
    4141
    4242#if OS(LINUX)
  • trunk/WebKit/chromium/src/WebGraphicsContext3DDefaultImpl.h

    r62288 r64767  
    326326    static bool s_initializedGLEW;
    327327#if OS(WINDOWS)
    328     HWND  m_canvasWindow;
    329     HDC   m_canvasDC;
     328    HWND m_canvasWindow;
     329    HDC m_canvasDC;
    330330    HGLRC m_contextObj;
    331331#elif PLATFORM(CG)
Note: See TracChangeset for help on using the changeset viewer.