New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement WebGLRenderingContextBase::readPixels(). #10668
Merged
+903
−40
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.
| @@ -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() { | ||
dzbarsky
Author
Member
|
||
| 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 | ||
This file was deleted.
Oops, something went wrong.
| @@ -1,5 +1,6 @@ | ||
| [readPixelsBadArgs.html] | ||
| type: testharness | ||
| expected: CRASH | ||
| [WebGL test #0: testReadPixels] | ||
| 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 |
| @@ -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 | ||
|
|
Oops, something went wrong.
ProTip!
Use n and p to navigate between commits in a pull request.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
nit: this could use copy_from_slice