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 "WebGLLayerChromium.h"
39 #include "CanvasRenderingContext.h"
41 #include "ChromeClientImpl.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
102 #if USE(ACCELERATED_COMPOSITING)
103 m_compositingLayer = WebGLLayerChromium::create(0);
107 GraphicsContext3DPrivate::~GraphicsContext3DPrivate()
111 m_grContext->contextDestroyed();
112 GrSafeUnref(m_grContext);
118 PassOwnPtr<GraphicsContext3DPrivate> GraphicsContext3DPrivate::create(WebKit::WebViewImpl* webViewImpl, PassOwnPtr<WebKit::WebGraphicsContext3D> webContext, GraphicsContext3D::Attributes attrs)
120 return adoptPtr(new GraphicsContext3DPrivate(webViewImpl, webContext, attrs));
123 PassRefPtr<GraphicsContext3D> GraphicsContext3DPrivate::createGraphicsContextFromWebContext(PassOwnPtr<WebKit::WebGraphicsContext3D> webContext, GraphicsContext3D::Attributes attrs, HostWindow* hostWindow, GraphicsContext3D::RenderStyle renderStyle, ThreadUsage threadUsage)
125 Chrome* chrome = static_cast<Chrome*>(hostWindow);
126 WebKit::WebViewImpl* webViewImpl = chrome ? static_cast<WebKit::WebViewImpl*>(chrome->client()->webView()) : 0;
128 if (threadUsage == ForUseOnThisThread && !webContext->makeContextCurrent())
131 OwnPtr<GraphicsContext3DPrivate> priv = GraphicsContext3DPrivate::create(webViewImpl, webContext, attrs);
135 bool renderDirectlyToHostWindow = renderStyle == GraphicsContext3D::RenderDirectlyToHostWindow;
136 RefPtr<GraphicsContext3D> result = adoptRef(new GraphicsContext3D(attrs, hostWindow, renderDirectlyToHostWindow));
137 result->m_private = priv.release();
138 return result.release();
143 PassRefPtr<GraphicsContext3D> createGraphicsContext(GraphicsContext3D::Attributes attrs, HostWindow* hostWindow, GraphicsContext3D::RenderStyle renderStyle, GraphicsContext3DPrivate::ThreadUsage threadUsage)
145 bool renderDirectlyToHostWindow = renderStyle == GraphicsContext3D::RenderDirectlyToHostWindow;
147 WebKit::WebGraphicsContext3D::Attributes webAttributes;
148 webAttributes.alpha = attrs.alpha;
149 webAttributes.depth = attrs.depth;
150 webAttributes.stencil = attrs.stencil;
151 webAttributes.antialias = attrs.antialias;
152 webAttributes.premultipliedAlpha = attrs.premultipliedAlpha;
153 webAttributes.canRecoverFromContextLoss = attrs.canRecoverFromContextLoss;
154 webAttributes.noExtensions = attrs.noExtensions;
155 webAttributes.shareResources = attrs.shareResources;
156 OwnPtr<WebKit::WebGraphicsContext3D> webContext = adoptPtr(WebKit::webKitPlatformSupport()->createGraphicsContext3D());
160 Chrome* chrome = static_cast<Chrome*>(hostWindow);
161 WebKit::WebViewImpl* webViewImpl = chrome ? static_cast<WebKit::WebViewImpl*>(chrome->client()->webView()) : 0;
163 if (!webContext->initialize(webAttributes, webViewImpl, renderDirectlyToHostWindow))
166 return GraphicsContext3DPrivate::createGraphicsContextFromWebContext(webContext.release(), attrs, hostWindow, renderStyle, threadUsage);
169 } // anonymous namespace
171 PassRefPtr<GraphicsContext3D> GraphicsContext3DPrivate::createGraphicsContextForAnotherThread(GraphicsContext3D::Attributes attrs, HostWindow* hostWindow, GraphicsContext3D::RenderStyle renderStyle)
173 return createGraphicsContext(attrs, hostWindow, renderStyle, ForUseOnAnotherThread);
176 WebKit::WebGraphicsContext3D* GraphicsContext3DPrivate::extractWebGraphicsContext3D(GraphicsContext3D* context)
180 return context->m_private->m_impl.get();
183 PlatformGraphicsContext3D GraphicsContext3DPrivate::platformGraphicsContext3D() const
188 Platform3DObject GraphicsContext3DPrivate::platformTexture() const
190 ASSERT(m_webViewImpl);
191 m_impl->setParentContext(m_webViewImpl->graphicsContext3D());
192 return m_impl->getPlatformTextureId();
196 GrContext* GraphicsContext3DPrivate::grContext()
198 // Limit the number of textures we hold in the bitmap->texture cache.
199 static const int maxTextureCacheCount = 512;
200 // Limit the bytes allocated toward textures in the bitmap->texture cache.
201 static const size_t maxTextureCacheBytes = 50 * 1024 * 1024;
204 SkAutoTUnref<GrGLInterface> interface(m_impl->createGrGLInterface());
205 m_grContext = GrContext::Create(kOpenGL_Shaders_GrEngine, reinterpret_cast<GrPlatform3DContext>(interface.get()));
207 m_grContext->setTextureCacheLimits(maxTextureCacheCount, maxTextureCacheBytes);
213 void GraphicsContext3DPrivate::prepareTexture()
215 m_impl->prepareTexture();
218 #if USE(ACCELERATED_COMPOSITING)
219 WebGLLayerChromium* GraphicsContext3DPrivate::platformLayer() const
221 return m_compositingLayer.get();
225 void GraphicsContext3DPrivate::markContextChanged()
227 #if USE(ACCELERATED_COMPOSITING)
228 platformLayer()->setTextureUpdated();
230 m_layerComposited = false;
233 void GraphicsContext3DPrivate::markLayerComposited()
235 m_layerComposited = true;
238 bool GraphicsContext3DPrivate::layerComposited() const
240 return m_layerComposited;
243 void GraphicsContext3DPrivate::paintFramebufferToCanvas(int framebuffer, int width, int height, bool premultiplyAlpha, ImageBuffer* imageBuffer)
245 unsigned char* pixels = 0;
246 size_t bufferSize = 4 * width * height;
248 const SkBitmap* canvasBitmap = imageBuffer->context()->platformContext()->bitmap();
249 const SkBitmap* readbackBitmap = 0;
250 ASSERT(canvasBitmap->config() == SkBitmap::kARGB_8888_Config);
251 if (canvasBitmap->width() == width && canvasBitmap->height() == height) {
252 // This is the fastest and most common case. We read back
253 // directly into the canvas's backing store.
254 readbackBitmap = canvasBitmap;
255 m_resizingBitmap.reset();
257 // We need to allocate a temporary bitmap for reading back the
258 // pixel data. We will then use Skia to rescale this bitmap to
259 // the size of the canvas's backing store.
260 if (m_resizingBitmap.width() != width || m_resizingBitmap.height() != height) {
261 m_resizingBitmap.setConfig(SkBitmap::kARGB_8888_Config,
264 if (!m_resizingBitmap.allocPixels())
267 readbackBitmap = &m_resizingBitmap;
270 // Read back the frame buffer.
271 SkAutoLockPixels bitmapLock(*readbackBitmap);
272 pixels = static_cast<unsigned char*>(readbackBitmap->getPixels());
274 if (!m_renderOutput || m_renderOutputSize != bufferSize) {
275 m_renderOutput = adoptArrayPtr(new unsigned char[bufferSize]);
276 m_renderOutputSize = bufferSize;
279 pixels = m_renderOutput.get();
281 #error Must port to your platform
284 m_impl->readBackFramebuffer(pixels, 4 * width * height, framebuffer, width, height);
286 if (premultiplyAlpha) {
287 for (size_t i = 0; i < bufferSize; i += 4) {
288 pixels[i + 0] = std::min(255, pixels[i + 0] * pixels[i + 3] / 255);
289 pixels[i + 1] = std::min(255, pixels[i + 1] * pixels[i + 3] / 255);
290 pixels[i + 2] = std::min(255, pixels[i + 2] * pixels[i + 3] / 255);
295 readbackBitmap->notifyPixelsChanged();
296 if (m_resizingBitmap.readyToDraw()) {
297 // We need to draw the resizing bitmap into the canvas's backing store.
298 SkCanvas canvas(*canvasBitmap);
300 dst.set(SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(canvasBitmap->width()), SkIntToScalar(canvasBitmap->height()));
301 canvas.drawBitmapRect(m_resizingBitmap, 0, dst);
304 GraphicsContext3D::paintToCanvas(pixels, width, height, imageBuffer->width(), imageBuffer->height(), imageBuffer->context()->platformContext());
306 #error Must port to your platform
310 void GraphicsContext3DPrivate::paintRenderingResultsToCanvas(CanvasRenderingContext* context)
312 ImageBuffer* imageBuffer = context->canvas()->buffer();
313 paintFramebufferToCanvas(0, m_impl->width(), m_impl->height(), !m_impl->getContextAttributes().premultipliedAlpha, imageBuffer);
316 bool GraphicsContext3DPrivate::paintCompositedResultsToCanvas(CanvasRenderingContext* context)
318 #if USE(ACCELERATED_COMPOSITING)
320 return platformLayer()->paintRenderedResultsToCanvas(context->canvas()->buffer());
325 PassRefPtr<ImageData> GraphicsContext3DPrivate::paintRenderingResultsToImageData()
327 if (m_impl->getContextAttributes().premultipliedAlpha)
330 RefPtr<ImageData> imageData = ImageData::create(IntSize(m_impl->width(), m_impl->height()));
331 unsigned char* pixels = imageData->data()->data()->data();
332 size_t bufferSize = 4 * m_impl->width() * m_impl->height();
334 m_impl->readBackFramebuffer(pixels, bufferSize, 0, m_impl->width(), m_impl->height());
336 for (size_t i = 0; i < bufferSize; i += 4)
337 std::swap(pixels[i], pixels[i + 2]);
339 return imageData.release();
342 bool GraphicsContext3DPrivate::paintsIntoCanvasBuffer() const
344 // If the gpu compositor is on then skip the readback and software rendering path.
345 ASSERT(m_webViewImpl);
346 return !m_webViewImpl->isAcceleratedCompositingActive();
349 void GraphicsContext3DPrivate::reshape(int width, int height)
351 if (width == m_impl->width() && height == m_impl->height())
354 m_impl->reshape(width, height);
357 IntSize GraphicsContext3DPrivate::getInternalFramebufferSize() const
359 return IntSize(m_impl->width(), m_impl->height());
362 bool GraphicsContext3DPrivate::isContextLost()
364 return m_impl->isContextLost();
367 // Macros to assist in delegating from GraphicsContext3DPrivate to
368 // WebGraphicsContext3D.
370 #define DELEGATE_TO_IMPL(name) \
371 void GraphicsContext3DPrivate::name() \
376 #define DELEGATE_TO_IMPL_R(name, rt) \
377 rt GraphicsContext3DPrivate::name() \
379 return m_impl->name(); \
382 #define DELEGATE_TO_IMPL_1(name, t1) \
383 void GraphicsContext3DPrivate::name(t1 a1) \
388 #define DELEGATE_TO_IMPL_1R(name, t1, rt) \
389 rt GraphicsContext3DPrivate::name(t1 a1) \
391 return m_impl->name(a1); \
394 #define DELEGATE_TO_IMPL_2(name, t1, t2) \
395 void GraphicsContext3DPrivate::name(t1 a1, t2 a2) \
397 m_impl->name(a1, a2); \
400 #define DELEGATE_TO_IMPL_2R(name, t1, t2, rt) \
401 rt GraphicsContext3DPrivate::name(t1 a1, t2 a2) \
403 return m_impl->name(a1, a2); \
406 #define DELEGATE_TO_IMPL_3(name, t1, t2, t3) \
407 void GraphicsContext3DPrivate::name(t1 a1, t2 a2, t3 a3) \
409 m_impl->name(a1, a2, a3); \
412 #define DELEGATE_TO_IMPL_3R(name, t1, t2, t3, rt) \
413 rt GraphicsContext3DPrivate::name(t1 a1, t2 a2, t3 a3) \
415 return m_impl->name(a1, a2, a3); \
418 #define DELEGATE_TO_IMPL_4(name, t1, t2, t3, t4) \
419 void GraphicsContext3DPrivate::name(t1 a1, t2 a2, t3 a3, t4 a4) \
421 m_impl->name(a1, a2, a3, a4); \
424 #define DELEGATE_TO_IMPL_4R(name, t1, t2, t3, t4, rt) \
425 rt GraphicsContext3DPrivate::name(t1 a1, t2 a2, t3 a3, t4 a4) \
427 return m_impl->name(a1, a2, a3, a4); \
430 #define DELEGATE_TO_IMPL_5(name, t1, t2, t3, t4, t5) \
431 void GraphicsContext3DPrivate::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) \
433 m_impl->name(a1, a2, a3, a4, a5); \
436 #define DELEGATE_TO_IMPL_5R(name, t1, t2, t3, t4, t5, rt) \
437 rt GraphicsContext3DPrivate::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) \
439 return m_impl->name(a1, a2, a3, a4, a5); \
442 #define DELEGATE_TO_IMPL_6(name, t1, t2, t3, t4, t5, t6) \
443 void GraphicsContext3DPrivate::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6) \
445 m_impl->name(a1, a2, a3, a4, a5, a6); \
448 #define DELEGATE_TO_IMPL_6R(name, t1, t2, t3, t4, t5, t6, rt) \
449 rt GraphicsContext3DPrivate::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6) \
451 return m_impl->name(a1, a2, a3, a4, a5, a6); \
454 #define DELEGATE_TO_IMPL_7(name, t1, t2, t3, t4, t5, t6, t7) \
455 void GraphicsContext3DPrivate::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7) \
457 m_impl->name(a1, a2, a3, a4, a5, a6, a7); \
460 #define DELEGATE_TO_IMPL_7R(name, t1, t2, t3, t4, t5, t6, t7, rt) \
461 rt GraphicsContext3DPrivate::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7) \
463 return m_impl->name(a1, a2, a3, a4, a5, a6, a7); \
466 #define DELEGATE_TO_IMPL_8(name, t1, t2, t3, t4, t5, t6, t7, t8) \
467 void GraphicsContext3DPrivate::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8 a8) \
469 m_impl->name(a1, a2, a3, a4, a5, a6, a7, a8); \
472 #define DELEGATE_TO_IMPL_9R(name, t1, t2, t3, t4, t5, t6, t7, t8, t9, rt) \
473 rt GraphicsContext3DPrivate::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8 a8, t9 a9) \
475 return m_impl->name(a1, a2, a3, a4, a5, a6, a7, a8, a9); \
478 #define DELEGATE_TO_IMPL_10(name, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10) \
479 void GraphicsContext3DPrivate::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8 a8, t9 a9, t10 a10) \
481 m_impl->name(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); \
484 DELEGATE_TO_IMPL_R(makeContextCurrent, bool)
486 bool GraphicsContext3DPrivate::isGLES2Compliant() const
488 return m_impl->isGLES2Compliant();
491 DELEGATE_TO_IMPL_1(activeTexture, GC3Denum)
492 DELEGATE_TO_IMPL_2(attachShader, Platform3DObject, Platform3DObject)
494 void GraphicsContext3DPrivate::bindAttribLocation(Platform3DObject program, GC3Duint index, const String& name)
496 m_impl->bindAttribLocation(program, index, name.utf8().data());
499 DELEGATE_TO_IMPL_2(bindBuffer, GC3Denum, Platform3DObject)
500 DELEGATE_TO_IMPL_2(bindFramebuffer, GC3Denum, Platform3DObject)
501 DELEGATE_TO_IMPL_2(bindRenderbuffer, GC3Denum, Platform3DObject)
502 DELEGATE_TO_IMPL_2(bindTexture, GC3Denum, Platform3DObject)
503 DELEGATE_TO_IMPL_4(blendColor, GC3Dclampf, GC3Dclampf, GC3Dclampf, GC3Dclampf)
504 DELEGATE_TO_IMPL_1(blendEquation, GC3Denum)
505 DELEGATE_TO_IMPL_2(blendEquationSeparate, GC3Denum, GC3Denum)
506 DELEGATE_TO_IMPL_2(blendFunc, GC3Denum, GC3Denum)
507 DELEGATE_TO_IMPL_4(blendFuncSeparate, GC3Denum, GC3Denum, GC3Denum, GC3Denum)
509 void GraphicsContext3DPrivate::bufferData(GC3Denum target, GC3Dsizeiptr size, GC3Denum usage)
511 m_impl->bufferData(target, size, 0, usage);
514 void GraphicsContext3DPrivate::bufferData(GC3Denum target, GC3Dsizeiptr size, const void* data, GC3Denum usage)
516 m_impl->bufferData(target, size, data, usage);
519 void GraphicsContext3DPrivate::bufferSubData(GC3Denum target, GC3Dintptr offset, GC3Dsizeiptr size, const void* data)
521 m_impl->bufferSubData(target, offset, size, data);
524 DELEGATE_TO_IMPL_1R(checkFramebufferStatus, GC3Denum, GC3Denum)
525 DELEGATE_TO_IMPL_1(clear, GC3Dbitfield)
526 DELEGATE_TO_IMPL_4(clearColor, GC3Dclampf, GC3Dclampf, GC3Dclampf, GC3Dclampf)
527 DELEGATE_TO_IMPL_1(clearDepth, GC3Dclampf)
528 DELEGATE_TO_IMPL_1(clearStencil, GC3Dint)
529 DELEGATE_TO_IMPL_4(colorMask, GC3Dboolean, GC3Dboolean, GC3Dboolean, GC3Dboolean)
530 DELEGATE_TO_IMPL_1(compileShader, Platform3DObject)
532 DELEGATE_TO_IMPL_8(copyTexImage2D, GC3Denum, GC3Dint, GC3Denum, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei, GC3Dint)
533 DELEGATE_TO_IMPL_8(copyTexSubImage2D, GC3Denum, GC3Dint, GC3Dint, GC3Dint, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei)
534 DELEGATE_TO_IMPL_1(cullFace, GC3Denum)
535 DELEGATE_TO_IMPL_1(depthFunc, GC3Denum)
536 DELEGATE_TO_IMPL_1(depthMask, GC3Dboolean)
537 DELEGATE_TO_IMPL_2(depthRange, GC3Dclampf, GC3Dclampf)
538 DELEGATE_TO_IMPL_2(detachShader, Platform3DObject, Platform3DObject)
539 DELEGATE_TO_IMPL_1(disable, GC3Denum)
540 DELEGATE_TO_IMPL_1(disableVertexAttribArray, GC3Duint)
541 DELEGATE_TO_IMPL_3(drawArrays, GC3Denum, GC3Dint, GC3Dsizei)
542 DELEGATE_TO_IMPL_4(drawElements, GC3Denum, GC3Dsizei, GC3Denum, GC3Dsizeiptr)
544 DELEGATE_TO_IMPL_1(enable, GC3Denum)
545 DELEGATE_TO_IMPL_1(enableVertexAttribArray, GC3Duint)
546 DELEGATE_TO_IMPL(finish)
547 DELEGATE_TO_IMPL(flush)
548 DELEGATE_TO_IMPL_4(framebufferRenderbuffer, GC3Denum, GC3Denum, GC3Denum, Platform3DObject)
549 DELEGATE_TO_IMPL_5(framebufferTexture2D, GC3Denum, GC3Denum, GC3Denum, Platform3DObject, GC3Dint)
550 DELEGATE_TO_IMPL_1(frontFace, GC3Denum)
551 DELEGATE_TO_IMPL_1(generateMipmap, GC3Denum)
553 bool GraphicsContext3DPrivate::getActiveAttrib(Platform3DObject program, GC3Duint index, ActiveInfo& info)
555 WebKit::WebGraphicsContext3D::ActiveInfo webInfo;
556 if (!m_impl->getActiveAttrib(program, index, webInfo))
558 info.name = webInfo.name;
559 info.type = webInfo.type;
560 info.size = webInfo.size;
564 bool GraphicsContext3DPrivate::getActiveUniform(Platform3DObject program, GC3Duint index, ActiveInfo& info)
566 WebKit::WebGraphicsContext3D::ActiveInfo webInfo;
567 if (!m_impl->getActiveUniform(program, index, webInfo))
569 info.name = webInfo.name;
570 info.type = webInfo.type;
571 info.size = webInfo.size;
575 DELEGATE_TO_IMPL_4(getAttachedShaders, Platform3DObject, GC3Dsizei, GC3Dsizei*, Platform3DObject*)
577 GC3Dint GraphicsContext3DPrivate::getAttribLocation(Platform3DObject program, const String& name)
579 return m_impl->getAttribLocation(program, name.utf8().data());
582 DELEGATE_TO_IMPL_2(getBooleanv, GC3Denum, GC3Dboolean*)
584 DELEGATE_TO_IMPL_3(getBufferParameteriv, GC3Denum, GC3Denum, GC3Dint*)
586 GraphicsContext3D::Attributes GraphicsContext3DPrivate::getContextAttributes()
588 WebKit::WebGraphicsContext3D::Attributes webAttributes = m_impl->getContextAttributes();
589 GraphicsContext3D::Attributes attributes;
590 attributes.alpha = webAttributes.alpha;
591 attributes.depth = webAttributes.depth;
592 attributes.stencil = webAttributes.stencil;
593 attributes.antialias = webAttributes.antialias;
594 attributes.premultipliedAlpha = webAttributes.premultipliedAlpha;
595 attributes.preserveDrawingBuffer = m_preserveDrawingBuffer;
599 DELEGATE_TO_IMPL_R(getError, GC3Denum)
601 DELEGATE_TO_IMPL_2(getFloatv, GC3Denum, GC3Dfloat*)
603 DELEGATE_TO_IMPL_4(getFramebufferAttachmentParameteriv, GC3Denum, GC3Denum, GC3Denum, GC3Dint*)
605 DELEGATE_TO_IMPL_2(getIntegerv, GC3Denum, GC3Dint*)
607 DELEGATE_TO_IMPL_3(getProgramiv, Platform3DObject, GC3Denum, GC3Dint*)
609 String GraphicsContext3DPrivate::getProgramInfoLog(Platform3DObject program)
611 return m_impl->getProgramInfoLog(program);
614 DELEGATE_TO_IMPL_3(getRenderbufferParameteriv, GC3Denum, GC3Denum, GC3Dint*)
616 DELEGATE_TO_IMPL_3(getShaderiv, Platform3DObject, GC3Denum, GC3Dint*)
618 String GraphicsContext3DPrivate::getShaderInfoLog(Platform3DObject shader)
620 return m_impl->getShaderInfoLog(shader);
623 String GraphicsContext3DPrivate::getShaderSource(Platform3DObject shader)
625 return m_impl->getShaderSource(shader);
628 String GraphicsContext3DPrivate::getString(GC3Denum name)
630 return m_impl->getString(name);
633 DELEGATE_TO_IMPL_3(getTexParameterfv, GC3Denum, GC3Denum, GC3Dfloat*)
634 DELEGATE_TO_IMPL_3(getTexParameteriv, GC3Denum, GC3Denum, GC3Dint*)
636 DELEGATE_TO_IMPL_3(getUniformfv, Platform3DObject, GC3Dint, GC3Dfloat*)
637 DELEGATE_TO_IMPL_3(getUniformiv, Platform3DObject, GC3Dint, GC3Dint*)
639 GC3Dint GraphicsContext3DPrivate::getUniformLocation(Platform3DObject program, const String& name)
641 return m_impl->getUniformLocation(program, name.utf8().data());
644 DELEGATE_TO_IMPL_3(getVertexAttribfv, GC3Duint, GC3Denum, GC3Dfloat*)
645 DELEGATE_TO_IMPL_3(getVertexAttribiv, GC3Duint, GC3Denum, GC3Dint*)
647 DELEGATE_TO_IMPL_2R(getVertexAttribOffset, GC3Duint, GC3Denum, GC3Dsizeiptr)
649 DELEGATE_TO_IMPL_2(hint, GC3Denum, GC3Denum)
650 DELEGATE_TO_IMPL_1R(isBuffer, Platform3DObject, GC3Dboolean)
651 DELEGATE_TO_IMPL_1R(isEnabled, GC3Denum, GC3Dboolean)
652 DELEGATE_TO_IMPL_1R(isFramebuffer, Platform3DObject, GC3Dboolean)
653 DELEGATE_TO_IMPL_1R(isProgram, Platform3DObject, GC3Dboolean)
654 DELEGATE_TO_IMPL_1R(isRenderbuffer, Platform3DObject, GC3Dboolean)
655 DELEGATE_TO_IMPL_1R(isShader, Platform3DObject, GC3Dboolean)
656 DELEGATE_TO_IMPL_1R(isTexture, Platform3DObject, GC3Dboolean)
657 DELEGATE_TO_IMPL_1(lineWidth, GC3Dfloat)
658 DELEGATE_TO_IMPL_1(linkProgram, Platform3DObject)
659 DELEGATE_TO_IMPL_2(pixelStorei, GC3Denum, GC3Dint)
660 DELEGATE_TO_IMPL_2(polygonOffset, GC3Dfloat, GC3Dfloat)
661 DELEGATE_TO_IMPL_7(readPixels, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei, GC3Denum, GC3Denum, void*)
662 DELEGATE_TO_IMPL(releaseShaderCompiler)
663 DELEGATE_TO_IMPL_4(renderbufferStorage, GC3Denum, GC3Denum, GC3Dsizei, GC3Dsizei)
664 DELEGATE_TO_IMPL_2(sampleCoverage, GC3Dclampf, GC3Dboolean)
665 DELEGATE_TO_IMPL_4(scissor, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei)
667 void GraphicsContext3DPrivate::shaderSource(Platform3DObject shader, const String& string)
669 m_impl->shaderSource(shader, string.utf8().data());
672 DELEGATE_TO_IMPL_3(stencilFunc, GC3Denum, GC3Dint, GC3Duint)
673 DELEGATE_TO_IMPL_4(stencilFuncSeparate, GC3Denum, GC3Denum, GC3Dint, GC3Duint)
674 DELEGATE_TO_IMPL_1(stencilMask, GC3Duint)
675 DELEGATE_TO_IMPL_2(stencilMaskSeparate, GC3Denum, GC3Duint)
676 DELEGATE_TO_IMPL_3(stencilOp, GC3Denum, GC3Denum, GC3Denum)
677 DELEGATE_TO_IMPL_4(stencilOpSeparate, GC3Denum, GC3Denum, GC3Denum, GC3Denum)
679 bool GraphicsContext3DPrivate::texImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3Denum type, const void* pixels)
681 m_impl->texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
685 DELEGATE_TO_IMPL_3(texParameterf, GC3Denum, GC3Denum, GC3Dfloat)
686 DELEGATE_TO_IMPL_3(texParameteri, GC3Denum, GC3Denum, GC3Dint)
688 void GraphicsContext3DPrivate::texSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, const void* pixels)
690 m_impl->texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
693 DELEGATE_TO_IMPL_2(uniform1f, GC3Dint, GC3Dfloat)
695 void GraphicsContext3DPrivate::uniform1fv(GC3Dint location, GC3Dfloat* v, GC3Dsizei size)
697 m_impl->uniform1fv(location, size, v);
700 DELEGATE_TO_IMPL_2(uniform1i, GC3Dint, GC3Dint)
702 void GraphicsContext3DPrivate::uniform1iv(GC3Dint location, GC3Dint* v, GC3Dsizei size)
704 m_impl->uniform1iv(location, size, v);
707 DELEGATE_TO_IMPL_3(uniform2f, GC3Dint, GC3Dfloat, GC3Dfloat)
709 void GraphicsContext3DPrivate::uniform2fv(GC3Dint location, GC3Dfloat* v, GC3Dsizei size)
711 m_impl->uniform2fv(location, size, v);
714 DELEGATE_TO_IMPL_3(uniform2i, GC3Dint, GC3Dint, GC3Dint)
716 void GraphicsContext3DPrivate::uniform2iv(GC3Dint location, GC3Dint* v, GC3Dsizei size)
718 m_impl->uniform2iv(location, size, v);
721 DELEGATE_TO_IMPL_4(uniform3f, GC3Dint, GC3Dfloat, GC3Dfloat, GC3Dfloat)
723 void GraphicsContext3DPrivate::uniform3fv(GC3Dint location, GC3Dfloat* v, GC3Dsizei size)
725 m_impl->uniform3fv(location, size, v);
728 DELEGATE_TO_IMPL_4(uniform3i, GC3Dint, GC3Dint, GC3Dint, GC3Dint)
730 void GraphicsContext3DPrivate::uniform3iv(GC3Dint location, GC3Dint* v, GC3Dsizei size)
732 m_impl->uniform3iv(location, size, v);
735 DELEGATE_TO_IMPL_5(uniform4f, GC3Dint, GC3Dfloat, GC3Dfloat, GC3Dfloat, GC3Dfloat)
737 void GraphicsContext3DPrivate::uniform4fv(GC3Dint location, GC3Dfloat* v, GC3Dsizei size)
739 m_impl->uniform4fv(location, size, v);
742 DELEGATE_TO_IMPL_5(uniform4i, GC3Dint, GC3Dint, GC3Dint, GC3Dint, GC3Dint)
744 void GraphicsContext3DPrivate::uniform4iv(GC3Dint location, GC3Dint* v, GC3Dsizei size)
746 m_impl->uniform4iv(location, size, v);
749 void GraphicsContext3DPrivate::uniformMatrix2fv(GC3Dint location, GC3Dboolean transpose, GC3Dfloat* value, GC3Dsizei size)
751 m_impl->uniformMatrix2fv(location, size, transpose, value);
754 void GraphicsContext3DPrivate::uniformMatrix3fv(GC3Dint location, GC3Dboolean transpose, GC3Dfloat* value, GC3Dsizei size)
756 m_impl->uniformMatrix3fv(location, size, transpose, value);
759 void GraphicsContext3DPrivate::uniformMatrix4fv(GC3Dint location, GC3Dboolean transpose, GC3Dfloat* value, GC3Dsizei size)
761 m_impl->uniformMatrix4fv(location, size, transpose, value);
764 DELEGATE_TO_IMPL_1(useProgram, Platform3DObject)
765 DELEGATE_TO_IMPL_1(validateProgram, Platform3DObject)
767 DELEGATE_TO_IMPL_2(vertexAttrib1f, GC3Duint, GC3Dfloat)
768 DELEGATE_TO_IMPL_2(vertexAttrib1fv, GC3Duint, GC3Dfloat*)
769 DELEGATE_TO_IMPL_3(vertexAttrib2f, GC3Duint, GC3Dfloat, GC3Dfloat)
770 DELEGATE_TO_IMPL_2(vertexAttrib2fv, GC3Duint, GC3Dfloat*)
771 DELEGATE_TO_IMPL_4(vertexAttrib3f, GC3Duint, GC3Dfloat, GC3Dfloat, GC3Dfloat)
772 DELEGATE_TO_IMPL_2(vertexAttrib3fv, GC3Duint, GC3Dfloat*)
773 DELEGATE_TO_IMPL_5(vertexAttrib4f, GC3Duint, GC3Dfloat, GC3Dfloat, GC3Dfloat, GC3Dfloat)
774 DELEGATE_TO_IMPL_2(vertexAttrib4fv, GC3Duint, GC3Dfloat*)
775 DELEGATE_TO_IMPL_6(vertexAttribPointer, GC3Duint, GC3Dint, GC3Denum, GC3Dboolean, GC3Dsizei, GC3Dsizeiptr)
777 DELEGATE_TO_IMPL_4(viewport, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei)
779 DELEGATE_TO_IMPL_R(createBuffer, Platform3DObject)
780 DELEGATE_TO_IMPL_R(createFramebuffer, Platform3DObject)
781 DELEGATE_TO_IMPL_R(createProgram, Platform3DObject)
782 DELEGATE_TO_IMPL_R(createRenderbuffer, Platform3DObject)
783 DELEGATE_TO_IMPL_1R(createShader, GC3Denum, Platform3DObject)
784 DELEGATE_TO_IMPL_R(createTexture, Platform3DObject)
786 DELEGATE_TO_IMPL_1(deleteBuffer, Platform3DObject)
787 DELEGATE_TO_IMPL_1(deleteFramebuffer, Platform3DObject)
788 DELEGATE_TO_IMPL_1(deleteProgram, Platform3DObject)
789 DELEGATE_TO_IMPL_1(deleteRenderbuffer, Platform3DObject)
790 DELEGATE_TO_IMPL_1(deleteShader, Platform3DObject)
791 DELEGATE_TO_IMPL_1(deleteTexture, Platform3DObject)
793 DELEGATE_TO_IMPL_1(synthesizeGLError, GC3Denum)
795 Extensions3D* GraphicsContext3DPrivate::getExtensions()
798 m_extensions = adoptPtr(new Extensions3DChromium(this));
799 return m_extensions.get();
802 bool GraphicsContext3DPrivate::isResourceSafe()
804 if (m_resourceSafety == ResourceSafetyUnknown)
805 m_resourceSafety = getExtensions()->isEnabled("GL_CHROMIUM_resource_safe") ? ResourceSafe : ResourceUnsafe;
806 return m_resourceSafety == ResourceSafe;
811 void splitStringHelper(const String& str, HashSet<String>& set)
813 Vector<String> substrings;
814 str.split(" ", substrings);
815 for (size_t i = 0; i < substrings.size(); ++i)
816 set.add(substrings[i]);
819 String mapExtensionName(const String& name)
821 if (name == "GL_ANGLE_framebuffer_blit"
822 || name == "GL_ANGLE_framebuffer_multisample")
823 return "GL_CHROMIUM_framebuffer_multisample";
827 } // anonymous namespace
829 void GraphicsContext3DPrivate::initializeExtensions()
831 bool success = makeContextCurrent();
833 if (success && !m_initializedAvailableExtensions) {
834 String extensionsString = getString(GraphicsContext3D::EXTENSIONS);
835 splitStringHelper(extensionsString, m_enabledExtensions);
837 String requestableExtensionsString = m_impl->getRequestableExtensionsCHROMIUM();
838 splitStringHelper(requestableExtensionsString, m_requestableExtensions);
840 m_initializedAvailableExtensions = true;
845 bool GraphicsContext3DPrivate::supportsExtension(const String& name)
847 initializeExtensions();
848 String mappedName = mapExtensionName(name);
849 return m_enabledExtensions.contains(mappedName) || m_requestableExtensions.contains(mappedName);
852 bool GraphicsContext3DPrivate::ensureExtensionEnabled(const String& name)
854 initializeExtensions();
856 String mappedName = mapExtensionName(name);
857 if (m_enabledExtensions.contains(mappedName))
860 if (m_requestableExtensions.contains(mappedName)) {
861 m_impl->requestExtensionCHROMIUM(mappedName.ascii().data());
862 m_enabledExtensions.clear();
863 m_requestableExtensions.clear();
864 m_initializedAvailableExtensions = false;
867 initializeExtensions();
868 return m_enabledExtensions.contains(mappedName);
871 bool GraphicsContext3DPrivate::isExtensionEnabled(const String& name)
873 initializeExtensions();
874 String mappedName = mapExtensionName(name);
875 return m_enabledExtensions.contains(mappedName);
878 DELEGATE_TO_IMPL_4R(mapBufferSubDataCHROMIUM, GC3Denum, GC3Dsizeiptr, GC3Dsizei, GC3Denum, void*)
879 DELEGATE_TO_IMPL_1(unmapBufferSubDataCHROMIUM, const void*)
880 DELEGATE_TO_IMPL_9R(mapTexSubImage2DCHROMIUM, GC3Denum, GC3Dint, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei, GC3Denum, GC3Denum, GC3Denum, void*)
881 DELEGATE_TO_IMPL_1(unmapTexSubImage2DCHROMIUM, const void*)
883 DELEGATE_TO_IMPL_10(blitFramebufferCHROMIUM, GC3Dint, GC3Dint, GC3Dint, GC3Dint, GC3Dint, GC3Dint, GC3Dint, GC3Dint, GC3Dbitfield, GC3Denum)
884 DELEGATE_TO_IMPL_5(renderbufferStorageMultisampleCHROMIUM, GC3Denum, GC3Dsizei, GC3Denum, GC3Dsizei, GC3Dsizei)
886 DELEGATE_TO_IMPL(rateLimitOffscreenContextCHROMIUM)
887 DELEGATE_TO_IMPL_R(getGraphicsResetStatusARB, GC3Denum)
889 //----------------------------------------------------------------------
893 // Macros to assist in delegating from GraphicsContext3D to
894 // GraphicsContext3DPrivate.
896 #define DELEGATE_TO_INTERNAL(name) \
897 void GraphicsContext3D::name() \
902 #define DELEGATE_TO_INTERNAL_R(name, rt) \
903 rt GraphicsContext3D::name() \
905 return m_private->name(); \
908 #define DELEGATE_TO_INTERNAL_1(name, t1) \
909 void GraphicsContext3D::name(t1 a1) \
911 m_private->name(a1); \
914 #define DELEGATE_TO_INTERNAL_1R(name, t1, rt) \
915 rt GraphicsContext3D::name(t1 a1) \
917 return m_private->name(a1); \
920 #define DELEGATE_TO_INTERNAL_2(name, t1, t2) \
921 void GraphicsContext3D::name(t1 a1, t2 a2) \
923 m_private->name(a1, a2); \
926 #define DELEGATE_TO_INTERNAL_2R(name, t1, t2, rt) \
927 rt GraphicsContext3D::name(t1 a1, t2 a2) \
929 return m_private->name(a1, a2); \
932 #define DELEGATE_TO_INTERNAL_3(name, t1, t2, t3) \
933 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3) \
935 m_private->name(a1, a2, a3); \
938 #define DELEGATE_TO_INTERNAL_3R(name, t1, t2, t3, rt) \
939 rt GraphicsContext3D::name(t1 a1, t2 a2, t3 a3) \
941 return m_private->name(a1, a2, a3); \
944 #define DELEGATE_TO_INTERNAL_4(name, t1, t2, t3, t4) \
945 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4) \
947 m_private->name(a1, a2, a3, a4); \
950 #define DELEGATE_TO_INTERNAL_4R(name, t1, t2, t3, t4, rt) \
951 rt GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4) \
953 return m_private->name(a1, a2, a3, a4); \
956 #define DELEGATE_TO_INTERNAL_5(name, t1, t2, t3, t4, t5) \
957 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) \
959 m_private->name(a1, a2, a3, a4, a5); \
962 #define DELEGATE_TO_INTERNAL_6(name, t1, t2, t3, t4, t5, t6) \
963 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6) \
965 m_private->name(a1, a2, a3, a4, a5, a6); \
968 #define DELEGATE_TO_INTERNAL_6R(name, t1, t2, t3, t4, t5, t6, rt) \
969 rt GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6) \
971 return m_private->name(a1, a2, a3, a4, a5, a6); \
974 #define DELEGATE_TO_INTERNAL_7(name, t1, t2, t3, t4, t5, t6, t7) \
975 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7) \
977 m_private->name(a1, a2, a3, a4, a5, a6, a7); \
980 #define DELEGATE_TO_INTERNAL_7R(name, t1, t2, t3, t4, t5, t6, t7, rt) \
981 rt GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7) \
983 return m_private->name(a1, a2, a3, a4, a5, a6, a7); \
986 #define DELEGATE_TO_INTERNAL_8(name, t1, t2, t3, t4, t5, t6, t7, t8) \
987 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8 a8) \
989 m_private->name(a1, a2, a3, a4, a5, a6, a7, a8); \
992 #define DELEGATE_TO_INTERNAL_9(name, t1, t2, t3, t4, t5, t6, t7, t8, t9) \
993 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8 a8, t9 a9) \
995 m_private->name(a1, a2, a3, a4, a5, a6, a7, a8, a9); \
998 #define DELEGATE_TO_INTERNAL_9R(name, t1, t2, t3, t4, t5, t6, t7, t8, t9, rt) \
999 rt GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8 a8, t9 a9) \
1001 return m_private->name(a1, a2, a3, a4, a5, a6, a7, a8, a9); \
1004 GraphicsContext3D::GraphicsContext3D(GraphicsContext3D::Attributes, HostWindow*, bool)
1008 GraphicsContext3D::~GraphicsContext3D()
1010 WebGLLayerChromium* canvasLayer = m_private->platformLayer();
1012 canvasLayer->setContext(0);
1013 m_private->setContextLostCallback(nullptr);
1014 m_private->setSwapBuffersCompleteCallbackCHROMIUM(nullptr);
1017 PassRefPtr<GraphicsContext3D> GraphicsContext3D::create(GraphicsContext3D::Attributes attrs, HostWindow* hostWindow, GraphicsContext3D::RenderStyle renderStyle)
1019 return createGraphicsContext(attrs, hostWindow, renderStyle, GraphicsContext3DPrivate::ForUseOnThisThread);
1022 PlatformGraphicsContext3D GraphicsContext3D::platformGraphicsContext3D() const
1024 return m_private->platformGraphicsContext3D();
1027 Platform3DObject GraphicsContext3D::platformTexture() const
1029 return m_private->platformTexture();
1033 GrContext* GraphicsContext3D::grContext()
1035 return m_private->grContext();
1039 void GraphicsContext3D::prepareTexture()
1041 return m_private->prepareTexture();
1044 IntSize GraphicsContext3D::getInternalFramebufferSize() const
1046 return m_private->getInternalFramebufferSize();
1049 bool GraphicsContext3D::isResourceSafe()
1051 return m_private->isResourceSafe();
1054 #if USE(ACCELERATED_COMPOSITING)
1055 PlatformLayer* GraphicsContext3D::platformLayer() const
1057 WebGLLayerChromium* canvasLayer = m_private->platformLayer();
1058 canvasLayer->setContext(this);
1063 DELEGATE_TO_INTERNAL(makeContextCurrent)
1064 DELEGATE_TO_INTERNAL_2(reshape, int, int)
1066 DELEGATE_TO_INTERNAL_1(activeTexture, GC3Denum)
1067 DELEGATE_TO_INTERNAL_2(attachShader, Platform3DObject, Platform3DObject)
1068 DELEGATE_TO_INTERNAL_3(bindAttribLocation, Platform3DObject, GC3Duint, const String&)
1070 DELEGATE_TO_INTERNAL_2(bindBuffer, GC3Denum, Platform3DObject)
1071 DELEGATE_TO_INTERNAL_2(bindFramebuffer, GC3Denum, Platform3DObject)
1072 DELEGATE_TO_INTERNAL_2(bindRenderbuffer, GC3Denum, Platform3DObject)
1073 DELEGATE_TO_INTERNAL_2(bindTexture, GC3Denum, Platform3DObject)
1074 DELEGATE_TO_INTERNAL_4(blendColor, GC3Dclampf, GC3Dclampf, GC3Dclampf, GC3Dclampf)
1075 DELEGATE_TO_INTERNAL_1(blendEquation, GC3Denum)
1076 DELEGATE_TO_INTERNAL_2(blendEquationSeparate, GC3Denum, GC3Denum)
1077 DELEGATE_TO_INTERNAL_2(blendFunc, GC3Denum, GC3Denum)
1078 DELEGATE_TO_INTERNAL_4(blendFuncSeparate, GC3Denum, GC3Denum, GC3Denum, GC3Denum)
1080 DELEGATE_TO_INTERNAL_3(bufferData, GC3Denum, GC3Dsizeiptr, GC3Denum)
1081 DELEGATE_TO_INTERNAL_4(bufferData, GC3Denum, GC3Dsizeiptr, const void*, GC3Denum)
1082 DELEGATE_TO_INTERNAL_4(bufferSubData, GC3Denum, GC3Dintptr, GC3Dsizeiptr, const void*)
1084 DELEGATE_TO_INTERNAL_1R(checkFramebufferStatus, GC3Denum, GC3Denum)
1085 DELEGATE_TO_INTERNAL_1(clear, GC3Dbitfield)
1086 DELEGATE_TO_INTERNAL_4(clearColor, GC3Dclampf, GC3Dclampf, GC3Dclampf, GC3Dclampf)
1087 DELEGATE_TO_INTERNAL_1(clearDepth, GC3Dclampf)
1088 DELEGATE_TO_INTERNAL_1(clearStencil, GC3Dint)
1089 DELEGATE_TO_INTERNAL_4(colorMask, GC3Dboolean, GC3Dboolean, GC3Dboolean, GC3Dboolean)
1090 DELEGATE_TO_INTERNAL_1(compileShader, Platform3DObject)
1092 DELEGATE_TO_INTERNAL_8(copyTexImage2D, GC3Denum, GC3Dint, GC3Denum, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei, GC3Dint)
1093 DELEGATE_TO_INTERNAL_8(copyTexSubImage2D, GC3Denum, GC3Dint, GC3Dint, GC3Dint, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei)
1094 DELEGATE_TO_INTERNAL_1(cullFace, GC3Denum)
1095 DELEGATE_TO_INTERNAL_1(depthFunc, GC3Denum)
1096 DELEGATE_TO_INTERNAL_1(depthMask, GC3Dboolean)
1097 DELEGATE_TO_INTERNAL_2(depthRange, GC3Dclampf, GC3Dclampf)
1098 DELEGATE_TO_INTERNAL_2(detachShader, Platform3DObject, Platform3DObject)
1099 DELEGATE_TO_INTERNAL_1(disable, GC3Denum)
1100 DELEGATE_TO_INTERNAL_1(disableVertexAttribArray, GC3Duint)
1101 DELEGATE_TO_INTERNAL_3(drawArrays, GC3Denum, GC3Dint, GC3Dsizei)
1102 DELEGATE_TO_INTERNAL_4(drawElements, GC3Denum, GC3Dsizei, GC3Denum, GC3Dintptr)
1104 DELEGATE_TO_INTERNAL_1(enable, GC3Denum)
1105 DELEGATE_TO_INTERNAL_1(enableVertexAttribArray, GC3Duint)
1106 DELEGATE_TO_INTERNAL(finish)
1107 DELEGATE_TO_INTERNAL(flush)
1108 DELEGATE_TO_INTERNAL_4(framebufferRenderbuffer, GC3Denum, GC3Denum, GC3Denum, Platform3DObject)
1109 DELEGATE_TO_INTERNAL_5(framebufferTexture2D, GC3Denum, GC3Denum, GC3Denum, Platform3DObject, GC3Dint)
1110 DELEGATE_TO_INTERNAL_1(frontFace, GC3Denum)
1111 DELEGATE_TO_INTERNAL_1(generateMipmap, GC3Denum)
1113 DELEGATE_TO_INTERNAL_3R(getActiveAttrib, Platform3DObject, GC3Duint, ActiveInfo&, bool)
1114 DELEGATE_TO_INTERNAL_3R(getActiveUniform, Platform3DObject, GC3Duint, ActiveInfo&, bool)
1115 DELEGATE_TO_INTERNAL_4(getAttachedShaders, Platform3DObject, GC3Dsizei, GC3Dsizei*, Platform3DObject*)
1116 DELEGATE_TO_INTERNAL_2R(getAttribLocation, Platform3DObject, const String&, GC3Dint)
1117 DELEGATE_TO_INTERNAL_2(getBooleanv, GC3Denum, GC3Dboolean*)
1118 DELEGATE_TO_INTERNAL_3(getBufferParameteriv, GC3Denum, GC3Denum, GC3Dint*)
1119 DELEGATE_TO_INTERNAL_R(getContextAttributes, GraphicsContext3D::Attributes)
1120 DELEGATE_TO_INTERNAL_R(getError, GC3Denum)
1121 DELEGATE_TO_INTERNAL_2(getFloatv, GC3Denum, GC3Dfloat*)
1122 DELEGATE_TO_INTERNAL_4(getFramebufferAttachmentParameteriv, GC3Denum, GC3Denum, GC3Denum, GC3Dint*)
1123 DELEGATE_TO_INTERNAL_2(getIntegerv, GC3Denum, GC3Dint*)
1124 DELEGATE_TO_INTERNAL_3(getProgramiv, Platform3DObject, GC3Denum, GC3Dint*)
1125 DELEGATE_TO_INTERNAL_1R(getProgramInfoLog, Platform3DObject, String)
1126 DELEGATE_TO_INTERNAL_3(getRenderbufferParameteriv, GC3Denum, GC3Denum, GC3Dint*)
1127 DELEGATE_TO_INTERNAL_3(getShaderiv, Platform3DObject, GC3Denum, GC3Dint*)
1128 DELEGATE_TO_INTERNAL_1R(getShaderInfoLog, Platform3DObject, String)
1129 DELEGATE_TO_INTERNAL_1R(getShaderSource, Platform3DObject, String)
1130 DELEGATE_TO_INTERNAL_1R(getString, GC3Denum, String)
1131 DELEGATE_TO_INTERNAL_3(getTexParameterfv, GC3Denum, GC3Denum, GC3Dfloat*)
1132 DELEGATE_TO_INTERNAL_3(getTexParameteriv, GC3Denum, GC3Denum, GC3Dint*)
1133 DELEGATE_TO_INTERNAL_3(getUniformfv, Platform3DObject, GC3Dint, GC3Dfloat*)
1134 DELEGATE_TO_INTERNAL_3(getUniformiv, Platform3DObject, GC3Dint, GC3Dint*)
1135 DELEGATE_TO_INTERNAL_2R(getUniformLocation, Platform3DObject, const String&, GC3Dint)
1136 DELEGATE_TO_INTERNAL_3(getVertexAttribfv, GC3Duint, GC3Denum, GC3Dfloat*)
1137 DELEGATE_TO_INTERNAL_3(getVertexAttribiv, GC3Duint, GC3Denum, GC3Dint*)
1138 DELEGATE_TO_INTERNAL_2R(getVertexAttribOffset, GC3Duint, GC3Denum, GC3Dsizeiptr)
1140 DELEGATE_TO_INTERNAL_2(hint, GC3Denum, GC3Denum)
1141 DELEGATE_TO_INTERNAL_1R(isBuffer, Platform3DObject, GC3Dboolean)
1142 DELEGATE_TO_INTERNAL_1R(isEnabled, GC3Denum, GC3Dboolean)
1143 DELEGATE_TO_INTERNAL_1R(isFramebuffer, Platform3DObject, GC3Dboolean)
1144 DELEGATE_TO_INTERNAL_1R(isProgram, Platform3DObject, GC3Dboolean)
1145 DELEGATE_TO_INTERNAL_1R(isRenderbuffer, Platform3DObject, GC3Dboolean)
1146 DELEGATE_TO_INTERNAL_1R(isShader, Platform3DObject, GC3Dboolean)
1147 DELEGATE_TO_INTERNAL_1R(isTexture, Platform3DObject, GC3Dboolean)
1148 DELEGATE_TO_INTERNAL_1(lineWidth, GC3Dfloat)
1149 DELEGATE_TO_INTERNAL_1(linkProgram, Platform3DObject)
1150 DELEGATE_TO_INTERNAL_2(pixelStorei, GC3Denum, GC3Dint)
1151 DELEGATE_TO_INTERNAL_2(polygonOffset, GC3Dfloat, GC3Dfloat)
1153 DELEGATE_TO_INTERNAL_7(readPixels, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei, GC3Denum, GC3Denum, void*)
1155 DELEGATE_TO_INTERNAL(releaseShaderCompiler)
1156 DELEGATE_TO_INTERNAL_4(renderbufferStorage, GC3Denum, GC3Denum, GC3Dsizei, GC3Dsizei)
1157 DELEGATE_TO_INTERNAL_2(sampleCoverage, GC3Dclampf, GC3Dboolean)
1158 DELEGATE_TO_INTERNAL_4(scissor, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei)
1159 DELEGATE_TO_INTERNAL_2(shaderSource, Platform3DObject, const String&)
1160 DELEGATE_TO_INTERNAL_3(stencilFunc, GC3Denum, GC3Dint, GC3Duint)
1161 DELEGATE_TO_INTERNAL_4(stencilFuncSeparate, GC3Denum, GC3Denum, GC3Dint, GC3Duint)
1162 DELEGATE_TO_INTERNAL_1(stencilMask, GC3Duint)
1163 DELEGATE_TO_INTERNAL_2(stencilMaskSeparate, GC3Denum, GC3Duint)
1164 DELEGATE_TO_INTERNAL_3(stencilOp, GC3Denum, GC3Denum, GC3Denum)
1165 DELEGATE_TO_INTERNAL_4(stencilOpSeparate, GC3Denum, GC3Denum, GC3Denum, GC3Denum)
1167 DELEGATE_TO_INTERNAL_9R(texImage2D, GC3Denum, GC3Dint, GC3Denum, GC3Dsizei, GC3Dsizei, GC3Dint, GC3Denum, GC3Denum, const void*, bool)
1168 DELEGATE_TO_INTERNAL_3(texParameterf, GC3Denum, GC3Denum, GC3Dfloat)
1169 DELEGATE_TO_INTERNAL_3(texParameteri, GC3Denum, GC3Denum, GC3Dint)
1170 DELEGATE_TO_INTERNAL_9(texSubImage2D, GC3Denum, GC3Dint, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei, GC3Denum, GC3Denum, const void*)
1172 DELEGATE_TO_INTERNAL_2(uniform1f, GC3Dint, GC3Dfloat)
1173 DELEGATE_TO_INTERNAL_3(uniform1fv, GC3Dint, GC3Dfloat*, GC3Dsizei)
1174 DELEGATE_TO_INTERNAL_2(uniform1i, GC3Dint, GC3Dint)
1175 DELEGATE_TO_INTERNAL_3(uniform1iv, GC3Dint, GC3Dint*, GC3Dsizei)
1176 DELEGATE_TO_INTERNAL_3(uniform2f, GC3Dint, GC3Dfloat, GC3Dfloat)
1177 DELEGATE_TO_INTERNAL_3(uniform2fv, GC3Dint, GC3Dfloat*, GC3Dsizei)
1178 DELEGATE_TO_INTERNAL_3(uniform2i, GC3Dint, GC3Dint, GC3Dint)
1179 DELEGATE_TO_INTERNAL_3(uniform2iv, GC3Dint, GC3Dint*, GC3Dsizei)
1180 DELEGATE_TO_INTERNAL_4(uniform3f, GC3Dint, GC3Dfloat, GC3Dfloat, GC3Dfloat)
1181 DELEGATE_TO_INTERNAL_3(uniform3fv, GC3Dint, GC3Dfloat*, GC3Dsizei)
1182 DELEGATE_TO_INTERNAL_4(uniform3i, GC3Dint, GC3Dint, GC3Dint, GC3Dint)
1183 DELEGATE_TO_INTERNAL_3(uniform3iv, GC3Dint, GC3Dint*, GC3Dsizei)
1184 DELEGATE_TO_INTERNAL_5(uniform4f, GC3Dint, GC3Dfloat, GC3Dfloat, GC3Dfloat, GC3Dfloat)
1185 DELEGATE_TO_INTERNAL_3(uniform4fv, GC3Dint, GC3Dfloat*, GC3Dsizei)
1186 DELEGATE_TO_INTERNAL_5(uniform4i, GC3Dint, GC3Dint, GC3Dint, GC3Dint, GC3Dint)
1187 DELEGATE_TO_INTERNAL_3(uniform4iv, GC3Dint, GC3Dint*, GC3Dsizei)
1188 DELEGATE_TO_INTERNAL_4(uniformMatrix2fv, GC3Dint, GC3Dboolean, GC3Dfloat*, GC3Dsizei)
1189 DELEGATE_TO_INTERNAL_4(uniformMatrix3fv, GC3Dint, GC3Dboolean, GC3Dfloat*, GC3Dsizei)
1190 DELEGATE_TO_INTERNAL_4(uniformMatrix4fv, GC3Dint, GC3Dboolean, GC3Dfloat*, GC3Dsizei)
1192 DELEGATE_TO_INTERNAL_1(useProgram, Platform3DObject)
1193 DELEGATE_TO_INTERNAL_1(validateProgram, Platform3DObject)
1195 DELEGATE_TO_INTERNAL_2(vertexAttrib1f, GC3Duint, GC3Dfloat)
1196 DELEGATE_TO_INTERNAL_2(vertexAttrib1fv, GC3Duint, GC3Dfloat*)
1197 DELEGATE_TO_INTERNAL_3(vertexAttrib2f, GC3Duint, GC3Dfloat, GC3Dfloat)
1198 DELEGATE_TO_INTERNAL_2(vertexAttrib2fv, GC3Duint, GC3Dfloat*)
1199 DELEGATE_TO_INTERNAL_4(vertexAttrib3f, GC3Duint, GC3Dfloat, GC3Dfloat, GC3Dfloat)
1200 DELEGATE_TO_INTERNAL_2(vertexAttrib3fv, GC3Duint, GC3Dfloat*)
1201 DELEGATE_TO_INTERNAL_5(vertexAttrib4f, GC3Duint, GC3Dfloat, GC3Dfloat, GC3Dfloat, GC3Dfloat)
1202 DELEGATE_TO_INTERNAL_2(vertexAttrib4fv, GC3Duint, GC3Dfloat*)
1203 DELEGATE_TO_INTERNAL_6(vertexAttribPointer, GC3Duint, GC3Dint, GC3Denum, GC3Dboolean, GC3Dsizei, GC3Dintptr)
1205 DELEGATE_TO_INTERNAL_4(viewport, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei)
1207 DELEGATE_TO_INTERNAL(markLayerComposited)
1208 DELEGATE_TO_INTERNAL(markContextChanged)
1210 bool GraphicsContext3D::layerComposited() const
1212 return m_private->layerComposited();
1215 DELEGATE_TO_INTERNAL_1(paintRenderingResultsToCanvas, CanvasRenderingContext*)
1216 DELEGATE_TO_INTERNAL_R(paintRenderingResultsToImageData, PassRefPtr<ImageData>)
1217 DELEGATE_TO_INTERNAL_1R(paintCompositedResultsToCanvas, CanvasRenderingContext*, bool)
1219 bool GraphicsContext3D::paintsIntoCanvasBuffer() const
1221 return m_private->paintsIntoCanvasBuffer();
1224 DELEGATE_TO_INTERNAL_R(createBuffer, Platform3DObject)
1225 DELEGATE_TO_INTERNAL_R(createFramebuffer, Platform3DObject)
1226 DELEGATE_TO_INTERNAL_R(createProgram, Platform3DObject)
1227 DELEGATE_TO_INTERNAL_R(createRenderbuffer, Platform3DObject)
1228 DELEGATE_TO_INTERNAL_1R(createShader, GC3Denum, Platform3DObject)
1229 DELEGATE_TO_INTERNAL_R(createTexture, Platform3DObject)
1231 DELEGATE_TO_INTERNAL_1(deleteBuffer, Platform3DObject)
1232 DELEGATE_TO_INTERNAL_1(deleteFramebuffer, Platform3DObject)
1233 DELEGATE_TO_INTERNAL_1(deleteProgram, Platform3DObject)
1234 DELEGATE_TO_INTERNAL_1(deleteRenderbuffer, Platform3DObject)
1235 DELEGATE_TO_INTERNAL_1(deleteShader, Platform3DObject)
1236 DELEGATE_TO_INTERNAL_1(deleteTexture, Platform3DObject)
1238 DELEGATE_TO_INTERNAL_1(synthesizeGLError, GC3Denum)
1239 DELEGATE_TO_INTERNAL_R(getExtensions, Extensions3D*)
1241 DELEGATE_TO_INTERNAL_1(setContextLostCallback, PassOwnPtr<GraphicsContext3D::ContextLostCallback>)
1243 class GraphicsContextLostCallbackAdapter : public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback {
1245 virtual void onContextLost();
1246 static PassOwnPtr<GraphicsContextLostCallbackAdapter> create(PassOwnPtr<GraphicsContext3D::ContextLostCallback>);
1247 virtual ~GraphicsContextLostCallbackAdapter() { }
1249 GraphicsContextLostCallbackAdapter(PassOwnPtr<GraphicsContext3D::ContextLostCallback> cb) : m_contextLostCallback(cb) { }
1250 OwnPtr<GraphicsContext3D::ContextLostCallback> m_contextLostCallback;
1253 void GraphicsContextLostCallbackAdapter::onContextLost()
1255 if (m_contextLostCallback)
1256 m_contextLostCallback->onContextLost();
1259 PassOwnPtr<GraphicsContextLostCallbackAdapter> GraphicsContextLostCallbackAdapter::create(PassOwnPtr<GraphicsContext3D::ContextLostCallback> cb)
1261 return adoptPtr(cb.get() ? new GraphicsContextLostCallbackAdapter(cb) : 0);
1264 void GraphicsContext3DPrivate::setContextLostCallback(PassOwnPtr<GraphicsContext3D::ContextLostCallback> cb)
1266 m_contextLostCallbackAdapter = GraphicsContextLostCallbackAdapter::create(cb);
1267 m_impl->setContextLostCallback(m_contextLostCallbackAdapter.get());
1270 bool GraphicsContext3D::isGLES2Compliant() const
1272 return m_private->isGLES2Compliant();
1275 class SwapBuffersCompleteCallbackAdapter : public WebKit::WebGraphicsContext3D::WebGraphicsSwapBuffersCompleteCallbackCHROMIUM {
1277 virtual void onSwapBuffersComplete();
1278 static PassOwnPtr<SwapBuffersCompleteCallbackAdapter> create(PassOwnPtr<Extensions3DChromium::SwapBuffersCompleteCallbackCHROMIUM>);
1279 virtual ~SwapBuffersCompleteCallbackAdapter() { }
1281 SwapBuffersCompleteCallbackAdapter(PassOwnPtr<Extensions3DChromium::SwapBuffersCompleteCallbackCHROMIUM> cb) : m_swapBuffersCompleteCallback(cb) { }
1282 OwnPtr<Extensions3DChromium::SwapBuffersCompleteCallbackCHROMIUM> m_swapBuffersCompleteCallback;
1285 void SwapBuffersCompleteCallbackAdapter::onSwapBuffersComplete()
1287 if (m_swapBuffersCompleteCallback)
1288 m_swapBuffersCompleteCallback->onSwapBuffersComplete();
1291 PassOwnPtr<SwapBuffersCompleteCallbackAdapter> SwapBuffersCompleteCallbackAdapter::create(PassOwnPtr<Extensions3DChromium::SwapBuffersCompleteCallbackCHROMIUM> cb)
1293 return adoptPtr(cb.get() ? new SwapBuffersCompleteCallbackAdapter(cb) : 0);
1296 void GraphicsContext3DPrivate::setSwapBuffersCompleteCallbackCHROMIUM(PassOwnPtr<Extensions3DChromium::SwapBuffersCompleteCallbackCHROMIUM> cb)
1298 m_swapBuffersCompleteCallbackAdapter = SwapBuffersCompleteCallbackAdapter::create(cb);
1299 m_impl->setSwapBuffersCompleteCallbackCHROMIUM(m_swapBuffersCompleteCallbackAdapter.get());
1302 } // namespace WebCore
1304 #endif // ENABLE(WEBGL)