Title: [283845] branches/safari-612-branch
Revision
283845
Author
[email protected]
Date
2021-10-08 15:43:49 -0700 (Fri, 08 Oct 2021)

Log Message

Revert r283238. rdar://problem/83955650

Modified Paths

Removed Paths

Diff

Modified: branches/safari-612-branch/ChangeLog (283844 => 283845)


--- branches/safari-612-branch/ChangeLog	2021-10-08 22:35:14 UTC (rev 283844)
+++ branches/safari-612-branch/ChangeLog	2021-10-08 22:43:49 UTC (rev 283845)
@@ -1,3 +1,7 @@
+2021-10-08  Russell Epstein  <[email protected]>
+
+        Revert r283238. rdar://problem/83955650
+
 2021-10-07  Alan Coon  <[email protected]>
 
         Cherry-pick r283238. rdar://problem/83955650

Modified: branches/safari-612-branch/LayoutTests/ChangeLog (283844 => 283845)


--- branches/safari-612-branch/LayoutTests/ChangeLog	2021-10-08 22:35:14 UTC (rev 283844)
+++ branches/safari-612-branch/LayoutTests/ChangeLog	2021-10-08 22:43:49 UTC (rev 283845)
@@ -1,5 +1,9 @@
 2021-10-08  Russell Epstein  <[email protected]>
 
+        Revert r283238. rdar://problem/83955650
+
+2021-10-08  Russell Epstein  <[email protected]>
+
         Cherry-pick r283531. rdar://problem/83956741
 
     Choose an appropriate color space when converting an SVG image into a NativeImage for canvas drawImage

Modified: branches/safari-612-branch/LayoutTests/fast/mediacapturefromelement/CanvasCaptureMediaStream-webgl-events-expected.txt (283844 => 283845)


--- branches/safari-612-branch/LayoutTests/fast/mediacapturefromelement/CanvasCaptureMediaStream-webgl-events-expected.txt	2021-10-08 22:35:14 UTC (rev 283844)
+++ branches/safari-612-branch/LayoutTests/fast/mediacapturefromelement/CanvasCaptureMediaStream-webgl-events-expected.txt	2021-10-08 22:43:49 UTC (rev 283845)
@@ -1,3 +1,4 @@
+CONSOLE MESSAGE: Turning drawing buffer preservation for the WebGL canvas being captured
 Exercises the potential events on CanvasCaptureMediaStream.
 
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".

Modified: branches/safari-612-branch/LayoutTests/fast/mediastream/captureStream/canvas3d-expected.txt (283844 => 283845)


--- branches/safari-612-branch/LayoutTests/fast/mediastream/captureStream/canvas3d-expected.txt	2021-10-08 22:35:14 UTC (rev 283844)
+++ branches/safari-612-branch/LayoutTests/fast/mediastream/captureStream/canvas3d-expected.txt	2021-10-08 22:43:49 UTC (rev 283845)
@@ -1,3 +1,4 @@
+CONSOLE MESSAGE: Turning drawing buffer preservation for the WebGL canvas being captured
 
 
 

Deleted: branches/safari-612-branch/ManualTests/mediastream/mediastream-canvas-to-video.html (283844 => 283845)


--- branches/safari-612-branch/ManualTests/mediastream/mediastream-canvas-to-video.html	2021-10-08 22:35:14 UTC (rev 283844)
+++ branches/safari-612-branch/ManualTests/mediastream/mediastream-canvas-to-video.html	2021-10-08 22:43:49 UTC (rev 283845)
@@ -1,192 +0,0 @@
-<html>
-<head>
-    <style type="text/css">
-    video { border: solid 1px black; }
-    canvas { padding: 1px }
-    .placeholder {
-        display: inline-block;
-        border: 1px dashed black;
-        width: 300px;
-        height: 150px;
-    }
-    </style>
-</head>
-<body>
-<p>
-<input type="button" _onclick_="drawOnce()" value="Draw once" />
-<input type="button" _onclick_="clearOnce()" value="Clear once" />
-<input type="button" _onclick_="toggleDrawing()" value="Toggle drawing"/>
-</p>
-<p>
-    <ul>
-        <li>Left: canvas</li>
-        <li>Right: video</li>
-        <li>Top rectangle small: opaque</li>
-        <li>Bottom rectangle big: 50% translucent</li>
-        <li>Background: transparent</li>
-    </ul>
-</p>
-<script>
-
-var ctx2Ds = [];
-
-var gls = [];
-
-function createTests()
-{
-    let glCases = [];
-    for (let preserveDrawingBuffer of [true, false]) {
-        for (let alpha of [true, false]) {
-            for (let premultipliedAlpha of [true, false]) {
-                glCases.push({
-                    preserveDrawingBuffer: preserveDrawingBuffer,
-                    alpha: alpha,
-                    premultipliedAlpha: premultipliedAlpha,
-                    antialias: false,
-                    inDocument: true
-                });
-            }
-        }
-    }
-    glCases.push({
-        preserveDrawingBuffer: false,
-        alpha: true,
-        premultipliedAlpha: true,
-        antialias: true,
-        inDocument: true
-    });
-    glCases.push({
-        preserveDrawingBuffer: false,
-        alpha: true,
-        premultipliedAlpha: true,
-        antialias: false,
-        inDocument: false
-    });
-
-    var ctx2DCases = [];
-    for (let inDocument of [true, false]) {
-        ctx2DCases.push({ inDocument: inDocument });
-    }
-
-    for (let c of glCases) {
-        let d = document.createElement("div");
-        document.body.appendChild(d);
-        let h = document.createElement("h3");
-        h.innerText = `WebGL case: ${JSON.stringify(c)}`;
-        d.appendChild(h);
-        let canvas = document.createElement("canvas");
-        if (c.inDocument)
-            d.appendChild(canvas);
-        else {
-            let p = document.createElement("div");
-            p.className = "placeholder";
-            d.appendChild(p);
-        }
-        let v = document.createElement("video");
-        v.controls = true;
-        v.autoplay = true;
-        d.appendChild(v);
-
-        let gl = canvas.getContext("webgl2", {
-            preserveDrawingBuffer: c.preserveDrawingBuffer,
-            alpha: c.alpha,
-            premultipliedAlpha: c.premultipliedAlpha,
-            antialias: c.antialias
-        });
-        v.srcObject = canvas.captureStream();
-        gls.push(gl);
-    }
-
-    for (let c of ctx2DCases) {
-        let d = document.createElement("div");
-        document.body.appendChild(d);
-        let h = document.createElement("h3");
-        h.innerText = `Canvas case: ${JSON.stringify(c)}`;
-        d.appendChild(h);
-        let canvas = document.createElement("canvas");
-        if (c.inDocument)
-            d.appendChild(canvas);
-        else {
-            let p = document.createElement("div");
-            p.className = "placeholder";
-            d.appendChild(p);
-        }
-        let v = document.createElement("video");
-        v.controls = true;
-        v.autoplay = true;
-        d.appendChild(v);
-        let ctx2D = canvas.getContext("2d");
-        v.srcObject = canvas.captureStream();
-        ctx2Ds.push(ctx2D);
-    }
-}
-
-function drawOnce()
-{
-    for (let c of gls) {
-        c.enable(c.SCISSOR_TEST);
-        if (c.getContextAttributes().premultipliedAlpha)
-            c.clearColor(0., 0.5, 0., 0.5);
-        else
-            c.clearColor(0., 1., 0., 0.5);
-        c.scissor(0, 0, 300, 50);
-        c.clear(c.COLOR_BUFFER_BIT);
-
-        c.scissor(125, 50, 50, 50);
-        c.clearColor(0., 1., 0., 1.);
-        c.clear(c.COLOR_BUFFER_BIT);
-        c.scissor(0, 0, 300, 50);
-        c.clear(c.COLOR_BUFFER_BIT);
-
-    }
-    for (let c of ctx2Ds) {
-        c.fillStyle = "rgba(0, 128, 0, 0.5)";
-        c.fillRect(0, 100, 300, 50);
-        c.fillStyle = "rgba(0, 255, 0, 1.)";
-        c.fillRect(125, 50, 50, 50);
-    }
-}
-
-function clearOnce()
-{
-    console.log("clear");
-    for (let c of gls) {
-        c.clearColor(0., 0., 0., 0.);
-        c.disable(c.SCISSOR_TEST);
-        c.clear(c.COLOR_BUFFER_BIT);
-    }
-    for (let c of ctx2Ds) {
-        c.clearRect(0, 0, 300, 150);
-    }
-}
-
-var isToggling = false;
-
-function toggleDrawing()
-{
-    if (isToggling) {
-        clearTimeout(isToggling);
-        isToggling = false;
-        return;
-    }
-    var hasDrawn = true;
-    function f() {
-        if (hasDrawn)
-            clearOnce();
-        else
-            drawOnce();
-        hasDrawn = !hasDrawn;
-        isToggling = setTimeout(f, 1000);
-    }
-    f();
-}
-
-createTests();
-
-if (window.testRunner) {
-    window.testRunner.waitUntilDone();
-    toggleDrawing();
-}
-</script>
-</body>
-</html>
\ No newline at end of file

Modified: branches/safari-612-branch/Source/WebCore/ChangeLog (283844 => 283845)


--- branches/safari-612-branch/Source/WebCore/ChangeLog	2021-10-08 22:35:14 UTC (rev 283844)
+++ branches/safari-612-branch/Source/WebCore/ChangeLog	2021-10-08 22:43:49 UTC (rev 283845)
@@ -1,5 +1,9 @@
 2021-10-08  Russell Epstein  <[email protected]>
 
+        Revert r283238. rdar://problem/83955650
+
+2021-10-08  Russell Epstein  <[email protected]>
+
         Cherry-pick r283531. rdar://problem/83956741
 
     Choose an appropriate color space when converting an SVG image into a NativeImage for canvas drawImage

Modified: branches/safari-612-branch/Source/WebCore/Modules/mediastream/CanvasCaptureMediaStreamTrack.cpp (283844 => 283845)


--- branches/safari-612-branch/Source/WebCore/Modules/mediastream/CanvasCaptureMediaStreamTrack.cpp	2021-10-08 22:35:14 UTC (rev 283844)
+++ branches/safari-612-branch/Source/WebCore/Modules/mediastream/CanvasCaptureMediaStreamTrack.cpp	2021-10-08 22:43:49 UTC (rev 283845)
@@ -153,6 +153,19 @@
 {
     ASSERT_UNUSED(canvas, m_canvas == &canvas);
 
+#if ENABLE(WEBGL)
+    // FIXME: We need to preserve drawing buffer as we are currently grabbing frames asynchronously.
+    // We should instead add an anchor point for both 2d and 3d contexts where canvas will actually paint.
+    // And call canvas observers from that point.
+    if (is<WebGLRenderingContextBase>(canvas.renderingContext())) {
+        auto& context = downcast<WebGLRenderingContextBase>(*canvas.renderingContext());
+        if (!context.isPreservingDrawingBuffer()) {
+            canvas.scriptExecutionContext()->addConsoleMessage(MessageSource::JS, MessageLevel::Warning, "Turning drawing buffer preservation for the WebGL canvas being captured"_s);
+            context.enablePreserveDrawingBuffer();
+        }
+    }
+#endif
+
     // FIXME: We should try to generate the frame at the time the screen is being updated.
     if (m_captureCanvasTimer.isActive())
         return;

Modified: branches/safari-612-branch/Source/WebCore/html/HTMLCanvasElement.cpp (283844 => 283845)


--- branches/safari-612-branch/Source/WebCore/html/HTMLCanvasElement.cpp	2021-10-08 22:35:14 UTC (rev 283844)
+++ branches/safari-612-branch/Source/WebCore/html/HTMLCanvasElement.cpp	2021-10-08 22:43:49 UTC (rev 283845)
@@ -758,13 +758,6 @@
 RefPtr<MediaSample> HTMLCanvasElement::toMediaSample()
 {
 #if PLATFORM(COCOA) || USE(GSTREAMER)
-#if ENABLE(WEBGL)
-    if (is<WebGLRenderingContextBase>(m_context.get())) {
-        if (RuntimeEnabledFeatures::sharedFeatures().webAPIStatisticsEnabled())
-            ResourceLoadObserver::shared().logCanvasRead(document());
-        return downcast<WebGLRenderingContextBase>(*m_context).paintCompositedResultsToMediaSample();
-    }
-#endif
     auto* imageBuffer = buffer();
     if (!imageBuffer)
         return nullptr;

Modified: branches/safari-612-branch/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp (283844 => 283845)


--- branches/safari-612-branch/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp	2021-10-08 22:35:14 UTC (rev 283844)
+++ branches/safari-612-branch/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp	2021-10-08 22:43:49 UTC (rev 283845)
@@ -134,10 +134,6 @@
 #include "OffscreenCanvas.h"
 #endif
 
-#if ENABLE(MEDIA_STREAM)
-#include "MediaSample.h"
-#endif
-
 namespace WebCore {
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(WebGLRenderingContextBase);
@@ -1258,15 +1254,6 @@
     return m_context->paintRenderingResultsToPixelBuffer();
 }
 
-#if ENABLE(MEDIA_STREAM)
-RefPtr<MediaSample> WebGLRenderingContextBase::paintCompositedResultsToMediaSample()
-{
-    if (isContextLostOrPending())
-        return nullptr;
-    return m_context->paintCompositedResultsToMediaSample();
-}
-#endif
-
 WebGLTexture::TextureExtensionFlag WebGLRenderingContextBase::textureExtensionFlags() const
 {
     return static_cast<WebGLTexture::TextureExtensionFlag>((m_oesTextureFloatLinear ? WebGLTexture::TextureExtensionFloatLinearEnabled : 0) | (m_oesTextureHalfFloatLinear ? WebGLTexture::TextureExtensionHalfFloatLinearEnabled : 0));
@@ -3836,6 +3823,14 @@
     return false;
 }
 
+void WebGLRenderingContextBase::enablePreserveDrawingBuffer()
+{
+    ASSERT(!m_attributes.preserveDrawingBuffer);
+    m_attributes.preserveDrawingBuffer = true;
+    // Must send this notification down to the GraphicsContextGL as well.
+    m_context->enablePreserveDrawingBuffer();
+}
+
 void WebGLRenderingContextBase::hint(GCGLenum target, GCGLenum mode)
 {
     if (isContextLostOrPending())

Modified: branches/safari-612-branch/Source/WebCore/html/canvas/WebGLRenderingContextBase.h (283844 => 283845)


--- branches/safari-612-branch/Source/WebCore/html/canvas/WebGLRenderingContextBase.h	2021-10-08 22:35:14 UTC (rev 283844)
+++ branches/safari-612-branch/Source/WebCore/html/canvas/WebGLRenderingContextBase.h	2021-10-08 22:43:49 UTC (rev 283845)
@@ -128,10 +128,6 @@
 using WebGLCanvas = WTF::Variant<RefPtr<HTMLCanvasElement>>;
 #endif
 
-#if ENABLE(MEDIA_STREAM)
-class MediaSample;
-#endif
-
 class WebGLRenderingContextBase : public GraphicsContextGL::Client, public GPUBasedCanvasRenderingContext, private ActivityStateChangeObserver {
     WTF_MAKE_ISO_ALLOCATED(WebGLRenderingContextBase);
 public:
@@ -237,6 +233,10 @@
     bool extensionIsEnabled(const String&);
 
     bool isPreservingDrawingBuffer() const { return m_attributes.preserveDrawingBuffer; }
+    // Concession to canvas capture API, which must dynamically enable
+    // preserveDrawingBuffer. This can only be called once, when
+    // isPreservingDrawingBuffer() returns false.
+    void enablePreserveDrawingBuffer();
 
     bool preventBufferClearForInspector() const { return m_preventBufferClearForInspector; }
     void setPreventBufferClearForInspector(bool value) { m_preventBufferClearForInspector = value; }
@@ -392,9 +392,6 @@
     void prepareForDisplayWithPaint() final;
     void paintRenderingResultsToCanvas() final;
     std::optional<PixelBuffer> paintRenderingResultsToPixelBuffer();
-#if ENABLE(MEDIA_STREAM)
-    RefPtr<MediaSample> paintCompositedResultsToMediaSample();
-#endif
 
     void removeSharedObject(WebGLSharedObject&);
     void removeContextObject(WebGLContextObject&);

Modified: branches/safari-612-branch/Source/WebCore/platform/graphics/GraphicsContextGL.cpp (283844 => 283845)


--- branches/safari-612-branch/Source/WebCore/platform/graphics/GraphicsContextGL.cpp	2021-10-08 22:35:14 UTC (rev 283844)
+++ branches/safari-612-branch/Source/WebCore/platform/graphics/GraphicsContextGL.cpp	2021-10-08 22:43:49 UTC (rev 283845)
@@ -362,6 +362,12 @@
 {
 }
 
+void GraphicsContextGL::enablePreserveDrawingBuffer()
+{
+    // Canvas capture should not call this unless necessary.
+    ASSERT(!m_attrs.preserveDrawingBuffer);
+    m_attrs.preserveDrawingBuffer = true;
+}
 
 unsigned GraphicsContextGL::getClearBitsByAttachmentType(GCGLenum attachment)
 {

Modified: branches/safari-612-branch/Source/WebCore/platform/graphics/GraphicsContextGL.h (283844 => 283845)


--- branches/safari-612-branch/Source/WebCore/platform/graphics/GraphicsContextGL.h	2021-10-08 22:35:14 UTC (rev 283844)
+++ branches/safari-612-branch/Source/WebCore/platform/graphics/GraphicsContextGL.h	2021-10-08 22:43:49 UTC (rev 283845)
@@ -59,10 +59,8 @@
 #if ENABLE(VIDEO) && USE(AVFOUNDATION)
 class GraphicsContextGLCV;
 #endif
-#if ENABLE(MEDIA_STREAM)
-class MediaSample;
-#endif
 
+
 // Base class for graphics context for implementing WebGL rendering model.
 class GraphicsContextGL : public RefCounted<GraphicsContextGL> {
 public:
@@ -1247,6 +1245,13 @@
     GraphicsContextGLAttributes contextAttributes() const { return m_attrs; }
     void setContextAttributes(const GraphicsContextGLAttributes& attrs) { m_attrs = attrs; }
 
+    // FIXME: The calling site should be fixed, this breaks the WebGL spec
+    // wrt preserveDrawingBuffer == false behavior.
+    // Concession to Canvas captureStream, which needs to dynamically set
+    // preserveDrawingBuffer to true in order to avoid implicit clears.
+    // Implementations generally do not support toggling this bit arbitrarily.
+    virtual void enablePreserveDrawingBuffer();
+
     // Support for extensions. Returns a non-null object, though not
     // all methods it contains may necessarily be supported on the
     // current hardware. Must call ExtensionsGL::supports() to
@@ -1290,9 +1295,6 @@
     virtual void paintRenderingResultsToCanvas(ImageBuffer&) = 0;
     virtual std::optional<PixelBuffer> paintRenderingResultsToPixelBuffer() = 0;
     virtual void paintCompositedResultsToCanvas(ImageBuffer&) = 0;
-#if ENABLE(MEDIA_STREAM)
-    virtual RefPtr<MediaSample> paintCompositedResultsToMediaSample() = 0;
-#endif
 
     // FIXME: this should be removed. The layer should be marked composited by
     // preparing for display, so that canvas image buffer and the layer agree

Modified: branches/safari-612-branch/Source/WebCore/platform/graphics/RemoteGraphicsContextGLProxyBase.cpp (283844 => 283845)


--- branches/safari-612-branch/Source/WebCore/platform/graphics/RemoteGraphicsContextGLProxyBase.cpp	2021-10-08 22:35:14 UTC (rev 283844)
+++ branches/safari-612-branch/Source/WebCore/platform/graphics/RemoteGraphicsContextGLProxyBase.cpp	2021-10-08 22:43:49 UTC (rev 283845)
@@ -97,6 +97,13 @@
     return m_buffersToAutoClear;
 }
 
+void RemoteGraphicsContextGLProxyBase::enablePreserveDrawingBuffer()
+{
+    // Redeclared for export reasons.
+    // FIXME: The whole function should be removed.
+    GraphicsContextGL::enablePreserveDrawingBuffer();
+}
+
 bool RemoteGraphicsContextGLProxyBase::supports(const String& name)
 {
     waitUntilInitialized();
@@ -149,12 +156,5 @@
 {
 }
 #endif
-
-#if ENABLE(MEDIA_STREAM) && !PLATFORM(COCOA)
-RefPtr<MediaSample> RemoteGraphicsContextGLProxyBase::paintCompositedResultsToMediaSample()
-{
-    return nullptr;
 }
 #endif
-}
-#endif

Modified: branches/safari-612-branch/Source/WebCore/platform/graphics/RemoteGraphicsContextGLProxyBase.h (283844 => 283845)


--- branches/safari-612-branch/Source/WebCore/platform/graphics/RemoteGraphicsContextGLProxyBase.h	2021-10-08 22:35:14 UTC (rev 283844)
+++ branches/safari-612-branch/Source/WebCore/platform/graphics/RemoteGraphicsContextGLProxyBase.h	2021-10-08 22:43:49 UTC (rev 283845)
@@ -67,6 +67,7 @@
     void setBuffersToAutoClear(GCGLbitfield) final;
     GCGLbitfield getBuffersToAutoClear() const final;
     void markLayerComposited() final;
+    void enablePreserveDrawingBuffer() final;
 
 #if ENABLE(VIDEO) && USE(AVFOUNDATION)
     GraphicsContextGLCV* asCV() final;
@@ -82,9 +83,6 @@
     void getnUniformfvEXT(GCGLuint, GCGLint, GCGLsizei, GCGLfloat*) final;
     void getnUniformivEXT(GCGLuint, GCGLint, GCGLsizei, GCGLint*) final;
 #endif
-#if ENABLE(MEDIA_STREAM)
-    RefPtr<MediaSample> paintCompositedResultsToMediaSample() final;
-#endif
 
 protected:
     void initialize(const String& availableExtensions, const String& requestableExtensions);

Modified: branches/safari-612-branch/Source/WebCore/platform/graphics/avfoundation/objc/MediaSampleAVFObjC.h (283844 => 283845)


--- branches/safari-612-branch/Source/WebCore/platform/graphics/avfoundation/objc/MediaSampleAVFObjC.h	2021-10-08 22:35:14 UTC (rev 283844)
+++ branches/safari-612-branch/Source/WebCore/platform/graphics/avfoundation/objc/MediaSampleAVFObjC.h	2021-10-08 22:43:49 UTC (rev 283845)
@@ -30,8 +30,6 @@
 #include <pal/avfoundation/MediaTimeAVFoundation.h>
 #include <wtf/Forward.h>
 
-using CVPixelBufferRef = struct __CVBuffer*;
-
 namespace WebCore {
 
 class PixelBuffer;
@@ -42,7 +40,6 @@
     static Ref<MediaSampleAVFObjC> create(CMSampleBufferRef sample, AtomString trackID) { return adoptRef(*new MediaSampleAVFObjC(sample, trackID)); }
     static Ref<MediaSampleAVFObjC> create(CMSampleBufferRef sample, VideoRotation rotation = VideoRotation::None, bool mirrored = false) { return adoptRef(*new MediaSampleAVFObjC(sample, rotation, mirrored)); }
     static RefPtr<MediaSampleAVFObjC> createImageSample(PixelBuffer&&);
-    static RefPtr<MediaSampleAVFObjC> createImageSample(RetainPtr<CVPixelBufferRef>&&, VideoRotation, bool mirrored);
 
     WEBCORE_EXPORT static void setAsDisplayImmediately(MediaSample&);
     static RetainPtr<CMSampleBufferRef> cloneSampleBufferAndSetAsDisplayImmediately(CMSampleBufferRef);

Modified: branches/safari-612-branch/Source/WebCore/platform/graphics/avfoundation/objc/MediaSampleAVFObjC.mm (283844 => 283845)


--- branches/safari-612-branch/Source/WebCore/platform/graphics/avfoundation/objc/MediaSampleAVFObjC.mm	2021-10-08 22:35:14 UTC (rev 283844)
+++ branches/safari-612-branch/Source/WebCore/platform/graphics/avfoundation/objc/MediaSampleAVFObjC.mm	2021-10-08 22:43:49 UTC (rev 283845)
@@ -95,33 +95,24 @@
         return nullptr;
     }
     ASSERT_UNUSED(status, !status);
-    return createImageSample(WTFMove(cvPixelBuffer), VideoRotation::None, false);
-}
 
-RefPtr<MediaSampleAVFObjC> MediaSampleAVFObjC::createImageSample(RetainPtr<CVPixelBufferRef>&& pixelBuffer, VideoRotation rotation, bool mirrored)
-{
     CMVideoFormatDescriptionRef formatDescriptionRaw = nullptr;
-    auto status = PAL::CMVideoFormatDescriptionCreateForImageBuffer(kCFAllocatorDefault, pixelBuffer.get(), &formatDescriptionRaw);
-    if (status || !formatDescriptionRaw) {
-        ASSERT_NOT_REACHED();
-        return nullptr;
-    }
+    status = PAL::CMVideoFormatDescriptionCreateForImageBuffer(kCFAllocatorDefault, cvPixelBuffer.get(), &formatDescriptionRaw);
+    ASSERT(!status);
     auto formatDescription = adoptCF(formatDescriptionRaw);
 
     CMSampleTimingInfo sampleTimingInformation = { PAL::kCMTimeInvalid, PAL::kCMTimeInvalid, PAL::kCMTimeInvalid };
     CMSampleBufferRef sampleBufferRaw = nullptr;
-    status = PAL::CMSampleBufferCreateReadyWithImageBuffer(kCFAllocatorDefault, pixelBuffer.get(), formatDescription.get(), &sampleTimingInformation, &sampleBufferRaw);
-    if (status || !sampleBufferRaw) {
-        ASSERT_NOT_REACHED();
-        return nullptr;
-    }
+    status = PAL::CMSampleBufferCreateReadyWithImageBuffer(kCFAllocatorDefault, cvPixelBuffer.get(), formatDescription.get(), &sampleTimingInformation, &sampleBufferRaw);
+    ASSERT(!status);
     auto sampleBuffer = adoptCF(sampleBufferRaw);
+
     CFArrayRef attachmentsArray = PAL::CMSampleBufferGetSampleAttachmentsArray(sampleBuffer.get(), true);
     for (CFIndex i = 0, count = CFArrayGetCount(attachmentsArray); i < count; ++i) {
         CFMutableDictionaryRef attachments = checked_cf_cast<CFMutableDictionaryRef>(CFArrayGetValueAtIndex(attachmentsArray, i));
         CFDictionarySetValue(attachments, PAL::kCMSampleAttachmentKey_DisplayImmediately, kCFBooleanTrue);
     }
-    return create(sampleBuffer.get(), rotation, mirrored);
+    return create(sampleBuffer.get());
 }
 
 MediaTime MediaSampleAVFObjC::presentationTime() const

Modified: branches/safari-612-branch/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLIOSurfaceSwapChain.cpp (283844 => 283845)


--- branches/safari-612-branch/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLIOSurfaceSwapChain.cpp	2021-10-08 22:35:14 UTC (rev 283844)
+++ branches/safari-612-branch/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLIOSurfaceSwapChain.cpp	2021-10-08 22:43:49 UTC (rev 283845)
@@ -37,11 +37,6 @@
     return m_displayBuffer;
 }
 
-void GraphicsContextGLIOSurfaceSwapChain::markDisplayBufferInUse()
-{
-    m_displayBufferInUse = true;
-}
-
 GraphicsContextGLIOSurfaceSwapChain::Buffer GraphicsContextGLIOSurfaceSwapChain::recycleBuffer()
 {
     if (m_spareBuffer.surface) {
@@ -61,10 +56,6 @@
 void GraphicsContextGLIOSurfaceSwapChain::present(Buffer&& buffer)
 {
     m_spareBuffer = std::exchange(m_displayBuffer, WTFMove(buffer));
-    if (m_displayBufferInUse) {
-        m_displayBufferInUse = false;
-        m_spareBuffer.surface.reset();
-    }
 }
 
 }

Modified: branches/safari-612-branch/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLIOSurfaceSwapChain.h (283844 => 283845)


--- branches/safari-612-branch/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLIOSurfaceSwapChain.h	2021-10-08 22:35:14 UTC (rev 283844)
+++ branches/safari-612-branch/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLIOSurfaceSwapChain.h	2021-10-08 22:43:49 UTC (rev 283845)
@@ -67,9 +67,6 @@
     // next present, recycleBuffer or detachClient call.
     virtual const Buffer& displayBuffer() const;
 
-    // Marks the current display buffer to be in use and not eligble to recycling.
-    void markDisplayBufferInUse();
-
     // Detaches the client and returns the current contents buffer metadata handle.
     // The if multiple buffers have been submitted, recycleBuffer must have been called before calling
     // this.
@@ -78,7 +75,6 @@
 protected:
     Buffer m_displayBuffer;
     Buffer m_spareBuffer;
-    bool m_displayBufferInUse = false;
 };
 
 }

Modified: branches/safari-612-branch/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm (283844 => 283845)


--- branches/safari-612-branch/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm	2021-10-08 22:35:14 UTC (rev 283844)
+++ branches/safari-612-branch/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm	2021-10-08 22:43:49 UTC (rev 283845)
@@ -28,7 +28,6 @@
 #if ENABLE(WEBGL)
 #import "GraphicsContextGLOpenGL.h"
 
-#import "CVUtilities.h"
 #import "ExtensionsGLANGLE.h"
 #import "GraphicsContextGLANGLEUtilities.h"
 #import "GraphicsContextGLIOSurfaceSwapChain.h"
@@ -51,10 +50,6 @@
 #include "GraphicsContextGLCV.h"
 #endif
 
-#if ENABLE(MEDIA_STREAM)
-#include "MediaSampleAVFObjC.h"
-#endif
-
 WTF_WEAK_LINK_FORCE_IMPORT(EGL_Initialize);
 
 namespace WebCore {
@@ -881,21 +876,6 @@
     ScopedEGLDefaultDisplay::releaseAllResourcesIfUnused();
 }
 
-#if ENABLE(MEDIA_STREAM)
-RefPtr<MediaSample> GraphicsContextGLOpenGL::paintCompositedResultsToMediaSample()
-{
-    auto &displayBuffer = m_swapChain->displayBuffer();
-    if (!displayBuffer.surface || !displayBuffer.handle)
-        return nullptr;
-    if (displayBuffer.surface->size() != getInternalFramebufferSize())
-        return nullptr;
-    m_swapChain->markDisplayBufferInUse();
-    auto pixelBuffer = createCVPixelBuffer(displayBuffer.surface->surface());
-    if (!pixelBuffer)
-        return nullptr;
-    return MediaSampleAVFObjC::createImageSample(WTFMove(*pixelBuffer), MediaSampleAVFObjC::VideoRotation::UpsideDown, true);
 }
-#endif
-}
 
 #endif // ENABLE(WEBGL)

Modified: branches/safari-612-branch/Source/WebCore/platform/graphics/cocoa/RemoteGraphicsContextGLProxyBaseCocoa.mm (283844 => 283845)


--- branches/safari-612-branch/Source/WebCore/platform/graphics/cocoa/RemoteGraphicsContextGLProxyBaseCocoa.mm	2021-10-08 22:35:14 UTC (rev 283844)
+++ branches/safari-612-branch/Source/WebCore/platform/graphics/cocoa/RemoteGraphicsContextGLProxyBaseCocoa.mm	2021-10-08 22:43:49 UTC (rev 283845)
@@ -32,11 +32,6 @@
 #import "WebGLLayer.h"
 #import <wtf/BlockObjCExceptions.h>
 
-#if ENABLE(MEDIA_STREAM)
-#import "CVUtilities.h"
-#import "MediaSampleAVFObjC.h"
-#endif
-
 namespace WebCore {
 
 void RemoteGraphicsContextGLProxyBase::platformInitialize()
@@ -68,20 +63,5 @@
     return [m_webGLLayer swapChain];
 }
 
-#if ENABLE(MEDIA_STREAM)
-RefPtr<MediaSample> RemoteGraphicsContextGLProxyBase::paintCompositedResultsToMediaSample()
-{
-    auto& sc = platformSwapChain();
-    auto& displayBuffer = sc.displayBuffer();
-    if (!displayBuffer.surface)
-        return nullptr;
-    sc.markDisplayBufferInUse();
-    auto pixelBuffer = createCVPixelBuffer(displayBuffer.surface->surface());
-    if (!pixelBuffer)
-        return nullptr;
-    return MediaSampleAVFObjC::createImageSample(WTFMove(*pixelBuffer), MediaSampleAVFObjC::VideoRotation::UpsideDown, true);
 }
 #endif
-
-}
-#endif

Modified: branches/safari-612-branch/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.cpp (283844 => 283845)


--- branches/safari-612-branch/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.cpp	2021-10-08 22:35:14 UTC (rev 283844)
+++ branches/safari-612-branch/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.cpp	2021-10-08 22:43:49 UTC (rev 283845)
@@ -34,7 +34,6 @@
 #include "ImageBuffer.h"
 #include "MediaPlayerPrivate.h"
 #include "PixelBuffer.h"
-#include <memory>
 #include <wtf/UniqueArray.h>
 
 #if USE(AVFOUNDATION)
@@ -41,9 +40,7 @@
 #include "GraphicsContextGLCV.h"
 #endif
 
-#if !PLATFORM(COCOA) && ENABLE(MEDIA_STREAM)
-#include "MediaSample.h"
-#endif
+#include <memory>
 
 namespace WebCore {
 
@@ -75,6 +72,14 @@
     return m_buffersToAutoClear;
 }
 
+void GraphicsContextGLOpenGL::enablePreserveDrawingBuffer()
+{
+    GraphicsContextGL::enablePreserveDrawingBuffer();
+    // After dynamically transitioning to preserveDrawingBuffer:true
+    // for canvas capture, clear out any buffer auto-clearing state.
+    m_buffersToAutoClear = 0;
+}
+
 #if !USE(ANGLE)
 bool GraphicsContextGLOpenGL::texImage2DResourceSafe(GCGLenum target, GCGLint level, GCGLenum internalformat, GCGLsizei width, GCGLsizei height, GCGLint border, GCGLenum format, GCGLenum type, GCGLint unpackAlignment)
 {
@@ -247,13 +252,6 @@
     return results;
 }
 
-#if !PLATFORM(COCOA) && ENABLE(MEDIA_STREAM)
-RefPtr<MediaSample> GraphicsContextGLOpenGL::paintCompositedResultsToMediaSample()
-{
-    return nullptr;
-}
-#endif
-
 std::optional<PixelBuffer> GraphicsContextGLOpenGL::readRenderingResultsForPainting()
 {
     if (!makeContextCurrent())

Modified: branches/safari-612-branch/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h (283844 => 283845)


--- branches/safari-612-branch/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h	2021-10-08 22:35:14 UTC (rev 283844)
+++ branches/safari-612-branch/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h	2021-10-08 22:43:49 UTC (rev 283845)
@@ -460,6 +460,7 @@
     void resetBuffersToAutoClear();
     void setBuffersToAutoClear(GCGLbitfield) final;
     GCGLbitfield getBuffersToAutoClear() const final;
+    void enablePreserveDrawingBuffer() final;
 
     void dispatchContextChangedNotification();
 
@@ -466,9 +467,6 @@
     void paintRenderingResultsToCanvas(ImageBuffer&) final;
     std::optional<PixelBuffer> paintRenderingResultsToPixelBuffer() final;
     void paintCompositedResultsToCanvas(ImageBuffer&) final;
-#if ENABLE(MEDIA_STREAM)
-    RefPtr<MediaSample> paintCompositedResultsToMediaSample() final;
-#endif
 
     std::optional<PixelBuffer> readRenderingResultsForPainting();
     std::optional<PixelBuffer> readCompositedResultsForPainting();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to