Skip to content
This repository was archived by the owner on Jun 8, 2020. It is now read-only.

Add support for surface pattern. - #156

Merged
jdm merged 2 commits into
servo:masterfrom
hyowon:master
May 15, 2015
Merged

jdm merged 2 commits into
servo:masterfrom
hyowon:master

Conversation

@hyowon

@hyowon hyowon commented May 14, 2015

Copy link
Copy Markdown
Contributor

I'm interested in implementing canvas features for servo.
SurfacePattern seems to be needed to support pattern fill for canvas.

@pcwalton

Copy link
Copy Markdown
Contributor

This will also be useful for making our tiled background painting code less hilariously slow.

@hyowon

hyowon commented May 15, 2015

Copy link
Copy Markdown
Contributor Author

@jdm All patterns are cloneable now.

#[derive(Clone)]
pub enum Pattern {
Color(ColorPattern),
LinearGradient(LinearGradientPattern),
RadialGradient(RadialGradientPattern),
Surface(SurfacePattern),
}

I'm not sure whether we can remove clone from all patterns or not.
But CanvasPaintState having Patterns needs clone.

#[derive(Clone)]
struct CanvasPaintState<'a> {
draw_options: DrawOptions,
fill_style: Pattern,
stroke_style: Pattern,
stroke_opts: StrokeOptions<'a>,
/// The current 2D transform matrix.
transform: Matrix2D,
}

Is it difficult to keep on using clone while avoiding a dangling pointer?
I'm a newbie to rust and servo. Please advice me further. Thank you for your review.

@pcwalton Interesting. I'll also see the tiled background painting code.

@jdm

jdm commented May 15, 2015

Copy link
Copy Markdown
Member

Yeah, I just noticed that the other pattern types derive Clone as well, so they have the same problem. The way to fix it here is to add a C API to clone an AzSurfacePatternRef that casts it to gfx::SourcePattern and returns new SurfacePattern(sourcePattern->mSurface, sourcePattern->mExtendMode, sourcePatter->mFilter, sourcePattern->mMatrix, sourcePattern->mSamplingRect). We should do the same for the other pattern types, and manually implement the Clone trait instead of deriving it. Does that make sense?

@hyowon

hyowon commented May 15, 2015

Copy link
Copy Markdown
Contributor Author

That makes great sense. Thank you for your kind guidance. Please review additional patch.

jdm added a commit that referenced this pull request May 15, 2015
Add support for surface pattern.
@jdm
jdm merged commit ecd3e60 into servo:master May 15, 2015
@jdm

jdm commented May 15, 2015

Copy link
Copy Markdown
Member

Looks great!

@hyowon

hyowon commented Jun 1, 2015

Copy link
Copy Markdown
Contributor Author

cc @yichoi

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants