Skip to content
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 CanvasRenderingContext2d.fillText's "unimplemented" message #18020

Merged
merged 1 commit into from Aug 23, 2017

Conversation

@BrunoBernardino
Copy link
Contributor

BrunoBernardino commented Aug 9, 2017

Basic skeleton for implementing CanvasRenderingContext2d.fillText, only adding methods and parameters in the right place, and a basic test, with some println!().

This is only the beginning. It were my first couple of hours looking at Rust and Servo.

However, I have no clue how to get the text to render now (basically go from the println!() to something else).

It's also possible I messed something up with the DOMString.parse() but not entirely sure.

I'm doing this PR as a starting point to get help and learn more about this, or at least maybe save someone some time while implementing this, if no one's able to take the time and show me where/how.

Because it's still a work-in-progress, I'm leaving the boxes below unchecked (even though there are no errors).


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #11681 and #17963
  • There are tests for these changes

This change is Reviewable

@highfive
Copy link

highfive commented Aug 9, 2017

Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @metajack (or someone else) soon.

@highfive
Copy link

highfive commented Aug 9, 2017

Heads up! This PR modifies the following files:

  • @fitzgen: components/script/dom/webidls/CanvasRenderingContext2D.webidl, components/script/dom/canvasrenderingcontext2d.rs
  • @KiChjang: components/script/dom/webidls/CanvasRenderingContext2D.webidl, components/script/dom/canvasrenderingcontext2d.rs
@highfive
Copy link

highfive commented Aug 9, 2017

warning Warning warning

  • These commits modify script code, but no tests are modified. Please consider adding a test!
@emilio
Copy link
Member

emilio commented Aug 9, 2017

So first of all, this is awesome, thank you! :)

It's a bit unclear to me how easy it is to fill the missing pieces here. For the current 2d canvas APIs for now we use bindings to azure.

So, in theory, the only thing that we have to do is to expose the text drawing APIs azure has, and use them from here, with the current parameters (that is, font-size, etc).

That being said, I suspect this is not an easy task though. As far as I understand, all the text caches in azure aren't thread-safe, so it'd need a fair amount of work.

It'd be nice to try to use another back-end, but that's also a huge amount of work. If we want to implement this properly, I'd rather discuss with people what's the best long-term fix for this. I know @asajeffrey has been fiddling with Canvas2D for a while now, so maybe he has ideas. @glennw may also have an opinion on what's the best way to support text stuff in Canvas2D.

@asajeffrey
Copy link
Member

asajeffrey commented Aug 9, 2017

I've talked to @pcwalton about using a back-end based on webrender + pathfinder, so I'm not sure how much effort we should put in to updating the current azure back end.

@bors-servo
Copy link
Contributor

bors-servo commented Aug 15, 2017

The latest upstream changes (presumably #17891) made this pull request unmergeable. Please resolve the merge conflicts.

@MortimerGoro
Copy link
Contributor

MortimerGoro commented Aug 15, 2017

It may be interesting to provide a mock implementation for fillText or other missing Canvas2D methods before the long term webrender/pathfinder solution lands (any ETA on this? I'm assuming that it can take some time). Some WebGL demos that I try crash due to the missing methods and usually is to render a sprite not related to the game itself (e.g. the fps stats).

I'd prefer some "unimplemented method" warnings in the console instead of a crash in those cases. Also a lot of WebGL tests are exiting early because of the missing fillText() function, it would be good to enable them.

What do you think?

@jdm
Copy link
Member

jdm commented Aug 15, 2017

@MortimerGoro I am confused how a missing JS method could cause a crash/panic in Servo. Do you mean that the tests report a JS exception?

@MortimerGoro
Copy link
Contributor

MortimerGoro commented Aug 15, 2017

@jdm Yes, I meant that JavaScript/game execution "crashes" with a uncaught JS exception, not the servo process.

@jdm
Copy link
Member

jdm commented Aug 15, 2017

I would be open to adding stubs for missing canvas APIs that are hidden behind a preference.

@bors-servo
Copy link
Contributor

bors-servo commented Aug 17, 2017

The latest upstream changes (presumably #18118) made this pull request unmergeable. Please resolve the merge conflicts.

@BrunoBernardino
Copy link
Contributor Author

BrunoBernardino commented Aug 18, 2017

Can you elaborate on that @jdm ? Basically change my console.logs above to better console.warn and where would the preference be? (and how could I add it)?

@jdm
Copy link
Member

jdm commented Aug 18, 2017

Replace them with error!(...) instead; add a [Pref="dom.canvas-text.enabled"] to the CanvasRenderingContext2D.webidl file (example); add the new preference to resources/prefs.json.

@BrunoBernardino
Copy link
Contributor Author

BrunoBernardino commented Aug 19, 2017

Not sure if this is what you were thinking about, and it doesn't really fix any of the mentioned issues, though, because they would require an actual implementation.

I do understand, as per @MortimerGoro's comment that it's fine and this will somewhat improve things.

screen shot 2017-08-19 at 18 15 51

screen shot 2017-08-19 at 18 21 01

Please let me know if I'm missing any other sort of unit tests or something.

@@ -800,6 +800,13 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
receiver.recv().unwrap()
}

// https://html.spec.whatwg.org/multipage/#dom-context-2d-filltext
fn FillText(&self, text: DOMString, x: f64, y: f64, max_width: Option<f64>) {
let parsed_text: String = text.parse().unwrap();

This comment has been minimized.

Copy link
@emilio

emilio Aug 19, 2017

Member

This doesn't need parse(), you should be able to do into(), or if it doesn't exist, you may as well add it.

This comment has been minimized.

Copy link
@BrunoBernardino

BrunoBernardino Aug 19, 2017

Author Contributor

Thank you @emilio! I'll do that!

This comment has been minimized.

Copy link
@BrunoBernardino

BrunoBernardino Aug 19, 2017

Author Contributor

Oh. I'm afraid DOMString doesn't have into() and I'm not sure how to add it to components/script/dom/bindings/str.rs, can you help?

This comment has been minimized.

Copy link
@BrunoBernardino

BrunoBernardino Aug 19, 2017

Author Contributor

Apparently just .into() works. I was trying .into().unwrap(). Thanks!

@BrunoBernardino BrunoBernardino changed the title Implement CanvasRenderingContext2d.fillText - WIP Implement CanvasRenderingContext2d.fillText's "unimplemented" message Aug 21, 2017
@bors-servo
Copy link
Contributor

bors-servo commented Aug 22, 2017

The latest upstream changes (presumably #18093) made this pull request unmergeable. Please resolve the merge conflicts.

@@ -1,7 +1,7 @@
{
"dom.bluetooth.enabled": false,
"dom.bluetooth.testing.enabled": false,
"dom.canvas-text.enabled": false,
"dom.canvas-text.enabled": true,

This comment has been minimized.

Copy link
@jdm

jdm Aug 22, 2017

Member

Please revert this change. We do not want this to be exposed by default, since it is incomplete. Anybody that needs to run tests with this API present can enable it explicitly.

This comment has been minimized.

Copy link
@BrunoBernardino

BrunoBernardino Aug 23, 2017

Author Contributor

Sounds good! I thought the goal here was to prevent the JS Exception by default.

@BrunoBernardino
Copy link
Contributor Author

BrunoBernardino commented Aug 23, 2017

Alright, I think that's it!

@jdm
Copy link
Member

jdm commented Aug 23, 2017

./resources/prefs.json:None: Unordered key (found dom.compositionevent.enabled before dom.canvas-text.enabled)

Otherwise, these changes look good. Could you squash all of the commits into one?

@jdm jdm added the S-fails-tidy label Aug 23, 2017
@BrunoBernardino
Copy link
Contributor Author

BrunoBernardino commented Aug 23, 2017

Will do.

Bruno Bernardino
@jdm
Copy link
Member

jdm commented Aug 23, 2017

@bors-servo: r+
Thanks!

@bors-servo
Copy link
Contributor

bors-servo commented Aug 23, 2017

📌 Commit 2af8284 has been approved by jdm

@bors-servo
Copy link
Contributor

bors-servo commented Aug 23, 2017

Testing commit 2af8284 with merge a9f9207e4049979351313e6939f38e1eb7d07e8a...

@bors-servo
Copy link
Contributor

bors-servo commented Aug 23, 2017

💔 Test failed - linux-rel-wpt

@jdm
Copy link
Member

jdm commented Aug 23, 2017

@bors-servo
Copy link
Contributor

bors-servo commented Aug 23, 2017

Testing commit 2af8284 with merge acd08c7...

bors-servo added a commit that referenced this pull request Aug 23, 2017
Implement CanvasRenderingContext2d.fillText's "unimplemented" message

Basic skeleton for implementing CanvasRenderingContext2d.fillText,  only adding methods and parameters in the right place, and a basic test, with some `println!()`.

<!-- Please describe your changes on the following line: -->

This is only the beginning. It were my first couple of hours looking at Rust and Servo.

However, I have _no clue_ how to get the text to render now (basically go from the `println!()` to something else).

It's also possible I messed something up with the `DOMString.parse()` but not entirely sure.

I'm doing this PR as a starting point to get help and learn more about this, _or_ at least maybe save someone some time while implementing this, if no one's able to take the time and show me where/how.

Because it's still a work-in-progress, I'm leaving the boxes below unchecked (even though there are no errors).

---
<!-- 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 #11681 and #17963

<!-- Either: -->
- [x] There are tests for these changes

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- 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/18020)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Aug 23, 2017

@bors-servo bors-servo merged commit 2af8284 into servo:master Aug 23, 2017
3 checks passed
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
@BrunoBernardino BrunoBernardino deleted the BrunoBernardino:feature-canvas-filltext branch Aug 24, 2017
@atouchet atouchet mentioned this pull request Aug 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

8 participants
You can’t perform that action at this time.