Index: Source/core/html/canvas/WebGLSharedResources.cpp |
diff --git a/Source/core/html/canvas/WebGLSharedResources.cpp b/Source/core/html/canvas/WebGLSharedResources.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a8f6f5a34723dbdb317cbde8bc5fd77a3006e07c |
--- /dev/null |
+++ b/Source/core/html/canvas/WebGLSharedResources.cpp |
@@ -0,0 +1,118 @@ |
+/* |
+ * Copyright (C) 2013 Google Inc. All rights reserved. |
+ * |
+ * Redistribution and use in source and binary forms, with or without |
+ * modification, are permitted provided that the following conditions |
+ * are met: |
+ * 1. Redistributions of source code must retain the above copyright |
+ * notice, this list of conditions and the following disclaimer. |
+ * 2. Redistributions in binary form must reproduce the above copyright |
+ * notice, this list of conditions and the following disclaimer in the |
+ * documentation and/or other materials provided with the distribution. |
+ * |
+ * THIS SOFTWARE IS PROVIDED BY GOOGLE, INC. ``AS IS'' AND ANY |
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE, INC. OR |
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+ */ |
+ |
+#include "config.h" |
+ |
+#include "core/html/canvas/WebGLSharedResources.h" |
+ |
+#include "core/html/canvas/WebGLAcquireSharedResourceCallback.h" |
+#include "core/html/canvas/WebGLContextGroup.h" |
+#include "core/html/canvas/WebGLRenderingContext.h" |
+#include "core/html/canvas/WebGLShareGroup.h" |
+#include "core/platform/graphics/Extensions3D.h" |
+ |
+namespace WebCore { |
+ |
+WebGLSharedResources::WebGLSharedResources(WebGLRenderingContext* context) |
+ : WebGLExtension(context) |
+ , m_shareGroup(WebGLShareGroup::create(context->contextGroup())) |
+{ |
+} |
+ |
+WebGLSharedResources::~WebGLSharedResources() |
+{ |
+} |
+ |
+bool WebGLSharedResources::intToAcquireMode(unsigned value, WebGLSharedObject::AcquireMode* mode) |
+{ |
+ switch (value) { |
+ case 0: |
+ *mode = WebGLSharedObject::Unacquired; |
+ return true; |
+ case 1: |
+ *mode = WebGLSharedObject::ReadOnly; |
+ return true; |
+ case 4: |
+ *mode = WebGLSharedObject::Exclusive; |
+ return true; |
+ default: |
+ return false; |
+ } |
+} |
+ |
+WebGLExtension::ExtensionName WebGLSharedResources::getName() const |
+{ |
+ return WebGLSharedResourcesName; |
+} |
+ |
+void WebGLSharedResources::lose(bool force) |
+{ |
+ // WebGLSharedResouces is not lost because it would cause too many hard to work around race considtions. |
+ // It is not actually manipulating GL resources. It is just passing references. |
+ if (force) |
+ WebGLExtension::lose(true); |
+} |
+ |
+PassRefPtr<WebGLSharedResources> WebGLSharedResources::create(WebGLRenderingContext* context) |
+{ |
+ return adoptRef(new WebGLSharedResources(context)); |
+} |
+ |
+long WebGLSharedResources::acquireSharedResource(WebGLSharedObject* object, unsigned desiredMode, PassRefPtr<WebGLAcquireSharedResourceCallback> callback, ExceptionCode& ec) |
+{ |
+ WebGLSharedObject::AcquireMode mode; |
+ if (!intToAcquireMode(desiredMode, &mode)) { |
+ m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "acquireSharedResource", "unknown mode"); |
+ return 0; |
+ } |
+ return m_context->acquireSharedResource(object, mode, callback, ec); |
+} |
+ |
+void WebGLSharedResources::releaseSharedResource(WebGLSharedObject* object, ExceptionCode& ec) |
+{ |
+ m_context->releaseSharedResource(object, ec); |
+} |
+ |
+void WebGLSharedResources::cancelAcquireSharedResource(long id) |
+{ |
+ m_context->cancelAcquireSharedResource(id); |
+} |
+ |
+bool WebGLSharedResources::supported(WebGLRenderingContext*) |
+{ |
+ return true; |
+} |
+ |
+PassRefPtr<WebGLShareGroup> WebGLSharedResources::group() const |
+{ |
+ return m_shareGroup; |
+} |
+ |
+const char* WebGLSharedResources::getExtensionName() |
+{ |
+ return "WEBGL_shared_resources"; |
+} |
+ |
+} // namespace WebCore |