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