Skip to content

Commit

Permalink
unrendered content uses doc's background color
Browse files Browse the repository at this point in the history
  uses html's background color, or body's.
  • Loading branch information
Isabelle Carter authored and unholydh committed Nov 24, 2013
1 parent 94df5d1 commit 9886135
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 14 deletions.
9 changes: 5 additions & 4 deletions src/components/gfx/render_task.rs
Expand Up @@ -4,7 +4,7 @@

// The task that handles all rendering/painting.

use azure::azure_hl::{B8G8R8A8, DrawTarget, StolenGLResources};
use azure::azure_hl::{B8G8R8A8, Color, DrawTarget, StolenGLResources};
use azure::AzFloat;
use geom::matrix2d::Matrix2D;
use geom::rect::Rect;
Expand All @@ -31,7 +31,8 @@ use render_context::RenderContext;

pub struct RenderLayer<T> {
display_list: Arc<DisplayList<T>>,
size: Size2D<uint>
size: Size2D<uint>,
color: Color
}

pub enum Msg<T> {
Expand Down Expand Up @@ -178,7 +179,7 @@ impl<C: RenderListener + Send,T:Send+Freeze> RenderTask<C,T> {
RenderMsg(render_layer) => {
if self.paint_permission {
self.epoch.next();
self.compositor.set_layer_page_size(self.id, render_layer.size, self.epoch);
self.compositor.set_layer_page_size_and_color(self.id, render_layer.size, self.epoch, render_layer.color);
} else {
self.constellation_chan.send(RendererReadyMsg(self.id));
}
Expand All @@ -202,7 +203,7 @@ impl<C: RenderListener + Send,T:Send+Freeze> RenderTask<C,T> {
match self.render_layer {
Some(ref render_layer) => {
self.epoch.next();
self.compositor.set_layer_page_size(self.id, render_layer.size, self.epoch);
self.compositor.set_layer_page_size_and_color(self.id, render_layer.size, self.epoch, render_layer.color);
}
None => {}
}
Expand Down
6 changes: 6 additions & 0 deletions src/components/main/compositing/compositor_layer.rs
Expand Up @@ -23,6 +23,8 @@ use servo_msg::constellation_msg::PipelineId;
use std::cell::Cell;
use windowing::{MouseWindowEvent, MouseWindowClickEvent, MouseWindowMouseDownEvent};
use windowing::{MouseWindowMouseUpEvent};
use azure::azure_hl::Color;
use gfx;

#[cfg(not(target_os="macos"))]
use layers::texturegl::TextureTarget2D;
Expand Down Expand Up @@ -69,6 +71,9 @@ pub struct CompositorLayer {

/// True if CPU rendering is enabled, false if we're using GPU rendering.
cpu_painting: bool,

/// The color to use for the unrendered-content void
unrendered_color: Color
}

/// Helper struct for keeping CompositorLayer children organized.
Expand Down Expand Up @@ -122,6 +127,7 @@ impl CompositorLayer {
epoch: Epoch(0),
scroll_behavior: Scroll,
cpu_painting: cpu_painting,
unrendered_color: gfx::color::rgba(0.0, 0.0, 0.0, 0.0),
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/components/main/compositing/mod.rs
Expand Up @@ -7,7 +7,7 @@ pub use windowing;
use constellation::SendableFrameTree;
use windowing::WindowMethods;

use azure::azure_hl::SourceSurfaceMethods;
use azure::azure_hl::{SourceSurfaceMethods, Color};
use geom::point::Point2D;
use geom::rect::Rect;
use geom::size::Size2D;
Expand Down Expand Up @@ -71,10 +71,12 @@ impl RenderListener for CompositorChan {
let Size2D { width, height } = page_size;
self.chan.send(NewLayer(id, Size2D(width as f32, height as f32)))
}
fn set_layer_page_size(&self, id: PipelineId, page_size: Size2D<uint>, epoch: Epoch) {
fn set_layer_page_size_and_color(&self, id: PipelineId, page_size: Size2D<uint>, epoch: Epoch, color: Color) {
let Size2D { width, height } = page_size;
self.chan.send(SetUnRenderedColor(id, color));
self.chan.send(SetLayerPageSize(id, Size2D(width as f32, height as f32), epoch))
}

fn set_layer_clip_rect(&self, id: PipelineId, new_rect: Rect<uint>) {
let new_rect = Rect(Point2D(new_rect.origin.x as f32,
new_rect.origin.y as f32),
Expand Down Expand Up @@ -132,6 +134,8 @@ pub enum Msg {
ChangeRenderState(RenderState),
/// Sets the channel to the current layout and render tasks, along with their id
SetIds(SendableFrameTree, Chan<()>, ConstellationChan),

SetUnRenderedColor(PipelineId, Color),
}

pub struct CompositorTask {
Expand Down
20 changes: 19 additions & 1 deletion src/components/main/compositing/run.rs
Expand Up @@ -89,6 +89,16 @@ pub fn run_compositor(compositor: &CompositorTask) {
ChangeReadyState(ready_state) => window.set_ready_state(ready_state),
ChangeRenderState(render_state) => window.set_render_state(render_state),

SetUnRenderedColor(id, color) => {
match compositor_layer {
Some(ref mut layer) => {
layer.unrendered_color = color;
}
None => {}
}
}


SetIds(frame_tree, response_chan, new_constellation_chan) => {
response_chan.send(());

Expand Down Expand Up @@ -332,8 +342,16 @@ pub fn run_compositor(compositor: &CompositorTask) {
debug!("compositor: compositing");
// Adjust the layer dimensions as necessary to correspond to the size of the window.
scene.size = window.size();

// Render the scene.
match compositor_layer {
Some(ref mut layer) => {
scene.background_color.r = layer.unrendered_color.r;
scene.background_color.g = layer.unrendered_color.g;
scene.background_color.b = layer.unrendered_color.b;
scene.background_color.a = layer.unrendered_color.a;
}
None => {}
}
rendergl::render_scene(context, &scene);
}

Expand Down
5 changes: 3 additions & 2 deletions src/components/main/compositing/run_headless.rs
Expand Up @@ -15,7 +15,7 @@ pub fn run_compositor(compositor: &CompositorTask) {
match compositor.port.recv() {
Exit => break,

GetGraphicsMetadata(chan) => {
GetGraphicsMetadata(chan) => {
unsafe {
chan.send(intrinsics::uninit());
}
Expand All @@ -30,7 +30,8 @@ pub fn run_compositor(compositor: &CompositorTask) {
// SetIds.

NewLayer(*) | SetLayerPageSize(*) | SetLayerClipRect(*) | DeleteLayer(*) |
Paint(*) | InvalidateRect(*) | ChangeReadyState(*) | ChangeRenderState(*)
Paint(*) | InvalidateRect(*) | ChangeReadyState(*) | ChangeRenderState(*)|
SetUnRenderedColor(*)
=> ()
}
}
Expand Down
29 changes: 25 additions & 4 deletions src/components/main/layout/layout_task.rs
Expand Up @@ -7,9 +7,10 @@

use css::matching::MatchMethods;
use css::select::new_stylist;
use css::node_style::StyledNode;
use layout::construct::{FlowConstructionResult, FlowConstructor, NoConstructionResult};
use layout::context::LayoutContext;
use layout::display_list_builder::{DisplayListBuilder};
use layout::display_list_builder::{DisplayListBuilder, ToGfxColor};
use layout::extra::LayoutAuxMethods;
use layout::flow::{FlowContext, ImmutableFlowUtils, MutableFlowUtils, PreorderFlowTraversal};
use layout::flow::{PostorderFlowTraversal};
Expand All @@ -25,9 +26,10 @@ use gfx::display_list::DisplayList;
use gfx::font_context::FontContext;
use gfx::opts::Opts;
use gfx::render_task::{RenderMsg, RenderChan, RenderLayer};
use gfx::render_task;
use gfx::{render_task, color};
use script::dom::event::ReflowEvent;
use script::dom::node::{AbstractNode, LayoutDataRef, LayoutView};
use script::dom::node::{AbstractNode, LayoutDataRef, LayoutView, ElementNodeTypeId};
use script::dom::element::{HTMLBodyElementTypeId, HTMLHtmlElementTypeId};
use script::layout_interface::{AddStylesheetMsg, ContentBoxQuery};
use script::layout_interface::{ContentBoxesQuery, ContentBoxesResponse, ExitNowMsg, LayoutQuery};
use script::layout_interface::{HitTestQuery, ContentBoxResponse, HitTestResponse};
Expand Down Expand Up @@ -515,10 +517,29 @@ impl LayoutTask {
}
}

let mut color = color::rgba(255.0, 255.0, 255.0, 255.0);

for child in node.traverse_preorder() {
if child.type_id() == ElementNodeTypeId(HTMLHtmlElementTypeId) ||
child.type_id() == ElementNodeTypeId(HTMLBodyElementTypeId) {
let element_bg_color = child.style().resolve_color(
child.style().Background.background_color
).to_gfx_color();
match element_bg_color {
color::rgba(0., 0., 0., 0.) => {}
_ => {
color = element_bg_color;
break;
}
}
}
}

let render_layer = RenderLayer {
display_list: display_list.clone(),
size: Size2D(root_size.width.to_nearest_px() as uint,
root_size.height.to_nearest_px() as uint)
root_size.height.to_nearest_px() as uint),
color: color
};

self.display_list = Some(display_list.clone());
Expand Down
3 changes: 2 additions & 1 deletion src/components/msg/compositor_msg.rs
Expand Up @@ -4,6 +4,7 @@

use geom::rect::Rect;
use geom::size::Size2D;
use azure::azure_hl::Color;
use layers::platform::surface::{NativeGraphicsMetadata, NativePaintingGraphicsContext};
use layers::platform::surface::{NativeSurface, NativeSurfaceMethods};

Expand Down Expand Up @@ -76,7 +77,7 @@ impl Epoch {
pub trait RenderListener {
fn get_graphics_metadata(&self) -> NativeGraphicsMetadata;
fn new_layer(&self, PipelineId, Size2D<uint>);
fn set_layer_page_size(&self, PipelineId, Size2D<uint>, Epoch);
fn set_layer_page_size_and_color(&self, PipelineId, Size2D<uint>, Epoch, Color);
fn set_layer_clip_rect(&self, PipelineId, Rect<uint>);
fn delete_layer(&self, PipelineId);
fn paint(&self, id: PipelineId, layer_buffer_set: ~LayerBufferSet, Epoch);
Expand Down
1 change: 1 addition & 0 deletions src/components/msg/constellation_msg.rs
Expand Up @@ -8,6 +8,7 @@
use std::comm::{Chan, SharedChan};
use extra::url::Url;
use extra::future::Future;
use azure::azure_hl::Color;
use geom::size::Size2D;
use geom::rect::Rect;

Expand Down

5 comments on commit 9886135

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from jdm
at ibnc@9886135

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging ibnc/servo/resizing_background_color = 9886135 into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ibnc/servo/resizing_background_color = 9886135 merged ok, testing candidate = 010b8cd

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 010b8cd

Please sign in to comment.