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

Hit testing is offset in GL aquarium #21168

Closed
jdm opened this issue Jul 12, 2018 · 8 comments
Closed

Hit testing is offset in GL aquarium #21168

jdm opened this issue Jul 12, 2018 · 8 comments
Labels

Comments

@jdm
Copy link
Member

@jdm jdm commented Jul 12, 2018

https://webglsamples.org/aquarium/aquarium.html

When I try to click the numbers, there is a clear vertical offset (like 100px or more) that I need to compensate for to click the numbers I intend.

@jdm jdm added the A-input label Jul 12, 2018
@cbrewster
Copy link
Member

@cbrewster cbrewster commented Jul 12, 2018

I think hit testing is broken in general, I see this behavior on every site. I think it may be related to hidpi screens; servo thinks the mouse is in the center of the window when its actually on the far right.

@gw3583
Copy link
Contributor

@gw3583 gw3583 commented Jul 12, 2018

I can also reproduce this on Linux - I'll investigate today.

@gw3583
Copy link
Contributor

@gw3583 gw3583 commented Jul 12, 2018

It looks like something has changed to do with how / where DPI scaling is applied, either in Servo or in Glutin / Winit. Specifically, in the hit test method in compositor.rs, we receive a DevicePoint but debug logs suggest that it is actually not a true device point, but has the DPI scale un-applied.

As a quick hack, I applied the following patch:

diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs
index 0e17b41baf..702a54d12c 100644
--- a/components/compositing/compositor.rs
+++ b/components/compositing/compositor.rs
@@ -678,10 +678,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
     }
 
     fn hit_test_at_point(&self, point: DevicePoint) -> HitTestResult {
-        let dppx = self.page_zoom * self.hidpi_factor();
-        let scaled_point = (point / dppx).to_untyped();
-
-        let world_cursor = webrender_api::WorldPoint::from_untyped(&scaled_point);
+        let world_cursor = webrender_api::WorldPoint::new(point.x, point.y);
         self.webrender_api.hit_test(
             self.webrender_document,
             None,

This appears to fix hit testing on my Linux machine in the tests I've tried thus far.

@jdm or @cbrewster Would you be able to check if this also fixes it on a Mac?

If it does, the proper fix will involve working out what changed and either restoring the previous behavior (so we are getting a true DevicePoint in this method) or modifying the method and signatures to reflect that it is no longer a DevicePoint. We'll still need to handle other scale factors, such as page zoom, which I've ignored in the patch above for now.

@jdm
Copy link
Member Author

@jdm jdm commented Jul 13, 2018

@gw3583 Yes, that patch fixes the issue for me as well.

@atouchet
Copy link
Contributor

@atouchet atouchet commented Jul 13, 2018

This might be due to the winit/glutin update in #21087. There were some HiDPI changes there: https://github.com/tomaka/winit/blob/master/CHANGELOG.md

@gw3583
Copy link
Contributor

@gw3583 gw3583 commented Jul 16, 2018

@jdm OK, I confirmed the issue is from #21087. It looks like winit now returns events in logical units, rather than device units. That patch will need to be re-worked in order to handle this - it looks like it gets logical / device units confused in a few places, by constructing those types directly from the scalar values, I think.

@jdm
Copy link
Member Author

@jdm jdm commented Jul 16, 2018

Thanks for investigating!

@jdm
Copy link
Member Author

@jdm jdm commented Jul 17, 2018

diff --git a/ports/servo/glutin_app/window.rs b/ports/servo/glutin_app/window.rs
index 514b1f8c07..75c5ac29d0 100644
--- a/ports/servo/glutin_app/window.rs
+++ b/ports/servo/glutin_app/window.rs
@@ -493,12 +493,14 @@ impl Window {
             },
             Event::WindowEvent {
                 event: winit::WindowEvent::CursorMoved {
-                    position: LogicalPosition { x, y },
+                    position,
                     ..
                 },
                 ..
             } => {
-                self.mouse_pos.set(TypedPoint2D::new(x as i32, y as i32));
+                let pos = position.to_physical(self.hidpi_factor().get() as f64);
+                let (x, y): (i32, i32) = pos.into();
+                self.mouse_pos.set(TypedPoint2D::new(x, y));
                 self.event_queue.borrow_mut().push(
                     WindowEvent::MouseWindowMoveEventClass(TypedPoint2D::new(x as f32, y as f32)));

This change fixed the hit testing for me.

@jdm jdm mentioned this issue Jul 17, 2018
4 of 4 tasks complete
bors-servo added a commit that referenced this issue Jul 17, 2018
Fix hittesting on HiDPI screens

This fixes some regressions introduced in #21087 due to treating logical coordinates as physical ones without converting between them correctly.

---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #21168
- [x] These changes do not require tests because we do not have the ability to test embedding input yet.

<!-- 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/21190)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this issue Jul 17, 2018
Fix hittesting on HiDPI screens

This fixes some regressions introduced in #21087 due to treating logical coordinates as physical ones without converting between them correctly.

---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #21168
- [x] These changes do not require tests because we do not have the ability to test embedding input yet.

<!-- 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/21190)
<!-- Reviewable:end -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

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