#include "core/html/canvas/WebGLFramebuffer.h"
-#include "core/html/canvas/WebGLRenderingContext.h"
+#include "core/html/canvas/WebGLRenderingContextBase.h"
#include "platform/NotImplemented.h"
-namespace WebCore {
+namespace blink {
namespace {
class WebGLRenderbufferAttachment FINAL : public WebGLFramebuffer::WebGLAttachment {
public:
- static PassRefPtr<WebGLFramebuffer::WebGLAttachment> create(WebGLRenderbuffer*);
+ static PassRefPtrWillBeRawPtr<WebGLFramebuffer::WebGLAttachment> create(WebGLRenderbuffer*);
+
+ virtual void trace(Visitor*) OVERRIDE;
private:
- WebGLRenderbufferAttachment(WebGLRenderbuffer*);
+ explicit WebGLRenderbufferAttachment(WebGLRenderbuffer*);
+ WebGLRenderbufferAttachment() { }
+
virtual GLsizei width() const OVERRIDE;
virtual GLsizei height() const OVERRIDE;
virtual GLenum format() const OVERRIDE;
virtual WebGLSharedObject* object() const OVERRIDE;
virtual bool isSharedObject(WebGLSharedObject*) const OVERRIDE;
virtual bool valid() const OVERRIDE;
- virtual bool initialized() const OVERRIDE;
- virtual void setInitialized() OVERRIDE;
virtual void onDetached(blink::WebGraphicsContext3D*) OVERRIDE;
virtual void attach(blink::WebGraphicsContext3D*, GLenum attachment) OVERRIDE;
virtual void unattach(blink::WebGraphicsContext3D*, GLenum attachment) OVERRIDE;
- WebGLRenderbufferAttachment() { };
-
- RefPtr<WebGLRenderbuffer> m_renderbuffer;
+ RefPtrWillBeMember<WebGLRenderbuffer> m_renderbuffer;
};
- PassRefPtr<WebGLFramebuffer::WebGLAttachment> WebGLRenderbufferAttachment::create(WebGLRenderbuffer* renderbuffer)
+ PassRefPtrWillBeRawPtr<WebGLFramebuffer::WebGLAttachment> WebGLRenderbufferAttachment::create(WebGLRenderbuffer* renderbuffer)
+ {
+ return adoptRefWillBeNoop(new WebGLRenderbufferAttachment(renderbuffer));
+ }
+
+ void WebGLRenderbufferAttachment::trace(Visitor* visitor)
{
- return adoptRef(new WebGLRenderbufferAttachment(renderbuffer));
+ visitor->trace(m_renderbuffer);
+ WebGLFramebuffer::WebGLAttachment::trace(visitor);
}
WebGLRenderbufferAttachment::WebGLRenderbufferAttachment(WebGLRenderbuffer* renderbuffer)
return m_renderbuffer->object();
}
- bool WebGLRenderbufferAttachment::initialized() const
- {
- return m_renderbuffer->object() && m_renderbuffer->initialized();
- }
-
- void WebGLRenderbufferAttachment::setInitialized()
- {
- if (m_renderbuffer->object())
- m_renderbuffer->setInitialized();
- }
-
void WebGLRenderbufferAttachment::onDetached(blink::WebGraphicsContext3D* context)
{
m_renderbuffer->onDetached(context);
class WebGLTextureAttachment FINAL : public WebGLFramebuffer::WebGLAttachment {
public:
- static PassRefPtr<WebGLFramebuffer::WebGLAttachment> create(WebGLTexture*, GLenum target, GLint level);
+ static PassRefPtrWillBeRawPtr<WebGLFramebuffer::WebGLAttachment> create(WebGLTexture*, GLenum target, GLint level);
+
+ virtual void trace(Visitor*) OVERRIDE;
private:
WebGLTextureAttachment(WebGLTexture*, GLenum target, GLint level);
+ WebGLTextureAttachment() { }
+
virtual GLsizei width() const OVERRIDE;
virtual GLsizei height() const OVERRIDE;
virtual GLenum format() const OVERRIDE;
virtual WebGLSharedObject* object() const OVERRIDE;
virtual bool isSharedObject(WebGLSharedObject*) const OVERRIDE;
virtual bool valid() const OVERRIDE;
- virtual bool initialized() const OVERRIDE;
- virtual void setInitialized() OVERRIDE;
virtual void onDetached(blink::WebGraphicsContext3D*) OVERRIDE;
virtual void attach(blink::WebGraphicsContext3D*, GLenum attachment) OVERRIDE;
virtual void unattach(blink::WebGraphicsContext3D*, GLenum attachment) OVERRIDE;
- WebGLTextureAttachment() { };
-
- RefPtr<WebGLTexture> m_texture;
+ RefPtrWillBeMember<WebGLTexture> m_texture;
GLenum m_target;
GLint m_level;
};
- PassRefPtr<WebGLFramebuffer::WebGLAttachment> WebGLTextureAttachment::create(WebGLTexture* texture, GLenum target, GLint level)
+ PassRefPtrWillBeRawPtr<WebGLFramebuffer::WebGLAttachment> WebGLTextureAttachment::create(WebGLTexture* texture, GLenum target, GLint level)
+ {
+ return adoptRefWillBeNoop(new WebGLTextureAttachment(texture, target, level));
+ }
+
+ void WebGLTextureAttachment::trace(Visitor* visitor)
{
- return adoptRef(new WebGLTextureAttachment(texture, target, level));
+ visitor->trace(m_texture);
+ WebGLFramebuffer::WebGLAttachment::trace(visitor);
}
WebGLTextureAttachment::WebGLTextureAttachment(WebGLTexture* texture, GLenum target, GLint level)
return m_texture->object();
}
- bool WebGLTextureAttachment::initialized() const
- {
- // Textures are assumed to be initialized.
- return true;
- }
-
- void WebGLTextureAttachment::setInitialized()
- {
- // Textures are assumed to be initialized.
- }
-
void WebGLTextureAttachment::onDetached(blink::WebGraphicsContext3D* context)
{
m_texture->onDetached(context);
{
}
-PassRefPtr<WebGLFramebuffer> WebGLFramebuffer::create(WebGLRenderingContext* ctx)
+PassRefPtrWillBeRawPtr<WebGLFramebuffer> WebGLFramebuffer::create(WebGLRenderingContextBase* ctx)
{
- return adoptRef(new WebGLFramebuffer(ctx));
+ return adoptRefWillBeNoop(new WebGLFramebuffer(ctx));
}
-WebGLFramebuffer::WebGLFramebuffer(WebGLRenderingContext* ctx)
+WebGLFramebuffer::WebGLFramebuffer(WebGLRenderingContextBase* ctx)
: WebGLContextObject(ctx)
, m_hasEverBeenBound(false)
{
- ScriptWrappable::init(this);
- setObject(ctx->webGraphicsContext3D()->createFramebuffer());
+ setObject(ctx->webContext()->createFramebuffer());
}
WebGLFramebuffer::~WebGLFramebuffer()
{
- deleteObject(0);
+ // Delete the platform framebuffer resource. Explicit detachment
+ // is for the benefit of Oilpan, where the framebuffer object
+ // isn't detached when it and the WebGLRenderingContextBase object
+ // it is registered with are both finalized. Without Oilpan, the
+ // object will have been detached.
+ //
+ // To keep the code regular, the trivial detach()ment is always
+ // performed.
+ detachAndDeleteObject();
}
void WebGLFramebuffer::setAttachmentForBoundFramebuffer(GLenum attachment, GLenum texTarget, WebGLTexture* texture, GLint level)
ASSERT(isBound());
WebGLAttachment* attachmentObject = getAttachment(attachment);
if (attachmentObject)
- attachmentObject->attach(context()->webGraphicsContext3D(), attachmentPoint);
+ attachmentObject->attach(context()->webContext(), attachmentPoint);
}
WebGLSharedObject* WebGLFramebuffer::getAttachmentObject(GLenum attachment) const
}
} else if (object->isTexture()) {
GLenum type = attachedObject->type();
- if (!(context()->m_webglDepthTexture && internalformat == GL_DEPTH_COMPONENT
+ if (!(context()->extensionEnabled(WebGLDepthTextureName) && internalformat == GL_DEPTH_COMPONENT
&& (type == GL_UNSIGNED_SHORT || type == GL_UNSIGNED_INT))) {
*reason = "the attached texture is not a depth texture";
return false;
}
} else if (object->isTexture()) {
GLenum type = attachedObject->type();
- if (!(context()->m_webglDepthTexture && internalformat == GL_DEPTH_STENCIL_OES
+ if (!(context()->extensionEnabled(WebGLDepthTextureName) && internalformat == GL_DEPTH_STENCIL_OES
&& type == GL_UNSIGNED_INT_24_8_OES)) {
*reason = "the attached texture is not a DEPTH_STENCIL texture";
return false;
}
}
} else if (attachment == GL_COLOR_ATTACHMENT0
- || (context()->m_webglDrawBuffers && attachment > GL_COLOR_ATTACHMENT0
+ || (context()->extensionEnabled(WebGLDrawBuffersName) && attachment > GL_COLOR_ATTACHMENT0
&& attachment < static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + context()->maxColorAttachments()))) {
if (object->isRenderbuffer()) {
if (!isColorRenderable(internalformat)) {
&& type != GL_UNSIGNED_SHORT_5_6_5
&& type != GL_UNSIGNED_SHORT_4_4_4_4
&& type != GL_UNSIGNED_SHORT_5_5_5_1
- && !(type == GL_FLOAT && context()->m_oesTextureFloat)
- && !(type == GL_HALF_FLOAT_OES && context()->m_oesTextureHalfFloat)) {
+ && !(type == GL_FLOAT && context()->extensionEnabled(OESTextureFloatName))
+ && !(type == GL_HALF_FLOAT_OES && context()->extensionEnabled(OESTextureHalfFloatName))) {
*reason = "unsupported type: The attached texture is not supported to be rendered to";
return false;
}
WebGLAttachment* attachmentObject = getAttachment(attachment);
if (attachmentObject) {
- attachmentObject->onDetached(context()->webGraphicsContext3D());
+ attachmentObject->onDetached(context()->webContext());
m_attachments.remove(attachment);
drawBuffersIfNecessary(false);
switch (attachment) {
WebGLAttachment* attachmentObject = it->value.get();
if (attachmentObject->isSharedObject(attachment)) {
GLenum attachmentType = it->key;
- attachmentObject->unattach(context()->webGraphicsContext3D(), attachmentType);
+ attachmentObject->unattach(context()->webContext(), attachmentType);
removeAttachmentFromBoundFramebuffer(attachmentType);
checkMore = true;
break;
}
}
-GLsizei WebGLFramebuffer::colorBufferWidth() const
-{
- if (!object())
- return 0;
- WebGLAttachment* attachment = getAttachment(GL_COLOR_ATTACHMENT0);
- if (!attachment)
- return 0;
-
- return attachment->width();
-}
-
-GLsizei WebGLFramebuffer::colorBufferHeight() const
-{
- if (!object())
- return 0;
- WebGLAttachment* attachment = getAttachment(GL_COLOR_ATTACHMENT0);
- if (!attachment)
- return 0;
-
- return attachment->height();
-}
-
GLenum WebGLFramebuffer::colorBufferFormat() const
{
if (!object())
GLenum WebGLFramebuffer::checkStatus(const char** reason) const
{
- unsigned int count = 0;
+ unsigned count = 0;
GLsizei width = 0, height = 0;
bool haveDepth = false;
bool haveStencil = false;
void WebGLFramebuffer::deleteObjectImpl(blink::WebGraphicsContext3D* context3d, Platform3DObject object)
{
+#if !ENABLE(OILPAN)
+ // With Oilpan, both the AttachmentMap and its WebGLAttachment objects are
+ // GCed objects and cannot be accessed, as they may have been finalized
+ // already during the same GC sweep.
+ //
+ // The WebGLAttachment-derived classes instead handle detachment
+ // on their own when finalizing, so the explicit notification is
+ // not needed.
for (AttachmentMap::iterator it = m_attachments.begin(); it != m_attachments.end(); ++it)
it->value->onDetached(context3d);
+#endif
context3d->deleteFramebuffer(object);
}
void WebGLFramebuffer::drawBuffersIfNecessary(bool force)
{
- if (!context()->m_webglDrawBuffers)
+ if (!context()->extensionEnabled(WebGLDrawBuffersName))
return;
bool reset = force;
// This filtering works around graphics driver bugs on Mac OS X.
}
}
if (reset) {
- context()->webGraphicsContext3D()->drawBuffersEXT(
+ context()->webContext()->drawBuffersEXT(
m_filteredDrawBuffers.size(), m_filteredDrawBuffers.data());
}
}
return GL_NONE;
}
+void WebGLFramebuffer::trace(Visitor* visitor)
+{
+#if ENABLE(OILPAN)
+ visitor->trace(m_attachments);
+#endif
+ WebGLContextObject::trace(visitor);
+}
+
}