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 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
540 formatWebGLStatusString("ErrorMessage", info.errorMessage.utf8().data(), | 540 formatWebGLStatusString("ErrorMessage", info.errorMessage.utf8().data(), |
541 builder); | 541 builder); |
542 builder.append('.'); | 542 builder.append('.'); |
543 return builder.toString(); | 543 return builder.toString(); |
544 } | 544 } |
545 | 545 |
546 struct ContextProviderCreationInfo { | 546 struct ContextProviderCreationInfo { |
547 // Inputs. | 547 // Inputs. |
548 Platform::ContextAttributes contextAttributes; | 548 Platform::ContextAttributes contextAttributes; |
549 Platform::GraphicsInfo* glInfo; | 549 Platform::GraphicsInfo* glInfo; |
550 ScriptState* scriptState; | 550 KURL url; |
551 // Outputs. | 551 // Outputs. |
552 std::unique_ptr<WebGraphicsContext3DProvider> createdContextProvider; | 552 std::unique_ptr<WebGraphicsContext3DProvider> createdContextProvider; |
553 }; | 553 }; |
554 | 554 |
555 static void createContextProviderOnMainThread( | 555 static void createContextProviderOnMainThread( |
556 ContextProviderCreationInfo* creationInfo, | 556 ContextProviderCreationInfo* creationInfo, |
557 WaitableEvent* waitableEvent) { | 557 WaitableEvent* waitableEvent) { |
558 ASSERT(isMainThread()); | 558 ASSERT(isMainThread()); |
559 creationInfo->createdContextProvider = | 559 creationInfo->createdContextProvider = |
560 wrapUnique(Platform::current()->createOffscreenGraphicsContext3DProvider( | 560 wrapUnique(Platform::current()->createOffscreenGraphicsContext3DProvider( |
561 creationInfo->contextAttributes, | 561 creationInfo->contextAttributes, creationInfo->url, 0, |
562 creationInfo->scriptState->getExecutionContext()->url(), 0, | |
563 creationInfo->glInfo)); | 562 creationInfo->glInfo)); |
564 waitableEvent->signal(); | 563 waitableEvent->signal(); |
565 } | 564 } |
566 | 565 |
567 static std::unique_ptr<WebGraphicsContext3DProvider> | 566 static std::unique_ptr<WebGraphicsContext3DProvider> |
568 createContextProviderOnWorkerThread( | 567 createContextProviderOnWorkerThread( |
569 Platform::ContextAttributes contextAttributes, | 568 Platform::ContextAttributes contextAttributes, |
570 Platform::GraphicsInfo* glInfo, | 569 Platform::GraphicsInfo* glInfo, |
571 ScriptState* scriptState) { | 570 const KURL& url) { |
572 WaitableEvent waitableEvent; | 571 WaitableEvent waitableEvent; |
573 ContextProviderCreationInfo creationInfo; | 572 ContextProviderCreationInfo creationInfo; |
574 creationInfo.contextAttributes = contextAttributes; | 573 creationInfo.contextAttributes = contextAttributes; |
575 creationInfo.glInfo = glInfo; | 574 creationInfo.glInfo = glInfo; |
576 creationInfo.scriptState = scriptState; | 575 creationInfo.url = url; |
577 WebTaskRunner* taskRunner = | 576 WebTaskRunner* taskRunner = |
578 Platform::current()->mainThread()->getWebTaskRunner(); | 577 Platform::current()->mainThread()->getWebTaskRunner(); |
579 taskRunner->postTask(BLINK_FROM_HERE, | 578 taskRunner->postTask(BLINK_FROM_HERE, |
580 crossThreadBind(&createContextProviderOnMainThread, | 579 crossThreadBind(&createContextProviderOnMainThread, |
581 crossThreadUnretained(&creationInfo), | 580 crossThreadUnretained(&creationInfo), |
582 crossThreadUnretained(&waitableEvent))); | 581 crossThreadUnretained(&waitableEvent))); |
583 waitableEvent.wait(); | 582 waitableEvent.wait(); |
584 return std::move(creationInfo.createdContextProvider); | 583 return std::move(creationInfo.createdContextProvider); |
585 } | 584 } |
586 | 585 |
587 std::unique_ptr<WebGraphicsContext3DProvider> | 586 std::unique_ptr<WebGraphicsContext3DProvider> |
588 WebGLRenderingContextBase::createContextProviderInternal( | 587 WebGLRenderingContextBase::createContextProviderInternal( |
589 HTMLCanvasElement* canvas, | 588 HTMLCanvasElement* canvas, |
590 ScriptState* scriptState, | 589 ScriptState* scriptState, |
591 const CanvasContextCreationAttributes& attributes, | 590 const CanvasContextCreationAttributes& attributes, |
592 unsigned webGLVersion) { | 591 unsigned webGLVersion) { |
593 // Exactly one of these must be provided. | 592 // Exactly one of these must be provided. |
594 DCHECK_EQ(!canvas, !!scriptState); | 593 DCHECK_EQ(!canvas, !!scriptState); |
595 // The canvas is only given on the main thread. | 594 // The canvas is only given on the main thread. |
596 DCHECK(!canvas || isMainThread()); | 595 DCHECK(!canvas || isMainThread()); |
597 | 596 |
598 Platform::ContextAttributes contextAttributes = | 597 Platform::ContextAttributes contextAttributes = |
599 toPlatformContextAttributes(attributes, webGLVersion); | 598 toPlatformContextAttributes(attributes, webGLVersion); |
600 Platform::GraphicsInfo glInfo; | 599 Platform::GraphicsInfo glInfo; |
601 std::unique_ptr<WebGraphicsContext3DProvider> contextProvider; | 600 std::unique_ptr<WebGraphicsContext3DProvider> contextProvider; |
601 const auto& url = canvas ? canvas->document().topDocument().url() | |
602 : scriptState->getExecutionContext()->url(); | |
602 if (isMainThread()) { | 603 if (isMainThread()) { |
603 const auto& url = canvas ? canvas->document().topDocument().url() | |
604 : scriptState->getExecutionContext()->url(); | |
605 contextProvider = wrapUnique( | 604 contextProvider = wrapUnique( |
606 Platform::current()->createOffscreenGraphicsContext3DProvider( | 605 Platform::current()->createOffscreenGraphicsContext3DProvider( |
607 contextAttributes, url, 0, &glInfo)); | 606 contextAttributes, url, 0, &glInfo)); |
608 } else { | 607 } else { |
609 contextProvider = createContextProviderOnWorkerThread(contextAttributes, | 608 contextProvider = |
610 &glInfo, scriptState); | 609 createContextProviderOnWorkerThread(contextAttributes, &glInfo, url); |
611 } | 610 } |
612 if (contextProvider && !contextProvider->bindToCurrentThread()) { | 611 if (contextProvider && !contextProvider->bindToCurrentThread()) { |
613 contextProvider = nullptr; | 612 contextProvider = nullptr; |
614 String errorString(glInfo.errorMessage.utf8().data()); | 613 String errorString(glInfo.errorMessage.utf8().data()); |
615 errorString.insert("bindToCurrentThread failed: ", 0); | 614 errorString.insert("bindToCurrentThread failed: ", 0); |
616 glInfo.errorMessage = errorString; | 615 glInfo.errorMessage = errorString; |
617 } | 616 } |
618 if (!contextProvider || shouldFailContextCreationForTesting) { | 617 if (!contextProvider || shouldFailContextCreationForTesting) { |
619 shouldFailContextCreationForTesting = false; | 618 shouldFailContextCreationForTesting = false; |
620 if (canvas) | 619 if (canvas) |
(...skipping 6669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7290 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, functionName, reason); | 7289 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, functionName, reason); |
7291 return false; | 7290 return false; |
7292 } | 7291 } |
7293 | 7292 |
7294 return true; | 7293 return true; |
7295 } | 7294 } |
7296 | 7295 |
7297 void WebGLRenderingContextBase::dispatchContextLostEvent(TimerBase*) { | 7296 void WebGLRenderingContextBase::dispatchContextLostEvent(TimerBase*) { |
7298 WebGLContextEvent* event = WebGLContextEvent::create( | 7297 WebGLContextEvent* event = WebGLContextEvent::create( |
7299 EventTypeNames::webglcontextlost, false, true, ""); | 7298 EventTypeNames::webglcontextlost, false, true, ""); |
7300 canvas()->dispatchEvent(event); | 7299 if (getOffscreenCanvas()) |
7300 getOffscreenCanvas()->dispatchEvent(event); | |
7301 else | |
7302 canvas()->dispatchEvent(event); | |
7301 m_restoreAllowed = event->defaultPrevented(); | 7303 m_restoreAllowed = event->defaultPrevented(); |
7302 if (m_restoreAllowed && !m_isHidden) { | 7304 if (m_restoreAllowed && !m_isHidden) { |
7303 if (m_autoRecoveryMethod == Auto) | 7305 if (m_autoRecoveryMethod == Auto) |
7304 m_restoreTimer.startOneShot(0, BLINK_FROM_HERE); | 7306 m_restoreTimer.startOneShot(0, BLINK_FROM_HERE); |
7305 } | 7307 } |
7306 } | 7308 } |
7307 | 7309 |
7308 void WebGLRenderingContextBase::maybeRestoreContext(TimerBase*) { | 7310 void WebGLRenderingContextBase::maybeRestoreContext(TimerBase*) { |
7309 ASSERT(isContextLost()); | 7311 ASSERT(isContextLost()); |
7310 | 7312 |
7311 // The rendering context is not restored unless the default behavior of the | 7313 // The rendering context is not restored unless the default behavior of the |
7312 // webglcontextlost event was prevented earlier. | 7314 // webglcontextlost event was prevented earlier. |
7313 // | 7315 // |
7314 // Because of the way m_restoreTimer is set up for real vs. synthetic lost | 7316 // Because of the way m_restoreTimer is set up for real vs. synthetic lost |
7315 // context events, we don't have to worry about this test short-circuiting | 7317 // context events, we don't have to worry about this test short-circuiting |
7316 // the retry loop for real context lost events. | 7318 // the retry loop for real context lost events. |
7317 if (!m_restoreAllowed) | 7319 if (!m_restoreAllowed) |
7318 return; | 7320 return; |
7319 | 7321 |
7320 LocalFrame* frame = canvas()->document().frame(); | 7322 if (canvas()) { |
7321 if (!frame) | 7323 LocalFrame* frame = canvas()->document().frame(); |
7322 return; | 7324 if (!frame) |
7325 return; | |
7323 | 7326 |
7324 Settings* settings = frame->settings(); | 7327 Settings* settings = frame->settings(); |
7325 | 7328 |
7326 if (!frame->loader().client()->allowWebGL(settings && | 7329 if (!frame->loader().client()->allowWebGL(settings && |
7327 settings->webGLEnabled())) | 7330 settings->webGLEnabled())) |
7328 return; | 7331 return; |
7332 } | |
7329 | 7333 |
7330 // If the context was lost due to RealLostContext, we need to destroy the old | 7334 // If the context was lost due to RealLostContext, we need to destroy the old |
7331 // DrawingBuffer before creating new DrawingBuffer to ensure resource budget | 7335 // DrawingBuffer before creating new DrawingBuffer to ensure resource budget |
7332 // enough. | 7336 // enough. |
7333 if (drawingBuffer()) { | 7337 if (drawingBuffer()) { |
7334 m_drawingBuffer->beginDestruction(); | 7338 m_drawingBuffer->beginDestruction(); |
7335 m_drawingBuffer.clear(); | 7339 m_drawingBuffer.clear(); |
7336 } | 7340 } |
7337 | 7341 |
7338 Platform::ContextAttributes attributes = | 7342 Platform::ContextAttributes attributes = |
7339 toPlatformContextAttributes(creationAttributes(), version()); | 7343 toPlatformContextAttributes(creationAttributes(), version()); |
7340 Platform::GraphicsInfo glInfo; | 7344 Platform::GraphicsInfo glInfo; |
7341 std::unique_ptr<WebGraphicsContext3DProvider> contextProvider = | 7345 std::unique_ptr<WebGraphicsContext3DProvider> contextProvider; |
7342 wrapUnique(Platform::current()->createOffscreenGraphicsContext3DProvider( | 7346 const auto& url = canvas() |
7343 attributes, canvas()->document().topDocument().url(), 0, &glInfo)); | 7347 ? canvas()->document().topDocument().url() |
7348 : getOffscreenCanvas()->getExecutionContext()->url(); | |
7349 if (isMainThread()) { | |
7350 contextProvider = wrapUnique( | |
7351 Platform::current()->createOffscreenGraphicsContext3DProvider( | |
7352 attributes, url, 0, &glInfo)); | |
7353 } else { | |
7354 contextProvider = | |
7355 createContextProviderOnWorkerThread(attributes, &glInfo, url); | |
7356 } | |
7344 RefPtr<DrawingBuffer> buffer; | 7357 RefPtr<DrawingBuffer> buffer; |
7345 if (contextProvider && contextProvider->bindToCurrentThread()) { | 7358 if (contextProvider && contextProvider->bindToCurrentThread()) { |
7346 // Construct a new drawing buffer with the new GL context. | 7359 // Construct a new drawing buffer with the new GL context. |
7347 // TODO(xidachen): make sure that the second parameter is correct for | 7360 if (canvas()) { |
7348 // OffscreenCanvas. | 7361 buffer = createDrawingBuffer(std::move(contextProvider), |
7349 buffer = createDrawingBuffer(std::move(contextProvider), | 7362 DrawingBuffer::AllowChromiumImage); |
7350 DrawingBuffer::AllowChromiumImage); | 7363 } else { |
7364 buffer = createDrawingBuffer(std::move(contextProvider), | |
7365 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:
| |
7366 } | |
7351 // If DrawingBuffer::create() fails to allocate a fbo, |drawingBuffer| is | 7367 // If DrawingBuffer::create() fails to allocate a fbo, |drawingBuffer| is |
7352 // set to null. | 7368 // set to null. |
7353 } | 7369 } |
7354 if (!buffer) { | 7370 if (!buffer) { |
7355 if (m_contextLostMode == RealLostContext) { | 7371 if (m_contextLostMode == RealLostContext) { |
7356 m_restoreTimer.startOneShot(secondsBetweenRestoreAttempts, | 7372 m_restoreTimer.startOneShot(secondsBetweenRestoreAttempts, |
7357 BLINK_FROM_HERE); | 7373 BLINK_FROM_HERE); |
7358 } else { | 7374 } else { |
7359 // This likely shouldn't happen but is the best way to report it to the | 7375 // This likely shouldn't happen but is the best way to report it to the |
7360 // WebGL app. | 7376 // WebGL app. |
(...skipping 10 matching lines...) Expand all Loading... | |
7371 drawingBuffer()->bind(GL_FRAMEBUFFER); | 7387 drawingBuffer()->bind(GL_FRAMEBUFFER); |
7372 m_lostContextErrors.clear(); | 7388 m_lostContextErrors.clear(); |
7373 m_contextLostMode = NotLostContext; | 7389 m_contextLostMode = NotLostContext; |
7374 m_autoRecoveryMethod = Manual; | 7390 m_autoRecoveryMethod = Manual; |
7375 m_restoreAllowed = false; | 7391 m_restoreAllowed = false; |
7376 removeFromEvictedList(this); | 7392 removeFromEvictedList(this); |
7377 | 7393 |
7378 setupFlags(); | 7394 setupFlags(); |
7379 initializeNewContext(); | 7395 initializeNewContext(); |
7380 markContextChanged(CanvasContextChanged); | 7396 markContextChanged(CanvasContextChanged); |
7381 canvas()->dispatchEvent(WebGLContextEvent::create( | 7397 WebGLContextEvent* event = WebGLContextEvent::create( |
7382 EventTypeNames::webglcontextrestored, false, true, "")); | 7398 EventTypeNames::webglcontextrestored, false, true, ""); |
7399 if (canvas()) | |
7400 canvas()->dispatchEvent(event); | |
7401 else | |
7402 getOffscreenCanvas()->dispatchEvent(event); | |
7383 } | 7403 } |
7384 | 7404 |
7385 String WebGLRenderingContextBase::ensureNotNull(const String& text) const { | 7405 String WebGLRenderingContextBase::ensureNotNull(const String& text) const { |
7386 if (text.isNull()) | 7406 if (text.isNull()) |
7387 return WTF::emptyString(); | 7407 return WTF::emptyString(); |
7388 return text; | 7408 return text; |
7389 } | 7409 } |
7390 | 7410 |
7391 WebGLRenderingContextBase::LRUImageBufferCache::LRUImageBufferCache( | 7411 WebGLRenderingContextBase::LRUImageBufferCache::LRUImageBufferCache( |
7392 int capacity) | 7412 int capacity) |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7668 | 7688 |
7669 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas( | 7689 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas( |
7670 HTMLCanvasElementOrOffscreenCanvas& result) const { | 7690 HTMLCanvasElementOrOffscreenCanvas& result) const { |
7671 if (canvas()) | 7691 if (canvas()) |
7672 result.setHTMLCanvasElement(canvas()); | 7692 result.setHTMLCanvasElement(canvas()); |
7673 else | 7693 else |
7674 result.setOffscreenCanvas(getOffscreenCanvas()); | 7694 result.setOffscreenCanvas(getOffscreenCanvas()); |
7675 } | 7695 } |
7676 | 7696 |
7677 } // namespace blink | 7697 } // namespace blink |
OLD | NEW |