-
Notifications
You must be signed in to change notification settings - Fork 567
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
Adds support for invalidating a single rectangle. #817
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
55d1aaa
Implement partial invalidation.
jneem 5adab13
Fix the small issues from code review.
jneem efd6521
Fix propagation of invalid region to children.
jneem 8959bc5
Hopefully fix invalidation on mac.
jneem fed49b1
Use rectangle outlines for debug_invalidation.
jneem 0f8b861
Propagate the invalid rects properly in wasm.
jneem dc9b5e9
Invalidate more conservatively when animating.
jneem File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Copyright 2020 The xi-editor Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use std::any::Any; | ||
|
||
use std::time::Instant; | ||
|
||
use druid_shell::kurbo::{Point, Rect}; | ||
use druid_shell::piet::{Color, Piet, RenderContext}; | ||
|
||
use druid_shell::{Application, WinHandler, WindowBuilder, WindowHandle}; | ||
|
||
struct InvalidateTest { | ||
handle: WindowHandle, | ||
size: (f64, f64), | ||
start_time: Instant, | ||
color: Color, | ||
rect: Rect, | ||
} | ||
|
||
impl InvalidateTest { | ||
fn update_color_and_rect(&mut self) { | ||
let time_since_start = (Instant::now() - self.start_time).as_nanos(); | ||
let (r, g, b, _) = self.color.as_rgba_u8(); | ||
self.color = match (time_since_start % 2, time_since_start % 3) { | ||
(0, _) => Color::rgb8(r.wrapping_add(10), g, b), | ||
(_, 0) => Color::rgb8(r, g.wrapping_add(10), b), | ||
(_, _) => Color::rgb8(r, g, b.wrapping_add(10)), | ||
}; | ||
|
||
self.rect.x0 = (self.rect.x0 + 5.0) % self.size.0; | ||
self.rect.x1 = (self.rect.x1 + 5.5) % self.size.0; | ||
self.rect.y0 = (self.rect.y0 + 3.0) % self.size.1; | ||
self.rect.y1 = (self.rect.y1 + 3.5) % self.size.1; | ||
} | ||
} | ||
|
||
impl WinHandler for InvalidateTest { | ||
fn connect(&mut self, handle: &WindowHandle) { | ||
self.handle = handle.clone(); | ||
} | ||
|
||
fn paint(&mut self, piet: &mut Piet, rect: Rect) -> bool { | ||
self.update_color_and_rect(); | ||
piet.fill(rect, &self.color); | ||
|
||
self.handle.invalidate_rect(self.rect); | ||
false | ||
} | ||
|
||
fn size(&mut self, width: u32, height: u32) { | ||
let dpi = self.handle.get_dpi(); | ||
let dpi_scale = dpi as f64 / 96.0; | ||
let width_f = (width as f64) / dpi_scale; | ||
let height_f = (height as f64) / dpi_scale; | ||
self.size = (width_f, height_f); | ||
} | ||
|
||
fn command(&mut self, id: u32) { | ||
match id { | ||
0x100 => self.handle.close(), | ||
_ => println!("unexpected id {}", id), | ||
} | ||
} | ||
|
||
fn as_any(&mut self) -> &mut dyn Any { | ||
self | ||
} | ||
} | ||
|
||
fn main() { | ||
let mut app = Application::new(None); | ||
let mut builder = WindowBuilder::new(); | ||
let inv_test = InvalidateTest { | ||
size: Default::default(), | ||
handle: Default::default(), | ||
start_time: Instant::now(), | ||
rect: Rect::from_origin_size(Point::ZERO, (10.0, 20.0)), | ||
color: Color::WHITE, | ||
}; | ||
builder.set_handler(Box::new(inv_test)); | ||
builder.set_title("Invalidate tester"); | ||
|
||
let window = builder.build().unwrap(); | ||
window.show(); | ||
app.run(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on mac, invalidation calls that happen during drawing are ignored.
I would suggest changing this to use a timer, something like: