| 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 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 ImageBitmap* WebGLRenderingContextBase::transferToImageBitmapBase( | 707 ImageBitmap* WebGLRenderingContextBase::transferToImageBitmapBase( |
| 708 ScriptState* scriptState) { | 708 ScriptState* scriptState) { |
| 709 UseCounter::Feature feature = | 709 UseCounter::Feature feature = |
| 710 UseCounter::OffscreenCanvasTransferToImageBitmapWebGL; | 710 UseCounter::OffscreenCanvasTransferToImageBitmapWebGL; |
| 711 UseCounter::count(scriptState->getExecutionContext(), feature); | 711 UseCounter::count(scriptState->getExecutionContext(), feature); |
| 712 if (!drawingBuffer()) | 712 if (!drawingBuffer()) |
| 713 return nullptr; | 713 return nullptr; |
| 714 return ImageBitmap::create(drawingBuffer()->transferToStaticBitmapImage()); | 714 return ImageBitmap::create(drawingBuffer()->transferToStaticBitmapImage()); |
| 715 } | 715 } |
| 716 | 716 |
| 717 void WebGLRenderingContextBase::commit(ScriptState* scriptState, | 717 ScriptPromise WebGLRenderingContextBase::commit( |
| 718 ExceptionState& exceptionState) { | 718 ScriptState* scriptState, |
| 719 ExceptionState& exceptionState) { |
| 719 UseCounter::Feature feature = UseCounter::OffscreenCanvasCommitWebGL; | 720 UseCounter::Feature feature = UseCounter::OffscreenCanvasCommitWebGL; |
| 720 UseCounter::count(scriptState->getExecutionContext(), feature); | 721 UseCounter::count(scriptState->getExecutionContext(), feature); |
| 721 if (!getOffscreenCanvas()) { | 722 if (!offscreenCanvas()) { |
| 722 exceptionState.throwDOMException(InvalidStateError, | 723 exceptionState.throwDOMException(InvalidStateError, |
| 723 "Commit() was called on a rendering " | 724 "Commit() was called on a rendering " |
| 724 "context that was not created from an " | 725 "context that was not created from an " |
| 725 "OffscreenCanvas."); | 726 "OffscreenCanvas."); |
| 726 return; | 727 return exceptionState.reject(scriptState); |
| 727 } | 728 } |
| 728 // no HTMLCanvas associated, thrown InvalidStateError | 729 // no HTMLCanvas associated, thrown InvalidStateError |
| 729 if (!getOffscreenCanvas()->hasPlaceholderCanvas()) { | 730 if (!offscreenCanvas()->hasPlaceholderCanvas()) { |
| 730 exceptionState.throwDOMException(InvalidStateError, | 731 exceptionState.throwDOMException(InvalidStateError, |
| 731 "Commit() was called on a context whose " | 732 "Commit() was called on a context whose " |
| 732 "OffscreenCanvas is not associated with a " | 733 "OffscreenCanvas is not associated with a " |
| 733 "canvas element."); | 734 "canvas element."); |
| 734 return; | 735 return exceptionState.reject(scriptState); |
| 735 } | 736 } |
| 736 if (!drawingBuffer()) | 737 if (!drawingBuffer()) { |
| 737 return; | 738 return offscreenCanvas()->commit(nullptr, false, scriptState); |
| 738 double commitStartTime = WTF::monotonicallyIncreasingTime(); | 739 } |
| 739 // TODO(crbug.com/646864): Make commit() work correctly with | 740 // TODO(crbug.com/646864): Make commit() work correctly with |
| 740 // { preserveDrawingBuffer : true }. | 741 // { preserveDrawingBuffer : true }. |
| 741 getOffscreenCanvas()->getOrCreateFrameDispatcher()->dispatchFrame( | 742 return offscreenCanvas()->commit( |
| 742 std::move(drawingBuffer()->transferToStaticBitmapImage()), | 743 std::move(drawingBuffer()->transferToStaticBitmapImage()), |
| 743 commitStartTime, | 744 drawingBuffer()->contextProvider()->isSoftwareRendering(), scriptState); |
| 744 drawingBuffer()->contextProvider()->isSoftwareRendering()); | |
| 745 } | 745 } |
| 746 | 746 |
| 747 PassRefPtr<Image> WebGLRenderingContextBase::getImage( | 747 PassRefPtr<Image> WebGLRenderingContextBase::getImage( |
| 748 AccelerationHint hint, | 748 AccelerationHint hint, |
| 749 SnapshotReason reason) const { | 749 SnapshotReason reason) const { |
| 750 if (!drawingBuffer()) | 750 if (!drawingBuffer()) |
| 751 return nullptr; | 751 return nullptr; |
| 752 | 752 |
| 753 drawingBuffer()->resolveAndBindForReadAndDraw(); | 753 drawingBuffer()->resolveAndBindForReadAndDraw(); |
| 754 IntSize size = clampedCanvasSize(); | 754 IntSize size = clampedCanvasSize(); |
| (...skipping 6644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7399 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, functionName, reason); | 7399 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, functionName, reason); |
| 7400 return false; | 7400 return false; |
| 7401 } | 7401 } |
| 7402 | 7402 |
| 7403 return true; | 7403 return true; |
| 7404 } | 7404 } |
| 7405 | 7405 |
| 7406 void WebGLRenderingContextBase::dispatchContextLostEvent(TimerBase*) { | 7406 void WebGLRenderingContextBase::dispatchContextLostEvent(TimerBase*) { |
| 7407 WebGLContextEvent* event = WebGLContextEvent::create( | 7407 WebGLContextEvent* event = WebGLContextEvent::create( |
| 7408 EventTypeNames::webglcontextlost, false, true, ""); | 7408 EventTypeNames::webglcontextlost, false, true, ""); |
| 7409 if (getOffscreenCanvas()) | 7409 if (offscreenCanvas()) |
| 7410 getOffscreenCanvas()->dispatchEvent(event); | 7410 offscreenCanvas()->dispatchEvent(event); |
| 7411 else | 7411 else |
| 7412 canvas()->dispatchEvent(event); | 7412 canvas()->dispatchEvent(event); |
| 7413 m_restoreAllowed = event->defaultPrevented(); | 7413 m_restoreAllowed = event->defaultPrevented(); |
| 7414 if (m_restoreAllowed && !m_isHidden) { | 7414 if (m_restoreAllowed && !m_isHidden) { |
| 7415 if (m_autoRecoveryMethod == Auto) | 7415 if (m_autoRecoveryMethod == Auto) |
| 7416 m_restoreTimer.startOneShot(0, BLINK_FROM_HERE); | 7416 m_restoreTimer.startOneShot(0, BLINK_FROM_HERE); |
| 7417 } | 7417 } |
| 7418 } | 7418 } |
| 7419 | 7419 |
| 7420 void WebGLRenderingContextBase::maybeRestoreContext(TimerBase*) { | 7420 void WebGLRenderingContextBase::maybeRestoreContext(TimerBase*) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 7446 // enough. | 7446 // enough. |
| 7447 if (drawingBuffer()) { | 7447 if (drawingBuffer()) { |
| 7448 m_drawingBuffer->beginDestruction(); | 7448 m_drawingBuffer->beginDestruction(); |
| 7449 m_drawingBuffer.clear(); | 7449 m_drawingBuffer.clear(); |
| 7450 } | 7450 } |
| 7451 | 7451 |
| 7452 Platform::ContextAttributes attributes = | 7452 Platform::ContextAttributes attributes = |
| 7453 toPlatformContextAttributes(creationAttributes(), version()); | 7453 toPlatformContextAttributes(creationAttributes(), version()); |
| 7454 Platform::GraphicsInfo glInfo; | 7454 Platform::GraphicsInfo glInfo; |
| 7455 std::unique_ptr<WebGraphicsContext3DProvider> contextProvider; | 7455 std::unique_ptr<WebGraphicsContext3DProvider> contextProvider; |
| 7456 const auto& url = canvas() | 7456 const auto& url = canvas() ? canvas()->document().topDocument().url() |
| 7457 ? canvas()->document().topDocument().url() | 7457 : offscreenCanvas()->getExecutionContext()->url(); |
| 7458 : getOffscreenCanvas()->getExecutionContext()->url(); | |
| 7459 if (isMainThread()) { | 7458 if (isMainThread()) { |
| 7460 contextProvider = WTF::wrapUnique( | 7459 contextProvider = WTF::wrapUnique( |
| 7461 Platform::current()->createOffscreenGraphicsContext3DProvider( | 7460 Platform::current()->createOffscreenGraphicsContext3DProvider( |
| 7462 attributes, url, 0, &glInfo)); | 7461 attributes, url, 0, &glInfo)); |
| 7463 } else { | 7462 } else { |
| 7464 contextProvider = | 7463 contextProvider = |
| 7465 createContextProviderOnWorkerThread(attributes, &glInfo, url); | 7464 createContextProviderOnWorkerThread(attributes, &glInfo, url); |
| 7466 } | 7465 } |
| 7467 RefPtr<DrawingBuffer> buffer; | 7466 RefPtr<DrawingBuffer> buffer; |
| 7468 if (contextProvider && contextProvider->bindToCurrentThread()) { | 7467 if (contextProvider && contextProvider->bindToCurrentThread()) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7503 removeFromEvictedList(this); | 7502 removeFromEvictedList(this); |
| 7504 | 7503 |
| 7505 setupFlags(); | 7504 setupFlags(); |
| 7506 initializeNewContext(); | 7505 initializeNewContext(); |
| 7507 markContextChanged(CanvasContextChanged); | 7506 markContextChanged(CanvasContextChanged); |
| 7508 WebGLContextEvent* event = WebGLContextEvent::create( | 7507 WebGLContextEvent* event = WebGLContextEvent::create( |
| 7509 EventTypeNames::webglcontextrestored, false, true, ""); | 7508 EventTypeNames::webglcontextrestored, false, true, ""); |
| 7510 if (canvas()) | 7509 if (canvas()) |
| 7511 canvas()->dispatchEvent(event); | 7510 canvas()->dispatchEvent(event); |
| 7512 else | 7511 else |
| 7513 getOffscreenCanvas()->dispatchEvent(event); | 7512 offscreenCanvas()->dispatchEvent(event); |
| 7514 } | 7513 } |
| 7515 | 7514 |
| 7516 String WebGLRenderingContextBase::ensureNotNull(const String& text) const { | 7515 String WebGLRenderingContextBase::ensureNotNull(const String& text) const { |
| 7517 if (text.isNull()) | 7516 if (text.isNull()) |
| 7518 return WTF::emptyString(); | 7517 return WTF::emptyString(); |
| 7519 return text; | 7518 return text; |
| 7520 } | 7519 } |
| 7521 | 7520 |
| 7522 WebGLRenderingContextBase::LRUImageBufferCache::LRUImageBufferCache( | 7521 WebGLRenderingContextBase::LRUImageBufferCache::LRUImageBufferCache( |
| 7523 int capacity) | 7522 int capacity) |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7629 else | 7628 else |
| 7630 contextGL()->Disable(capability); | 7629 contextGL()->Disable(capability); |
| 7631 } | 7630 } |
| 7632 | 7631 |
| 7633 IntSize WebGLRenderingContextBase::clampedCanvasSize() const { | 7632 IntSize WebGLRenderingContextBase::clampedCanvasSize() const { |
| 7634 int width, height; | 7633 int width, height; |
| 7635 if (canvas()) { | 7634 if (canvas()) { |
| 7636 width = canvas()->width(); | 7635 width = canvas()->width(); |
| 7637 height = canvas()->height(); | 7636 height = canvas()->height(); |
| 7638 } else { | 7637 } else { |
| 7639 width = getOffscreenCanvas()->width(); | 7638 width = offscreenCanvas()->width(); |
| 7640 height = getOffscreenCanvas()->height(); | 7639 height = offscreenCanvas()->height(); |
| 7641 } | 7640 } |
| 7642 return IntSize(clamp(width, 1, m_maxViewportDims[0]), | 7641 return IntSize(clamp(width, 1, m_maxViewportDims[0]), |
| 7643 clamp(height, 1, m_maxViewportDims[1])); | 7642 clamp(height, 1, m_maxViewportDims[1])); |
| 7644 } | 7643 } |
| 7645 | 7644 |
| 7646 GLint WebGLRenderingContextBase::maxDrawBuffers() { | 7645 GLint WebGLRenderingContextBase::maxDrawBuffers() { |
| 7647 if (isContextLost() || | 7646 if (isContextLost() || |
| 7648 !(extensionEnabled(WebGLDrawBuffersName) || isWebGL2OrHigher())) | 7647 !(extensionEnabled(WebGLDrawBuffersName) || isWebGL2OrHigher())) |
| 7649 return 0; | 7648 return 0; |
| 7650 if (!m_maxDrawBuffers) | 7649 if (!m_maxDrawBuffers) |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7792 void WebGLRenderingContextBase::restoreUnpackParameters() { | 7791 void WebGLRenderingContextBase::restoreUnpackParameters() { |
| 7793 if (m_unpackAlignment != 1) | 7792 if (m_unpackAlignment != 1) |
| 7794 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); | 7793 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); |
| 7795 } | 7794 } |
| 7796 | 7795 |
| 7797 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas( | 7796 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas( |
| 7798 HTMLCanvasElementOrOffscreenCanvas& result) const { | 7797 HTMLCanvasElementOrOffscreenCanvas& result) const { |
| 7799 if (canvas()) | 7798 if (canvas()) |
| 7800 result.setHTMLCanvasElement(canvas()); | 7799 result.setHTMLCanvasElement(canvas()); |
| 7801 else | 7800 else |
| 7802 result.setOffscreenCanvas(getOffscreenCanvas()); | 7801 result.setOffscreenCanvas(offscreenCanvas()); |
| 7803 } | 7802 } |
| 7804 | 7803 |
| 7805 } // namespace blink | 7804 } // namespace blink |
| OLD | NEW |