Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Unified Diff: third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp

Issue 1990063004: Move bindToCurrentThread out to the creators of WebGL contexts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: bindwebgl: . Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp
diff --git a/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp b/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp
index 4f64e965baee7d050d1238d96baa164b5d28447a..9346b16bc082daa03d93d324f0a9f5f1996bde0e 100644
--- a/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp
+++ b/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp
@@ -531,63 +531,58 @@ static String extractWebGLContextCreationError(const Platform::GraphicsInfo& inf
return statusMessage;
}
-class WebGLRenderingContextBase::ContextProviderCreationInfo {
-public:
- ContextProviderCreationInfo(Platform::ContextAttributes contextAttributes, Platform::GraphicsInfo glInfo, ScriptState* scriptState)
- {
- m_contextAttributes = contextAttributes;
- m_glInfo = glInfo;
- m_scriptState = scriptState;
- }
- Platform::ContextAttributes contextAttributes() { return m_contextAttributes; }
- Platform::GraphicsInfo glInfo() { return m_glInfo; }
- ScriptState* scriptState() { return m_scriptState; }
- void setContextProvider(PassOwnPtr<WebGraphicsContext3DProvider> provider) { m_provider = std::move(provider); }
- PassOwnPtr<WebGraphicsContext3DProvider> releaseContextProvider() { return std::move(m_provider); }
-private:
- Platform::ContextAttributes m_contextAttributes;
- Platform::GraphicsInfo m_glInfo;
- ScriptState* m_scriptState;
- OwnPtr<WebGraphicsContext3DProvider> m_provider;
+struct ContextProviderCreationInfo {
+ // Inputs.
+ Platform::ContextAttributes contextAttributes;
+ Platform::GraphicsInfo* glInfo;
+ ScriptState* scriptState;
+ // Outputs.
+ OwnPtr<WebGraphicsContext3DProvider> createdContextProvider;
};
-void WebGLRenderingContextBase::createContextProviderOnMainThread(ContextProviderCreationInfo* creationInfo, WaitableEvent* waitableEvent)
+static void createContextProviderOnMainThread(ContextProviderCreationInfo* creationInfo, WaitableEvent* waitableEvent)
{
ASSERT(isMainThread());
- Platform::GraphicsInfo glInfo = creationInfo->glInfo();
- OwnPtr<WebGraphicsContext3DProvider> provider = adoptPtr(Platform::current()->createOffscreenGraphicsContext3DProvider(
- creationInfo->contextAttributes(), creationInfo->scriptState()->getExecutionContext()->url(), 0, &glInfo, Platform::DoNotBindToCurrentThread));
- creationInfo->setContextProvider(std::move(provider));
+ creationInfo->createdContextProvider = adoptPtr(Platform::current()->createOffscreenGraphicsContext3DProvider(
+ creationInfo->contextAttributes, creationInfo->scriptState->getExecutionContext()->url(), 0, creationInfo->glInfo));
waitableEvent->signal();
}
-PassOwnPtr<WebGraphicsContext3DProvider> WebGLRenderingContextBase::createContextProviderOnWorkerThread(Platform::ContextAttributes contextAttributes, Platform::GraphicsInfo glInfo, ScriptState* scriptState)
+static PassOwnPtr<WebGraphicsContext3DProvider> createContextProviderOnWorkerThread(Platform::ContextAttributes contextAttributes, Platform::GraphicsInfo* glInfo, ScriptState* scriptState)
{
WaitableEvent waitableEvent;
- OwnPtr<ContextProviderCreationInfo> creationInfo = adoptPtr(new ContextProviderCreationInfo(contextAttributes, glInfo, scriptState));
+ ContextProviderCreationInfo creationInfo;
+ creationInfo.contextAttributes = contextAttributes;
+ creationInfo.glInfo = glInfo;
+ creationInfo.scriptState = scriptState;
WebTaskRunner* taskRunner = Platform::current()->mainThread()->getWebTaskRunner();
- taskRunner->postTask(BLINK_FROM_HERE, threadSafeBind(&createContextProviderOnMainThread, AllowCrossThreadAccess(creationInfo.get()), AllowCrossThreadAccess(&waitableEvent)));
+ taskRunner->postTask(BLINK_FROM_HERE, threadSafeBind(&createContextProviderOnMainThread, AllowCrossThreadAccess(&creationInfo), AllowCrossThreadAccess(&waitableEvent)));
waitableEvent.wait();
- return creationInfo->releaseContextProvider();
+ return std::move(creationInfo.createdContextProvider);
}
PassOwnPtr<WebGraphicsContext3DProvider> WebGLRenderingContextBase::createContextProviderInternal(HTMLCanvasElement* canvas, ScriptState* scriptState, WebGLContextAttributes attributes, unsigned webGLVersion)
{
+ // Exactly one of these must be provided.
+ DCHECK_EQ(!canvas, !!scriptState);
+ // The canvas is only given on the main thread.
+ DCHECK(!canvas || isMainThread());
+
Platform::ContextAttributes contextAttributes = toPlatformContextAttributes(attributes, webGLVersion);
Platform::GraphicsInfo glInfo;
OwnPtr<WebGraphicsContext3DProvider> contextProvider;
- if (canvas) {
+ if (isMainThread()) {
+ const auto& url = canvas ? canvas->document().topDocument().url() : scriptState->getExecutionContext()->url();
contextProvider = adoptPtr(Platform::current()->createOffscreenGraphicsContext3DProvider(
- contextAttributes, canvas->document().topDocument().url(), 0, &glInfo, Platform::BindToCurrentThread));
+ contextAttributes, url, 0, &glInfo));
} else {
- if (isMainThread()) {
- contextProvider = adoptPtr(Platform::current()->createOffscreenGraphicsContext3DProvider(
- contextAttributes, scriptState->getExecutionContext()->url(), 0, &glInfo, Platform::BindToCurrentThread));
- } else {
- contextProvider = createContextProviderOnWorkerThread(contextAttributes, glInfo, scriptState);
- if (!contextProvider->bindToCurrentThread())
- return nullptr;
- }
+ contextProvider = createContextProviderOnWorkerThread(contextAttributes, &glInfo, scriptState);
+ }
+ if (contextProvider && !contextProvider->bindToCurrentThread()) {
+ contextProvider = nullptr;
+ String errorString(glInfo.errorMessage.utf8().data());
+ errorString.insert("bindToCurrentThread failed: ", 0);
+ glInfo.errorMessage = errorString;
}
if (!contextProvider || shouldFailContextCreationForTesting) {
shouldFailContextCreationForTesting = false;
@@ -6051,9 +6046,9 @@ void WebGLRenderingContextBase::maybeRestoreContext(Timer<WebGLRenderingContextB
Platform::ContextAttributes attributes = toPlatformContextAttributes(m_requestedAttributes, version());
Platform::GraphicsInfo glInfo;
OwnPtr<WebGraphicsContext3DProvider> contextProvider = adoptPtr(Platform::current()->createOffscreenGraphicsContext3DProvider(
- attributes, canvas()->document().topDocument().url(), 0, &glInfo, Platform::BindToCurrentThread));
+ attributes, canvas()->document().topDocument().url(), 0, &glInfo));
RefPtr<DrawingBuffer> buffer;
- if (contextProvider) {
+ if (contextProvider->bindToCurrentThread()) {
// Construct a new drawing buffer with the new GL context.
buffer = createDrawingBuffer(std::move(contextProvider));
// If DrawingBuffer::create() fails to allocate a fbo, |drawingBuffer| is set to null.
« no previous file with comments | « third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.h ('k') | third_party/WebKit/public/platform/Platform.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698