Upstream version 7.35.139.0
[platform/framework/web/crosswalk.git] / src / content / common / gpu / client / webgraphicscontext3d_command_buffer_impl.h
1 // Copyright (c) 2012 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 CONTENT_COMMON_GPU_CLIENT_WEBGRAPHICSCONTEXT3D_COMMAND_BUFFER_IMPL_H_
6 #define CONTENT_COMMON_GPU_CLIENT_WEBGRAPHICSCONTEXT3D_COMMAND_BUFFER_IMPL_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/callback.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/synchronization/lock.h"
15 #include "content/common/content_export.h"
16 #include "content/common/gpu/client/command_buffer_proxy_impl.h"
17 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
18 #include "third_party/WebKit/public/platform/WebString.h"
19 #include "ui/gfx/native_widget_types.h"
20 #include "ui/gl/gpu_preference.h"
21 #include "url/gurl.h"
22
23 namespace gpu {
24
25 class ContextSupport;
26 class TransferBuffer;
27
28 namespace gles2 {
29 class GLES2CmdHelper;
30 class GLES2Implementation;
31 class GLES2Interface;
32 }
33 }
34
35 using blink::WebGLId;
36
37 using blink::WGC3Dbyte;
38 using blink::WGC3Dchar;
39 using blink::WGC3Denum;
40 using blink::WGC3Dboolean;
41 using blink::WGC3Dbitfield;
42 using blink::WGC3Dint;
43 using blink::WGC3Dsizei;
44 using blink::WGC3Duint;
45 using blink::WGC3Dfloat;
46 using blink::WGC3Dclampf;
47 using blink::WGC3Dintptr;
48 using blink::WGC3Dsizeiptr;
49
50 namespace content {
51 class GpuChannelHost;
52
53 const size_t kDefaultCommandBufferSize = 1024 * 1024;
54 const size_t kDefaultStartTransferBufferSize = 1 * 1024 * 1024;
55 const size_t kDefaultMinTransferBufferSize = 1 * 256 * 1024;
56 const size_t kDefaultMaxTransferBufferSize = 16 * 1024 * 1024;
57
58 class WebGraphicsContext3DErrorMessageCallback;
59
60 class WebGraphicsContext3DCommandBufferImpl
61     : public blink::WebGraphicsContext3D {
62  public:
63   enum MappedMemoryReclaimLimit {
64     kNoLimit = 0,
65   };
66
67   struct CONTENT_EXPORT SharedMemoryLimits {
68     SharedMemoryLimits();
69
70     size_t command_buffer_size;
71     size_t start_transfer_buffer_size;
72     size_t min_transfer_buffer_size;
73     size_t max_transfer_buffer_size;
74     size_t mapped_memory_reclaim_limit;
75   };
76
77   class ShareGroup : public base::RefCountedThreadSafe<ShareGroup> {
78    public:
79     ShareGroup();
80
81     WebGraphicsContext3DCommandBufferImpl* GetAnyContextLocked() {
82       // In order to ensure that the context returned is not removed while
83       // in use, the share group's lock should be aquired before calling this
84       // function.
85       lock_.AssertAcquired();
86       if (contexts_.empty())
87         return NULL;
88       return contexts_.front();
89     }
90
91     void AddContextLocked(WebGraphicsContext3DCommandBufferImpl* context) {
92       lock_.AssertAcquired();
93       contexts_.push_back(context);
94     }
95
96     void RemoveContext(WebGraphicsContext3DCommandBufferImpl* context) {
97       base::AutoLock auto_lock(lock_);
98       contexts_.erase(std::remove(contexts_.begin(), contexts_.end(), context),
99           contexts_.end());
100     }
101
102     void RemoveAllContexts() {
103       base::AutoLock auto_lock(lock_);
104       contexts_.clear();
105     }
106
107     base::Lock& lock() {
108       return lock_;
109     }
110
111    private:
112     friend class base::RefCountedThreadSafe<ShareGroup>;
113     virtual ~ShareGroup();
114
115     std::vector<WebGraphicsContext3DCommandBufferImpl*> contexts_;
116     base::Lock lock_;
117
118     DISALLOW_COPY_AND_ASSIGN(ShareGroup);
119   };
120
121   WebGraphicsContext3DCommandBufferImpl(
122       int surface_id,
123       const GURL& active_url,
124       GpuChannelHost* host,
125       const Attributes& attributes,
126 #if !defined(OS_CHROMEOS)
127       bool bind_generates_resources,
128 #endif
129       bool lose_context_when_out_of_memory,
130       const SharedMemoryLimits& limits,
131       WebGraphicsContext3DCommandBufferImpl* share_context);
132
133   virtual ~WebGraphicsContext3DCommandBufferImpl();
134
135   CommandBufferProxyImpl* GetCommandBufferProxy() {
136     return command_buffer_.get();
137   }
138
139   CONTENT_EXPORT gpu::ContextSupport* GetContextSupport();
140
141   gpu::gles2::GLES2Implementation* GetImplementation() {
142     return real_gl_.get();
143   }
144
145   // Return true if GPU process reported context lost or there was a
146   // problem communicating with the GPU process.
147   bool IsCommandBufferContextLost();
148
149   // Create & initialize a WebGraphicsContext3DCommandBufferImpl.  Return NULL
150   // on any failure.
151   static CONTENT_EXPORT WebGraphicsContext3DCommandBufferImpl*
152       CreateOffscreenContext(
153           GpuChannelHost* host,
154           const WebGraphicsContext3D::Attributes& attributes,
155           bool lose_context_when_out_of_memory,
156           const GURL& active_url,
157           const SharedMemoryLimits& limits,
158           WebGraphicsContext3DCommandBufferImpl* share_context);
159
160   size_t GetMappedMemoryLimit() {
161     return mem_limits_.mapped_memory_reclaim_limit;
162   }
163
164   //----------------------------------------------------------------------
165   // WebGraphicsContext3D methods
166
167   // Must be called after initialize() and before any of the following methods.
168   // Permanently binds to the first calling thread. Returns false if the
169   // graphics context fails to create. Do not call from more than one thread.
170   virtual bool makeContextCurrent();
171
172   virtual uint32_t lastFlushID();
173
174   virtual unsigned int insertSyncPoint();
175   virtual void waitSyncPoint(unsigned int sync_point);
176
177   virtual void loseContextCHROMIUM(WGC3Denum current, WGC3Denum other);
178
179   virtual void reshapeWithScaleFactor(
180       int width, int height, float scale_factor);
181
182   virtual void prepareTexture();
183   virtual void postSubBufferCHROMIUM(int x, int y, int width, int height);
184
185   virtual void activeTexture(WGC3Denum texture);
186   virtual void attachShader(WebGLId program, WebGLId shader);
187   virtual void bindAttribLocation(WebGLId program, WGC3Duint index,
188                                   const WGC3Dchar* name);
189   virtual void bindBuffer(WGC3Denum target, WebGLId buffer);
190   virtual void bindFramebuffer(WGC3Denum target, WebGLId framebuffer);
191   virtual void bindRenderbuffer(WGC3Denum target, WebGLId renderbuffer);
192   virtual void bindTexture(WGC3Denum target, WebGLId texture);
193   virtual void blendColor(WGC3Dclampf red, WGC3Dclampf green,
194                           WGC3Dclampf blue, WGC3Dclampf alpha);
195   virtual void blendEquation(WGC3Denum mode);
196   virtual void blendEquationSeparate(WGC3Denum modeRGB,
197                                      WGC3Denum modeAlpha);
198   virtual void blendFunc(WGC3Denum sfactor, WGC3Denum dfactor);
199   virtual void blendFuncSeparate(WGC3Denum srcRGB,
200                                  WGC3Denum dstRGB,
201                                  WGC3Denum srcAlpha,
202                                  WGC3Denum dstAlpha);
203
204   virtual void bufferData(WGC3Denum target, WGC3Dsizeiptr size,
205                           const void* data, WGC3Denum usage);
206   virtual void bufferSubData(WGC3Denum target, WGC3Dintptr offset,
207                              WGC3Dsizeiptr size, const void* data);
208
209   virtual WGC3Denum checkFramebufferStatus(WGC3Denum target);
210   virtual void clear(WGC3Dbitfield mask);
211   virtual void clearColor(WGC3Dclampf red, WGC3Dclampf green,
212                           WGC3Dclampf blue, WGC3Dclampf alpha);
213   virtual void clearDepth(WGC3Dclampf depth);
214   virtual void clearStencil(WGC3Dint s);
215   virtual void colorMask(WGC3Dboolean red, WGC3Dboolean green,
216                          WGC3Dboolean blue, WGC3Dboolean alpha);
217   virtual void compileShader(WebGLId shader);
218
219   virtual void compressedTexImage2D(WGC3Denum target,
220                                     WGC3Dint level,
221                                     WGC3Denum internalformat,
222                                     WGC3Dsizei width,
223                                     WGC3Dsizei height,
224                                     WGC3Dint border,
225                                     WGC3Dsizei imageSize,
226                                     const void* data);
227   virtual void compressedTexSubImage2D(WGC3Denum target,
228                                        WGC3Dint level,
229                                        WGC3Dint xoffset,
230                                        WGC3Dint yoffset,
231                                        WGC3Dsizei width,
232                                        WGC3Dsizei height,
233                                        WGC3Denum format,
234                                        WGC3Dsizei imageSize,
235                                        const void* data);
236   virtual void copyTexImage2D(WGC3Denum target,
237                               WGC3Dint level,
238                               WGC3Denum internalformat,
239                               WGC3Dint x,
240                               WGC3Dint y,
241                               WGC3Dsizei width,
242                               WGC3Dsizei height,
243                               WGC3Dint border);
244   virtual void copyTexSubImage2D(WGC3Denum target,
245                                  WGC3Dint level,
246                                  WGC3Dint xoffset,
247                                  WGC3Dint yoffset,
248                                  WGC3Dint x,
249                                  WGC3Dint y,
250                                  WGC3Dsizei width,
251                                  WGC3Dsizei height);
252   virtual void cullFace(WGC3Denum mode);
253   virtual void depthFunc(WGC3Denum func);
254   virtual void depthMask(WGC3Dboolean flag);
255   virtual void depthRange(WGC3Dclampf zNear, WGC3Dclampf zFar);
256   virtual void detachShader(WebGLId program, WebGLId shader);
257   virtual void disable(WGC3Denum cap);
258   virtual void disableVertexAttribArray(WGC3Duint index);
259   virtual void drawArrays(WGC3Denum mode, WGC3Dint first, WGC3Dsizei count);
260   virtual void drawElements(WGC3Denum mode,
261                             WGC3Dsizei count,
262                             WGC3Denum type,
263                             WGC3Dintptr offset);
264
265   virtual void enable(WGC3Denum cap);
266   virtual void enableVertexAttribArray(WGC3Duint index);
267   virtual void finish();
268   virtual void flush();
269   virtual void framebufferRenderbuffer(WGC3Denum target,
270                                        WGC3Denum attachment,
271                                        WGC3Denum renderbuffertarget,
272                                        WebGLId renderbuffer);
273   virtual void framebufferTexture2D(WGC3Denum target,
274                                     WGC3Denum attachment,
275                                     WGC3Denum textarget,
276                                     WebGLId texture,
277                                     WGC3Dint level);
278   virtual void frontFace(WGC3Denum mode);
279   virtual void generateMipmap(WGC3Denum target);
280
281   virtual bool getActiveAttrib(WebGLId program,
282                                WGC3Duint index,
283                                ActiveInfo&);
284   virtual bool getActiveUniform(WebGLId program,
285                                 WGC3Duint index,
286                                 ActiveInfo&);
287
288   virtual void getAttachedShaders(WebGLId program,
289                                   WGC3Dsizei maxCount,
290                                   WGC3Dsizei* count,
291                                   WebGLId* shaders);
292
293   virtual WGC3Dint  getAttribLocation(WebGLId program, const WGC3Dchar* name);
294
295   virtual void getBooleanv(WGC3Denum pname, WGC3Dboolean* value);
296
297   virtual void getBufferParameteriv(WGC3Denum target,
298                                     WGC3Denum pname,
299                                     WGC3Dint* value);
300
301   virtual Attributes getContextAttributes();
302
303   virtual WGC3Denum getError();
304
305   virtual bool isContextLost();
306
307   virtual void getFloatv(WGC3Denum pname, WGC3Dfloat* value);
308
309   virtual void getFramebufferAttachmentParameteriv(WGC3Denum target,
310                                                    WGC3Denum attachment,
311                                                    WGC3Denum pname,
312                                                    WGC3Dint* value);
313
314   virtual void getIntegerv(WGC3Denum pname, WGC3Dint* value);
315
316   virtual void getProgramiv(WebGLId program, WGC3Denum pname, WGC3Dint* value);
317
318   virtual blink::WebString getProgramInfoLog(WebGLId program);
319
320   virtual void getRenderbufferParameteriv(WGC3Denum target,
321                                           WGC3Denum pname,
322                                           WGC3Dint* value);
323
324   virtual void getShaderiv(WebGLId shader, WGC3Denum pname, WGC3Dint* value);
325
326   virtual blink::WebString getShaderInfoLog(WebGLId shader);
327
328   virtual void getShaderPrecisionFormat(WGC3Denum shadertype,
329                                         WGC3Denum precisiontype,
330                                         WGC3Dint* range,
331                                         WGC3Dint* precision);
332
333   virtual blink::WebString getShaderSource(WebGLId shader);
334   virtual blink::WebString getString(WGC3Denum name);
335
336   virtual void getTexParameterfv(WGC3Denum target,
337                                  WGC3Denum pname,
338                                  WGC3Dfloat* value);
339   virtual void getTexParameteriv(WGC3Denum target,
340                                  WGC3Denum pname,
341                                  WGC3Dint* value);
342
343   virtual void getUniformfv(WebGLId program,
344                             WGC3Dint location,
345                             WGC3Dfloat* value);
346   virtual void getUniformiv(WebGLId program,
347                             WGC3Dint location,
348                             WGC3Dint* value);
349
350   virtual WGC3Dint getUniformLocation(WebGLId program, const WGC3Dchar* name);
351
352   virtual void getVertexAttribfv(WGC3Duint index, WGC3Denum pname,
353                                  WGC3Dfloat* value);
354   virtual void getVertexAttribiv(WGC3Duint index, WGC3Denum pname,
355                                  WGC3Dint* value);
356
357   virtual WGC3Dsizeiptr getVertexAttribOffset(WGC3Duint index, WGC3Denum pname);
358
359   virtual void hint(WGC3Denum target, WGC3Denum mode);
360   virtual WGC3Dboolean isBuffer(WebGLId buffer);
361   virtual WGC3Dboolean isEnabled(WGC3Denum cap);
362   virtual WGC3Dboolean isFramebuffer(WebGLId framebuffer);
363   virtual WGC3Dboolean isProgram(WebGLId program);
364   virtual WGC3Dboolean isRenderbuffer(WebGLId renderbuffer);
365   virtual WGC3Dboolean isShader(WebGLId shader);
366   virtual WGC3Dboolean isTexture(WebGLId texture);
367   virtual void lineWidth(WGC3Dfloat);
368   virtual void linkProgram(WebGLId program);
369   virtual void pixelStorei(WGC3Denum pname, WGC3Dint param);
370   virtual void polygonOffset(WGC3Dfloat factor, WGC3Dfloat units);
371
372   virtual void readPixels(WGC3Dint x,
373                           WGC3Dint y,
374                           WGC3Dsizei width,
375                           WGC3Dsizei height,
376                           WGC3Denum format,
377                           WGC3Denum type,
378                           void* pixels);
379
380   virtual void releaseShaderCompiler();
381   virtual void renderbufferStorage(WGC3Denum target,
382                                    WGC3Denum internalformat,
383                                    WGC3Dsizei width,
384                                    WGC3Dsizei height);
385   virtual void sampleCoverage(WGC3Dfloat value, WGC3Dboolean invert);
386   virtual void scissor(WGC3Dint x, WGC3Dint y,
387                        WGC3Dsizei width, WGC3Dsizei height);
388   virtual void shaderSource(WebGLId shader, const WGC3Dchar* string);
389   virtual void stencilFunc(WGC3Denum func, WGC3Dint ref, WGC3Duint mask);
390   virtual void stencilFuncSeparate(WGC3Denum face,
391                                    WGC3Denum func,
392                                    WGC3Dint ref,
393                                    WGC3Duint mask);
394   virtual void stencilMask(WGC3Duint mask);
395   virtual void stencilMaskSeparate(WGC3Denum face, WGC3Duint mask);
396   virtual void stencilOp(WGC3Denum fail,
397                          WGC3Denum zfail,
398                          WGC3Denum zpass);
399   virtual void stencilOpSeparate(WGC3Denum face,
400                                  WGC3Denum fail,
401                                  WGC3Denum zfail,
402                                  WGC3Denum zpass);
403
404   virtual void texImage2D(WGC3Denum target,
405                           WGC3Dint level,
406                           WGC3Denum internalformat,
407                           WGC3Dsizei width,
408                           WGC3Dsizei height,
409                           WGC3Dint border,
410                           WGC3Denum format,
411                           WGC3Denum type,
412                           const void* pixels);
413
414   virtual void texParameterf(WGC3Denum target,
415                              WGC3Denum pname,
416                              WGC3Dfloat param);
417   virtual void texParameteri(WGC3Denum target,
418                              WGC3Denum pname,
419                              WGC3Dint param);
420
421   virtual void texSubImage2D(WGC3Denum target,
422                              WGC3Dint level,
423                              WGC3Dint xoffset,
424                              WGC3Dint yoffset,
425                              WGC3Dsizei width,
426                              WGC3Dsizei height,
427                              WGC3Denum format,
428                              WGC3Denum type,
429                              const void* pixels);
430
431   virtual void uniform1f(WGC3Dint location, WGC3Dfloat x);
432   virtual void uniform1fv(WGC3Dint location,
433                           WGC3Dsizei count, const WGC3Dfloat* v);
434   virtual void uniform1i(WGC3Dint location, WGC3Dint x);
435   virtual void uniform1iv(WGC3Dint location,
436                           WGC3Dsizei count, const WGC3Dint* v);
437   virtual void uniform2f(WGC3Dint location, WGC3Dfloat x, WGC3Dfloat y);
438   virtual void uniform2fv(WGC3Dint location,
439                           WGC3Dsizei count, const WGC3Dfloat* v);
440   virtual void uniform2i(WGC3Dint location, WGC3Dint x, WGC3Dint y);
441   virtual void uniform2iv(WGC3Dint location,
442                           WGC3Dsizei count, const WGC3Dint* v);
443   virtual void uniform3f(WGC3Dint location,
444                          WGC3Dfloat x, WGC3Dfloat y, WGC3Dfloat z);
445   virtual void uniform3fv(WGC3Dint location,
446                           WGC3Dsizei count, const WGC3Dfloat* v);
447   virtual void uniform3i(WGC3Dint location,
448                          WGC3Dint x, WGC3Dint y, WGC3Dint z);
449   virtual void uniform3iv(WGC3Dint location,
450                           WGC3Dsizei count, const WGC3Dint* v);
451   virtual void uniform4f(WGC3Dint location,
452                          WGC3Dfloat x, WGC3Dfloat y,
453                          WGC3Dfloat z, WGC3Dfloat w);
454   virtual void uniform4fv(WGC3Dint location,
455                           WGC3Dsizei count, const WGC3Dfloat* v);
456   virtual void uniform4i(WGC3Dint location,
457                          WGC3Dint x, WGC3Dint y, WGC3Dint z, WGC3Dint w);
458   virtual void uniform4iv(WGC3Dint location,
459                           WGC3Dsizei count, const WGC3Dint* v);
460   virtual void uniformMatrix2fv(WGC3Dint location,
461                                 WGC3Dsizei count,
462                                 WGC3Dboolean transpose,
463                                 const WGC3Dfloat* value);
464   virtual void uniformMatrix3fv(WGC3Dint location,
465                                 WGC3Dsizei count,
466                                 WGC3Dboolean transpose,
467                                 const WGC3Dfloat* value);
468   virtual void uniformMatrix4fv(WGC3Dint location,
469                                 WGC3Dsizei count,
470                                 WGC3Dboolean transpose,
471                                 const WGC3Dfloat* value);
472
473   virtual void useProgram(WebGLId program);
474   virtual void validateProgram(WebGLId program);
475
476   virtual void vertexAttrib1f(WGC3Duint index, WGC3Dfloat x);
477   virtual void vertexAttrib1fv(WGC3Duint index, const WGC3Dfloat* values);
478   virtual void vertexAttrib2f(WGC3Duint index, WGC3Dfloat x, WGC3Dfloat y);
479   virtual void vertexAttrib2fv(WGC3Duint index, const WGC3Dfloat* values);
480   virtual void vertexAttrib3f(WGC3Duint index,
481                               WGC3Dfloat x, WGC3Dfloat y, WGC3Dfloat z);
482   virtual void vertexAttrib3fv(WGC3Duint index, const WGC3Dfloat* values);
483   virtual void vertexAttrib4f(WGC3Duint index,
484                               WGC3Dfloat x, WGC3Dfloat y,
485                               WGC3Dfloat z, WGC3Dfloat w);
486   virtual void vertexAttrib4fv(WGC3Duint index, const WGC3Dfloat* values);
487   virtual void vertexAttribPointer(WGC3Duint index,
488                                    WGC3Dint size,
489                                    WGC3Denum type,
490                                    WGC3Dboolean normalized,
491                                    WGC3Dsizei stride,
492                                    WGC3Dintptr offset);
493
494   virtual void viewport(WGC3Dint x, WGC3Dint y,
495                         WGC3Dsizei width, WGC3Dsizei height);
496
497   // Support for buffer creation and deletion
498   virtual void genBuffers(WGC3Dsizei count, WebGLId* ids);
499   virtual void genFramebuffers(WGC3Dsizei count, WebGLId* ids);
500   virtual void genRenderbuffers(WGC3Dsizei count, WebGLId* ids);
501   virtual void genTextures(WGC3Dsizei count, WebGLId* ids);
502
503   virtual void deleteBuffers(WGC3Dsizei count, WebGLId* ids);
504   virtual void deleteFramebuffers(WGC3Dsizei count, WebGLId* ids);
505   virtual void deleteRenderbuffers(WGC3Dsizei count, WebGLId* ids);
506   virtual void deleteTextures(WGC3Dsizei count, WebGLId* ids);
507
508   virtual WebGLId createBuffer();
509   virtual WebGLId createFramebuffer();
510   virtual WebGLId createRenderbuffer();
511   virtual WebGLId createTexture();
512
513   virtual void deleteBuffer(WebGLId);
514   virtual void deleteFramebuffer(WebGLId);
515   virtual void deleteRenderbuffer(WebGLId);
516   virtual void deleteTexture(WebGLId);
517
518   virtual WebGLId createProgram();
519   virtual WebGLId createShader(WGC3Denum);
520
521   virtual void deleteProgram(WebGLId);
522   virtual void deleteShader(WebGLId);
523
524   virtual void synthesizeGLError(WGC3Denum);
525
526   virtual void* mapBufferSubDataCHROMIUM(
527       WGC3Denum target, WGC3Dintptr offset,
528       WGC3Dsizeiptr size, WGC3Denum access);
529   virtual void unmapBufferSubDataCHROMIUM(const void*);
530   virtual void* mapTexSubImage2DCHROMIUM(
531       WGC3Denum target,
532       WGC3Dint level,
533       WGC3Dint xoffset,
534       WGC3Dint yoffset,
535       WGC3Dsizei width,
536       WGC3Dsizei height,
537       WGC3Denum format,
538       WGC3Denum type,
539       WGC3Denum access);
540   virtual void unmapTexSubImage2DCHROMIUM(const void*);
541
542   virtual void setVisibilityCHROMIUM(bool visible);
543
544   virtual void discardFramebufferEXT(WGC3Denum target,
545                                      WGC3Dsizei numAttachments,
546                                      const WGC3Denum* attachments);
547   virtual void copyTextureToParentTextureCHROMIUM(
548       WebGLId texture, WebGLId parentTexture);
549
550   virtual blink::WebString getRequestableExtensionsCHROMIUM();
551   virtual void requestExtensionCHROMIUM(const char*);
552
553   virtual void blitFramebufferCHROMIUM(
554       WGC3Dint srcX0, WGC3Dint srcY0, WGC3Dint srcX1, WGC3Dint srcY1,
555       WGC3Dint dstX0, WGC3Dint dstY0, WGC3Dint dstX1, WGC3Dint dstY1,
556       WGC3Dbitfield mask, WGC3Denum filter);
557   virtual void renderbufferStorageMultisampleCHROMIUM(
558       WGC3Denum target, WGC3Dsizei samples, WGC3Denum internalformat,
559       WGC3Dsizei width, WGC3Dsizei height);
560
561   virtual blink::WebString getTranslatedShaderSourceANGLE(WebGLId shader);
562
563   virtual void setContextLostCallback(
564       WebGraphicsContext3D::WebGraphicsContextLostCallback* callback);
565
566   virtual WGC3Denum getGraphicsResetStatusARB();
567
568   virtual void setErrorMessageCallback(
569       WebGraphicsContext3D::WebGraphicsErrorMessageCallback* callback);
570
571   virtual void texImageIOSurface2DCHROMIUM(
572       WGC3Denum target, WGC3Dint width, WGC3Dint height,
573       WGC3Duint ioSurfaceId, WGC3Duint plane);
574
575   virtual void texStorage2DEXT(
576       WGC3Denum target, WGC3Dint levels, WGC3Duint internalformat,
577       WGC3Dint width, WGC3Dint height);
578
579   virtual WebGLId createQueryEXT();
580   virtual void deleteQueryEXT(WebGLId query);
581   virtual WGC3Dboolean isQueryEXT(WGC3Duint query);
582   virtual void beginQueryEXT(WGC3Denum target, WebGLId query);
583   virtual void endQueryEXT(WGC3Denum target);
584   virtual void getQueryivEXT(
585       WGC3Denum target, WGC3Denum pname, WGC3Dint* params);
586   virtual void getQueryObjectuivEXT(
587       WebGLId query, WGC3Denum pname, WGC3Duint* params);
588
589   virtual void copyTextureCHROMIUM(WGC3Denum target, WebGLId source_id,
590                                    WebGLId dest_id, WGC3Dint level,
591                                    WGC3Denum internal_format,
592                                    WGC3Denum dest_type);
593
594   virtual void bindUniformLocationCHROMIUM(WebGLId program, WGC3Dint location,
595                                            const WGC3Dchar* uniform);
596
597   virtual void shallowFlushCHROMIUM();
598   virtual void shallowFinishCHROMIUM();
599
600   virtual void genMailboxCHROMIUM(WGC3Dbyte* mailbox);
601   virtual void produceTextureCHROMIUM(WGC3Denum target,
602                                       const WGC3Dbyte* mailbox);
603   virtual void consumeTextureCHROMIUM(WGC3Denum target,
604                                       const WGC3Dbyte* mailbox);
605
606   virtual void insertEventMarkerEXT(const WGC3Dchar* marker);
607   virtual void pushGroupMarkerEXT(const WGC3Dchar* marker);
608   virtual void popGroupMarkerEXT();
609
610   // GL_OES_vertex_array_object
611   virtual WebGLId createVertexArrayOES();
612   virtual void deleteVertexArrayOES(WebGLId array);
613   virtual WGC3Dboolean isVertexArrayOES(WebGLId array);
614   virtual void bindVertexArrayOES(WebGLId array);
615
616   virtual void bindTexImage2DCHROMIUM(WGC3Denum target, WGC3Dint image_id);
617   virtual void releaseTexImage2DCHROMIUM(WGC3Denum target, WGC3Dint image_id);
618
619   virtual void* mapBufferCHROMIUM(WGC3Denum target, WGC3Denum access);
620   virtual WGC3Dboolean unmapBufferCHROMIUM(WGC3Denum target);
621
622   // Async pixel transfer functions.
623   virtual void asyncTexImage2DCHROMIUM(
624       WGC3Denum target,
625       WGC3Dint level,
626       WGC3Denum internalformat,
627       WGC3Dsizei width,
628       WGC3Dsizei height,
629       WGC3Dint border,
630       WGC3Denum format,
631       WGC3Denum type,
632       const void* pixels);
633   virtual void asyncTexSubImage2DCHROMIUM(
634       WGC3Denum target,
635       WGC3Dint level,
636       WGC3Dint xoffset,
637       WGC3Dint yoffset,
638       WGC3Dsizei width,
639       WGC3Dsizei height,
640       WGC3Denum format,
641       WGC3Denum type,
642       const void* pixels);
643   virtual void waitAsyncTexImage2DCHROMIUM(WGC3Denum target);
644
645   // GL_EXT_draw_buffers
646   virtual void drawBuffersEXT(
647       WGC3Dsizei n,
648       const WGC3Denum* bufs);
649
650   // GL_ANGLE_instanced_arrays
651   virtual void drawArraysInstancedANGLE(WGC3Denum mode, WGC3Dint first,
652       WGC3Dsizei count, WGC3Dsizei primcount);
653   virtual void drawElementsInstancedANGLE(WGC3Denum mode, WGC3Dsizei count,
654       WGC3Denum type, WGC3Dintptr offset, WGC3Dsizei primcount);
655   virtual void vertexAttribDivisorANGLE(WGC3Duint index, WGC3Duint divisor);
656
657   // GL_CHROMIUM_map_image
658   virtual WGC3Duint createImageCHROMIUM(
659       WGC3Dsizei width, WGC3Dsizei height, WGC3Denum internalformat);
660   virtual void destroyImageCHROMIUM(WGC3Duint image_id);
661   virtual void getImageParameterivCHROMIUM(
662       WGC3Duint image_id, WGC3Denum pname, WGC3Dint* params);
663   virtual void* mapImageCHROMIUM(WGC3Duint image_id, WGC3Denum access);
664   virtual void unmapImageCHROMIUM(WGC3Duint image_id);
665
666   // GL_EXT_multisampled_render_to_texture
667   virtual void framebufferTexture2DMultisampleEXT(WGC3Denum target,
668                                     WGC3Denum attachment,
669                                     WGC3Denum textarget,
670                                     WebGLId texture,
671                                     WGC3Dint level,
672                                     WGC3Dsizei samples);
673   virtual void renderbufferStorageMultisampleEXT(
674       WGC3Denum target, WGC3Dsizei samples, WGC3Denum internalformat,
675       WGC3Dsizei width, WGC3Dsizei height);
676
677   virtual GrGLInterface* createGrGLInterface();
678
679  private:
680   // These are the same error codes as used by EGL.
681   enum Error {
682     SUCCESS               = 0x3000,
683     BAD_ATTRIBUTE         = 0x3004,
684     CONTEXT_LOST          = 0x300E
685   };
686   // WebGraphicsContext3DCommandBufferImpl configuration attributes. Those in
687   // the 16-bit range are the same as used by EGL. Those outside the 16-bit
688   // range are unique to Chromium. Attributes are matched using a closest fit
689   // algorithm.
690   // Changes to this enum should also be copied to
691   // gpu/command_buffer/common/gles2_cmd_utils.cc and to
692   // gpu/command_buffer/client/gl_in_process_context.cc
693   enum Attribute {
694     ALPHA_SIZE = 0x3021,
695     BLUE_SIZE = 0x3022,
696     GREEN_SIZE = 0x3023,
697     RED_SIZE = 0x3024,
698     DEPTH_SIZE = 0x3025,
699     STENCIL_SIZE = 0x3026,
700     SAMPLES = 0x3031,
701     SAMPLE_BUFFERS = 0x3032,
702     HEIGHT = 0x3056,
703     WIDTH = 0x3057,
704     NONE = 0x3038,  // Attrib list = terminator
705     SHARE_RESOURCES = 0x10000,
706     BIND_GENERATES_RESOURCES = 0x10001,
707     FAIL_IF_MAJOR_PERF_CAVEAT = 0x10002,
708     LOSE_CONTEXT_WHEN_OUT_OF_MEMORY = 0x10003,
709   };
710   friend class WebGraphicsContext3DErrorMessageCallback;
711
712   // Initialize the underlying GL context. May be called multiple times; second
713   // and subsequent calls are ignored. Must be called from the thread that is
714   // going to use this object to issue GL commands (which might not be the main
715   // thread).
716   bool MaybeInitializeGL();
717
718   bool InitializeCommandBuffer(bool onscreen,
719       WebGraphicsContext3DCommandBufferImpl* share_context);
720
721   void Destroy();
722
723   // Create a CommandBufferProxy that renders directly to a view. The view and
724   // the associated window must not be destroyed until the returned
725   // CommandBufferProxy has been destroyed, otherwise the GPU process might
726   // attempt to render to an invalid window handle.
727   //
728   // NOTE: on Mac OS X, this entry point is only used to set up the
729   // accelerated compositor's output. On this platform, we actually pass
730   // a gfx::PluginWindowHandle in place of the gfx::NativeViewId,
731   // because the facility to allocate a fake PluginWindowHandle is
732   // already in place. We could add more entry points and messages to
733   // allocate both fake PluginWindowHandles and NativeViewIds and map
734   // from fake NativeViewIds to PluginWindowHandles, but this seems like
735   // unnecessary complexity at the moment.
736   bool CreateContext(bool onscreen);
737
738   virtual void OnGpuChannelLost();
739   virtual void OnErrorMessage(const std::string& message, int id);
740
741   bool initialize_failed_;
742
743   bool visible_;
744
745   // State needed by MaybeInitializeGL.
746   scoped_refptr<GpuChannelHost> host_;
747   int32 surface_id_;
748   GURL active_url_;
749
750   WebGraphicsContext3D::WebGraphicsContextLostCallback* context_lost_callback_;
751   WGC3Denum context_lost_reason_;
752
753   WebGraphicsContext3D::WebGraphicsErrorMessageCallback*
754       error_message_callback_;
755   scoped_ptr<WebGraphicsContext3DErrorMessageCallback>
756       client_error_message_callback_;
757
758   blink::WebGraphicsContext3D::Attributes attributes_;
759   gfx::GpuPreference gpu_preference_;
760
761   // Errors raised by synthesizeGLError().
762   std::vector<WGC3Denum> synthetic_errors_;
763
764   base::WeakPtrFactory<WebGraphicsContext3DCommandBufferImpl> weak_ptr_factory_;
765
766   bool initialized_;
767   scoped_ptr<CommandBufferProxyImpl> command_buffer_;
768   scoped_ptr<gpu::gles2::GLES2CmdHelper> gles2_helper_;
769   scoped_ptr<gpu::TransferBuffer> transfer_buffer_;
770   gpu::gles2::GLES2Interface* gl_;
771   scoped_ptr<gpu::gles2::GLES2Implementation> real_gl_;
772   scoped_ptr<gpu::gles2::GLES2Interface> trace_gl_;
773   Error last_error_;
774 #if !defined(OS_CHROMEOS)
775   bool bind_generates_resources_;
776 #endif
777   bool lose_context_when_out_of_memory_;
778   SharedMemoryLimits mem_limits_;
779
780   uint32_t flush_id_;
781   scoped_refptr<ShareGroup> share_group_;
782 };
783
784 }  // namespace content
785
786 #endif  // CONTENT_COMMON_GPU_CLIENT_WEBGRAPHICSCONTEXT3D_COMMAND_BUFFER_IMPL_H_