Change the argument orders to match OpenGL's in GraphicsContext3D functions
[WebKit-https.git] / Source / WebKit / chromium / src / GraphicsContext3DChromium.cpp
1 /*
2  * Copyright (C) 2009 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 #include "config.h"
32
33 #if ENABLE(WEBGL)
34
35 #include "GraphicsContext3D.h"
36
37 #include "CachedImage.h"
38 #include "CanvasRenderingContext.h"
39 #include "Chrome.h"
40 #include "ChromeClientImpl.h"
41 #include "DrawingBuffer.h"
42 #include "Extensions3DChromium.h"
43 #include "GraphicsContext3DPrivate.h"
44 #include "HTMLCanvasElement.h"
45 #include "HTMLImageElement.h"
46 #include "ImageBuffer.h"
47 #include "ImageData.h"
48 #include "WebKit.h"
49 #include "WebViewClient.h"
50 #include "WebViewImpl.h"
51 #include "platform/WebGraphicsContext3D.h"
52 #include "platform/WebKitPlatformSupport.h"
53
54 #include <stdio.h>
55 #include <wtf/FastMalloc.h>
56 #include <wtf/text/CString.h>
57
58 #if USE(CG)
59 #include "GraphicsContext.h"
60 #include "WebGLRenderingContext.h"
61 #include <CoreGraphics/CGContext.h>
62 #include <CoreGraphics/CGImage.h>
63 #endif
64
65 #if USE(SKIA)
66 #include "GrContext.h"
67 #include "GrGLInterface.h"
68 #endif
69
70 // There are two levels of delegation in this file:
71 //
72 //   1. GraphicsContext3D delegates to GraphicsContext3DPrivate. This is done
73 //      so that we have some place to store data members common among
74 //      implementations; GraphicsContext3D only provides us the m_private
75 //      pointer. We always delegate to the GraphicsContext3DPrivate. 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. GraphicsContext3DPrivate 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 namespace WebCore {
84
85 //----------------------------------------------------------------------
86 // GraphicsContext3DPrivate
87
88 GraphicsContext3DPrivate::GraphicsContext3DPrivate(PassOwnPtr<WebKit::WebGraphicsContext3D> webContext, bool preserveDrawingBuffer)
89     : m_impl(webContext)
90     , m_initializedAvailableExtensions(false)
91     , m_layerComposited(false)
92     , m_preserveDrawingBuffer(preserveDrawingBuffer)
93     , m_resourceSafety(ResourceSafetyUnknown)
94 #if USE(SKIA)
95     , m_grContext(0)
96 #elif USE(CG)
97     , m_renderOutputSize(0)
98 #else
99 #error Must port to your platform
100 #endif
101 {
102 }
103
104 GraphicsContext3DPrivate::~GraphicsContext3DPrivate()
105 {
106 #if USE(SKIA)
107     if (m_grContext) {
108         m_grContext->contextDestroyed();
109         GrSafeUnref(m_grContext);
110     }
111 #endif
112 }
113
114 PassRefPtr<GraphicsContext3D> GraphicsContext3DPrivate::createGraphicsContextFromWebContext(PassOwnPtr<WebKit::WebGraphicsContext3D> webContext, GraphicsContext3D::RenderStyle renderStyle, bool preserveDrawingBuffer)
115 {
116     bool renderDirectlyToHostWindow = renderStyle == GraphicsContext3D::RenderDirectlyToHostWindow;
117
118     RefPtr<GraphicsContext3D> context = adoptRef(new GraphicsContext3D(GraphicsContext3D::Attributes(), 0, renderDirectlyToHostWindow));
119
120     OwnPtr<GraphicsContext3DPrivate> priv = adoptPtr(new GraphicsContext3DPrivate(webContext, preserveDrawingBuffer));
121     context->m_private = priv.release();
122     return context.release();
123 }
124
125 namespace {
126
127 void getDrawingParameters(DrawingBuffer* drawingBuffer, WebKit::WebGraphicsContext3D* graphicsContext3D,
128                           Platform3DObject* frameBufferId, int* width, int* height)
129 {
130     if (drawingBuffer) {
131         *frameBufferId = drawingBuffer->framebuffer();
132         *width = drawingBuffer->size().width();
133         *height = drawingBuffer->size().height();
134     } else {
135         *frameBufferId = 0;
136         *width = graphicsContext3D->width();
137         *height = graphicsContext3D->height();
138     }
139 }
140
141 } // anonymous namespace
142
143 WebKit::WebGraphicsContext3D* GraphicsContext3DPrivate::extractWebGraphicsContext3D(GraphicsContext3D* context)
144 {
145     if (!context)
146         return 0;
147     return context->m_private->m_impl.get();
148 }
149
150 PlatformGraphicsContext3D GraphicsContext3DPrivate::platformGraphicsContext3D() const
151 {
152     return m_impl.get();
153 }
154
155 Platform3DObject GraphicsContext3DPrivate::platformTexture() const
156 {
157     return m_impl->getPlatformTextureId();
158 }
159
160 #if USE(SKIA)
161 class GrMemoryAllocationChangedCallback : public Extensions3DChromium::GpuMemoryAllocationChangedCallbackCHROMIUM {
162 public:
163     GrMemoryAllocationChangedCallback(GraphicsContext3DPrivate* context)
164         : m_context(context)
165     {
166     }
167
168     virtual void onGpuMemoryAllocationChanged(size_t gpuResourceSizeInBytes)
169     {
170         if (!gpuResourceSizeInBytes && m_context->grContext())
171             m_context->grContext()->freeGpuResources();
172     }
173
174 private:
175     GraphicsContext3DPrivate* m_context;
176 };
177
178 GrContext* GraphicsContext3DPrivate::grContext()
179 {
180     // Limit the number of textures we hold in the bitmap->texture cache.
181     static const int maxTextureCacheCount = 512;
182     // Limit the bytes allocated toward textures in the bitmap->texture cache.
183     static const size_t maxTextureCacheBytes = 96 * 1024 * 1024;
184
185     if (!m_grContext) {
186         SkAutoTUnref<GrGLInterface> interface(m_impl->createGrGLInterface());
187         m_grContext = GrContext::Create(kOpenGL_Shaders_GrEngine, reinterpret_cast<GrPlatform3DContext>(interface.get()));
188         if (m_grContext) {
189             m_grContext->setTextureCacheLimits(maxTextureCacheCount, maxTextureCacheBytes);
190             Extensions3DChromium* extensions3DChromium = static_cast<Extensions3DChromium*>(getExtensions());
191             if (extensions3DChromium->supports("GL_CHROMIUM_gpu_memory_manager"))
192                 extensions3DChromium->setGpuMemoryAllocationChangedCallbackCHROMIUM(adoptPtr(new GrMemoryAllocationChangedCallback(this)));
193         }
194     }
195     return m_grContext;
196 }
197 #endif
198
199 void GraphicsContext3DPrivate::prepareTexture()
200 {
201     m_impl->prepareTexture();
202 }
203
204 void GraphicsContext3DPrivate::markContextChanged()
205 {
206     m_layerComposited = false;
207 }
208
209 void GraphicsContext3DPrivate::markLayerComposited()
210 {
211     m_layerComposited = true;
212 }
213
214 bool GraphicsContext3DPrivate::layerComposited() const
215 {
216     return m_layerComposited;
217 }
218
219 void GraphicsContext3DPrivate::paintFramebufferToCanvas(int framebuffer, int width, int height, bool premultiplyAlpha, ImageBuffer* imageBuffer)
220 {
221     unsigned char* pixels = 0;
222     size_t bufferSize = 4 * width * height;
223 #if USE(SKIA)
224     const SkBitmap* canvasBitmap = imageBuffer->context()->platformContext()->bitmap();
225     const SkBitmap* readbackBitmap = 0;
226     ASSERT(canvasBitmap->config() == SkBitmap::kARGB_8888_Config);
227     if (canvasBitmap->width() == width && canvasBitmap->height() == height) {
228         // This is the fastest and most common case. We read back
229         // directly into the canvas's backing store.
230         readbackBitmap = canvasBitmap;
231         m_resizingBitmap.reset();
232     } else {
233         // We need to allocate a temporary bitmap for reading back the
234         // pixel data. We will then use Skia to rescale this bitmap to
235         // the size of the canvas's backing store.
236         if (m_resizingBitmap.width() != width || m_resizingBitmap.height() != height) {
237             m_resizingBitmap.setConfig(SkBitmap::kARGB_8888_Config,
238                                        width,
239                                        height);
240             if (!m_resizingBitmap.allocPixels())
241                 return;
242         }
243         readbackBitmap = &m_resizingBitmap;
244     }
245
246     // Read back the frame buffer.
247     SkAutoLockPixels bitmapLock(*readbackBitmap);
248     pixels = static_cast<unsigned char*>(readbackBitmap->getPixels());
249 #elif USE(CG)
250     if (!m_renderOutput || m_renderOutputSize != bufferSize) {
251         m_renderOutput = adoptArrayPtr(new unsigned char[bufferSize]);
252         m_renderOutputSize = bufferSize;
253     }
254
255     pixels = m_renderOutput.get();
256 #else
257 #error Must port to your platform
258 #endif
259
260     m_impl->readBackFramebuffer(pixels, 4 * width * height, framebuffer, width, height);
261
262     if (premultiplyAlpha) {
263         for (size_t i = 0; i < bufferSize; i += 4) {
264             pixels[i + 0] = std::min(255, pixels[i + 0] * pixels[i + 3] / 255);
265             pixels[i + 1] = std::min(255, pixels[i + 1] * pixels[i + 3] / 255);
266             pixels[i + 2] = std::min(255, pixels[i + 2] * pixels[i + 3] / 255);
267         }
268     }
269
270 #if USE(SKIA)
271     readbackBitmap->notifyPixelsChanged();
272     if (m_resizingBitmap.readyToDraw()) {
273         // We need to draw the resizing bitmap into the canvas's backing store.
274         SkCanvas canvas(*canvasBitmap);
275         SkRect dst;
276         dst.set(SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(canvasBitmap->width()), SkIntToScalar(canvasBitmap->height()));
277         canvas.drawBitmapRect(m_resizingBitmap, 0, dst);
278     }
279 #elif USE(CG)
280     GraphicsContext3D::paintToCanvas(pixels, width, height, imageBuffer->width(), imageBuffer->height(), imageBuffer->context()->platformContext());
281 #else
282 #error Must port to your platform
283 #endif
284 }
285
286 void GraphicsContext3DPrivate::paintRenderingResultsToCanvas(CanvasRenderingContext* context, DrawingBuffer* drawingBuffer)
287 {
288     ImageBuffer* imageBuffer = context->canvas()->buffer();
289     Platform3DObject framebufferId;
290     int width, height;
291     getDrawingParameters(drawingBuffer, m_impl.get(), &framebufferId, &width, &height);
292     paintFramebufferToCanvas(framebufferId, width, height, !m_impl->getContextAttributes().premultipliedAlpha, imageBuffer);
293 }
294
295 bool GraphicsContext3DPrivate::paintCompositedResultsToCanvas(CanvasRenderingContext* context)
296 {
297     return false;
298 }
299
300 PassRefPtr<ImageData> GraphicsContext3DPrivate::paintRenderingResultsToImageData(DrawingBuffer* drawingBuffer)
301 {
302     if (m_impl->getContextAttributes().premultipliedAlpha)
303         return 0;
304
305     Platform3DObject framebufferId;
306     int width, height;
307     getDrawingParameters(drawingBuffer, m_impl.get(), &framebufferId, &width, &height);
308
309     RefPtr<ImageData> imageData = ImageData::create(IntSize(width, height));
310     unsigned char* pixels = imageData->data()->data()->data();
311     size_t bufferSize = 4 * width * height;
312
313     m_impl->readBackFramebuffer(pixels, bufferSize, framebufferId, width, height);
314
315     for (size_t i = 0; i < bufferSize; i += 4)
316         std::swap(pixels[i], pixels[i + 2]);
317
318     return imageData.release();
319 }
320
321 void GraphicsContext3DPrivate::reshape(int width, int height)
322 {
323     if (width == m_impl->width() && height == m_impl->height())
324         return;
325
326     m_impl->reshape(width, height);
327 }
328
329 IntSize GraphicsContext3DPrivate::getInternalFramebufferSize() const
330 {
331     return IntSize(m_impl->width(), m_impl->height());
332 }
333
334 bool GraphicsContext3DPrivate::isContextLost()
335 {
336     return m_impl->isContextLost();
337 }
338
339 // Macros to assist in delegating from GraphicsContext3DPrivate to
340 // WebGraphicsContext3D.
341
342 #define DELEGATE_TO_IMPL(name) \
343 void GraphicsContext3DPrivate::name() \
344 { \
345     m_impl->name(); \
346 }
347
348 #define DELEGATE_TO_IMPL_R(name, rt)           \
349 rt GraphicsContext3DPrivate::name() \
350 { \
351     return m_impl->name(); \
352 }
353
354 #define DELEGATE_TO_IMPL_1(name, t1) \
355 void GraphicsContext3DPrivate::name(t1 a1) \
356 { \
357     m_impl->name(a1); \
358 }
359
360 #define DELEGATE_TO_IMPL_1R(name, t1, rt)    \
361 rt GraphicsContext3DPrivate::name(t1 a1) \
362 { \
363     return m_impl->name(a1); \
364 }
365
366 #define DELEGATE_TO_IMPL_2(name, t1, t2) \
367 void GraphicsContext3DPrivate::name(t1 a1, t2 a2) \
368 { \
369     m_impl->name(a1, a2); \
370 }
371
372 #define DELEGATE_TO_IMPL_2R(name, t1, t2, rt)  \
373 rt GraphicsContext3DPrivate::name(t1 a1, t2 a2) \
374 { \
375     return m_impl->name(a1, a2); \
376 }
377
378 #define DELEGATE_TO_IMPL_3(name, t1, t2, t3)   \
379 void GraphicsContext3DPrivate::name(t1 a1, t2 a2, t3 a3)    \
380 { \
381     m_impl->name(a1, a2, a3);                  \
382 }
383
384 #define DELEGATE_TO_IMPL_3R(name, t1, t2, t3, rt)   \
385 rt GraphicsContext3DPrivate::name(t1 a1, t2 a2, t3 a3)    \
386 { \
387     return m_impl->name(a1, a2, a3);                  \
388 }
389
390 #define DELEGATE_TO_IMPL_4(name, t1, t2, t3, t4)    \
391 void GraphicsContext3DPrivate::name(t1 a1, t2 a2, t3 a3, t4 a4)  \
392 { \
393     m_impl->name(a1, a2, a3, a4);              \
394 }
395
396 #define DELEGATE_TO_IMPL_4R(name, t1, t2, t3, t4, rt)       \
397 rt GraphicsContext3DPrivate::name(t1 a1, t2 a2, t3 a3, t4 a4)        \
398 { \
399     return m_impl->name(a1, a2, a3, a4);           \
400 }
401
402 #define DELEGATE_TO_IMPL_5(name, t1, t2, t3, t4, t5)      \
403 void GraphicsContext3DPrivate::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5)        \
404 { \
405     m_impl->name(a1, a2, a3, a4, a5);   \
406 }
407
408 #define DELEGATE_TO_IMPL_5R(name, t1, t2, t3, t4, t5, rt)      \
409 rt GraphicsContext3DPrivate::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5)        \
410 { \
411     return m_impl->name(a1, a2, a3, a4, a5);   \
412 }
413
414 #define DELEGATE_TO_IMPL_6(name, t1, t2, t3, t4, t5, t6)  \
415 void GraphicsContext3DPrivate::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6) \
416 { \
417     m_impl->name(a1, a2, a3, a4, a5, a6);       \
418 }
419
420 #define DELEGATE_TO_IMPL_6R(name, t1, t2, t3, t4, t5, t6, rt)  \
421 rt GraphicsContext3DPrivate::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6) \
422 { \
423     return m_impl->name(a1, a2, a3, a4, a5, a6);       \
424 }
425
426 #define DELEGATE_TO_IMPL_7(name, t1, t2, t3, t4, t5, t6, t7) \
427 void GraphicsContext3DPrivate::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7) \
428 { \
429     m_impl->name(a1, a2, a3, a4, a5, a6, a7);   \
430 }
431
432 #define DELEGATE_TO_IMPL_7R(name, t1, t2, t3, t4, t5, t6, t7, rt) \
433 rt GraphicsContext3DPrivate::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7) \
434 { \
435     return m_impl->name(a1, a2, a3, a4, a5, a6, a7);   \
436 }
437
438 #define DELEGATE_TO_IMPL_8(name, t1, t2, t3, t4, t5, t6, t7, t8)       \
439 void GraphicsContext3DPrivate::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8 a8) \
440 { \
441     m_impl->name(a1, a2, a3, a4, a5, a6, a7, a8);      \
442 }
443
444 #define DELEGATE_TO_IMPL_9(name, t1, t2, t3, t4, t5, t6, t7, t8, t9)       \
445 void GraphicsContext3DPrivate::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8 a8, t9 a9) \
446 { \
447     m_impl->name(a1, a2, a3, a4, a5, a6, a7, a8, a9);      \
448 }
449
450 #define DELEGATE_TO_IMPL_9R(name, t1, t2, t3, t4, t5, t6, t7, t8, t9, rt) \
451 rt GraphicsContext3DPrivate::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8 a8, t9 a9) \
452 { \
453     return m_impl->name(a1, a2, a3, a4, a5, a6, a7, a8, a9);   \
454 }
455
456 #define DELEGATE_TO_IMPL_10(name, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10) \
457 void GraphicsContext3DPrivate::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8 a8, t9 a9, t10 a10) \
458 { \
459     m_impl->name(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); \
460 }
461
462 DELEGATE_TO_IMPL_R(makeContextCurrent, bool)
463
464 bool GraphicsContext3DPrivate::isGLES2Compliant() const
465 {
466     return m_impl->isGLES2Compliant();
467 }
468
469 DELEGATE_TO_IMPL_1(activeTexture, GC3Denum)
470 DELEGATE_TO_IMPL_2(attachShader, Platform3DObject, Platform3DObject)
471
472 void GraphicsContext3DPrivate::bindAttribLocation(Platform3DObject program, GC3Duint index, const String& name)
473 {
474     m_impl->bindAttribLocation(program, index, name.utf8().data());
475 }
476
477 DELEGATE_TO_IMPL_2(bindBuffer, GC3Denum, Platform3DObject)
478 DELEGATE_TO_IMPL_2(bindFramebuffer, GC3Denum, Platform3DObject)
479 DELEGATE_TO_IMPL_2(bindRenderbuffer, GC3Denum, Platform3DObject)
480 DELEGATE_TO_IMPL_2(bindTexture, GC3Denum, Platform3DObject)
481 DELEGATE_TO_IMPL_4(blendColor, GC3Dclampf, GC3Dclampf, GC3Dclampf, GC3Dclampf)
482 DELEGATE_TO_IMPL_1(blendEquation, GC3Denum)
483 DELEGATE_TO_IMPL_2(blendEquationSeparate, GC3Denum, GC3Denum)
484 DELEGATE_TO_IMPL_2(blendFunc, GC3Denum, GC3Denum)
485 DELEGATE_TO_IMPL_4(blendFuncSeparate, GC3Denum, GC3Denum, GC3Denum, GC3Denum)
486
487 void GraphicsContext3DPrivate::bufferData(GC3Denum target, GC3Dsizeiptr size, GC3Denum usage)
488 {
489     m_impl->bufferData(target, size, 0, usage);
490 }
491
492 void GraphicsContext3DPrivate::bufferData(GC3Denum target, GC3Dsizeiptr size, const void* data, GC3Denum usage)
493 {
494     m_impl->bufferData(target, size, data, usage);
495 }
496
497 void GraphicsContext3DPrivate::bufferSubData(GC3Denum target, GC3Dintptr offset, GC3Dsizeiptr size, const void* data)
498 {
499     m_impl->bufferSubData(target, offset, size, data);
500 }
501
502 DELEGATE_TO_IMPL_1R(checkFramebufferStatus, GC3Denum, GC3Denum)
503 DELEGATE_TO_IMPL_1(clear, GC3Dbitfield)
504 DELEGATE_TO_IMPL_4(clearColor, GC3Dclampf, GC3Dclampf, GC3Dclampf, GC3Dclampf)
505 DELEGATE_TO_IMPL_1(clearDepth, GC3Dclampf)
506 DELEGATE_TO_IMPL_1(clearStencil, GC3Dint)
507 DELEGATE_TO_IMPL_4(colorMask, GC3Dboolean, GC3Dboolean, GC3Dboolean, GC3Dboolean)
508 DELEGATE_TO_IMPL_1(compileShader, Platform3DObject)
509
510 DELEGATE_TO_IMPL_8(compressedTexImage2D, GC3Denum, GC3Dint, GC3Denum, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei, const void*)
511 DELEGATE_TO_IMPL_9(compressedTexSubImage2D, GC3Denum, GC3Dint, GC3Dint, GC3Dint, GC3Dint, GC3Dint, GC3Denum, GC3Dsizei, const void*)
512 DELEGATE_TO_IMPL_8(copyTexImage2D, GC3Denum, GC3Dint, GC3Denum, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei, GC3Dint)
513 DELEGATE_TO_IMPL_8(copyTexSubImage2D, GC3Denum, GC3Dint, GC3Dint, GC3Dint, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei)
514 DELEGATE_TO_IMPL_1(cullFace, GC3Denum)
515 DELEGATE_TO_IMPL_1(depthFunc, GC3Denum)
516 DELEGATE_TO_IMPL_1(depthMask, GC3Dboolean)
517 DELEGATE_TO_IMPL_2(depthRange, GC3Dclampf, GC3Dclampf)
518 DELEGATE_TO_IMPL_2(detachShader, Platform3DObject, Platform3DObject)
519 DELEGATE_TO_IMPL_1(disable, GC3Denum)
520 DELEGATE_TO_IMPL_1(disableVertexAttribArray, GC3Duint)
521 DELEGATE_TO_IMPL_3(drawArrays, GC3Denum, GC3Dint, GC3Dsizei)
522 DELEGATE_TO_IMPL_4(drawElements, GC3Denum, GC3Dsizei, GC3Denum, GC3Dsizeiptr)
523
524 DELEGATE_TO_IMPL_1(enable, GC3Denum)
525 DELEGATE_TO_IMPL_1(enableVertexAttribArray, GC3Duint)
526 DELEGATE_TO_IMPL(finish)
527 DELEGATE_TO_IMPL(flush)
528 DELEGATE_TO_IMPL_4(framebufferRenderbuffer, GC3Denum, GC3Denum, GC3Denum, Platform3DObject)
529 DELEGATE_TO_IMPL_5(framebufferTexture2D, GC3Denum, GC3Denum, GC3Denum, Platform3DObject, GC3Dint)
530 DELEGATE_TO_IMPL_1(frontFace, GC3Denum)
531 DELEGATE_TO_IMPL_1(generateMipmap, GC3Denum)
532
533 bool GraphicsContext3DPrivate::getActiveAttrib(Platform3DObject program, GC3Duint index, ActiveInfo& info)
534 {
535     WebKit::WebGraphicsContext3D::ActiveInfo webInfo;
536     if (!m_impl->getActiveAttrib(program, index, webInfo))
537         return false;
538     info.name = webInfo.name;
539     info.type = webInfo.type;
540     info.size = webInfo.size;
541     return true;
542 }
543
544 bool GraphicsContext3DPrivate::getActiveUniform(Platform3DObject program, GC3Duint index, ActiveInfo& info)
545 {
546     WebKit::WebGraphicsContext3D::ActiveInfo webInfo;
547     if (!m_impl->getActiveUniform(program, index, webInfo))
548         return false;
549     info.name = webInfo.name;
550     info.type = webInfo.type;
551     info.size = webInfo.size;
552     return true;
553 }
554
555 DELEGATE_TO_IMPL_4(getAttachedShaders, Platform3DObject, GC3Dsizei, GC3Dsizei*, Platform3DObject*)
556
557 GC3Dint GraphicsContext3DPrivate::getAttribLocation(Platform3DObject program, const String& name)
558 {
559     return m_impl->getAttribLocation(program, name.utf8().data());
560 }
561
562 DELEGATE_TO_IMPL_2(getBooleanv, GC3Denum, GC3Dboolean*)
563
564 DELEGATE_TO_IMPL_3(getBufferParameteriv, GC3Denum, GC3Denum, GC3Dint*)
565
566 GraphicsContext3D::Attributes GraphicsContext3DPrivate::getContextAttributes()
567 {
568     WebKit::WebGraphicsContext3D::Attributes webAttributes = m_impl->getContextAttributes();
569     GraphicsContext3D::Attributes attributes;
570     attributes.alpha = webAttributes.alpha;
571     attributes.depth = webAttributes.depth;
572     attributes.stencil = webAttributes.stencil;
573     attributes.antialias = webAttributes.antialias;
574     attributes.premultipliedAlpha = webAttributes.premultipliedAlpha;
575     attributes.preserveDrawingBuffer = m_preserveDrawingBuffer;
576     return attributes;
577 }
578
579 DELEGATE_TO_IMPL_R(getError, GC3Denum)
580
581 DELEGATE_TO_IMPL_2(getFloatv, GC3Denum, GC3Dfloat*)
582
583 DELEGATE_TO_IMPL_4(getFramebufferAttachmentParameteriv, GC3Denum, GC3Denum, GC3Denum, GC3Dint*)
584
585 DELEGATE_TO_IMPL_2(getIntegerv, GC3Denum, GC3Dint*)
586
587 DELEGATE_TO_IMPL_3(getProgramiv, Platform3DObject, GC3Denum, GC3Dint*)
588
589 String GraphicsContext3DPrivate::getProgramInfoLog(Platform3DObject program)
590 {
591     return m_impl->getProgramInfoLog(program);
592 }
593
594 DELEGATE_TO_IMPL_3(getRenderbufferParameteriv, GC3Denum, GC3Denum, GC3Dint*)
595
596 DELEGATE_TO_IMPL_3(getShaderiv, Platform3DObject, GC3Denum, GC3Dint*)
597
598 String GraphicsContext3DPrivate::getShaderInfoLog(Platform3DObject shader)
599 {
600     return m_impl->getShaderInfoLog(shader);
601 }
602
603 String GraphicsContext3DPrivate::getShaderSource(Platform3DObject shader)
604 {
605     return m_impl->getShaderSource(shader);
606 }
607
608 String GraphicsContext3DPrivate::getString(GC3Denum name)
609 {
610     return m_impl->getString(name);
611 }
612
613 DELEGATE_TO_IMPL_3(getTexParameterfv, GC3Denum, GC3Denum, GC3Dfloat*)
614 DELEGATE_TO_IMPL_3(getTexParameteriv, GC3Denum, GC3Denum, GC3Dint*)
615
616 DELEGATE_TO_IMPL_3(getUniformfv, Platform3DObject, GC3Dint, GC3Dfloat*)
617 DELEGATE_TO_IMPL_3(getUniformiv, Platform3DObject, GC3Dint, GC3Dint*)
618
619 GC3Dint GraphicsContext3DPrivate::getUniformLocation(Platform3DObject program, const String& name)
620 {
621     return m_impl->getUniformLocation(program, name.utf8().data());
622 }
623
624 DELEGATE_TO_IMPL_3(getVertexAttribfv, GC3Duint, GC3Denum, GC3Dfloat*)
625 DELEGATE_TO_IMPL_3(getVertexAttribiv, GC3Duint, GC3Denum, GC3Dint*)
626
627 DELEGATE_TO_IMPL_2R(getVertexAttribOffset, GC3Duint, GC3Denum, GC3Dsizeiptr)
628
629 DELEGATE_TO_IMPL_2(hint, GC3Denum, GC3Denum)
630 DELEGATE_TO_IMPL_1R(isBuffer, Platform3DObject, GC3Dboolean)
631 DELEGATE_TO_IMPL_1R(isEnabled, GC3Denum, GC3Dboolean)
632 DELEGATE_TO_IMPL_1R(isFramebuffer, Platform3DObject, GC3Dboolean)
633 DELEGATE_TO_IMPL_1R(isProgram, Platform3DObject, GC3Dboolean)
634 DELEGATE_TO_IMPL_1R(isRenderbuffer, Platform3DObject, GC3Dboolean)
635 DELEGATE_TO_IMPL_1R(isShader, Platform3DObject, GC3Dboolean)
636 DELEGATE_TO_IMPL_1R(isTexture, Platform3DObject, GC3Dboolean)
637 DELEGATE_TO_IMPL_1(lineWidth, GC3Dfloat)
638 DELEGATE_TO_IMPL_1(linkProgram, Platform3DObject)
639 DELEGATE_TO_IMPL_2(pixelStorei, GC3Denum, GC3Dint)
640 DELEGATE_TO_IMPL_2(polygonOffset, GC3Dfloat, GC3Dfloat)
641 DELEGATE_TO_IMPL_7(readPixels, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei, GC3Denum, GC3Denum, void*)
642 DELEGATE_TO_IMPL(releaseShaderCompiler)
643 DELEGATE_TO_IMPL_4(renderbufferStorage, GC3Denum, GC3Denum, GC3Dsizei, GC3Dsizei)
644 DELEGATE_TO_IMPL_2(sampleCoverage, GC3Dclampf, GC3Dboolean)
645 DELEGATE_TO_IMPL_4(scissor, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei)
646
647 void GraphicsContext3DPrivate::shaderSource(Platform3DObject shader, const String& string)
648 {
649     m_impl->shaderSource(shader, string.utf8().data());
650 }
651
652 DELEGATE_TO_IMPL_3(stencilFunc, GC3Denum, GC3Dint, GC3Duint)
653 DELEGATE_TO_IMPL_4(stencilFuncSeparate, GC3Denum, GC3Denum, GC3Dint, GC3Duint)
654 DELEGATE_TO_IMPL_1(stencilMask, GC3Duint)
655 DELEGATE_TO_IMPL_2(stencilMaskSeparate, GC3Denum, GC3Duint)
656 DELEGATE_TO_IMPL_3(stencilOp, GC3Denum, GC3Denum, GC3Denum)
657 DELEGATE_TO_IMPL_4(stencilOpSeparate, GC3Denum, GC3Denum, GC3Denum, GC3Denum)
658
659 bool GraphicsContext3DPrivate::texImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3Denum type, const void* pixels)
660 {
661     m_impl->texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
662     return true;
663 }
664
665 DELEGATE_TO_IMPL_3(texParameterf, GC3Denum, GC3Denum, GC3Dfloat)
666 DELEGATE_TO_IMPL_3(texParameteri, GC3Denum, GC3Denum, GC3Dint)
667
668 void GraphicsContext3DPrivate::texSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, const void* pixels)
669 {
670     m_impl->texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
671 }
672
673 DELEGATE_TO_IMPL_2(uniform1f, GC3Dint, GC3Dfloat)
674
675 void GraphicsContext3DPrivate::uniform1fv(GC3Dint location, GC3Dsizei size, GC3Dfloat* v)
676 {
677     m_impl->uniform1fv(location, size, v);
678 }
679
680 DELEGATE_TO_IMPL_2(uniform1i, GC3Dint, GC3Dint)
681
682 void GraphicsContext3DPrivate::uniform1iv(GC3Dint location, GC3Dsizei size, GC3Dint* v)
683 {
684     m_impl->uniform1iv(location, size, v);
685 }
686
687 DELEGATE_TO_IMPL_3(uniform2f, GC3Dint, GC3Dfloat, GC3Dfloat)
688
689 void GraphicsContext3DPrivate::uniform2fv(GC3Dint location, GC3Dsizei size, GC3Dfloat* v)
690 {
691     m_impl->uniform2fv(location, size, v);
692 }
693
694 DELEGATE_TO_IMPL_3(uniform2i, GC3Dint, GC3Dint, GC3Dint)
695
696 void GraphicsContext3DPrivate::uniform2iv(GC3Dint location, GC3Dsizei size, GC3Dint* v)
697 {
698     m_impl->uniform2iv(location, size, v);
699 }
700
701 DELEGATE_TO_IMPL_4(uniform3f, GC3Dint, GC3Dfloat, GC3Dfloat, GC3Dfloat)
702
703 void GraphicsContext3DPrivate::uniform3fv(GC3Dint location, GC3Dsizei size, GC3Dfloat* v)
704 {
705     m_impl->uniform3fv(location, size, v);
706 }
707
708 DELEGATE_TO_IMPL_4(uniform3i, GC3Dint, GC3Dint, GC3Dint, GC3Dint)
709
710 void GraphicsContext3DPrivate::uniform3iv(GC3Dint location, GC3Dsizei size, GC3Dint* v)
711 {
712     m_impl->uniform3iv(location, size, v);
713 }
714
715 DELEGATE_TO_IMPL_5(uniform4f, GC3Dint, GC3Dfloat, GC3Dfloat, GC3Dfloat, GC3Dfloat)
716
717 void GraphicsContext3DPrivate::uniform4fv(GC3Dint location, GC3Dsizei size, GC3Dfloat* v)
718 {
719     m_impl->uniform4fv(location, size, v);
720 }
721
722 DELEGATE_TO_IMPL_5(uniform4i, GC3Dint, GC3Dint, GC3Dint, GC3Dint, GC3Dint)
723
724 void GraphicsContext3DPrivate::uniform4iv(GC3Dint location, GC3Dsizei size, GC3Dint* v)
725 {
726     m_impl->uniform4iv(location, size, v);
727 }
728
729 void GraphicsContext3DPrivate::uniformMatrix2fv(GC3Dint location, GC3Dsizei size, GC3Dboolean transpose, GC3Dfloat* value)
730 {
731     m_impl->uniformMatrix2fv(location, size, transpose, value);
732 }
733
734 void GraphicsContext3DPrivate::uniformMatrix3fv(GC3Dint location, GC3Dsizei size, GC3Dboolean transpose, GC3Dfloat* value)
735 {
736     m_impl->uniformMatrix3fv(location, size, transpose, value);
737 }
738
739 void GraphicsContext3DPrivate::uniformMatrix4fv(GC3Dint location, GC3Dsizei size, GC3Dboolean transpose, GC3Dfloat* value)
740 {
741     m_impl->uniformMatrix4fv(location, size, transpose, value);
742 }
743
744 DELEGATE_TO_IMPL_1(useProgram, Platform3DObject)
745 DELEGATE_TO_IMPL_1(validateProgram, Platform3DObject)
746
747 DELEGATE_TO_IMPL_2(vertexAttrib1f, GC3Duint, GC3Dfloat)
748 DELEGATE_TO_IMPL_2(vertexAttrib1fv, GC3Duint, GC3Dfloat*)
749 DELEGATE_TO_IMPL_3(vertexAttrib2f, GC3Duint, GC3Dfloat, GC3Dfloat)
750 DELEGATE_TO_IMPL_2(vertexAttrib2fv, GC3Duint, GC3Dfloat*)
751 DELEGATE_TO_IMPL_4(vertexAttrib3f, GC3Duint, GC3Dfloat, GC3Dfloat, GC3Dfloat)
752 DELEGATE_TO_IMPL_2(vertexAttrib3fv, GC3Duint, GC3Dfloat*)
753 DELEGATE_TO_IMPL_5(vertexAttrib4f, GC3Duint, GC3Dfloat, GC3Dfloat, GC3Dfloat, GC3Dfloat)
754 DELEGATE_TO_IMPL_2(vertexAttrib4fv, GC3Duint, GC3Dfloat*)
755 DELEGATE_TO_IMPL_6(vertexAttribPointer, GC3Duint, GC3Dint, GC3Denum, GC3Dboolean, GC3Dsizei, GC3Dsizeiptr)
756
757 DELEGATE_TO_IMPL_4(viewport, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei)
758
759 DELEGATE_TO_IMPL_R(createBuffer, Platform3DObject)
760 DELEGATE_TO_IMPL_R(createFramebuffer, Platform3DObject)
761 DELEGATE_TO_IMPL_R(createProgram, Platform3DObject)
762 DELEGATE_TO_IMPL_R(createRenderbuffer, Platform3DObject)
763 DELEGATE_TO_IMPL_1R(createShader, GC3Denum, Platform3DObject)
764 DELEGATE_TO_IMPL_R(createTexture, Platform3DObject)
765
766 DELEGATE_TO_IMPL_1(deleteBuffer, Platform3DObject)
767 DELEGATE_TO_IMPL_1(deleteFramebuffer, Platform3DObject)
768 DELEGATE_TO_IMPL_1(deleteProgram, Platform3DObject)
769 DELEGATE_TO_IMPL_1(deleteRenderbuffer, Platform3DObject)
770 DELEGATE_TO_IMPL_1(deleteShader, Platform3DObject)
771 DELEGATE_TO_IMPL_1(deleteTexture, Platform3DObject)
772
773 DELEGATE_TO_IMPL_1(synthesizeGLError, GC3Denum)
774
775 Extensions3D* GraphicsContext3DPrivate::getExtensions()
776 {
777     if (!m_extensions)
778         m_extensions = adoptPtr(new Extensions3DChromium(this));
779     return m_extensions.get();
780 }
781
782 bool GraphicsContext3DPrivate::isResourceSafe()
783 {
784     if (m_resourceSafety == ResourceSafetyUnknown)
785         m_resourceSafety = getExtensions()->isEnabled("GL_CHROMIUM_resource_safe") ? ResourceSafe : ResourceUnsafe;
786     return m_resourceSafety == ResourceSafe;
787 }
788
789 namespace {
790
791 void splitStringHelper(const String& str, HashSet<String>& set)
792 {
793     Vector<String> substrings;
794     str.split(" ", substrings);
795     for (size_t i = 0; i < substrings.size(); ++i)
796         set.add(substrings[i]);
797 }
798
799 String mapExtensionName(const String& name)
800 {
801     if (name == "GL_ANGLE_framebuffer_blit"
802         || name == "GL_ANGLE_framebuffer_multisample")
803         return "GL_CHROMIUM_framebuffer_multisample";
804     return name;
805 }
806
807 } // anonymous namespace
808
809 void GraphicsContext3DPrivate::initializeExtensions()
810 {
811     if (m_initializedAvailableExtensions)
812         return;
813
814     m_initializedAvailableExtensions = true;
815     bool success = makeContextCurrent();
816     ASSERT(success);
817     if (!success)
818         return;
819
820     String extensionsString = getString(GraphicsContext3D::EXTENSIONS);
821     splitStringHelper(extensionsString, m_enabledExtensions);
822
823     String requestableExtensionsString = m_impl->getRequestableExtensionsCHROMIUM();
824     splitStringHelper(requestableExtensionsString, m_requestableExtensions);
825 }
826
827
828 bool GraphicsContext3DPrivate::supportsExtension(const String& name)
829 {
830     initializeExtensions();
831     String mappedName = mapExtensionName(name);
832     return m_enabledExtensions.contains(mappedName) || m_requestableExtensions.contains(mappedName);
833 }
834
835 bool GraphicsContext3DPrivate::ensureExtensionEnabled(const String& name)
836 {
837     initializeExtensions();
838
839     String mappedName = mapExtensionName(name);
840     if (m_enabledExtensions.contains(mappedName))
841         return true;
842
843     if (m_requestableExtensions.contains(mappedName)) {
844         m_impl->requestExtensionCHROMIUM(mappedName.ascii().data());
845         m_enabledExtensions.clear();
846         m_requestableExtensions.clear();
847         m_initializedAvailableExtensions = false;
848     }
849
850     initializeExtensions();
851     return m_enabledExtensions.contains(mappedName);
852 }
853
854 bool GraphicsContext3DPrivate::isExtensionEnabled(const String& name)
855 {
856     initializeExtensions();
857     String mappedName = mapExtensionName(name);
858     return m_enabledExtensions.contains(mappedName);
859 }
860
861 DELEGATE_TO_IMPL_4(postSubBufferCHROMIUM, int, int, int, int)
862
863 DELEGATE_TO_IMPL_4R(mapBufferSubDataCHROMIUM, GC3Denum, GC3Dsizeiptr, GC3Dsizei, GC3Denum, void*)
864 DELEGATE_TO_IMPL_1(unmapBufferSubDataCHROMIUM, const void*)
865 DELEGATE_TO_IMPL_9R(mapTexSubImage2DCHROMIUM, GC3Denum, GC3Dint, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei, GC3Denum, GC3Denum, GC3Denum, void*)
866 DELEGATE_TO_IMPL_1(unmapTexSubImage2DCHROMIUM, const void*)
867
868 DELEGATE_TO_IMPL_1(setVisibilityCHROMIUM, bool);
869
870 DELEGATE_TO_IMPL_10(blitFramebufferCHROMIUM, GC3Dint, GC3Dint, GC3Dint, GC3Dint, GC3Dint, GC3Dint, GC3Dint, GC3Dint, GC3Dbitfield, GC3Denum)
871 DELEGATE_TO_IMPL_5(renderbufferStorageMultisampleCHROMIUM, GC3Denum, GC3Dsizei, GC3Denum, GC3Dsizei, GC3Dsizei)
872
873 DELEGATE_TO_IMPL(rateLimitOffscreenContextCHROMIUM)
874 DELEGATE_TO_IMPL_R(getGraphicsResetStatusARB, GC3Denum)
875
876 DELEGATE_TO_IMPL_1R(getTranslatedShaderSourceANGLE, Platform3DObject, String)
877 DELEGATE_TO_IMPL_5(texImageIOSurface2DCHROMIUM, GC3Denum, GC3Dint, GC3Dint, GC3Duint, GC3Duint)
878 DELEGATE_TO_IMPL_5(texStorage2DEXT, GC3Denum, GC3Dint, GC3Duint, GC3Dint, GC3Dint)
879
880 //----------------------------------------------------------------------
881 // GraphicsContext3D
882 //
883
884 // Macros to assist in delegating from GraphicsContext3D to
885 // GraphicsContext3DPrivate.
886
887 #define DELEGATE_TO_INTERNAL(name) \
888 void GraphicsContext3D::name() \
889 { \
890     m_private->name(); \
891 }
892
893 #define DELEGATE_TO_INTERNAL_R(name, rt)           \
894 rt GraphicsContext3D::name() \
895 { \
896     return m_private->name(); \
897 }
898
899 #define DELEGATE_TO_INTERNAL_1(name, t1) \
900 void GraphicsContext3D::name(t1 a1) \
901 { \
902     m_private->name(a1); \
903 }
904
905 #define DELEGATE_TO_INTERNAL_1R(name, t1, rt)    \
906 rt GraphicsContext3D::name(t1 a1) \
907 { \
908     return m_private->name(a1); \
909 }
910
911 #define DELEGATE_TO_INTERNAL_2(name, t1, t2) \
912 void GraphicsContext3D::name(t1 a1, t2 a2) \
913 { \
914     m_private->name(a1, a2); \
915 }
916
917 #define DELEGATE_TO_INTERNAL_2R(name, t1, t2, rt)  \
918 rt GraphicsContext3D::name(t1 a1, t2 a2) \
919 { \
920     return m_private->name(a1, a2); \
921 }
922
923 #define DELEGATE_TO_INTERNAL_3(name, t1, t2, t3)   \
924 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3)    \
925 { \
926     m_private->name(a1, a2, a3);                  \
927 }
928
929 #define DELEGATE_TO_INTERNAL_3R(name, t1, t2, t3, rt)   \
930 rt GraphicsContext3D::name(t1 a1, t2 a2, t3 a3)    \
931 { \
932     return m_private->name(a1, a2, a3);                  \
933 }
934
935 #define DELEGATE_TO_INTERNAL_4(name, t1, t2, t3, t4)    \
936 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4)  \
937 { \
938     m_private->name(a1, a2, a3, a4);              \
939 }
940
941 #define DELEGATE_TO_INTERNAL_4R(name, t1, t2, t3, t4, rt)    \
942 rt GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4)  \
943 { \
944     return m_private->name(a1, a2, a3, a4);           \
945 }
946
947 #define DELEGATE_TO_INTERNAL_5(name, t1, t2, t3, t4, t5)      \
948 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5)        \
949 { \
950     m_private->name(a1, a2, a3, a4, a5);   \
951 }
952
953 #define DELEGATE_TO_INTERNAL_6(name, t1, t2, t3, t4, t5, t6)  \
954 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6) \
955 { \
956     m_private->name(a1, a2, a3, a4, a5, a6);   \
957 }
958
959 #define DELEGATE_TO_INTERNAL_6R(name, t1, t2, t3, t4, t5, t6, rt)  \
960 rt GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6) \
961 { \
962     return m_private->name(a1, a2, a3, a4, a5, a6);       \
963 }
964
965 #define DELEGATE_TO_INTERNAL_7(name, t1, t2, t3, t4, t5, t6, t7) \
966 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7) \
967 { \
968     m_private->name(a1, a2, a3, a4, a5, a6, a7);   \
969 }
970
971 #define DELEGATE_TO_INTERNAL_7R(name, t1, t2, t3, t4, t5, t6, t7, rt) \
972 rt GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7) \
973 { \
974     return m_private->name(a1, a2, a3, a4, a5, a6, a7);   \
975 }
976
977 #define DELEGATE_TO_INTERNAL_8(name, t1, t2, t3, t4, t5, t6, t7, t8)       \
978 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8 a8) \
979 { \
980     m_private->name(a1, a2, a3, a4, a5, a6, a7, a8);      \
981 }
982
983 #define DELEGATE_TO_INTERNAL_9(name, t1, t2, t3, t4, t5, t6, t7, t8, t9) \
984 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8 a8, t9 a9) \
985 { \
986     m_private->name(a1, a2, a3, a4, a5, a6, a7, a8, a9);   \
987 }
988
989 #define DELEGATE_TO_INTERNAL_9R(name, t1, t2, t3, t4, t5, t6, t7, t8, t9, rt) \
990 rt GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8 a8, t9 a9) \
991 { \
992     return m_private->name(a1, a2, a3, a4, a5, a6, a7, a8, a9);   \
993 }
994
995 GraphicsContext3D::GraphicsContext3D(GraphicsContext3D::Attributes, HostWindow*, bool)
996 {
997 }
998
999 GraphicsContext3D::~GraphicsContext3D()
1000 {
1001     m_private->setContextLostCallback(nullptr);
1002     m_private->setErrorMessageCallback(nullptr);
1003     m_private->setSwapBuffersCompleteCallbackCHROMIUM(nullptr);
1004     m_private->setGpuMemoryAllocationChangedCallbackCHROMIUM(nullptr);
1005 }
1006
1007 PassRefPtr<GraphicsContext3D> GraphicsContext3D::create(GraphicsContext3D::Attributes attrs, HostWindow*, GraphicsContext3D::RenderStyle renderStyle)
1008 {
1009     ASSERT(renderStyle != GraphicsContext3D::RenderDirectlyToHostWindow);
1010
1011     WebKit::WebGraphicsContext3D::Attributes webAttributes;
1012     webAttributes.alpha = attrs.alpha;
1013     webAttributes.depth = attrs.depth;
1014     webAttributes.stencil = attrs.stencil;
1015     webAttributes.antialias = attrs.antialias;
1016     webAttributes.premultipliedAlpha = attrs.premultipliedAlpha;
1017     webAttributes.canRecoverFromContextLoss = attrs.canRecoverFromContextLoss;
1018     webAttributes.noExtensions = attrs.noExtensions;
1019     webAttributes.shareResources = attrs.shareResources;
1020
1021     OwnPtr<WebKit::WebGraphicsContext3D> webContext = adoptPtr(WebKit::webKitPlatformSupport()->createOffscreenGraphicsContext3D(webAttributes));
1022     if (!webContext)
1023         return 0;
1024
1025     return GraphicsContext3DPrivate::createGraphicsContextFromWebContext(webContext.release(), renderStyle, attrs.preserveDrawingBuffer);
1026 }
1027
1028 PlatformGraphicsContext3D GraphicsContext3D::platformGraphicsContext3D() const
1029 {
1030     return m_private->platformGraphicsContext3D();
1031 }
1032
1033 Platform3DObject GraphicsContext3D::platformTexture() const
1034 {
1035     return m_private->platformTexture();
1036 }
1037
1038 #if USE(SKIA)
1039 GrContext* GraphicsContext3D::grContext()
1040 {
1041     return m_private->grContext();
1042 }
1043 #endif
1044
1045 void GraphicsContext3D::prepareTexture()
1046 {
1047     return m_private->prepareTexture();
1048 }
1049
1050 IntSize GraphicsContext3D::getInternalFramebufferSize() const
1051 {
1052     return m_private->getInternalFramebufferSize();
1053 }
1054
1055 bool GraphicsContext3D::isResourceSafe()
1056 {
1057     return m_private->isResourceSafe();
1058 }
1059
1060 #if USE(ACCELERATED_COMPOSITING)
1061 PlatformLayer* GraphicsContext3D::platformLayer() const
1062 {
1063     return 0;
1064 }
1065 #endif
1066
1067 DELEGATE_TO_INTERNAL_R(makeContextCurrent, bool)
1068 DELEGATE_TO_INTERNAL_2(reshape, int, int)
1069
1070 DELEGATE_TO_INTERNAL_1(activeTexture, GC3Denum)
1071 DELEGATE_TO_INTERNAL_2(attachShader, Platform3DObject, Platform3DObject)
1072 DELEGATE_TO_INTERNAL_3(bindAttribLocation, Platform3DObject, GC3Duint, const String&)
1073
1074 DELEGATE_TO_INTERNAL_2(bindBuffer, GC3Denum, Platform3DObject)
1075 DELEGATE_TO_INTERNAL_2(bindFramebuffer, GC3Denum, Platform3DObject)
1076 DELEGATE_TO_INTERNAL_2(bindRenderbuffer, GC3Denum, Platform3DObject)
1077 DELEGATE_TO_INTERNAL_2(bindTexture, GC3Denum, Platform3DObject)
1078 DELEGATE_TO_INTERNAL_4(blendColor, GC3Dclampf, GC3Dclampf, GC3Dclampf, GC3Dclampf)
1079 DELEGATE_TO_INTERNAL_1(blendEquation, GC3Denum)
1080 DELEGATE_TO_INTERNAL_2(blendEquationSeparate, GC3Denum, GC3Denum)
1081 DELEGATE_TO_INTERNAL_2(blendFunc, GC3Denum, GC3Denum)
1082 DELEGATE_TO_INTERNAL_4(blendFuncSeparate, GC3Denum, GC3Denum, GC3Denum, GC3Denum)
1083
1084 DELEGATE_TO_INTERNAL_3(bufferData, GC3Denum, GC3Dsizeiptr, GC3Denum)
1085 DELEGATE_TO_INTERNAL_4(bufferData, GC3Denum, GC3Dsizeiptr, const void*, GC3Denum)
1086 DELEGATE_TO_INTERNAL_4(bufferSubData, GC3Denum, GC3Dintptr, GC3Dsizeiptr, const void*)
1087
1088 DELEGATE_TO_INTERNAL_1R(checkFramebufferStatus, GC3Denum, GC3Denum)
1089 DELEGATE_TO_INTERNAL_1(clear, GC3Dbitfield)
1090 DELEGATE_TO_INTERNAL_4(clearColor, GC3Dclampf, GC3Dclampf, GC3Dclampf, GC3Dclampf)
1091 DELEGATE_TO_INTERNAL_1(clearDepth, GC3Dclampf)
1092 DELEGATE_TO_INTERNAL_1(clearStencil, GC3Dint)
1093 DELEGATE_TO_INTERNAL_4(colorMask, GC3Dboolean, GC3Dboolean, GC3Dboolean, GC3Dboolean)
1094 DELEGATE_TO_INTERNAL_1(compileShader, Platform3DObject)
1095
1096 DELEGATE_TO_INTERNAL_8(compressedTexImage2D, GC3Denum, GC3Dint, GC3Denum, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei, const void*)
1097 DELEGATE_TO_INTERNAL_9(compressedTexSubImage2D, GC3Denum, GC3Dint, GC3Dint, GC3Dint, GC3Dint, GC3Dint, GC3Denum, GC3Dsizei, const void*)
1098 DELEGATE_TO_INTERNAL_8(copyTexImage2D, GC3Denum, GC3Dint, GC3Denum, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei, GC3Dint)
1099 DELEGATE_TO_INTERNAL_8(copyTexSubImage2D, GC3Denum, GC3Dint, GC3Dint, GC3Dint, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei)
1100 DELEGATE_TO_INTERNAL_1(cullFace, GC3Denum)
1101 DELEGATE_TO_INTERNAL_1(depthFunc, GC3Denum)
1102 DELEGATE_TO_INTERNAL_1(depthMask, GC3Dboolean)
1103 DELEGATE_TO_INTERNAL_2(depthRange, GC3Dclampf, GC3Dclampf)
1104 DELEGATE_TO_INTERNAL_2(detachShader, Platform3DObject, Platform3DObject)
1105 DELEGATE_TO_INTERNAL_1(disable, GC3Denum)
1106 DELEGATE_TO_INTERNAL_1(disableVertexAttribArray, GC3Duint)
1107 DELEGATE_TO_INTERNAL_3(drawArrays, GC3Denum, GC3Dint, GC3Dsizei)
1108 DELEGATE_TO_INTERNAL_4(drawElements, GC3Denum, GC3Dsizei, GC3Denum, GC3Dintptr)
1109
1110 DELEGATE_TO_INTERNAL_1(enable, GC3Denum)
1111 DELEGATE_TO_INTERNAL_1(enableVertexAttribArray, GC3Duint)
1112 DELEGATE_TO_INTERNAL(finish)
1113 DELEGATE_TO_INTERNAL(flush)
1114 DELEGATE_TO_INTERNAL_4(framebufferRenderbuffer, GC3Denum, GC3Denum, GC3Denum, Platform3DObject)
1115 DELEGATE_TO_INTERNAL_5(framebufferTexture2D, GC3Denum, GC3Denum, GC3Denum, Platform3DObject, GC3Dint)
1116 DELEGATE_TO_INTERNAL_1(frontFace, GC3Denum)
1117 DELEGATE_TO_INTERNAL_1(generateMipmap, GC3Denum)
1118
1119 DELEGATE_TO_INTERNAL_3R(getActiveAttrib, Platform3DObject, GC3Duint, ActiveInfo&, bool)
1120 DELEGATE_TO_INTERNAL_3R(getActiveUniform, Platform3DObject, GC3Duint, ActiveInfo&, bool)
1121 DELEGATE_TO_INTERNAL_4(getAttachedShaders, Platform3DObject, GC3Dsizei, GC3Dsizei*, Platform3DObject*)
1122 DELEGATE_TO_INTERNAL_2R(getAttribLocation, Platform3DObject, const String&, GC3Dint)
1123 DELEGATE_TO_INTERNAL_2(getBooleanv, GC3Denum, GC3Dboolean*)
1124 DELEGATE_TO_INTERNAL_3(getBufferParameteriv, GC3Denum, GC3Denum, GC3Dint*)
1125 DELEGATE_TO_INTERNAL_R(getContextAttributes, GraphicsContext3D::Attributes)
1126 DELEGATE_TO_INTERNAL_R(getError, GC3Denum)
1127 DELEGATE_TO_INTERNAL_2(getFloatv, GC3Denum, GC3Dfloat*)
1128 DELEGATE_TO_INTERNAL_4(getFramebufferAttachmentParameteriv, GC3Denum, GC3Denum, GC3Denum, GC3Dint*)
1129 DELEGATE_TO_INTERNAL_2(getIntegerv, GC3Denum, GC3Dint*)
1130 DELEGATE_TO_INTERNAL_3(getProgramiv, Platform3DObject, GC3Denum, GC3Dint*)
1131 DELEGATE_TO_INTERNAL_1R(getProgramInfoLog, Platform3DObject, String)
1132 DELEGATE_TO_INTERNAL_3(getRenderbufferParameteriv, GC3Denum, GC3Denum, GC3Dint*)
1133 DELEGATE_TO_INTERNAL_3(getShaderiv, Platform3DObject, GC3Denum, GC3Dint*)
1134 DELEGATE_TO_INTERNAL_1R(getShaderInfoLog, Platform3DObject, String)
1135 DELEGATE_TO_INTERNAL_1R(getShaderSource, Platform3DObject, String)
1136 DELEGATE_TO_INTERNAL_1R(getString, GC3Denum, String)
1137 DELEGATE_TO_INTERNAL_3(getTexParameterfv, GC3Denum, GC3Denum, GC3Dfloat*)
1138 DELEGATE_TO_INTERNAL_3(getTexParameteriv, GC3Denum, GC3Denum, GC3Dint*)
1139 DELEGATE_TO_INTERNAL_3(getUniformfv, Platform3DObject, GC3Dint, GC3Dfloat*)
1140 DELEGATE_TO_INTERNAL_3(getUniformiv, Platform3DObject, GC3Dint, GC3Dint*)
1141 DELEGATE_TO_INTERNAL_2R(getUniformLocation, Platform3DObject, const String&, GC3Dint)
1142 DELEGATE_TO_INTERNAL_3(getVertexAttribfv, GC3Duint, GC3Denum, GC3Dfloat*)
1143 DELEGATE_TO_INTERNAL_3(getVertexAttribiv, GC3Duint, GC3Denum, GC3Dint*)
1144 DELEGATE_TO_INTERNAL_2R(getVertexAttribOffset, GC3Duint, GC3Denum, GC3Dsizeiptr)
1145
1146 DELEGATE_TO_INTERNAL_2(hint, GC3Denum, GC3Denum)
1147 DELEGATE_TO_INTERNAL_1R(isBuffer, Platform3DObject, GC3Dboolean)
1148 DELEGATE_TO_INTERNAL_1R(isEnabled, GC3Denum, GC3Dboolean)
1149 DELEGATE_TO_INTERNAL_1R(isFramebuffer, Platform3DObject, GC3Dboolean)
1150 DELEGATE_TO_INTERNAL_1R(isProgram, Platform3DObject, GC3Dboolean)
1151 DELEGATE_TO_INTERNAL_1R(isRenderbuffer, Platform3DObject, GC3Dboolean)
1152 DELEGATE_TO_INTERNAL_1R(isShader, Platform3DObject, GC3Dboolean)
1153 DELEGATE_TO_INTERNAL_1R(isTexture, Platform3DObject, GC3Dboolean)
1154 DELEGATE_TO_INTERNAL_1(lineWidth, GC3Dfloat)
1155 DELEGATE_TO_INTERNAL_1(linkProgram, Platform3DObject)
1156 DELEGATE_TO_INTERNAL_2(pixelStorei, GC3Denum, GC3Dint)
1157 DELEGATE_TO_INTERNAL_2(polygonOffset, GC3Dfloat, GC3Dfloat)
1158
1159 DELEGATE_TO_INTERNAL_7(readPixels, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei, GC3Denum, GC3Denum, void*)
1160
1161 DELEGATE_TO_INTERNAL(releaseShaderCompiler)
1162 DELEGATE_TO_INTERNAL_4(renderbufferStorage, GC3Denum, GC3Denum, GC3Dsizei, GC3Dsizei)
1163 DELEGATE_TO_INTERNAL_2(sampleCoverage, GC3Dclampf, GC3Dboolean)
1164 DELEGATE_TO_INTERNAL_4(scissor, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei)
1165 DELEGATE_TO_INTERNAL_2(shaderSource, Platform3DObject, const String&)
1166 DELEGATE_TO_INTERNAL_3(stencilFunc, GC3Denum, GC3Dint, GC3Duint)
1167 DELEGATE_TO_INTERNAL_4(stencilFuncSeparate, GC3Denum, GC3Denum, GC3Dint, GC3Duint)
1168 DELEGATE_TO_INTERNAL_1(stencilMask, GC3Duint)
1169 DELEGATE_TO_INTERNAL_2(stencilMaskSeparate, GC3Denum, GC3Duint)
1170 DELEGATE_TO_INTERNAL_3(stencilOp, GC3Denum, GC3Denum, GC3Denum)
1171 DELEGATE_TO_INTERNAL_4(stencilOpSeparate, GC3Denum, GC3Denum, GC3Denum, GC3Denum)
1172
1173 DELEGATE_TO_INTERNAL_9R(texImage2D, GC3Denum, GC3Dint, GC3Denum, GC3Dsizei, GC3Dsizei, GC3Dint, GC3Denum, GC3Denum, const void*, bool)
1174 DELEGATE_TO_INTERNAL_3(texParameterf, GC3Denum, GC3Denum, GC3Dfloat)
1175 DELEGATE_TO_INTERNAL_3(texParameteri, GC3Denum, GC3Denum, GC3Dint)
1176 DELEGATE_TO_INTERNAL_9(texSubImage2D, GC3Denum, GC3Dint, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei, GC3Denum, GC3Denum, const void*)
1177
1178 DELEGATE_TO_INTERNAL_2(uniform1f, GC3Dint, GC3Dfloat)
1179 DELEGATE_TO_INTERNAL_3(uniform1fv, GC3Dint, GC3Dsizei, GC3Dfloat*)
1180 DELEGATE_TO_INTERNAL_2(uniform1i, GC3Dint, GC3Dint)
1181 DELEGATE_TO_INTERNAL_3(uniform1iv, GC3Dint, GC3Dsizei, GC3Dint*)
1182 DELEGATE_TO_INTERNAL_3(uniform2f, GC3Dint, GC3Dfloat, GC3Dfloat)
1183 DELEGATE_TO_INTERNAL_3(uniform2fv, GC3Dint, GC3Dsizei, GC3Dfloat*)
1184 DELEGATE_TO_INTERNAL_3(uniform2i, GC3Dint, GC3Dint, GC3Dint)
1185 DELEGATE_TO_INTERNAL_3(uniform2iv, GC3Dint, GC3Dsizei, GC3Dint*)
1186 DELEGATE_TO_INTERNAL_4(uniform3f, GC3Dint, GC3Dfloat, GC3Dfloat, GC3Dfloat)
1187 DELEGATE_TO_INTERNAL_3(uniform3fv, GC3Dint, GC3Dsizei, GC3Dfloat*)
1188 DELEGATE_TO_INTERNAL_4(uniform3i, GC3Dint, GC3Dint, GC3Dint, GC3Dint)
1189 DELEGATE_TO_INTERNAL_3(uniform3iv, GC3Dint, GC3Dsizei, GC3Dint*)
1190 DELEGATE_TO_INTERNAL_5(uniform4f, GC3Dint, GC3Dfloat, GC3Dfloat, GC3Dfloat, GC3Dfloat)
1191 DELEGATE_TO_INTERNAL_3(uniform4fv, GC3Dint, GC3Dsizei, GC3Dfloat*)
1192 DELEGATE_TO_INTERNAL_5(uniform4i, GC3Dint, GC3Dint, GC3Dint, GC3Dint, GC3Dint)
1193 DELEGATE_TO_INTERNAL_3(uniform4iv, GC3Dint, GC3Dsizei, GC3Dint*)
1194 DELEGATE_TO_INTERNAL_4(uniformMatrix2fv, GC3Dint, GC3Dsizei, GC3Dboolean, GC3Dfloat*)
1195 DELEGATE_TO_INTERNAL_4(uniformMatrix3fv, GC3Dint, GC3Dsizei, GC3Dboolean, GC3Dfloat*)
1196 DELEGATE_TO_INTERNAL_4(uniformMatrix4fv, GC3Dint, GC3Dsizei, GC3Dboolean, GC3Dfloat*)
1197
1198 DELEGATE_TO_INTERNAL_1(useProgram, Platform3DObject)
1199 DELEGATE_TO_INTERNAL_1(validateProgram, Platform3DObject)
1200
1201 DELEGATE_TO_INTERNAL_2(vertexAttrib1f, GC3Duint, GC3Dfloat)
1202 DELEGATE_TO_INTERNAL_2(vertexAttrib1fv, GC3Duint, GC3Dfloat*)
1203 DELEGATE_TO_INTERNAL_3(vertexAttrib2f, GC3Duint, GC3Dfloat, GC3Dfloat)
1204 DELEGATE_TO_INTERNAL_2(vertexAttrib2fv, GC3Duint, GC3Dfloat*)
1205 DELEGATE_TO_INTERNAL_4(vertexAttrib3f, GC3Duint, GC3Dfloat, GC3Dfloat, GC3Dfloat)
1206 DELEGATE_TO_INTERNAL_2(vertexAttrib3fv, GC3Duint, GC3Dfloat*)
1207 DELEGATE_TO_INTERNAL_5(vertexAttrib4f, GC3Duint, GC3Dfloat, GC3Dfloat, GC3Dfloat, GC3Dfloat)
1208 DELEGATE_TO_INTERNAL_2(vertexAttrib4fv, GC3Duint, GC3Dfloat*)
1209 DELEGATE_TO_INTERNAL_6(vertexAttribPointer, GC3Duint, GC3Dint, GC3Denum, GC3Dboolean, GC3Dsizei, GC3Dintptr)
1210
1211 DELEGATE_TO_INTERNAL_4(viewport, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei)
1212
1213 DELEGATE_TO_INTERNAL(markLayerComposited)
1214 DELEGATE_TO_INTERNAL(markContextChanged)
1215
1216 bool GraphicsContext3D::layerComposited() const
1217 {
1218     return m_private->layerComposited();
1219 }
1220
1221 void GraphicsContext3D::paintRenderingResultsToCanvas(CanvasRenderingContext* context, DrawingBuffer* drawingBuffer)
1222 {
1223     return m_private->paintRenderingResultsToCanvas(context, drawingBuffer);
1224 }
1225
1226 PassRefPtr<ImageData> GraphicsContext3D::paintRenderingResultsToImageData(DrawingBuffer* drawingBuffer)
1227 {
1228     return m_private->paintRenderingResultsToImageData(drawingBuffer);
1229 }
1230
1231 DELEGATE_TO_INTERNAL_1R(paintCompositedResultsToCanvas, CanvasRenderingContext*, bool)
1232
1233 DELEGATE_TO_INTERNAL_R(createBuffer, Platform3DObject)
1234 DELEGATE_TO_INTERNAL_R(createFramebuffer, Platform3DObject)
1235 DELEGATE_TO_INTERNAL_R(createProgram, Platform3DObject)
1236 DELEGATE_TO_INTERNAL_R(createRenderbuffer, Platform3DObject)
1237 DELEGATE_TO_INTERNAL_1R(createShader, GC3Denum, Platform3DObject)
1238 DELEGATE_TO_INTERNAL_R(createTexture, Platform3DObject)
1239
1240 DELEGATE_TO_INTERNAL_1(deleteBuffer, Platform3DObject)
1241 DELEGATE_TO_INTERNAL_1(deleteFramebuffer, Platform3DObject)
1242 DELEGATE_TO_INTERNAL_1(deleteProgram, Platform3DObject)
1243 DELEGATE_TO_INTERNAL_1(deleteRenderbuffer, Platform3DObject)
1244 DELEGATE_TO_INTERNAL_1(deleteShader, Platform3DObject)
1245 DELEGATE_TO_INTERNAL_1(deleteTexture, Platform3DObject)
1246
1247 DELEGATE_TO_INTERNAL_1(synthesizeGLError, GC3Denum)
1248 DELEGATE_TO_INTERNAL_R(getExtensions, Extensions3D*)
1249
1250 DELEGATE_TO_INTERNAL_1(setContextLostCallback, PassOwnPtr<GraphicsContext3D::ContextLostCallback>)
1251 DELEGATE_TO_INTERNAL_1(setErrorMessageCallback, PassOwnPtr<GraphicsContext3D::ErrorMessageCallback>)
1252
1253 class GraphicsContextLostCallbackAdapter : public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback {
1254 public:
1255     virtual void onContextLost();
1256     static PassOwnPtr<GraphicsContextLostCallbackAdapter> create(PassOwnPtr<GraphicsContext3D::ContextLostCallback>);
1257     virtual ~GraphicsContextLostCallbackAdapter() { }
1258 private:
1259     GraphicsContextLostCallbackAdapter(PassOwnPtr<GraphicsContext3D::ContextLostCallback> cb) : m_contextLostCallback(cb) { }
1260     OwnPtr<GraphicsContext3D::ContextLostCallback> m_contextLostCallback;
1261 };
1262
1263 void GraphicsContextLostCallbackAdapter::onContextLost()
1264 {
1265     if (m_contextLostCallback)
1266         m_contextLostCallback->onContextLost();
1267 }
1268
1269 PassOwnPtr<GraphicsContextLostCallbackAdapter> GraphicsContextLostCallbackAdapter::create(PassOwnPtr<GraphicsContext3D::ContextLostCallback> cb)
1270 {
1271     return adoptPtr(cb.get() ? new GraphicsContextLostCallbackAdapter(cb) : 0);
1272 }
1273
1274 void GraphicsContext3DPrivate::setContextLostCallback(PassOwnPtr<GraphicsContext3D::ContextLostCallback> cb)
1275 {
1276     m_contextLostCallbackAdapter = GraphicsContextLostCallbackAdapter::create(cb);
1277     m_impl->setContextLostCallback(m_contextLostCallbackAdapter.get());
1278 }
1279
1280 class GraphicsErrorMessageCallbackAdapter : public WebKit::WebGraphicsContext3D::WebGraphicsErrorMessageCallback {
1281 public:
1282     virtual void onErrorMessage(const WebKit::WebString&, WebKit::WGC3Dint);
1283     static PassOwnPtr<GraphicsErrorMessageCallbackAdapter> create(PassOwnPtr<GraphicsContext3D::ErrorMessageCallback>);
1284     virtual ~GraphicsErrorMessageCallbackAdapter() { }
1285 private:
1286     GraphicsErrorMessageCallbackAdapter(PassOwnPtr<GraphicsContext3D::ErrorMessageCallback> cb) : m_errorMessageCallback(cb) { }
1287     OwnPtr<GraphicsContext3D::ErrorMessageCallback> m_errorMessageCallback;
1288 };
1289
1290 void GraphicsErrorMessageCallbackAdapter::onErrorMessage(const WebKit::WebString& message, WebKit::WGC3Dint id)
1291 {
1292     if (m_errorMessageCallback)
1293         m_errorMessageCallback->onErrorMessage(message, id);
1294 }
1295
1296 PassOwnPtr<GraphicsErrorMessageCallbackAdapter> GraphicsErrorMessageCallbackAdapter::create(PassOwnPtr<GraphicsContext3D::ErrorMessageCallback> cb)
1297 {
1298     return adoptPtr(cb.get() ? new GraphicsErrorMessageCallbackAdapter(cb) : 0);
1299 }
1300
1301 void GraphicsContext3DPrivate::setErrorMessageCallback(PassOwnPtr<GraphicsContext3D::ErrorMessageCallback> cb)
1302 {
1303     m_errorMessageCallbackAdapter = GraphicsErrorMessageCallbackAdapter::create(cb);
1304     m_impl->setErrorMessageCallback(m_errorMessageCallbackAdapter.get());
1305 }
1306
1307 bool GraphicsContext3D::isGLES2Compliant() const
1308 {
1309     return m_private->isGLES2Compliant();
1310 }
1311
1312 class GraphicsContext3DSwapBuffersCompleteCallbackAdapter : public WebKit::WebGraphicsContext3D::WebGraphicsSwapBuffersCompleteCallbackCHROMIUM {
1313 public:
1314     virtual void onSwapBuffersComplete();
1315     static PassOwnPtr<GraphicsContext3DSwapBuffersCompleteCallbackAdapter> create(PassOwnPtr<Extensions3DChromium::SwapBuffersCompleteCallbackCHROMIUM>);
1316     virtual ~GraphicsContext3DSwapBuffersCompleteCallbackAdapter() { }
1317
1318 private:
1319     GraphicsContext3DSwapBuffersCompleteCallbackAdapter(PassOwnPtr<Extensions3DChromium::SwapBuffersCompleteCallbackCHROMIUM> cb) : m_swapBuffersCompleteCallback(cb) { }
1320     OwnPtr<Extensions3DChromium::SwapBuffersCompleteCallbackCHROMIUM> m_swapBuffersCompleteCallback;
1321 };
1322
1323 void GraphicsContext3DSwapBuffersCompleteCallbackAdapter::onSwapBuffersComplete()
1324 {
1325     if (m_swapBuffersCompleteCallback)
1326         m_swapBuffersCompleteCallback->onSwapBuffersComplete();
1327 }
1328
1329 PassOwnPtr<GraphicsContext3DSwapBuffersCompleteCallbackAdapter> GraphicsContext3DSwapBuffersCompleteCallbackAdapter::create(PassOwnPtr<Extensions3DChromium::SwapBuffersCompleteCallbackCHROMIUM> cb)
1330 {
1331     return adoptPtr(cb.get() ? new GraphicsContext3DSwapBuffersCompleteCallbackAdapter(cb) : 0);
1332 }
1333
1334 void GraphicsContext3DPrivate::setSwapBuffersCompleteCallbackCHROMIUM(PassOwnPtr<Extensions3DChromium::SwapBuffersCompleteCallbackCHROMIUM> cb)
1335 {
1336     m_swapBuffersCompleteCallbackAdapter = GraphicsContext3DSwapBuffersCompleteCallbackAdapter::create(cb);
1337     m_impl->setSwapBuffersCompleteCallbackCHROMIUM(m_swapBuffersCompleteCallbackAdapter.get());
1338 }
1339
1340 class GraphicsContext3DMemoryAllocationChangedCallbackAdapter : public WebKit::WebGraphicsContext3D::WebGraphicsMemoryAllocationChangedCallbackCHROMIUM {
1341 public:
1342     GraphicsContext3DMemoryAllocationChangedCallbackAdapter(PassOwnPtr<Extensions3DChromium::GpuMemoryAllocationChangedCallbackCHROMIUM> cb)
1343         : m_memoryAllocationChangedCallback(cb)
1344     {
1345     }
1346
1347     virtual ~GraphicsContext3DMemoryAllocationChangedCallbackAdapter() { }
1348
1349     virtual void onMemoryAllocationChanged(size_t gpuResourceSizeInBytes)
1350     {
1351         if (m_memoryAllocationChangedCallback)
1352             m_memoryAllocationChangedCallback->onGpuMemoryAllocationChanged(gpuResourceSizeInBytes);
1353     }
1354
1355 private:
1356     OwnPtr<Extensions3DChromium::GpuMemoryAllocationChangedCallbackCHROMIUM> m_memoryAllocationChangedCallback;
1357 };
1358
1359 void GraphicsContext3DPrivate::setGpuMemoryAllocationChangedCallbackCHROMIUM(PassOwnPtr<Extensions3DChromium::GpuMemoryAllocationChangedCallbackCHROMIUM> cb)
1360 {
1361     m_memoryAllocationChangedCallbackAdapter = adoptPtr(new GraphicsContext3DMemoryAllocationChangedCallbackAdapter(cb));
1362     m_impl->setMemoryAllocationChangedCallbackCHROMIUM(m_memoryAllocationChangedCallbackAdapter.get());
1363 }
1364
1365 } // namespace WebCore
1366
1367 #endif // ENABLE(WEBGL)