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

webgl: premultiplication, y flipping, and format conversion #15122

Merged
merged 4 commits into from Feb 3, 2017

Conversation

Projects
None yet
5 participants
@anholt
Contributor

anholt commented Jan 20, 2017

This series implements a bunch of the texture unpack path features for WebGL. There are known issues with big-endian systems noted in the comments, but I don't know of a clean way to cast from Vec<u16> to Vec<u8> (which, if we had one, would make this code much cleaner anyway).


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #__ (github issue number if applicable).
  • There are tests for these changes OR
  • These changes do not require tests because _____

This change is Reviewable

@highfive

This comment has been minimized.

Show comment
Hide comment
@highfive

highfive Jan 20, 2017

Heads up! This PR modifies the following files:

  • @KiChjang: components/script/dom/webglrenderingcontext.rs
  • @fitzgen: components/script/dom/webglrenderingcontext.rs
  • @emilio: components/script/dom/webglrenderingcontext.rs

highfive commented Jan 20, 2017

Heads up! This PR modifies the following files:

  • @KiChjang: components/script/dom/webglrenderingcontext.rs
  • @fitzgen: components/script/dom/webglrenderingcontext.rs
  • @emilio: components/script/dom/webglrenderingcontext.rs
@emilio

emilio approved these changes Jan 20, 2017

Looks great! Only minor comments, thanks for doing this!

Show outdated Hide outdated components/script/dom/webglrenderingcontext.rs Outdated
Show outdated Hide outdated components/script/dom/webglrenderingcontext.rs Outdated
Show outdated Hide outdated components/script/dom/webglrenderingcontext.rs Outdated
Show outdated Hide outdated components/script/dom/webglrenderingcontext.rs Outdated
Show outdated Hide outdated components/script/dom/webglrenderingcontext.rs Outdated
Show outdated Hide outdated components/script/dom/webglrenderingcontext.rs Outdated
Show outdated Hide outdated ...ance/textures/tex-image-and-sub-image-2d-with-array-buffer-view.html.ini Outdated
Show outdated Hide outdated components/script/dom/webglrenderingcontext.rs Outdated
Show outdated Hide outdated components/script/dom/webglrenderingcontext.rs Outdated
Show outdated Hide outdated components/script/dom/webglrenderingcontext.rs Outdated
@emilio

This comment has been minimized.

Show comment
Hide comment
@emilio

emilio Jan 20, 2017

Member

Regarding casting Vecs, you probably can do something using slice::from_raw_parts{_mut}, but I think we should only introduce unsafe code if totally necessary. Probably the conversion is not going to be more costly than the IPC message, but if we want to optimize it we could use that I think.

Member

emilio commented Jan 20, 2017

Regarding casting Vecs, you probably can do something using slice::from_raw_parts{_mut}, but I think we should only introduce unsafe code if totally necessary. Probably the conversion is not going to be more costly than the IPC message, but if we want to optimize it we could use that I think.

@Ms2ger

This comment has been minimized.

Show comment
Hide comment
@Ms2ger
Contributor

Ms2ger commented Jan 20, 2017

@emilio

emilio approved these changes Jan 21, 2017

r=me, thanks Eric :)

@emilio

This comment has been minimized.

Show comment
Hide comment
@emilio
Member

emilio commented Jan 21, 2017

@bors-servo

This comment has been minimized.

Show comment
Hide comment
@bors-servo

bors-servo Jan 21, 2017

Contributor

📌 Commit 41a4f63 has been approved by emilio

Contributor

bors-servo commented Jan 21, 2017

📌 Commit 41a4f63 has been approved by emilio

@bors-servo

This comment has been minimized.

Show comment
Hide comment
@bors-servo

bors-servo Jan 21, 2017

Contributor

⌛️ Testing commit 41a4f63 with merge 82e854a...

Contributor

bors-servo commented Jan 21, 2017

⌛️ Testing commit 41a4f63 with merge 82e854a...

bors-servo added a commit that referenced this pull request Jan 21, 2017

Auto merge of #15122 - anholt:webgl-premultiply, r=emilio
webgl: premultiplication, y flipping, and format conversion

<!-- Please describe your changes on the following line: -->
This series implements a bunch of the texture unpack path features for WebGL.  There are known issues with big-endian systems noted in the comments, but I don't know of a clean way to cast from `Vec<u16>` to `Vec<u8>` (which, if we had one, would make this code much cleaner anyway).

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [x] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15122)
<!-- Reviewable:end -->
@bors-servo

This comment has been minimized.

Show comment
Hide comment
@bors-servo

bors-servo Jan 21, 2017

Contributor

💔 Test failed - mac-rel-wpt2

Contributor

bors-servo commented Jan 21, 2017

💔 Test failed - mac-rel-wpt2

@anholt

This comment has been minimized.

Show comment
Hide comment
@anholt

anholt Jan 23, 2017

Contributor

OK, I think I know the cause of that Mac failure: not having unpack alignment support.

Contributor

anholt commented Jan 23, 2017

OK, I think I know the cause of that Mac failure: not having unpack alignment support.

@emilio

This comment has been minimized.

Show comment
Hide comment
@emilio

emilio Jan 28, 2017

Member

We could mark those as failing on mac if you want, I think this is worth landing

Member

emilio commented Jan 28, 2017

We could mark those as failing on mac if you want, I think this is worth landing

anholt added some commits Jan 15, 2017

webgl: Implement FLIP_Y_AXIS unpacking flag for TexImage, TexSubImage.
This fixes a couple of tests doing RGBA/ubyte image uploads with
flipping.  Other tests with flipping get their expectations changed,
because some other feature is missing (premultiplication or
ImageData/canvas format conversion)
webgl: Add support for premultiplying alpha.
Now the affected testcase only fails due to unpack alignment.
webgl: Convert non-raw TexImage sources to the requested format.
The code was returning RGBA8 data from the non-raw sources (HTML
canvas elements, JS ImageData, etc.), but we then validated and passed
that rgba8 data as if it was whatever format/datatype was specified in
TexImage2D/TexSubImage2D, so the pixels would come out as garbage.

It would seem like we could just rewrite the passed in format/datatype
for the TexImage call to be RGBA/UNSIGNED_BYTE, but that would leave
incorrect levels of precision if the internalformat didn't match the
format/datatype (and older desktop implementations often ignore the
internalformat in choosing their internal format, anyway).
@anholt

This comment has been minimized.

Show comment
Hide comment
@anholt

anholt Jan 28, 2017

Contributor

I'm actually testing the unpack fix now.

Contributor

anholt commented Jan 28, 2017

I'm actually testing the unpack fix now.

webgl: Fix handling of UNPACK_ALIGNMENT.
We were setting it to whatever value from {1,2,4,8} the user requested
and otherwise ignoring it.  There were two problems there:

1) Validation ignored it, so GL could read outside of the user's array
   in TexImage() or TexSubImage() if the aligment was greater than
   cpp.

2) TexImage()/TexSubImage() from image/canvas sources wasn't packing
   its data according to the unpack alignment.

To fix this, start tracking the user-requested alignment in the DOM
side of the context.  Set the GL's alignment to 1 for image/canvas
sources or the user's value for array sources, and pass the user's
alignment in to validation so that it can figure out the correct size
of image that the GL will ready.
@emilio

As a uber-nit, s/ready.$/read./ in the last commit message, but I don't really want to block landing this on it.

let expected_byte_length = width * height * element_size * components / components_per_element;
return Ok(expected_byte_length);
if height == 0 {
return Ok(0);

This comment has been minimized.

@emilio

emilio Feb 3, 2017

Member

nit: Since you early-return, there's no need for the else branch, but not a big deal.

@emilio

emilio Feb 3, 2017

Member

nit: Since you early-return, there's no need for the else branch, but not a big deal.

@emilio

This comment has been minimized.

Show comment
Hide comment
@emilio

emilio Feb 3, 2017

Member

@bors-servo r+

Thanks!

Member

emilio commented Feb 3, 2017

@bors-servo r+

Thanks!

@bors-servo

This comment has been minimized.

Show comment
Hide comment
@bors-servo

bors-servo Feb 3, 2017

Contributor

📌 Commit fcef92f has been approved by emilio

Contributor

bors-servo commented Feb 3, 2017

📌 Commit fcef92f has been approved by emilio

@bors-servo

This comment has been minimized.

Show comment
Hide comment
@bors-servo

bors-servo Feb 3, 2017

Contributor

⌛️ Testing commit fcef92f with merge 536c0d7...

Contributor

bors-servo commented Feb 3, 2017

⌛️ Testing commit fcef92f with merge 536c0d7...

bors-servo added a commit that referenced this pull request Feb 3, 2017

Auto merge of #15122 - anholt:webgl-premultiply, r=emilio
webgl: premultiplication, y flipping, and format conversion

<!-- Please describe your changes on the following line: -->
This series implements a bunch of the texture unpack path features for WebGL.  There are known issues with big-endian systems noted in the comments, but I don't know of a clean way to cast from `Vec<u16>` to `Vec<u8>` (which, if we had one, would make this code much cleaner anyway).

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [x] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15122)
<!-- Reviewable:end -->
@bors-servo

This comment has been minimized.

Show comment
Hide comment
@bors-servo
Contributor

bors-servo commented Feb 3, 2017

@bors-servo bors-servo merged commit fcef92f into servo:master Feb 3, 2017

3 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details

@bors-servo bors-servo referenced this pull request Feb 3, 2017

Merged

Rewrite WebGLRenderingContext to use typed array APIs #15352

4 of 4 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment