2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
35 #include "GraphicsContext3D.h"
37 #include "CachedImage.h"
38 #include "CanvasRenderingContext.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"
50 #include "WebKitPlatformSupport.h"
51 #include "WebViewImpl.h"
54 #include <wtf/FastMalloc.h>
55 #include <wtf/text/CString.h>
58 #include "GraphicsContext.h"
59 #include "WebGLRenderingContext.h"
60 #include <CoreGraphics/CGContext.h>
61 #include <CoreGraphics/CGImage.h>
65 #include "GrContext.h"
66 #include "GrGLInterface.h"
69 // There are two levels of delegation in this file:
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.
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.
84 //----------------------------------------------------------------------
85 // GraphicsContext3DPrivate
87 GraphicsContext3DPrivate::GraphicsContext3DPrivate(WebKit::WebViewImpl* webViewImpl, PassOwnPtr<WebKit::WebGraphicsContext3D> webContext, GraphicsContext3D::Attributes attrs)
89 , m_webViewImpl(webViewImpl)
90 , m_initializedAvailableExtensions(false)
91 , m_layerComposited(false)
92 , m_preserveDrawingBuffer(attrs.preserveDrawingBuffer)
93 , m_resourceSafety(ResourceSafetyUnknown)
97 , m_renderOutputSize(0)
99 #error Must port to your platform
104 GraphicsContext3DPrivate::~GraphicsContext3DPrivate()
108 m_grContext->contextDestroyed();
109 GrSafeUnref(m_grContext);
115 PassOwnPtr<GraphicsContext3DPrivate> GraphicsContext3DPrivate::create(WebKit::WebViewImpl* webViewImpl, PassOwnPtr<WebKit::WebGraphicsContext3D> webContext, GraphicsContext3D::Attributes attrs)
117 return adoptPtr(new GraphicsContext3DPrivate(webViewImpl, webContext, attrs));
120 PassRefPtr<GraphicsContext3D> GraphicsContext3DPrivate::createGraphicsContextFromWebContext(PassOwnPtr<WebKit::WebGraphicsContext3D> webContext, GraphicsContext3D::Attributes attrs, HostWindow* hostWindow, GraphicsContext3D::RenderStyle renderStyle, ThreadUsage threadUsage)
122 Chrome* chrome = static_cast<Chrome*>(hostWindow);
123 WebKit::WebViewImpl* webViewImpl = chrome ? static_cast<WebKit::WebViewImpl*>(chrome->client()->webView()) : 0;
125 if (threadUsage == ForUseOnThisThread && !webContext->makeContextCurrent())
128 OwnPtr<GraphicsContext3DPrivate> priv = GraphicsContext3DPrivate::create(webViewImpl, webContext, attrs);
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();
140 PassRefPtr<GraphicsContext3D> createGraphicsContext(GraphicsContext3D::Attributes attrs, HostWindow* hostWindow, GraphicsContext3D::RenderStyle renderStyle, GraphicsContext3DPrivate::ThreadUsage threadUsage)
142 bool renderDirectlyToHostWindow = renderStyle == GraphicsContext3D::RenderDirectlyToHostWindow;
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());
157 Chrome* chrome = static_cast<Chrome*>(hostWindow);
158 WebKit::WebViewImpl* webViewImpl = chrome ? static_cast<WebKit::WebViewImpl*>(chrome->client()->webView()) : 0;
160 if (!webContext->initialize(webAttributes, webViewImpl, renderDirectlyToHostWindow))
163 return GraphicsContext3DPrivate::createGraphicsContextFromWebContext(webContext.release(), attrs, hostWindow, renderStyle, threadUsage);
166 void getDrawingParameters(DrawingBuffer* drawingBuffer, WebKit::WebGraphicsContext3D* graphicsContext3D,
167 Platform3DObject* frameBufferId, int* width, int* height)
170 *frameBufferId = drawingBuffer->framebuffer();
171 *width = drawingBuffer->size().width();
172 *height = drawingBuffer->size().height();
175 *width = graphicsContext3D->width();
176 *height = graphicsContext3D->height();
180 } // anonymous namespace
182 PassRefPtr<GraphicsContext3D> GraphicsContext3DPrivate::createGraphicsContextForAnotherThread(GraphicsContext3D::Attributes attrs, HostWindow* hostWindow, GraphicsContext3D::RenderStyle renderStyle)
184 return createGraphicsContext(attrs, hostWindow, renderStyle, ForUseOnAnotherThread);
187 WebKit::WebGraphicsContext3D* GraphicsContext3DPrivate::extractWebGraphicsContext3D(GraphicsContext3D* context)
191 return context->m_private->m_impl.get();
194 PlatformGraphicsContext3D GraphicsContext3DPrivate::platformGraphicsContext3D() const
199 Platform3DObject GraphicsContext3DPrivate::platformTexture() const
201 ASSERT(m_webViewImpl);
202 m_impl->setParentContext(m_webViewImpl->graphicsContext3D());
203 return m_impl->getPlatformTextureId();
207 GrContext* GraphicsContext3DPrivate::grContext()
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;
215 SkAutoTUnref<GrGLInterface> interface(m_impl->createGrGLInterface());
216 m_grContext = GrContext::Create(kOpenGL_Shaders_GrEngine, reinterpret_cast<GrPlatform3DContext>(interface.get()));
218 m_grContext->setTextureCacheLimits(maxTextureCacheCount, maxTextureCacheBytes);
224 void GraphicsContext3DPrivate::prepareTexture()
226 m_impl->prepareTexture();
229 void GraphicsContext3DPrivate::markContextChanged()
231 m_layerComposited = false;
234 void GraphicsContext3DPrivate::markLayerComposited()
236 m_layerComposited = true;
239 bool GraphicsContext3DPrivate::layerComposited() const
241 return m_layerComposited;
244 void GraphicsContext3DPrivate::paintFramebufferToCanvas(int framebuffer, int width, int height, bool premultiplyAlpha, ImageBuffer* imageBuffer)
246 unsigned char* pixels = 0;
247 size_t bufferSize = 4 * width * height;
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();
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,
265 if (!m_resizingBitmap.allocPixels())
268 readbackBitmap = &m_resizingBitmap;
271 // Read back the frame buffer.
272 SkAutoLockPixels bitmapLock(*readbackBitmap);
273 pixels = static_cast<unsigned char*>(readbackBitmap->getPixels());
275 if (!m_renderOutput || m_renderOutputSize != bufferSize) {
276 m_renderOutput = adoptArrayPtr(new unsigned char[bufferSize]);
277 m_renderOutputSize = bufferSize;
280 pixels = m_renderOutput.get();
282 #error Must port to your platform
285 m_impl->readBackFramebuffer(pixels, 4 * width * height, framebuffer, width, height);
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);
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);
301 dst.set(SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(canvasBitmap->width()), SkIntToScalar(canvasBitmap->height()));
302 canvas.drawBitmapRect(m_resizingBitmap, 0, dst);
305 GraphicsContext3D::paintToCanvas(pixels, width, height, imageBuffer->width(), imageBuffer->height(), imageBuffer->context()->platformContext());
307 #error Must port to your platform
311 void GraphicsContext3DPrivate::paintRenderingResultsToCanvas(CanvasRenderingContext* context, DrawingBuffer* drawingBuffer)
313 ImageBuffer* imageBuffer = context->canvas()->buffer();
314 Platform3DObject framebufferId;
316 getDrawingParameters(drawingBuffer, m_impl.get(), &framebufferId, &width, &height);
317 paintFramebufferToCanvas(framebufferId, width, height, !m_impl->getContextAttributes().premultipliedAlpha, imageBuffer);
320 bool GraphicsContext3DPrivate::paintCompositedResultsToCanvas(CanvasRenderingContext* context)
325 PassRefPtr<ImageData> GraphicsContext3DPrivate::paintRenderingResultsToImageData(DrawingBuffer* drawingBuffer)
327 if (m_impl->getContextAttributes().premultipliedAlpha)
330 Platform3DObject framebufferId;
332 getDrawingParameters(drawingBuffer, m_impl.get(), &framebufferId, &width, &height);
334 RefPtr<ImageData> imageData = ImageData::create(IntSize(width, height));
335 unsigned char* pixels = imageData->data()->data()->data();
336 size_t bufferSize = 4 * width * height;
338 m_impl->readBackFramebuffer(pixels, bufferSize, framebufferId, width, height);
340 for (size_t i = 0; i < bufferSize; i += 4)
341 std::swap(pixels[i], pixels[i + 2]);
343 return imageData.release();
346 bool GraphicsContext3DPrivate::paintsIntoCanvasBuffer() const
348 // If the gpu compositor is on then skip the readback and software rendering path.
349 ASSERT(m_webViewImpl);
350 return !m_webViewImpl->isAcceleratedCompositingActive();
353 void GraphicsContext3DPrivate::reshape(int width, int height)
355 if (width == m_impl->width() && height == m_impl->height())
358 m_impl->reshape(width, height);
361 IntSize GraphicsContext3DPrivate::getInternalFramebufferSize() const
363 return IntSize(m_impl->width(), m_impl->height());
366 bool GraphicsContext3DPrivate::isContextLost()
368 return m_impl->isContextLost();
371 // Macros to assist in delegating from GraphicsContext3DPrivate to
372 // WebGraphicsContext3D.
374 #define DELEGATE_TO_IMPL(name) \
375 void GraphicsContext3DPrivate::name() \
380 #define DELEGATE_TO_IMPL_R(name, rt) \
381 rt GraphicsContext3DPrivate::name() \
383 return m_impl->name(); \
386 #define DELEGATE_TO_IMPL_1(name, t1) \
387 void GraphicsContext3DPrivate::name(t1 a1) \
392 #define DELEGATE_TO_IMPL_1R(name, t1, rt) \
393 rt GraphicsContext3DPrivate::name(t1 a1) \
395 return m_impl->name(a1); \
398 #define DELEGATE_TO_IMPL_2(name, t1, t2) \
399 void GraphicsContext3DPrivate::name(t1 a1, t2 a2) \
401 m_impl->name(a1, a2); \
404 #define DELEGATE_TO_IMPL_2R(name, t1, t2, rt) \
405 rt GraphicsContext3DPrivate::name(t1 a1, t2 a2) \
407 return m_impl->name(a1, a2); \
410 #define DELEGATE_TO_IMPL_3(name, t1, t2, t3) \
411 void GraphicsContext3DPrivate::name(t1 a1, t2 a2, t3 a3) \
413 m_impl->name(a1, a2, a3); \
416 #define DELEGATE_TO_IMPL_3R(name, t1, t2, t3, rt) \
417 rt GraphicsContext3DPrivate::name(t1 a1, t2 a2, t3 a3) \
419 return m_impl->name(a1, a2, a3); \
422 #define DELEGATE_TO_IMPL_4(name, t1, t2, t3, t4) \
423 void GraphicsContext3DPrivate::name(t1 a1, t2 a2, t3 a3, t4 a4) \
425 m_impl->name(a1, a2, a3, a4); \
428 #define DELEGATE_TO_IMPL_4R(name, t1, t2, t3, t4, rt) \
429 rt GraphicsContext3DPrivate::name(t1 a1, t2 a2, t3 a3, t4 a4) \
431 return m_impl->name(a1, a2, a3, a4); \
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) \
437 m_impl->name(a1, a2, a3, a4, a5); \
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) \
443 return m_impl->name(a1, a2, a3, a4, a5); \
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) \
449 m_impl->name(a1, a2, a3, a4, a5, a6); \
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) \
455 return m_impl->name(a1, a2, a3, a4, a5, a6); \
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) \
461 m_impl->name(a1, a2, a3, a4, a5, a6, a7); \
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) \
467 return m_impl->name(a1, a2, a3, a4, a5, a6, a7); \
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) \
473 m_impl->name(a1, a2, a3, a4, a5, a6, a7, a8); \
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) \
479 return m_impl->name(a1, a2, a3, a4, a5, a6, a7, a8, a9); \
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) \
485 m_impl->name(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); \
488 DELEGATE_TO_IMPL_R(makeContextCurrent, bool)
490 bool GraphicsContext3DPrivate::isGLES2Compliant() const
492 return m_impl->isGLES2Compliant();
495 DELEGATE_TO_IMPL_1(activeTexture, GC3Denum)
496 DELEGATE_TO_IMPL_2(attachShader, Platform3DObject, Platform3DObject)
498 void GraphicsContext3DPrivate::bindAttribLocation(Platform3DObject program, GC3Duint index, const String& name)
500 m_impl->bindAttribLocation(program, index, name.utf8().data());
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)
513 void GraphicsContext3DPrivate::bufferData(GC3Denum target, GC3Dsizeiptr size, GC3Denum usage)
515 m_impl->bufferData(target, size, 0, usage);
518 void GraphicsContext3DPrivate::bufferData(GC3Denum target, GC3Dsizeiptr size, const void* data, GC3Denum usage)
520 m_impl->bufferData(target, size, data, usage);
523 void GraphicsContext3DPrivate::bufferSubData(GC3Denum target, GC3Dintptr offset, GC3Dsizeiptr size, const void* data)
525 m_impl->bufferSubData(target, offset, size, data);
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)
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)
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)
557 bool GraphicsContext3DPrivate::getActiveAttrib(Platform3DObject program, GC3Duint index, ActiveInfo& info)
559 WebKit::WebGraphicsContext3D::ActiveInfo webInfo;
560 if (!m_impl->getActiveAttrib(program, index, webInfo))
562 info.name = webInfo.name;
563 info.type = webInfo.type;
564 info.size = webInfo.size;
568 bool GraphicsContext3DPrivate::getActiveUniform(Platform3DObject program, GC3Duint index, ActiveInfo& info)
570 WebKit::WebGraphicsContext3D::ActiveInfo webInfo;
571 if (!m_impl->getActiveUniform(program, index, webInfo))
573 info.name = webInfo.name;
574 info.type = webInfo.type;
575 info.size = webInfo.size;
579 DELEGATE_TO_IMPL_4(getAttachedShaders, Platform3DObject, GC3Dsizei, GC3Dsizei*, Platform3DObject*)
581 GC3Dint GraphicsContext3DPrivate::getAttribLocation(Platform3DObject program, const String& name)
583 return m_impl->getAttribLocation(program, name.utf8().data());
586 DELEGATE_TO_IMPL_2(getBooleanv, GC3Denum, GC3Dboolean*)
588 DELEGATE_TO_IMPL_3(getBufferParameteriv, GC3Denum, GC3Denum, GC3Dint*)
590 GraphicsContext3D::Attributes GraphicsContext3DPrivate::getContextAttributes()
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;
603 DELEGATE_TO_IMPL_R(getError, GC3Denum)
605 DELEGATE_TO_IMPL_2(getFloatv, GC3Denum, GC3Dfloat*)
607 DELEGATE_TO_IMPL_4(getFramebufferAttachmentParameteriv, GC3Denum, GC3Denum, GC3Denum, GC3Dint*)
609 DELEGATE_TO_IMPL_2(getIntegerv, GC3Denum, GC3Dint*)
611 DELEGATE_TO_IMPL_3(getProgramiv, Platform3DObject, GC3Denum, GC3Dint*)
613 String GraphicsContext3DPrivate::getProgramInfoLog(Platform3DObject program)
615 return m_impl->getProgramInfoLog(program);
618 DELEGATE_TO_IMPL_3(getRenderbufferParameteriv, GC3Denum, GC3Denum, GC3Dint*)
620 DELEGATE_TO_IMPL_3(getShaderiv, Platform3DObject, GC3Denum, GC3Dint*)
622 String GraphicsContext3DPrivate::getShaderInfoLog(Platform3DObject shader)
624 return m_impl->getShaderInfoLog(shader);
627 String GraphicsContext3DPrivate::getShaderSource(Platform3DObject shader)
629 return m_impl->getShaderSource(shader);
632 String GraphicsContext3DPrivate::getString(GC3Denum name)
634 return m_impl->getString(name);
637 DELEGATE_TO_IMPL_3(getTexParameterfv, GC3Denum, GC3Denum, GC3Dfloat*)
638 DELEGATE_TO_IMPL_3(getTexParameteriv, GC3Denum, GC3Denum, GC3Dint*)
640 DELEGATE_TO_IMPL_3(getUniformfv, Platform3DObject, GC3Dint, GC3Dfloat*)
641 DELEGATE_TO_IMPL_3(getUniformiv, Platform3DObject, GC3Dint, GC3Dint*)
643 GC3Dint GraphicsContext3DPrivate::getUniformLocation(Platform3DObject program, const String& name)
645 return m_impl->getUniformLocation(program, name.utf8().data());
648 DELEGATE_TO_IMPL_3(getVertexAttribfv, GC3Duint, GC3Denum, GC3Dfloat*)
649 DELEGATE_TO_IMPL_3(getVertexAttribiv, GC3Duint, GC3Denum, GC3Dint*)
651 DELEGATE_TO_IMPL_2R(getVertexAttribOffset, GC3Duint, GC3Denum, GC3Dsizeiptr)
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)
671 void GraphicsContext3DPrivate::shaderSource(Platform3DObject shader, const String& string)
673 m_impl->shaderSource(shader, string.utf8().data());
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)
683 bool GraphicsContext3DPrivate::texImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3Denum type, const void* pixels)
685 m_impl->texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
689 DELEGATE_TO_IMPL_3(texParameterf, GC3Denum, GC3Denum, GC3Dfloat)
690 DELEGATE_TO_IMPL_3(texParameteri, GC3Denum, GC3Denum, GC3Dint)
692 void GraphicsContext3DPrivate::texSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, const void* pixels)
694 m_impl->texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
697 DELEGATE_TO_IMPL_2(uniform1f, GC3Dint, GC3Dfloat)
699 void GraphicsContext3DPrivate::uniform1fv(GC3Dint location, GC3Dfloat* v, GC3Dsizei size)
701 m_impl->uniform1fv(location, size, v);
704 DELEGATE_TO_IMPL_2(uniform1i, GC3Dint, GC3Dint)
706 void GraphicsContext3DPrivate::uniform1iv(GC3Dint location, GC3Dint* v, GC3Dsizei size)
708 m_impl->uniform1iv(location, size, v);
711 DELEGATE_TO_IMPL_3(uniform2f, GC3Dint, GC3Dfloat, GC3Dfloat)
713 void GraphicsContext3DPrivate::uniform2fv(GC3Dint location, GC3Dfloat* v, GC3Dsizei size)
715 m_impl->uniform2fv(location, size, v);
718 DELEGATE_TO_IMPL_3(uniform2i, GC3Dint, GC3Dint, GC3Dint)
720 void GraphicsContext3DPrivate::uniform2iv(GC3Dint location, GC3Dint* v, GC3Dsizei size)
722 m_impl->uniform2iv(location, size, v);
725 DELEGATE_TO_IMPL_4(uniform3f, GC3Dint, GC3Dfloat, GC3Dfloat, GC3Dfloat)
727 void GraphicsContext3DPrivate::uniform3fv(GC3Dint location, GC3Dfloat* v, GC3Dsizei size)
729 m_impl->uniform3fv(location, size, v);
732 DELEGATE_TO_IMPL_4(uniform3i, GC3Dint, GC3Dint, GC3Dint, GC3Dint)
734 void GraphicsContext3DPrivate::uniform3iv(GC3Dint location, GC3Dint* v, GC3Dsizei size)
736 m_impl->uniform3iv(location, size, v);
739 DELEGATE_TO_IMPL_5(uniform4f, GC3Dint, GC3Dfloat, GC3Dfloat, GC3Dfloat, GC3Dfloat)
741 void GraphicsContext3DPrivate::uniform4fv(GC3Dint location, GC3Dfloat* v, GC3Dsizei size)
743 m_impl->uniform4fv(location, size, v);
746 DELEGATE_TO_IMPL_5(uniform4i, GC3Dint, GC3Dint, GC3Dint, GC3Dint, GC3Dint)
748 void GraphicsContext3DPrivate::uniform4iv(GC3Dint location, GC3Dint* v, GC3Dsizei size)
750 m_impl->uniform4iv(location, size, v);
753 void GraphicsContext3DPrivate::uniformMatrix2fv(GC3Dint location, GC3Dboolean transpose, GC3Dfloat* value, GC3Dsizei size)
755 m_impl->uniformMatrix2fv(location, size, transpose, value);
758 void GraphicsContext3DPrivate::uniformMatrix3fv(GC3Dint location, GC3Dboolean transpose, GC3Dfloat* value, GC3Dsizei size)
760 m_impl->uniformMatrix3fv(location, size, transpose, value);
763 void GraphicsContext3DPrivate::uniformMatrix4fv(GC3Dint location, GC3Dboolean transpose, GC3Dfloat* value, GC3Dsizei size)
765 m_impl->uniformMatrix4fv(location, size, transpose, value);
768 DELEGATE_TO_IMPL_1(useProgram, Platform3DObject)
769 DELEGATE_TO_IMPL_1(validateProgram, Platform3DObject)
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)
781 DELEGATE_TO_IMPL_4(viewport, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei)
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)
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)
797 DELEGATE_TO_IMPL_1(synthesizeGLError, GC3Denum)
799 Extensions3D* GraphicsContext3DPrivate::getExtensions()
802 m_extensions = adoptPtr(new Extensions3DChromium(this));
803 return m_extensions.get();
806 bool GraphicsContext3DPrivate::isResourceSafe()
808 if (m_resourceSafety == ResourceSafetyUnknown)
809 m_resourceSafety = getExtensions()->isEnabled("GL_CHROMIUM_resource_safe") ? ResourceSafe : ResourceUnsafe;
810 return m_resourceSafety == ResourceSafe;
815 void splitStringHelper(const String& str, HashSet<String>& set)
817 Vector<String> substrings;
818 str.split(" ", substrings);
819 for (size_t i = 0; i < substrings.size(); ++i)
820 set.add(substrings[i]);
823 String mapExtensionName(const String& name)
825 if (name == "GL_ANGLE_framebuffer_blit"
826 || name == "GL_ANGLE_framebuffer_multisample")
827 return "GL_CHROMIUM_framebuffer_multisample";
831 } // anonymous namespace
833 void GraphicsContext3DPrivate::initializeExtensions()
835 if (m_initializedAvailableExtensions)
838 m_initializedAvailableExtensions = true;
839 bool success = makeContextCurrent();
844 String extensionsString = getString(GraphicsContext3D::EXTENSIONS);
845 splitStringHelper(extensionsString, m_enabledExtensions);
847 String requestableExtensionsString = m_impl->getRequestableExtensionsCHROMIUM();
848 splitStringHelper(requestableExtensionsString, m_requestableExtensions);
852 bool GraphicsContext3DPrivate::supportsExtension(const String& name)
854 initializeExtensions();
855 String mappedName = mapExtensionName(name);
856 return m_enabledExtensions.contains(mappedName) || m_requestableExtensions.contains(mappedName);
859 bool GraphicsContext3DPrivate::ensureExtensionEnabled(const String& name)
861 initializeExtensions();
863 String mappedName = mapExtensionName(name);
864 if (m_enabledExtensions.contains(mappedName))
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;
874 initializeExtensions();
875 return m_enabledExtensions.contains(mappedName);
878 bool GraphicsContext3DPrivate::isExtensionEnabled(const String& name)
880 initializeExtensions();
881 String mappedName = mapExtensionName(name);
882 return m_enabledExtensions.contains(mappedName);
885 DELEGATE_TO_IMPL_4(postSubBufferCHROMIUM, int, int, int, int)
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*)
892 DELEGATE_TO_IMPL_1(setVisibilityCHROMIUM, bool);
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)
897 DELEGATE_TO_IMPL(rateLimitOffscreenContextCHROMIUM)
898 DELEGATE_TO_IMPL_R(getGraphicsResetStatusARB, GC3Denum)
900 DELEGATE_TO_IMPL_1R(getTranslatedShaderSourceANGLE, Platform3DObject, String)
901 DELEGATE_TO_IMPL_5(texImageIOSurface2DCHROMIUM, GC3Denum, GC3Dint, GC3Dint, GC3Duint, GC3Duint)
903 //----------------------------------------------------------------------
907 // Macros to assist in delegating from GraphicsContext3D to
908 // GraphicsContext3DPrivate.
910 #define DELEGATE_TO_INTERNAL(name) \
911 void GraphicsContext3D::name() \
916 #define DELEGATE_TO_INTERNAL_R(name, rt) \
917 rt GraphicsContext3D::name() \
919 return m_private->name(); \
922 #define DELEGATE_TO_INTERNAL_1(name, t1) \
923 void GraphicsContext3D::name(t1 a1) \
925 m_private->name(a1); \
928 #define DELEGATE_TO_INTERNAL_1R(name, t1, rt) \
929 rt GraphicsContext3D::name(t1 a1) \
931 return m_private->name(a1); \
934 #define DELEGATE_TO_INTERNAL_2(name, t1, t2) \
935 void GraphicsContext3D::name(t1 a1, t2 a2) \
937 m_private->name(a1, a2); \
940 #define DELEGATE_TO_INTERNAL_2R(name, t1, t2, rt) \
941 rt GraphicsContext3D::name(t1 a1, t2 a2) \
943 return m_private->name(a1, a2); \
946 #define DELEGATE_TO_INTERNAL_3(name, t1, t2, t3) \
947 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3) \
949 m_private->name(a1, a2, a3); \
952 #define DELEGATE_TO_INTERNAL_3R(name, t1, t2, t3, rt) \
953 rt GraphicsContext3D::name(t1 a1, t2 a2, t3 a3) \
955 return m_private->name(a1, a2, a3); \
958 #define DELEGATE_TO_INTERNAL_4(name, t1, t2, t3, t4) \
959 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4) \
961 m_private->name(a1, a2, a3, a4); \
964 #define DELEGATE_TO_INTERNAL_4R(name, t1, t2, t3, t4, rt) \
965 rt GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4) \
967 return m_private->name(a1, a2, a3, a4); \
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) \
973 m_private->name(a1, a2, a3, a4, a5); \
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) \
979 m_private->name(a1, a2, a3, a4, a5, a6); \
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) \
985 return m_private->name(a1, a2, a3, a4, a5, a6); \
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) \
991 m_private->name(a1, a2, a3, a4, a5, a6, a7); \
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) \
997 return m_private->name(a1, a2, a3, a4, a5, a6, a7); \
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) \
1003 m_private->name(a1, a2, a3, a4, a5, a6, a7, a8); \
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) \
1009 m_private->name(a1, a2, a3, a4, a5, a6, a7, a8, a9); \
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) \
1015 return m_private->name(a1, a2, a3, a4, a5, a6, a7, a8, a9); \
1018 GraphicsContext3D::GraphicsContext3D(GraphicsContext3D::Attributes, HostWindow*, bool)
1022 GraphicsContext3D::~GraphicsContext3D()
1024 m_private->setContextLostCallback(nullptr);
1025 m_private->setSwapBuffersCompleteCallbackCHROMIUM(nullptr);
1028 PassRefPtr<GraphicsContext3D> GraphicsContext3D::create(GraphicsContext3D::Attributes attrs, HostWindow* hostWindow, GraphicsContext3D::RenderStyle renderStyle)
1030 return createGraphicsContext(attrs, hostWindow, renderStyle, GraphicsContext3DPrivate::ForUseOnThisThread);
1033 PlatformGraphicsContext3D GraphicsContext3D::platformGraphicsContext3D() const
1035 return m_private->platformGraphicsContext3D();
1038 Platform3DObject GraphicsContext3D::platformTexture() const
1040 return m_private->platformTexture();
1044 GrContext* GraphicsContext3D::grContext()
1046 return m_private->grContext();
1050 void GraphicsContext3D::prepareTexture()
1052 return m_private->prepareTexture();
1055 IntSize GraphicsContext3D::getInternalFramebufferSize() const
1057 return m_private->getInternalFramebufferSize();
1060 bool GraphicsContext3D::isResourceSafe()
1062 return m_private->isResourceSafe();
1065 #if USE(ACCELERATED_COMPOSITING)
1066 PlatformLayer* GraphicsContext3D::platformLayer() const
1072 DELEGATE_TO_INTERNAL_R(makeContextCurrent, bool)
1073 DELEGATE_TO_INTERNAL_2(reshape, int, int)
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&)
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)
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*)
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)
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)
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)
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)
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)
1162 DELEGATE_TO_INTERNAL_7(readPixels, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei, GC3Denum, GC3Denum, void*)
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)
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*)
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)
1201 DELEGATE_TO_INTERNAL_1(useProgram, Platform3DObject)
1202 DELEGATE_TO_INTERNAL_1(validateProgram, Platform3DObject)
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)
1214 DELEGATE_TO_INTERNAL_4(viewport, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei)
1216 DELEGATE_TO_INTERNAL(markLayerComposited)
1217 DELEGATE_TO_INTERNAL(markContextChanged)
1219 bool GraphicsContext3D::layerComposited() const
1221 return m_private->layerComposited();
1224 void GraphicsContext3D::paintRenderingResultsToCanvas(CanvasRenderingContext* context, DrawingBuffer* drawingBuffer)
1226 return m_private->paintRenderingResultsToCanvas(context, drawingBuffer);
1229 PassRefPtr<ImageData> GraphicsContext3D::paintRenderingResultsToImageData(DrawingBuffer* drawingBuffer)
1231 return m_private->paintRenderingResultsToImageData(drawingBuffer);
1234 DELEGATE_TO_INTERNAL_1R(paintCompositedResultsToCanvas, CanvasRenderingContext*, bool)
1236 bool GraphicsContext3D::paintsIntoCanvasBuffer() const
1238 return m_private->paintsIntoCanvasBuffer();
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)
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)
1255 DELEGATE_TO_INTERNAL_1(synthesizeGLError, GC3Denum)
1256 DELEGATE_TO_INTERNAL_R(getExtensions, Extensions3D*)
1258 DELEGATE_TO_INTERNAL_1(setContextLostCallback, PassOwnPtr<GraphicsContext3D::ContextLostCallback>)
1260 class GraphicsContextLostCallbackAdapter : public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback {
1262 virtual void onContextLost();
1263 static PassOwnPtr<GraphicsContextLostCallbackAdapter> create(PassOwnPtr<GraphicsContext3D::ContextLostCallback>);
1264 virtual ~GraphicsContextLostCallbackAdapter() { }
1266 GraphicsContextLostCallbackAdapter(PassOwnPtr<GraphicsContext3D::ContextLostCallback> cb) : m_contextLostCallback(cb) { }
1267 OwnPtr<GraphicsContext3D::ContextLostCallback> m_contextLostCallback;
1270 void GraphicsContextLostCallbackAdapter::onContextLost()
1272 if (m_contextLostCallback)
1273 m_contextLostCallback->onContextLost();
1276 PassOwnPtr<GraphicsContextLostCallbackAdapter> GraphicsContextLostCallbackAdapter::create(PassOwnPtr<GraphicsContext3D::ContextLostCallback> cb)
1278 return adoptPtr(cb.get() ? new GraphicsContextLostCallbackAdapter(cb) : 0);
1281 void GraphicsContext3DPrivate::setContextLostCallback(PassOwnPtr<GraphicsContext3D::ContextLostCallback> cb)
1283 m_contextLostCallbackAdapter = GraphicsContextLostCallbackAdapter::create(cb);
1284 m_impl->setContextLostCallback(m_contextLostCallbackAdapter.get());
1287 bool GraphicsContext3D::isGLES2Compliant() const
1289 return m_private->isGLES2Compliant();
1292 class GraphicsContext3DSwapBuffersCompleteCallbackAdapter : public WebKit::WebGraphicsContext3D::WebGraphicsSwapBuffersCompleteCallbackCHROMIUM {
1294 virtual void onSwapBuffersComplete();
1295 static PassOwnPtr<GraphicsContext3DSwapBuffersCompleteCallbackAdapter> create(PassOwnPtr<Extensions3DChromium::SwapBuffersCompleteCallbackCHROMIUM>);
1296 virtual ~GraphicsContext3DSwapBuffersCompleteCallbackAdapter() { }
1299 GraphicsContext3DSwapBuffersCompleteCallbackAdapter(PassOwnPtr<Extensions3DChromium::SwapBuffersCompleteCallbackCHROMIUM> cb) : m_swapBuffersCompleteCallback(cb) { }
1300 OwnPtr<Extensions3DChromium::SwapBuffersCompleteCallbackCHROMIUM> m_swapBuffersCompleteCallback;
1303 void GraphicsContext3DSwapBuffersCompleteCallbackAdapter::onSwapBuffersComplete()
1305 if (m_swapBuffersCompleteCallback)
1306 m_swapBuffersCompleteCallback->onSwapBuffersComplete();
1309 PassOwnPtr<GraphicsContext3DSwapBuffersCompleteCallbackAdapter> GraphicsContext3DSwapBuffersCompleteCallbackAdapter::create(PassOwnPtr<Extensions3DChromium::SwapBuffersCompleteCallbackCHROMIUM> cb)
1311 return adoptPtr(cb.get() ? new GraphicsContext3DSwapBuffersCompleteCallbackAdapter(cb) : 0);
1314 void GraphicsContext3DPrivate::setSwapBuffersCompleteCallbackCHROMIUM(PassOwnPtr<Extensions3DChromium::SwapBuffersCompleteCallbackCHROMIUM> cb)
1316 m_swapBuffersCompleteCallbackAdapter = GraphicsContext3DSwapBuffersCompleteCallbackAdapter::create(cb);
1317 m_impl->setSwapBuffersCompleteCallbackCHROMIUM(m_swapBuffersCompleteCallbackAdapter.get());
1320 } // namespace WebCore
1322 #endif // ENABLE(WEBGL)