OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_RENDERER_WEBGRAPHICSCONTEXT3D_COMMAND_BUFFER_IMPL_H_ |
| 6 #define CHROME_RENDERER_WEBGRAPHICSCONTEXT3D_COMMAND_BUFFER_IMPL_H_ |
| 7 |
| 8 #if defined(ENABLE_GPU) |
| 9 |
| 10 #include <vector> |
| 11 |
| 12 #include "base/scoped_ptr.h" |
| 13 #include "chrome/renderer/ggl/ggl.h" |
| 14 #include "third_party/WebKit/WebKit/chromium/public/WebGraphicsContext3D.h" |
| 15 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" |
| 16 |
| 17 #if !defined(OS_MACOSX) |
| 18 #define FLIP_FRAMEBUFFER_VERTICALLY |
| 19 #endif |
| 20 |
| 21 class GpuChannelHost; |
| 22 class CommandBufferProxy; |
| 23 |
| 24 namespace gpu { |
| 25 namespace gles2 { |
| 26 class GLES2Implementation; |
| 27 } |
| 28 } |
| 29 |
| 30 using WebKit::WebGLId; |
| 31 |
| 32 class WebGraphicsContext3DCommandBufferImpl |
| 33 : public WebKit::WebGraphicsContext3D { |
| 34 public: |
| 35 |
| 36 WebGraphicsContext3DCommandBufferImpl(); |
| 37 virtual ~WebGraphicsContext3DCommandBufferImpl(); |
| 38 |
| 39 //---------------------------------------------------------------------- |
| 40 // WebGraphicsContext3D methods |
| 41 virtual bool initialize(WebGraphicsContext3D::Attributes attributes); |
| 42 virtual bool makeContextCurrent(); |
| 43 |
| 44 virtual int width(); |
| 45 virtual int height(); |
| 46 |
| 47 virtual int sizeInBytes(int type); |
| 48 |
| 49 virtual void reshape(int width, int height); |
| 50 |
| 51 virtual bool readBackFramebuffer(unsigned char* pixels, size_t buffer_size); |
| 52 |
| 53 virtual void activeTexture(unsigned long texture); |
| 54 virtual void attachShader(WebGLId program, WebGLId shader); |
| 55 virtual void bindAttribLocation(WebGLId program, unsigned long index, |
| 56 const char* name); |
| 57 virtual void bindBuffer(unsigned long target, WebGLId buffer); |
| 58 virtual void bindFramebuffer(unsigned long target, WebGLId framebuffer); |
| 59 virtual void bindRenderbuffer(unsigned long target, WebGLId renderbuffer); |
| 60 virtual void bindTexture(unsigned long target, WebGLId texture); |
| 61 virtual void blendColor(double red, double green, |
| 62 double blue, double alpha); |
| 63 virtual void blendEquation(unsigned long mode); |
| 64 virtual void blendEquationSeparate(unsigned long modeRGB, |
| 65 unsigned long modeAlpha); |
| 66 virtual void blendFunc(unsigned long sfactor, unsigned long dfactor); |
| 67 virtual void blendFuncSeparate(unsigned long srcRGB, |
| 68 unsigned long dstRGB, |
| 69 unsigned long srcAlpha, |
| 70 unsigned long dstAlpha); |
| 71 |
| 72 virtual void bufferData(unsigned long target, int size, |
| 73 const void* data, unsigned long usage); |
| 74 virtual void bufferSubData(unsigned long target, long offset, |
| 75 int size, const void* data); |
| 76 |
| 77 virtual unsigned long checkFramebufferStatus(unsigned long target); |
| 78 virtual void clear(unsigned long mask); |
| 79 virtual void clearColor(double red, double green, |
| 80 double blue, double alpha); |
| 81 virtual void clearDepth(double depth); |
| 82 virtual void clearStencil(long s); |
| 83 virtual void colorMask(bool red, bool green, bool blue, bool alpha); |
| 84 virtual void compileShader(WebGLId shader); |
| 85 |
| 86 virtual void copyTexImage2D(unsigned long target, |
| 87 long level, |
| 88 unsigned long internalformat, |
| 89 long x, |
| 90 long y, |
| 91 unsigned long width, |
| 92 unsigned long height, |
| 93 long border); |
| 94 virtual void copyTexSubImage2D(unsigned long target, |
| 95 long level, |
| 96 long xoffset, |
| 97 long yoffset, |
| 98 long x, |
| 99 long y, |
| 100 unsigned long width, |
| 101 unsigned long height); |
| 102 virtual void cullFace(unsigned long mode); |
| 103 virtual void depthFunc(unsigned long func); |
| 104 virtual void depthMask(bool flag); |
| 105 virtual void depthRange(double zNear, double zFar); |
| 106 virtual void detachShader(WebGLId program, WebGLId shader); |
| 107 virtual void disable(unsigned long cap); |
| 108 virtual void disableVertexAttribArray(unsigned long index); |
| 109 virtual void drawArrays(unsigned long mode, long first, long count); |
| 110 virtual void drawElements(unsigned long mode, |
| 111 unsigned long count, |
| 112 unsigned long type, |
| 113 long offset); |
| 114 |
| 115 virtual void enable(unsigned long cap); |
| 116 virtual void enableVertexAttribArray(unsigned long index); |
| 117 virtual void finish(); |
| 118 virtual void flush(); |
| 119 virtual void framebufferRenderbuffer(unsigned long target, |
| 120 unsigned long attachment, |
| 121 unsigned long renderbuffertarget, |
| 122 WebGLId renderbuffer); |
| 123 virtual void framebufferTexture2D(unsigned long target, |
| 124 unsigned long attachment, |
| 125 unsigned long textarget, |
| 126 WebGLId texture, |
| 127 long level); |
| 128 virtual void frontFace(unsigned long mode); |
| 129 virtual void generateMipmap(unsigned long target); |
| 130 |
| 131 virtual bool getActiveAttrib(WebGLId program, |
| 132 unsigned long index, |
| 133 ActiveInfo&); |
| 134 virtual bool getActiveUniform(WebGLId program, |
| 135 unsigned long index, |
| 136 ActiveInfo&); |
| 137 |
| 138 virtual int getAttribLocation(WebGLId program, const char* name); |
| 139 |
| 140 virtual void getBooleanv(unsigned long pname, unsigned char* value); |
| 141 |
| 142 virtual void getBufferParameteriv(unsigned long target, |
| 143 unsigned long pname, |
| 144 int* value); |
| 145 |
| 146 virtual Attributes getContextAttributes(); |
| 147 |
| 148 virtual unsigned long getError(); |
| 149 |
| 150 virtual void getFloatv(unsigned long pname, float* value); |
| 151 |
| 152 virtual void getFramebufferAttachmentParameteriv(unsigned long target, |
| 153 unsigned long attachment, |
| 154 unsigned long pname, |
| 155 int* value); |
| 156 |
| 157 virtual void getIntegerv(unsigned long pname, int* value); |
| 158 |
| 159 virtual void getProgramiv(WebGLId program, unsigned long pname, int* value); |
| 160 |
| 161 virtual WebKit::WebString getProgramInfoLog(WebGLId program); |
| 162 |
| 163 virtual void getRenderbufferParameteriv(unsigned long target, |
| 164 unsigned long pname, |
| 165 int* value); |
| 166 |
| 167 virtual void getShaderiv(WebGLId shader, unsigned long pname, int* value); |
| 168 |
| 169 virtual WebKit::WebString getShaderInfoLog(WebGLId shader); |
| 170 |
| 171 // TBD |
| 172 // void glGetShaderPrecisionFormat (GLenum shadertype, |
| 173 // GLenum precisiontype, |
| 174 // GLint* range, |
| 175 // GLint* precision); |
| 176 |
| 177 virtual WebKit::WebString getShaderSource(WebGLId shader); |
| 178 virtual WebKit::WebString getString(unsigned long name); |
| 179 |
| 180 virtual void getTexParameterfv(unsigned long target, |
| 181 unsigned long pname, |
| 182 float* value); |
| 183 virtual void getTexParameteriv(unsigned long target, |
| 184 unsigned long pname, |
| 185 int* value); |
| 186 |
| 187 virtual void getUniformfv(WebGLId program, long location, float* value); |
| 188 virtual void getUniformiv(WebGLId program, long location, int* value); |
| 189 |
| 190 virtual long getUniformLocation(WebGLId program, const char* name); |
| 191 |
| 192 virtual void getVertexAttribfv(unsigned long index, unsigned long pname, |
| 193 float* value); |
| 194 virtual void getVertexAttribiv(unsigned long index, unsigned long pname, |
| 195 int* value); |
| 196 |
| 197 virtual long getVertexAttribOffset(unsigned long index, unsigned long pname); |
| 198 |
| 199 virtual void hint(unsigned long target, unsigned long mode); |
| 200 virtual bool isBuffer(WebGLId buffer); |
| 201 virtual bool isEnabled(unsigned long cap); |
| 202 virtual bool isFramebuffer(WebGLId framebuffer); |
| 203 virtual bool isProgram(WebGLId program); |
| 204 virtual bool isRenderbuffer(WebGLId renderbuffer); |
| 205 virtual bool isShader(WebGLId shader); |
| 206 virtual bool isTexture(WebGLId texture); |
| 207 virtual void lineWidth(double); |
| 208 virtual void linkProgram(WebGLId program); |
| 209 virtual void pixelStorei(unsigned long pname, long param); |
| 210 virtual void polygonOffset(double factor, double units); |
| 211 |
| 212 virtual void readPixels(long x, |
| 213 long y, |
| 214 unsigned long width, |
| 215 unsigned long height, |
| 216 unsigned long format, |
| 217 unsigned long type, |
| 218 void* pixels); |
| 219 |
| 220 virtual void releaseShaderCompiler(); |
| 221 virtual void renderbufferStorage(unsigned long target, |
| 222 unsigned long internalformat, |
| 223 unsigned long width, |
| 224 unsigned long height); |
| 225 virtual void sampleCoverage(double value, bool invert); |
| 226 virtual void scissor(long x, long y, |
| 227 unsigned long width, unsigned long height); |
| 228 virtual void shaderSource(WebGLId shader, const char* string); |
| 229 virtual void stencilFunc(unsigned long func, long ref, unsigned long mask); |
| 230 virtual void stencilFuncSeparate(unsigned long face, |
| 231 unsigned long func, |
| 232 long ref, |
| 233 unsigned long mask); |
| 234 virtual void stencilMask(unsigned long mask); |
| 235 virtual void stencilMaskSeparate(unsigned long face, unsigned long mask); |
| 236 virtual void stencilOp(unsigned long fail, |
| 237 unsigned long zfail, |
| 238 unsigned long zpass); |
| 239 virtual void stencilOpSeparate(unsigned long face, |
| 240 unsigned long fail, |
| 241 unsigned long zfail, |
| 242 unsigned long zpass); |
| 243 |
| 244 virtual void texImage2D(unsigned target, |
| 245 unsigned level, |
| 246 unsigned internalformat, |
| 247 unsigned width, |
| 248 unsigned height, |
| 249 unsigned border, |
| 250 unsigned format, |
| 251 unsigned type, |
| 252 const void* pixels); |
| 253 |
| 254 virtual void texParameterf(unsigned target, unsigned pname, float param); |
| 255 virtual void texParameteri(unsigned target, unsigned pname, int param); |
| 256 |
| 257 virtual void texSubImage2D(unsigned target, |
| 258 unsigned level, |
| 259 unsigned xoffset, |
| 260 unsigned yoffset, |
| 261 unsigned width, |
| 262 unsigned height, |
| 263 unsigned format, |
| 264 unsigned type, |
| 265 const void* pixels); |
| 266 |
| 267 virtual void uniform1f(long location, float x); |
| 268 virtual void uniform1fv(long location, int count, float* v); |
| 269 virtual void uniform1i(long location, int x); |
| 270 virtual void uniform1iv(long location, int count, int* v); |
| 271 virtual void uniform2f(long location, float x, float y); |
| 272 virtual void uniform2fv(long location, int count, float* v); |
| 273 virtual void uniform2i(long location, int x, int y); |
| 274 virtual void uniform2iv(long location, int count, int* v); |
| 275 virtual void uniform3f(long location, float x, float y, float z); |
| 276 virtual void uniform3fv(long location, int count, float* v); |
| 277 virtual void uniform3i(long location, int x, int y, int z); |
| 278 virtual void uniform3iv(long location, int count, int* v); |
| 279 virtual void uniform4f(long location, float x, float y, float z, float w); |
| 280 virtual void uniform4fv(long location, int count, float* v); |
| 281 virtual void uniform4i(long location, int x, int y, int z, int w); |
| 282 virtual void uniform4iv(long location, int count, int* v); |
| 283 virtual void uniformMatrix2fv(long location, int count, bool transpose, |
| 284 const float* value); |
| 285 virtual void uniformMatrix3fv(long location, int count, bool transpose, |
| 286 const float* value); |
| 287 virtual void uniformMatrix4fv(long location, int count, bool transpose, |
| 288 const float* value); |
| 289 |
| 290 virtual void useProgram(WebGLId program); |
| 291 virtual void validateProgram(WebGLId program); |
| 292 |
| 293 virtual void vertexAttrib1f(unsigned long indx, float x); |
| 294 virtual void vertexAttrib1fv(unsigned long indx, const float* values); |
| 295 virtual void vertexAttrib2f(unsigned long indx, float x, float y); |
| 296 virtual void vertexAttrib2fv(unsigned long indx, const float* values); |
| 297 virtual void vertexAttrib3f(unsigned long indx, float x, float y, float z); |
| 298 virtual void vertexAttrib3fv(unsigned long indx, const float* values); |
| 299 virtual void vertexAttrib4f(unsigned long indx, |
| 300 float x, float y, float z, float w); |
| 301 virtual void vertexAttrib4fv(unsigned long indx, const float* values); |
| 302 virtual void vertexAttribPointer(unsigned long indx, int size, int type, |
| 303 bool normalized, unsigned long stride, |
| 304 unsigned long offset); |
| 305 |
| 306 virtual void viewport(long x, long y, |
| 307 unsigned long width, unsigned long height); |
| 308 |
| 309 // Support for buffer creation and deletion |
| 310 virtual unsigned createBuffer(); |
| 311 virtual unsigned createFramebuffer(); |
| 312 virtual unsigned createProgram(); |
| 313 virtual unsigned createRenderbuffer(); |
| 314 virtual unsigned createShader(unsigned long); |
| 315 virtual unsigned createTexture(); |
| 316 |
| 317 virtual void deleteBuffer(unsigned); |
| 318 virtual void deleteFramebuffer(unsigned); |
| 319 virtual void deleteProgram(unsigned); |
| 320 virtual void deleteRenderbuffer(unsigned); |
| 321 virtual void deleteShader(unsigned); |
| 322 virtual void deleteTexture(unsigned); |
| 323 |
| 324 virtual void synthesizeGLError(unsigned long error); |
| 325 |
| 326 private: |
| 327 // The GGL context we use for OpenGL rendering. |
| 328 ggl::Context* context_; |
| 329 |
| 330 WebKit::WebGraphicsContext3D::Attributes attributes_; |
| 331 unsigned int texture_; |
| 332 unsigned int fbo_; |
| 333 unsigned int depth_buffer_; |
| 334 int cached_width_, cached_height_; |
| 335 |
| 336 // For tracking which FBO is bound. |
| 337 unsigned int bound_fbo_; |
| 338 |
| 339 // Errors raised by synthesizeGLError(). |
| 340 std::vector<unsigned long> synthetic_errors_; |
| 341 |
| 342 #ifdef FLIP_FRAMEBUFFER_VERTICALLY |
| 343 scoped_ptr<uint8> scanline_; |
| 344 void FlipVertically(uint8* framebuffer, |
| 345 unsigned int width, |
| 346 unsigned int height); |
| 347 #endif |
| 348 }; |
| 349 |
| 350 #endif // defined(ENABLE_GPU) |
| 351 #endif // CHROME_RENDERER_WEBGRAPHICSCONTEXT3D_COMMAND_BUFFER_IMPL_H_ |
| 352 |
OLD | NEW |