Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: webkit/gpu/webgraphicscontext3d_in_process_impl.h

Issue 6100009: Move the in-process WebGL implementation from the WebKit to the... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(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 WEBKIT_GPU_WEBGRAPHICSCONTEXT3D_IN_PROCESS_IMPL_H_
6 #define WEBKIT_GPU_WEBGRAPHICSCONTEXT3D_IN_PROCESS_IMPL_H_
7
8 #include <list>
9 #include <set>
10
11 #include "base/hash_tables.h"
12 #include "base/scoped_ptr.h"
13 #include "third_party/angle/include/GLSLANG/ShaderLang.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 namespace gfx {
21 class GLContext;
22 }
23
24 namespace webkit_gpu {
darin (slow to review) 2011/01/11 20:41:56 one more nit: according to brettw's post to chrom
25
26 // The default implementation of WebGL. In Chromium, using this class
27 // requires the sandbox to be disabled, which is strongly discouraged.
28 // It is provided for support of test_shell and any Chromium ports
29 // where an in-renderer WebGL implementation would be helpful.
30
31 class WebGraphicsContext3DInProcessImpl : public WebKit::WebGraphicsContext3D {
32 public:
33 WebGraphicsContext3DInProcessImpl();
34 virtual ~WebGraphicsContext3DInProcessImpl();
35
36 //----------------------------------------------------------------------
37 // WebGraphicsContext3D methods
38 virtual bool initialize(
39 WebGraphicsContext3D::Attributes attributes, WebKit::WebView*, bool);
40 virtual bool makeContextCurrent();
41
42 virtual int width();
43 virtual int height();
44
45 virtual int sizeInBytes(int type);
46
47 virtual bool isGLES2Compliant();
48
49 virtual void reshape(int width, int height);
50
51 virtual bool readBackFramebuffer(unsigned char* pixels, size_t bufferSize);
52
53 virtual unsigned int getPlatformTextureId();
54 virtual void prepareTexture();
55
56 virtual void synthesizeGLError(unsigned long error);
57 virtual void* mapBufferSubDataCHROMIUM(
58 unsigned target, int offset, int size, unsigned access);
59 virtual void unmapBufferSubDataCHROMIUM(const void*);
60 virtual void* mapTexSubImage2DCHROMIUM(
61 unsigned target,
62 int level,
63 int xoffset,
64 int yoffset,
65 int width,
66 int height,
67 unsigned format,
68 unsigned type,
69 unsigned access);
70 virtual void unmapTexSubImage2DCHROMIUM(const void*);
71 virtual void copyTextureToParentTextureCHROMIUM(
72 unsigned texture, unsigned parentTexture);
73
74 virtual WebKit::WebString getRequestableExtensionsCHROMIUM();
75 virtual void requestExtensionCHROMIUM(const char*);
76
77 virtual void activeTexture(unsigned long texture);
78 virtual void attachShader(WebKit::WebGLId program, WebKit::WebGLId shader);
79 virtual void bindAttribLocation(
80 WebKit::WebGLId program, unsigned long index, const char* name);
81 virtual void bindBuffer(unsigned long target, WebKit::WebGLId buffer);
82 virtual void bindFramebuffer(
83 unsigned long target, WebKit::WebGLId framebuffer);
84 virtual void bindRenderbuffer(
85 unsigned long target, WebKit::WebGLId renderbuffer);
86 virtual void bindTexture(unsigned long target, WebKit::WebGLId texture);
87 virtual void blendColor(
88 double red, double green, double blue, double alpha);
89 virtual void blendEquation(unsigned long mode);
90 virtual void blendEquationSeparate(
91 unsigned long modeRGB, unsigned long modeAlpha);
92 virtual void blendFunc(unsigned long sfactor, unsigned long dfactor);
93 virtual void blendFuncSeparate(
94 unsigned long srcRGB,
95 unsigned long dstRGB,
96 unsigned long srcAlpha,
97 unsigned long dstAlpha);
98
99 virtual void bufferData(
100 unsigned long target, int size, const void* data, unsigned long usage);
101 virtual void bufferSubData(
102 unsigned long target, long offset, int size, const void* data);
103
104 virtual unsigned long checkFramebufferStatus(unsigned long target);
105 virtual void clear(unsigned long mask);
106 virtual void clearColor(
107 double red, double green, double blue, double alpha);
108 virtual void clearDepth(double depth);
109 virtual void clearStencil(long s);
110 virtual void colorMask(bool red, bool green, bool blue, bool alpha);
111 virtual void compileShader(WebKit::WebGLId shader);
112
113 virtual void copyTexImage2D(
114 unsigned long target,
115 long level,
116 unsigned long internalformat,
117 long x,
118 long y,
119 unsigned long width,
120 unsigned long height,
121 long border);
122 virtual void copyTexSubImage2D(
123 unsigned long target,
124 long level,
125 long xoffset,
126 long yoffset,
127 long x,
128 long y,
129 unsigned long width,
130 unsigned long height);
131 virtual void cullFace(unsigned long mode);
132 virtual void depthFunc(unsigned long func);
133 virtual void depthMask(bool flag);
134 virtual void depthRange(double zNear, double zFar);
135 virtual void detachShader(WebKit::WebGLId program, WebKit::WebGLId shader);
136 virtual void disable(unsigned long cap);
137 virtual void disableVertexAttribArray(unsigned long index);
138 virtual void drawArrays(unsigned long mode, long first, long count);
139 virtual void drawElements(
140 unsigned long mode,
141 unsigned long count,
142 unsigned long type,
143 long offset);
144
145 virtual void enable(unsigned long cap);
146 virtual void enableVertexAttribArray(unsigned long index);
147 virtual void finish();
148 virtual void flush();
149 virtual void framebufferRenderbuffer(
150 unsigned long target,
151 unsigned long attachment,
152 unsigned long renderbuffertarget,
153 WebKit::WebGLId renderbuffer);
154 virtual void framebufferTexture2D(
155 unsigned long target,
156 unsigned long attachment,
157 unsigned long textarget,
158 WebKit::WebGLId texture,
159 long level);
160 virtual void frontFace(unsigned long mode);
161 virtual void generateMipmap(unsigned long target);
162
163 virtual bool getActiveAttrib(
164 WebKit::WebGLId program, unsigned long index, ActiveInfo&);
165 virtual bool getActiveUniform(
166 WebKit::WebGLId program, unsigned long index, ActiveInfo&);
167
168 virtual void getAttachedShaders(
169 WebKit::WebGLId program, int maxCount, int* count, unsigned int* shaders);
170
171 virtual int getAttribLocation(WebKit::WebGLId program, const char* name);
172
173 virtual void getBooleanv(unsigned long pname, unsigned char* value);
174
175 virtual void getBufferParameteriv(
176 unsigned long target, unsigned long pname, int* value);
177
178 virtual Attributes getContextAttributes();
179
180 virtual unsigned long getError();
181
182 virtual bool isContextLost();
183
184 virtual void getFloatv(unsigned long pname, float* value);
185
186 virtual void getFramebufferAttachmentParameteriv(
187 unsigned long target,
188 unsigned long attachment,
189 unsigned long pname,
190 int* value);
191
192 virtual void getIntegerv(unsigned long pname, int* value);
193
194 virtual void getProgramiv(
195 WebKit::WebGLId program, unsigned long pname, int* value);
196
197 virtual WebKit::WebString getProgramInfoLog(WebKit::WebGLId program);
198
199 virtual void getRenderbufferParameteriv(
200 unsigned long target, unsigned long pname, int* value);
201
202 virtual void getShaderiv(
203 WebKit::WebGLId shader, unsigned long pname, int* value);
204
205 virtual WebKit::WebString getShaderInfoLog(WebKit::WebGLId shader);
206
207 // TBD
208 // void glGetShaderPrecisionFormat(
209 // GLenum shadertype, GLenum precisiontype,
210 // GLint* range, GLint* precision);
211
212 virtual WebKit::WebString getShaderSource(WebKit::WebGLId shader);
213 virtual WebKit::WebString getString(unsigned long name);
214
215 virtual void getTexParameterfv(
216 unsigned long target, unsigned long pname, float* value);
217 virtual void getTexParameteriv(
218 unsigned long target, unsigned long pname, int* value);
219
220 virtual void getUniformfv(
221 WebKit::WebGLId program, long location, float* value);
222 virtual void getUniformiv(
223 WebKit::WebGLId program, long location, int* value);
224
225 virtual long getUniformLocation(WebKit::WebGLId program, const char* name);
226
227 virtual void getVertexAttribfv(
228 unsigned long index, unsigned long pname, float* value);
229 virtual void getVertexAttribiv(
230 unsigned long index, unsigned long pname, int* value);
231
232 virtual long getVertexAttribOffset(
233 unsigned long index, unsigned long pname);
234
235 virtual void hint(unsigned long target, unsigned long mode);
236 virtual bool isBuffer(WebKit::WebGLId buffer);
237 virtual bool isEnabled(unsigned long cap);
238 virtual bool isFramebuffer(WebKit::WebGLId framebuffer);
239 virtual bool isProgram(WebKit::WebGLId program);
240 virtual bool isRenderbuffer(WebKit::WebGLId renderbuffer);
241 virtual bool isShader(WebKit::WebGLId shader);
242 virtual bool isTexture(WebKit::WebGLId texture);
243 virtual void lineWidth(double width);
244 virtual void linkProgram(WebKit::WebGLId program);
245 virtual void pixelStorei(unsigned long pname, long param);
246 virtual void polygonOffset(double factor, double units);
247
248 virtual void readPixels(
249 long x, long y,
250 unsigned long width, unsigned long height,
251 unsigned long format,
252 unsigned long type,
253 void* pixels);
254
255 virtual void releaseShaderCompiler();
256 virtual void renderbufferStorage(
257 unsigned long target,
258 unsigned long internalformat,
259 unsigned long width,
260 unsigned long height);
261 virtual void sampleCoverage(double value, bool invert);
262 virtual void scissor(
263 long x, long y, unsigned long width, unsigned long height);
264 virtual void shaderSource(WebKit::WebGLId shader, const char* source);
265 virtual void stencilFunc(unsigned long func, long ref, unsigned long mask);
266 virtual void stencilFuncSeparate(
267 unsigned long face, unsigned long func, long ref, unsigned long mask);
268 virtual void stencilMask(unsigned long mask);
269 virtual void stencilMaskSeparate(unsigned long face, unsigned long mask);
270 virtual void stencilOp(
271 unsigned long fail, unsigned long zfail, unsigned long zpass);
272 virtual void stencilOpSeparate(
273 unsigned long face,
274 unsigned long fail,
275 unsigned long zfail,
276 unsigned long zpass);
277
278 virtual void texImage2D(
279 unsigned target,
280 unsigned level,
281 unsigned internalformat,
282 unsigned width,
283 unsigned height,
284 unsigned border,
285 unsigned format,
286 unsigned type,
287 const void* pixels);
288
289 virtual void texParameterf(unsigned target, unsigned pname, float param);
290 virtual void texParameteri(unsigned target, unsigned pname, int param);
291
292 virtual void texSubImage2D(
293 unsigned target,
294 unsigned level,
295 unsigned xoffset,
296 unsigned yoffset,
297 unsigned width,
298 unsigned height,
299 unsigned format,
300 unsigned type,
301 const void* pixels);
302
303 virtual void uniform1f(long location, float x);
304 virtual void uniform1fv(long location, int count, float* v);
305 virtual void uniform1i(long location, int x);
306 virtual void uniform1iv(long location, int count, int* v);
307 virtual void uniform2f(long location, float x, float y);
308 virtual void uniform2fv(long location, int count, float* v);
309 virtual void uniform2i(long location, int x, int y);
310 virtual void uniform2iv(long location, int count, int* v);
311 virtual void uniform3f(long location, float x, float y, float z);
312 virtual void uniform3fv(long location, int count, float* v);
313 virtual void uniform3i(long location, int x, int y, int z);
314 virtual void uniform3iv(long location, int count, int* v);
315 virtual void uniform4f(long location, float x, float y, float z, float w);
316 virtual void uniform4fv(long location, int count, float* v);
317 virtual void uniform4i(long location, int x, int y, int z, int w);
318 virtual void uniform4iv(long location, int count, int* v);
319 virtual void uniformMatrix2fv(
320 long location, int count, bool transpose, const float* value);
321 virtual void uniformMatrix3fv(
322 long location, int count, bool transpose, const float* value);
323 virtual void uniformMatrix4fv(
324 long location, int count, bool transpose, const float* value);
325
326 virtual void useProgram(WebKit::WebGLId program);
327 virtual void validateProgram(WebKit::WebGLId program);
328
329 virtual void vertexAttrib1f(unsigned long indx, float x);
330 virtual void vertexAttrib1fv(unsigned long indx, const float* values);
331 virtual void vertexAttrib2f(unsigned long indx, float x, float y);
332 virtual void vertexAttrib2fv(unsigned long indx, const float* values);
333 virtual void vertexAttrib3f(unsigned long indx, float x, float y, float z);
334 virtual void vertexAttrib3fv(unsigned long indx, const float* values);
335 virtual void vertexAttrib4f(
336 unsigned long indx, float x, float y, float z, float w);
337 virtual void vertexAttrib4fv(unsigned long indx, const float* values);
338 virtual void vertexAttribPointer(
339 unsigned long indx,
340 int size,
341 int type,
342 bool normalized,
343 unsigned long stride,
344 unsigned long offset);
345
346 virtual void viewport(
347 long x, long y, unsigned long width, unsigned long height);
348
349 // Support for buffer creation and deletion
350 virtual unsigned createBuffer();
351 virtual unsigned createFramebuffer();
352 virtual unsigned createProgram();
353 virtual unsigned createRenderbuffer();
354 virtual unsigned createShader(unsigned long);
355 virtual unsigned createTexture();
356
357 virtual void deleteBuffer(unsigned);
358 virtual void deleteFramebuffer(unsigned);
359 virtual void deleteProgram(unsigned);
360 virtual void deleteRenderbuffer(unsigned);
361 virtual void deleteShader(unsigned);
362 virtual void deleteTexture(unsigned);
363
364 private:
365 // Note: we aren't currently using this information, but we will
366 // need to in order to verify that all enabled vertex arrays have
367 // a valid buffer bound -- to avoid crashes on certain cards.
368 struct VertexAttribPointerState {
369 VertexAttribPointerState();
370
371 bool enabled;
372 unsigned long buffer;
373 unsigned long indx;
374 int size;
375 int type;
376 bool normalized;
377 unsigned long stride;
378 unsigned long offset;
379 };
380
381 enum {
382 kNumTrackedPointerStates = 2
383 };
384
385 // ANGLE related.
386 struct ShaderSourceEntry {
387 explicit ShaderSourceEntry(unsigned long shader_type)
388 : type(shader_type),
389 is_valid(false) {
390 }
391
392 unsigned long type;
393 scoped_array<char> source;
394 scoped_array<char> log;
395 scoped_array<char> translated_source;
396 bool is_valid;
397 };
398
399 WebGraphicsContext3D::Attributes attributes_;
400 bool initialized_;
401 bool render_directly_to_web_view_;
402 bool is_gles2_;
403 bool have_ext_framebuffer_object_;
404 bool have_ext_framebuffer_multisample_;
405 bool have_angle_framebuffer_multisample_;
406
407 unsigned int texture_;
408 unsigned int fbo_;
409 unsigned int depth_stencil_buffer_;
410 unsigned int cached_width_, cached_height_;
411
412 // For multisampling
413 unsigned int multisample_fbo_;
414 unsigned int multisample_depth_stencil_buffer_;
415 unsigned int multisample_color_buffer_;
416
417 // For tracking which FBO is bound
418 unsigned int bound_fbo_;
419
420 // For tracking which texture is bound
421 unsigned int bound_texture_;
422
423 // FBO used for copying child texture to parent texture.
424 unsigned copy_texture_to_parent_texture_fbo_;
425
426 unsigned int bound_array_buffer_;
427
428 #ifdef FLIP_FRAMEBUFFER_VERTICALLY
429 unsigned char* scanline_;
430 #endif
431
432 VertexAttribPointerState vertex_attrib_pointer_state_[
433 kNumTrackedPointerStates];
434
435 // Errors raised by synthesizeGLError().
436 std::list<unsigned long> synthetic_errors_list_;
437 std::set<unsigned long> synthetic_errors_set_;
438
439 scoped_ptr<gfx::GLContext> gl_context_;
440
441 typedef base::hash_map<WebKit::WebGLId, ShaderSourceEntry*> ShaderSourceMap;
442 ShaderSourceMap shader_source_map_;
443
444 ShHandle fragment_compiler_;
445 ShHandle vertex_compiler_;
446
447 #ifdef FLIP_FRAMEBUFFER_VERTICALLY
448 void FlipVertically(unsigned char* framebuffer,
449 unsigned int width,
450 unsigned int height);
451 #endif
452
453 // Take into account the user's requested context creation attributes, in
454 // particular stencil and antialias, and determine which could or could
455 // not be honored based on the capabilities of the OpenGL implementation.
456 void ValidateAttributes();
darin (slow to review) 2011/01/11 19:32:51 nit: order of stuff in private section is usually:
457
458 // Resolve the given rectangle of the multisampled framebuffer if necessary.
459 void ResolveMultisampledFramebuffer(
460 unsigned x, unsigned y, unsigned width, unsigned height);
461
462 bool AngleCreateCompilers();
463 void AngleDestroyCompilers();
464 bool AngleValidateShaderSource(ShaderSourceEntry* entry);
465 };
466
467 } // namespace webkit_gpu
468
469 #endif // WEBKIT_GPU_WEBGRAPHICSCONTEXT3D_IN_PROCESS_IMPL_H_
470
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698