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

Start texture atlases off small, and allow them to grow. #200

Merged
merged 2 commits into from Feb 26, 2016
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

Reenable border corner tessellation for monochromatic borders.

Multicolored borders aren't tessellated for now; this can be a followup.
  • Loading branch information
pcwalton committed Feb 25, 2016
commit bc254b1bd8ff7621efc382b14e1a01e34a9264e0
@@ -19,6 +19,7 @@ use std::collections::HashMap;
use std::collections::hash_map::Entry::{Occupied, Vacant};
use std::f32;
use std::hash::BuildHasherDefault;
use tessellator::{self, BorderCornerTessellation};
use texture_cache::{TextureCacheItem};
use util;
use util::RectVaryings;
@@ -1204,6 +1205,7 @@ impl<'a> BatchBuilder<'a> {
inner_radius: &Size2D<f32>,
resource_cache: &ResourceCache,
frame_id: FrameId,
can_tessellate: bool,
rotation_angle: BasicRotationAngle,
device_pixel_ratio: f32) {
if color0.a <= 0.0 && color1.a <= 0.0 {
@@ -1242,6 +1244,7 @@ impl<'a> BatchBuilder<'a> {
inner_radius,
resource_cache,
frame_id,
can_tessellate,
rotation_angle,
device_pixel_ratio);
self.add_solid_border_corner(&inner_corner_rect,
@@ -1252,6 +1255,7 @@ impl<'a> BatchBuilder<'a> {
inner_radius,
resource_cache,
frame_id,
can_tessellate,
rotation_angle,
device_pixel_ratio);

@@ -1337,6 +1341,7 @@ impl<'a> BatchBuilder<'a> {
&Size2D::new(0.0, 0.0),
resource_cache,
frame_id,
can_tessellate,
rotation_angle,
device_pixel_ratio);

@@ -1350,6 +1355,7 @@ impl<'a> BatchBuilder<'a> {
inner_radius,
resource_cache,
frame_id,
can_tessellate,
rotation_angle,
device_pixel_ratio);

@@ -1364,6 +1370,7 @@ impl<'a> BatchBuilder<'a> {
inner_radius,
resource_cache,
frame_id,
can_tessellate,
rotation_angle,
device_pixel_ratio)
}
@@ -1379,6 +1386,7 @@ impl<'a> BatchBuilder<'a> {
inner_radius: &Size2D<f32>,
resource_cache: &ResourceCache,
frame_id: FrameId,
can_tessellate: bool,
rotation_angle: BasicRotationAngle,
_device_pixel_ratio: f32) {
// TODO: Check for zero width/height borders!
@@ -1390,13 +1398,26 @@ impl<'a> BatchBuilder<'a> {
let dummy_mask_image = resource_cache.get_dummy_mask_image();

// Draw the rounded part of the corner.
//for rect_index in 0..tessellator::quad_count_for_border_corner(outer_radius,
// device_pixel_ratio) {
let tessellated_rect = outer_corner_rect;//.tessellate_border_corner(outer_radius,
// inner_radius,
// device_pixel_ratio,
// rotation_angle,
// rect_index);
let quad_count = if can_tessellate {
tessellator::quad_count_for_border_corner(outer_radius, self.device_pixel_ratio)
} else {
1
};
for rect_index in 0..quad_count {
let tessellated_rect;
let index;
if can_tessellate {
tessellated_rect =
outer_corner_rect.tessellate_border_corner(outer_radius,
inner_radius,
self.device_pixel_ratio,
rotation_angle,
rect_index);
index = Some(rect_index)
} else {
tessellated_rect = outer_corner_rect;
index = None
};

let outer_radius_x = DevicePixel::new(outer_radius.width, self.device_pixel_ratio);
let outer_radius_y = DevicePixel::new(outer_radius.height, self.device_pixel_ratio);
@@ -1408,7 +1429,7 @@ impl<'a> BatchBuilder<'a> {
inner_radius_x,
inner_radius_y,
false,
None,//Some(rect_index),
index,
ImageFormat::A8) {
Some(raster_item) => {
resource_cache.get_raster(&RasterItem::BorderRadius(raster_item), frame_id)
@@ -1433,7 +1454,7 @@ impl<'a> BatchBuilder<'a> {
color1,
resource_cache,
rotation_angle);
//}
}

// Draw the inner rect.
self.add_border_corner_piece(RectPolygon {
@@ -1590,6 +1611,8 @@ impl<'a> BatchBuilder<'a> {
let right_color = right.border_color(2.0/3.0, 1.0, 0.7, 0.3);
let bottom_color = bottom.border_color(2.0/3.0, 1.0, 0.7, 0.3);

let can_tessellate = tessellator::can_tessellate_border(info);

// Edges
self.add_border_edge(&Rect::new(Point2D::new(tl_outer.x, tl_inner.y),
Size2D::new(left.width, bl_inner.y - tl_inner.y)),
@@ -1638,6 +1661,7 @@ impl<'a> BatchBuilder<'a> {
&info.top_left_inner_radius(),
resource_cache,
frame_id,
can_tessellate,
BasicRotationAngle::Upright,
device_pixel_ratio);

@@ -1653,6 +1677,7 @@ impl<'a> BatchBuilder<'a> {
&info.top_right_inner_radius(),
resource_cache,
frame_id,
can_tessellate,
BasicRotationAngle::Clockwise90,
device_pixel_ratio);

@@ -1668,6 +1693,7 @@ impl<'a> BatchBuilder<'a> {
&info.bottom_right_inner_radius(),
resource_cache,
frame_id,
can_tessellate,
BasicRotationAngle::Clockwise180,
device_pixel_ratio);

@@ -1683,6 +1709,7 @@ impl<'a> BatchBuilder<'a> {
&info.bottom_left_inner_radius(),
resource_cache,
frame_id,
can_tessellate,
BasicRotationAngle::Clockwise270,
device_pixel_ratio);
}
@@ -14,6 +14,7 @@ use internal_types::{TextureUpdateDetails, TextureUpdateList, PackedVertex, Rend
use internal_types::{ORTHO_NEAR_PLANE, ORTHO_FAR_PLANE, DevicePixel};
use internal_types::{PackedVertexForTextureCacheUpdate, CompositionOp, ChildLayerIndex};
use internal_types::{AxisDirection, LowLevelFilterOp, DrawCommand, DrawLayer, ANGLE_FLOAT_TO_FIXED};
use internal_types::{BasicRotationAngle};
use ipc_channel::ipc;
use profiler::{Profiler, BackendProfileCounters};
use profiler::{RendererProfileTimers, RendererProfileCounters};
@@ -26,7 +27,7 @@ use std::path::PathBuf;
use std::sync::{Arc, Mutex};
use std::sync::mpsc::{channel, Receiver, Sender};
use std::thread;
//use tessellator::BorderCornerTessellation;
use tessellator::BorderCornerTessellation;
use texture_cache::{BorderType, TextureCache, TextureInsertOp};
use time::precise_time_ns;
use webrender_traits::{ColorF, Epoch, PipelineId, RenderNotifier};
@@ -661,7 +662,7 @@ impl Renderer {
outer_ry,
inner_rx,
inner_ry,
_index,
index,
inverted,
border_type) => {
// From here on out everything is in device coordinates.
@@ -678,6 +679,8 @@ impl Renderer {
let zero_point = Point2D::new(0.0, 0.0);
let zero_size = Size2D::new(0.0, 0.0);

let device_pixel_ratio = self.device_pixel_ratio;

self.add_rect_to_raster_batch(update.id,
TextureId(0),
border_program_id,
@@ -686,8 +689,30 @@ impl Renderer {
Size2D::new(width as u32, height as u32)),
border_type,
|texture_rect| {
let border_position = Point2D::new(texture_rect.origin.x + outer_rx.as_f32(),
texture_rect.origin.y + outer_ry.as_f32());
let border_radii_outer_size =
Size2D::new(border_radii_outer.x,
border_radii_outer.y);
let border_radii_inner_size =
Size2D::new(border_radii_inner.x,
border_radii_inner.y);
let untessellated_rect =
Rect::new(texture_rect.origin, border_radii_outer_size);
let tessellated_rect =
match index {
None => untessellated_rect,
Some(index) => {
untessellated_rect.tessellate_border_corner(
&border_radii_outer_size,
&border_radii_inner_size,
1.0,
BasicRotationAngle::Upright,
index)
}
};

let border_position =
untessellated_rect.bottom_right() -
(tessellated_rect.origin - texture_rect.origin);

[
PackedVertexForTextureCacheUpdate::new(
@@ -232,7 +232,8 @@ impl ResourceCache {
if !self.cached_rasters.contains_key(raster_item) {
let image_id = self.texture_cache.new_item_id();
self.texture_cache.insert_raster_op(image_id,
raster_item);
raster_item,
self.device_pixel_ratio);
self.cached_rasters.insert(raster_item.clone(), image_id, frame_id);
}
self.cached_rasters.mark_as_needed(raster_item, frame_id);
@@ -13,6 +13,7 @@ use resource_cache::ResourceCache;
use std::collections::{HashMap, HashSet};
use std::collections::hash_map::Entry::{Occupied, Vacant};
use std::hash::BuildHasherDefault;
use tessellator;
use webrender_traits::{BorderRadius, BorderStyle, BoxShadowClipMode, ImageRendering};
use webrender_traits::{FontKey, ImageFormat, ImageKey, SpecificDisplayItem};

@@ -203,42 +204,27 @@ impl BuildRequiredResources for AABBTreeNode {
}
}
SpecificDisplayItem::Border(ref info) => {
//for rect_index in 0..tessellator::quad_count_for_border_corner(
// &info.radius.top_left,
// resource_cache.device_pixel_ratio()) {
resource_list.add_radius_raster(&info.radius.top_left,
&info.top_left_inner_radius(),
false,
None,//Some(rect_index),
ImageFormat::A8);
//}
//for rect_index in 0..tessellator::quad_count_for_border_corner(
// &info.radius.top_right,
// resource_cache.device_pixel_ratio()) {
resource_list.add_radius_raster(&info.radius.top_right,
&info.top_right_inner_radius(),
false,
None,//Some(rect_index),
ImageFormat::A8);
//}
//for rect_index in 0..tessellator::quad_count_for_border_corner(
// &info.radius.bottom_left,
// resource_cache.device_pixel_ratio()) {
resource_list.add_radius_raster(&info.radius.bottom_left,
&info.bottom_left_inner_radius(),
false,
None,//Some(rect_index),
ImageFormat::A8);
//}
//for rect_index in 0..tessellator::quad_count_for_border_corner(
// &info.radius.bottom_right,
// resource_cache.device_pixel_ratio()) {
resource_list.add_radius_raster(&info.radius.bottom_right,
&info.bottom_right_inner_radius(),
false,
None,//Some(rect_index),
ImageFormat::A8);
//}
let can_tessellate = tessellator::can_tessellate_border(info);
add_border_radius_raster(&info.radius.top_left,
&info.top_left_inner_radius(),
can_tessellate,
resource_cache,
&mut resource_list);
add_border_radius_raster(&info.radius.top_right,
&info.top_right_inner_radius(),
can_tessellate,
resource_cache,
&mut resource_list);
add_border_radius_raster(&info.radius.bottom_right,
&info.bottom_right_inner_radius(),
can_tessellate,
resource_cache,
&mut resource_list);
add_border_radius_raster(&info.radius.bottom_left,
&info.bottom_left_inner_radius(),
can_tessellate,
resource_cache,
&mut resource_list);

if info.top.style == BorderStyle::Dotted {
resource_list.add_radius_raster(&Size2D::new(info.top.width / 2.0,
@@ -336,3 +322,29 @@ impl BuildRequiredResources for AABBTreeNode {
self.resource_list = Some(resource_list);
}
}

fn add_border_radius_raster(outer_radius: &Size2D<f32>,
inner_radius: &Size2D<f32>,
can_tessellate: bool,
resource_cache: &ResourceCache,
resource_list: &mut ResourceList) {
let quad_count = if can_tessellate {
tessellator::quad_count_for_border_corner(outer_radius,
resource_cache.device_pixel_ratio())
} else {
1
};
for rect_index in 0..quad_count {
let index = if can_tessellate {
Some(rect_index)
} else {
None
};
resource_list.add_radius_raster(outer_radius,
inner_radius,
false,
index,
ImageFormat::A8);
}
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.