Chromium Code Reviews| 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 294e0c46f234963ceb291f12a10d635e4897d627..2087a2d863ca6fd0322798a3eb4df6c7c7722445 100644 |
| --- a/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp |
| +++ b/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp |
| @@ -66,7 +66,6 @@ |
| #include "modules/webgl/WebGLCompressedTexturePVRTC.h" |
| #include "modules/webgl/WebGLCompressedTextureS3TC.h" |
| #include "modules/webgl/WebGLContextAttributeHelpers.h" |
| -#include "modules/webgl/WebGLContextAttributes.h" |
| #include "modules/webgl/WebGLContextEvent.h" |
| #include "modules/webgl/WebGLContextGroup.h" |
| #include "modules/webgl/WebGLDebugRendererInfo.h" |
| @@ -79,20 +78,19 @@ |
| #include "modules/webgl/WebGLRenderbuffer.h" |
| #include "modules/webgl/WebGLShader.h" |
| #include "modules/webgl/WebGLShaderPrecisionFormat.h" |
| -#include "modules/webgl/WebGLTexture.h" |
| #include "modules/webgl/WebGLUniformLocation.h" |
| #include "modules/webgl/WebGLVertexArrayObject.h" |
| #include "modules/webgl/WebGLVertexArrayObjectOES.h" |
| #include "platform/CheckedInt.h" |
| #include "platform/RuntimeEnabledFeatures.h" |
| +#include "platform/ThreadSafeFunctional.h" |
| +#include "platform/WaitableEvent.h" |
| #include "platform/geometry/IntSize.h" |
| #include "platform/graphics/GraphicsContext.h" |
| #include "platform/graphics/UnacceleratedImageBufferSurface.h" |
| #include "platform/graphics/gpu/AcceleratedImageBufferSurface.h" |
| -#include "platform/graphics/gpu/DrawingBuffer.h" |
| #include "public/platform/Platform.h" |
| #include "public/platform/WebGraphicsContext3D.h" |
| -#include "public/platform/WebGraphicsContext3DProvider.h" |
| #include "public/platform/functional/WebFunction.h" |
| #include "wtf/Functional.h" |
| #include "wtf/PassOwnPtr.h" |
| @@ -503,29 +501,63 @@ static String extractWebGLContextCreationError(const Platform::GraphicsInfo& inf |
| return statusMessage; |
| } |
| -static PassOwnPtr<WebGraphicsContext3DProvider> createWebGraphicsContext3DProviderInternal(HTMLCanvasElement* canvas, ScriptState* scriptState, WebGLContextAttributes attributes, unsigned webGLVersion) |
| +// A helper function, the reason it exist is because this has to be called in createWebGraphicsContext3DProviderMainThread() |
| +// because contextProvider->contextGL() checks whether the current thread is the same as the thread that creates contextProvider. |
| +static bool checkCreatedContext3DProvider(HTMLCanvasElement* canvas, WebGraphicsContext3DProvider* contextProvider, Platform::GraphicsInfo& glInfo) |
| { |
| - Platform::ContextAttributes contextAttributes = toPlatformContextAttributes(attributes, webGLVersion); |
| - Platform::GraphicsInfo glInfo; |
| - OwnPtr<WebGraphicsContext3DProvider> contextProvider; |
| - if (canvas) { |
| - contextProvider = adoptPtr(Platform::current()->createOffscreenGraphicsContext3DProvider( |
| - contextAttributes, canvas->document().topDocument().url(), 0, &glInfo)); |
| - } else { |
| - contextProvider = adoptPtr(Platform::current()->createOffscreenGraphicsContext3DProvider( |
| - contextAttributes, scriptState->getExecutionContext()->url(), 0, &glInfo)); |
| - } |
| + ASSERT(isMainThread()); |
| if (!contextProvider || shouldFailContextCreationForTesting) { |
| shouldFailContextCreationForTesting = false; |
| if (canvas) |
| canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcontextcreationerror, false, true, extractWebGLContextCreationError(glInfo))); |
| - return nullptr; |
| + return false; |
| } |
| gpu::gles2::GLES2Interface* gl = contextProvider->contextGL(); |
|
xidachen
2016/04/29 15:58:21
The program works fine on a Release build, but cra
bajones
2016/04/29 19:38:25
Many of our bots run with DCHECKs enabled, so if t
xidachen
2016/04/29 19:41:11
Yes, the current code crashes.
I am quite surpris
Justin Novosad
2016/04/29 19:43:43
You just have to call ContextProviderCommandBuffer
xidachen
2016/04/30 01:02:33
Here is what I propose:
We change the WebGraphics
|
| if (!String(gl->GetString(GL_EXTENSIONS)).contains("GL_OES_packed_depth_stencil")) { |
| if (canvas) |
| canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcontextcreationerror, false, true, "OES_packed_depth_stencil support is required.")); |
| - return nullptr; |
| + return false; |
| + } |
| + return true; |
| +} |
| + |
| +void WebGLRenderingContextBase::createWebGraphicsContext3DProviderMainThread(WebGLRenderingContextBase::createWebGraphicsContext3DProviderUtils* createUtils, WaitableEvent* waitableEvent) |
| +{ |
| + ASSERT(isMainThread()); |
| + Platform::GraphicsInfo glInfo = createUtils->glInfo(); |
| + OwnPtr<WebGraphicsContext3DProvider> provider = adoptPtr(Platform::current()->createOffscreenGraphicsContext3DProvider( |
| + createUtils->contextAttributes(), createUtils->scriptState()->getExecutionContext()->url(), 0, &glInfo)); |
| + if (checkCreatedContext3DProvider(nullptr, provider.get(), glInfo)) |
| + createUtils->setContextProvider(provider.release()); |
| + else |
| + createUtils->setContextProvider(nullptr); |
| + waitableEvent->signal(); |
| +} |
| + |
| +PassOwnPtr<WebGraphicsContext3DProvider> WebGLRenderingContextBase::createWebGraphicsContext3DProviderInternal(HTMLCanvasElement* canvas, ScriptState* scriptState, WebGLContextAttributes attributes, unsigned webGLVersion) |
| +{ |
| + Platform::ContextAttributes contextAttributes = toPlatformContextAttributes(attributes, webGLVersion); |
| + Platform::GraphicsInfo glInfo; |
| + OwnPtr<WebGraphicsContext3DProvider> contextProvider; |
| + if (canvas) { |
| + contextProvider = adoptPtr(Platform::current()->createOffscreenGraphicsContext3DProvider( |
| + contextAttributes, canvas->document().topDocument().url(), 0, &glInfo)); |
| + if (!checkCreatedContext3DProvider(canvas, contextProvider.get(), glInfo)) |
| + return nullptr; |
| + } else { |
| + if (isMainThread()) { |
| + contextProvider = adoptPtr(Platform::current()->createOffscreenGraphicsContext3DProvider( |
| + contextAttributes, scriptState->getExecutionContext()->url(), 0, &glInfo)); |
| + if (!checkCreatedContext3DProvider(canvas, contextProvider.get(), glInfo)) |
| + return nullptr; |
| + } else { |
| + WaitableEvent waitableEvent; |
| + WebTaskRunner* taskRunner = Platform::current()->mainThread()->getWebTaskRunner(); |
| + OwnPtr<WebGLRenderingContextBase::createWebGraphicsContext3DProviderUtils> createUtils = adoptPtr(new WebGLRenderingContextBase::createWebGraphicsContext3DProviderUtils(contextAttributes, glInfo, scriptState)); |
| + taskRunner->postTask(BLINK_FROM_HERE, threadSafeBind(&createWebGraphicsContext3DProviderMainThread, AllowCrossThreadAccess(createUtils.get()), AllowCrossThreadAccess(&waitableEvent))); |
| + waitableEvent.wait(); |
| + contextProvider = createUtils->releaseContextProvider(); |
| + } |
| } |
| return contextProvider.release(); |