From e1db06475c7d1833b7a4469b797cdadceb28df6e Mon Sep 17 00:00:00 2001 From: Adenilson Cavalcanti Date: Tue, 3 Feb 2015 17:40:50 -0800 Subject: [PATCH 1/4] There are cases where we need opaque black (e.g. border color) and other cases where we need transparent black (e.g. clearing, root layers). --- components/gfx/color.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/components/gfx/color.rs b/components/gfx/color.rs index f1f589ef4b7..0bf03bff6dc 100644 --- a/components/gfx/color.rs +++ b/components/gfx/color.rs @@ -24,6 +24,11 @@ pub fn rgba(r: AzFloat, g: AzFloat, b: AzFloat, a: AzFloat) -> AzColor { #[inline] pub fn black() -> AzColor { + AzColor { r: 0.0, g: 0.0, b: 0.0, a: 1.0 } +} + +#[inline] +pub fn transparent_black() -> AzColor { AzColor { r: 0.0, g: 0.0, b: 0.0, a: 0.0 } } From ffa23088fffab788a73eeb004ec11404c7633e05 Mon Sep 17 00:00:00 2001 From: Adenilson Cavalcanti Date: Tue, 3 Feb 2015 18:08:30 -0800 Subject: [PATCH 2/4] Using the new transparent_black() in the proper places. --- components/compositing/compositor.rs | 2 +- components/gfx/paint_context.rs | 2 +- components/layout/layout_task.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index f09eb6b51a8..e9e0f6bf8d2 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -508,7 +508,7 @@ impl IOCompositor { epoch: Epoch(0), id: LayerId::null(), rect: Rect::zero(), - background_color: color::black(), + background_color: color::transparent_black(), scroll_policy: ScrollPolicy::Scrollable, }; diff --git a/components/gfx/paint_context.rs b/components/gfx/paint_context.rs index 7a304bfb4cb..77b0effb037 100644 --- a/components/gfx/paint_context.rs +++ b/components/gfx/paint_context.rs @@ -154,7 +154,7 @@ impl<'a> PaintContext<'a> { } pub fn clear(&self) { - let pattern = ColorPattern::new(color::black()); + let pattern = ColorPattern::new(color::transparent_black()); let rect = Rect(Point2D(self.page_rect.origin.x as AzFloat, self.page_rect.origin.y as AzFloat), Size2D(self.screen_rect.size.width as AzFloat, diff --git a/components/layout/layout_task.rs b/components/layout/layout_task.rs index e2eea711de7..9a19a84c6e1 100644 --- a/components/layout/layout_task.rs +++ b/components/layout/layout_task.rs @@ -677,7 +677,7 @@ impl LayoutTask { .to_gfx_color() }; - let black = color::black(); + let black = color::transparent_black(); // TODO: Use equality operators when we sync with rust-azure. if element_bg_color.r != black.r || element_bg_color.g != black.g || element_bg_color.b != black.b || element_bg_color.a != black.a { From 3088b8fc30b700117ec3e96b88651b887947ad93 Mon Sep 17 00:00:00 2001 From: Adenilson Cavalcanti Date: Tue, 3 Feb 2015 18:14:42 -0800 Subject: [PATCH 3/4] Using the new equality operator in LayoutTask. --- components/layout/layout_task.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/components/layout/layout_task.rs b/components/layout/layout_task.rs index 9a19a84c6e1..cd2328df866 100644 --- a/components/layout/layout_task.rs +++ b/components/layout/layout_task.rs @@ -678,9 +678,7 @@ impl LayoutTask { }; let black = color::transparent_black(); - // TODO: Use equality operators when we sync with rust-azure. - if element_bg_color.r != black.r || element_bg_color.g != black.g || - element_bg_color.b != black.b || element_bg_color.a != black.a { + if element_bg_color != black { color = element_bg_color; break; From 7a366349635e5b818b1c6ab3268775a2f645c23f Mon Sep 17 00:00:00 2001 From: Adenilson Cavalcanti Date: Tue, 3 Feb 2015 18:51:50 -0800 Subject: [PATCH 4/4] Using the equality operator in PaintContext. Pay attention this is a change on behavior as we previously didn't test for alpha channel. --- components/gfx/paint_context.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/components/gfx/paint_context.rs b/components/gfx/paint_context.rs index 77b0effb037..64495418ffe 100644 --- a/components/gfx/paint_context.rs +++ b/components/gfx/paint_context.rs @@ -729,9 +729,8 @@ impl<'a> PaintContext<'a> { }; let mut lighter_color; - let mut darker_color = color::black();; - // TODO(Savago): Use equality operators when we sync with rust-azure. - if color.r != darker_color.r || color.g != darker_color.g || color.b != darker_color.b { + let mut darker_color = color::black(); + if color != darker_color { darker_color = self.scale_color(color, if is_groove { 1.0/3.0 } else { 2.0/3.0 }); lighter_color = color; } else { @@ -775,8 +774,7 @@ impl<'a> PaintContext<'a> { // You can't scale black color (i.e. 'scaled = 0 * scale', equals black). let mut scaled_color = color::black(); - // TODO(Savago): Use equality operators when we sync with rust-azure. - if color.r != scaled_color.r || color.g != scaled_color.g || color.b != scaled_color.b { + if color != scaled_color { scaled_color = match direction { Direction::Top | Direction::Left => { self.scale_color(color, if is_inset { 2.0/3.0 } else { 1.0 })