Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / html / canvas / WebGLFramebuffer.cpp
index ebc4b02..86d1664 100644 (file)
 
 #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 {
 
@@ -41,10 +41,14 @@ 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;
@@ -52,20 +56,22 @@ namespace {
         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)
@@ -109,17 +115,6 @@ namespace {
         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);
@@ -154,10 +149,14 @@ namespace {
 
     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;
@@ -165,22 +164,24 @@ namespace {
         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)
@@ -220,17 +221,6 @@ namespace {
         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);
@@ -279,22 +269,29 @@ WebGLFramebuffer::WebGLAttachment::~WebGLAttachment()
 {
 }
 
-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)
@@ -328,7 +325,7 @@ void WebGLFramebuffer::attach(GLenum attachment, GLenum attachmentPoint)
     ASSERT(isBound());
     WebGLAttachment* attachmentObject = getAttachment(attachment);
     if (attachmentObject)
-        attachmentObject->attach(context()->webGraphicsContext3D(), attachmentPoint);
+        attachmentObject->attach(context()->webContext(), attachmentPoint);
 }
 
 WebGLSharedObject* WebGLFramebuffer::getAttachmentObject(GLenum attachment) const
@@ -356,7 +353,7 @@ bool WebGLFramebuffer::isAttachmentComplete(WebGLAttachment* attachedObject, GLe
             }
         } 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;
@@ -379,14 +376,14 @@ bool WebGLFramebuffer::isAttachmentComplete(WebGLAttachment* attachedObject, GLe
             }
         } 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)) {
@@ -407,8 +404,8 @@ bool WebGLFramebuffer::isAttachmentComplete(WebGLAttachment* attachedObject, GLe
                 && 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;
             }
@@ -439,7 +436,7 @@ void WebGLFramebuffer::removeAttachmentFromBoundFramebuffer(GLenum attachment)
 
     WebGLAttachment* attachmentObject = getAttachment(attachment);
     if (attachmentObject) {
-        attachmentObject->onDetached(context()->webGraphicsContext3D());
+        attachmentObject->onDetached(context()->webContext());
         m_attachments.remove(attachment);
         drawBuffersIfNecessary(false);
         switch (attachment) {
@@ -472,7 +469,7 @@ void WebGLFramebuffer::removeAttachmentFromBoundFramebuffer(WebGLSharedObject* a
             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;
@@ -481,28 +478,6 @@ void WebGLFramebuffer::removeAttachmentFromBoundFramebuffer(WebGLSharedObject* a
     }
 }
 
-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())
@@ -515,7 +490,7 @@ GLenum WebGLFramebuffer::colorBufferFormat() const
 
 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;
@@ -587,8 +562,17 @@ bool WebGLFramebuffer::hasStencilBuffer() const
 
 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);
 }
@@ -609,7 +593,7 @@ void WebGLFramebuffer::drawBuffers(const Vector<GLenum>& bufs)
 
 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.
@@ -627,7 +611,7 @@ void WebGLFramebuffer::drawBuffersIfNecessary(bool force)
         }
     }
     if (reset) {
-        context()->webGraphicsContext3D()->drawBuffersEXT(
+        context()->webContext()->drawBuffersEXT(
             m_filteredDrawBuffers.size(), m_filteredDrawBuffers.data());
     }
 }
@@ -643,4 +627,12 @@ GLenum WebGLFramebuffer::getDrawBuffer(GLenum drawBuffer)
     return GL_NONE;
 }
 
+void WebGLFramebuffer::trace(Visitor* visitor)
+{
+#if ENABLE(OILPAN)
+    visitor->trace(m_attachments);
+#endif
+    WebGLContextObject::trace(visitor);
+}
+
 }