Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2009 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 519 formatWebGLStatusString("VENDOR", info.vendorId ? String::format("0x%04x", i nfo.vendorId).utf8().data() : "0xffff", statusMessage); | 519 formatWebGLStatusString("VENDOR", info.vendorId ? String::format("0x%04x", i nfo.vendorId).utf8().data() : "0xffff", statusMessage); |
| 520 formatWebGLStatusString("DEVICE", info.deviceId ? String::format("0x%04x", i nfo.deviceId).utf8().data() : "0xffff", statusMessage); | 520 formatWebGLStatusString("DEVICE", info.deviceId ? String::format("0x%04x", i nfo.deviceId).utf8().data() : "0xffff", statusMessage); |
| 521 formatWebGLStatusString("GL_VENDOR", info.vendorInfo.utf8().data(), statusMe ssage); | 521 formatWebGLStatusString("GL_VENDOR", info.vendorInfo.utf8().data(), statusMe ssage); |
| 522 formatWebGLStatusString("GL_RENDERER", info.rendererInfo.utf8().data(), stat usMessage); | 522 formatWebGLStatusString("GL_RENDERER", info.rendererInfo.utf8().data(), stat usMessage); |
| 523 formatWebGLStatusString("GL_VERSION", info.driverVersion.utf8().data(), stat usMessage); | 523 formatWebGLStatusString("GL_VERSION", info.driverVersion.utf8().data(), stat usMessage); |
| 524 formatWebGLStatusString("Sandboxed", info.sandboxed ? "yes" : "no", statusMe ssage); | 524 formatWebGLStatusString("Sandboxed", info.sandboxed ? "yes" : "no", statusMe ssage); |
| 525 formatWebGLStatusString("Optimus", info.optimus ? "yes" : "no", statusMessag e); | 525 formatWebGLStatusString("Optimus", info.optimus ? "yes" : "no", statusMessag e); |
| 526 formatWebGLStatusString("AMD switchable", info.amdSwitchable ? "yes" : "no", statusMessage); | 526 formatWebGLStatusString("AMD switchable", info.amdSwitchable ? "yes" : "no", statusMessage); |
| 527 formatWebGLStatusString("Reset notification strategy", String::format("0x%04 x", info.resetNotificationStrategy).utf8().data(), statusMessage); | 527 formatWebGLStatusString("Reset notification strategy", String::format("0x%04 x", info.resetNotificationStrategy).utf8().data(), statusMessage); |
| 528 formatWebGLStatusString("GPU process crash count", String::number(info.proce ssCrashCount).utf8().data(), statusMessage); | 528 formatWebGLStatusString("GPU process crash count", String::number(info.proce ssCrashCount).utf8().data(), statusMessage); |
| 529 formatWebGLStatusString("ErrorMessage", info.errorMessage.utf8().data(), sta tusMessage); | 529 String errorString(info.errorMessage.utf8().data()); |
| 530 errorString.insert("bindToCurrentThread failed: ", 0); | |
| 531 formatWebGLStatusString("ErrorMessage", errorString, statusMessage); | |
| 530 statusMessage.append("."); | 532 statusMessage.append("."); |
| 531 return statusMessage; | 533 return statusMessage; |
| 532 } | 534 } |
| 533 | 535 |
| 534 class WebGLRenderingContextBase::ContextProviderCreationInfo { | 536 struct ContextProviderCreationInfo { |
| 535 public: | 537 // Inputs. |
| 536 ContextProviderCreationInfo(Platform::ContextAttributes contextAttributes, P latform::GraphicsInfo glInfo, ScriptState* scriptState) | 538 Platform::ContextAttributes contextAttributes; |
| 537 { | 539 Platform::GraphicsInfo* glInfo; |
| 538 m_contextAttributes = contextAttributes; | 540 ScriptState* scriptState; |
| 539 m_glInfo = glInfo; | 541 // Outputs. |
| 540 m_scriptState = scriptState; | 542 OwnPtr<WebGraphicsContext3DProvider> createdContextProvider; |
| 541 } | |
| 542 Platform::ContextAttributes contextAttributes() { return m_contextAttributes ; } | |
| 543 Platform::GraphicsInfo glInfo() { return m_glInfo; } | |
| 544 ScriptState* scriptState() { return m_scriptState; } | |
| 545 void setContextProvider(PassOwnPtr<WebGraphicsContext3DProvider> provider) { m_provider = std::move(provider); } | |
| 546 PassOwnPtr<WebGraphicsContext3DProvider> releaseContextProvider() { return s td::move(m_provider); } | |
| 547 private: | |
| 548 Platform::ContextAttributes m_contextAttributes; | |
| 549 Platform::GraphicsInfo m_glInfo; | |
| 550 ScriptState* m_scriptState; | |
| 551 OwnPtr<WebGraphicsContext3DProvider> m_provider; | |
| 552 }; | 543 }; |
| 553 | 544 |
| 554 void WebGLRenderingContextBase::createContextProviderOnMainThread(ContextProvide rCreationInfo* creationInfo, WaitableEvent* waitableEvent) | 545 static void createContextProviderOnMainThread(ContextProviderCreationInfo* creat ionInfo, WaitableEvent* waitableEvent) |
| 555 { | 546 { |
| 556 ASSERT(isMainThread()); | 547 ASSERT(isMainThread()); |
| 557 Platform::GraphicsInfo glInfo = creationInfo->glInfo(); | 548 creationInfo->createdContextProvider = adoptPtr(Platform::current()->createO ffscreenGraphicsContext3DProvider( |
| 558 OwnPtr<WebGraphicsContext3DProvider> provider = adoptPtr(Platform::current() ->createOffscreenGraphicsContext3DProvider( | 549 creationInfo->contextAttributes, creationInfo->scriptState->getExecution Context()->url(), 0, creationInfo->glInfo)); |
| 559 creationInfo->contextAttributes(), creationInfo->scriptState()->getExecu tionContext()->url(), 0, &glInfo, Platform::DoNotBindToCurrentThread)); | |
| 560 creationInfo->setContextProvider(std::move(provider)); | |
| 561 waitableEvent->signal(); | 550 waitableEvent->signal(); |
| 562 } | 551 } |
| 563 | 552 |
| 564 PassOwnPtr<WebGraphicsContext3DProvider> WebGLRenderingContextBase::createContex tProviderOnWorkerThread(Platform::ContextAttributes contextAttributes, Platform: :GraphicsInfo glInfo, ScriptState* scriptState) | 553 static PassOwnPtr<WebGraphicsContext3DProvider> createContextProviderOnWorkerThr ead(Platform::ContextAttributes contextAttributes, Platform::GraphicsInfo* glInf o, ScriptState* scriptState) |
| 565 { | 554 { |
| 566 WaitableEvent waitableEvent; | 555 WaitableEvent waitableEvent; |
| 567 OwnPtr<ContextProviderCreationInfo> creationInfo = adoptPtr(new ContextProvi derCreationInfo(contextAttributes, glInfo, scriptState)); | 556 ContextProviderCreationInfo creationInfo; |
| 557 creationInfo.contextAttributes = contextAttributes; | |
| 558 creationInfo.glInfo = glInfo; | |
| 559 creationInfo.scriptState = scriptState; | |
| 568 WebTaskRunner* taskRunner = Platform::current()->mainThread()->getWebTaskRun ner(); | 560 WebTaskRunner* taskRunner = Platform::current()->mainThread()->getWebTaskRun ner(); |
| 569 taskRunner->postTask(BLINK_FROM_HERE, threadSafeBind(&createContextProviderO nMainThread, AllowCrossThreadAccess(creationInfo.get()), AllowCrossThreadAccess( &waitableEvent))); | 561 taskRunner->postTask(BLINK_FROM_HERE, threadSafeBind(&createContextProviderO nMainThread, AllowCrossThreadAccess(&creationInfo), AllowCrossThreadAccess(&wait ableEvent))); |
| 570 waitableEvent.wait(); | 562 waitableEvent.wait(); |
| 571 return creationInfo->releaseContextProvider(); | 563 return std::move(creationInfo.createdContextProvider); |
| 572 } | 564 } |
| 573 | 565 |
| 574 PassOwnPtr<WebGraphicsContext3DProvider> WebGLRenderingContextBase::createContex tProviderInternal(HTMLCanvasElement* canvas, ScriptState* scriptState, WebGLCont extAttributes attributes, unsigned webGLVersion) | 566 PassOwnPtr<WebGraphicsContext3DProvider> WebGLRenderingContextBase::createContex tProviderInternal(HTMLCanvasElement* canvas, ScriptState* scriptState, WebGLCont extAttributes attributes, unsigned webGLVersion) |
| 575 { | 567 { |
| 568 // Exactly one of these must be provided. | |
| 569 DCHECK_EQ(!canvas, !!scriptState); | |
| 570 // The canvas is only given on the main thread. | |
| 571 DCHECK(!canvas || isMainThread()); | |
| 572 | |
| 576 Platform::ContextAttributes contextAttributes = toPlatformContextAttributes( attributes, webGLVersion); | 573 Platform::ContextAttributes contextAttributes = toPlatformContextAttributes( attributes, webGLVersion); |
| 577 Platform::GraphicsInfo glInfo; | 574 Platform::GraphicsInfo glInfo; |
| 578 OwnPtr<WebGraphicsContext3DProvider> contextProvider; | 575 OwnPtr<WebGraphicsContext3DProvider> contextProvider; |
| 579 if (canvas) { | 576 if (isMainThread()) { |
| 577 const auto& url = canvas ? canvas->document().topDocument().url() : scri ptState->getExecutionContext()->url(); | |
| 580 contextProvider = adoptPtr(Platform::current()->createOffscreenGraphicsC ontext3DProvider( | 578 contextProvider = adoptPtr(Platform::current()->createOffscreenGraphicsC ontext3DProvider( |
| 581 contextAttributes, canvas->document().topDocument().url(), 0, &glInf o, Platform::BindToCurrentThread)); | 579 contextAttributes, url, 0, &glInfo)); |
| 582 } else { | 580 } else { |
| 583 if (isMainThread()) { | 581 contextProvider = createContextProviderOnWorkerThread(contextAttributes, &glInfo, scriptState); |
| 584 contextProvider = adoptPtr(Platform::current()->createOffscreenGraph icsContext3DProvider( | |
| 585 contextAttributes, scriptState->getExecutionContext()->url(), 0, &glInfo, Platform::BindToCurrentThread)); | |
| 586 } else { | |
| 587 contextProvider = createContextProviderOnWorkerThread(contextAttribu tes, glInfo, scriptState); | |
| 588 if (!contextProvider->bindToCurrentThread()) | |
| 589 return nullptr; | |
| 590 } | |
| 591 } | 582 } |
| 592 if (!contextProvider || shouldFailContextCreationForTesting) { | 583 if (!contextProvider->bindToCurrentThread() || shouldFailContextCreationForT esting) { |
|
danakj
2016/05/19 18:44:17
Oh, slight lie here. While making a ContextProvide
| |
| 593 shouldFailContextCreationForTesting = false; | 584 shouldFailContextCreationForTesting = false; |
| 594 if (canvas) | 585 if (canvas) |
| 595 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webg lcontextcreationerror, false, true, extractWebGLContextCreationError(glInfo))); | 586 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webg lcontextcreationerror, false, true, extractWebGLContextCreationError(glInfo))); |
| 596 return nullptr; | 587 return nullptr; |
| 597 } | 588 } |
| 598 gpu::gles2::GLES2Interface* gl = contextProvider->contextGL(); | 589 gpu::gles2::GLES2Interface* gl = contextProvider->contextGL(); |
| 599 if (!String(gl->GetString(GL_EXTENSIONS)).contains("GL_OES_packed_depth_sten cil")) { | 590 if (!String(gl->GetString(GL_EXTENSIONS)).contains("GL_OES_packed_depth_sten cil")) { |
| 600 if (canvas) | 591 if (canvas) |
| 601 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webg lcontextcreationerror, false, true, "OES_packed_depth_stencil support is require d.")); | 592 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webg lcontextcreationerror, false, true, "OES_packed_depth_stencil support is require d.")); |
| 602 return nullptr; | 593 return nullptr; |
| (...skipping 5441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6044 | 6035 |
| 6045 // If the context was lost due to RealLostContext, we need to destroy the ol d DrawingBuffer before creating new DrawingBuffer to ensure resource budget enou gh. | 6036 // If the context was lost due to RealLostContext, we need to destroy the ol d DrawingBuffer before creating new DrawingBuffer to ensure resource budget enou gh. |
| 6046 if (drawingBuffer()) { | 6037 if (drawingBuffer()) { |
| 6047 m_drawingBuffer->beginDestruction(); | 6038 m_drawingBuffer->beginDestruction(); |
| 6048 m_drawingBuffer.clear(); | 6039 m_drawingBuffer.clear(); |
| 6049 } | 6040 } |
| 6050 | 6041 |
| 6051 Platform::ContextAttributes attributes = toPlatformContextAttributes(m_reque stedAttributes, version()); | 6042 Platform::ContextAttributes attributes = toPlatformContextAttributes(m_reque stedAttributes, version()); |
| 6052 Platform::GraphicsInfo glInfo; | 6043 Platform::GraphicsInfo glInfo; |
| 6053 OwnPtr<WebGraphicsContext3DProvider> contextProvider = adoptPtr(Platform::cu rrent()->createOffscreenGraphicsContext3DProvider( | 6044 OwnPtr<WebGraphicsContext3DProvider> contextProvider = adoptPtr(Platform::cu rrent()->createOffscreenGraphicsContext3DProvider( |
| 6054 attributes, canvas()->document().topDocument().url(), 0, &glInfo, Platfo rm::BindToCurrentThread)); | 6045 attributes, canvas()->document().topDocument().url(), 0, &glInfo)); |
| 6055 RefPtr<DrawingBuffer> buffer; | 6046 RefPtr<DrawingBuffer> buffer; |
| 6056 if (contextProvider) { | 6047 if (contextProvider->bindToCurrentThread()) { |
| 6057 // Construct a new drawing buffer with the new GL context. | 6048 // Construct a new drawing buffer with the new GL context. |
| 6058 buffer = createDrawingBuffer(std::move(contextProvider)); | 6049 buffer = createDrawingBuffer(std::move(contextProvider)); |
| 6059 // If DrawingBuffer::create() fails to allocate a fbo, |drawingBuffer| i s set to null. | 6050 // If DrawingBuffer::create() fails to allocate a fbo, |drawingBuffer| i s set to null. |
| 6060 } | 6051 } |
| 6061 if (!buffer) { | 6052 if (!buffer) { |
| 6062 if (m_contextLostMode == RealLostContext) { | 6053 if (m_contextLostMode == RealLostContext) { |
| 6063 m_restoreTimer.startOneShot(secondsBetweenRestoreAttempts, BLINK_FRO M_HERE); | 6054 m_restoreTimer.startOneShot(secondsBetweenRestoreAttempts, BLINK_FRO M_HERE); |
| 6064 } else { | 6055 } else { |
| 6065 // This likely shouldn't happen but is the best way to report it to the WebGL app. | 6056 // This likely shouldn't happen but is the best way to report it to the WebGL app. |
| 6066 synthesizeGLError(GL_INVALID_OPERATION, "", "error restoring context "); | 6057 synthesizeGLError(GL_INVALID_OPERATION, "", "error restoring context "); |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6384 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1); | 6375 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1); |
| 6385 } | 6376 } |
| 6386 | 6377 |
| 6387 void WebGLRenderingContextBase::restoreUnpackParameters() | 6378 void WebGLRenderingContextBase::restoreUnpackParameters() |
| 6388 { | 6379 { |
| 6389 if (m_unpackAlignment != 1) | 6380 if (m_unpackAlignment != 1) |
| 6390 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); | 6381 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); |
| 6391 } | 6382 } |
| 6392 | 6383 |
| 6393 } // namespace blink | 6384 } // namespace blink |
| OLD | NEW |