[SCM] WebKit Debian packaging branch, webkit-1.2, updated. upstream/1.1.90-6072-g9a69373

cmarrin at apple.com cmarrin at apple.com
Wed Apr 7 23:10:13 UTC 2010


The following commit has been merged in the webkit-1.2 branch:
commit 42a84f4fd25bcad8652a9aa1414c87fc2be7326f
Author: cmarrin at apple.com <cmarrin at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue Oct 27 22:41:17 2009 +0000

            Make WebGL context failure more robust and make it succeed in more cases
            https://bugs.webkit.org/show_bug.cgi?id=30349
    
            Bubble a failure to get a CGLContext up to HTMLContextElement so it can
            return null from getContext. Also added a more robust pixel format choosing
            mechanism and can render correctly when a SW renderer is chosen.
    
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@50181 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 094bb52..c21a75a 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,33 @@
+2009-10-27  Chris Marrin  <cmarrin at apple.com>
+
+        Reviewed by Simon Fraser.
+        
+        Make WebGL context failure more robust and make it succeed in more cases
+        https://bugs.webkit.org/show_bug.cgi?id=30349
+
+        Bubble a failure to get a CGLContext up to HTMLContextElement so it can
+        return null from getContext. Also added a more robust pixel format choosing 
+        mechanism and can render correctly when a SW renderer is chosen.
+
+        * html/HTMLCanvasElement.cpp:
+        (WebCore::HTMLCanvasElement::getContext):
+        * html/canvas/CanvasRenderingContext.h:
+        * html/canvas/CanvasRenderingContext2D.cpp:
+        * html/canvas/CanvasRenderingContext3D.cpp:
+        * html/canvas/CanvasRenderingContext3D.h:
+        (WebCore::CanvasRenderingContext3D::graphicsContext3D):
+        (WebCore::CanvasRenderingContext3D::cleanupAfterGraphicsCall):
+        * platform/graphics/GraphicsContext3D.h:
+        * platform/graphics/mac/Canvas3DLayer.mm:
+        (-[Canvas3DLayer copyCGLPixelFormatForDisplayMask:]):
+        * platform/graphics/mac/GraphicsContext3DMac.cpp:
+        (WebCore::setPixelFormat):
+        (WebCore::GraphicsContext3D::create):
+        (WebCore::GraphicsContext3D::GraphicsContext3D):
+        (WebCore::GraphicsContext3D::~GraphicsContext3D):
+        (WebCore::GraphicsContext3D::reshape):
+        (WebCore::ensureContext):
+
 2009-10-27  Geoffrey Garen  <ggaren at apple.com>
 
         Mac build fix: a forwarding header.
diff --git a/WebCore/html/HTMLCanvasElement.cpp b/WebCore/html/HTMLCanvasElement.cpp
index 335b20f..7bae6e3 100644
--- a/WebCore/html/HTMLCanvasElement.cpp
+++ b/WebCore/html/HTMLCanvasElement.cpp
@@ -172,10 +172,11 @@ CanvasRenderingContext* HTMLCanvasElement::getContext(const String& type)
             if (m_context && !m_context->is3d())
                 return 0;
             if (!m_context) {
-                m_context = new CanvasRenderingContext3D(this);
-
-                // Need to make sure a RenderLayer and compositing layer get created for the Canvas
-                setNeedsStyleRecalc(SyntheticStyleChange);
+                m_context = CanvasRenderingContext3D::create(this);
+                if (m_context) {
+                    // Need to make sure a RenderLayer and compositing layer get created for the Canvas
+                    setNeedsStyleRecalc(SyntheticStyleChange);
+                }
             }
             return m_context.get();
         }
diff --git a/WebCore/html/canvas/CanvasRenderingContext.h b/WebCore/html/canvas/CanvasRenderingContext.h
index 9ac9e57..f752377 100644
--- a/WebCore/html/canvas/CanvasRenderingContext.h
+++ b/WebCore/html/canvas/CanvasRenderingContext.h
@@ -38,6 +38,7 @@ namespace WebCore {
         CanvasRenderingContext(HTMLCanvasElement*);
         virtual ~CanvasRenderingContext() { }
         
+        // Ref and deref the m_canvas
         void ref();
         void deref();
         
@@ -46,7 +47,7 @@ namespace WebCore {
         virtual bool is2d() const { return false; }
         virtual bool is3d() const { return false; }
 
-    protected:
+    private:
         HTMLCanvasElement* m_canvas;
     };
 
diff --git a/WebCore/html/canvas/CanvasRenderingContext2D.cpp b/WebCore/html/canvas/CanvasRenderingContext2D.cpp
index 5e25b93..51210f1 100644
--- a/WebCore/html/canvas/CanvasRenderingContext2D.cpp
+++ b/WebCore/html/canvas/CanvasRenderingContext2D.cpp
@@ -165,10 +165,10 @@ void CanvasRenderingContext2D::setStrokeStyle(PassRefPtr<CanvasStyle> style)
     if (!style)
         return;
 
-    if (m_canvas->originClean()) {
+    if (canvas()->originClean()) {
         if (CanvasPattern* pattern = style->canvasPattern()) {
             if (!pattern->originClean())
-                m_canvas->setOriginTainted();
+                canvas()->setOriginTainted();
         }
     }
 
@@ -189,10 +189,10 @@ void CanvasRenderingContext2D::setFillStyle(PassRefPtr<CanvasStyle> style)
     if (!style)
         return;
  
-    if (m_canvas->originClean()) {
+    if (canvas()->originClean()) {
         if (CanvasPattern* pattern = style->canvasPattern()) {
             if (!pattern->originClean())
-                m_canvas->setOriginTainted();
+                canvas()->setOriginTainted();
         }
     }
 
@@ -447,7 +447,7 @@ void CanvasRenderingContext2D::setTransform(float m11, float m12, float m21, flo
     if (!ctm.isInvertible())
         return;
     c->concatCTM(c->getCTM().inverse());
-    c->concatCTM(m_canvas->baseTransform());
+    c->concatCTM(canvas()->baseTransform());
     state().m_transform.multiply(ctm.inverse());
     m_path.transform(ctm);
 
@@ -630,7 +630,7 @@ void CanvasRenderingContext2D::rect(float x, float y, float width, float height)
 #if ENABLE(DASHBOARD_SUPPORT)
 void CanvasRenderingContext2D::clearPathForDashboardBackwardCompatibilityMode()
 {
-    if (Settings* settings = m_canvas->document()->settings())
+    if (Settings* settings = canvas()->document()->settings())
         if (settings->usesDashboardBackwardCompatibilityMode())
             m_path.clear();
 }
@@ -935,8 +935,8 @@ static inline FloatRect normalizeRect(const FloatRect& rect)
 
 void CanvasRenderingContext2D::checkOrigin(const KURL& url)
 {
-    if (m_canvas->document()->securityOrigin()->taintsCanvas(url))
-        m_canvas->setOriginTainted();
+    if (canvas()->document()->securityOrigin()->taintsCanvas(url))
+        canvas()->setOriginTainted();
 }
 
 void CanvasRenderingContext2D::checkOrigin(const String& url)
@@ -986,11 +986,11 @@ void CanvasRenderingContext2D::drawImage(HTMLImageElement* image, const FloatRec
     if (!cachedImage)
         return;
 
-    if (m_canvas->originClean())
+    if (canvas()->originClean())
         checkOrigin(cachedImage->response().url());
 
-    if (m_canvas->originClean() && !cachedImage->image()->hasSingleSecurityOrigin())
-        m_canvas->setOriginTainted();
+    if (canvas()->originClean() && !cachedImage->image()->hasSingleSecurityOrigin())
+        canvas()->setOriginTainted();
 
     FloatRect sourceRect = c->roundToDevicePixels(srcRect);
     FloatRect destRect = c->roundToDevicePixels(dstRect);
@@ -1012,14 +1012,14 @@ void CanvasRenderingContext2D::drawImage(HTMLCanvasElement* canvas,
     drawImage(canvas, FloatRect(0, 0, canvas->width(), canvas->height()), FloatRect(x, y, width, height), ec);
 }
 
-void CanvasRenderingContext2D::drawImage(HTMLCanvasElement* canvas, const FloatRect& srcRect,
+void CanvasRenderingContext2D::drawImage(HTMLCanvasElement* sourceCanvas, const FloatRect& srcRect,
     const FloatRect& dstRect, ExceptionCode& ec)
 {
-    ASSERT(canvas);
+    ASSERT(sourceCanvas);
 
     ec = 0;
 
-    FloatRect srcCanvasRect = FloatRect(FloatPoint(), canvas->size());
+    FloatRect srcCanvasRect = FloatRect(FloatPoint(), sourceCanvas->size());
     if (!srcCanvasRect.contains(normalizeRect(srcRect)) || srcRect.width() == 0 || srcRect.height() == 0) {
         ec = INDEX_SIZE_ERR;
         return;
@@ -1038,12 +1038,12 @@ void CanvasRenderingContext2D::drawImage(HTMLCanvasElement* canvas, const FloatR
     FloatRect destRect = c->roundToDevicePixels(dstRect);
         
     // FIXME: Do this through platform-independent GraphicsContext API.
-    ImageBuffer* buffer = canvas->buffer();
+    ImageBuffer* buffer = sourceCanvas->buffer();
     if (!buffer)
         return;
 
-    if (!canvas->originClean())
-        m_canvas->setOriginTainted();
+    if (!canvas()->originClean())
+        canvas()->setOriginTainted();
 
     c->drawImage(buffer->image(), destRect, sourceRect, state().m_globalComposite);
     willDraw(destRect); // This call comes after drawImage, since the buffer we draw into may be our own, and we need to make sure it is dirty.
@@ -1088,11 +1088,11 @@ void CanvasRenderingContext2D::drawImage(HTMLVideoElement* video, const FloatRec
     if (!state().m_invertibleCTM)
         return;
 
-    if (m_canvas->originClean())
+    if (canvas()->originClean())
         checkOrigin(video->currentSrc());
 
-    if (m_canvas->originClean() && !video->hasSingleSecurityOrigin())
-        m_canvas->setOriginTainted();
+    if (canvas()->originClean() && !video->hasSingleSecurityOrigin())
+        canvas()->setOriginTainted();
 
     FloatRect sourceRect = c->roundToDevicePixels(srcRect);
     FloatRect destRect = c->roundToDevicePixels(dstRect);
@@ -1121,11 +1121,11 @@ void CanvasRenderingContext2D::drawImageFromRect(HTMLImageElement* image,
     if (!cachedImage)
         return;
 
-    if (m_canvas->originClean())
+    if (canvas()->originClean())
         checkOrigin(cachedImage->response().url());
 
-    if (m_canvas->originClean() && !cachedImage->image()->hasSingleSecurityOrigin())
-        m_canvas->setOriginTainted();
+    if (canvas()->originClean() && !cachedImage->image()->hasSingleSecurityOrigin())
+        canvas()->setOriginTainted();
 
     GraphicsContext* c = drawingContext();
     if (!c)
@@ -1155,7 +1155,7 @@ void CanvasRenderingContext2D::setCompositeOperation(const String& operation)
 void CanvasRenderingContext2D::prepareGradientForDashboard(CanvasGradient* gradient) const
 {
 #if ENABLE(DASHBOARD_SUPPORT)
-    if (Settings* settings = m_canvas->document()->settings())
+    if (Settings* settings = canvas()->document()->settings())
         if (settings->usesDashboardBackwardCompatibilityMode())
             gradient->setDashboardCompatibilityMode();
 #else
@@ -1205,7 +1205,7 @@ PassRefPtr<CanvasPattern> CanvasRenderingContext2D::createPattern(HTMLImageEleme
     if (!cachedImage || !image->cachedImage()->image())
         return CanvasPattern::create(Image::nullImage(), repeatX, repeatY, true);
 
-    bool originClean = !m_canvas->document()->securityOrigin()->taintsCanvas(KURL(KURL(), cachedImage->url()));
+    bool originClean = !canvas()->document()->securityOrigin()->taintsCanvas(KURL(KURL(), cachedImage->url()));
     return CanvasPattern::create(cachedImage->image(), repeatX, repeatY, originClean);
 }
 
@@ -1253,12 +1253,12 @@ void CanvasRenderingContext2D::willDraw(const FloatRect& r, unsigned options)
         // we'd have to keep the clip path around.
     }
     
-    m_canvas->willDraw(dirtyRect);
+    canvas()->willDraw(dirtyRect);
 }
 
 GraphicsContext* CanvasRenderingContext2D::drawingContext() const
 {
-    return m_canvas->drawingContext();
+    return canvas()->drawingContext();
 }
 
 static PassRefPtr<ImageData> createEmptyImageData(const IntSize& size)
@@ -1276,7 +1276,7 @@ PassRefPtr<ImageData> CanvasRenderingContext2D::createImageData(float sw, float
         return 0;
     }
     FloatSize unscaledSize(sw, sh);
-    IntSize scaledSize = m_canvas->convertLogicalToDevice(unscaledSize);
+    IntSize scaledSize = canvas()->convertLogicalToDevice(unscaledSize);
     if (scaledSize.width() < 1)
         scaledSize.setWidth(1);
     if (scaledSize.height() < 1)
@@ -1287,18 +1287,18 @@ PassRefPtr<ImageData> CanvasRenderingContext2D::createImageData(float sw, float
 
 PassRefPtr<ImageData> CanvasRenderingContext2D::getImageData(float sx, float sy, float sw, float sh, ExceptionCode& ec) const
 {
-    if (!m_canvas->originClean()) {
+    if (!canvas()->originClean()) {
         ec = SECURITY_ERR;
         return 0;
     }
     
     FloatRect unscaledRect(sx, sy, sw, sh);
-    IntRect scaledRect = m_canvas->convertLogicalToDevice(unscaledRect);
+    IntRect scaledRect = canvas()->convertLogicalToDevice(unscaledRect);
     if (scaledRect.width() < 1)
         scaledRect.setWidth(1);
     if (scaledRect.height() < 1)
         scaledRect.setHeight(1);
-    ImageBuffer* buffer = m_canvas ? m_canvas->buffer() : 0;
+    ImageBuffer* buffer = canvas() ? canvas()->buffer() : 0;
     if (!buffer)
         return createEmptyImageData(scaledRect.size());
     return buffer->getUnmultipliedImageData(scaledRect);
@@ -1326,7 +1326,7 @@ void CanvasRenderingContext2D::putImageData(ImageData* data, float dx, float dy,
         return;
     }
 
-    ImageBuffer* buffer = m_canvas->buffer();
+    ImageBuffer* buffer = canvas()->buffer();
     if (!buffer)
         return;
 
@@ -1363,7 +1363,7 @@ String CanvasRenderingContext2D::font() const
 void CanvasRenderingContext2D::setFont(const String& newFont)
 {
     RefPtr<CSSMutableStyleDeclaration> tempDecl = CSSMutableStyleDeclaration::create();
-    CSSParser parser(!m_canvas->document()->inCompatMode()); // Use the parse mode of the canvas' document when parsing CSS.
+    CSSParser parser(!canvas()->document()->inCompatMode()); // Use the parse mode of the canvas' document when parsing CSS.
         
     String declarationText("font: ");
     declarationText += newFont;
@@ -1377,11 +1377,11 @@ void CanvasRenderingContext2D::setFont(const String& newFont)
     // Map the <canvas> font into the text style. If the font uses keywords like larger/smaller, these will work
     // relative to the canvas.
     RefPtr<RenderStyle> newStyle = RenderStyle::create();
-    if (m_canvas->computedStyle())
-        newStyle->setFontDescription(m_canvas->computedStyle()->fontDescription());
+    if (canvas()->computedStyle())
+        newStyle->setFontDescription(canvas()->computedStyle()->fontDescription());
 
     // Now map the font property into the style.
-    CSSStyleSelector* styleSelector = m_canvas->document()->styleSelector();
+    CSSStyleSelector* styleSelector = canvas()->document()->styleSelector();
     styleSelector->applyPropertyToStyle(CSSPropertyFont, tempDecl->getPropertyCSSValue(CSSPropertyFont).get(), newStyle.get());
     
     state().m_font = newStyle->font();
@@ -1455,8 +1455,8 @@ void CanvasRenderingContext2D::drawTextInternal(const String& text, float x, flo
     // FIXME: Handle maxWidth.
     // FIXME: Need to turn off font smoothing.
 
-    bool rtl = m_canvas->computedStyle() ? m_canvas->computedStyle()->direction() == RTL : false;
-    bool override = m_canvas->computedStyle() ? m_canvas->computedStyle()->unicodeBidi() == Override : false;
+    bool rtl = canvas()->computedStyle() ? canvas()->computedStyle()->direction() == RTL : false;
+    bool override = canvas()->computedStyle() ? canvas()->computedStyle()->unicodeBidi() == Override : false;
 
     unsigned length = text.length();
     const UChar* string = text.characters();
@@ -1508,11 +1508,11 @@ void CanvasRenderingContext2D::drawTextInternal(const String& text, float x, flo
         textRect.inflate(c->strokeThickness() / 2);
 
     if (fill)
-        m_canvas->willDraw(textRect);
+        canvas()->willDraw(textRect);
     else {
         // When stroking text, pointy miters can extend outside of textRect, so we
         // punt and dirty the whole canvas.
-        m_canvas->willDraw(FloatRect(0, 0, m_canvas->width(), m_canvas->height()));
+        canvas()->willDraw(FloatRect(0, 0, canvas()->width(), canvas()->height()));
     }
     
 #if PLATFORM(CG)
diff --git a/WebCore/html/canvas/CanvasRenderingContext3D.cpp b/WebCore/html/canvas/CanvasRenderingContext3D.cpp
index 9cca57b..612b4c3 100644
--- a/WebCore/html/canvas/CanvasRenderingContext3D.cpp
+++ b/WebCore/html/canvas/CanvasRenderingContext3D.cpp
@@ -42,12 +42,23 @@
 
 namespace WebCore {
 
-CanvasRenderingContext3D::CanvasRenderingContext3D(HTMLCanvasElement* canvas)
-    : CanvasRenderingContext(canvas)
+PassOwnPtr<CanvasRenderingContext3D> CanvasRenderingContext3D::create(HTMLCanvasElement* canvas)
+{
+    OwnPtr<GraphicsContext3D> context(GraphicsContext3D::create());
+    if (!context)
+        return 0;
+        
+    return new CanvasRenderingContext3D(canvas, context.release());
+}
+
+CanvasRenderingContext3D::CanvasRenderingContext3D(HTMLCanvasElement* passedCanvas, PassOwnPtr<GraphicsContext3D> context)
+    : CanvasRenderingContext(passedCanvas)
+    , m_context(context)
     , m_needsUpdate(true)
     , m_markedCanvasDirty(false)
 {
-    m_context.reshape(m_canvas->width(), m_canvas->height());
+    ASSERT(m_context);
+    m_context->reshape(canvas()->width(), canvas()->height());
 }
 
 CanvasRenderingContext3D::~CanvasRenderingContext3D()
@@ -58,14 +69,14 @@ CanvasRenderingContext3D::~CanvasRenderingContext3D()
 void CanvasRenderingContext3D::markContextChanged()
 {
 #if USE(ACCELERATED_COMPOSITING)
-    if (m_canvas->renderBox() && m_canvas->renderBox()->hasLayer()) {
-        m_canvas->renderBox()->layer()->rendererContentChanged();
+    if (canvas()->renderBox() && canvas()->renderBox()->hasLayer()) {
+        canvas()->renderBox()->layer()->rendererContentChanged();
     } else {
 #endif
         if (!m_markedCanvasDirty) {
             // Make sure the canvas's image buffer is allocated.
-            m_canvas->buffer();
-            m_canvas->willDraw(FloatRect(0, 0, m_canvas->width(), m_canvas->height()));
+            canvas()->buffer();
+            canvas()->willDraw(FloatRect(0, 0, canvas()->width(), canvas()->height()));
             m_markedCanvasDirty = true;
         }
 #if USE(ACCELERATED_COMPOSITING)
@@ -76,7 +87,7 @@ void CanvasRenderingContext3D::markContextChanged()
 void CanvasRenderingContext3D::beginPaint()
 {
     if (m_markedCanvasDirty) {
-        m_context.beginPaint(this);
+        m_context->beginPaint(this);
     }
 }
 
@@ -84,7 +95,7 @@ void CanvasRenderingContext3D::endPaint()
 {
     if (m_markedCanvasDirty) {
         m_markedCanvasDirty = false;
-        m_context.endPaint();
+        m_context->endPaint();
     }
 }
 
@@ -92,18 +103,18 @@ void CanvasRenderingContext3D::reshape(int width, int height)
 {
     if (m_needsUpdate) {
 #if USE(ACCELERATED_COMPOSITING)
-        if (m_canvas->renderBox() && m_canvas->renderBox()->hasLayer())
-            m_canvas->renderBox()->layer()->rendererContentChanged();
+        if (canvas()->renderBox() && canvas()->renderBox()->hasLayer())
+            canvas()->renderBox()->layer()->rendererContentChanged();
 #endif
         m_needsUpdate = false;
     }
     
-    m_context.reshape(width, height);
+    m_context->reshape(width, height);
 }
 
 int CanvasRenderingContext3D::sizeInBytes(int type, ExceptionCode& ec)
 {
-    int result = m_context.sizeInBytes(type);
+    int result = m_context->sizeInBytes(type);
     if (result <= 0) {
         ec = SYNTAX_ERR;
     }
@@ -112,7 +123,7 @@ int CanvasRenderingContext3D::sizeInBytes(int type, ExceptionCode& ec)
 
 void CanvasRenderingContext3D::activeTexture(unsigned long texture)
 {
-    m_context.activeTexture(texture);
+    m_context->activeTexture(texture);
     cleanupAfterGraphicsCall(false);
 }
 
@@ -120,7 +131,7 @@ void CanvasRenderingContext3D::attachShader(CanvasProgram* program, CanvasShader
 {
     if (!program || !shader)
         return;
-    m_context.attachShader(program, shader);
+    m_context->attachShader(program, shader);
     cleanupAfterGraphicsCall(false);
 }
 
@@ -128,94 +139,94 @@ void CanvasRenderingContext3D::bindAttribLocation(CanvasProgram* program, unsign
 {
     if (!program)
         return;
-    m_context.bindAttribLocation(program, index, name);
+    m_context->bindAttribLocation(program, index, name);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::bindBuffer(unsigned long target, CanvasBuffer* buffer)
 {
-    m_context.bindBuffer(target, buffer);
+    m_context->bindBuffer(target, buffer);
     cleanupAfterGraphicsCall(false);
 }
 
 
 void CanvasRenderingContext3D::bindFramebuffer(unsigned long target, CanvasFramebuffer* buffer)
 {
-    m_context.bindFramebuffer(target, buffer);
+    m_context->bindFramebuffer(target, buffer);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::bindRenderbuffer(unsigned long target, CanvasRenderbuffer* renderbuffer)
 {
-    m_context.bindRenderbuffer(target, renderbuffer);
+    m_context->bindRenderbuffer(target, renderbuffer);
     cleanupAfterGraphicsCall(false);
 }
 
 
 void CanvasRenderingContext3D::bindTexture(unsigned long target, CanvasTexture* texture)
 {
-    m_context.bindTexture(target, texture);
+    m_context->bindTexture(target, texture);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::blendColor(double red, double green, double blue, double alpha)
 {
-    m_context.blendColor(red, green, blue, alpha);
+    m_context->blendColor(red, green, blue, alpha);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::blendEquation( unsigned long mode )
 {
-    m_context.blendEquation(mode);
+    m_context->blendEquation(mode);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::blendEquationSeparate(unsigned long modeRGB, unsigned long modeAlpha)
 {
-    m_context.blendEquationSeparate(modeRGB, modeAlpha);
+    m_context->blendEquationSeparate(modeRGB, modeAlpha);
     cleanupAfterGraphicsCall(false);
 }
 
 
 void CanvasRenderingContext3D::blendFunc(unsigned long sfactor, unsigned long dfactor)
 {
-    m_context.blendFunc(sfactor, dfactor);
+    m_context->blendFunc(sfactor, dfactor);
     cleanupAfterGraphicsCall(false);
 }       
 
 void CanvasRenderingContext3D::blendFuncSeparate(unsigned long srcRGB, unsigned long dstRGB, unsigned long srcAlpha, unsigned long dstAlpha)
 {
-    m_context.blendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
+    m_context->blendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::bufferData(unsigned long target, int size, unsigned long usage)
 {
-    m_context.bufferData(target, size, usage);
+    m_context->bufferData(target, size, usage);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::bufferData(unsigned long target, CanvasArray* data, unsigned long usage)
 {
-    m_context.bufferData(target, data, usage);
+    m_context->bufferData(target, data, usage);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::bufferSubData(unsigned long target, long offset, CanvasArray* data)
 {
-    m_context.bufferSubData(target, offset, data);
+    m_context->bufferSubData(target, offset, data);
     cleanupAfterGraphicsCall(false);
 }
 
 unsigned long CanvasRenderingContext3D::checkFramebufferStatus(unsigned long target)
 {
-    return m_context.checkFramebufferStatus(target);
+    return m_context->checkFramebufferStatus(target);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::clear(unsigned long mask)
 {
-    m_context.clear(mask);
+    m_context->clear(mask);
     cleanupAfterGraphicsCall(true);
 }
 
@@ -229,43 +240,43 @@ void CanvasRenderingContext3D::clearColor(double r, double g, double b, double a
         b = 0;
     if (isnan(a))
         a = 1;
-    m_context.clearColor(r, g, b, a);
+    m_context->clearColor(r, g, b, a);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::clearDepth(double depth)
 {
-    m_context.clearDepth(depth);
+    m_context->clearDepth(depth);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::clearStencil(long s)
 {
-    m_context.clearStencil(s);
+    m_context->clearStencil(s);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::colorMask(bool red, bool green, bool blue, bool alpha)
 {
-    m_context.colorMask(red, green, blue, alpha);
+    m_context->colorMask(red, green, blue, alpha);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::compileShader(CanvasShader* shader)
 {
-    m_context.compileShader(shader);
+    m_context->compileShader(shader);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::copyTexImage2D(unsigned long target, long level, unsigned long internalformat, long x, long y, unsigned long width, unsigned long height, long border)
 {
-    m_context.copyTexImage2D(target, level, internalformat, x, y, width, height, border);
+    m_context->copyTexImage2D(target, level, internalformat, x, y, width, height, border);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::copyTexSubImage2D(unsigned long target, long level, long xoffset, long yoffset, long x, long y, unsigned long width, unsigned long height)
 {
-    m_context.copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
+    m_context->copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
     cleanupAfterGraphicsCall(false);
 }
 
@@ -319,7 +330,7 @@ PassRefPtr<CanvasShader> CanvasRenderingContext3D::createShader(unsigned long ty
 
 void CanvasRenderingContext3D::cullFace(unsigned long mode)
 {
-    m_context.cullFace(mode);
+    m_context->cullFace(mode);
     cleanupAfterGraphicsCall(false);
 }
 
@@ -373,19 +384,19 @@ void CanvasRenderingContext3D::deleteTexture(CanvasTexture* texture)
 
 void CanvasRenderingContext3D::depthFunc(unsigned long func)
 {
-    m_context.depthFunc(func);
+    m_context->depthFunc(func);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::depthMask(bool flag)
 {
-    m_context.depthMask(flag);
+    m_context->depthMask(flag);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::depthRange(double zNear, double zFar)
 {
-    m_context.depthRange(zNear, zFar);
+    m_context->depthRange(zNear, zFar);
     cleanupAfterGraphicsCall(false);
 }
 
@@ -394,58 +405,58 @@ void CanvasRenderingContext3D::detachShader(CanvasProgram* program, CanvasShader
     if (!program || !shader)
         return;
 
-    m_context.detachShader(program, shader);
+    m_context->detachShader(program, shader);
     cleanupAfterGraphicsCall(false);
 }
 
 
 void CanvasRenderingContext3D::disable(unsigned long cap)
 {
-    m_context.disable(cap);
+    m_context->disable(cap);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::disableVertexAttribArray(unsigned long index)
 {
-    m_context.disableVertexAttribArray(index);
+    m_context->disableVertexAttribArray(index);
     cleanupAfterGraphicsCall(false);
 }
 
 
 void CanvasRenderingContext3D::drawArrays(unsigned long mode, long first, long count)
 {
-    m_context.drawArrays(mode, first, count);
+    m_context->drawArrays(mode, first, count);
     cleanupAfterGraphicsCall(true);
 }
 
 void CanvasRenderingContext3D::drawElements(unsigned long mode, unsigned long count, unsigned long type, long offset)
 {
-    m_context.drawElements(mode, count, type, offset);
+    m_context->drawElements(mode, count, type, offset);
     cleanupAfterGraphicsCall(true);
 }
 
 void CanvasRenderingContext3D::enable(unsigned long cap)
 {
-    m_context.enable(cap);
+    m_context->enable(cap);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::enableVertexAttribArray(unsigned long index)
 {
-    m_context.enableVertexAttribArray(index);
+    m_context->enableVertexAttribArray(index);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::finish()
 {
-    m_context.finish();
+    m_context->finish();
     cleanupAfterGraphicsCall(true);
 }
 
 
 void CanvasRenderingContext3D::flush()
 {
-    m_context.flush();
+    m_context->flush();
     cleanupAfterGraphicsCall(true);
 }
 
@@ -454,7 +465,7 @@ void CanvasRenderingContext3D::framebufferRenderbuffer(unsigned long target, uns
     if (!buffer)
         return;
         
-    m_context.framebufferRenderbuffer(target, attachment, renderbuffertarget, buffer);
+    m_context->framebufferRenderbuffer(target, attachment, renderbuffertarget, buffer);
     cleanupAfterGraphicsCall(false);
 }
 
@@ -463,26 +474,26 @@ void CanvasRenderingContext3D::framebufferTexture2D(unsigned long target, unsign
     if (!texture)
         return;
         
-    m_context.framebufferTexture2D(target, attachment, textarget, texture, level);
+    m_context->framebufferTexture2D(target, attachment, textarget, texture, level);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::frontFace(unsigned long mode)
 {
-    m_context.frontFace(mode);
+    m_context->frontFace(mode);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::generateMipmap(unsigned long target)
 {
-    m_context.generateMipmap(target);
+    m_context->generateMipmap(target);
     cleanupAfterGraphicsCall(false);
 }
 
 PassRefPtr<CanvasActiveInfo> CanvasRenderingContext3D::getActiveAttrib(CanvasProgram* program, unsigned long index, ExceptionCode& ec)
 {
     ActiveInfo info;
-    if (!program || program->context() != this || !m_context.getActiveAttrib(program, index, info)) {
+    if (!program || program->context() != this || !m_context->getActiveAttrib(program, index, info)) {
         ec = INDEX_SIZE_ERR;
         return 0;
     }
@@ -492,7 +503,7 @@ PassRefPtr<CanvasActiveInfo> CanvasRenderingContext3D::getActiveAttrib(CanvasPro
 PassRefPtr<CanvasActiveInfo> CanvasRenderingContext3D::getActiveUniform(CanvasProgram* program, unsigned long index, ExceptionCode& ec)
 {
     ActiveInfo info;
-    if (!program || program->context() != this || !m_context.getActiveUniform(program, index, info)) {
+    if (!program || program->context() != this || !m_context->getActiveUniform(program, index, info)) {
         ec = INDEX_SIZE_ERR;
         return 0;
     }
@@ -501,251 +512,251 @@ PassRefPtr<CanvasActiveInfo> CanvasRenderingContext3D::getActiveUniform(CanvasPr
 
 int CanvasRenderingContext3D::getAttribLocation(CanvasProgram* program, const String& name)
 {
-    return m_context.getAttribLocation(program, name);
+    return m_context->getAttribLocation(program, name);
 }
 
 bool CanvasRenderingContext3D::getBoolean(unsigned long pname)
 {
-    bool result = m_context.getBoolean(pname);
+    bool result = m_context->getBoolean(pname);
     cleanupAfterGraphicsCall(false);
     return result;
 }
 
 PassRefPtr<CanvasUnsignedByteArray> CanvasRenderingContext3D::getBooleanv(unsigned long pname)
 {
-    RefPtr<CanvasUnsignedByteArray> array = m_context.getBooleanv(pname);
+    RefPtr<CanvasUnsignedByteArray> array = m_context->getBooleanv(pname);
     cleanupAfterGraphicsCall(false);
     return array;
 }
 
 int CanvasRenderingContext3D::getBufferParameteri(unsigned long target, unsigned long pname)
 {
-    int result = m_context.getBufferParameteri(target, pname);
+    int result = m_context->getBufferParameteri(target, pname);
     cleanupAfterGraphicsCall(false);
     return result;
 }
 
 PassRefPtr<CanvasIntArray> CanvasRenderingContext3D::getBufferParameteriv(unsigned long target, unsigned long pname)
 {
-    RefPtr<CanvasIntArray> array = m_context.getBufferParameteriv(target, pname);
+    RefPtr<CanvasIntArray> array = m_context->getBufferParameteriv(target, pname);
     cleanupAfterGraphicsCall(false);
     return array;
 }
 
 unsigned long CanvasRenderingContext3D::getError()
 {
-    return m_context.getError();
+    return m_context->getError();
 }
 
 float CanvasRenderingContext3D::getFloat(unsigned long pname)
 {
-    float result = m_context.getFloat(pname);
+    float result = m_context->getFloat(pname);
     cleanupAfterGraphicsCall(false);
     return result;
 }
 
 PassRefPtr<CanvasFloatArray> CanvasRenderingContext3D::getFloatv(unsigned long pname)
 {
-    RefPtr<CanvasFloatArray> array = m_context.getFloatv(pname);
+    RefPtr<CanvasFloatArray> array = m_context->getFloatv(pname);
     cleanupAfterGraphicsCall(false);
     return array;
 }
 
 int CanvasRenderingContext3D::getFramebufferAttachmentParameteri(unsigned long target, unsigned long attachment, unsigned long pname)
 {
-    int result = m_context.getFramebufferAttachmentParameteri(target, attachment, pname);
+    int result = m_context->getFramebufferAttachmentParameteri(target, attachment, pname);
     cleanupAfterGraphicsCall(false);
     return result;
 }
 
 PassRefPtr<CanvasIntArray> CanvasRenderingContext3D::getFramebufferAttachmentParameteriv(unsigned long target, unsigned long attachment, unsigned long pname)
 {
-    RefPtr<CanvasIntArray> array = m_context.getFramebufferAttachmentParameteriv(target, attachment, pname);
+    RefPtr<CanvasIntArray> array = m_context->getFramebufferAttachmentParameteriv(target, attachment, pname);
     cleanupAfterGraphicsCall(false);
     return array;
 }
 
 int CanvasRenderingContext3D::getInteger(unsigned long pname)
 {
-    float result = m_context.getInteger(pname);
+    float result = m_context->getInteger(pname);
     cleanupAfterGraphicsCall(false);
     return result;
 }
 
 PassRefPtr<CanvasIntArray> CanvasRenderingContext3D::getIntegerv(unsigned long pname)
 {
-    RefPtr<CanvasIntArray> array = m_context.getIntegerv(pname);
+    RefPtr<CanvasIntArray> array = m_context->getIntegerv(pname);
     cleanupAfterGraphicsCall(false);
     return array;
 }
 
 int CanvasRenderingContext3D::getProgrami(CanvasProgram* program, unsigned long pname)
 {
-    int result = m_context.getProgrami(program, pname);
+    int result = m_context->getProgrami(program, pname);
     cleanupAfterGraphicsCall(false);
     return result;
 }
 
 PassRefPtr<CanvasIntArray> CanvasRenderingContext3D::getProgramiv(CanvasProgram* program, unsigned long pname)
 {
-    RefPtr<CanvasIntArray> array = m_context.getProgramiv(program, pname);
+    RefPtr<CanvasIntArray> array = m_context->getProgramiv(program, pname);
     cleanupAfterGraphicsCall(false);
     return array;
 }
 
 String CanvasRenderingContext3D::getProgramInfoLog(CanvasProgram* program)
 {
-    String s = m_context.getProgramInfoLog(program);
+    String s = m_context->getProgramInfoLog(program);
     cleanupAfterGraphicsCall(false);
     return s;
 }
 
 int CanvasRenderingContext3D::getRenderbufferParameteri(unsigned long target, unsigned long pname)
 {
-    int result = m_context.getRenderbufferParameteri(target, pname);
+    int result = m_context->getRenderbufferParameteri(target, pname);
     cleanupAfterGraphicsCall(false);
     return result;
 }
 
 PassRefPtr<CanvasIntArray> CanvasRenderingContext3D::getRenderbufferParameteriv(unsigned long target, unsigned long pname)
 {
-    RefPtr<CanvasIntArray> array = m_context.getRenderbufferParameteriv(target, pname);
+    RefPtr<CanvasIntArray> array = m_context->getRenderbufferParameteriv(target, pname);
     cleanupAfterGraphicsCall(false);
     return array;
 }
 
 int CanvasRenderingContext3D::getShaderi(CanvasShader* shader, unsigned long pname)
 {
-    int result = m_context.getShaderi(shader, pname);
+    int result = m_context->getShaderi(shader, pname);
     cleanupAfterGraphicsCall(false);
     return result;
 }
 
 PassRefPtr<CanvasIntArray> CanvasRenderingContext3D::getShaderiv(CanvasShader* shader, unsigned long pname)
 {
-    RefPtr<CanvasIntArray> array = m_context.getShaderiv(shader, pname);
+    RefPtr<CanvasIntArray> array = m_context->getShaderiv(shader, pname);
     cleanupAfterGraphicsCall(false);
     return array;
 }
 
 String CanvasRenderingContext3D::getShaderInfoLog(CanvasShader* shader)
 {
-    String s = m_context.getShaderInfoLog(shader);
+    String s = m_context->getShaderInfoLog(shader);
     cleanupAfterGraphicsCall(false);
     return s;
 }
 
 String CanvasRenderingContext3D::getShaderSource(CanvasShader* shader)
 {
-    String s = m_context.getShaderSource(shader);
+    String s = m_context->getShaderSource(shader);
     cleanupAfterGraphicsCall(false);
     return s;
 }
 
 String CanvasRenderingContext3D::getString(unsigned long name)
 {
-    return m_context.getString(name);
+    return m_context->getString(name);
 }
 
 float CanvasRenderingContext3D::getTexParameterf(unsigned long target, unsigned long pname)
 {
-    float result = m_context.getTexParameterf(target, pname);
+    float result = m_context->getTexParameterf(target, pname);
     cleanupAfterGraphicsCall(false);
     return result;
 }
 
 PassRefPtr<CanvasFloatArray> CanvasRenderingContext3D::getTexParameterfv(unsigned long target, unsigned long pname)
 {
-    RefPtr<CanvasFloatArray> array = m_context.getTexParameterfv(target, pname);
+    RefPtr<CanvasFloatArray> array = m_context->getTexParameterfv(target, pname);
     cleanupAfterGraphicsCall(false);
     return array;
 }
 
 int CanvasRenderingContext3D::getTexParameteri(unsigned long target, unsigned long pname)
 {
-    int result = m_context.getTexParameteri(target, pname);
+    int result = m_context->getTexParameteri(target, pname);
     cleanupAfterGraphicsCall(false);
     return result;
 }
 
 PassRefPtr<CanvasIntArray> CanvasRenderingContext3D::getTexParameteriv(unsigned long target, unsigned long pname)
 {
-    RefPtr<CanvasIntArray> array = m_context.getTexParameteriv(target, pname);
+    RefPtr<CanvasIntArray> array = m_context->getTexParameteriv(target, pname);
     cleanupAfterGraphicsCall(false);
     return array;
 }
 
 float CanvasRenderingContext3D::getUniformf(CanvasProgram* program, long location)
 {
-    float result = m_context.getUniformf(program, location);
+    float result = m_context->getUniformf(program, location);
     cleanupAfterGraphicsCall(false);
     return result;
 }
 
 PassRefPtr<CanvasFloatArray> CanvasRenderingContext3D::getUniformfv(CanvasProgram* program, long location)
 {
-    RefPtr<CanvasFloatArray> array = m_context.getUniformfv(program, location);
+    RefPtr<CanvasFloatArray> array = m_context->getUniformfv(program, location);
     cleanupAfterGraphicsCall(false);
     return array;
 }
 
 long CanvasRenderingContext3D::getUniformi(CanvasProgram* program, long location)
 {
-    long result = m_context.getUniformi(program, location);
+    long result = m_context->getUniformi(program, location);
     cleanupAfterGraphicsCall(false);
     return result;
 }
 
 PassRefPtr<CanvasIntArray> CanvasRenderingContext3D::getUniformiv(CanvasProgram* program, long location)
 {
-    RefPtr<CanvasIntArray> array = m_context.getUniformiv(program, location);
+    RefPtr<CanvasIntArray> array = m_context->getUniformiv(program, location);
     cleanupAfterGraphicsCall(false);
     return array;
 }
 
 long CanvasRenderingContext3D::getUniformLocation(CanvasProgram* program, const String& name)
 {
-    return m_context.getUniformLocation(program, name);
+    return m_context->getUniformLocation(program, name);
 }
 
 float CanvasRenderingContext3D::getVertexAttribf(unsigned long index, unsigned long pname)
 {
-    float result = m_context.getVertexAttribf(index, pname);
+    float result = m_context->getVertexAttribf(index, pname);
     cleanupAfterGraphicsCall(false);
     return result;
 }
 
 PassRefPtr<CanvasFloatArray> CanvasRenderingContext3D::getVertexAttribfv(unsigned long index, unsigned long pname)
 {
-    RefPtr<CanvasFloatArray> array = m_context.getVertexAttribfv(index, pname);
+    RefPtr<CanvasFloatArray> array = m_context->getVertexAttribfv(index, pname);
     cleanupAfterGraphicsCall(false);
     return array;
 }
 
 long CanvasRenderingContext3D::getVertexAttribi(unsigned long index, unsigned long pname)
 {
-    long result = m_context.getVertexAttribi(index, pname);
+    long result = m_context->getVertexAttribi(index, pname);
     cleanupAfterGraphicsCall(false);
     return result;
 }
 
 PassRefPtr<CanvasIntArray> CanvasRenderingContext3D::getVertexAttribiv(unsigned long index, unsigned long pname)
 {
-    RefPtr<CanvasIntArray> array = m_context.getVertexAttribiv(index, pname);
+    RefPtr<CanvasIntArray> array = m_context->getVertexAttribiv(index, pname);
     cleanupAfterGraphicsCall(false);
     return array;
 }
 
 long CanvasRenderingContext3D::getVertexAttribOffset(unsigned long index, unsigned long pname)
 {
-    long result = m_context.getVertexAttribOffset(index, pname);
+    long result = m_context->getVertexAttribOffset(index, pname);
     cleanupAfterGraphicsCall(false);
     return result;
 }
 
 void CanvasRenderingContext3D::hint(unsigned long target, unsigned long mode)
 {
-    m_context.hint(target, mode);
+    m_context->hint(target, mode);
     cleanupAfterGraphicsCall(false);
 }
 
@@ -754,42 +765,42 @@ bool CanvasRenderingContext3D::isBuffer(CanvasBuffer* buffer)
     if (!buffer)
         return false;
         
-    return m_context.isBuffer(buffer);
+    return m_context->isBuffer(buffer);
 }
 
 bool CanvasRenderingContext3D::isEnabled(unsigned long cap)
 {
-    return m_context.isEnabled(cap);
+    return m_context->isEnabled(cap);
 }
 
 bool CanvasRenderingContext3D::isFramebuffer(CanvasFramebuffer* framebuffer)
 {
-    return m_context.isFramebuffer(framebuffer);
+    return m_context->isFramebuffer(framebuffer);
 }
 
 bool CanvasRenderingContext3D::isProgram(CanvasProgram* program)
 {
-    return m_context.isProgram(program);
+    return m_context->isProgram(program);
 }
 
 bool CanvasRenderingContext3D::isRenderbuffer(CanvasRenderbuffer* renderbuffer)
 {
-    return m_context.isRenderbuffer(renderbuffer);
+    return m_context->isRenderbuffer(renderbuffer);
 }
 
 bool CanvasRenderingContext3D::isShader(CanvasShader* shader)
 {
-    return m_context.isShader(shader);
+    return m_context->isShader(shader);
 }
 
 bool CanvasRenderingContext3D::isTexture(CanvasTexture* texture)
 {
-    return m_context.isTexture(texture);
+    return m_context->isTexture(texture);
 }
 
 void CanvasRenderingContext3D::lineWidth(double width)
 {
-    m_context.lineWidth((float) width);
+    m_context->lineWidth((float) width);
     cleanupAfterGraphicsCall(false);
 }
 
@@ -798,92 +809,92 @@ void CanvasRenderingContext3D::linkProgram(CanvasProgram* program)
     if (!program)
         return;
         
-    m_context.linkProgram(program);
+    m_context->linkProgram(program);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::pixelStorei(unsigned long pname, long param)
 {
-    m_context.pixelStorei(pname, param);
+    m_context->pixelStorei(pname, param);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::polygonOffset(double factor, double units)
 {
-    m_context.polygonOffset((float) factor, (float) units);
+    m_context->polygonOffset((float) factor, (float) units);
     cleanupAfterGraphicsCall(false);
 }
 
 PassRefPtr<CanvasArray> CanvasRenderingContext3D::readPixels(long x, long y, unsigned long width, unsigned long height, unsigned long format, unsigned long type)
 {
-    RefPtr<CanvasArray> array = m_context.readPixels(x, y, width, height, format, type);
+    RefPtr<CanvasArray> array = m_context->readPixels(x, y, width, height, format, type);
     cleanupAfterGraphicsCall(false);
     return array;
 }
 
 void CanvasRenderingContext3D::releaseShaderCompiler()
 {
-    m_context.releaseShaderCompiler();
+    m_context->releaseShaderCompiler();
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::renderbufferStorage(unsigned long target, unsigned long internalformat, unsigned long width, unsigned long height)
 {
-    m_context.renderbufferStorage(target, internalformat, width, height);
+    m_context->renderbufferStorage(target, internalformat, width, height);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::sampleCoverage(double value, bool invert)
 {
-    m_context.sampleCoverage((float) value, invert);
+    m_context->sampleCoverage((float) value, invert);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::scissor(long x, long y, unsigned long width, unsigned long height)
 {
-    m_context.scissor(x, y, width, height);
+    m_context->scissor(x, y, width, height);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::shaderSource(CanvasShader* shader, const String& string)
 {
-    m_context.shaderSource(shader, string);
+    m_context->shaderSource(shader, string);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::stencilFunc(unsigned long func, long ref, unsigned long mask)
 {
-    m_context.stencilFunc(func, ref, mask);
+    m_context->stencilFunc(func, ref, mask);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::stencilFuncSeparate(unsigned long face, unsigned long func, long ref, unsigned long mask)
 {
-    m_context.stencilFuncSeparate(face, func, ref, mask);
+    m_context->stencilFuncSeparate(face, func, ref, mask);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::stencilMask(unsigned long mask)
 {
-    m_context.stencilMask(mask);
+    m_context->stencilMask(mask);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::stencilMaskSeparate(unsigned long face, unsigned long mask)
 {
-    m_context.stencilMaskSeparate(face, mask);
+    m_context->stencilMaskSeparate(face, mask);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::stencilOp(unsigned long fail, unsigned long zfail, unsigned long zpass)
 {
-    m_context.stencilOp(fail, zfail, zpass);
+    m_context->stencilOp(fail, zfail, zpass);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::stencilOpSeparate(unsigned long face, unsigned long fail, unsigned long zfail, unsigned long zpass)
 {
-    m_context.stencilOpSeparate(face, fail, zfail, zpass);
+    m_context->stencilOpSeparate(face, fail, zfail, zpass);
     cleanupAfterGraphicsCall(false);
 }
 
@@ -893,7 +904,7 @@ void CanvasRenderingContext3D::texImage2D(unsigned target, unsigned level, unsig
 {
     // FIXME: For now we ignore any errors returned
     ec = 0;
-    m_context.texImage2D(target, level, internalformat, width, height,
+    m_context->texImage2D(target, level, internalformat, width, height,
                          border, format, type, pixels);
     cleanupAfterGraphicsCall(false);
 }
@@ -904,7 +915,7 @@ void CanvasRenderingContext3D::texImage2D(unsigned target, unsigned level, unsig
 {
     // FIXME: For now we ignore any errors returned
     ec = 0;
-    m_context.texImage2D(target, level, internalformat, width, height,
+    m_context->texImage2D(target, level, internalformat, width, height,
                          border, format, type, pixels);
     cleanupAfterGraphicsCall(false);
 }
@@ -914,7 +925,7 @@ void CanvasRenderingContext3D::texImage2D(unsigned target, unsigned level, HTMLI
 {
     // FIXME: For now we ignore any errors returned
     ec = 0;
-    m_context.texImage2D(target, level, image, flipY, premultiplyAlpha);
+    m_context->texImage2D(target, level, image, flipY, premultiplyAlpha);
     cleanupAfterGraphicsCall(false);
 }
 
@@ -923,7 +934,7 @@ void CanvasRenderingContext3D::texImage2D(unsigned target, unsigned level, HTMLC
 {
     // FIXME: For now we ignore any errors returned
     ec = 0;
-    m_context.texImage2D(target, level, canvas, flipY, premultiplyAlpha);
+    m_context->texImage2D(target, level, canvas, flipY, premultiplyAlpha);
     cleanupAfterGraphicsCall(false);
 }
 
@@ -932,19 +943,19 @@ void CanvasRenderingContext3D::texImage2D(unsigned target, unsigned level, HTMLV
 {
     // FIXME: For now we ignore any errors returned
     ec = 0;
-    m_context.texImage2D(target, level, video, flipY, premultiplyAlpha);
+    m_context->texImage2D(target, level, video, flipY, premultiplyAlpha);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::texParameterf(unsigned target, unsigned pname, float param)
 {
-    m_context.texParameterf(target, pname, param);
+    m_context->texParameterf(target, pname, param);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::texParameteri(unsigned target, unsigned pname, int param)
 {
-    m_context.texParameteri(target, pname, param);
+    m_context->texParameteri(target, pname, param);
     cleanupAfterGraphicsCall(false);
 }
 
@@ -954,7 +965,7 @@ void CanvasRenderingContext3D::texSubImage2D(unsigned target, unsigned level, un
 {
     // FIXME: For now we ignore any errors returned
     ec = 0;
-    m_context.texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
+    m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
     cleanupAfterGraphicsCall(false);
 }
 
@@ -964,7 +975,7 @@ void CanvasRenderingContext3D::texSubImage2D(unsigned target, unsigned level, un
 {
     // FIXME: For now we ignore any errors returned
     ec = 0;
-    m_context.texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
+    m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
     cleanupAfterGraphicsCall(false);
 }
 
@@ -974,7 +985,7 @@ void CanvasRenderingContext3D::texSubImage2D(unsigned target, unsigned level, un
 {
     // FIXME: For now we ignore any errors returned
     ec = 0;
-    m_context.texSubImage2D(target, level, xoffset, yoffset, width, height, image, flipY, premultiplyAlpha);
+    m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, image, flipY, premultiplyAlpha);
     cleanupAfterGraphicsCall(false);
 }
 
@@ -984,7 +995,7 @@ void CanvasRenderingContext3D::texSubImage2D(unsigned target, unsigned level, un
 {
     // FIXME: For now we ignore any errors returned
     ec = 0;
-    m_context.texSubImage2D(target, level, xoffset, yoffset, width, height, canvas, flipY, premultiplyAlpha);
+    m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, canvas, flipY, premultiplyAlpha);
     cleanupAfterGraphicsCall(false);
 }
 
@@ -994,13 +1005,13 @@ void CanvasRenderingContext3D::texSubImage2D(unsigned target, unsigned level, un
 {
     // FIXME: For now we ignore any errors returned
     ec = 0;
-    m_context.texSubImage2D(target, level, xoffset, yoffset, width, height, video, flipY, premultiplyAlpha);
+    m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, video, flipY, premultiplyAlpha);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::uniform1f(long location, float x)
 {
-    m_context.uniform1f(location, x);
+    m_context->uniform1f(location, x);
     cleanupAfterGraphicsCall(false);
 }
 
@@ -1010,7 +1021,7 @@ void CanvasRenderingContext3D::uniform1fv(long location, CanvasFloatArray* v)
     if (!v)
         return;
         
-    m_context.uniform1fv(location, v->data(), v->length());
+    m_context->uniform1fv(location, v->data(), v->length());
     cleanupAfterGraphicsCall(false);
 }
 
@@ -1020,13 +1031,13 @@ void CanvasRenderingContext3D::uniform1fv(long location, float* v, int size)
     if (!v)
         return;
         
-    m_context.uniform1fv(location, v, size);
+    m_context->uniform1fv(location, v, size);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::uniform1i(long location, int x)
 {
-    m_context.uniform1i(location, x);
+    m_context->uniform1i(location, x);
     cleanupAfterGraphicsCall(false);
 }
 
@@ -1036,7 +1047,7 @@ void CanvasRenderingContext3D::uniform1iv(long location, CanvasIntArray* v)
     if (!v)
         return;
         
-    m_context.uniform1iv(location, v->data(), v->length());
+    m_context->uniform1iv(location, v->data(), v->length());
     cleanupAfterGraphicsCall(false);
 }
 
@@ -1046,13 +1057,13 @@ void CanvasRenderingContext3D::uniform1iv(long location, int* v, int size)
     if (!v)
         return;
         
-    m_context.uniform1iv(location, v, size);
+    m_context->uniform1iv(location, v, size);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::uniform2f(long location, float x, float y)
 {
-    m_context.uniform2f(location, x, y);
+    m_context->uniform2f(location, x, y);
     cleanupAfterGraphicsCall(false);
 }
 
@@ -1063,7 +1074,7 @@ void CanvasRenderingContext3D::uniform2fv(long location, CanvasFloatArray* v)
         return;
         
     // FIXME: length needs to be a multiple of 2
-    m_context.uniform2fv(location, v->data(), v->length() / 2);
+    m_context->uniform2fv(location, v->data(), v->length() / 2);
     cleanupAfterGraphicsCall(false);
 }
 
@@ -1074,13 +1085,13 @@ void CanvasRenderingContext3D::uniform2fv(long location, float* v, int size)
         return;
         
     // FIXME: length needs to be a multiple of 2
-    m_context.uniform2fv(location, v, size / 2);
+    m_context->uniform2fv(location, v, size / 2);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::uniform2i(long location, int x, int y)
 {
-    m_context.uniform2i(location, x, y);
+    m_context->uniform2i(location, x, y);
     cleanupAfterGraphicsCall(false);
 }
 
@@ -1091,7 +1102,7 @@ void CanvasRenderingContext3D::uniform2iv(long location, CanvasIntArray* v)
         return;
         
     // FIXME: length needs to be a multiple of 2
-    m_context.uniform2iv(location, v->data(), v->length() / 2);
+    m_context->uniform2iv(location, v->data(), v->length() / 2);
     cleanupAfterGraphicsCall(false);
 }
 
@@ -1102,13 +1113,13 @@ void CanvasRenderingContext3D::uniform2iv(long location, int* v, int size)
         return;
         
     // FIXME: length needs to be a multiple of 2
-    m_context.uniform2iv(location, v, size / 2);
+    m_context->uniform2iv(location, v, size / 2);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::uniform3f(long location, float x, float y, float z)
 {
-    m_context.uniform3f(location, x, y, z);
+    m_context->uniform3f(location, x, y, z);
     cleanupAfterGraphicsCall(false);
 }
 
@@ -1119,7 +1130,7 @@ void CanvasRenderingContext3D::uniform3fv(long location, CanvasFloatArray* v)
         return;
         
     // FIXME: length needs to be a multiple of 3
-    m_context.uniform3fv(location, v->data(), v->length() / 3);
+    m_context->uniform3fv(location, v->data(), v->length() / 3);
     cleanupAfterGraphicsCall(false);
 }
 
@@ -1130,13 +1141,13 @@ void CanvasRenderingContext3D::uniform3fv(long location, float* v, int size)
         return;
         
     // FIXME: length needs to be a multiple of 3
-    m_context.uniform3fv(location, v, size / 3);
+    m_context->uniform3fv(location, v, size / 3);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::uniform3i(long location, int x, int y, int z)
 {
-    m_context.uniform3i(location, x, y, z);
+    m_context->uniform3i(location, x, y, z);
     cleanupAfterGraphicsCall(false);
 }
 
@@ -1147,7 +1158,7 @@ void CanvasRenderingContext3D::uniform3iv(long location, CanvasIntArray* v)
         return;
         
     // FIXME: length needs to be a multiple of 3
-    m_context.uniform3iv(location, v->data(), v->length() / 3);
+    m_context->uniform3iv(location, v->data(), v->length() / 3);
     cleanupAfterGraphicsCall(false);
 }
 
@@ -1158,13 +1169,13 @@ void CanvasRenderingContext3D::uniform3iv(long location, int* v, int size)
         return;
         
     // FIXME: length needs to be a multiple of 3
-    m_context.uniform3iv(location, v, size / 3);
+    m_context->uniform3iv(location, v, size / 3);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::uniform4f(long location, float x, float y, float z, float w)
 {
-    m_context.uniform4f(location, x, y, z, w);
+    m_context->uniform4f(location, x, y, z, w);
     cleanupAfterGraphicsCall(false);
 }
 
@@ -1175,7 +1186,7 @@ void CanvasRenderingContext3D::uniform4fv(long location, CanvasFloatArray* v)
         return;
         
     // FIXME: length needs to be a multiple of 4
-    m_context.uniform4fv(location, v->data(), v->length() / 4);
+    m_context->uniform4fv(location, v->data(), v->length() / 4);
     cleanupAfterGraphicsCall(false);
 }
 
@@ -1186,13 +1197,13 @@ void CanvasRenderingContext3D::uniform4fv(long location, float* v, int size)
         return;
         
     // FIXME: length needs to be a multiple of 4
-    m_context.uniform4fv(location, v, size / 4);
+    m_context->uniform4fv(location, v, size / 4);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::uniform4i(long location, int x, int y, int z, int w)
 {
-    m_context.uniform4i(location, x, y, z, w);
+    m_context->uniform4i(location, x, y, z, w);
     cleanupAfterGraphicsCall(false);
 }
 
@@ -1203,7 +1214,7 @@ void CanvasRenderingContext3D::uniform4iv(long location, CanvasIntArray* v)
         return;
         
     // FIXME: length needs to be a multiple of 4
-    m_context.uniform4iv(location, v->data(), v->length() / 4);
+    m_context->uniform4iv(location, v->data(), v->length() / 4);
     cleanupAfterGraphicsCall(false);
 }
 
@@ -1214,7 +1225,7 @@ void CanvasRenderingContext3D::uniform4iv(long location, int* v, int size)
         return;
         
     // FIXME: length needs to be a multiple of 4
-    m_context.uniform4iv(location, v, size / 4);
+    m_context->uniform4iv(location, v, size / 4);
     cleanupAfterGraphicsCall(false);
 }
 
@@ -1225,7 +1236,7 @@ void CanvasRenderingContext3D::uniformMatrix2fv(long location, bool transpose, C
         return;
         
     // FIXME: length needs to be a multiple of 4
-    m_context.uniformMatrix2fv(location, transpose, v->data(), v->length() / 4);
+    m_context->uniformMatrix2fv(location, transpose, v->data(), v->length() / 4);
     cleanupAfterGraphicsCall(false);
 }
 
@@ -1236,7 +1247,7 @@ void CanvasRenderingContext3D::uniformMatrix2fv(long location, bool transpose, f
         return;
         
     // FIXME: length needs to be a multiple of 4
-    m_context.uniformMatrix2fv(location, transpose, v, size / 4);
+    m_context->uniformMatrix2fv(location, transpose, v, size / 4);
     cleanupAfterGraphicsCall(false);
 }
 
@@ -1247,7 +1258,7 @@ void CanvasRenderingContext3D::uniformMatrix3fv(long location, bool transpose, C
         return;
         
     // FIXME: length needs to be a multiple of 9
-    m_context.uniformMatrix3fv(location, transpose, v->data(), v->length() / 9);
+    m_context->uniformMatrix3fv(location, transpose, v->data(), v->length() / 9);
     cleanupAfterGraphicsCall(false);
 }
 
@@ -1258,7 +1269,7 @@ void CanvasRenderingContext3D::uniformMatrix3fv(long location, bool transpose, f
         return;
         
     // FIXME: length needs to be a multiple of 9
-    m_context.uniformMatrix3fv(location, transpose, v, size / 9);
+    m_context->uniformMatrix3fv(location, transpose, v, size / 9);
     cleanupAfterGraphicsCall(false);
 }
 
@@ -1269,7 +1280,7 @@ void CanvasRenderingContext3D::uniformMatrix4fv(long location, bool transpose, C
         return;
         
     // FIXME: length needs to be a multiple of 16
-    m_context.uniformMatrix4fv(location, transpose, v->data(), v->length() / 16);
+    m_context->uniformMatrix4fv(location, transpose, v->data(), v->length() / 16);
     cleanupAfterGraphicsCall(false);
 }
 
@@ -1280,32 +1291,32 @@ void CanvasRenderingContext3D::uniformMatrix4fv(long location, bool transpose, f
         return;
         
     // FIXME: length needs to be a multiple of 16
-    m_context.uniformMatrix4fv(location, transpose, v, size / 16);
+    m_context->uniformMatrix4fv(location, transpose, v, size / 16);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::useProgram(CanvasProgram* program)
 {
-    m_context.useProgram(program);
+    m_context->useProgram(program);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::validateProgram(CanvasProgram* program)
 {
-    m_context.validateProgram(program);
+    m_context->validateProgram(program);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::vertexAttrib1f(unsigned long indx, float v0)
 {
-    m_context.vertexAttrib1f(indx, v0);
+    m_context->vertexAttrib1f(indx, v0);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::vertexAttrib1fv(unsigned long indx, CanvasFloatArray* v)
 {
     // FIXME: Need to make sure array is big enough for attribute being set
-    m_context.vertexAttrib1fv(indx, v->data());
+    m_context->vertexAttrib1fv(indx, v->data());
     cleanupAfterGraphicsCall(false);
 }
 
@@ -1314,20 +1325,20 @@ void CanvasRenderingContext3D::vertexAttrib1fv(unsigned long indx, float* v, int
     // FIXME: Need to make sure array is big enough for attribute being set
     UNUSED_PARAM(size);
     
-    m_context.vertexAttrib1fv(indx, v);
+    m_context->vertexAttrib1fv(indx, v);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::vertexAttrib2f(unsigned long indx, float v0, float v1)
 {
-    m_context.vertexAttrib2f(indx, v0, v1);
+    m_context->vertexAttrib2f(indx, v0, v1);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::vertexAttrib2fv(unsigned long indx, CanvasFloatArray* v)
 {
     // FIXME: Need to make sure array is big enough for attribute being set
-    m_context.vertexAttrib2fv(indx, v->data());
+    m_context->vertexAttrib2fv(indx, v->data());
     cleanupAfterGraphicsCall(false);
 }
 
@@ -1336,20 +1347,20 @@ void CanvasRenderingContext3D::vertexAttrib2fv(unsigned long indx, float* v, int
     // FIXME: Need to make sure array is big enough for attribute being set
     UNUSED_PARAM(size);
     
-    m_context.vertexAttrib2fv(indx, v);
+    m_context->vertexAttrib2fv(indx, v);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::vertexAttrib3f(unsigned long indx, float v0, float v1, float v2)
 {
-    m_context.vertexAttrib3f(indx, v0, v1, v2);
+    m_context->vertexAttrib3f(indx, v0, v1, v2);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::vertexAttrib3fv(unsigned long indx, CanvasFloatArray* v)
 {
     // FIXME: Need to make sure array is big enough for attribute being set
-    m_context.vertexAttrib3fv(indx, v->data());
+    m_context->vertexAttrib3fv(indx, v->data());
     cleanupAfterGraphicsCall(false);
 }
 
@@ -1358,20 +1369,20 @@ void CanvasRenderingContext3D::vertexAttrib3fv(unsigned long indx, float* v, int
     // FIXME: Need to make sure array is big enough for attribute being set
     UNUSED_PARAM(size);
     
-    m_context.vertexAttrib3fv(indx, v);
+    m_context->vertexAttrib3fv(indx, v);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::vertexAttrib4f(unsigned long indx, float v0, float v1, float v2, float v3)
 {
-    m_context.vertexAttrib4f(indx, v0, v1, v2, v3);
+    m_context->vertexAttrib4f(indx, v0, v1, v2, v3);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::vertexAttrib4fv(unsigned long indx, CanvasFloatArray* v)
 {
     // FIXME: Need to make sure array is big enough for attribute being set
-    m_context.vertexAttrib4fv(indx, v->data());
+    m_context->vertexAttrib4fv(indx, v->data());
     cleanupAfterGraphicsCall(false);
 }
 
@@ -1380,13 +1391,13 @@ void CanvasRenderingContext3D::vertexAttrib4fv(unsigned long indx, float* v, int
     // FIXME: Need to make sure array is big enough for attribute being set
     UNUSED_PARAM(size);
     
-    m_context.vertexAttrib4fv(indx, v);
+    m_context->vertexAttrib4fv(indx, v);
     cleanupAfterGraphicsCall(false);
 }
 
 void CanvasRenderingContext3D::vertexAttribPointer(unsigned long indx, long size, unsigned long type, bool normalized, unsigned long stride, unsigned long offset)
 {
-    m_context.vertexAttribPointer(indx, size, type, normalized, stride, offset);
+    m_context->vertexAttribPointer(indx, size, type, normalized, stride, offset);
     cleanupAfterGraphicsCall(false);
 }
 
@@ -1400,7 +1411,7 @@ void CanvasRenderingContext3D::viewport(long x, long y, unsigned long width, uns
         width = 100;
     if (isnan(height))
         height = 100;
-    m_context.viewport(x, y, width, height);
+    m_context->viewport(x, y, width, height);
     cleanupAfterGraphicsCall(false);
 }
 
diff --git a/WebCore/html/canvas/CanvasRenderingContext3D.h b/WebCore/html/canvas/CanvasRenderingContext3D.h
index 526281b..70d9b95 100644
--- a/WebCore/html/canvas/CanvasRenderingContext3D.h
+++ b/WebCore/html/canvas/CanvasRenderingContext3D.h
@@ -51,8 +51,8 @@ class WebKitCSSMatrix;
 
     class CanvasRenderingContext3D : public CanvasRenderingContext {
     public:
-        CanvasRenderingContext3D(HTMLCanvasElement*);
-        ~CanvasRenderingContext3D();
+        static PassOwnPtr<CanvasRenderingContext3D> create(HTMLCanvasElement*);
+        virtual ~CanvasRenderingContext3D();
 
         virtual bool is3d() const { return true; }
 
@@ -288,7 +288,7 @@ class WebKitCSSMatrix;
 
         void viewport(long x, long y, unsigned long width, unsigned long height);
 
-        GraphicsContext3D* graphicsContext3D() { return &m_context; }
+        GraphicsContext3D* graphicsContext3D() const { return m_context.get(); }
     
         void reshape(int width, int height);
 
@@ -300,18 +300,21 @@ class WebKitCSSMatrix;
         
     private:
         friend class CanvasObject;
+
+        CanvasRenderingContext3D(HTMLCanvasElement*, PassOwnPtr<GraphicsContext3D>);
+
         void addObject(CanvasObject*);
         void detachAndRemoveAllObjects();
 
         void markContextChanged();
         void cleanupAfterGraphicsCall(bool changed)
         {
-            m_context.checkError();
+            m_context->checkError();
             if (changed)
                 markContextChanged();
         }
         
-        GraphicsContext3D m_context;
+        OwnPtr<GraphicsContext3D> m_context;
         bool m_needsUpdate;
         bool m_markedCanvasDirty;
         // FIXME: I think this is broken -- it does not increment any
diff --git a/WebCore/platform/graphics/GraphicsContext3D.h b/WebCore/platform/graphics/GraphicsContext3D.h
index 67224e2..9fcb523 100644
--- a/WebCore/platform/graphics/GraphicsContext3D.h
+++ b/WebCore/platform/graphics/GraphicsContext3D.h
@@ -74,11 +74,11 @@ namespace WebCore {
     class GraphicsContext3DInternal;
 #endif
 
-    class GraphicsContext3D : Noncopyable {
+    class GraphicsContext3D : public Noncopyable {
     public:
         enum ShaderType { FRAGMENT_SHADER, VERTEX_SHADER };
     
-        GraphicsContext3D();
+        static PassOwnPtr<GraphicsContext3D> create();
         virtual ~GraphicsContext3D();
 
 #if PLATFORM(MAC)
@@ -92,7 +92,6 @@ namespace WebCore {
         Platform3DObject platformTexture() const { return NullPlatform3DObject; }
 #endif
         void checkError() const;
-        
         void makeContextCurrent();
         
         // Helper to return the size in bytes of OpenGL data types
@@ -320,6 +319,8 @@ namespace WebCore {
         void deleteTexture(unsigned);        
         
     private:        
+        GraphicsContext3D();
+
         int m_currentWidth, m_currentHeight;
         
 #if PLATFORM(MAC)
diff --git a/WebCore/platform/graphics/mac/Canvas3DLayer.mm b/WebCore/platform/graphics/mac/Canvas3DLayer.mm
index 517e03f..94819d4 100644
--- a/WebCore/platform/graphics/mac/Canvas3DLayer.mm
+++ b/WebCore/platform/graphics/mac/Canvas3DLayer.mm
@@ -50,19 +50,14 @@ using namespace WebCore;
 
 -(CGLPixelFormatObj)copyCGLPixelFormatForDisplayMask:(uint32_t)mask
 {
-    CGLPixelFormatAttribute attribs[] =
-    {
-        (CGLPixelFormatAttribute) kCGLPFAAccelerated,
-        (CGLPixelFormatAttribute) kCGLPFAColorSize, (CGLPixelFormatAttribute) 32,
-        (CGLPixelFormatAttribute) kCGLPFADisplayMask, (CGLPixelFormatAttribute) mask,
-        (CGLPixelFormatAttribute) 0
-    };
-    
-    CGLPixelFormatObj pixelFormatObj;
-    GLint numPixelFormats;
- 
-    CGLChoosePixelFormat(attribs, &pixelFormatObj, &numPixelFormats);
-    return pixelFormatObj;
+    // FIXME: The mask param tells you which display (on a multi-display system)
+    // is to be used. But since we are now getting the pixel format from the 
+    // Canvas CGL context, we don't use it. This seems to do the right thing on
+    // one multi-display system. But there may be cases where this is not the case.
+    // If needed we will have to set the display mask in the Canvas CGLContext and
+    // make sure it matches.
+    UNUSED_PARAM(mask);
+    return CGLRetainPixelFormat(CGLGetPixelFormat(m_contextObj));
 }
 
 -(CGLContextObj)copyCGLContextForPixelFormat:(CGLPixelFormatObj)pixelFormat
diff --git a/WebCore/platform/graphics/mac/GraphicsContext3DMac.cpp b/WebCore/platform/graphics/mac/GraphicsContext3DMac.cpp
index bc17595..47617d8 100644
--- a/WebCore/platform/graphics/mac/GraphicsContext3DMac.cpp
+++ b/WebCore/platform/graphics/mac/GraphicsContext3DMac.cpp
@@ -50,54 +50,76 @@
 #include "WebKitCSSMatrix.h"
 
 #include <CoreGraphics/CGBitmapContext.h>
+#include <OpenGL/CGLRenderers.h>
 
 namespace WebCore {
 
+static void setPixelFormat(Vector<CGLPixelFormatAttribute>& attribs, int colorBits, int depthBits, bool accelerated, bool supersample, bool closest)
+{
+    attribs.clear();
+    
+    attribs.append(kCGLPFAColorSize);
+    attribs.append(static_cast<CGLPixelFormatAttribute>(colorBits));
+    attribs.append(kCGLPFADepthSize);
+    attribs.append(static_cast<CGLPixelFormatAttribute>(depthBits));
+    
+    if (accelerated)
+        attribs.append(kCGLPFAAccelerated);
+    else {
+        attribs.append(kCGLPFARendererID);
+        attribs.append(static_cast<CGLPixelFormatAttribute>(kCGLRendererGenericFloatID));
+    }
+        
+    if (supersample)
+        attribs.append(kCGLPFASupersample);
+        
+    if (closest)
+        attribs.append(kCGLPFAClosestPolicy);
+        
+    attribs.append(static_cast<CGLPixelFormatAttribute>(0));
+}
+
+PassOwnPtr<GraphicsContext3D> GraphicsContext3D::create()
+{
+    OwnPtr<GraphicsContext3D> context(new GraphicsContext3D());
+    return context->m_contextObj ? context.release() : 0;
+}
+
 GraphicsContext3D::GraphicsContext3D()
     : m_contextObj(0)
     , m_texture(0)
     , m_fbo(0)
     , m_depthBuffer(0)
 {
-    CGLPixelFormatAttribute attribs[] =
-    {
-        kCGLPFAClosestPolicy,
-        (CGLPixelFormatAttribute) kCGLPFAColorSize, (CGLPixelFormatAttribute) 32,
-        (CGLPixelFormatAttribute) kCGLPFADepthSize, (CGLPixelFormatAttribute) 32,
-        (CGLPixelFormatAttribute) kCGLPFAAccelerated,
-        (CGLPixelFormatAttribute) kCGLPFASupersample,
-        (CGLPixelFormatAttribute) 0
-    };
-    
-    // Make sure to change these constants to match the above list
-    const int superSampleIndex = 6;
-    const int acceleratedIndex = 5;
-    const int depthSizeIndex = 4;
-    
+    Vector<CGLPixelFormatAttribute> attribs;
     CGLPixelFormatObj pixelFormatObj = 0;
     GLint numPixelFormats = 0;
     
-    // We will try for the above format first. If that fails, we will
-    // try for one without supersample. If that fails, we will try for
-    // one that has a 16 bit depth buffer. If that fails, we will try
-    // for a software renderer. If none of that works, we simply fail 
-    // and set m_contextObj to 0.
-    CGLChoosePixelFormat(attribs, &pixelFormatObj, &numPixelFormats);
+    // We will try:
+    //
+    //  1) 32 bit RGBA/32 bit depth/accelerated/supersampled
+    //  2) 32 bit RGBA/32 bit depth/accelerated
+    //  3) 32 bit RGBA/16 bit depth/accelerated
+    //  4) closest to 32 bit RGBA/16 bit depth/software renderer
+    //
+    //  If none of that works, we simply fail and set m_contextObj to 0.
+    
+    setPixelFormat(attribs, 32, 32, true, true, false);
+    CGLChoosePixelFormat(attribs.data(), &pixelFormatObj, &numPixelFormats);
     if (numPixelFormats == 0) {
-        attribs[superSampleIndex] = static_cast<CGLPixelFormatAttribute>(0);
-        CGLChoosePixelFormat(attribs, &pixelFormatObj, &numPixelFormats);
+        setPixelFormat(attribs, 32, 32, true, false, false);
+        CGLChoosePixelFormat(attribs.data(), &pixelFormatObj, &numPixelFormats);
         
         if (numPixelFormats == 0) {
-            attribs[depthSizeIndex] = static_cast<CGLPixelFormatAttribute>(16);
-            CGLChoosePixelFormat(attribs, &pixelFormatObj, &numPixelFormats);
+            setPixelFormat(attribs, 32, 16, true, false, false);
+            CGLChoosePixelFormat(attribs.data(), &pixelFormatObj, &numPixelFormats);
         
             if (numPixelFormats == 0) {
-                attribs[acceleratedIndex] = static_cast<CGLPixelFormatAttribute>(0);
-                CGLChoosePixelFormat(attribs, &pixelFormatObj, &numPixelFormats);
+                setPixelFormat(attribs, 32, 16, false, false, true);
+                CGLChoosePixelFormat(attribs.data(), &pixelFormatObj, &numPixelFormats);
         
                 if (numPixelFormats == 0) {
                     // Could not find an acceptable renderer - fail
-                    m_contextObj = 0;
                     return;
                 }
             }
@@ -143,12 +165,14 @@ GraphicsContext3D::GraphicsContext3D()
 
 GraphicsContext3D::~GraphicsContext3D()
 {
-    CGLSetCurrentContext(m_contextObj);
-    ::glDeleteRenderbuffersEXT(1, & m_depthBuffer);
-    ::glDeleteTextures(1, &m_texture);
-    ::glDeleteFramebuffersEXT(1, &m_fbo);
-    CGLSetCurrentContext(0);
-    CGLDestroyContext(m_contextObj);
+    if (m_contextObj) {
+        CGLSetCurrentContext(m_contextObj);
+        ::glDeleteRenderbuffersEXT(1, & m_depthBuffer);
+        ::glDeleteTextures(1, &m_texture);
+        ::glDeleteFramebuffersEXT(1, &m_fbo);
+        CGLSetCurrentContext(0);
+        CGLDestroyContext(m_contextObj);
+    }
 }
 
 void GraphicsContext3D::checkError() const
@@ -176,7 +200,7 @@ void GraphicsContext3D::endPaint()
 
 void GraphicsContext3D::reshape(int width, int height)
 {
-    if (width == m_currentWidth && height == m_currentHeight)
+    if (width == m_currentWidth && height == m_currentHeight || !m_contextObj)
         return;
     
     m_currentWidth = width;
@@ -208,6 +232,9 @@ void GraphicsContext3D::reshape(int width, int height)
 
 static inline void ensureContext(CGLContextObj context)
 {
+    if (!context)
+        return;
+        
     CGLContextObj currentContext = CGLGetCurrentContext();
     if (currentContext != context)
         CGLSetCurrentContext(context);

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list