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 revamped RedrawRequested on Windows #1050

Merged
merged 2 commits into from
Aug 27, 2019

Conversation

Osspial
Copy link
Contributor

@Osspial Osspial commented Jul 17, 2019

  • Tested on all platforms changed
  • cargo fmt has been run on this branch
  • Added an entry to CHANGELOG.md if knowledge of this change could be valuable to users
  • Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior
  • Created or updated an example program if it would help users understand this functionality
  • Updated feature matrix, if new features were added or implemented

I wrote this up before submitting #1041 so I could verify that the API would solve the problems I wanted it to solve. This is still tentative since I don't believe we've reached a conclusion on #1041, but it implements my version of the proposal, so even if it doesn't get merged it's still worthwhile to have around for testing purposes.

@Osspial Osspial changed the base branch from master to redraw-requested-2.0 July 23, 2019 02:37
@goddessfreya
Copy link
Contributor

@notriddle, since you are on the testers list, would you like to test this? Please make sure the examples don't freeze, and the ordering of the events is consistent with what is proposed here: #1041

Thanks :)

@notriddle
Copy link
Contributor

Okay, I went ahead and tried some of the examples.

win32_text example fails to compile
PS C:\Users\micha\IdeaProjects\winit> cargo run --example win32_text
    Updating crates.io index
   Compiling arrayvec v0.4.10
   Compiling autocfg v0.1.4
   Compiling libc v0.2.58
   Compiling cfg-if v0.1.9
   Compiling lazy_static v1.3.0
   Compiling winapi v0.3.7
   Compiling nodrop v0.1.13
   Compiling semver-parser v0.7.0
   Compiling proc-macro2 v0.4.30
   Compiling unicode-xid v0.1.0
   Compiling memoffset v0.2.1
   Compiling rand_core v0.4.0
   Compiling scopeguard v0.3.3
   Compiling memchr v2.2.0
   Compiling rayon-core v1.5.0
   Compiling syn v0.15.39
   Compiling byteorder v1.3.2
   Compiling bitflags v1.1.0
   Compiling num-derive v0.2.5
   Compiling ucd-util v0.1.3
   Compiling adler32 v1.0.3
   Compiling scopeguard v1.0.0
   Compiling smallvec v0.6.10
   Compiling either v1.5.2
   Compiling regex v1.1.7
   Compiling quick-error v1.2.2
   Compiling color_quant v1.0.1
   Compiling lzw v0.10.0
   Compiling utf8-ranges v1.0.3
   Compiling scoped_threadpool v0.1.9
   Compiling log v0.4.6
   Compiling crossbeam-utils v0.6.5
   Compiling thread_local v0.3.6
   Compiling rand_pcg v0.1.2
   Compiling num-traits v0.2.8
   Compiling rand_chacha v0.1.1
   Compiling num-integer v0.1.41
   Compiling rand v0.6.5
   Compiling num-iter v0.1.39
   Compiling num-rational v0.2.2
   Compiling semver v0.9.0
   Compiling rand_core v0.3.1
   Compiling lock_api v0.2.0
   Compiling inflate v0.4.5
   Compiling regex-syntax v0.6.7
   Compiling humantime v1.2.0
   Compiling gif v0.10.2
   Compiling crossbeam-queue v0.1.2
   Compiling rand_isaac v0.1.1
   Compiling rand_xorshift v0.1.1
   Compiling rand_hc v0.1.0
   Compiling rustc_version v0.2.3
   Compiling num_cpus v1.10.1
   Compiling crossbeam-epoch v0.7.1
   Compiling quote v0.6.12
   Compiling aho-corasick v0.7.3
   Compiling deflate v0.7.19
   Compiling parking_lot_core v0.5.0
   Compiling parking_lot v0.8.0
   Compiling crossbeam-deque v0.6.3
   Compiling rand_os v0.1.3
   Compiling rand_jitter v0.1.4
   Compiling winapi-util v0.1.2
   Compiling atty v0.2.11
   Compiling wincolor v1.0.1
   Compiling rayon v1.1.0
   Compiling png v0.14.1
   Compiling termcolor v1.0.5
   Compiling env_logger v0.5.13
   Compiling jpeg-decoder v0.1.15
   Compiling derivative v1.0.2
   Compiling winit v0.20.0-alpha1 (C:\Users\micha\IdeaProjects\winit)
   Compiling tiff v0.2.2
   Compiling image v0.21.2
error[E0599]: no variant named `EventsCleared` found for type `winit::event::Event<_>` in the current scope
  --> examples\win32_text.rs:23:20
   |
23 |             Event::EventsCleared => {
   |                    ^^^^^^^^^^^^^
   |                    |
   |                    variant not found in `winit::event::Event<_>`
   |                    help: did you mean: `MainEventsCleared`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0599`.
error: Could not compile `winit`.

To learn more, run the command again with --verbose.

window doesn't seem right. On master, it eventually stops spitting out events if you open the window and stop moving your mouse. On this branch, however, it enters a perpetual hot loop of

NewEvents(Poll)
MainEventsCleared
RedrawRequested(WindowId(WindowId(0x4e06b8)))
RedrawEventsCleared

and eating a constant 10% of my CPU.

request_redraw compiles, and, more importantly, it always seems to have RedrawRequested(WindowId(WindowId(0x2d0aa8))) followed by RedrawEventsCleared, no matter what I do to. If it is the inactive window, it will also eventually settle down and only write the redraw events once every few seconds, just like on master.

In both cases, while the window is pure white on master, it's white on top with black on the bottom on your branch, which makes me think there's something wrong with how it paints.

master screenshot

image

branch screenshot

image

@aloucks
Copy link
Contributor

aloucks commented Jul 28, 2019

What happens if you call Window::request_redraw from RedrawEventsCleared?

@notriddle
Copy link
Contributor

You mean like this?

PS C:\Users\micha\IdeaProjects\winit> git diff
diff --git a/examples/window.rs b/examples/window.rs
index e2265dbd..a6d161fe 100644
--- a/examples/window.rs
+++ b/examples/window.rs
@@ -20,7 +20,7 @@ fn main() {
                 event: WindowEvent::CloseRequested,
                 window_id,
             } if window_id == window.id() => *control_flow = ControlFlow::Exit,
-            Event::MainEventsCleared => {
+            Event::MainEventsCleared | Event::RedrawEventsCleared => {
                 window.request_redraw();
             }
             _ => *control_flow = ControlFlow::Poll,

Same perpetual hot loop. Chews through 10% of my CPU.

@aloucks
Copy link
Contributor

aloucks commented Jul 28, 2019

You mean like this?

Sorry, I was just asking in general if there is any difference in behavior when Window::request_redraw is called from RedrawEventsCleared vs MainEventsCleared. My comment wasn't related to your question.

With that said, the control flow is set toPoll, which should run the loop at full throttle. I would expect it to eat some percentage of CPU and see the constant stream of events.

@notriddle
Copy link
Contributor

notriddle commented Jul 28, 2019

Oh, you're right. In master, it's set up like this

        _ => *control_flow = ControlFlow::Wait,

But it's not set up that way on the branch. Oops.

If I change it to Wait, with this branch being run, it works right. My mistake.


I applied this patch to the window example, and now it behaves reasonable. I thought I had locked it up, but I can't reproduce it more than once.

diff --git a/examples/window.rs b/examples/window.rs
index e2265dbd..42738434 100644
--- a/examples/window.rs
+++ b/examples/window.rs
@@ -23,7 +23,7 @@ fn main() {
             Event::MainEventsCleared => {
                 window.request_redraw();
             }
-            _ => *control_flow = ControlFlow::Poll,
+            _ => *control_flow = ControlFlow::Wait,
         }
     });
 }

@goddessfreya
Copy link
Contributor

@Osspial is this ready for merging, it appears to work, no?

@Osspial Osspial marked this pull request as ready for review August 26, 2019 23:56
@Osspial
Copy link
Contributor Author

Osspial commented Aug 27, 2019

@zegentzy I've rebased this against murarth's changes so it should be good now.

@Osspial Osspial merged commit 5e68ec0 into rust-windowing:redraw-requested-2.0 Aug 27, 2019
hecrj pushed a commit to hecrj/winit that referenced this pull request Aug 31, 2019
* Move event loop runner to runner module

* Implement new redraw API
Osspial added a commit that referenced this pull request Oct 3, 2019
* Move event loop runner to runner module

* Implement new redraw API
cheako pushed a commit to cheako/winit that referenced this pull request Oct 19, 2019
* Move event loop runner to runner module

* Implement new redraw API
Osspial added a commit that referenced this pull request Oct 23, 2019
* Move event loop runner to runner module

* Implement new redraw API
Osspial added a commit that referenced this pull request Dec 22, 2019
* Move event loop runner to runner module

* Implement new redraw API
Osspial added a commit that referenced this pull request Dec 22, 2019
* Move event loop runner to runner module

* Implement new redraw API
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants