Skip to content
This repository has been archived by the owner on Jun 26, 2021. It is now read-only.

Commit

Permalink
Update webrender
Browse files Browse the repository at this point in the history
  • Loading branch information
christolliday committed Feb 3, 2018
1 parent afd29f0 commit 7e5d7ec
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 34 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ limn-text_layout = { path = "text_layout", version = "0.0.1" }
limn-layout = { path = "layout", version = "0.0.1" }
cassowary = "0.3.0"

euclid = "0.15.1"
euclid = "0.16"
log = "0.3"
gleam = "0.4.15"
gleam = "0.4.20"

webrender = { git = "https://github.com/servo/webrender", rev = "bcdcd6aa7794e1421c70de639f2e14cad786a262" }
webrender = { git = "https://github.com/servo/webrender", rev = "c383ef73113d0d5f8634385565ce83a4c84ca944" }

stb_truetype = "0.2.1"
app_units = "0.5"
app_units = "0.6"
rusttype = "0.2.1"
glutin = "0.12.0"
image = "0.16"
Expand Down
16 changes: 8 additions & 8 deletions examples/clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use limn::webrender::api::*;
use limn::prelude::*;
use limn::draw::ellipse::EllipseState;

type Radians = euclid::Radians<f32>;
type Angle = euclid::Angle<f32>;

struct ClockTick;

Expand All @@ -25,7 +25,7 @@ pub struct ClockHand {
color: Color,
width: f32,
length: f32,
rotation: Radians,
rotation: Angle,
}

impl Default for ClockHand {
Expand All @@ -34,7 +34,7 @@ impl Default for ClockHand {
color: BLACK,
width: 0.0,
length: 0.0,
rotation: Radians::new(0.0),
rotation: Angle::radians(0.0),
}
}
}
Expand All @@ -46,7 +46,7 @@ impl Component for ClockHand {
}

impl ClockHand {
pub fn new(color: Color, width: f32, length: f32, rotation: Radians) -> Self {
pub fn new(color: Color, width: f32, length: f32, rotation: Angle) -> Self {
ClockHand {
color: color,
width: width,
Expand All @@ -59,7 +59,7 @@ impl ClockHand {
impl Draw for ClockHand {
fn draw(&mut self, bounds: Rect, _: Rect, renderer: &mut RenderBuilder) {
let transform = rotation_transform(&bounds.center(),
self.rotation + Radians::new(f32::consts::PI));
self.rotation + Angle::radians(f32::consts::PI));
renderer.builder.push_stacking_context(
&PrimitiveInfo::new(Rect::zero()),
ScrollPolicy::Fixed,
Expand All @@ -80,15 +80,15 @@ impl Draw for ClockHand {
}
}

fn rotation_transform(origin: &LayoutPoint, rotation: Radians) -> LayoutTransform {
fn rotation_transform(origin: &LayoutPoint, rotation: Angle) -> LayoutTransform {
let pre_transform = LayoutTransform::create_translation(origin.x, origin.y, 0.0);
let post_transform = LayoutTransform::create_translation(-origin.x, -origin.y, -0.0);
let transform = LayoutTransform::identity().pre_rotate(0.0, 0.0, 1.0, -rotation);
pre_transform.pre_mul(&transform).pre_mul(&post_transform)
}

fn rotation(fraction: f32) -> Radians {
Radians::new(2.0 * f32::consts::PI * fraction)
fn rotation(fraction: f32) -> Angle {
Angle::radians(2.0 * f32::consts::PI * fraction)
}

struct ClockBuilder {
Expand Down
2 changes: 1 addition & 1 deletion layout/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ homepage = "https://github.com/christolliday/limn"

[dependencies]
cassowary = "0.3.0"
euclid = "0.15.1"
euclid = "0.16"
log = "0.3"
lazy_static = "0.2.2"

Expand Down
7 changes: 4 additions & 3 deletions src/draw/glcanvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ impl GLCanvasState {
let data = ExternalImageData {
id: ExternalImageId(texture_id),
channel_index: 0,
image_type: ExternalImageType::Texture2DHandle,
image_type: ExternalImageType::TextureHandle(TextureTarget::Default),
};
let descriptor = ImageDescriptor::new(0, 0, ImageFormat::RGB8, true);
let descriptor = ImageDescriptor::new(0, 0, ImageFormat::BGRA8, true);
let image_info = resources().image_loader.create_image_resource(ImageData::External(data), descriptor);
GLCanvasState {
data: data,
Expand All @@ -45,7 +45,7 @@ impl Draw for GLCanvasState {
let descriptor = self.image_info.descriptor;
let (bounds_width, bounds_height) = (bounds.width() as u32, bounds.height() as u32);
if bounds_width != descriptor.width || bounds_height != descriptor.height {
let descriptor = ImageDescriptor::new(bounds_width, bounds_height, ImageFormat::RGB8, true);
let descriptor = ImageDescriptor::new(bounds_width, bounds_height, ImageFormat::BGRA8, true);
resources().image_loader.update_texture(self.image_info.key, descriptor, self.data);
self.image_info.descriptor = descriptor;
}
Expand All @@ -54,6 +54,7 @@ impl Draw for GLCanvasState {
bounds.size,
LayoutSize::zero(),
ImageRendering::Auto,
AlphaType::Alpha,
self.image_info.key,
);
}
Expand Down
1 change: 1 addition & 0 deletions src/draw/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ impl Draw for ImageState {
bounds.size,
LayoutSize::zero(),
ImageRendering::Auto,
AlphaType::Alpha,
key,
);
}
Expand Down
24 changes: 15 additions & 9 deletions src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ impl WebRenderContext {
let root_background_color = ColorF::new(0.8, 0.8, 0.8, 1.0);

let pipeline_id = PipelineId(0, 0);
api.set_root_pipeline(document_id, pipeline_id);
let mut txn = Transaction::new();
txn.set_root_pipeline(pipeline_id);
api.send_transaction(document_id, txn);

WebRenderContext {
renderer: renderer,
render_api: api,
Expand All @@ -85,18 +88,21 @@ impl WebRenderContext {
}
}
pub fn set_display_list(&mut self, builder: DisplayListBuilder, resources: ResourceUpdates, window_size: LayoutSize) {
self.render_api.set_display_list(
self.document_id,
let mut txn = Transaction::new();
txn.set_display_list(
self.epoch,
Some(self.root_background_color),
window_size,
builder.finalize(),
true,
resources
);
txn.update_resources(resources);
self.render_api.send_transaction(self.document_id, txn);
}
pub fn generate_frame(&mut self) {
self.render_api.generate_frame(self.document_id, None);
let mut txn = Transaction::new();
txn.generate_frame();
self.render_api.send_transaction(self.document_id, txn);
}
pub fn frame_ready(&mut self) -> bool {
self.frame_ready.load(atomic::Ordering::Acquire)
Expand Down Expand Up @@ -169,10 +175,10 @@ impl webrender::ExternalImageHandler for LimnExternalImageHandler {
fn lock(&mut self, key: ExternalImageId, _channel_index: u8) -> webrender::ExternalImage {
let descriptor = resources::resources().image_loader.texture_descriptors[&key.0];
webrender::ExternalImage {
u0: 0.0,
u1: descriptor.width as f32,
v1: 0.0,
v0: descriptor.height as f32,
uv: TexelRect {
uv0: TypedPoint2D::zero(),
uv1: TypedPoint2D::<f32, DevicePixel>::new(descriptor.width as f32, descriptor.height as f32),
},
source: webrender::ExternalImageSource::NativeTexture(key.0 as _),
}
}
Expand Down
12 changes: 5 additions & 7 deletions src/resources/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,10 @@ impl ImageLoader {
fn prepare_image(image: DynamicImage) -> Result<(ImageData, ImageDescriptor), Error> {
let image_dims = image.dimensions();
let format = match image {
image::ImageLuma8(_) => ImageFormat::A8,
image::ImageRgb8(_) => ImageFormat::RGB8,
image::ImageLuma8(_) => ImageFormat::R8,
image::ImageRgba8(_) => ImageFormat::BGRA8,
image::ImageLumaA8(_) => {
return Err(ImageError::UnsupportedError("ImageLumaA8 unsupported".to_string()).into());
_ => {
return Err(ImageError::UnsupportedError("ImageFormat unsupported".to_string()).into());
}
};
let mut bytes = image.raw_pixels();
Expand All @@ -153,9 +152,8 @@ fn is_image_opaque(format: ImageFormat, bytes: &[u8]) -> bool {
}
is_opaque
}
ImageFormat::RGB8 | ImageFormat::RG8 => true,
ImageFormat::A8 => false,
ImageFormat::Invalid | ImageFormat::RGBAF32 => unreachable!(),
ImageFormat::R8 => true,
_ => unreachable!(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/widget/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ impl Widget {

fn draw_widget(&mut self, crop_to: Rect, renderer: &mut RenderBuilder) {
let bounds = self.bounds();
let clip_id = renderer.builder.define_clip(None, bounds, vec![], None);
let clip_id = renderer.builder.define_clip(bounds, vec![], None);
renderer.builder.push_clip_id(clip_id);
for (_, modifier) in &self.widget().draw_modifiers {
modifier.push(renderer);
Expand Down
2 changes: 1 addition & 1 deletion text_layout/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ homepage = "https://github.com/christolliday/limn"

[dependencies]
rusttype = "0.2.1"
euclid = "0.15.1"
euclid = "0.16"

0 comments on commit 7e5d7ec

Please sign in to comment.