summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordanakj <danakj@chromium.org>2016-03-24 20:11:58 -0700
committerCommit bot <commit-bot@chromium.org>2016-03-25 03:13:39 +0000
commit6d1bfc385d5f190c3b37e8df0793ae75af5ae6f5 (patch)
tree98e6e6494387fc2a87e0f60f6b4892fe1de2919c
parente18e7a6d2e1971e9b50b0ca3fe1fc9f17b264193 (diff)
downloadchromium_src-6d1bfc385d5f190c3b37e8df0793ae75af5ae6f5.zip
chromium_src-6d1bfc385d5f190c3b37e8df0793ae75af5ae6f5.tar.gz
chromium_src-6d1bfc385d5f190c3b37e8df0793ae75af5ae6f5.tar.bz2
Make lost context callback a base::Closure thru the WGC3DProvider.
This makes the WebGraphicsContext3DProvider have a method to set a lost context callback, and has that method take a SameThreadClosure, wrapped inside a WebClosure. The SameThreadClosure is converted to a base::Closure and passed thru by the WebGraphicsContext3DProviderImpl (which lives in content/) to the actual ContextProvider::SetLostContextCallback() method. This skips going through WebGraphicsContext3D in blink for the callback, though internally the provider does call the same method on WebGraphicsContext3DImpl, which blink used to hijack from it later. This removes the setter method from the WebGraphicsContext3D public API exposed to blink. It introduces a new public/platform/callback/ directory for the WebClosure in order to make separate DEPS rules for this class. It makes use of base::Bind/Callback which has previously not been allowed in blink, though only to wrap a WTF::SameThreadClosure. It also makes use of base/logging.h directly (previously we were unable to use DCHECK in public/platform since the files there build both with and without BLINK_IMPLEMENTATION and in the without case wtf/ is not available to be included. It also uses scoped_ptr since that is nicer than raw pointers and base::Callback understands it but doesn't understand OwnPtr. R=kbr@chromium.org, kinuko@chromium.org, piman@chromium.org BUG=584497 CQ_INCLUDE_TRYBOTS=tryserver.chromium.win:win_optional_gpu_tests_rel Review URL: https://codereview.chromium.org/1830033003 Cr-Commit-Position: refs/heads/master@{#383233}
-rw-r--r--content/renderer/webgraphicscontext3d_provider_impl.cc6
-rw-r--r--content/renderer/webgraphicscontext3d_provider_impl.h1
-rw-r--r--gpu/blink/webgraphicscontext3d_impl.h2
-rw-r--r--third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp31
-rw-r--r--third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.h1
-rw-r--r--third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridgeTest.cpp3
-rw-r--r--third_party/WebKit/Source/platform/graphics/gpu/DrawingBuffer.cpp5
-rw-r--r--third_party/WebKit/Source/platform/graphics/gpu/DrawingBuffer.h1
-rw-r--r--third_party/WebKit/Source/platform/graphics/gpu/DrawingBufferTest.cpp2
-rw-r--r--third_party/WebKit/public/blink_headers.gypi1
-rw-r--r--third_party/WebKit/public/platform/WebGraphicsContext3D.h1
-rw-r--r--third_party/WebKit/public/platform/WebGraphicsContext3DProvider.h6
-rw-r--r--third_party/WebKit/public/platform/callback/DEPS11
-rw-r--r--third_party/WebKit/public/platform/callback/WebClosure.h78
14 files changed, 116 insertions, 33 deletions
diff --git a/content/renderer/webgraphicscontext3d_provider_impl.cc b/content/renderer/webgraphicscontext3d_provider_impl.cc
index 5151e8a..28a3327 100644
--- a/content/renderer/webgraphicscontext3d_provider_impl.cc
+++ b/content/renderer/webgraphicscontext3d_provider_impl.cc
@@ -5,6 +5,7 @@
#include "content/renderer/webgraphicscontext3d_provider_impl.h"
#include "cc/blink/context_provider_web_context.h"
+#include "third_party/WebKit/public/platform/callback/WebClosure.h"
namespace content {
@@ -27,4 +28,9 @@ GrContext* WebGraphicsContext3DProviderImpl::grContext() {
return provider_->GrContext();
}
+void WebGraphicsContext3DProviderImpl::setLostContextCallback(
+ blink::WebClosure c) {
+ provider_->SetLostContextCallback(c.TakeBaseClosure());
+}
+
} // namespace content
diff --git a/content/renderer/webgraphicscontext3d_provider_impl.h b/content/renderer/webgraphicscontext3d_provider_impl.h
index de155bd..7b1d88c 100644
--- a/content/renderer/webgraphicscontext3d_provider_impl.h
+++ b/content/renderer/webgraphicscontext3d_provider_impl.h
@@ -33,6 +33,7 @@ class CONTENT_EXPORT WebGraphicsContext3DProviderImpl
blink::WebGraphicsContext3D* context3d() override;
gpu::gles2::GLES2Interface* contextGL() override;
GrContext* grContext() override;
+ void setLostContextCallback(blink::WebClosure) override;
private:
scoped_refptr<cc_blink::ContextProviderWebContext> provider_;
diff --git a/gpu/blink/webgraphicscontext3d_impl.h b/gpu/blink/webgraphicscontext3d_impl.h
index db08260..071e508 100644
--- a/gpu/blink/webgraphicscontext3d_impl.h
+++ b/gpu/blink/webgraphicscontext3d_impl.h
@@ -52,7 +52,7 @@ class GPU_BLINK_EXPORT WebGraphicsContext3DImpl
blink::WebGLId shader) override;
void setContextLostCallback(
- WebGraphicsContext3D::WebGraphicsContextLostCallback* callback) override;
+ WebGraphicsContext3D::WebGraphicsContextLostCallback* callback);
void setErrorMessageCallback(
WebGraphicsContext3D::WebGraphicsErrorMessageCallback* callback) override;
diff --git a/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp b/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp
index e156684..6f65886 100644
--- a/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp
+++ b/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp
@@ -96,7 +96,9 @@
#include "public/platform/Platform.h"
#include "public/platform/WebGraphicsContext3D.h"
#include "public/platform/WebGraphicsContext3DProvider.h"
+#include "public/platform/callback/WebClosure.h"
#include "wtf/ArrayBufferContents.h"
+#include "wtf/Functional.h"
#include "wtf/PassOwnPtr.h"
#include "wtf/text/StringBuilder.h"
#include "wtf/text/StringUTF8Adaptor.h"
@@ -491,29 +493,6 @@ private:
RawPtrWillBeMember<WebGLRenderingContextBase> m_context;
};
-class WebGLRenderingContextLostCallback final : public GarbageCollectedFinalized<WebGLRenderingContextLostCallback>, public WebGraphicsContext3D::WebGraphicsContextLostCallback {
-public:
- static WebGLRenderingContextLostCallback* create(WebGLRenderingContextBase* context)
- {
- return new WebGLRenderingContextLostCallback(context);
- }
-
- ~WebGLRenderingContextLostCallback() override { }
-
- virtual void onContextLost() { m_context->forceLostContext(WebGLRenderingContextBase::RealLostContext, WebGLRenderingContextBase::Auto); }
-
- DEFINE_INLINE_TRACE()
- {
- visitor->trace(m_context);
- }
-
-private:
- explicit WebGLRenderingContextLostCallback(WebGLRenderingContextBase* context)
- : m_context(context) { }
-
- RawPtrWillBeMember<WebGLRenderingContextBase> m_context;
-};
-
class WebGLRenderingContextErrorMessageCallback final : public GarbageCollectedFinalized<WebGLRenderingContextErrorMessageCallback>, public WebGraphicsContext3D::WebGraphicsErrorMessageCallback {
public:
static WebGLRenderingContextErrorMessageCallback* create(WebGLRenderingContextBase* context)
@@ -993,10 +972,9 @@ void WebGLRenderingContextBase::initializeNewContext()
contextGL()->Viewport(0, 0, drawingBufferWidth(), drawingBufferHeight());
contextGL()->Scissor(0, 0, drawingBufferWidth(), drawingBufferHeight());
- m_contextLostCallbackAdapter = WebGLRenderingContextLostCallback::create(this);
m_errorMessageCallbackAdapter = WebGLRenderingContextErrorMessageCallback::create(this);
- webContext()->setContextLostCallback(m_contextLostCallbackAdapter.get());
+ drawingBuffer()->contextProvider()->setLostContextCallback(WebClosure(WTF::bind(&WebGLRenderingContextBase::forceLostContext, createWeakThisPointer(), WebGLRenderingContextBase::RealLostContext, WebGLRenderingContextBase::Auto)));
webContext()->setErrorMessageCallback(m_errorMessageCallbackAdapter.get());
// This ensures that the context has a valid "lastFlushID" and won't be mistakenly identified as the "least recently used" context.
@@ -1112,7 +1090,7 @@ void WebGLRenderingContextBase::destroyContext()
m_extensionsUtil.clear();
- webContext()->setContextLostCallback(nullptr);
+ drawingBuffer()->contextProvider()->setLostContextCallback(WebClosure());
webContext()->setErrorMessageCallback(nullptr);
ASSERT(drawingBuffer());
@@ -6283,7 +6261,6 @@ DEFINE_TRACE(WebGLRenderingContextBase)
#if ENABLE(OILPAN)
visitor->trace(m_contextObjects);
#endif
- visitor->trace(m_contextLostCallbackAdapter);
visitor->trace(m_errorMessageCallbackAdapter);
visitor->trace(m_boundArrayBuffer);
visitor->trace(m_defaultVertexArrayObject);
diff --git a/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.h b/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.h
index 34afc49..e1c84d9 100644
--- a/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.h
+++ b/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.h
@@ -525,7 +525,6 @@ protected:
HashSet<UntracedMember<WebGLContextObject>> m_contextObjects;
#endif
- PersistentWillBeMember<WebGLRenderingContextLostCallback> m_contextLostCallbackAdapter;
PersistentWillBeMember<WebGLRenderingContextErrorMessageCallback> m_errorMessageCallbackAdapter;
// List of bound VBO's. Used to maintain info about sizes for ARRAY_BUFFER and stored values for ELEMENT_ARRAY_BUFFER
diff --git a/third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridgeTest.cpp b/third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridgeTest.cpp
index 2508eaf..2c21e79 100644
--- a/third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridgeTest.cpp
+++ b/third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridgeTest.cpp
@@ -41,6 +41,7 @@
#include "public/platform/WebTaskRunner.h"
#include "public/platform/WebThread.h"
#include "public/platform/WebTraceLocation.h"
+#include "public/platform/callback/WebClosure.h"
#include "skia/ext/texture_handle.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -94,6 +95,8 @@ public:
return m_gl;
}
+ void setLostContextCallback(WebClosure) override {}
+
private:
WebGraphicsContext3D* m_context3d;
gpu::gles2::GLES2Interface* m_gl;
diff --git a/third_party/WebKit/Source/platform/graphics/gpu/DrawingBuffer.cpp b/third_party/WebKit/Source/platform/graphics/gpu/DrawingBuffer.cpp
index 518f87b..0b4c635 100644
--- a/third_party/WebKit/Source/platform/graphics/gpu/DrawingBuffer.cpp
+++ b/third_party/WebKit/Source/platform/graphics/gpu/DrawingBuffer.cpp
@@ -211,6 +211,11 @@ gpu::gles2::GLES2Interface* DrawingBuffer::contextGL()
return m_gl;
}
+WebGraphicsContext3DProvider* DrawingBuffer::contextProvider()
+{
+ return m_contextProvider.get();
+}
+
void DrawingBuffer::setIsHidden(bool hidden)
{
if (m_isHidden == hidden)
diff --git a/third_party/WebKit/Source/platform/graphics/gpu/DrawingBuffer.h b/third_party/WebKit/Source/platform/graphics/gpu/DrawingBuffer.h
index 137830a..1a90b2c 100644
--- a/third_party/WebKit/Source/platform/graphics/gpu/DrawingBuffer.h
+++ b/third_party/WebKit/Source/platform/graphics/gpu/DrawingBuffer.h
@@ -152,6 +152,7 @@ public:
WebGraphicsContext3D* context();
gpu::gles2::GLES2Interface* contextGL();
+ WebGraphicsContext3DProvider* contextProvider();
// Returns the actual context attributes for this drawing buffer which may differ from the
// requested context attributes due to implementation limits.
diff --git a/third_party/WebKit/Source/platform/graphics/gpu/DrawingBufferTest.cpp b/third_party/WebKit/Source/platform/graphics/gpu/DrawingBufferTest.cpp
index 9b6258f..a360656 100644
--- a/third_party/WebKit/Source/platform/graphics/gpu/DrawingBufferTest.cpp
+++ b/third_party/WebKit/Source/platform/graphics/gpu/DrawingBufferTest.cpp
@@ -40,6 +40,7 @@
#include "public/platform/WebExternalTextureMailbox.h"
#include "public/platform/WebGraphicsContext3D.h"
#include "public/platform/WebGraphicsContext3DProvider.h"
+#include "public/platform/callback/WebClosure.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "wtf/RefPtr.h"
@@ -274,6 +275,7 @@ public:
gpu::gles2::GLES2Interface* contextGL() override { return m_gl.get(); }
// Not used by WebGL code.
GrContext* grContext() override { return nullptr; }
+ void setLostContextCallback(WebClosure) {}
private:
OwnPtr<WebGraphicsContext3D> m_context;
diff --git a/third_party/WebKit/public/blink_headers.gypi b/third_party/WebKit/public/blink_headers.gypi
index 394ddc2..d0020f6 100644
--- a/third_party/WebKit/public/blink_headers.gypi
+++ b/third_party/WebKit/public/blink_headers.gypi
@@ -5,6 +5,7 @@
{
'variables': {
'blink_public_sources': [
+ "platform/callback/WebClosure.h",
"platform/Platform.h",
"platform/FilePathConversion.h",
"platform/URLConversion.h",
diff --git a/third_party/WebKit/public/platform/WebGraphicsContext3D.h b/third_party/WebKit/public/platform/WebGraphicsContext3D.h
index 2f59efb..21f725b 100644
--- a/third_party/WebKit/public/platform/WebGraphicsContext3D.h
+++ b/third_party/WebKit/public/platform/WebGraphicsContext3D.h
@@ -145,7 +145,6 @@ public:
virtual WebString getShaderInfoLog(WebGLId shader) = 0;
virtual WebString getShaderSource(WebGLId shader) = 0;
- virtual void setContextLostCallback(WebGraphicsContextLostCallback* callback) { }
virtual void setErrorMessageCallback(WebGraphicsErrorMessageCallback* callback) { }
virtual WebString getTranslatedShaderSourceANGLE(WebGLId shader) = 0;
diff --git a/third_party/WebKit/public/platform/WebGraphicsContext3DProvider.h b/third_party/WebKit/public/platform/WebGraphicsContext3DProvider.h
index 709c1d2..ba149c1 100644
--- a/third_party/WebKit/public/platform/WebGraphicsContext3DProvider.h
+++ b/third_party/WebKit/public/platform/WebGraphicsContext3DProvider.h
@@ -31,8 +31,6 @@
#ifndef WebGraphicsContext3DProvider_h
#define WebGraphicsContext3DProvider_h
-#include "WebCommon.h"
-
class GrContext;
namespace gpu {
@@ -42,7 +40,7 @@ class GLES2Interface;
}
namespace blink {
-
+class WebClosure;
class WebGraphicsContext3D;
class WebGraphicsContext3DProvider {
@@ -52,6 +50,8 @@ public:
virtual WebGraphicsContext3D* context3d() = 0;
virtual gpu::gles2::GLES2Interface* contextGL() = 0;
virtual GrContext* grContext() = 0;
+
+ virtual void setLostContextCallback(WebClosure) = 0;
};
} // namespace blink
diff --git a/third_party/WebKit/public/platform/callback/DEPS b/third_party/WebKit/public/platform/callback/DEPS
new file mode 100644
index 0000000..a8b8245
--- /dev/null
+++ b/third_party/WebKit/public/platform/callback/DEPS
@@ -0,0 +1,11 @@
+include_rules = [
+ # Bind/Callback is only allowed in rare cases, here it's allowed to convert
+ # from WTF::Function to base::Callback in order to pass callbacks out of
+ # blink.
+ "+base/bind.h",
+ "+base/callback.h",
+ "+base/callback_helpers.h",
+ "+base/logging.h",
+ "+base/macros.h",
+ "+base/memory/scoped_ptr.h",
+]
diff --git a/third_party/WebKit/public/platform/callback/WebClosure.h b/third_party/WebKit/public/platform/callback/WebClosure.h
new file mode 100644
index 0000000..8c0fe5c
--- /dev/null
+++ b/third_party/WebKit/public/platform/callback/WebClosure.h
@@ -0,0 +1,78 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef WebClosure_h
+#define WebClosure_h
+
+#include "base/bind.h"
+#include "base/callback.h"
+#include "base/callback_helpers.h"
+#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+#include "public/platform/WebCommon.h"
+
+#include <utility>
+
+#if BLINK_IMPLEMENTATION
+#include "wtf/Functional.h"
+#else
+#include "base/logging.h"
+#endif
+
+namespace blink {
+
+// Conversion from WTF closures to base closures to pass a callback out of
+// blink.
+class WebClosure {
+public:
+#if BLINK_IMPLEMENTATION
+ WebClosure() {}
+
+ explicit WebClosure(PassOwnPtr<SameThreadClosure> c)
+ {
+ m_closure = base::Bind(&RunAndDelete, base::Passed(make_scoped_ptr(c.leakPtr())));
+ }
+#endif
+
+ // TODO(danakj): These could be =default with MSVC 2015.
+ WebClosure(WebClosure&& other) { *this = std::move(other); }
+ WebClosure& operator=(WebClosure&& other)
+ {
+#if DCHECK_IS_ON()
+ m_haveClosure = other.m_haveClosure;
+ other.m_haveClosure = false;
+#endif
+ m_closure = std::move(other.m_closure);
+ return *this;
+ }
+
+#if !BLINK_IMPLEMENTATION
+ // TODO(danakj): This could be rvalue-ref-qualified.
+ base::Closure TakeBaseClosure()
+ {
+#if DCHECK_IS_ON()
+ // Don't call this more than once!
+ DCHECK(m_haveClosure);
+ m_haveClosure = false;
+#endif
+ return std::move(m_closure);
+ }
+#endif
+
+private:
+#if BLINK_IMPLEMENTATION
+ static void RunAndDelete(scoped_ptr<SameThreadClosure> c) { (*c)(); }
+#endif
+
+#if DCHECK_IS_ON()
+ bool m_haveClosure = true;
+#endif
+ base::Closure m_closure;
+
+ DISALLOW_COPY_AND_ASSIGN(WebClosure);
+};
+
+} // namespace blink
+
+#endif // WebClosure_h