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 b0926df7214b42806c1b44e89d5a4c4469b3b0b1..4bfb2dba1ad196ebfa5b5b8cefaa73ac2059a199 100644 |
--- a/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp |
+++ b/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp |
@@ -547,7 +547,7 @@ struct ContextProviderCreationInfo { |
// Inputs. |
Platform::ContextAttributes contextAttributes; |
Platform::GraphicsInfo* glInfo; |
- ScriptState* scriptState; |
+ KURL url; |
// Outputs. |
std::unique_ptr<WebGraphicsContext3DProvider> createdContextProvider; |
}; |
@@ -558,8 +558,7 @@ static void createContextProviderOnMainThread( |
ASSERT(isMainThread()); |
creationInfo->createdContextProvider = |
wrapUnique(Platform::current()->createOffscreenGraphicsContext3DProvider( |
- creationInfo->contextAttributes, |
- creationInfo->scriptState->getExecutionContext()->url(), 0, |
+ creationInfo->contextAttributes, creationInfo->url, 0, |
creationInfo->glInfo)); |
waitableEvent->signal(); |
} |
@@ -568,12 +567,12 @@ static std::unique_ptr<WebGraphicsContext3DProvider> |
createContextProviderOnWorkerThread( |
Platform::ContextAttributes contextAttributes, |
Platform::GraphicsInfo* glInfo, |
- ScriptState* scriptState) { |
+ const KURL& url) { |
WaitableEvent waitableEvent; |
ContextProviderCreationInfo creationInfo; |
creationInfo.contextAttributes = contextAttributes; |
creationInfo.glInfo = glInfo; |
- creationInfo.scriptState = scriptState; |
+ creationInfo.url = url; |
WebTaskRunner* taskRunner = |
Platform::current()->mainThread()->getWebTaskRunner(); |
taskRunner->postTask(BLINK_FROM_HERE, |
@@ -599,15 +598,15 @@ WebGLRenderingContextBase::createContextProviderInternal( |
toPlatformContextAttributes(attributes, webGLVersion); |
Platform::GraphicsInfo glInfo; |
std::unique_ptr<WebGraphicsContext3DProvider> contextProvider; |
+ const auto& url = canvas ? canvas->document().topDocument().url() |
+ : scriptState->getExecutionContext()->url(); |
if (isMainThread()) { |
- const auto& url = canvas ? canvas->document().topDocument().url() |
- : scriptState->getExecutionContext()->url(); |
contextProvider = wrapUnique( |
Platform::current()->createOffscreenGraphicsContext3DProvider( |
contextAttributes, url, 0, &glInfo)); |
} else { |
- contextProvider = createContextProviderOnWorkerThread(contextAttributes, |
- &glInfo, scriptState); |
+ contextProvider = |
+ createContextProviderOnWorkerThread(contextAttributes, &glInfo, url); |
} |
if (contextProvider && !contextProvider->bindToCurrentThread()) { |
contextProvider = nullptr; |
@@ -7297,7 +7296,10 @@ bool WebGLRenderingContextBase::validateDrawElements(const char* functionName, |
void WebGLRenderingContextBase::dispatchContextLostEvent(TimerBase*) { |
WebGLContextEvent* event = WebGLContextEvent::create( |
EventTypeNames::webglcontextlost, false, true, ""); |
- canvas()->dispatchEvent(event); |
+ if (getOffscreenCanvas()) |
+ getOffscreenCanvas()->dispatchEvent(event); |
+ else |
+ canvas()->dispatchEvent(event); |
m_restoreAllowed = event->defaultPrevented(); |
if (m_restoreAllowed && !m_isHidden) { |
if (m_autoRecoveryMethod == Auto) |
@@ -7317,15 +7319,17 @@ void WebGLRenderingContextBase::maybeRestoreContext(TimerBase*) { |
if (!m_restoreAllowed) |
return; |
- LocalFrame* frame = canvas()->document().frame(); |
- if (!frame) |
- return; |
+ if (canvas()) { |
+ LocalFrame* frame = canvas()->document().frame(); |
+ if (!frame) |
+ return; |
- Settings* settings = frame->settings(); |
+ Settings* settings = frame->settings(); |
- if (!frame->loader().client()->allowWebGL(settings && |
- settings->webGLEnabled())) |
- return; |
+ if (!frame->loader().client()->allowWebGL(settings && |
+ settings->webGLEnabled())) |
+ return; |
+ } |
// If the context was lost due to RealLostContext, we need to destroy the old |
// DrawingBuffer before creating new DrawingBuffer to ensure resource budget |
@@ -7338,16 +7342,28 @@ void WebGLRenderingContextBase::maybeRestoreContext(TimerBase*) { |
Platform::ContextAttributes attributes = |
toPlatformContextAttributes(creationAttributes(), version()); |
Platform::GraphicsInfo glInfo; |
- std::unique_ptr<WebGraphicsContext3DProvider> contextProvider = |
- wrapUnique(Platform::current()->createOffscreenGraphicsContext3DProvider( |
- attributes, canvas()->document().topDocument().url(), 0, &glInfo)); |
+ std::unique_ptr<WebGraphicsContext3DProvider> contextProvider; |
+ const auto& url = canvas() |
+ ? canvas()->document().topDocument().url() |
+ : getOffscreenCanvas()->getExecutionContext()->url(); |
+ if (isMainThread()) { |
+ contextProvider = wrapUnique( |
+ Platform::current()->createOffscreenGraphicsContext3DProvider( |
+ attributes, url, 0, &glInfo)); |
+ } else { |
+ contextProvider = |
+ createContextProviderOnWorkerThread(attributes, &glInfo, url); |
+ } |
RefPtr<DrawingBuffer> buffer; |
if (contextProvider && contextProvider->bindToCurrentThread()) { |
// Construct a new drawing buffer with the new GL context. |
- // TODO(xidachen): make sure that the second parameter is correct for |
- // OffscreenCanvas. |
- buffer = createDrawingBuffer(std::move(contextProvider), |
- DrawingBuffer::AllowChromiumImage); |
+ if (canvas()) { |
+ buffer = createDrawingBuffer(std::move(contextProvider), |
+ DrawingBuffer::AllowChromiumImage); |
+ } else { |
+ buffer = createDrawingBuffer(std::move(contextProvider), |
+ DrawingBuffer::DisallowChromiumImage); |
Justin Novosad
2016/11/15 19:54:33
Why? Perhaps add a comment.
xidachen
2016/11/15 20:14:18
Comment added in the new patch.
Long story short:
|
+ } |
// If DrawingBuffer::create() fails to allocate a fbo, |drawingBuffer| is |
// set to null. |
} |
@@ -7378,8 +7394,12 @@ void WebGLRenderingContextBase::maybeRestoreContext(TimerBase*) { |
setupFlags(); |
initializeNewContext(); |
markContextChanged(CanvasContextChanged); |
- canvas()->dispatchEvent(WebGLContextEvent::create( |
- EventTypeNames::webglcontextrestored, false, true, "")); |
+ WebGLContextEvent* event = WebGLContextEvent::create( |
+ EventTypeNames::webglcontextrestored, false, true, ""); |
+ if (canvas()) |
+ canvas()->dispatchEvent(event); |
+ else |
+ getOffscreenCanvas()->dispatchEvent(event); |
} |
String WebGLRenderingContextBase::ensureNotNull(const String& text) const { |