mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Use typed coordinates.
We use Size2D and Point2D across compositing, constellation and script, losing the type of pixels we use (DevicePixel, DeviceIndepententPixel or CSSPixel) along the way, which might lead to bugs like window.outerHeight not taking into account the page zoom (using DeviceIndepententPixel instead of CSSPixel).
This commit is contained in:
parent
b93f153ed5
commit
ac4614d6ce
10 changed files with 122 additions and 102 deletions
|
@ -6,7 +6,7 @@ use CompositionPipeline;
|
|||
use SendableFrameTree;
|
||||
use compositor_thread::{CompositorProxy, CompositorReceiver};
|
||||
use compositor_thread::{InitialCompositorState, Msg};
|
||||
use euclid::{TypedPoint2D, TypedVector2D, TypedScale};
|
||||
use euclid::{Length, TypedPoint2D, TypedVector2D, TypedScale};
|
||||
use gfx_traits::Epoch;
|
||||
use gleam::gl;
|
||||
use image::{DynamicImage, ImageFormat, RgbImage};
|
||||
|
@ -274,15 +274,15 @@ impl RenderTargetInfo {
|
|||
}
|
||||
}
|
||||
|
||||
fn initialize_png(gl: &gl::Gl, width: usize, height: usize) -> RenderTargetInfo {
|
||||
fn initialize_png(gl: &gl::Gl, width: Length<u32, DevicePixel>, height: Length<u32, DevicePixel>) -> RenderTargetInfo {
|
||||
let framebuffer_ids = gl.gen_framebuffers(1);
|
||||
gl.bind_framebuffer(gl::FRAMEBUFFER, framebuffer_ids[0]);
|
||||
|
||||
let texture_ids = gl.gen_textures(1);
|
||||
gl.bind_texture(gl::TEXTURE_2D, texture_ids[0]);
|
||||
|
||||
gl.tex_image_2d(gl::TEXTURE_2D, 0, gl::RGB as gl::GLint, width as gl::GLsizei,
|
||||
height as gl::GLsizei, 0, gl::RGB, gl::UNSIGNED_BYTE, None);
|
||||
gl.tex_image_2d(gl::TEXTURE_2D, 0, gl::RGB as gl::GLint, width.get() as gl::GLsizei,
|
||||
height.get() as gl::GLsizei, 0, gl::RGB, gl::UNSIGNED_BYTE, None);
|
||||
gl.tex_parameter_i(gl::TEXTURE_2D, gl::TEXTURE_MAG_FILTER, gl::NEAREST as gl::GLint);
|
||||
gl.tex_parameter_i(gl::TEXTURE_2D, gl::TEXTURE_MIN_FILTER, gl::NEAREST as gl::GLint);
|
||||
|
||||
|
@ -296,8 +296,8 @@ fn initialize_png(gl: &gl::Gl, width: usize, height: usize) -> RenderTargetInfo
|
|||
gl.bind_renderbuffer(gl::RENDERBUFFER, depth_rb);
|
||||
gl.renderbuffer_storage(gl::RENDERBUFFER,
|
||||
gl::DEPTH_COMPONENT24,
|
||||
width as gl::GLsizei,
|
||||
height as gl::GLsizei);
|
||||
width.get() as gl::GLsizei,
|
||||
height.get() as gl::GLsizei);
|
||||
gl.framebuffer_renderbuffer(gl::FRAMEBUFFER,
|
||||
gl::DEPTH_ATTACHMENT,
|
||||
gl::RENDERBUFFER,
|
||||
|
@ -646,9 +646,11 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
|||
device_pixel_ratio: dppx,
|
||||
initial_viewport: initial_viewport,
|
||||
};
|
||||
|
||||
let top_level_browsing_context_id = self.root_pipeline.as_ref().map(|pipeline| {
|
||||
pipeline.top_level_browsing_context_id
|
||||
});
|
||||
|
||||
let msg = ConstellationMsg::WindowSize(top_level_browsing_context_id, data, size_type);
|
||||
|
||||
if let Err(e) = self.constellation_chan.send(msg) {
|
||||
|
@ -1253,8 +1255,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
|||
fn composite_specific_target(&mut self,
|
||||
target: CompositeTarget)
|
||||
-> Result<Option<Image>, UnableToComposite> {
|
||||
let (width, height) =
|
||||
(self.frame_size.width as usize, self.frame_size.height as usize);
|
||||
let (width, height) = (self.frame_size.width_typed(), self.frame_size.height_typed());
|
||||
if !self.window.prepare_for_composite(width, height) {
|
||||
return Err(UnableToComposite::WindowUnprepared)
|
||||
}
|
||||
|
@ -1374,9 +1375,11 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
|||
|
||||
fn draw_img(&self,
|
||||
render_target_info: RenderTargetInfo,
|
||||
width: usize,
|
||||
height: usize)
|
||||
width: Length<u32, DevicePixel>,
|
||||
height: Length<u32, DevicePixel>)
|
||||
-> RgbImage {
|
||||
let width = width.get() as usize;
|
||||
let height = height.get() as usize;
|
||||
// For some reason, OSMesa fails to render on the 3rd
|
||||
// attempt in headless mode, under some conditions.
|
||||
// I think this can only be some kind of synchronization
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
use SendableFrameTree;
|
||||
use compositor::CompositingReason;
|
||||
use euclid::{Point2D, Size2D};
|
||||
use euclid::{TypedPoint2D, TypedSize2D};
|
||||
use gfx_traits::Epoch;
|
||||
use ipc_channel::ipc::IpcSender;
|
||||
use msg::constellation_msg::{Key, KeyModifiers, KeyState, PipelineId, TopLevelBrowsingContextId};
|
||||
|
@ -17,6 +17,7 @@ use script_traits::{AnimationState, ConstellationMsg, EventResult, LoadData};
|
|||
use servo_url::ServoUrl;
|
||||
use std::fmt::{Debug, Error, Formatter};
|
||||
use std::sync::mpsc::{Receiver, Sender};
|
||||
use style_traits::DevicePixel;
|
||||
use style_traits::cursor::CursorKind;
|
||||
use style_traits::viewport::ViewportConstraints;
|
||||
use webrender;
|
||||
|
@ -119,15 +120,16 @@ pub enum EmbedderMsg {
|
|||
/// Alerts the embedder that the current page has changed its title.
|
||||
ChangePageTitle(TopLevelBrowsingContextId, Option<String>),
|
||||
/// Move the window to a point
|
||||
MoveTo(TopLevelBrowsingContextId, Point2D<i32>),
|
||||
MoveTo(TopLevelBrowsingContextId, TypedPoint2D<i32, DevicePixel>),
|
||||
/// Resize the window to size
|
||||
ResizeTo(TopLevelBrowsingContextId, Size2D<u32>),
|
||||
ResizeTo(TopLevelBrowsingContextId, TypedSize2D<u32, DevicePixel>),
|
||||
/// Get Window Informations size and position
|
||||
GetClientWindow(TopLevelBrowsingContextId, IpcSender<(Size2D<u32>, Point2D<i32>)>),
|
||||
GetClientWindow(TopLevelBrowsingContextId,
|
||||
IpcSender<(TypedSize2D<u32, DevicePixel>, TypedPoint2D<i32, DevicePixel>)>),
|
||||
/// Get screen size (pixel)
|
||||
GetScreenSize(TopLevelBrowsingContextId, IpcSender<(Size2D<u32>)>),
|
||||
GetScreenSize(TopLevelBrowsingContextId, IpcSender<(TypedSize2D<u32, DevicePixel>)>),
|
||||
/// Get screen available size (pixel)
|
||||
GetScreenAvailSize(TopLevelBrowsingContextId, IpcSender<(Size2D<u32>)>),
|
||||
GetScreenAvailSize(TopLevelBrowsingContextId, IpcSender<(TypedSize2D<u32, DevicePixel>)>),
|
||||
/// Wether or not to follow a link
|
||||
AllowNavigation(TopLevelBrowsingContextId, ServoUrl, IpcSender<bool>),
|
||||
/// Sends an unconsumed key event back to the embedder.
|
||||
|
|
|
@ -5,8 +5,7 @@
|
|||
//! Abstract windowing methods. The concrete implementations of these can be found in `platform/`.
|
||||
|
||||
use compositor_thread::EventLoopWaker;
|
||||
use euclid::{Point2D, Size2D};
|
||||
use euclid::{TypedScale, TypedPoint2D, TypedSize2D};
|
||||
use euclid::{Length, TypedScale, TypedPoint2D, TypedSize2D};
|
||||
use gleam::gl;
|
||||
use ipc_channel::ipc::IpcSender;
|
||||
use msg::constellation_msg::{Key, KeyModifiers, KeyState, TopLevelBrowsingContextId, TraversalDirection};
|
||||
|
@ -123,21 +122,22 @@ pub trait WindowMethods {
|
|||
fn framebuffer_size(&self) -> DeviceUintSize;
|
||||
/// Returns the position and size of the window within the rendering area.
|
||||
fn window_rect(&self) -> DeviceUintRect;
|
||||
/// Returns the size of the window in density-independent "px" units.
|
||||
fn size(&self) -> TypedSize2D<f32, DeviceIndependentPixel>;
|
||||
/// Returns the size of the window.
|
||||
fn size(&self) -> TypedSize2D<f32, DevicePixel>;
|
||||
/// Presents the window to the screen (perhaps by page flipping).
|
||||
fn present(&self);
|
||||
|
||||
/// Return the size of the window with head and borders and position of the window values
|
||||
fn client_window(&self, ctx: TopLevelBrowsingContextId) -> (Size2D<u32>, Point2D<i32>);
|
||||
/// Return the size of the screen (pixel)
|
||||
fn screen_size(&self, ctx: TopLevelBrowsingContextId) -> Size2D<u32>;
|
||||
/// Return the available size of the screen (pixel)
|
||||
fn screen_avail_size(&self, ctx: TopLevelBrowsingContextId) -> Size2D<u32>;
|
||||
fn client_window(&self, ctx: TopLevelBrowsingContextId) ->
|
||||
(TypedSize2D<u32, DevicePixel>, TypedPoint2D<i32, DevicePixel>);
|
||||
/// Return the size of the screen.
|
||||
fn screen_size(&self, ctx: TopLevelBrowsingContextId) -> TypedSize2D<u32, DevicePixel>;
|
||||
/// Return the available size of the screen.
|
||||
fn screen_avail_size(&self, ctx: TopLevelBrowsingContextId) -> TypedSize2D<u32, DevicePixel>;
|
||||
/// Set the size inside of borders and head
|
||||
fn set_inner_size(&self, ctx: TopLevelBrowsingContextId, size: Size2D<u32>);
|
||||
fn set_inner_size(&self, ctx: TopLevelBrowsingContextId, size: TypedSize2D<u32, DevicePixel>);
|
||||
/// Set the window position
|
||||
fn set_position(&self, ctx: TopLevelBrowsingContextId, point: Point2D<i32>);
|
||||
fn set_position(&self, ctx: TopLevelBrowsingContextId, point: TypedPoint2D<i32, DevicePixel>);
|
||||
/// Set fullscreen state
|
||||
fn set_fullscreen_state(&self, ctx: TopLevelBrowsingContextId, state: bool);
|
||||
|
||||
|
@ -167,7 +167,7 @@ pub trait WindowMethods {
|
|||
/// Requests that the window system prepare a composite. Typically this will involve making
|
||||
/// some type of platform-specific graphics context current. Returns true if the composite may
|
||||
/// proceed and false if it should not.
|
||||
fn prepare_for_composite(&self, width: usize, height: usize) -> bool;
|
||||
fn prepare_for_composite(&self, width: Length<u32, DevicePixel>, height: Length<u32, DevicePixel>) -> bool;
|
||||
|
||||
/// Sets the cursor to be used in the window.
|
||||
fn set_cursor(&self, cursor: CursorKind);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue