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

Remove refs from WebRenderContext constructor API #153

Merged
merged 1 commit into from
Apr 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions piet-web/examples/basic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn run() {
.unwrap()
.dyn_into::<HtmlCanvasElement>()
.unwrap();
let mut context = canvas
let context = canvas
.get_context("2d")
.unwrap()
.unwrap()
Expand All @@ -31,7 +31,7 @@ pub fn run() {
canvas.set_height((canvas.offset_height() as f64 * dpr) as u32);
let _ = context.scale(dpr, dpr);

let mut piet_context = WebRenderContext::new(&mut context, &window);
let mut piet_context = WebRenderContext::new(context, window);
run_tests(&mut piet_context);

// TODO: make the test picture selectable
Expand Down
16 changes: 9 additions & 7 deletions piet-web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,20 @@ use piet::{
pub use text::{WebFont, WebFontBuilder, WebTextLayout, WebTextLayoutBuilder};

pub struct WebRenderContext<'a> {
ctx: &'a mut CanvasRenderingContext2d,
ctx: CanvasRenderingContext2d,
/// Used for creating image bitmaps and possibly other resources.
window: &'a Window,
window: Window,
err: Result<(), Error>,
phantom: std::marker::PhantomData<&'a ()>,
}

impl<'a> WebRenderContext<'a> {
pub fn new(ctx: &'a mut CanvasRenderingContext2d, window: &'a Window) -> WebRenderContext<'a> {
pub fn new(ctx: CanvasRenderingContext2d, window: Window) -> WebRenderContext<'a> {
WebRenderContext {
ctx,
window,
err: Ok(()),
phantom: std::marker::PhantomData,
}
}
}
Expand Down Expand Up @@ -326,9 +328,9 @@ impl<'a> RenderContext for WebRenderContext<'a> {
}
}

fn draw_image<'a>(
ctx: &mut WebRenderContext<'a>,
image: &<WebRenderContext<'a> as RenderContext>::Image,
fn draw_image(
ctx: &mut WebRenderContext,
image: &<WebRenderContext as RenderContext>::Image,
src_rect: Option<Rect>,
dst_rect: Rect,
_interp: InterpolationMode,
Expand Down Expand Up @@ -393,7 +395,7 @@ fn set_gradient_stops(dst: &mut CanvasGradient, src: &[GradientStop]) {
}
}

impl<'a> WebRenderContext<'a> {
impl WebRenderContext<'_> {
/// Set the source pattern to the brush.
///
/// Web canvas is super stateful, and we're trying to have more retained stuff.
Expand Down