1 // Copyright 2011 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.
5 #ifndef CC_TEST_FAKE_WEB_GRAPHICS_CONTEXT_3D_H_
6 #define CC_TEST_FAKE_WEB_GRAPHICS_CONTEXT_3D_H_
8 #include "third_party/khronos/GLES2/gl2.h"
9 #include <public/WebGraphicsContext3D.h>
13 // WebGraphicsContext3D base class for use in WebKit unit tests.
14 // All operations are no-ops (returning 0 if necessary).
15 class FakeWebGraphicsContext3D
: public WebGraphicsContext3D
{
17 FakeWebGraphicsContext3D()
22 virtual bool makeContextCurrent() { return true; }
24 virtual int width() { return 0; }
25 virtual int height() { return 0; }
27 virtual void reshape(int width
, int height
) { }
29 virtual bool isGLES2Compliant() { return false; }
31 virtual bool readBackFramebuffer(unsigned char* pixels
, size_t bufferSize
, WebGLId framebuffer
, int width
, int height
) { return false; }
33 virtual WebGLId
getPlatformTextureId() { return 0; }
35 virtual void prepareTexture() { }
37 virtual void postSubBufferCHROMIUM(int x
, int y
, int width
, int height
) { }
39 virtual void synthesizeGLError(WGC3Denum
) { }
41 virtual bool isContextLost() { return false; }
43 virtual void* mapBufferSubDataCHROMIUM(WGC3Denum target
, WGC3Dintptr offset
, WGC3Dsizeiptr size
, WGC3Denum access
) { return 0; }
44 virtual void unmapBufferSubDataCHROMIUM(const void*) { }
45 virtual void* mapTexSubImage2DCHROMIUM(WGC3Denum target
, WGC3Dint level
, WGC3Dint xoffset
, WGC3Dint yoffset
, WGC3Dsizei width
, WGC3Dsizei height
, WGC3Denum format
, WGC3Denum type
, WGC3Denum access
) { return 0; }
46 virtual void unmapTexSubImage2DCHROMIUM(const void*) { }
48 virtual void setVisibilityCHROMIUM(bool visible
) { }
50 virtual void discardFramebufferEXT(WGC3Denum target
, WGC3Dsizei numAttachments
, const WGC3Denum
* attachments
) { }
51 virtual void ensureFramebufferCHROMIUM() { }
53 virtual void setMemoryAllocationChangedCallbackCHROMIUM(WebGraphicsMemoryAllocationChangedCallbackCHROMIUM
* callback
) { }
55 virtual WebString
getRequestableExtensionsCHROMIUM() { return WebString(); }
56 virtual void requestExtensionCHROMIUM(const char*) { }
58 virtual void blitFramebufferCHROMIUM(WGC3Dint srcX0
, WGC3Dint srcY0
, WGC3Dint srcX1
, WGC3Dint srcY1
, WGC3Dint dstX0
, WGC3Dint dstY0
, WGC3Dint dstX1
, WGC3Dint dstY1
, WGC3Dbitfield mask
, WGC3Denum filter
) { }
59 virtual void renderbufferStorageMultisampleCHROMIUM(WGC3Denum target
, WGC3Dsizei samples
, WGC3Denum internalformat
, WGC3Dsizei width
, WGC3Dsizei height
) { }
61 virtual void activeTexture(WGC3Denum texture
) { }
62 virtual void attachShader(WebGLId program
, WebGLId shader
) { }
63 virtual void bindAttribLocation(WebGLId program
, WGC3Duint index
, const WGC3Dchar
* name
) { }
64 virtual void bindBuffer(WGC3Denum target
, WebGLId buffer
) { }
65 virtual void bindFramebuffer(WGC3Denum target
, WebGLId framebuffer
) { }
66 virtual void bindRenderbuffer(WGC3Denum target
, WebGLId renderbuffer
) { }
67 virtual void bindTexture(WGC3Denum target
, WebGLId texture
) { }
68 virtual void blendColor(WGC3Dclampf red
, WGC3Dclampf green
, WGC3Dclampf blue
, WGC3Dclampf alpha
) { }
69 virtual void blendEquation(WGC3Denum mode
) { }
70 virtual void blendEquationSeparate(WGC3Denum modeRGB
, WGC3Denum modeAlpha
) { }
71 virtual void blendFunc(WGC3Denum sfactor
, WGC3Denum dfactor
) { }
72 virtual void blendFuncSeparate(WGC3Denum srcRGB
, WGC3Denum dstRGB
, WGC3Denum srcAlpha
, WGC3Denum dstAlpha
) { }
74 virtual void bufferData(WGC3Denum target
, WGC3Dsizeiptr size
, const void* data
, WGC3Denum usage
) { }
75 virtual void bufferSubData(WGC3Denum target
, WGC3Dintptr offset
, WGC3Dsizeiptr size
, const void* data
) { }
77 virtual WGC3Denum
checkFramebufferStatus(WGC3Denum target
)
79 return GL_FRAMEBUFFER_COMPLETE
;
82 virtual void clear(WGC3Dbitfield mask
) { }
83 virtual void clearColor(WGC3Dclampf red
, WGC3Dclampf green
, WGC3Dclampf blue
, WGC3Dclampf alpha
) { }
84 virtual void clearDepth(WGC3Dclampf depth
) { }
85 virtual void clearStencil(WGC3Dint s
) { }
86 virtual void colorMask(WGC3Dboolean red
, WGC3Dboolean green
, WGC3Dboolean blue
, WGC3Dboolean alpha
) { }
87 virtual void compileShader(WebGLId shader
) { }
89 virtual void compressedTexImage2D(WGC3Denum target
, WGC3Dint level
, WGC3Denum internalformat
, WGC3Dsizei width
, WGC3Dsizei height
, WGC3Dint border
, WGC3Dsizei imageSize
, const void* data
) { }
90 virtual void compressedTexSubImage2D(WGC3Denum target
, WGC3Dint level
, WGC3Dint xoffset
, WGC3Dint yoffset
, WGC3Dsizei width
, WGC3Dsizei height
, WGC3Denum format
, WGC3Dsizei imageSize
, const void* data
) { }
91 virtual void copyTexImage2D(WGC3Denum target
, WGC3Dint level
, WGC3Denum internalformat
, WGC3Dint x
, WGC3Dint y
, WGC3Dsizei width
, WGC3Dsizei height
, WGC3Dint border
) { }
92 virtual void copyTexSubImage2D(WGC3Denum target
, WGC3Dint level
, WGC3Dint xoffset
, WGC3Dint yoffset
, WGC3Dint x
, WGC3Dint y
, WGC3Dsizei width
, WGC3Dsizei height
) { }
93 virtual void cullFace(WGC3Denum mode
) { }
94 virtual void depthFunc(WGC3Denum func
) { }
95 virtual void depthMask(WGC3Dboolean flag
) { }
96 virtual void depthRange(WGC3Dclampf zNear
, WGC3Dclampf zFar
) { }
97 virtual void detachShader(WebGLId program
, WebGLId shader
) { }
98 virtual void disable(WGC3Denum cap
) { }
99 virtual void disableVertexAttribArray(WGC3Duint index
) { }
100 virtual void drawArrays(WGC3Denum mode
, WGC3Dint first
, WGC3Dsizei count
) { }
101 virtual void drawElements(WGC3Denum mode
, WGC3Dsizei count
, WGC3Denum type
, WGC3Dintptr offset
) { }
103 virtual void enable(WGC3Denum cap
) { }
104 virtual void enableVertexAttribArray(WGC3Duint index
) { }
105 virtual void finish() { }
106 virtual void flush() { }
107 virtual void framebufferRenderbuffer(WGC3Denum target
, WGC3Denum attachment
, WGC3Denum renderbuffertarget
, WebGLId renderbuffer
) { }
108 virtual void framebufferTexture2D(WGC3Denum target
, WGC3Denum attachment
, WGC3Denum textarget
, WebGLId texture
, WGC3Dint level
) { }
109 virtual void frontFace(WGC3Denum mode
) { }
110 virtual void generateMipmap(WGC3Denum target
) { }
112 virtual bool getActiveAttrib(WebGLId program
, WGC3Duint index
, ActiveInfo
&) { return false; }
113 virtual bool getActiveUniform(WebGLId program
, WGC3Duint index
, ActiveInfo
&) { return false; }
114 virtual void getAttachedShaders(WebGLId program
, WGC3Dsizei maxCount
, WGC3Dsizei
* count
, WebGLId
* shaders
) { }
115 virtual WGC3Dint
getAttribLocation(WebGLId program
, const WGC3Dchar
* name
) { return 0; }
116 virtual void getBooleanv(WGC3Denum pname
, WGC3Dboolean
* value
) { }
117 virtual void getBufferParameteriv(WGC3Denum target
, WGC3Denum pname
, WGC3Dint
* value
) { }
118 virtual Attributes
getContextAttributes() { return m_attrs
; }
119 virtual WGC3Denum
getError() { return 0; }
120 virtual void getFloatv(WGC3Denum pname
, WGC3Dfloat
* value
) { }
121 virtual void getFramebufferAttachmentParameteriv(WGC3Denum target
, WGC3Denum attachment
, WGC3Denum pname
, WGC3Dint
* value
) { }
123 virtual void getIntegerv(WGC3Denum pname
, WGC3Dint
* value
)
125 if (pname
== GL_MAX_TEXTURE_SIZE
)
129 virtual void getProgramiv(WebGLId program
, WGC3Denum pname
, WGC3Dint
* value
)
131 if (pname
== GL_LINK_STATUS
)
135 virtual WebString
getProgramInfoLog(WebGLId program
) { return WebString(); }
136 virtual void getRenderbufferParameteriv(WGC3Denum target
, WGC3Denum pname
, WGC3Dint
* value
) { }
138 virtual void getShaderiv(WebGLId shader
, WGC3Denum pname
, WGC3Dint
* value
)
140 if (pname
== GL_COMPILE_STATUS
)
144 virtual WebString
getShaderInfoLog(WebGLId shader
) { return WebString(); }
145 virtual void getShaderPrecisionFormat(WGC3Denum shadertype
, WGC3Denum precisiontype
, WGC3Dint
* range
, WGC3Dint
* precision
) { }
146 virtual WebString
getShaderSource(WebGLId shader
) { return WebString(); }
147 virtual WebString
getString(WGC3Denum name
) { return WebString(); }
148 virtual void getTexParameterfv(WGC3Denum target
, WGC3Denum pname
, WGC3Dfloat
* value
) { }
149 virtual void getTexParameteriv(WGC3Denum target
, WGC3Denum pname
, WGC3Dint
* value
) { }
150 virtual void getUniformfv(WebGLId program
, WGC3Dint location
, WGC3Dfloat
* value
) { }
151 virtual void getUniformiv(WebGLId program
, WGC3Dint location
, WGC3Dint
* value
) { }
152 virtual WGC3Dint
getUniformLocation(WebGLId program
, const WGC3Dchar
* name
) { return 0; }
153 virtual void getVertexAttribfv(WGC3Duint index
, WGC3Denum pname
, WGC3Dfloat
* value
) { }
154 virtual void getVertexAttribiv(WGC3Duint index
, WGC3Denum pname
, WGC3Dint
* value
) { }
155 virtual WGC3Dsizeiptr
getVertexAttribOffset(WGC3Duint index
, WGC3Denum pname
) { return 0; }
157 virtual void hint(WGC3Denum target
, WGC3Denum mode
) { }
158 virtual WGC3Dboolean
isBuffer(WebGLId buffer
) { return false; }
159 virtual WGC3Dboolean
isEnabled(WGC3Denum cap
) { return false; }
160 virtual WGC3Dboolean
isFramebuffer(WebGLId framebuffer
) { return false; }
161 virtual WGC3Dboolean
isProgram(WebGLId program
) { return false; }
162 virtual WGC3Dboolean
isRenderbuffer(WebGLId renderbuffer
) { return false; }
163 virtual WGC3Dboolean
isShader(WebGLId shader
) { return false; }
164 virtual WGC3Dboolean
isTexture(WebGLId texture
) { return false; }
165 virtual void lineWidth(WGC3Dfloat
) { }
166 virtual void linkProgram(WebGLId program
) { }
167 virtual void pixelStorei(WGC3Denum pname
, WGC3Dint param
) { }
168 virtual void polygonOffset(WGC3Dfloat factor
, WGC3Dfloat units
) { }
170 virtual void readPixels(WGC3Dint x
, WGC3Dint y
, WGC3Dsizei width
, WGC3Dsizei height
, WGC3Denum format
, WGC3Denum type
, void* pixels
) { }
172 virtual void releaseShaderCompiler() { }
174 virtual void renderbufferStorage(WGC3Denum target
, WGC3Denum internalformat
, WGC3Dsizei width
, WGC3Dsizei height
) { }
175 virtual void sampleCoverage(WGC3Dclampf value
, WGC3Dboolean invert
) { }
176 virtual void scissor(WGC3Dint x
, WGC3Dint y
, WGC3Dsizei width
, WGC3Dsizei height
) { }
177 virtual void shaderSource(WebGLId shader
, const WGC3Dchar
* string
) { }
178 virtual void stencilFunc(WGC3Denum func
, WGC3Dint ref
, WGC3Duint mask
) { }
179 virtual void stencilFuncSeparate(WGC3Denum face
, WGC3Denum func
, WGC3Dint ref
, WGC3Duint mask
) { }
180 virtual void stencilMask(WGC3Duint mask
) { }
181 virtual void stencilMaskSeparate(WGC3Denum face
, WGC3Duint mask
) { }
182 virtual void stencilOp(WGC3Denum fail
, WGC3Denum zfail
, WGC3Denum zpass
) { }
183 virtual void stencilOpSeparate(WGC3Denum face
, WGC3Denum fail
, WGC3Denum zfail
, WGC3Denum zpass
) { }
185 virtual void texImage2D(WGC3Denum target
, WGC3Dint level
, WGC3Denum internalformat
, WGC3Dsizei width
, WGC3Dsizei height
, WGC3Dint border
, WGC3Denum format
, WGC3Denum type
, const void* pixels
) { }
187 virtual void texParameterf(WGC3Denum target
, WGC3Denum pname
, WGC3Dfloat param
) { }
188 virtual void texParameteri(WGC3Denum target
, WGC3Denum pname
, WGC3Dint param
) { }
190 virtual void texSubImage2D(WGC3Denum target
, WGC3Dint level
, WGC3Dint xoffset
, WGC3Dint yoffset
, WGC3Dsizei width
, WGC3Dsizei height
, WGC3Denum format
, WGC3Denum type
, const void* pixels
) { }
192 virtual void uniform1f(WGC3Dint location
, WGC3Dfloat x
) { }
193 virtual void uniform1fv(WGC3Dint location
, WGC3Dsizei count
, const WGC3Dfloat
* v
) { }
194 virtual void uniform1i(WGC3Dint location
, WGC3Dint x
) { }
195 virtual void uniform1iv(WGC3Dint location
, WGC3Dsizei count
, const WGC3Dint
* v
) { }
196 virtual void uniform2f(WGC3Dint location
, WGC3Dfloat x
, WGC3Dfloat y
) { }
197 virtual void uniform2fv(WGC3Dint location
, WGC3Dsizei count
, const WGC3Dfloat
* v
) { }
198 virtual void uniform2i(WGC3Dint location
, WGC3Dint x
, WGC3Dint y
) { }
199 virtual void uniform2iv(WGC3Dint location
, WGC3Dsizei count
, const WGC3Dint
* v
) { }
200 virtual void uniform3f(WGC3Dint location
, WGC3Dfloat x
, WGC3Dfloat y
, WGC3Dfloat z
) { }
201 virtual void uniform3fv(WGC3Dint location
, WGC3Dsizei count
, const WGC3Dfloat
* v
) { }
202 virtual void uniform3i(WGC3Dint location
, WGC3Dint x
, WGC3Dint y
, WGC3Dint z
) { }
203 virtual void uniform3iv(WGC3Dint location
, WGC3Dsizei count
, const WGC3Dint
* v
) { }
204 virtual void uniform4f(WGC3Dint location
, WGC3Dfloat x
, WGC3Dfloat y
, WGC3Dfloat z
, WGC3Dfloat w
) { }
205 virtual void uniform4fv(WGC3Dint location
, WGC3Dsizei count
, const WGC3Dfloat
* v
) { }
206 virtual void uniform4i(WGC3Dint location
, WGC3Dint x
, WGC3Dint y
, WGC3Dint z
, WGC3Dint w
) { }
207 virtual void uniform4iv(WGC3Dint location
, WGC3Dsizei count
, const WGC3Dint
* v
) { }
208 virtual void uniformMatrix2fv(WGC3Dint location
, WGC3Dsizei count
, WGC3Dboolean transpose
, const WGC3Dfloat
* value
) { }
209 virtual void uniformMatrix3fv(WGC3Dint location
, WGC3Dsizei count
, WGC3Dboolean transpose
, const WGC3Dfloat
* value
) { }
210 virtual void uniformMatrix4fv(WGC3Dint location
, WGC3Dsizei count
, WGC3Dboolean transpose
, const WGC3Dfloat
* value
) { }
212 virtual void useProgram(WebGLId program
) { }
213 virtual void validateProgram(WebGLId program
) { }
215 virtual void vertexAttrib1f(WGC3Duint index
, WGC3Dfloat x
) { }
216 virtual void vertexAttrib1fv(WGC3Duint index
, const WGC3Dfloat
* values
) { }
217 virtual void vertexAttrib2f(WGC3Duint index
, WGC3Dfloat x
, WGC3Dfloat y
) { }
218 virtual void vertexAttrib2fv(WGC3Duint index
, const WGC3Dfloat
* values
) { }
219 virtual void vertexAttrib3f(WGC3Duint index
, WGC3Dfloat x
, WGC3Dfloat y
, WGC3Dfloat z
) { }
220 virtual void vertexAttrib3fv(WGC3Duint index
, const WGC3Dfloat
* values
) { }
221 virtual void vertexAttrib4f(WGC3Duint index
, WGC3Dfloat x
, WGC3Dfloat y
, WGC3Dfloat z
, WGC3Dfloat w
) { }
222 virtual void vertexAttrib4fv(WGC3Duint index
, const WGC3Dfloat
* values
) { }
223 virtual void vertexAttribPointer(WGC3Duint index
, WGC3Dint size
, WGC3Denum type
, WGC3Dboolean normalized
,
224 WGC3Dsizei stride
, WGC3Dintptr offset
) { }
226 virtual void viewport(WGC3Dint x
, WGC3Dint y
, WGC3Dsizei width
, WGC3Dsizei height
) { }
228 virtual WebGLId
createBuffer() { return 1; }
229 virtual WebGLId
createFramebuffer() { return 1; }
230 virtual WebGLId
createProgram() { return 1; }
231 virtual WebGLId
createRenderbuffer() { return 1; }
232 virtual WebGLId
createShader(WGC3Denum
) { return 1; }
233 virtual WebGLId
createTexture() { return m_nextTextureId
++; }
235 virtual void deleteBuffer(WebGLId
) { }
236 virtual void deleteFramebuffer(WebGLId
) { }
237 virtual void deleteProgram(WebGLId
) { }
238 virtual void deleteRenderbuffer(WebGLId
) { }
239 virtual void deleteShader(WebGLId
) { }
240 virtual void deleteTexture(WebGLId
) { }
242 virtual void texStorage2DEXT(WGC3Denum target
, WGC3Dint levels
, WGC3Duint internalformat
,
243 WGC3Dint width
, WGC3Dint height
) { }
245 virtual WebGLId
createQueryEXT() { return 1; }
246 virtual void deleteQueryEXT(WebGLId
) { }
247 virtual WGC3Dboolean
isQueryEXT(WebGLId
) { return true; }
248 virtual void beginQueryEXT(WGC3Denum
, WebGLId
) { }
249 virtual void endQueryEXT(WGC3Denum
) { }
250 virtual void getQueryivEXT(WGC3Denum
, WGC3Denum
, WGC3Dint
*) { }
251 virtual void getQueryObjectuivEXT(WebGLId
, WGC3Denum
, WGC3Duint
*) { }
254 unsigned m_nextTextureId
;
258 } // namespace WebKit
260 #endif // CC_TEST_FAKE_WEB_GRAPHICS_CONTEXT_3D_H_