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

Use DeviceInt* instead of DeviceUint*. #3291

Merged
merged 1 commit into from Nov 15, 2018
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Use DeviceInt* instead of DeviceUint*.

We currently use a mix of both which can be untiddy at places and is error prone when doing intermediate computations that may go through negative values.
  • Loading branch information
nical authored and jrmuizel committed Nov 15, 2018
commit 5a384b918b0dfeaa40055d9cbfc85f5da9bbea08
@@ -34,7 +34,7 @@ fn main() {

let mut clicks: usize = 0;
let mut offset_y = 100.;
let size = api::DeviceUintSize::new;
let size = api::DeviceIntSize::new;
let mut rects = [
Rectangle::new(&composition, &notifier, factor, size(300, 200), 0., 0.2, 0.4, 1.),
Rectangle::new(&composition, &notifier, factor, size(400, 300), 0., 0.5, 0., 0.5),
@@ -95,15 +95,15 @@ struct Rectangle {
renderer: Option<webrender::Renderer>,
api: api::RenderApi,
document_id: api::DocumentId,
size: api::DeviceUintSize,
size: api::DeviceIntSize,
color: api::ColorF,
}

impl Rectangle {
fn new(composition: &DirectComposition, notifier: &Box<Notifier>,
device_pixel_ratio: f32, size: api::DeviceUintSize, r: f32, g: f32, b: f32, a: f32)
device_pixel_ratio: f32, size: api::DeviceIntSize, r: f32, g: f32, b: f32, a: f32)
-> Self {
let visual = composition.create_angle_visual(size.width, size.height);
let visual = composition.create_angle_visual(size.width as u32, size.height as u32);
visual.make_current();

let (renderer, sender) = webrender::Renderer::new(
@@ -25,7 +25,7 @@ impl Example for App {
_api: &RenderApi,
builder: &mut DisplayListBuilder,
_txn: &mut Transaction,
_framebuffer_size: DeviceUintSize,
_framebuffer_size: DeviceIntSize,
_pipeline_id: PipelineId,
_document_id: DocumentId,
) {
@@ -36,7 +36,7 @@ impl Example for App {
_api: &RenderApi,
builder: &mut DisplayListBuilder,
_txn: &mut Transaction,
_framebuffer_size: DeviceUintSize,
_framebuffer_size: DeviceIntSize,
_pipeline_id: PipelineId,
_document_id: DocumentId,
) {
@@ -185,7 +185,7 @@ impl Example for App {
api: &RenderApi,
builder: &mut DisplayListBuilder,
txn: &mut Transaction,
_: DeviceUintSize,
_: DeviceIntSize,
_pipeline_id: PipelineId,
_document_id: DocumentId,
) {
@@ -17,7 +17,7 @@ use rayon::prelude::*;
use std::collections::HashMap;
use std::sync::Arc;
use webrender::api::{self, DisplayListBuilder, DocumentId, PipelineId, RenderApi, Transaction};
use webrender::api::{ColorF, DeviceUintRect, DeviceUintPoint};
use webrender::api::{ColorF, DeviceIntRect, DeviceIntPoint};

// This example shows how to implement a very basic BlobImageHandler that can only render
// a checkerboard pattern.
@@ -65,8 +65,8 @@ fn render_blob(
for x in 0 .. descriptor.size.width {
// Apply the tile's offset. This is important: all drawing commands should be
// translated by this offset to give correct results with tiled blob images.
let x2 = x + descriptor.offset.x as u32;
let y2 = y + descriptor.offset.y as u32;
let x2 = x + descriptor.offset.x as i32;
let y2 = y + descriptor.offset.y as i32;

// Render a simple checkerboard pattern
let checker = if (x2 % 20 >= 10) != (y2 % 20 >= 10) {
@@ -98,8 +98,8 @@ fn render_blob(

Ok(api::RasterizedBlobImage {
data: Arc::new(texels),
rasterized_rect: DeviceUintRect {
origin: DeviceUintPoint::origin(),
rasterized_rect: DeviceIntRect {
origin: DeviceIntPoint::origin(),
size: descriptor.size,
},
})
@@ -135,7 +135,7 @@ impl api::BlobImageHandler for CheckerboardRenderer {
.insert(key, Arc::new(deserialize_blob(&cmds[..]).unwrap()));
}

fn update(&mut self, key: api::ImageKey, cmds: Arc<api::BlobImageData>, _dirty_rect: Option<api::DeviceUintRect>) {
fn update(&mut self, key: api::ImageKey, cmds: Arc<api::BlobImageData>, _dirty_rect: Option<api::DeviceIntRect>) {
// Here, updating is just replacing the current version of the commands with
// the new one (no incremental updates).
self.image_cmds
@@ -194,7 +194,7 @@ impl Example for App {
api: &RenderApi,
builder: &mut DisplayListBuilder,
txn: &mut Transaction,
_framebuffer_size: api::DeviceUintSize,
_framebuffer_size: api::DeviceIntSize,
_pipeline_id: PipelineId,
_document_id: DocumentId,
) {
@@ -78,7 +78,7 @@ pub trait Example {
api: &RenderApi,
builder: &mut DisplayListBuilder,
txn: &mut Transaction,
framebuffer_size: DeviceUintSize,
framebuffer_size: DeviceIntSize,
pipeline_id: PipelineId,
document_id: DocumentId,
);
@@ -162,7 +162,7 @@ pub fn main_wrapper<E: Example>(
.get_inner_size()
.unwrap()
.to_physical(device_pixel_ratio as f64);
DeviceUintSize::new(size.width as u32, size.height as u32)
DeviceIntSize::new(size.width as i32, size.height as i32)
};
let notifier = Box::new(Notifier::new(events_loop.create_proxy()));
let (mut renderer, sender) = webrender::Renderer::new(gl.clone(), notifier, opts, None).unwrap();
@@ -244,12 +244,12 @@ pub fn main_wrapper<E: Example>(
),
winit::VirtualKeyCode::Key1 => txn.set_window_parameters(
framebuffer_size,
DeviceUintRect::new(DeviceUintPoint::zero(), framebuffer_size),
DeviceIntRect::new(DeviceIntPoint::zero(), framebuffer_size),
1.0
),
winit::VirtualKeyCode::Key2 => txn.set_window_parameters(
framebuffer_size,
DeviceUintRect::new(DeviceUintPoint::zero(), framebuffer_size),
DeviceIntRect::new(DeviceIntPoint::zero(), framebuffer_size),
2.0
),
winit::VirtualKeyCode::M => api.notify_memory_pressure(),
@@ -12,5 +12,8 @@ pub fn make_checkerboard(width: u32, height: u32) -> (ImageDescriptor, ImageData
image_data.extend_from_slice(&[lum, lum, lum, 0xff]);
}
}
(ImageDescriptor::new(width, height, ImageFormat::BGRA8, true, false), ImageData::new(image_data))
(
ImageDescriptor::new(width as i32, height as i32, ImageFormat::BGRA8, true, false),
ImageData::new(image_data)
)
}
@@ -33,39 +33,39 @@ impl App {
fn init(
&mut self,
api: &RenderApi,
framebuffer_size: DeviceUintSize,
framebuffer_size: DeviceIntSize,
device_pixel_ratio: f32,
) {
let init_data = vec![
(
PipelineId(1, 0),
-1,
ColorF::new(0.0, 1.0, 0.0, 1.0),
DeviceUintPoint::new(0, 0),
DeviceIntPoint::new(0, 0),
),
(
PipelineId(2, 0),
-2,
ColorF::new(1.0, 1.0, 0.0, 1.0),
DeviceUintPoint::new(200, 0),
DeviceIntPoint::new(200, 0),
),
(
PipelineId(3, 0),
-3,
ColorF::new(1.0, 0.0, 0.0, 1.0),
DeviceUintPoint::new(200, 200),
DeviceIntPoint::new(200, 200),
),
(
PipelineId(4, 0),
-4,
ColorF::new(1.0, 0.0, 1.0, 1.0),
DeviceUintPoint::new(0, 200),
DeviceIntPoint::new(0, 200),
),
];

for (pipeline_id, layer, color, offset) in init_data {
let size = DeviceUintSize::new(250, 250);
let bounds = DeviceUintRect::new(offset, size);
let size = DeviceIntSize::new(250, 250);
let bounds = DeviceIntRect::new(offset, size);

let document_id = api.add_document(size, layer);
let mut txn = Transaction::new();
@@ -89,7 +89,7 @@ impl Example for App {
api: &RenderApi,
base_builder: &mut DisplayListBuilder,
_txn: &mut Transaction,
framebuffer_size: DeviceUintSize,
framebuffer_size: DeviceIntSize,
_: PipelineId,
_: DocumentId,
) {
@@ -68,7 +68,7 @@ impl App {
fn init_output_document(
&mut self,
api: &RenderApi,
framebuffer_size: DeviceUintSize,
framebuffer_size: DeviceIntSize,
device_pixel_ratio: f32,
) {
// Generate the external image key that will be used to render the output document to the root document.
@@ -77,7 +77,7 @@ impl App {
let pipeline_id = PipelineId(1, 0);
let layer = 1;
let color = ColorF::new(1., 1., 0., 1.);
let bounds = DeviceUintRect::new(DeviceUintPoint::zero(), framebuffer_size);
let bounds = DeviceIntRect::new(DeviceIntPoint::zero(), framebuffer_size);
let document_id = api.add_document(framebuffer_size, layer);

let document = Document {
@@ -144,14 +144,14 @@ impl Example for App {
api: &RenderApi,
builder: &mut DisplayListBuilder,
_txn: &mut Transaction,
framebuffer_size: DeviceUintSize,
framebuffer_size: DeviceIntSize,
_pipeline_id: PipelineId,
_document_id: DocumentId,
) {
if self.output_document.is_none() {
let device_pixel_ratio = framebuffer_size.width as f32 /
builder.content_size().width;
self.init_output_document(api, DeviceUintSize::new(200, 200), device_pixel_ratio);
self.init_output_document(api, DeviceIntSize::new(200, 200), device_pixel_ratio);
}

let info = LayoutPrimitiveInfo::new((100, 100).to(200, 200));
@@ -25,12 +25,12 @@ impl Example for App {
api: &RenderApi,
builder: &mut DisplayListBuilder,
_txn: &mut Transaction,
_framebuffer_size: DeviceUintSize,
_framebuffer_size: DeviceIntSize,
pipeline_id: PipelineId,
document_id: DocumentId,
) {
// All the sub_* things are for the nested pipeline
let sub_size = DeviceUintSize::new(100, 100);
let sub_size = DeviceIntSize::new(100, 100);
let sub_bounds = (0, 0).to(sub_size.width as i32, sub_size.height as i32);

let sub_pipeline_id = PipelineId(pipeline_id.0, 42);
@@ -25,7 +25,7 @@ impl Example for App {
_api: &RenderApi,
builder: &mut DisplayListBuilder,
txn: &mut Transaction,
_framebuffer_size: DeviceUintSize,
_framebuffer_size: DeviceIntSize,
_pipeline_id: PipelineId,
_document_id: DocumentId,
) {
@@ -102,7 +102,7 @@ impl Window {
.get_inner_size()
.unwrap()
.to_physical(device_pixel_ratio as f64);
DeviceUintSize::new(size.width as u32, size.height as u32)
DeviceIntSize::new(size.width as i32, size.height as i32)
};
let notifier = Box::new(Notifier::new(events_loop.create_proxy()));
let (renderer, sender) = webrender::Renderer::new(gl.clone(), notifier, opts, None).unwrap();
@@ -180,7 +180,7 @@ impl Window {
.get_inner_size()
.unwrap()
.to_physical(device_pixel_ratio as f64);
DeviceUintSize::new(size.width as u32, size.height as u32)
DeviceIntSize::new(size.width as i32, size.height as i32)
};
let layout_size = framebuffer_size.to_f32() / euclid::TypedScale::new(device_pixel_ratio);
let mut txn = Transaction::new();
@@ -26,7 +26,7 @@ impl Example for App {
_api: &RenderApi,
builder: &mut DisplayListBuilder,
_txn: &mut Transaction,
_framebuffer_size: DeviceUintSize,
_framebuffer_size: DeviceIntSize,
_pipeline_id: PipelineId,
_document_id: DocumentId,
) {
@@ -37,7 +37,7 @@ impl ImageGenerator {
}
}

fn generate_image(&mut self, size: u32) {
fn generate_image(&mut self, size: i32) {
let pattern = &self.patterns[self.next_pattern];
self.current_image.clear();
for y in 0 .. size {
@@ -67,7 +67,7 @@ impl webrender::ExternalImageHandler for ImageGenerator {
channel_index: u8,
_rendering: ImageRendering
) -> webrender::ExternalImage {
self.generate_image(channel_index as u32);
self.generate_image(channel_index as i32);
webrender::ExternalImage {
uv: TexelRect::new(0.0, 0.0, 1.0, 1.0),
source: webrender::ExternalImageSource::RawData(&self.current_image),
@@ -90,7 +90,7 @@ impl Example for App {
api: &RenderApi,
builder: &mut DisplayListBuilder,
txn: &mut Transaction,
_framebuffer_size: DeviceUintSize,
_framebuffer_size: DeviceIntSize,
_pipeline_id: PipelineId,
_document_id: DocumentId,
) {
@@ -87,7 +87,7 @@ impl Example for App {
api: &RenderApi,
builder: &mut DisplayListBuilder,
txn: &mut Transaction,
_framebuffer_size: DeviceUintSize,
_framebuffer_size: DeviceIntSize,
_pipeline_id: PipelineId,
_document_id: DocumentId,
) {
@@ -2,9 +2,9 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use api::{AlphaType, ClipMode, DeviceIntRect, DeviceIntSize};
use api::{DeviceUintRect, DeviceUintPoint, ExternalImageType, FilterOp, ImageRendering};
use api::{YuvColorSpace, YuvFormat, ColorDepth, PictureRect};
use api::{AlphaType, ClipMode, DeviceIntRect, DeviceIntPoint, DeviceIntSize};
use api::{ExternalImageType, FilterOp, ImageRendering};
use api::{YuvColorSpace, YuvFormat, PictureRect, ColorDepth};
use clip::{ClipDataStore, ClipNodeFlags, ClipNodeRange, ClipItem, ClipStore};
use clip_scroll_tree::{ClipScrollTree, ROOT_SPATIAL_NODE_INDEX, SpatialNodeIndex};
use glyph_rasterizer::GlyphFormat;
@@ -1995,8 +1995,8 @@ pub fn resolve_image(
let cache_item = CacheItem {
texture_id: TextureSource::External(external_image),
uv_rect_handle: cache_handle,
uv_rect: DeviceUintRect::new(
DeviceUintPoint::zero(),
uv_rect: DeviceIntRect::new(
DeviceIntPoint::zero(),
image_properties.descriptor.size,
),
texture_layer: 0,
@@ -8,6 +8,8 @@ use std::path::{Path, PathBuf};
use api::{CaptureBits, ExternalImageData, ImageDescriptor, TexelRect};
#[cfg(feature = "png")]
use device::ReadPixelsFormat;
#[cfg(feature = "png")]
use api::DeviceIntSize;
use ron;
use serde;

@@ -77,7 +79,7 @@ impl CaptureConfig {

#[cfg(feature = "png")]
pub fn save_png(
path: PathBuf, size: (u32, u32), format: ReadPixelsFormat, data: &[u8],
path: PathBuf, size: DeviceIntSize, format: ReadPixelsFormat, data: &[u8],
) {
use api::ImageFormat;
use png::{BitDepth, ColorType, Encoder, HasParameters};
@@ -97,7 +99,7 @@ impl CaptureConfig {
}
};
let w = BufWriter::new(File::create(path).unwrap());
let mut enc = Encoder::new(w, size.0, size.1);
let mut enc = Encoder::new(w, size.width as u32, size.height as u32);
enc
.set(color_type)
.set(BitDepth::Eight);
@@ -300,7 +300,7 @@ impl ClipNode {
&image_rect,
&visible_rect,
&device_image_size,
tile_size as u32,
tile_size as i32,
);
for tile in tiles {
resource_cache.request_image(
@@ -13,10 +13,10 @@ pub struct BakedGlyph {
pub xa: f32,
}

pub const FIRST_GLYPH_INDEX: u32 = 32;
pub const BMP_WIDTH: u32 = 128;
pub const BMP_HEIGHT: u32 = 128;
pub const FONT_SIZE: u32 = 19;
pub const FIRST_GLYPH_INDEX: i32 = 32;
pub const BMP_WIDTH: i32 = 128;
pub const BMP_HEIGHT: i32 = 128;
pub const FONT_SIZE: i32 = 19;

pub const GLYPHS: [BakedGlyph; 96] = [
BakedGlyph {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.