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