6

Changeset 265543 – WebKit

 3 years ago
source link: https://trac.webkit.org/changeset/265543/webkit
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Changeset 265543 in webkit

View differences
Show lines around each change
Show the changes in full context
Ignore:
Blank lines
Case changes
White space changes
Timestamp: Aug 12, 2020 2:05:54 AM (4 months ago) Author: Chris Lord Message:

Implement Canvas.transferControlToOffscreen and OffscreenCanvasRenderingContext2D.commit
​https://bugs.webkit.org/show_bug.cgi?id=202797

Reviewed by Dean Jackson.

LayoutTests/imported/w3c:

  • web-platform-tests/html/canvas/offscreen/filter/offscreencanvas.filter.w-expected.txt:
  • web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.commit-expected.txt:
  • web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.commit.w-expected.txt:
  • web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.getcontext-expected.txt:
  • web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.getcontext.worker-expected.txt:
  • web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.resize-expected.txt:
  • web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.transfercontrol.to.offscreen-expected.txt:
  • web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.transfercontrol.to.offscreen.w-expected.txt:

Source/WebCore:

Implement HTMLCanvasElement.transferControlToOffscreen and
OffscreenCanvasRenderingContext2D.commit. This allows for
(synchronous) display of asynchronously rendered OffscreenCanvas
content.

No new tests. Covered by existing tests.

  • html/HTMLCanvasElement.cpp:

(WebCore::HTMLCanvasElement::setHeight):
(WebCore::HTMLCanvasElement::setWidth):
(WebCore::HTMLCanvasElement::reset):
(WebCore::HTMLCanvasElement::transferControlToOffscreen):
(WebCore::HTMLCanvasElement::setImageBufferAndMarkDirty):
(WebCore::HTMLCanvasElement::isControlledByOffscreen const):

  • html/HTMLCanvasElement.h:
  • html/HTMLCanvasElement.idl:
  • html/OffscreenCanvas.cpp:

(WebCore::DetachedOffscreenCanvas::takePlaceholderCanvas):
(WebCore::OffscreenCanvas::create):
(WebCore::OffscreenCanvas::getContext):
(WebCore::OffscreenCanvas::didDraw):
(WebCore::OffscreenCanvas::detach):
(WebCore::OffscreenCanvas::setPlaceholderCanvas):
(WebCore::OffscreenCanvas::pushBufferToPlaceholder):
(WebCore::OffscreenCanvas::commitToPlaceholderCanvas):
(WebCore::OffscreenCanvas::scheduleCommitToPlaceholderCanvas):
(WebCore::OffscreenCanvas::reset):

  • html/OffscreenCanvas.h:
  • html/canvas/OffscreenCanvasRenderingContext2D.cpp:

(WebCore::OffscreenCanvasRenderingContext2D::commit):

  • html/canvas/OffscreenCanvasRenderingContext2D.h:
  • html/canvas/OffscreenCanvasRenderingContext2D.idl:
  • html/canvas/PlaceholderRenderingContext.cpp:

(WebCore::PlaceholderRenderingContext::canvas const):

  • html/canvas/PlaceholderRenderingContext.h:

LayoutTests:

  • platform/glib/imported/w3c/web-platform-tests/html/canvas/offscreen/manual/filter/offscreencanvas.filter.w-expected.txt: Removed.
Location: trunk Files:
1 deleted 21 edited
  • TabularUnified trunk/LayoutTests/ChangeLog

    r265541 r265543   12020-08-12  Chris Lord  <[email protected]> 2 3        Implement Canvas.transferControlToOffscreen and OffscreenCanvasRenderingContext2D.commit 4        https://bugs.webkit.org/show_bug.cgi?id=202797 5 6        Reviewed by Dean Jackson. 7 8        * platform/glib/imported/w3c/web-platform-tests/html/canvas/offscreen/manual/filter/offscreencanvas.filter.w-expected.txt: Removed. 9 1102020-08-11  Lauro Moura  <[email protected]> 211
  • TabularUnified trunk/LayoutTests/imported/w3c/ChangeLog

    r265536 r265543   12020-08-12  Chris Lord  <[email protected]> 2 3        Implement Canvas.transferControlToOffscreen and OffscreenCanvasRenderingContext2D.commit 4        https://bugs.webkit.org/show_bug.cgi?id=202797 5 6        Reviewed by Dean Jackson. 7 8        * web-platform-tests/html/canvas/offscreen/filter/offscreencanvas.filter.w-expected.txt: 9        * web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.commit-expected.txt: 10        * web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.commit.w-expected.txt: 11        * web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.getcontext-expected.txt: 12        * web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.getcontext.worker-expected.txt: 13        * web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.resize-expected.txt: 14        * web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.transfercontrol.to.offscreen-expected.txt: 15        * web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.transfercontrol.to.offscreen.w-expected.txt: 16 1172020-08-11  Chris Dumez  <[email protected]> 218
  • TabularUnified trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/filter/offscreencanvas.filter.w-expected.txt

    r262615 r265543   1FAIL: Timed out waiting for notifyDone to be called 12 2PASS offscreencanvas 3
  • TabularUnified trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.commit-expected.txt

    r265436 r265543   11 2FAIL Test that calling OffscreenCanvas's commit pushes its contents to its placeholder. placeholder.transferControlToOffscreen is not a function. (In 'placeholder.transferControlToOffscreen()', 'placeholder.transferControlToOffscreen' is undefined) 3FAIL Test that calling commit on an OffscreenCanvas that is not transferred from a HTMLCanvasElement is a noop. ctx.commit is not a function. (In 'ctx.commit()', 'ctx.commit' is undefined) 2PASS Test that calling OffscreenCanvas's commit pushes its contents to its placeholder. 3PASS Test that calling commit on an OffscreenCanvas that is not transferred from a HTMLCanvasElement is a noop. 44
  • TabularUnified trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.commit.w-expected.txt

    r265436 r265543   11 2FAIL Test that calling OffscreenCanvas's commit pushes its contents to its placeholder. placeholder.transferControlToOffscreen is not a function. (In 'placeholder.transferControlToOffscreen()', 'placeholder.transferControlToOffscreen' is undefined) 2PASS Test that calling OffscreenCanvas's commit pushes its contents to its placeholder. 33PASS Test that calling commit on an OffscreenCanvas that is not transferred from a HTMLCanvasElement throws an exception in a worker. 44
  • TabularUnified trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.getcontext-expected.txt

    r265436 r265543   22PASS Test that getContext with un-supported string throws a TypeError. 33FAIL Test that getContext with supported string returns correct results Argument 1 ('contextType') to OffscreenCanvas.getContext must be one of: "2d", "webgl" 4FAIL Test that getContext twice with different context type returns null the second time The object is in an invalid state. 4PASS Test that getContext twice with different context type returns null the second time 55PASS Test that 2dcontext.canvas should return the original OffscreenCanvas 66PASS Test that webglcontext.canvas should return the original OffscreenCanvas
  • TabularUnified trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.getcontext.worker-expected.txt

    r265436 r265543   11 22PASS Test that getContext with un-supported string throws a TypeError. 3FAIL Test that getContext with supported string returns correct results Can't find variable: OffscreenCanvasRenderingContext2D 4FAIL Test that getContext twice with different context type returns null the second time The object is in an invalid state. 3FAIL Test that getContext with supported string returns correct results Can't find variable: WebGLRenderingContext 4PASS Test that getContext twice with different context type returns null the second time 55PASS Test that 2dcontext.canvas should return the original OffscreenCanvas 66PASS Test that webglcontext.canvas should return the original OffscreenCanvas
  • TabularUnified trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.resize-expected.txt

    r265436 r265543   33PASS Verify that writing to the width and height attributes of an OffscreenCanvas works when there is a 2d context attached. 44PASS Verify that writing to the width and height attributes of an OffscreenCanvas works when there is a webgl context attached. 5FAIL Verify that writing to the width or height attribute of a placeholder canvas throws an exception placeholder.transferControlToOffscreen is not a function. (In 'placeholder.transferControlToOffscreen()', 'placeholder.transferControlToOffscreen' is undefined) 6FAIL Verify that writing to the width or height attribute of a placeholder canvas throws an exception even when not changing the value of the attribute. placeholder.transferControlToOffscreen is not a function. (In 'placeholder.transferControlToOffscreen()', 'placeholder.transferControlToOffscreen' is undefined) 5PASS Verify that writing to the width or height attribute of a placeholder canvas throws an exception 6PASS Verify that writing to the width or height attribute of a placeholder canvas throws an exception even when not changing the value of the attribute. 77PASS Verify that resizing a 2d context resets its state. 88PASS Verify that setting the size of a 2d context to the same size it already had resets its state. 9FAIL Verify that resizing an OffscreenCanvas with a 2d context propagates the new size to its placeholder canvas asynchronously. placeholder.transferControlToOffscreen is not a function. (In 'placeholder.transferControlToOffscreen()', 'placeholder.transferControlToOffscreen' is undefined) 10FAIL Verify that resizing an OffscreenCanvas with a webgl context propagates the new size to its placeholder canvas asynchronously. placeholder.transferControlToOffscreen is not a function. (In 'placeholder.transferControlToOffscreen()', 'placeholder.transferControlToOffscreen' is undefined) 11FAIL Verify that drawImage uses the size of the frame as the intinsic size of a placeholder canvas. placeholder.transferControlToOffscreen is not a function. (In 'placeholder.transferControlToOffscreen()', 'placeholder.transferControlToOffscreen' is undefined) 9PASS Verify that resizing an OffscreenCanvas with a 2d context propagates the new size to its placeholder canvas asynchronously. 10PASS Verify that resizing an OffscreenCanvas with a webgl context propagates the new size to its placeholder canvas asynchronously. 11PASS Verify that drawImage uses the size of the frame as the intinsic size of a placeholder canvas. 1212
  • TabularUnified trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.transfercontrol.to.offscreen-expected.txt

    r265436 r265543   11 2FAIL Test that an OffscreenCanvas generated by transferControlToOffscreen gets correct width and height placeholder.transferControlToOffscreen is not a function. (In 'placeholder.transferControlToOffscreen()', 'placeholder.transferControlToOffscreen' is undefined) 3FAIL Test that calling getContext on a placeholder canvas that has already transferred its control throws an exception placeholder.transferControlToOffscreen is not a function. (In 'placeholder.transferControlToOffscreen()', 'placeholder.transferControlToOffscreen' is undefined) 4FAIL Test that calling transferControlToOffscreen twice throws an exception placeholder.transferControlToOffscreen is not a function. (In 'placeholder.transferControlToOffscreen()', 'placeholder.transferControlToOffscreen' is undefined) 2PASS Test that an OffscreenCanvas generated by transferControlToOffscreen gets correct width and height 3PASS Test that calling getContext on a placeholder canvas that has already transferred its control throws an exception 4PASS Test that calling transferControlToOffscreen twice throws an exception 55
  • TabularUnified trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.transfercontrol.to.offscreen.w-expected.txt

    r265436 r265543   11 2FAIL Test that an OffscreenCanvas generated by transferControlToOffscreen gets correct width and height when it is transferred to a worker placeholder.transferControlToOffscreen is not a function. (In 'placeholder.transferControlToOffscreen()', 'placeholder.transferControlToOffscreen' is undefined) 3FAIL Test that calling getContext on a placeholder canvas that is transferred its control to an OffscreenCanvas throws an exception, when the OffscreenCanvas is transferred to a worker placeholder.transferControlToOffscreen is not a function. (In 'placeholder.transferControlToOffscreen()', 'placeholder.transferControlToOffscreen' is undefined) 4FAIL Test that calling transferControlToOffscreen twice throws an exception, when its associated OffscreenCanvas is transferred to a worker placeholder.transferControlToOffscreen is not a function. (In 'placeholder.transferControlToOffscreen()', 'placeholder.transferControlToOffscreen' is undefined) 2PASS Test that an OffscreenCanvas generated by transferControlToOffscreen gets correct width and height when it is transferred to a worker 3PASS Test that calling getContext on a placeholder canvas that is transferred its control to an OffscreenCanvas throws an exception, when the OffscreenCanvas is transferred to a worker 4PASS Test that calling transferControlToOffscreen twice throws an exception, when its associated OffscreenCanvas is transferred to a worker 55
  • TabularUnified trunk/Source/WebCore/ChangeLog

    r265542 r265543   12020-08-12  Chris Lord  <[email protected]> 2 3        Implement Canvas.transferControlToOffscreen and OffscreenCanvasRenderingContext2D.commit 4        https://bugs.webkit.org/show_bug.cgi?id=202797 5 6        Reviewed by Dean Jackson. 7 8        Implement HTMLCanvasElement.transferControlToOffscreen and 9        OffscreenCanvasRenderingContext2D.commit. This allows for 10        (synchronous) display of asynchronously rendered OffscreenCanvas 11        content. 12 13        No new tests. Covered by existing tests. 14 15        * html/HTMLCanvasElement.cpp: 16        (WebCore::HTMLCanvasElement::setHeight): 17        (WebCore::HTMLCanvasElement::setWidth): 18        (WebCore::HTMLCanvasElement::reset): 19        (WebCore::HTMLCanvasElement::transferControlToOffscreen): 20        (WebCore::HTMLCanvasElement::setImageBufferAndMarkDirty): 21        (WebCore::HTMLCanvasElement::isControlledByOffscreen const): 22        * html/HTMLCanvasElement.h: 23        * html/HTMLCanvasElement.idl: 24        * html/OffscreenCanvas.cpp: 25        (WebCore::DetachedOffscreenCanvas::takePlaceholderCanvas): 26        (WebCore::OffscreenCanvas::create): 27        (WebCore::OffscreenCanvas::getContext): 28        (WebCore::OffscreenCanvas::didDraw): 29        (WebCore::OffscreenCanvas::detach): 30        (WebCore::OffscreenCanvas::setPlaceholderCanvas): 31        (WebCore::OffscreenCanvas::pushBufferToPlaceholder): 32        (WebCore::OffscreenCanvas::commitToPlaceholderCanvas): 33        (WebCore::OffscreenCanvas::scheduleCommitToPlaceholderCanvas): 34        (WebCore::OffscreenCanvas::reset): 35        * html/OffscreenCanvas.h: 36        * html/canvas/OffscreenCanvasRenderingContext2D.cpp: 37        (WebCore::OffscreenCanvasRenderingContext2D::commit): 38        * html/canvas/OffscreenCanvasRenderingContext2D.h: 39        * html/canvas/OffscreenCanvasRenderingContext2D.idl: 40        * html/canvas/PlaceholderRenderingContext.cpp: 41        (WebCore::PlaceholderRenderingContext::canvas const): 42        * html/canvas/PlaceholderRenderingContext.h: 43 1442020-08-12  Carlos Garcia Campos  <[email protected]> 245
  • TabularUnified trunk/Source/WebCore/html/HTMLCanvasElement.cpp

    r265116 r265543   5050#include "JSDOMConvertDictionary.h" 5151#include "MIMETypeRegistry.h" 52#include "PlaceholderRenderingContext.h" 5253#include "RenderElement.h" 5354#include "RenderHTMLCanvas.h"   185186ExceptionOr<void> HTMLCanvasElement::setHeight(unsigned value) 186187{ 187    if (m_context && m_context->isPlaceholder()) 188    if (isControlledByOffscreen()) 188189        return Exception { InvalidStateError }; 189190    setAttributeWithoutSynchronization(heightAttr, AtomString::number(limitToOnlyHTMLNonNegative(value, defaultHeight)));   193194ExceptionOr<void> HTMLCanvasElement::setWidth(unsigned value) 194195{ 195    if (m_context && m_context->isPlaceholder()) 196    if (isControlledByOffscreen()) 196197        return Exception { InvalidStateError }; 197198    setAttributeWithoutSynchronization(widthAttr, AtomString::number(limitToOnlyHTMLNonNegative(value, defaultWidth)));   567568void HTMLCanvasElement::reset() 568569{ 569    if (m_ignoreReset) 570    if (m_ignoreReset || isControlledByOffscreen()) 570571        return; 571572   769770} 770771 772#if ENABLE(OFFSCREEN_CANVAS) 773ExceptionOr<Ref<OffscreenCanvas>> HTMLCanvasElement::transferControlToOffscreen(ScriptExecutionContext& context) 774{ 775    if (m_context) 776        return Exception { InvalidStateError }; 777 778    m_context = makeUnique<PlaceholderRenderingContext>(*this); 779    return OffscreenCanvas::create(context, *this); 780} 781#endif 782 771783RefPtr<ImageData> HTMLCanvasElement::getImageData() 772784{   946958void HTMLCanvasElement::setImageBufferAndMarkDirty(std::unique_ptr<ImageBuffer>&& buffer) 947959{ 960    IntSize oldSize = size(); 948961    m_hasCreatedImageBuffer = true; 949962    setImageBuffer(WTFMove(buffer)); 963 964    if (isControlledByOffscreen() && oldSize != size()) { 965        setAttributeWithoutSynchronization(widthAttr, AtomString::number(width())); 966        setAttributeWithoutSynchronization(heightAttr, AtomString::number(height())); 967 968        auto renderer = this->renderer(); 969        if (is<RenderHTMLCanvas>(renderer)) { 970            auto& canvasRenderer = downcast<RenderHTMLCanvas>(*renderer); 971            canvasRenderer.canvasSizeChanged(); 972            canvasRenderer.contentChanged(CanvasChanged); 973        } 974 975        notifyObserversCanvasResized(); 976    } 977 950978    didDraw(FloatRect(FloatPoint(), size())); 951979}   10531081} 10541082 1055} 1083bool HTMLCanvasElement::isControlledByOffscreen() const 1084{ 1085    return m_context && m_context->isPlaceholder(); 1086} 1087 1088}
  • TabularUnified trunk/Source/WebCore/html/HTMLCanvasElement.h

    r265116 r265543   5151class MediaSample; 5252class MediaStream; 53class OffscreenCanvas; 5354class WebGLRenderingContextBase; 5455class GPUCanvasContext;   9899    WEBCORE_EXPORT ExceptionOr<UncachedString> toDataURL(const String& mimeType); 99100    ExceptionOr<void> toBlob(ScriptExecutionContext&, Ref<BlobCallback>&&, const String& mimeType, JSC::JSValue quality); 101#if ENABLE(OFFSCREEN_CANVAS) 102    ExceptionOr<Ref<OffscreenCanvas>> transferControlToOffscreen(ScriptExecutionContext&); 103#endif 100104 101105    // Used for rendering   135139    void setIsSnapshotting(bool isSnapshotting) { m_isSnapshotting = isSnapshotting; } 136140    bool isSnapshotting() const { return m_isSnapshotting; } 141 142    bool isControlledByOffscreen() const; 137143 138144private:
  • TabularUnified trunk/Source/WebCore/html/HTMLCanvasElement.idl

    r259130 r265543   5151    [MayThrowException] DOMString toDataURL(optional DOMString type, optional any quality); 5252    [CallWith=ScriptExecutionContext, MayThrowException] void toBlob(BlobCallback callback, optional DOMString type, optional any quality); 53    [Conditional=OFFSCREEN_CANVAS, CallWith=ScriptExecutionContext, MayThrowException] OffscreenCanvas transferControlToOffscreen(); 5354 5455    [Conditional=MEDIA_STREAM, CallWith=Document, MayThrowException, NewObject] MediaStream captureStream(optional double frameRequestRate);
  • TabularUnified trunk/Source/WebCore/html/OffscreenCanvas.cpp

    r265360 r265543   3232#include "CanvasRenderingContext.h" 3333#include "Document.h" 34#include "HTMLCanvasElement.h" 3435#include "ImageBitmap.h" 36#include "ImageData.h" 3537#include "JSBlob.h" 3638#include "JSDOMPromiseDeferred.h" 3739#include "MIMETypeRegistry.h" 3840#include "OffscreenCanvasRenderingContext2D.h" 41#include "PlaceholderRenderingContext.h" 3942#include "WebGLRenderingContext.h" 4043#include "WorkerGlobalScope.h"   5760} 5861 62WeakPtr<HTMLCanvasElement> DetachedOffscreenCanvas::takePlaceholderCanvas() 63{ 64    ASSERT(isMainThread()); 65    return std::exchange(m_placeholderCanvas, nullptr); 66} 67 5968Ref<OffscreenCanvas> OffscreenCanvas::create(ScriptExecutionContext& context, unsigned width, unsigned height) 6069{   6978        clone->setOriginTainted(); 7079 80    callOnMainThread([detachedCanvas = WTFMove(detachedCanvas), offscreenCanvas = makeRef(clone.get())] () mutable { 81        offscreenCanvas->m_placeholderCanvas = detachedCanvas->takePlaceholderCanvas(); 82        offscreenCanvas->scriptExecutionContext()->postTask({ ScriptExecutionContext::Task::CleanupTask, 83            [releaseOffscreenCanvas = WTFMove(offscreenCanvas)] (ScriptExecutionContext&) { } }); 84    }); 85 7186    return clone; 87} 88 89Ref<OffscreenCanvas> OffscreenCanvas::create(ScriptExecutionContext& context, HTMLCanvasElement& canvas) 90{ 91    auto offscreen = adoptRef(*new OffscreenCanvas(context, canvas.width(), canvas.height())); 92    offscreen->setPlaceholderCanvas(canvas); 93    return offscreen; 7294} 7395   120142} 121143 122ExceptionOr<OffscreenRenderingContext> OffscreenCanvas::getContext(JSC::JSGlobalObject& state, RenderingContextType contextType, Vector<JSC::Strong<JSC::Unknown>>&& arguments) 144ExceptionOr<Optional<OffscreenRenderingContext>> OffscreenCanvas::getContext(JSC::JSGlobalObject& state, RenderingContextType contextType, Vector<JSC::Strong<JSC::Unknown>>&& arguments) 123145{ 124146    if (m_detached)   128150        if (m_context) { 129151            if (!is<OffscreenCanvasRenderingContext2D>(*m_context)) 130                return Exception { InvalidStateError }; 131            return { RefPtr<OffscreenCanvasRenderingContext2D> { &downcast<OffscreenCanvasRenderingContext2D>(*m_context) } }; 152                return { { WTF::nullopt } }; 153            return { { RefPtr<OffscreenCanvasRenderingContext2D> { &downcast<OffscreenCanvasRenderingContext2D>(*m_context) } } }; 132154        } 133155 134156        m_context = makeUnique<OffscreenCanvasRenderingContext2D>(*this); 135157        if (!m_context) 136            return { RefPtr<OffscreenCanvasRenderingContext2D> { nullptr } }; 137 138        return { RefPtr<OffscreenCanvasRenderingContext2D> { &downcast<OffscreenCanvasRenderingContext2D>(*m_context) } }; 158            return { { WTF::nullopt } }; 159 160        return { { RefPtr<OffscreenCanvasRenderingContext2D> { &downcast<OffscreenCanvasRenderingContext2D>(*m_context) } } }; 139161    } 140162#if ENABLE(WEBGL) 141163    if (contextType == RenderingContextType::Webgl) { 142164        if (m_context) { 143            if (!is<WebGLRenderingContext>(*m_context)) 144                return Exception { InvalidStateError }; 145            return { RefPtr<WebGLRenderingContext> { &downcast<WebGLRenderingContext>(*m_context) } }; 165            if (is<WebGLRenderingContext>(*m_context)) 166                return { { RefPtr<WebGLRenderingContext> { &downcast<WebGLRenderingContext>(*m_context) } } }; 167            return { { WTF::nullopt } }; 146168        } 147169   152174        m_context = WebGLRenderingContextBase::create(*this, attributes, "webgl"); 153175        if (!m_context) 154            return { RefPtr<WebGLRenderingContext> { nullptr } }; 155 156        return { RefPtr<WebGLRenderingContext> { &downcast<WebGLRenderingContext>(*m_context) } }; 176            return { { WTF::nullopt } }; 177 178        return { { RefPtr<WebGLRenderingContext> { &downcast<WebGLRenderingContext>(*m_context) } } }; 157179    } 158180#endif 159181 160    return Exception { NotSupportedError }; 182    return Exception { TypeError }; 161183} 162184   260282{ 261283    clearCopiedImage(); 284    scheduleCommitToPlaceholderCanvas(); 262285    notifyObserversCanvasChanged(rect); 263286}   302325    m_detached = true; 303326 304    return makeUnique<DetachedOffscreenCanvas>(takeImageBuffer(), size(), originClean()); 327    auto detached = makeUnique<DetachedOffscreenCanvas>(takeImageBuffer(), size(), originClean()); 328    detached->m_placeholderCanvas = std::exchange(m_placeholderCanvas, nullptr); 329 330    return detached; 331} 332 333void OffscreenCanvas::setPlaceholderCanvas(HTMLCanvasElement& canvas) 334{ 335    ASSERT(!m_context); 336    ASSERT(isMainThread()); 337    m_placeholderCanvas = makeWeakPtr(canvas); 338} 339 340void OffscreenCanvas::pushBufferToPlaceholder() 341{ 342    callOnMainThread([protectedThis = makeRef(*this), this] () mutable { 343        auto locker = holdLock(m_commitLock); 344 345        if (m_placeholderCanvas && m_hasPendingCommitData) { 346            std::unique_ptr<ImageBuffer> buffer = ImageBuffer::create(FloatSize(m_pendingCommitData->size()), RenderingMode::Unaccelerated); 347            buffer->putImageData(AlphaPremultiplication::Premultiplied, *m_pendingCommitData, IntRect(IntPoint(), m_pendingCommitData->size())); 348            m_placeholderCanvas->setImageBufferAndMarkDirty(WTFMove(buffer)); 349            m_hasPendingCommitData = false; 350        } 351 352        scriptExecutionContext()->postTask([releaseThis = WTFMove(protectedThis)] (ScriptExecutionContext&) { }); 353    }); 354} 355 356void OffscreenCanvas::commitToPlaceholderCanvas() 357{ 358    auto* imageBuffer = buffer(); 359    if (!imageBuffer) 360        return; 361 362    // FIXME: Transfer texture over if we're using accelerated compositing 363    if (m_context && (m_context->isWebGL() || m_context->isAccelerated())) 364        m_context->paintRenderingResultsToCanvas(); 365 366    if (isMainThread()) { 367        if (m_placeholderCanvas) { 368            if (auto bufferCopy = imageBuffer->copyRectToBuffer(FloatRect(FloatPoint(), imageBuffer->logicalSize()), ColorSpace::SRGB, imageBuffer->context())) 369                m_placeholderCanvas->setImageBufferAndMarkDirty(WTFMove(bufferCopy)); 370        } 371        return; 372    } 373 374    auto locker = holdLock(m_commitLock); 375 376    bool shouldPushBuffer = !m_hasPendingCommitData; 377    m_pendingCommitData = imageBuffer->getImageData(AlphaPremultiplication::Premultiplied, IntRect(IntPoint(), imageBuffer->logicalSize())); 378    m_hasPendingCommitData = true; 379 380    if (shouldPushBuffer) 381        pushBufferToPlaceholder(); 382} 383 384void OffscreenCanvas::scheduleCommitToPlaceholderCanvas() 385{ 386    if (!m_hasScheduledCommit) { 387        auto& scriptContext = *scriptExecutionContext(); 388        m_hasScheduledCommit = true; 389        scriptContext.postTask([protectedThis = makeRef(*this), this] (ScriptExecutionContext&) { 390            m_hasScheduledCommit = false; 391            commitToPlaceholderCanvas(); 392        }); 393    } 305394} 306395   352441 353442    notifyObserversCanvasResized(); 443    scheduleCommitToPlaceholderCanvas(); 354444} 355445
  • TabularUnified trunk/Source/WebCore/html/OffscreenCanvas.h

    r262899 r265543   3939#include <wtf/Forward.h> 4040#include <wtf/RefCounted.h> 41#include <wtf/WeakPtr.h> 4142#include <wtf/text/WTFString.h> 4243   4647class CSSValuePool; 4748class DeferredPromise; 49class HTMLCanvasElement; 4850class ImageBitmap; 51class ImageData; 4952class OffscreenCanvasRenderingContext2D; 5053class WebGLRenderingContext;   5962    WTF_MAKE_NONCOPYABLE(DetachedOffscreenCanvas); 6063    WTF_MAKE_FAST_ALLOCATED; 64    friend class OffscreenCanvas; 65 6166public: 6267    DetachedOffscreenCanvas(std::unique_ptr<ImageBuffer>&&, const IntSize&, bool originClean);   7277        return 0; 7378    } 79    WeakPtr<HTMLCanvasElement> takePlaceholderCanvas(); 7480 7581private:   7783    IntSize m_size; 7884    bool m_originClean; 85    WeakPtr<HTMLCanvasElement> m_placeholderCanvas; 7986}; 8087   95102    static Ref<OffscreenCanvas> create(ScriptExecutionContext&, unsigned width, unsigned height); 96103    static Ref<OffscreenCanvas> create(ScriptExecutionContext&, std::unique_ptr<DetachedOffscreenCanvas>&&); 104    static Ref<OffscreenCanvas> create(ScriptExecutionContext&, HTMLCanvasElement&); 97105    virtual ~OffscreenCanvas(); 98106   104112    CanvasRenderingContext* renderingContext() const final { return m_context.get(); } 105113 106    ExceptionOr<OffscreenRenderingContext> getContext(JSC::JSGlobalObject&, RenderingContextType, Vector<JSC::Strong<JSC::Unknown>>&& arguments); 114    ExceptionOr<Optional<OffscreenRenderingContext>> getContext(JSC::JSGlobalObject&, RenderingContextType, Vector<JSC::Strong<JSC::Unknown>>&& arguments); 107115    ExceptionOr<RefPtr<ImageBitmap>> transferToImageBitmap(); 108116    void convertToBlob(ImageEncodeOptions&&, Ref<DeferredPromise>&&);   117125    bool canDetach() const; 118126    std::unique_ptr<DetachedOffscreenCanvas> detach(); 127 128    void commitToPlaceholderCanvas(); 119129 120130    CSSValuePool& cssValuePool();   147157    void clearCopiedImage() const; 148158 159    void setPlaceholderCanvas(HTMLCanvasElement&); 160    void pushBufferToPlaceholder(); 161    void scheduleCommitToPlaceholderCanvas(); 162 149163    std::unique_ptr<CanvasRenderingContext> m_context; 150164   155169 156170    mutable RefPtr<Image> m_copiedImage; 171 172    bool m_hasScheduledCommit { false }; 173    WeakPtr<HTMLCanvasElement> m_placeholderCanvas; 174 175    mutable Lock m_commitLock; 176    bool m_hasPendingCommitData { false }; 177    RefPtr<ImageData> m_pendingCommitData; 157178}; 158179
  • TabularUnified trunk/Source/WebCore/html/canvas/OffscreenCanvasRenderingContext2D.cpp

    r251630 r265543   4949OffscreenCanvasRenderingContext2D::~OffscreenCanvasRenderingContext2D() = default; 5050 51void OffscreenCanvasRenderingContext2D::commit() 52{ 53    downcast<OffscreenCanvas>(canvasBase()).commitToPlaceholderCanvas(); 54} 55 5156} // namespace WebCore 5257
  • TabularUnified trunk/Source/WebCore/html/canvas/OffscreenCanvasRenderingContext2D.h

    r251630 r265543   4343 4444    OffscreenCanvas& canvas() const { return downcast<OffscreenCanvas>(canvasBase()); } 45 46    void commit(); 4547}; 4648
  • TabularUnified trunk/Source/WebCore/html/canvas/OffscreenCanvasRenderingContext2D.idl

    r251630 r265543   2828    EnabledAtRuntime=OffscreenCanvas, 2929    Conditional=OFFSCREEN_CANVAS, 30    Exposed=(Window), // FIXME: OffscreenCanvas - should be Window,Worker 30    Exposed=(Window,Worker), 3131    JSGenerateToJSObject, 3232    JSCustomMarkFunction,   3434] interface OffscreenCanvasRenderingContext2D { 3535    readonly attribute OffscreenCanvas canvas; 36    // FIXME: OffscreenCanvas. 37    // void commit(); 36    void commit(); 3837 3938    // Inspector-only.
  • TabularUnified trunk/Source/WebCore/html/canvas/PlaceholderRenderingContext.cpp

    r243887 r265543   2727#include "PlaceholderRenderingContext.h" 2828 29#if ENABLE(OFFSCREEN_CANVAS) 30 31#include "HTMLCanvasElement.h" 32#include "OffscreenCanvas.h" 2933#include <wtf/IsoMallocInlines.h> 3034   3842} 3943 44HTMLCanvasElement* PlaceholderRenderingContext::canvas() const 45{ 46    auto& base = canvasBase(); 47    if (!is<HTMLCanvasElement>(base)) 48        return nullptr; 49    return &downcast<HTMLCanvasElement>(base); 4050} 51 52} 53 54#endif
  • TabularUnified trunk/Source/WebCore/html/canvas/PlaceholderRenderingContext.h

    r243887 r265543   2626#pragma once 2727 28#if ENABLE(OFFSCREEN_CANVAS) 29 2830#include "CanvasRenderingContext.h" 2931 3032namespace WebCore { 33 34class OffscreenCanvas; 3135 3236class PlaceholderRenderingContext final : public CanvasRenderingContext {   3438public: 3539    PlaceholderRenderingContext(CanvasBase&); 40 41    HTMLCanvasElement* canvas() const; 3642 3743private:   4248 4349SPECIALIZE_TYPE_TRAITS_CANVASRENDERINGCONTEXT(WebCore::PlaceholderRenderingContext, isPlaceholder()) 50 51#endif
Note: See TracChangeset for help on using the changeset viewer.

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK