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

Add viewport configuration support to the compositor #7552

Merged
merged 1 commit into from Oct 14, 2015
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -93,6 +93,9 @@ pub struct IOCompositor<Window: WindowMethods> {
/// The application window size.
window_size: TypedSize2D<DevicePixel, u32>,

/// The overridden viewport.
viewport: Option<(TypedPoint2D<DevicePixel, u32>, TypedSize2D<DevicePixel, u32>)>,

/// "Mobile-style" zoom that does not reflow the page.
viewport_zoom: ScaleFactor<PagePx, ViewportPx, f32>,

@@ -292,6 +295,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
size: window_size.as_f32(),
}),
window_size: window_size,
viewport: None,
hidpi_factor: hidpi_factor,
channel_to_self: state.sender.clone_compositor_proxy(),
scrolling_timer: ScrollingTimerProxy::new(state.sender),
@@ -1017,6 +1021,10 @@ impl<Window: WindowMethods> IOCompositor<Window> {
self.initialize_compositing();
}

WindowEvent::Viewport(point, size) => {
self.viewport = Some((point, size));
}

WindowEvent::Resize(size) => {
self.on_resize_window_event(size);
}
@@ -1574,15 +1582,39 @@ impl<Window: WindowMethods> IOCompositor<Window> {
profile(ProfilerCategory::Compositing, None, self.time_profiler_chan.clone(), || {
debug!("compositor: compositing");
// Adjust the layer dimensions as necessary to correspond to the size of the window.
self.scene.viewport = Rect {
origin: Point2D::zero(),
size: self.window_size.as_f32(),
self.scene.viewport = match self.viewport {
Some((point, size)) => Rect {
origin: point.as_f32(),
size: size.as_f32(),
},

None => Rect {
origin: Point2D::zero(),
size: self.window_size.as_f32(),
}
};

// Paint the scene.
if let Some(ref layer) = self.scene.root {
match self.context {
Some(context) => rendergl::render_scene(layer.clone(), context, &self.scene),
Some(context) => {
if let Some((point, size)) = self.viewport {
let point = point.to_untyped();
let size = size.to_untyped();

gl::scissor(point.x as GLint, point.y as GLint,
size.width as GLsizei, size.height as GLsizei);

gl::enable(gl::SCISSOR_TEST);
rendergl::render_scene(layer.clone(), context, &self.scene);
gl::disable(gl::SCISSOR_TEST);

}
else {
rendergl::render_scene(layer.clone(), context, &self.scene);
}
}

None => {
debug!("compositor: not compositing because context not yet set up")
}
@@ -51,6 +51,8 @@ pub enum WindowEvent {
InitializeCompositing,
/// Sent when the window is resized.
Resize(TypedSize2D<DevicePixel, u32>),
/// Sent when you want to override the viewport.
Viewport(TypedPoint2D<DevicePixel, u32>, TypedSize2D<DevicePixel, u32>),
/// Sent when a new URL is to be loaded.
LoadUrl(String),
/// Sent when a mouse hit test is to be performed.
@@ -81,6 +83,7 @@ impl Debug for WindowEvent {
WindowEvent::Refresh => write!(f, "Refresh"),
WindowEvent::InitializeCompositing => write!(f, "InitializeCompositing"),
WindowEvent::Resize(..) => write!(f, "Resize"),
WindowEvent::Viewport(..) => write!(f, "Viewport"),
WindowEvent::KeyEvent(..) => write!(f, "Key"),
WindowEvent::LoadUrl(..) => write!(f, "LoadUrl"),
WindowEvent::MouseWindowEventClass(..) => write!(f, "Mouse"),
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.