mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Add viewport configuration support to the compositor
This commit is contained in:
parent
e4b02cc981
commit
123c19a57a
2 changed files with 39 additions and 4 deletions
|
@ -93,6 +93,9 @@ pub struct IOCompositor<Window: WindowMethods> {
|
||||||
/// The application window size.
|
/// The application window size.
|
||||||
window_size: TypedSize2D<DevicePixel, u32>,
|
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.
|
/// "Mobile-style" zoom that does not reflow the page.
|
||||||
viewport_zoom: ScaleFactor<PagePx, ViewportPx, f32>,
|
viewport_zoom: ScaleFactor<PagePx, ViewportPx, f32>,
|
||||||
|
|
||||||
|
@ -292,6 +295,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
||||||
size: window_size.as_f32(),
|
size: window_size.as_f32(),
|
||||||
}),
|
}),
|
||||||
window_size: window_size,
|
window_size: window_size,
|
||||||
|
viewport: None,
|
||||||
hidpi_factor: hidpi_factor,
|
hidpi_factor: hidpi_factor,
|
||||||
channel_to_self: state.sender.clone_compositor_proxy(),
|
channel_to_self: state.sender.clone_compositor_proxy(),
|
||||||
scrolling_timer: ScrollingTimerProxy::new(state.sender),
|
scrolling_timer: ScrollingTimerProxy::new(state.sender),
|
||||||
|
@ -1017,6 +1021,10 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
||||||
self.initialize_compositing();
|
self.initialize_compositing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WindowEvent::Viewport(point, size) => {
|
||||||
|
self.viewport = Some((point, size));
|
||||||
|
}
|
||||||
|
|
||||||
WindowEvent::Resize(size) => {
|
WindowEvent::Resize(size) => {
|
||||||
self.on_resize_window_event(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(), || {
|
profile(ProfilerCategory::Compositing, None, self.time_profiler_chan.clone(), || {
|
||||||
debug!("compositor: compositing");
|
debug!("compositor: compositing");
|
||||||
// Adjust the layer dimensions as necessary to correspond to the size of the window.
|
// Adjust the layer dimensions as necessary to correspond to the size of the window.
|
||||||
self.scene.viewport = Rect {
|
self.scene.viewport = match self.viewport {
|
||||||
origin: Point2D::zero(),
|
Some((point, size)) => Rect {
|
||||||
size: self.window_size.as_f32(),
|
origin: point.as_f32(),
|
||||||
|
size: size.as_f32(),
|
||||||
|
},
|
||||||
|
|
||||||
|
None => Rect {
|
||||||
|
origin: Point2D::zero(),
|
||||||
|
size: self.window_size.as_f32(),
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Paint the scene.
|
// Paint the scene.
|
||||||
if let Some(ref layer) = self.scene.root {
|
if let Some(ref layer) = self.scene.root {
|
||||||
match self.context {
|
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 => {
|
None => {
|
||||||
debug!("compositor: not compositing because context not yet set up")
|
debug!("compositor: not compositing because context not yet set up")
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,8 @@ pub enum WindowEvent {
|
||||||
InitializeCompositing,
|
InitializeCompositing,
|
||||||
/// Sent when the window is resized.
|
/// Sent when the window is resized.
|
||||||
Resize(TypedSize2D<DevicePixel, u32>),
|
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.
|
/// Sent when a new URL is to be loaded.
|
||||||
LoadUrl(String),
|
LoadUrl(String),
|
||||||
/// Sent when a mouse hit test is to be performed.
|
/// Sent when a mouse hit test is to be performed.
|
||||||
|
@ -81,6 +83,7 @@ impl Debug for WindowEvent {
|
||||||
WindowEvent::Refresh => write!(f, "Refresh"),
|
WindowEvent::Refresh => write!(f, "Refresh"),
|
||||||
WindowEvent::InitializeCompositing => write!(f, "InitializeCompositing"),
|
WindowEvent::InitializeCompositing => write!(f, "InitializeCompositing"),
|
||||||
WindowEvent::Resize(..) => write!(f, "Resize"),
|
WindowEvent::Resize(..) => write!(f, "Resize"),
|
||||||
|
WindowEvent::Viewport(..) => write!(f, "Viewport"),
|
||||||
WindowEvent::KeyEvent(..) => write!(f, "Key"),
|
WindowEvent::KeyEvent(..) => write!(f, "Key"),
|
||||||
WindowEvent::LoadUrl(..) => write!(f, "LoadUrl"),
|
WindowEvent::LoadUrl(..) => write!(f, "LoadUrl"),
|
||||||
WindowEvent::MouseWindowEventClass(..) => write!(f, "Mouse"),
|
WindowEvent::MouseWindowEventClass(..) => write!(f, "Mouse"),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue