Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / html / canvas / WebGLProgram.cpp
index e1e4959..db19263 100644 (file)
 
 #include "core/html/canvas/WebGLProgram.h"
 
+#include "core/html/canvas/WebGLContextGroup.h"
 #include "core/html/canvas/WebGLRenderingContextBase.h"
 
-namespace WebCore {
+namespace blink {
 
-PassRefPtr<WebGLProgram> WebGLProgram::create(WebGLRenderingContextBase* ctx)
+PassRefPtrWillBeRawPtr<WebGLProgram> WebGLProgram::create(WebGLRenderingContextBase* ctx)
 {
-    return adoptRef(new WebGLProgram(ctx));
+    return adoptRefWillBeNoop(new WebGLProgram(ctx));
 }
 
 WebGLProgram::WebGLProgram(WebGLRenderingContextBase* ctx)
@@ -48,7 +49,22 @@ WebGLProgram::WebGLProgram(WebGLRenderingContextBase* ctx)
 
 WebGLProgram::~WebGLProgram()
 {
-    deleteObject(0);
+#if ENABLE(OILPAN)
+    // These heap objects handle detachment on their own. Clear out
+    // the references to prevent deleteObjectImpl() from trying to do
+    // same, as we cannot safely access other heap objects from this
+    // destructor.
+    m_vertexShader = nullptr;
+    m_fragmentShader = nullptr;
+#endif
+    // Always call detach here to ensure that platform object deletion
+    // happens with Oilpan enabled. It keeps the code regular to do it
+    // with or without Oilpan enabled.
+    //
+    // See comment in WebGLBuffer's destructor for additional
+    // information on why this is done for WebGLSharedObject-derived
+    // objects.
+    detachAndDeleteObject();
 }
 
 void WebGLProgram::deleteObjectImpl(blink::WebGraphicsContext3D* context3d, Platform3DObject obj)
@@ -174,7 +190,9 @@ void WebGLProgram::cacheInfoIfNeeded()
     if (!object())
         return;
 
-    blink::WebGraphicsContext3D* context = getAWebGraphicsContext3D();
+    if (!contextGroup())
+        return;
+    blink::WebGraphicsContext3D* context = contextGroup()->getAWebGraphicsContext3D();
     if (!context)
         return;
     GLint linkStatus = 0;
@@ -185,4 +203,11 @@ void WebGLProgram::cacheInfoIfNeeded()
     m_infoValid = true;
 }
 
+void WebGLProgram::trace(Visitor* visitor)
+{
+    visitor->trace(m_vertexShader);
+    visitor->trace(m_fragmentShader);
+    WebGLSharedObject::trace(visitor);
+}
+
 }