Skip to content
Permalink
Browse files

Implement ReadPixels

  • Loading branch information
dzbarsky committed May 13, 2016
1 parent 03465ad commit 2f416baa11aed23049d98e37b1693a63cb7103bd
Showing with 903 additions and 40 deletions.
  1. +34 −8 components/script/dom/webglrenderingcontext.rs
  2. +2 −0 components/script/dom/webidls/WebGLRenderingContext.webidl
  3. +6 −0 tests/wpt/metadata/webgl/conformance-1.0.3/conformance/attribs/gl-disabled-vertex-attrib.html.ini
  4. +3 −0 tests/wpt/metadata/webgl/conformance-1.0.3/conformance/attribs/gl-vertex-attrib-zero-issues.html.ini
  5. +3 −0 ...etadata/webgl/conformance-1.0.3/conformance/buffers/element-array-buffer-delete-recreate.html.ini
  6. +3 −0 tests/wpt/metadata/webgl/conformance-1.0.3/conformance/limits/gl-min-uniforms.html.ini
  7. +0 −5 tests/wpt/metadata/webgl/conformance-1.0.3/conformance/more/functions/readPixels.html.ini
  8. +1 −0 tests/wpt/metadata/webgl/conformance-1.0.3/conformance/more/functions/readPixelsBadArgs.html.ini
  9. +6 −0 ...ata/webgl/conformance-1.0.3/conformance/programs/gl-bind-attrib-location-long-names-test.html.ini
  10. +6 −0 ...s/wpt/metadata/webgl/conformance-1.0.3/conformance/programs/gl-bind-attrib-location-test.html.ini
  11. +1 −0 tests/wpt/metadata/webgl/conformance-1.0.3/conformance/reading/read-pixels-pack-alignment.html.ini
  12. +1 −1 tests/wpt/metadata/webgl/conformance-1.0.3/conformance/reading/read-pixels-test.html.ini
  13. +3 −0 ...t/metadata/webgl/conformance-1.0.3/conformance/renderbuffers/renderbuffer-initialization.html.ini
  14. +21 −0 tests/wpt/metadata/webgl/conformance-1.0.3/conformance/rendering/culling.html.ini
  15. +57 −0 tests/wpt/metadata/webgl/conformance-1.0.3/conformance/rendering/gl-scissor-test.html.ini
  16. +45 −0 tests/wpt/metadata/webgl/conformance-1.0.3/conformance/rendering/gl-viewport-test.html.ini
  17. +3 −0 tests/wpt/metadata/webgl/conformance-1.0.3/conformance/rendering/point-no-attributes.html.ini
  18. +27 −0 tests/wpt/metadata/webgl/conformance-1.0.3/conformance/rendering/polygon-offset.html.ini
  19. +3 −0 tests/wpt/metadata/webgl/conformance-1.0.3/conformance/rendering/simple.html.ini
  20. +0 −1 ...pt/metadata/webgl/conformance-1.0.3/conformance/state/state-uneffected-after-compositing.html.ini
  21. +6 −0 tests/wpt/metadata/webgl/conformance-1.0.3/conformance/textures/default-texture.html.ini
  22. +9 −0 ...conformance-1.0.3/conformance/textures/tex-image-and-sub-image-2d-with-array-buffer-view.html.ini
  23. +3 −1 ...bgl/conformance-1.0.3/conformance/textures/tex-image-and-sub-image-2d-with-canvas-rgb565.html.ini
  24. +3 −1 ...l/conformance-1.0.3/conformance/textures/tex-image-and-sub-image-2d-with-canvas-rgba4444.html.ini
  25. +6 −1 ...l/conformance-1.0.3/conformance/textures/tex-image-and-sub-image-2d-with-canvas-rgba5551.html.ini
  26. +3 −1 ...data/webgl/conformance-1.0.3/conformance/textures/tex-image-and-sub-image-2d-with-canvas.html.ini
  27. +3 −1 ...conformance-1.0.3/conformance/textures/tex-image-and-sub-image-2d-with-image-data-rgb565.html.ini
  28. +3 −3 ...nformance-1.0.3/conformance/textures/tex-image-and-sub-image-2d-with-image-data-rgba4444.html.ini
  29. +6 −1 ...nformance-1.0.3/conformance/textures/tex-image-and-sub-image-2d-with-image-data-rgba5551.html.ini
  30. +3 −1 .../webgl/conformance-1.0.3/conformance/textures/tex-image-and-sub-image-2d-with-image-data.html.ini
  31. +3 −1 ...ebgl/conformance-1.0.3/conformance/textures/tex-image-and-sub-image-2d-with-image-rgb565.html.ini
  32. +3 −1 ...gl/conformance-1.0.3/conformance/textures/tex-image-and-sub-image-2d-with-image-rgba4444.html.ini
  33. +6 −1 ...gl/conformance-1.0.3/conformance/textures/tex-image-and-sub-image-2d-with-image-rgba5551.html.ini
  34. +3 −1 ...adata/webgl/conformance-1.0.3/conformance/textures/tex-image-and-sub-image-2d-with-image.html.ini
  35. +3 −1 ...a/webgl/conformance-1.0.3/conformance/textures/tex-image-and-sub-image-2d-with-svg-image.html.ini
  36. +3 −1 ...nformance-1.0.3/conformance/textures/tex-image-and-sub-image-2d-with-webgl-canvas-rgb565.html.ini
  37. +3 −1 ...ormance-1.0.3/conformance/textures/tex-image-and-sub-image-2d-with-webgl-canvas-rgba4444.html.ini
  38. +6 −1 ...ormance-1.0.3/conformance/textures/tex-image-and-sub-image-2d-with-webgl-canvas-rgba5551.html.ini
  39. +3 −1 ...ebgl/conformance-1.0.3/conformance/textures/tex-image-and-sub-image-2d-with-webgl-canvas.html.ini
  40. +6 −0 tests/wpt/metadata/webgl/conformance-1.0.3/conformance/textures/tex-image-webgl.html.ini
  41. +0 −3 ...wpt/metadata/webgl/conformance-1.0.3/conformance/textures/tex-image-with-format-and-type.html.ini
  42. +3 −0 tests/wpt/metadata/webgl/conformance-1.0.3/conformance/textures/texture-hd-dpi.html.ini
  43. +12 −0 tests/wpt/metadata/webgl/conformance-1.0.3/conformance/textures/texture-npot.html.ini
  44. +3 −1 tests/wpt/metadata/webgl/conformance-1.0.3/conformance/textures/texture-size.html.ini
  45. +0 −2 ...data/webgl/conformance-1.0.3/conformance/textures/texture-transparent-pixels-initialized.html.ini
  46. +576 −0 tests/wpt/metadata/webgl/conformance-1.0.3/conformance/uniforms/uniform-values-per-program.html.ini
@@ -7,7 +7,7 @@ use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderi
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::{WebGLRenderingContextMethods};
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::{self, WebGLContextAttributes};
use dom::bindings::codegen::UnionTypes::ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement;
use dom::bindings::conversions::{ToJSValConvertible, array_buffer_view_data_checked};
use dom::bindings::conversions::{ToJSValConvertible, array_buffer_view_data, array_buffer_view_data_checked};
use dom::bindings::conversions::{array_buffer_view_to_vec_checked, array_buffer_view_to_vec};
use dom::bindings::global::GlobalRef;
use dom::bindings::inheritance::Castable;
@@ -28,7 +28,7 @@ use dom::webgltexture::{TexParameterValue, WebGLTexture};
use dom::webgluniformlocation::WebGLUniformLocation;
use euclid::size::Size2D;
use ipc_channel::ipc::{self, IpcSender};
use js::jsapi::{JSContext, JSObject, RootedValue};
use js::jsapi::{JSContext, JS_GetArrayBufferViewType, JSObject, RootedValue, Type};
use js::jsval::{BooleanValue, DoubleValue, Int32Value, JSVal, NullValue, UndefinedValue};
use net_traits::image::base::PixelFormat;
use net_traits::image_cache_thread::ImageResponse;
@@ -471,8 +471,8 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
WebGLParameter::Int(val) => Int32Value(val),
WebGLParameter::Bool(_) => panic!("Buffer parameter should not be bool"),
WebGLParameter::Float(_) => panic!("Buffer parameter should not be float"),
WebGLParameter::String(_) => panic!("Buffer parameter should not be string"),
WebGLParameter::FloatArray(_) => panic!("Buffer parameter should not be float array"),
WebGLParameter::String(_) => panic!("Buffer parameter should not be string"),
WebGLParameter::Invalid => NullValue(),
}
}
@@ -1238,6 +1238,36 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
.unwrap()
}

#[allow(unsafe_code)]
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.12
fn ReadPixels(&self, _cx: *mut JSContext, x: i32, y: i32, width: i32, height: i32,
format: u32, pixel_type: u32, pixels: *mut JSObject) {
let mut data = match unsafe { array_buffer_view_data::<u8>(pixels) } {
Some(data) => data,
None => return self.webgl_error(InvalidValue),
};

match unsafe { JS_GetArrayBufferViewType(pixels) } {
Type::Uint8 => (),
_ => return self.webgl_error(InvalidOperation)
}

let (sender, receiver) = ipc::channel().unwrap();
self.ipc_renderer
.send(CanvasMsg::WebGL(WebGLCommand::ReadPixels(x, y, width, height, format, pixel_type, sender)))
.unwrap();

let result = receiver.recv().unwrap();

if result.len() > data.len() {
return self.webgl_error(InvalidOperation)
}

for i in 0..result.len() {
data[i] = result[i]
}
}

// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.4
fn Scissor(&self, x: i32, y: i32, width: i32, height: i32) {
self.ipc_renderer
@@ -1337,11 +1367,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {

// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
fn GetShaderSource(&self, shader: Option<&WebGLShader>) -> Option<DOMString> {
if let Some(shader) = shader {
shader.source()
} else {
None
}
shader.and_then(|s| s.source())
}

// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
@@ -614,6 +614,8 @@ interface WebGLRenderingContextBase

//void readPixels(GLint x, GLint y, GLsizei width, GLsizei height,
// GLenum format, GLenum type, ArrayBufferView? pixels);
void readPixels(GLint x, GLint y, GLsizei width, GLsizei height,
GLenum format, GLenum type, object? pixels);

//void renderbufferStorage(GLenum target, GLenum internalformat,
// GLsizei width, GLsizei height);
@@ -3,3 +3,9 @@
[WebGL test #0: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
expected: FAIL

[WebGL test #15: at (0, 0) expected: 0,255,0,255 was 255,255,255,255]
expected: FAIL

[WebGL test #16: getError expected: NO_ERROR. Was INVALID_ENUM : should be no errors]
expected: FAIL

@@ -3,3 +3,6 @@
[WebGL test #3: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
expected: FAIL

[WebGL test #4: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
expected: FAIL

@@ -6,3 +6,6 @@
[WebGL test #1: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
expected: FAIL

[WebGL test #1: at (0, 0) expected: 0,255,0,255 was 0,0,0,0]
expected: FAIL

@@ -6,3 +6,6 @@
[WebGL test #0: getError expected: NO_ERROR. Was INVALID_OPERATION : Should be no errors from setup.]
expected: FAIL

[WebGL test #4: at (0, 0) expected: 32,64,127,255 was 255,128,64,255]
expected: FAIL

This file was deleted.

@@ -1,5 +1,6 @@
[readPixelsBadArgs.html]
type: testharness
expected: CRASH
[WebGL test #0: testReadPixels]
expected: FAIL

@@ -3,3 +3,9 @@
[WebGL test #4: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
expected: FAIL

[WebGL test #4: at (0, 0) expected: 0,255,0,255 was 255,255,255,255]
expected: FAIL

[WebGL test #5: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
expected: FAIL

@@ -3,3 +3,9 @@
[WebGL test #6: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
expected: FAIL

[WebGL test #7: at (20, 15) expected: 0,255,0,255 was 0,0,0,255]
expected: FAIL

[WebGL test #9: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
expected: FAIL

@@ -1,5 +1,6 @@
[read-pixels-pack-alignment.html]
type: testharness
expected: CRASH
[WebGL test #3: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
expected: FAIL

@@ -1,3 +1,3 @@
[read-pixels-test.html]
type: testharness
expected: TIMEOUT
expected: CRASH
@@ -3,3 +3,6 @@
[WebGL test #0: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
expected: FAIL

[WebGL test #1: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
expected: FAIL

@@ -3,3 +3,24 @@
[WebGL test #0: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
expected: FAIL

[WebGL test #0: at (0, 0) expected: 0,255,0,255 was 0,0,0,0]
expected: FAIL

[WebGL test #1: at (0, 0) expected: 0,255,0,255 was 0,0,0,0]
expected: FAIL

[WebGL test #2: at (0, 0) expected: 0,255,0,255 was 0,0,0,0]
expected: FAIL

[WebGL test #4: at (0, 0) expected: 0,255,0,255 was 0,0,0,0]
expected: FAIL

[WebGL test #7: at (0, 0) expected: 0,255,0,255 was 0,0,0,0]
expected: FAIL

[WebGL test #9: at (0, 0) expected: 0,255,0,255 was 0,0,0,0]
expected: FAIL

[WebGL test #10: at (0, 0) expected: 0,255,0,255 was 0,0,0,0]
expected: FAIL

@@ -3,3 +3,60 @@
[WebGL test #2: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
expected: FAIL

[WebGL test #50: at (0, 0) expected: 0,255,0,255 was 0,0,0,0]
expected: FAIL

[WebGL test #53: at (1, 1) expected: 0,255,0,255 was 0,0,0,0]
expected: FAIL

[WebGL test #56: at (2, 2) expected: 0,255,0,255 was 0,0,0,0]
expected: FAIL

[WebGL test #59: at (3, 3) expected: 0,255,0,255 was 0,0,0,0]
expected: FAIL

[WebGL test #62: at (4, 4) expected: 0,255,0,255 was 0,0,0,0]
expected: FAIL

[WebGL test #65: at (5, 5) expected: 0,255,0,255 was 0,0,0,0]
expected: FAIL

[WebGL test #68: at (6, 6) expected: 0,255,0,255 was 0,0,0,0]
expected: FAIL

[WebGL test #71: at (7, 7) expected: 0,255,0,255 was 0,0,0,0]
expected: FAIL

[WebGL test #74: at (8, 8) expected: 0,255,0,255 was 0,0,0,0]
expected: FAIL

[WebGL test #77: at (9, 9) expected: 0,255,0,255 was 0,0,0,0]
expected: FAIL

[WebGL test #80: at (10, 10) expected: 0,255,0,255 was 0,0,0,0]
expected: FAIL

[WebGL test #83: at (11, 11) expected: 0,255,0,255 was 0,0,0,0]
expected: FAIL

[WebGL test #86: at (12, 12) expected: 0,255,0,255 was 0,0,0,0]
expected: FAIL

[WebGL test #89: at (13, 13) expected: 0,255,0,255 was 0,0,0,0]
expected: FAIL

[WebGL test #92: at (14, 14) expected: 0,255,0,255 was 0,0,0,0]
expected: FAIL

[WebGL test #95: at (15, 15) expected: 0,255,0,255 was 0,0,0,0]
expected: FAIL

[WebGL test #97: getError expected: NO_ERROR. Was INVALID_ENUM : there should be no errors]
expected: FAIL

[WebGL test #98: Unable to fetch WebGL rendering context for Canvas]
expected: FAIL

[WebGL test #99: context does not exist]
expected: FAIL

@@ -3,3 +3,48 @@
[WebGL test #1: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
expected: FAIL

[WebGL test #1: at (16, 32) expected: 0,0,255,255 was 0,0,0,0]
expected: FAIL

[WebGL test #6: at (8, 8) expected: 0,0,255,255 was 0,0,0,0]
expected: FAIL

[WebGL test #11: at (4, 16) expected: 0,0,255,255 was 0,0,0,0]
expected: FAIL

[WebGL test #16: at (32, 64) expected: 0,0,255,255 was 0,0,0,0]
expected: FAIL

[WebGL test #41: at (32, 96) expected: 0,0,255,255 was 0,0,0,0]
expected: FAIL

[WebGL test #46: at (24, 72) expected: 0,0,255,255 was 0,0,0,0]
expected: FAIL

[WebGL test #51: at (36, 48) expected: 0,0,255,255 was 0,0,0,0]
expected: FAIL

[WebGL test #56: at (48, 96) expected: 0,0,255,255 was 0,0,0,0]
expected: FAIL

[WebGL test #61: at (0, 32) expected: 0,0,255,255 was 0,0,0,0]
expected: FAIL

[WebGL test #66: at (8, 0) expected: 0,0,255,255 was 0,0,0,0]
expected: FAIL

[WebGL test #71: at (0, 16) expected: 0,0,255,255 was 0,0,0,0]
expected: FAIL

[WebGL test #76: at (32, 0) expected: 0,0,255,255 was 0,0,0,0]
expected: FAIL

[WebGL test #81: getError expected: NO_ERROR. Was INVALID_ENUM : there should be no errors]
expected: FAIL

[WebGL test #82: Unable to fetch WebGL rendering context for Canvas]
expected: FAIL

[WebGL test #83: context does not exist]
expected: FAIL

@@ -3,3 +3,6 @@
[WebGL test #1: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
expected: FAIL

[WebGL test #1: at (0, 0) expected: 0,255,0,255 was 0,0,0,0]
expected: FAIL

@@ -3,3 +3,30 @@
[WebGL test #0: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
expected: FAIL

[WebGL test #0: at (0, 0) expected: 0,255,0,255 was 0,0,0,0]
expected: FAIL

[WebGL test #1: at (0, 0) expected: 0,255,0,255 was 0,0,0,0]
expected: FAIL

[WebGL test #2: at (0, 0) expected: 0,255,0,255 was 0,0,0,0]
expected: FAIL

[WebGL test #3: at (0, 0) expected: 0,255,0,255 was 0,0,0,0]
expected: FAIL

[WebGL test #4: at (0, 0) expected: 0,255,0,255 was 0,0,0,0]
expected: FAIL

[WebGL test #5: at (0, 0) expected: 0,255,0,255 was 0,0,0,0]
expected: FAIL

[WebGL test #6: at (0, 0) expected: 0,255,0,255 was 0,0,0,0]
expected: FAIL

[WebGL test #7: at (0, 0) expected: 0,255,0,255 was 0,0,0,0]
expected: FAIL

[WebGL test #8: at (0, 0) expected: 0,255,0,255 was 0,0,0,0]
expected: FAIL

@@ -3,3 +3,6 @@
[WebGL test #0: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
expected: FAIL

[WebGL test #2: getError expected: NO_ERROR. Was INVALID_ENUM : there should be no errors]
expected: FAIL

@@ -1,6 +1,5 @@
[state-uneffected-after-compositing.html]
type: testharness
expected: TIMEOUT
[WebGL test #0: Unable to fetch WebGL rendering context for Canvas]
expected: FAIL

@@ -3,3 +3,9 @@
[WebGL test #0: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
expected: FAIL

[WebGL test #0: at (0, 0) expected: 0,0,0,255 was 0,0,0,0]
expected: FAIL

[WebGL test #0: at (0, 0) expected: 0,0,0,255 was 64,255,191,128]
expected: FAIL

@@ -9,3 +9,12 @@
[WebGL test #1: successfullyParsed should be true. Was false.]
expected: FAIL

[WebGL test #0: at (0, 0) expected: 0,255,0,255 was 255,0,0,255]
expected: FAIL

[WebGL test #1: at (0, 8) expected: 255,0,0,255 was 0,255,0,255]
expected: FAIL

[WebGL test #2: successfullyParsed should be true. Was false.]
expected: FAIL

@@ -1,3 +1,5 @@
[tex-image-and-sub-image-2d-with-canvas-rgb565.html]
type: testharness
expected: TIMEOUT
[WebGL test #0: at (0, 16) expected: 255,0,0 was 255,227,0]
expected: FAIL

@@ -1,3 +1,5 @@
[tex-image-and-sub-image-2d-with-canvas-rgba4444.html]
type: testharness
expected: TIMEOUT
[WebGL test #0: at (0, 16) expected: 255,0,0 was 255,255,0]
expected: FAIL

0 comments on commit 2f416ba

Please sign in to comment.
You can’t perform that action at this time.