Title: [225706] trunk
Revision
225706
Author
d...@apple.com
Date
2017-12-08 14:46:50 -0800 (Fri, 08 Dec 2017)

Log Message

Implement transferToImageBitmap for WebGL offscreen canvas objects
https://bugs.webkit.org/show_bug.cgi?id=180603
<rdar://problem/34147143>

Reviewed by Sam Weinig.

Source/WebCore:

Implement the basic version of creating an ImageBitmap from an
OffscreenCanvas that is using a WebGL context.

Tests: http/wpt/offscreen-canvas/transferToImageBitmap-empty.html
       http/wpt/offscreen-canvas/transferToImageBitmap-webgl.html

* html/ImageBitmap.cpp:
(WebCore::ImageBitmap::create): Add a new constructor to be used by OffscreenCanvas.
Creates a blank ImageBitmap.
* html/ImageBitmap.h:

* html/OffscreenCanvas.cpp:
(WebCore::OffscreenCanvas::transferToImageBitmap): Create a new ImageBitmap
and paint the current canvas into it.

LayoutTests:

* http/wpt/offscreen-canvas/transferToImageBitmap-empty-expected.txt: Renamed from LayoutTests/http/wpt/offscreen-canvas/transferToImageBitmap-expected.txt.
* http/wpt/offscreen-canvas/transferToImageBitmap-empty.html: Renamed from LayoutTests/http/wpt/offscreen-canvas/transferToImageBitmap.html.
* http/wpt/offscreen-canvas/transferToImageBitmap-webgl-expected.html: Added.
* http/wpt/offscreen-canvas/transferToImageBitmap-webgl.html: Added.

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (225705 => 225706)


--- trunk/LayoutTests/ChangeLog	2017-12-08 22:45:21 UTC (rev 225705)
+++ trunk/LayoutTests/ChangeLog	2017-12-08 22:46:50 UTC (rev 225706)
@@ -1,3 +1,16 @@
+2017-12-08  Dean Jackson  <d...@apple.com>
+
+        Implement transferToImageBitmap for WebGL offscreen canvas objects
+        https://bugs.webkit.org/show_bug.cgi?id=180603
+        <rdar://problem/34147143>
+
+        Reviewed by Sam Weinig.
+
+        * http/wpt/offscreen-canvas/transferToImageBitmap-empty-expected.txt: Renamed from LayoutTests/http/wpt/offscreen-canvas/transferToImageBitmap-expected.txt.
+        * http/wpt/offscreen-canvas/transferToImageBitmap-empty.html: Renamed from LayoutTests/http/wpt/offscreen-canvas/transferToImageBitmap.html.
+        * http/wpt/offscreen-canvas/transferToImageBitmap-webgl-expected.html: Added.
+        * http/wpt/offscreen-canvas/transferToImageBitmap-webgl.html: Added.
+
 2017-12-08  Youenn Fablet  <you...@apple.com>
 
         Service Worker should use a correct SessionID

Copied: trunk/LayoutTests/http/wpt/offscreen-canvas/transferToImageBitmap-empty-expected.txt (from rev 225705, trunk/LayoutTests/http/wpt/offscreen-canvas/transferToImageBitmap-expected.txt) (0 => 225706)


--- trunk/LayoutTests/http/wpt/offscreen-canvas/transferToImageBitmap-empty-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/offscreen-canvas/transferToImageBitmap-empty-expected.txt	2017-12-08 22:46:50 UTC (rev 225706)
@@ -0,0 +1,3 @@
+
+PASS Test transferToImageBitmap. 
+

Copied: trunk/LayoutTests/http/wpt/offscreen-canvas/transferToImageBitmap-empty.html (from rev 225705, trunk/LayoutTests/http/wpt/offscreen-canvas/transferToImageBitmap.html) (0 => 225706)


--- trunk/LayoutTests/http/wpt/offscreen-canvas/transferToImageBitmap-empty.html	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/offscreen-canvas/transferToImageBitmap-empty.html	2017-12-08 22:46:50 UTC (rev 225706)
@@ -0,0 +1,15 @@
+    <!DOCTYPE html>
+<script src=""
+<script src=""
+<script src=""
+<link rel="help" href=""
+<script>
+
+test(function() {
+    let offscreenCanvas = new OffscreenCanvas(100, 100);
+    let imageBitmap = offscreenCanvas.transferToImageBitmap();
+    assert_equals(imageBitmap, null);
+}, "Test transferToImageBitmap.");
+
+</script>
+

Deleted: trunk/LayoutTests/http/wpt/offscreen-canvas/transferToImageBitmap-expected.txt (225705 => 225706)


--- trunk/LayoutTests/http/wpt/offscreen-canvas/transferToImageBitmap-expected.txt	2017-12-08 22:45:21 UTC (rev 225705)
+++ trunk/LayoutTests/http/wpt/offscreen-canvas/transferToImageBitmap-expected.txt	2017-12-08 22:46:50 UTC (rev 225706)
@@ -1,3 +0,0 @@
-
-PASS Test transferToImageBitmap. 
-

Added: trunk/LayoutTests/http/wpt/offscreen-canvas/transferToImageBitmap-webgl-expected.html (0 => 225706)


--- trunk/LayoutTests/http/wpt/offscreen-canvas/transferToImageBitmap-webgl-expected.html	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/offscreen-canvas/transferToImageBitmap-webgl-expected.html	2017-12-08 22:46:50 UTC (rev 225706)
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<link rel="help" href=""
+<canvas id="c1" width="100" height="100"></canvas>
+<canvas id="c2" width="100" height="100"></canvas>
+<canvas id="c3" width="100" height="100"></canvas>
+<canvas id="c4" width="100" height="100"></canvas>
+<script>
+    const c1 = document.getElementById("c1");
+    const gl1 = c1.getContext("webgl");
+    gl1.clearColor(1, 0, 0, 1);
+    gl1.clear(gl1.COLOR_BUFFER_BIT);
+
+    const c2 = document.getElementById("c2");
+    const gl2 = c2.getContext("webgl");
+    gl2.clearColor(0, 1, 0, 1);
+    gl2.clear(gl2.COLOR_BUFFER_BIT);
+
+    const c3 = document.getElementById("c3");
+    const gl3 = c3.getContext("webgl");
+    gl3.clearColor(0, 0, 1, 1);
+    gl3.clear(gl3.COLOR_BUFFER_BIT);
+</script>
Property changes on: trunk/LayoutTests/http/wpt/offscreen-canvas/transferToImageBitmap-webgl-expected.html
___________________________________________________________________

Added: svn:eol-style

+native \ No newline at end of property

Added: svn:keywords

+Date Revision \ No newline at end of property

Added: svn:mime-type

+text/html \ No newline at end of property

Added: trunk/LayoutTests/http/wpt/offscreen-canvas/transferToImageBitmap-webgl.html (0 => 225706)


--- trunk/LayoutTests/http/wpt/offscreen-canvas/transferToImageBitmap-webgl.html	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/offscreen-canvas/transferToImageBitmap-webgl.html	2017-12-08 22:46:50 UTC (rev 225706)
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<link rel="help" href=""
+<canvas id="c1" width="100" height="100"></canvas>
+<canvas id="c2" width="100" height="100"></canvas>
+<canvas id="c3" width="100" height="100"></canvas>
+<canvas id="c4" width="100" height="100"></canvas>
+<script>
+    const offscreenCanvas = new OffscreenCanvas(100, 100);
+    const gl = offscreenCanvas.getContext("webgl");
+
+    gl.clearColor(1, 0, 0, 1);
+    gl.clear(gl.COLOR_BUFFER_BIT);
+
+    const c1 = document.getElementById("c1");
+    const bitmapContext1 = c1.getContext("bitmaprenderer");
+    bitmapContext1.transferFromImageBitmap(offscreenCanvas.transferToImageBitmap());
+
+    gl.clearColor(0, 1, 0, 1);
+    gl.clear(gl.COLOR_BUFFER_BIT);
+
+    const c2 = document.getElementById("c2");
+    const bitmapContext2 = c2.getContext("bitmaprenderer");
+    bitmapContext2.transferFromImageBitmap(offscreenCanvas.transferToImageBitmap());
+
+    gl.clearColor(0, 0, 1, 1);
+    gl.clear(gl.COLOR_BUFFER_BIT);
+
+    const c3 = document.getElementById("c3");
+    const bitmapContext3 = c3.getContext("bitmaprenderer");
+    bitmapContext3.transferFromImageBitmap(offscreenCanvas.transferToImageBitmap());
+
+    const c4 = document.getElementById("c4");
+    const bitmapContext4 = c4.getContext("bitmaprenderer");
+    bitmapContext4.transferFromImageBitmap(offscreenCanvas.transferToImageBitmap());
+</script>
Property changes on: trunk/LayoutTests/http/wpt/offscreen-canvas/transferToImageBitmap-webgl.html
___________________________________________________________________

Added: svn:eol-style

+native \ No newline at end of property

Added: svn:keywords

+Date Revision \ No newline at end of property

Added: svn:mime-type

+text/html \ No newline at end of property

Deleted: trunk/LayoutTests/http/wpt/offscreen-canvas/transferToImageBitmap.html (225705 => 225706)


--- trunk/LayoutTests/http/wpt/offscreen-canvas/transferToImageBitmap.html	2017-12-08 22:45:21 UTC (rev 225705)
+++ trunk/LayoutTests/http/wpt/offscreen-canvas/transferToImageBitmap.html	2017-12-08 22:46:50 UTC (rev 225706)
@@ -1,17 +0,0 @@
-<!DOCTYPE html>
-<script src=""
-<script src=""
-<script src=""
-<link rel="help" href=""
-<script>
-
-test(function() {
-    let offscreenCanvas = new OffscreenCanvas(100, 100);
-    // let gl = offscreenCanvas.getContext("webgl");
-    // assert_equals(gl, null);
-    let imageBitmap = offscreenCanvas.transferToImageBitmap();
-    assert_equals(imageBitmap, null);
-}, "Test transferToImageBitmap.");
-
-</script>
-

Modified: trunk/Source/WebCore/ChangeLog (225705 => 225706)


--- trunk/Source/WebCore/ChangeLog	2017-12-08 22:45:21 UTC (rev 225705)
+++ trunk/Source/WebCore/ChangeLog	2017-12-08 22:46:50 UTC (rev 225706)
@@ -1,3 +1,26 @@
+2017-12-08  Dean Jackson  <d...@apple.com>
+
+        Implement transferToImageBitmap for WebGL offscreen canvas objects
+        https://bugs.webkit.org/show_bug.cgi?id=180603
+        <rdar://problem/34147143>
+
+        Reviewed by Sam Weinig.
+
+        Implement the basic version of creating an ImageBitmap from an
+        OffscreenCanvas that is using a WebGL context.
+
+        Tests: http/wpt/offscreen-canvas/transferToImageBitmap-empty.html
+               http/wpt/offscreen-canvas/transferToImageBitmap-webgl.html
+
+        * html/ImageBitmap.cpp:
+        (WebCore::ImageBitmap::create): Add a new constructor to be used by OffscreenCanvas.
+        Creates a blank ImageBitmap.
+        * html/ImageBitmap.h:
+
+        * html/OffscreenCanvas.cpp:
+        (WebCore::OffscreenCanvas::transferToImageBitmap): Create a new ImageBitmap
+        and paint the current canvas into it.
+
 2017-12-08  Youenn Fablet  <you...@apple.com>
 
         WebServiceWorkerProvider should use Cancellation error to notify DTL that it cannot handle a fetch

Modified: trunk/Source/WebCore/html/ImageBitmap.cpp (225705 => 225706)


--- trunk/Source/WebCore/html/ImageBitmap.cpp	2017-12-08 22:45:21 UTC (rev 225705)
+++ trunk/Source/WebCore/html/ImageBitmap.cpp	2017-12-08 22:46:50 UTC (rev 225706)
@@ -54,6 +54,13 @@
 static RenderingMode bufferRenderingMode = Unaccelerated;
 #endif
 
+Ref<ImageBitmap> ImageBitmap::create(IntSize size)
+{
+    auto imageBitmap = adoptRef(*new ImageBitmap);
+    imageBitmap->m_bitmapData = ImageBuffer::create(FloatSize(size.width(), size.height()), bufferRenderingMode);
+    return imageBitmap;
+}
+
 Ref<ImageBitmap> ImageBitmap::create()
 {
     return adoptRef(*new ImageBitmap);

Modified: trunk/Source/WebCore/html/ImageBitmap.h (225705 => 225706)


--- trunk/Source/WebCore/html/ImageBitmap.h	2017-12-08 22:45:21 UTC (rev 225705)
+++ trunk/Source/WebCore/html/ImageBitmap.h	2017-12-08 22:46:50 UTC (rev 225706)
@@ -40,6 +40,7 @@
 class ImageBuffer;
 class ImageData;
 class IntRect;
+class IntSize;
 class PendingImageBitmap;
 class ScriptExecutionContext;
 struct ImageBitmapOptions;
@@ -62,6 +63,8 @@
     static void createPromise(ScriptExecutionContext&, Source&&, ImageBitmapOptions&&, Promise&&);
     static void createPromise(ScriptExecutionContext&, Source&&, ImageBitmapOptions&&, int sx, int sy, int sw, int sh, Promise&&);
 
+    static Ref<ImageBitmap> create(IntSize);
+
     ~ImageBitmap();
 
     unsigned width() const;

Modified: trunk/Source/WebCore/html/OffscreenCanvas.cpp (225705 => 225706)


--- trunk/Source/WebCore/html/OffscreenCanvas.cpp	2017-12-08 22:45:21 UTC (rev 225705)
+++ trunk/Source/WebCore/html/OffscreenCanvas.cpp	2017-12-08 22:46:50 UTC (rev 225706)
@@ -98,7 +98,36 @@
 
 RefPtr<ImageBitmap> OffscreenCanvas::transferToImageBitmap()
 {
-    return nullptr;
+    if (!m_context)
+        return nullptr;
+
+    if (!is<WebGLRenderingContext>(*m_context))
+        return nullptr;
+
+    auto webGLContext = &downcast<WebGLRenderingContext>(*m_context);
+
+    // FIXME: We're supposed to create an ImageBitmap using the backing
+    // store from this canvas (or its context), but for now we'll just
+    // create a new bitmap and paint into it.
+
+    auto imageBitmap = ImageBitmap::create(m_size);
+    if (!imageBitmap->buffer())
+        return nullptr;
+
+    auto* gc3d = webGLContext->graphicsContext3D();
+    gc3d->paintRenderingResultsToCanvas(imageBitmap->buffer());
+
+    // FIXME: The transfer algorithm requires that the canvas effectively
+    // creates a new backing store. Since we're not doing that yet, we
+    // need to erase what's there.
+
+    GC3Dfloat clearColor[4];
+    gc3d->getFloatv(GraphicsContext3D::COLOR_CLEAR_VALUE, clearColor);
+    gc3d->clearColor(0, 0, 0, 0);
+    gc3d->clear(GraphicsContext3D::COLOR_BUFFER_BIT | GraphicsContext3D::DEPTH_BUFFER_BIT | GraphicsContext3D::STENCIL_BUFFER_BIT);
+    gc3d->clearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
+
+    return imageBitmap;
 }
 
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to