Skip to content
This repository was archived by the owner on Jul 10, 2023. It is now read-only.

start tidying #233

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 49 additions & 42 deletions src/layers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ known_heap_size!(0, ContentAge);

impl ContentAge {
pub fn new() -> ContentAge {
ContentAge {
age: 0,
}
ContentAge { age: 0 }
}

pub fn next(&mut self) {
Expand Down Expand Up @@ -103,15 +101,16 @@ pub struct Layer<T> {
}

impl<T> Layer<T> {
pub fn new(bounds: TypedRect<f32, LayerPixel>,
tile_size: usize,
background_color: Color,
opacity: f32,
establishes_3d_context: bool,
data: T)
-> Layer<T> {
pub fn new(
bounds: TypedRect<f32, LayerPixel>,
tile_size: usize,
background_color: Color,
opacity: f32,
establishes_3d_context: bool,
data: T,
) -> Layer<T> {
Layer {
children: RefCell::new(vec!()),
children: RefCell::new(vec![]),
transform: RefCell::new(Matrix4D::identity()),
perspective: RefCell::new(Matrix4D::identity()),
bounds: RefCell::new(bounds),
Expand Down Expand Up @@ -142,19 +141,21 @@ impl<T> Layer<T> {

/// Returns buffer requests inside the given dirty rect, and simultaneously throws out tiles
/// outside the given viewport rect.
pub fn get_buffer_requests(&self,
rect_in_layer: TypedRect<f32, LayerPixel>,
viewport_in_layer: TypedRect<f32, LayerPixel>,
scale: ScaleFactor<f32, LayerPixel, DevicePixel>)
-> Vec<BufferRequest> {
pub fn get_buffer_requests(
&self,
rect_in_layer: TypedRect<f32, LayerPixel>,
viewport_in_layer: TypedRect<f32, LayerPixel>,
scale: ScaleFactor<f32, LayerPixel, DevicePixel>,
) -> Vec<BufferRequest> {
let mut tile_grid = self.tile_grid.borrow_mut();
tile_grid.get_buffer_requests_in_rect(rect_in_layer * scale,
viewport_in_layer * scale,
self.bounds.borrow().size * scale,
&(self.transform_state.borrow().world_rect.origin *
scale.get()),
&self.transform_state.borrow().final_transform,
*self.content_age.borrow())
tile_grid.get_buffer_requests_in_rect(
rect_in_layer * scale,
viewport_in_layer * scale,
self.bounds.borrow().size * scale,
&(self.transform_state.borrow().world_rect.origin * scale.get()),
&self.transform_state.borrow().final_transform,
*self.content_age.borrow(),
)
}

pub fn resize(&self, new_size: TypedSize2D<f32, LayerPixel>) {
Expand Down Expand Up @@ -185,14 +186,14 @@ impl<T> Layer<T> {
self.tile_grid.borrow().do_for_all_tiles(f);
}

pub fn update_transform_state(&self,
parent_transform: &Matrix4D<f32>,
parent_perspective: &Matrix4D<f32>,
parent_origin: &Point2D<f32>) {
pub fn update_transform_state(
&self,
parent_transform: &Matrix4D<f32>,
parent_perspective: &Matrix4D<f32>,
parent_origin: &Point2D<f32>,
) {
let mut ts = self.transform_state.borrow_mut();
let rect_without_scroll = self.bounds.borrow()
.to_untyped()
.translate(parent_origin);
let rect_without_scroll = self.bounds.borrow().to_untyped().translate(parent_origin);

ts.world_rect = rect_without_scroll.translate(&self.content_offset.borrow().to_untyped());

Expand All @@ -205,9 +206,9 @@ impl<T> Layer<T> {
.pre_mul(&*self.transform.borrow())
.pre_translated(-x0, -y0, 0.0);

ts.final_transform = parent_perspective
.pre_mul(&local_transform)
.pre_mul(&parent_transform);
ts.final_transform = parent_perspective.pre_mul(&local_transform).pre_mul(
&parent_transform,
);
ts.screen_rect = project_rect_to_screen(&ts.world_rect, &ts.final_transform);

// TODO(gw): This is quite bogus. It's a hack to allow the paint task
Expand All @@ -224,18 +225,21 @@ impl<T> Layer<T> {
.pre_translated(-x0, -y0, 0.0);

for child in self.children().iter() {
child.update_transform_state(&ts.final_transform,
&perspective_transform,
&rect_without_scroll.origin);
child.update_transform_state(
&ts.final_transform,
&perspective_transform,
&rect_without_scroll.origin,
);
}
}

/// Calculate the amount of memory used by this layer and all its children.
/// The memory may be allocated on the heap or in GPU memory.
pub fn get_memory_usage(&self) -> usize {
let size_of_children : usize = self.children().iter().map(|ref child| -> usize {
child.get_memory_usage()
}).sum();
let size_of_children: usize = self.children()
.iter()
.map(|ref child| -> usize { child.get_memory_usage() })
.sum();
size_of_children + self.tile_grid.borrow().get_memory_usage()
}
}
Expand All @@ -256,8 +260,11 @@ pub struct BufferRequest {
}

impl BufferRequest {
pub fn new(screen_rect: Rect<usize>, page_rect: Rect<f32>, content_age: ContentAge)
-> BufferRequest {
pub fn new(
screen_rect: Rect<usize>,
page_rect: Rect<f32>,
content_age: ContentAge,
) -> BufferRequest {
BufferRequest {
screen_rect: screen_rect,
page_rect: page_rect,
Expand Down Expand Up @@ -320,7 +327,7 @@ impl LayerBuffer {
/// A set of layer buffers. This is an atomic unit used to switch between the front and back
/// buffers.
pub struct LayerBufferSet {
pub buffers: Vec<Box<LayerBuffer>>
pub buffers: Vec<Box<LayerBuffer>>,
}

impl LayerBufferSet {
Expand Down
20 changes: 10 additions & 10 deletions src/lib.rs
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ extern crate rustc_serialize;
extern crate gleam;
extern crate skia;

#[cfg(target_os="macos")]
#[cfg(target_os = "macos")]
extern crate core_foundation;
#[cfg(target_os="macos")]
#[cfg(target_os = "macos")]
extern crate io_surface;
#[cfg(target_os="macos")]
#[cfg(target_os = "macos")]
extern crate cgl;

#[cfg(target_os="linux")]
#[cfg(target_os = "linux")]
extern crate x11;
#[cfg(target_os="linux")]
#[cfg(target_os = "linux")]
extern crate glx;

#[cfg(any(target_os = "linux", target_os = "android"))]
Expand All @@ -46,23 +46,23 @@ pub mod tiling;
pub mod util;

pub mod platform {
#[cfg(target_os="linux")]
#[cfg(target_os = "linux")]
pub mod linux {
pub mod surface;
}
#[cfg(target_os="macos")]
#[cfg(target_os = "macos")]
pub mod macos {
pub mod surface;
}
#[cfg(target_os="android")]
#[cfg(target_os = "android")]
pub mod android {
pub mod surface;
}
#[cfg(any(target_os="android",target_os="linux"))]
#[cfg(any(target_os = "android", target_os = "linux"))]
pub mod egl {
pub mod surface;
}
#[cfg(target_os="windows")]
#[cfg(target_os = "windows")]
pub mod windows {
pub mod surface;
}
Expand Down
56 changes: 28 additions & 28 deletions src/platform/android/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use std::vec::Vec;
/// buffer. EGLImageKHR is used to GPU rendering and vector is used to CPU rendering. EGL
/// extension seems not provide simple way to accessing its bitmap directly. In the
/// future, we need to find out the way to integrate them.

#[derive(Clone, Copy)]
pub struct NativeDisplay {
pub display: EGLDisplay,
Expand All @@ -40,15 +39,11 @@ impl NativeDisplay {
}

pub fn new_with_display(display: EGLDisplay) -> NativeDisplay {
NativeDisplay {
display: display,
}
NativeDisplay { display: display }
}

pub fn platform_display_data(&self) -> PlatformDisplayData {
PlatformDisplayData {
display: self.display,
}
PlatformDisplayData { display: self.display }
}
}

Expand Down Expand Up @@ -85,25 +80,29 @@ impl EGLImageNativeSurface {
pub fn bind_to_texture(&self, _: &NativeDisplay, texture: &Texture) {
let _bound = texture.bind();
match self.image {
None => match self.bitmap {
Some(ref bitmap) => {
let data = bitmap.as_ptr() as *const c_void;
unsafe {
TexImage2D(TEXTURE_2D,
0,
BGRA_EXT as i32,
self.size.width as i32,
self.size.height as i32,
0,
BGRA_EXT as u32,
UNSIGNED_BYTE,
data);
None => {
match self.bitmap {
Some(ref bitmap) => {
let data = bitmap.as_ptr() as *const c_void;
unsafe {
TexImage2D(
TEXTURE_2D,
0,
BGRA_EXT as i32,
self.size.width as i32,
self.size.height as i32,
0,
BGRA_EXT as u32,
UNSIGNED_BYTE,
data,
);
}
}
None => {
debug!("Cannot bind the buffer(CPU rendering), there is no bitmap");
}
}
None => {
debug!("Cannot bind the buffer(CPU rendering), there is no bitmap");
}
},
}
Some(image_khr) => {
egl_image_target_texture2d_oes(TEXTURE_2D, image_khr as *const c_void);
}
Expand Down Expand Up @@ -132,7 +131,7 @@ impl EGLImageNativeSurface {

pub fn destroy(&mut self, graphics_context: &NativeDisplay) {
match self.image {
None => {},
None => {}
Some(image_khr) => {
DestroyImageKHR(graphics_context.display, image_khr);
mem::replace(&mut self.image, None);
Expand All @@ -149,9 +148,10 @@ impl EGLImageNativeSurface {
self.will_leak = false
}

pub fn gl_rasterization_context(&mut self,
gl_context: Arc<GLContext>)
-> Option<GLRasterizationContext> {
pub fn gl_rasterization_context(
&mut self,
gl_context: Arc<GLContext>,
) -> Option<GLRasterizationContext> {
// TODO: Eventually we should preserve the previous GLRasterizationContext,
// so that we don't have to keep destroying and recreating the image.
if let Some(egl_image) = self.image.take() {
Expand Down
51 changes: 28 additions & 23 deletions src/platform/egl/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ const GL_FORMAT_BGRA: gl::GLuint = gl::BGRA;
#[cfg(any(target_os = "android", target_os = "gonk"))]
const GL_FORMAT_BGRA: gl::GLuint = gl::BGRA_EXT;

#[cfg(target_os="linux")]
#[cfg(target_os = "linux")]
pub use platform::linux::surface::NativeDisplay;

#[cfg(target_os="android")]
#[cfg(target_os = "android")]
pub use platform::android::surface::NativeDisplay;

pub struct EGLImageNativeSurface {
Expand Down Expand Up @@ -68,25 +68,29 @@ impl EGLImageNativeSurface {
pub fn bind_to_texture(&self, _: &NativeDisplay, texture: &Texture) {
let _bound = texture.bind();
match self.image {
None => match self.bitmap {
Some(ref bitmap) => {
let data = bitmap.as_ptr() as *const c_void;
unsafe {
TexImage2D(TEXTURE_2D,
0,
GL_FORMAT_BGRA as i32,
self.size.width as i32,
self.size.height as i32,
0,
GL_FORMAT_BGRA as u32,
UNSIGNED_BYTE,
data);
}
}
None => {
debug!("Cannot bind the buffer(CPU rendering), there is no bitmap");
None => {
match self.bitmap {
Some(ref bitmap) => {
let data = bitmap.as_ptr() as *const c_void;
unsafe {
TexImage2D(
TEXTURE_2D,
0,
GL_FORMAT_BGRA as i32,
self.size.width as i32,
self.size.height as i32,
0,
GL_FORMAT_BGRA as u32,
UNSIGNED_BYTE,
data,
);
}
}
None => {
debug!("Cannot bind the buffer(CPU rendering), there is no bitmap");
}
}
},
}
Some(_image_khr) => {
panic!("TODO: Support GPU rasterizer path on EGL");
}
Expand Down Expand Up @@ -128,9 +132,10 @@ impl EGLImageNativeSurface {
self.will_leak = false
}

pub fn gl_rasterization_context(&mut self,
_gl_context: Arc<GLContext>)
-> Option<GLRasterizationContext> {
pub fn gl_rasterization_context(
&mut self,
_gl_context: Arc<GLContext>,
) -> Option<GLRasterizationContext> {
panic!("TODO: Support GL context on EGL");
}
}
Loading