Commit 4e7728f4 authored by cmarrin@apple.com's avatar cmarrin@apple.com

Final patch for Canvas 3D support

        https://bugs.webkit.org/show_bug.cgi?id=28018

        This hooks everything up and provides a working implementation of
        Canvas 3D. I plumb the creation of the 3D canvas down to GraphicsLayer,
        passing the opaque context and texture pointers so a Canvas3DLayer can be
        created (more on that later). It also plumbs changes to the 3D canvas so
        that Canvas3DLayer can recomposite the results.
        
        A 3D Canvas element needs a RenderLayer and compositing layer to render.
        This is because it renders to an off-screen texture in the GPU and then
        hands it to a Canvas3DLayer, which is a subclass of CAOpenGLLayer, to
        render that texture as a 3D quad. This keeps everything in GPU memory to 
        maximize performance. When a CanvasRenderingContext3D is created it 
        forces a style recalc which creates the RenderLayer and compositing 
        layer if needed. 
        
        I repurposed an existing flag which was put in place for animation to accomplish 
        this. This flag is passed to setNeedsStyleRecalc(), and I renamed it from 
        AnimationStyleChange to SyntheticStyleChange. It essentially says that you need
        to do a complete style recalc, even though the style itself has not really
        changed.
        
        This patch also fixes a couple of bugs discovered when testing with 3d-canvas
        turned on. I also added a constructor DOMWindow.idl for CanvasRenderingContext3D.
        This is needed when making a JS wrapper for the object so the prototype 
        property can be set.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@47843 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent bf58e2cb
2009-08-27 Chris Marrin <cmarrin@apple.com>
Reviewed by Simon Fraser.
Modified tests to work when 3D-CANVAS flag is on and added a test for crashing when context is changed
https://bugs.webkit.org/show_bug.cgi?id=28018
* fast/canvas/change-context-expected.txt: Added.
* fast/canvas/change-context.html: Added.
* fast/dom/Window/window-properties.html:
* fast/dom/resources/prototype-inheritance-2.js:
(constructorNamesForWindow):
* fast/dom/resources/prototype-inheritance.js:
2009-08-27 Drew Wilson <atwilson@google.com>
Unreviewed.
......
This test ensures that changing the context does not crash.
This test ensures that changing the context does not crash.
<canvas id="canvas"></canvas><br />
<script>
if (window.layoutTestController)
layoutTestController.dumpAsText();
var canvas = document.getElementById("canvas");
var ctx1 = canvas.getContext("2d");
var ctx2 = canvas.getContext("");
ctx1.save();
canvas.parentNode.removeChild(canvas);
if (window.GCController)
GCController.collect();
ctx1.save();
</script>
......@@ -60,7 +60,8 @@ var __skip__ = {
"window.objCPlugin" : 1,
"window.objCPluginFunction" : 1,
"window.plainText" : 1,
"window.textInputController" : 1
"window.textInputController" : 1,
"window.CanvasRenderingContext3D" : 1 // We ignore CanvasRenderingContext3D and test it elsewhere, since it is not in all builds
};
function logValue(valueName)
......
......@@ -56,6 +56,8 @@ function constructorNamesForWindow(globalObject)
if (value == null)
continue;
var type = classNameForObject(value);
if (type == "CanvasRenderingContext3DConstructor")
continue; // We ignore CanvasRenderingContext3D and test it elsewhere, since it is not in all builds
if (!type.match('Constructor$'))
continue;
namesSet[type] = 1;
......
......@@ -12,6 +12,7 @@ var skippedProperties = [
"objCController", "textInputController", "navigationController",
"eventSender", "objCPlugin", "objCPluginFunction",
"appleScriptController", "plainText", "accessibilityController",
"CanvasRenderingContext3D", // Ignore this property because it does not exist in all implementations. It will be tested separately
];
var skippedPropertiesSet = {};
......
2009-08-27 Chris Marrin <cmarrin@apple.com>
Reviewed by Simon Fraser.
Final patch for Canvas 3D support
https://bugs.webkit.org/show_bug.cgi?id=28018
This hooks everything up and provides a working implementation of
Canvas 3D. I plumb the creation of the 3D canvas down to GraphicsLayer,
passing the opaque context and texture pointers so a Canvas3DLayer can be
created (more on that later). It also plumbs changes to the 3D canvas so
that Canvas3DLayer can recomposite the results.
A 3D Canvas element needs a RenderLayer and compositing layer to render.
This is because it renders to an off-screen texture in the GPU and then
hands it to a Canvas3DLayer, which is a subclass of CAOpenGLLayer, to
render that texture as a 3D quad. This keeps everything in GPU memory to
maximize performance. When a CanvasRenderingContext3D is created it
forces a style recalc which creates the RenderLayer and compositing
layer if needed.
I repurposed an existing flag which was put in place for animation to accomplish
this. This flag is passed to setNeedsStyleRecalc(), and I renamed it from
AnimationStyleChange to SyntheticStyleChange. It essentially says that you need
to do a complete style recalc, even though the style itself has not really
changed.
This patch also fixes a couple of bugs discovered when testing with 3d-canvas
turned on. I also added a constructor DOMWindow.idl for CanvasRenderingContext3D.
This is needed when making a JS wrapper for the object so the prototype
property can be set.
Test: fast/canvas/change-context.html
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSCanvasRenderingContext3DCustom.cpp:
(WebCore::JSCanvasRenderingContext3D::glDrawElements):
* bindings/js/JSCanvasRenderingContextCustom.cpp:
(WebCore::toJS):
* dom/Element.cpp:
(WebCore::Element::recalcStyle):
* dom/Node.cpp:
(WebCore::Node::setNeedsStyleRecalc):
* dom/Node.h:
(WebCore::):
* html/HTMLCanvasElement.cpp:
(WebCore::HTMLCanvasElement::getContext):
(WebCore::HTMLCanvasElement::is3D):
* html/HTMLCanvasElement.h:
* html/canvas/CanvasBuffer.cpp:
(WebCore::CanvasBuffer::create):
(WebCore::CanvasBuffer::CanvasBuffer):
(WebCore::CanvasBuffer::_deleteObject):
* html/canvas/CanvasBuffer.h:
* html/canvas/CanvasFramebuffer.cpp:
(WebCore::CanvasFramebuffer::create):
(WebCore::CanvasFramebuffer::CanvasFramebuffer):
(WebCore::CanvasFramebuffer::_deleteObject):
* html/canvas/CanvasFramebuffer.h:
* html/canvas/CanvasObject.cpp:
(WebCore::CanvasObject::CanvasObject):
(WebCore::CanvasObject::~CanvasObject):
(WebCore::CanvasObject::deleteObject):
* html/canvas/CanvasObject.h:
(WebCore::CanvasObject::context):
* html/canvas/CanvasProgram.cpp:
(WebCore::CanvasProgram::create):
(WebCore::CanvasProgram::CanvasProgram):
(WebCore::CanvasProgram::_deleteObject):
* html/canvas/CanvasProgram.h:
* html/canvas/CanvasRenderbuffer.cpp:
(WebCore::CanvasRenderbuffer::create):
(WebCore::CanvasRenderbuffer::CanvasRenderbuffer):
(WebCore::CanvasRenderbuffer::_deleteObject):
* html/canvas/CanvasRenderbuffer.h:
* html/canvas/CanvasRenderingContext3D.cpp:
(WebCore::CanvasRenderingContext3D::createBuffer):
(WebCore::CanvasRenderingContext3D::createFramebuffer):
(WebCore::CanvasRenderingContext3D::createTexture):
(WebCore::CanvasRenderingContext3D::createProgram):
(WebCore::CanvasRenderingContext3D::createRenderbuffer):
(WebCore::CanvasRenderingContext3D::createShader):
* html/canvas/CanvasRenderingContext3D.h:
(WebCore::CanvasRenderingContext3D::graphicsContext3D):
* html/canvas/CanvasShader.cpp:
(WebCore::CanvasShader::create):
(WebCore::CanvasShader::CanvasShader):
(WebCore::CanvasShader::_deleteObject):
* html/canvas/CanvasShader.h:
* html/canvas/CanvasTexture.cpp:
(WebCore::CanvasTexture::create):
(WebCore::CanvasTexture::CanvasTexture):
(WebCore::CanvasTexture::_deleteObject):
* html/canvas/CanvasTexture.h:
* page/DOMWindow.idl:
* page/animation/AnimationBase.cpp:
(WebCore::AnimationBase::setNeedsStyleRecalc):
* page/animation/AnimationController.cpp:
(WebCore::AnimationControllerPrivate::updateAnimationTimer):
(WebCore::AnimationControllerPrivate::updateStyleIfNeededDispatcherFired):
(WebCore::AnimationControllerPrivate::pauseAnimationAtTime):
(WebCore::AnimationControllerPrivate::pauseTransitionAtTime):
(WebCore::AnimationController::cancelAnimations):
* platform/graphics/GraphicsContext3D.h:
(WebCore::GraphicsContext3D::platformGraphicsContext3D):
(WebCore::GraphicsContext3D::platformTexture):
* platform/graphics/GraphicsLayer.h:
(WebCore::GraphicsLayer::setContentsToGraphicsContext3D):
(WebCore::GraphicsLayer::setGraphicsContext3DNeedsDisplay):
* platform/graphics/mac/GraphicsContext3DMac.cpp:
(WebCore::GraphicsContext3D::~GraphicsContext3D):
(WebCore::GraphicsContext3D::reshape):
* platform/graphics/mac/GraphicsLayerCA.h:
(WebCore::GraphicsLayerCA::):
* platform/graphics/mac/GraphicsLayerCA.mm:
(WebCore::GraphicsLayerCA::GraphicsLayerCA):
(WebCore::GraphicsLayerCA::commitLayerChanges):
(WebCore::GraphicsLayerCA::updateContentsGraphicsContext3D):
(WebCore::GraphicsLayerCA::setContentsToGraphicsContext3D):
(WebCore::GraphicsLayerCA::setGraphicsContext3DNeedsDisplay):
* rendering/RenderHTMLCanvas.cpp:
(WebCore::RenderHTMLCanvas::requiresLayer):
* rendering/RenderHTMLCanvas.h:
(WebCore::RenderHTMLCanvas::isCanvas):
* rendering/RenderLayerBacking.cpp:
(WebCore::RenderLayerBacking::updateGraphicsLayerConfiguration):
(WebCore::RenderLayerBacking::canUseDirectCompositing):
(WebCore::RenderLayerBacking::rendererContentChanged):
* rendering/RenderLayerCompositor.cpp:
(WebCore::RenderLayerCompositor::requiresCompositingLayer):
(WebCore::RenderLayerCompositor::requiresCompositingForCanvas):
* rendering/RenderLayerCompositor.h:
* rendering/RenderObject.h:
(WebCore::RenderObject::isCanvas):
2009-08-27 Peter Kasting <pkasting@google.com>
Reviewed by Eric Seidel.
......@@ -825,7 +825,7 @@
49C7B9E31042D32F0009D447 /* CanvasShader.h in Headers */ = {isa = PBXBuildFile; fileRef = 49C7B9C31042D32F0009D447 /* CanvasShader.h */; };
49C7B9E51042D32F0009D447 /* CanvasTexture.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49C7B9C51042D32F0009D447 /* CanvasTexture.cpp */; };
49C7B9E61042D32F0009D447 /* CanvasTexture.h in Headers */ = {isa = PBXBuildFile; fileRef = 49C7B9C61042D32F0009D447 /* CanvasTexture.h */; };
49C7B9FC1042D3650009D447 /* GraphicsContext3D.h in Headers */ = {isa = PBXBuildFile; fileRef = 49C7B9FB1042D3650009D447 /* GraphicsContext3D.h */; };
49C7B9FC1042D3650009D447 /* GraphicsContext3D.h in Headers */ = {isa = PBXBuildFile; fileRef = 49C7B9FB1042D3650009D447 /* GraphicsContext3D.h */; settings = {ATTRIBUTES = (Private, ); }; };
49C7BA001042D38C0009D447 /* Canvas3DLayer.h in Headers */ = {isa = PBXBuildFile; fileRef = 49C7B9FD1042D38C0009D447 /* Canvas3DLayer.h */; };
49C7BA011042D38C0009D447 /* Canvas3DLayer.mm in Sources */ = {isa = PBXBuildFile; fileRef = 49C7B9FE1042D38C0009D447 /* Canvas3DLayer.mm */; };
49C7BA021042D38C0009D447 /* GraphicsContext3DMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49C7B9FF1042D38C0009D447 /* GraphicsContext3DMac.cpp */; };
......@@ -16284,6 +16284,7 @@
B2A015A90AF6CD53006BCE0E /* GraphicsContext.h in Headers */,
A80D67080E9E9DEB00E420F0 /* GraphicsContextPlatformPrivateCG.h in Headers */,
A88FE3340E5EEE87008D8C0F /* GraphicsContextPrivate.h in Headers */,
49C7B9FC1042D3650009D447 /* GraphicsContext3D.h in Headers */,
0F580B0D0F12A2690051D689 /* GraphicsLayer.h in Headers */,
0F580B060F12A2550051D689 /* GraphicsLayerCA.h in Headers */,
0F580B0E0F12A2690051D689 /* GraphicsLayerClient.h in Headers */,
......@@ -17570,7 +17571,6 @@
49C7B9E01042D32F0009D447 /* CanvasRenderingContext3D.h in Headers */,
49C7B9E31042D32F0009D447 /* CanvasShader.h in Headers */,
49C7B9E61042D32F0009D447 /* CanvasTexture.h in Headers */,
49C7B9FC1042D3650009D447 /* GraphicsContext3D.h in Headers */,
49C7BA001042D38C0009D447 /* Canvas3DLayer.h in Headers */,
E1284BB110449FFA00EAEB52 /* JSPageTransitionEvent.h in Headers */,
E1284BD61044A01E00EAEB52 /* DOMPageTransitionEvent.h in Headers */,
......@@ -274,8 +274,6 @@ JSValue JSCanvasRenderingContext3D::glDrawElements(JSC::ExecState* exec, JSC::Ar
unsigned mode = args.at(0).toInt32(exec);
unsigned type = args.at(1).toInt32(exec);
unsigned int count = 0;
// If the third param is not an object, it is a number, which is the count.
// In this case if there is a 4th param, it is the offset. If there is no
// 4th param, the offset is 0
......@@ -284,42 +282,44 @@ JSValue JSCanvasRenderingContext3D::glDrawElements(JSC::ExecState* exec, JSC::Ar
if (args.size() > 4)
return throwError(exec, SyntaxError);
count = args.at(2).toInt32(exec);
unsigned int count = args.at(2).toInt32(exec);
unsigned int offset = (args.size() == 4) ? args.at(3).toInt32(exec) : 0;
context->glDrawElements(mode, count, type, (void*) offset);
return jsUndefined();
}
// 3rd param is an object. Treat it as an array
if (args.size() != 3)
return throwError(exec, SyntaxError);
if (type != GL_UNSIGNED_BYTE && type != GL_UNSIGNED_SHORT)
return throwError(exec, TypeError);
JSObject* array = asObject(args.at(2));
unsigned int count = array->get(exec, Identifier(exec, "length")).toInt32(exec);
size_t size = count * ((type == GL_UNSIGNED_BYTE) ? sizeof(unsigned char) : sizeof(unsigned short));
void* tempIndices;
if (!tryFastMalloc(size).getValue(tempIndices))
return throwError(exec, GeneralError);
OwnFastMallocPtr<void> passedIndices(tempIndices);
if (type == GL_UNSIGNED_BYTE) {
unsigned char* indices = static_cast<unsigned char*>(passedIndices.get());
for (unsigned int i = 0; i < count; ++i) {
unsigned short value = static_cast<unsigned char>(array->get(exec, i).toUInt32(exec));
indices[i] = value;
}
} else {
if (args.size() != 3)
return throwError(exec, SyntaxError);
if (type != GL_UNSIGNED_BYTE && type != GL_UNSIGNED_SHORT)
return throwError(exec, TypeError);
size_t size = count * ((type == GL_UNSIGNED_BYTE) ? sizeof(unsigned char) : sizeof(unsigned short));
void* tempIndices;
if (!tryFastMalloc(size).getValue(tempIndices))
return throwError(exec, GeneralError);
OwnFastMallocPtr<void> passedIndices(tempIndices);
JSObject* array = asObject(args.at(2));
count = array->get(exec, Identifier(exec, "length")).toInt32(exec);
if (type == GL_UNSIGNED_BYTE) {
unsigned char* indices = static_cast<unsigned char*>(passedIndices.get());
for (unsigned int i = 0; i < count; ++i) {
unsigned short value = static_cast<unsigned char>(array->get(exec, i).toUInt32(exec));
indices[i] = value;
}
} else {
unsigned short* indices = static_cast<unsigned short*>(passedIndices.get());
for (unsigned int i = 0; i < count; ++i) {
unsigned short value = static_cast<unsigned short>(array->get(exec, i).toUInt32(exec));
indices[i] = value;
}
unsigned short* indices = static_cast<unsigned short*>(passedIndices.get());
for (unsigned int i = 0; i < count; ++i) {
unsigned short value = static_cast<unsigned short>(array->get(exec, i).toUInt32(exec));
indices[i] = value;
}
context->glDrawElements(mode, count, type, passedIndices.get());
}
context->glDrawElements(mode, count, type, passedIndices.get());
return jsUndefined();
}
......
......@@ -48,7 +48,6 @@ JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, CanvasR
#endif
ASSERT(object->is2d());
return getDOMObjectWrapper<JSCanvasRenderingContext2D>(exec, globalObject, static_cast<CanvasRenderingContext2D*>(object));
}
} // namespace WebCore
......@@ -860,7 +860,7 @@ void Element::recalcStyle(StyleChange change)
if (ch != NoChange || pseudoStyleCacheIsInvalid(currentStyle.get(), newStyle.get())) {
setRenderStyle(newStyle);
} else if (needsStyleRecalc() && (styleChangeType() != AnimationStyleChange) && (document()->usesSiblingRules() || document()->usesDescendantRules())) {
} else if (needsStyleRecalc() && (styleChangeType() != SyntheticStyleChange) && (document()->usesSiblingRules() || document()->usesDescendantRules())) {
// Although no change occurred, we use the new style so that the cousin style sharing code won't get
// fooled into believing this style is the same. This is only necessary if the document actually uses
// sibling/descendant rules, since otherwise it isn't possible for ancestor styles to affect sharing of
......@@ -869,7 +869,7 @@ void Element::recalcStyle(StyleChange change)
renderer()->setStyleInternal(newStyle.get());
else
setRenderStyle(newStyle);
} else if (styleChangeType() == AnimationStyleChange)
} else if (styleChangeType() == SyntheticStyleChange)
setRenderStyle(newStyle);
if (change != Force) {
......
......@@ -765,7 +765,7 @@ void Node::setNeedsStyleRecalc(StyleChangeType changeType)
if ((changeType != NoStyleChange) && !attached()) // changed compared to what?
return;
if (!(changeType == InlineStyleChange && (m_styleChange == FullStyleChange || m_styleChange == AnimationStyleChange)))
if (!(changeType == InlineStyleChange && (m_styleChange == FullStyleChange || m_styleChange == SyntheticStyleChange)))
m_styleChange = changeType;
if (m_styleChange != NoStyleChange) {
......
......@@ -67,7 +67,10 @@ class StringBuilder;
typedef int ExceptionCode;
enum StyleChangeType { NoStyleChange, InlineStyleChange, FullStyleChange, AnimationStyleChange };
// SyntheticStyleChange means that we need to go through the entire style change logic even though
// no style property has actually changed. It is used to restructure the tree when, for instance,
// RenderLayers are created or destroyed due to animation changes.
enum StyleChangeType { NoStyleChange, InlineStyleChange, FullStyleChange, SyntheticStyleChange };
const unsigned short DOCUMENT_POSITION_EQUIVALENT = 0x00;
const unsigned short DOCUMENT_POSITION_DISCONNECTED = 0x01;
......
......@@ -153,26 +153,31 @@ CanvasRenderingContext* HTMLCanvasElement::getContext(const String& type)
// context is already 2D, just return that. If the existing context is 3D, then destroy it
// before creating a new 2D context. Vice versa when requesting a 3D canvas. Requesting a
// context with any other type string will destroy any existing context.
// FIXME - The code depends on the context not going away once created, to prevent JS from
// seeing a dangling pointer. So for now we will disallow the context from being changed
// once it is created.
if (type == "2d") {
if (m_context && !m_context->is2d())
m_context.clear();
return 0;
if (!m_context)
m_context.set(new CanvasRenderingContext2D(this));
m_context = new CanvasRenderingContext2D(this);
return m_context.get();
}
#if ENABLE(3D_CANVAS)
else if (type == "webkit-3d") {
if (type == "webkit-3d") {
if (m_context && !m_context->is3d())
m_context.clear();
return 0;
if (!m_context) {
m_context.set(new CanvasRenderingContext3D(this));
setNeedsStyleRecalc();
m_context = new CanvasRenderingContext3D(this);
// Need to make sure a RenderLayer and compositing layer get created for the Canvas
setNeedsStyleRecalc(SyntheticStyleChange);
}
return m_context.get();
}
#endif
else if (m_context)
m_context.clear();
return m_context.get();
return 0;
}
void HTMLCanvasElement::willDraw(const FloatRect& rect)
......@@ -325,20 +330,6 @@ bool HTMLCanvasElement::is3D() const
{
return m_context && m_context->is3d();
}
PlatformGraphicsContext3D HTMLCanvasElement::context3D() const
{
if (m_context && m_context->is3d())
return static_cast<CanvasRenderingContext3D*>(m_context.get())->context3D();
return 0;
}
Platform3DObject HTMLCanvasElement::texture3D() const
{
if (m_context && m_context->is3d())
return static_cast<CanvasRenderingContext3D*>(m_context.get())->texture3D();
return 0;
}
#endif
}
......@@ -105,8 +105,6 @@ public:
#if ENABLE(3D_CANVAS)
bool is3D() const;
PlatformGraphicsContext3D context3D() const;
Platform3DObject texture3D() const;
#endif
private:
......
......@@ -28,23 +28,24 @@
#if ENABLE(3D_CANVAS)
#include "CanvasBuffer.h"
#include "CanvasRenderingContext3D.h"
namespace WebCore {
PassRefPtr<CanvasBuffer> CanvasBuffer::create(GraphicsContext3D* ctx)
PassRefPtr<CanvasBuffer> CanvasBuffer::create(CanvasRenderingContext3D* ctx)
{
return adoptRef(new CanvasBuffer(ctx));
}
CanvasBuffer::CanvasBuffer(GraphicsContext3D* ctx)
CanvasBuffer::CanvasBuffer(CanvasRenderingContext3D* ctx)
: CanvasObject(ctx)
{
setObject(context()->createBuffer());
setObject(context()->graphicsContext3D()->createBuffer());
}
void CanvasBuffer::_deleteObject(Platform3DObject object)
{
context()->deleteBuffer(object);
context()->graphicsContext3D()->deleteBuffer(object);
}
}
......
......@@ -37,10 +37,10 @@ namespace WebCore {
public:
virtual ~CanvasBuffer() { deleteObject(); }
static PassRefPtr<CanvasBuffer> create(GraphicsContext3D*);
static PassRefPtr<CanvasBuffer> create(CanvasRenderingContext3D*);
protected:
CanvasBuffer(GraphicsContext3D*);
CanvasBuffer(CanvasRenderingContext3D*);
virtual void _deleteObject(Platform3DObject o);
};
......
......@@ -28,23 +28,24 @@
#if ENABLE(3D_CANVAS)
#include "CanvasFramebuffer.h"
#include "CanvasRenderingContext3D.h"
namespace WebCore {
PassRefPtr<CanvasFramebuffer> CanvasFramebuffer::create(GraphicsContext3D* ctx)
PassRefPtr<CanvasFramebuffer> CanvasFramebuffer::create(CanvasRenderingContext3D* ctx)
{
return adoptRef(new CanvasFramebuffer(ctx));
}
CanvasFramebuffer::CanvasFramebuffer(GraphicsContext3D* ctx)
CanvasFramebuffer::CanvasFramebuffer(CanvasRenderingContext3D* ctx)
: CanvasObject(ctx)
{
setObject(context()->createFramebuffer());
setObject(context()->graphicsContext3D()->createFramebuffer());
}
void CanvasFramebuffer::_deleteObject(Platform3DObject object)
{
context()->deleteFramebuffer(object);
context()->graphicsContext3D()->deleteFramebuffer(object);
}
}
......
......@@ -37,10 +37,10 @@ namespace WebCore {
public:
virtual ~CanvasFramebuffer() { deleteObject(); }
static PassRefPtr<CanvasFramebuffer> create(GraphicsContext3D*);
static PassRefPtr<CanvasFramebuffer> create(CanvasRenderingContext3D*);
protected:
CanvasFramebuffer(GraphicsContext3D*);
CanvasFramebuffer(CanvasRenderingContext3D*);
virtual void _deleteObject(Platform3DObject);
};
......
......@@ -28,11 +28,11 @@
#if ENABLE(3D_CANVAS)
#include "CanvasObject.h"
#include "CanvasRenderingContext.h"
#include "CanvasRenderingContext3D.h"
namespace WebCore {
CanvasObject::CanvasObject(GraphicsContext3D* context)
CanvasObject::CanvasObject(CanvasRenderingContext3D* context)
: m_object(0)
, m_context(context)
{
......@@ -40,6 +40,8 @@ CanvasObject::CanvasObject(GraphicsContext3D* context)
CanvasObject::~CanvasObject()
{
if (m_context)
m_context->removeObject(this);
}
void CanvasObject::setObject(Platform3DObject object)
......@@ -55,7 +57,7 @@ void CanvasObject::deleteObject()
{
if (m_object) {
if (m_context) {
m_context->makeContextCurrent();
m_context->graphicsContext3D()->makeContextCurrent();
_deleteObject(m_object);
}
m_object = 0;
......
......@@ -33,7 +33,7 @@
namespace WebCore {
class GraphicsContext3D;
class CanvasRenderingContext3D;
class CanvasObject : public RefCounted<CanvasObject> {
public:
......@@ -50,14 +50,14 @@ namespace WebCore {
}
protected:
CanvasObject(GraphicsContext3D*);
CanvasObject(CanvasRenderingContext3D*);
virtual void _deleteObject(Platform3DObject) = 0;
GraphicsContext3D* context() const { return m_context; }
CanvasRenderingContext3D* context() const { return m_context; }
private:
Platform3DObject m_object;
GraphicsContext3D* m_context;
CanvasRenderingContext3D* m_context;
};
} // namespace WebCore
......
......@@ -28,23 +28,24 @@
#if ENABLE(3D_CANVAS)
#include "CanvasProgram.h"
#include "CanvasRenderingContext3D.h"
namespace WebCore {
PassRefPtr<CanvasProgram> CanvasProgram::create(GraphicsContext3D* ctx)
PassRefPtr<CanvasProgram> CanvasProgram::create(CanvasRenderingContext3D* ctx)
{
return adoptRef(new CanvasProgram(ctx));
}
CanvasProgram::CanvasProgram(GraphicsContext3D* ctx)
CanvasProgram::CanvasProgram(CanvasRenderingContext3D* ctx)
: CanvasObject(ctx)
{
setObject(context()->createProgram());
setObject(context()->graphicsContext3D()->createProgram());
}
void CanvasProgram::_deleteObject(Platform3DObject object)
{
context()->deleteProgram(object);
context()->graphicsContext3D()->deleteProgram(object);
}
}
......
......@@ -37,10 +37,10 @@ namespace WebCore {
public:
virtual ~CanvasProgram() { deleteObject(); }
static PassRefPtr<CanvasProgram> create(GraphicsContext3D*);
static PassRefPtr<CanvasProgram> create(CanvasRenderingContext3D*);
protected:
CanvasProgram(GraphicsContext3D*);
CanvasProgram(CanvasRenderingContext3D*);
virtual void _deleteObject(Platform3DObject);
};
......
......@@ -28,23 +28,24 @@
#if ENABLE(3D_CANVAS)
#include "CanvasRenderbuffer.h"
#include "CanvasRenderingContext3D.h"
namespace WebCore {
PassRefPtr<CanvasRenderbuffer> CanvasRenderbuffer::create(GraphicsContext3D* ctx)
PassRefPtr<CanvasRenderbuffer> CanvasRenderbuffer::create(CanvasRenderingContext3D* ctx)
{
return adoptRef(new CanvasRenderbuffer(ctx));
}
CanvasRenderbuffer::CanvasRenderbuffer(GraphicsContext3D* ctx)
CanvasRenderbuffer::CanvasRenderbuffer(CanvasRenderingContext3D* ctx)
: CanvasObject(ctx)
{
setObject(context()->createRenderbuffer());
setObject(context()->graphicsContext3D()->createRenderbuffer());
}
void CanvasRenderbuffer::_deleteObject(Platform3DObject object)
{
context()->deleteRenderbuffer(object);
context()->graphicsContext3D()->deleteRenderbuffer(object);
}
}
......
......@@ -37,10 +37,10 @@ namespace WebCore {
public:
virtual ~CanvasRenderbuffer() { deleteObject(); }