aboutsummaryrefslogtreecommitdiffstats
path: root/components/canvas/canvas_paint_task.rs
diff options
context:
space:
mode:
authorbors-servo <metajack+bors@gmail.com>2015-06-17 13:32:25 -0600
committerbors-servo <metajack+bors@gmail.com>2015-06-17 13:32:25 -0600
commite1b28d893e54601bf497d0d5b83d77658ca16bac (patch)
tree11659c018548257f0ca9b654535a7e09849ab662 /components/canvas/canvas_paint_task.rs
parentee54c89e3f801dcd90a494c65ff8cfd975a6be6f (diff)
parent2e230bdb933948c5f71cb0e177fb4cc832cfae13 (diff)
downloadservo-e1b28d893e54601bf497d0d5b83d77658ca16bac.tar.gz
servo-e1b28d893e54601bf497d0d5b83d77658ca16bac.zip
Auto merge of #6402 - hyowon:canvas_fill_stroke, r=pcwalton
Fill and stroke for all pattern types and check the zero size gradient. Depends on servo/rust-azure#170 which has been already merged. So this patch contains the update of rust-azure. r? @nox cc @yichoi <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6402) <!-- Reviewable:end -->
Diffstat (limited to 'components/canvas/canvas_paint_task.rs')
-rw-r--r--components/canvas/canvas_paint_task.rs66
1 files changed, 41 insertions, 25 deletions
diff --git a/components/canvas/canvas_paint_task.rs b/components/canvas/canvas_paint_task.rs
index dfe262d27f7..c09dc021579 100644
--- a/components/canvas/canvas_paint_task.rs
+++ b/components/canvas/canvas_paint_task.rs
@@ -250,6 +250,10 @@ impl<'a> CanvasPaintTask<'a> {
}
fn fill_rect(&self, rect: &Rect<f32>) {
+ if is_zero_size_gradient(&self.state.fill_style) {
+ return; // Paint nothing if gradient size is zero.
+ }
+
let draw_rect = Rect::new(rect.origin,
match self.state.fill_style {
Pattern::Surface(ref surface) => {
@@ -281,14 +285,19 @@ impl<'a> CanvasPaintTask<'a> {
}
fn stroke_rect(&self, rect: &Rect<f32>) {
- match self.state.stroke_style {
- Pattern::Color(ref color) => {
- self.drawtarget.stroke_rect(rect, color, &self.state.stroke_opts, &self.state.draw_options)
- }
- _ => {
- // TODO(pcwalton)
- }
- };
+ if is_zero_size_gradient(&self.state.stroke_style) {
+ return; // Paint nothing if gradient size is zero.
+ }
+
+ if self.need_to_draw_shadow() {
+ self.draw_with_shadow(&rect, |new_draw_target: &DrawTarget| {
+ new_draw_target.stroke_rect(rect, self.state.stroke_style.to_pattern_ref(),
+ &self.state.stroke_opts, &self.state.draw_options);
+ });
+ } else {
+ self.drawtarget.stroke_rect(rect, self.state.stroke_style.to_pattern_ref(),
+ &self.state.stroke_opts, &self.state.draw_options);
+ }
}
fn begin_path(&mut self) {
@@ -300,26 +309,24 @@ impl<'a> CanvasPaintTask<'a> {
}
fn fill(&self) {
- match self.state.fill_style {
- Pattern::Color(ref color) => {
- self.drawtarget.fill(&self.path_builder.finish(), color, &self.state.draw_options);
- }
- _ => {
- // TODO(pcwalton)
- }
- };
+ if is_zero_size_gradient(&self.state.fill_style) {
+ return; // Paint nothing if gradient size is zero.
+ }
+
+ self.drawtarget.fill(&self.path_builder.finish(),
+ self.state.fill_style.to_pattern_ref(),
+ &self.state.draw_options);
}
fn stroke(&self) {
- match self.state.stroke_style {
- Pattern::Color(ref color) => {
- self.drawtarget.stroke(&self.path_builder.finish(),
- color, &self.state.stroke_opts, &self.state.draw_options);
- }
- _ => {
- // TODO
- }
- };
+ if is_zero_size_gradient(&self.state.stroke_style) {
+ return; // Paint nothing if gradient size is zero.
+ }
+
+ self.drawtarget.stroke(&self.path_builder.finish(),
+ self.state.stroke_style.to_pattern_ref(),
+ &self.state.stroke_opts,
+ &self.state.draw_options);
}
fn clip(&self) {
@@ -733,6 +740,15 @@ fn write_pixels(draw_target: &DrawTarget,
draw_options);
}
+fn is_zero_size_gradient(pattern: &Pattern) -> bool {
+ if let &Pattern::LinearGradient(ref gradient) = pattern {
+ if gradient.is_zero_size() {
+ return true;
+ }
+ }
+ return false;
+}
+
pub trait SizeToi32 {
fn to_i32(&self) -> Size2D<i32>;
}