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

Decoupled flattening from ResourceCache #1527

Merged
merged 1 commit into from Jul 27, 2017
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Decoupled flattening from ResourceCache

  • Loading branch information
kvark committed Jul 27, 2017
commit d73d42b49e7979b26f71f255e5099659237b4c09
@@ -17,7 +17,7 @@ use internal_types::{RendererFrame};
use frame_builder::{FrameBuilder, FrameBuilderConfig};
use mask_cache::ClipRegion;
use profiler::{GpuCacheProfileCounters, TextureCacheProfileCounters};
use resource_cache::ResourceCache;
use resource_cache::{ResourceCache, TiledImageMap};
use scene::{Scene, SceneProperties};
use std::cmp;
use std::collections::HashMap;
@@ -91,7 +91,7 @@ impl NestedDisplayListInfo {
struct FlattenContext<'a> {
scene: &'a Scene,
builder: &'a mut FrameBuilder,
resource_cache: &'a mut ResourceCache,
tiled_image_map: TiledImageMap,
replacements: Vec<(ClipId, ClipId)>,
nested_display_list_info: Vec<NestedDisplayListInfo>,
current_nested_display_list_index: u64,
@@ -100,12 +100,12 @@ struct FlattenContext<'a> {
impl<'a> FlattenContext<'a> {
fn new(scene: &'a Scene,
builder: &'a mut FrameBuilder,
resource_cache: &'a mut ResourceCache)
resource_cache: &ResourceCache)
-> FlattenContext<'a> {
FlattenContext {
scene,
builder,
resource_cache,
tiled_image_map: resource_cache.get_tiled_image_map(),
replacements: Vec::new(),
nested_display_list_info: Vec::new(),
current_nested_display_list_index: 0,
@@ -539,19 +539,16 @@ impl Frame {
info.context_id);
}
SpecificDisplayItem::Image(ref info) => {
let image = context.resource_cache.get_image_properties(info.image_key);
if let Some(tile_size) = image.tiling {
if let Some(tiling) = context.tiled_image_map.get(&info.image_key) {
// The image resource is tiled. We have to generate an image primitive
// for each tile.
let image_size = DeviceUintSize::new(image.descriptor.width,
image.descriptor.height);
self.decompose_image(clip_and_scroll,
context,
&mut context.builder,
&item_rect_with_offset,
&clip_with_offset,
info,
image_size,
tile_size as u32);
tiling.image_size,
tiling.tile_size as u32);
} else {
context.builder.add_image(clip_and_scroll,
item_rect_with_offset,
@@ -878,7 +875,7 @@ impl Frame {
/// takes care of the decomposition required by the internal tiling of the image.
fn decompose_image(&mut self,
clip_and_scroll: ClipAndScrollInfo,
context: &mut FlattenContext,
builder: &mut FrameBuilder,
item_rect: &LayerRect,
item_local_clip: &LocalClip,
info: &ImageDisplayItem,
@@ -888,7 +885,7 @@ impl Frame {
let no_vertical_spacing = info.tile_spacing.height == 0.0;
if no_vertical_tiling && no_vertical_spacing {
self.decompose_image_row(clip_and_scroll,
context,
builder,
item_rect,
item_local_clip,
info,
@@ -908,7 +905,7 @@ impl Frame {
info.stretch_size.height
).intersection(item_rect) {
self.decompose_image_row(clip_and_scroll,
context,
builder,
&row_rect,
item_local_clip,
info,
@@ -920,7 +917,7 @@ impl Frame {

fn decompose_image_row(&mut self,
clip_and_scroll: ClipAndScrollInfo,
context: &mut FlattenContext,
builder: &mut FrameBuilder,
item_rect: &LayerRect,
item_local_clip: &LocalClip,
info: &ImageDisplayItem,
@@ -930,7 +927,7 @@ impl Frame {
let no_horizontal_spacing = info.tile_spacing.width == 0.0;
if no_horizontal_tiling && no_horizontal_spacing {
self.decompose_tiled_image(clip_and_scroll,
context,
builder,
item_rect,
item_local_clip,
info,
@@ -950,7 +947,7 @@ impl Frame {
item_rect.size.height,
).intersection(item_rect) {
self.decompose_tiled_image(clip_and_scroll,
context,
builder,
&decomposed_rect,
item_local_clip,
info,
@@ -962,7 +959,7 @@ impl Frame {

fn decompose_tiled_image(&mut self,
clip_and_scroll: ClipAndScrollInfo,
context: &mut FlattenContext,
builder: &mut FrameBuilder,
item_rect: &LayerRect,
item_local_clip: &LocalClip,
info: &ImageDisplayItem,
@@ -1005,14 +1002,14 @@ impl Frame {
if info.stretch_size.width < item_rect.size.width {
// If this assert blows up it means we haven't properly decomposed the image in decompose_image_row.
debug_assert!(image_size.width <= tile_size);
// we don't actually tile in this dimmension so repeating can be done in the shader.
// we don't actually tile in this dimension so repeating can be done in the shader.
repeat_x = true;
}

if info.stretch_size.height < item_rect.size.height {
// If this assert blows up it means we haven't properly decomposed the image in decompose_image.
debug_assert!(image_size.height <= tile_size);
// we don't actually tile in this dimmension so repeating can be done in the shader.
// we don't actually tile in this dimension so repeating can be done in the shader.
repeat_y = true;
}

@@ -1041,7 +1038,7 @@ impl Frame {
for ty in 0..num_tiles_y {
for tx in 0..num_tiles_x {
self.add_tile_primitive(clip_and_scroll,
context,
builder,
item_rect,
item_local_clip,
info,
@@ -1053,7 +1050,7 @@ impl Frame {
if leftover.width != 0 {
// Tiles on the right edge that are smaller than the tile size.
self.add_tile_primitive(clip_and_scroll,
context,
builder,
item_rect,
item_local_clip,
info,
@@ -1069,7 +1066,7 @@ impl Frame {
for tx in 0..num_tiles_x {
// Tiles on the bottom edge that are smaller than the tile size.
self.add_tile_primitive(clip_and_scroll,
context,
builder,
item_rect,
item_local_clip,
info,
@@ -1084,7 +1081,7 @@ impl Frame {
if leftover.width != 0 {
// Finally, the bottom-right tile with a "leftover" size.
self.add_tile_primitive(clip_and_scroll,
context,
builder,
item_rect,
item_local_clip,
info,
@@ -1100,7 +1097,7 @@ impl Frame {

fn add_tile_primitive(&mut self,
clip_and_scroll: ClipAndScrollInfo,
context: &mut FlattenContext,
builder: &mut FrameBuilder,
item_rect: &LayerRect,
item_local_clip: &LocalClip,
info: &ImageDisplayItem,
@@ -1144,15 +1141,15 @@ impl Frame {

// Fix up the primitive's rect if it overflows the original item rect.
if let Some(prim_rect) = prim_rect.intersection(item_rect) {
context.builder.add_image(clip_and_scroll,
prim_rect,
item_local_clip,
&stretched_size,
&info.tile_spacing,
None,
info.image_key,
info.image_rendering,
Some(tile_offset));
builder.add_image(clip_and_scroll,
prim_rect,
item_local_clip,
&stretched_size,
&info.tile_spacing,
None,
info.image_key,
info.image_rendering,
Some(tile_offset));
}
}

@@ -16,13 +16,14 @@ use std::hash::Hash;
use std::mem;
use std::sync::Arc;
use texture_cache::{TextureCache, TextureCacheItemId};
use api::{Epoch, FontInstanceKey, FontKey, FontTemplate, GlyphKey, ImageKey, ImageRendering};
use api::{ImageData, GlyphDimensions, WebGLContextId, IdNamespace};
use api::{DevicePoint, DeviceIntSize, DeviceUintRect, ImageDescriptor};
use api::{GlyphInstance, SubpixelPoint, TileOffset, TileSize};
use api::{BlobImageRenderer, BlobImageDescriptor, BlobImageError, BlobImageRequest, BlobImageData};
use api::BlobImageResources;
use api::{ExternalImageData, ExternalImageType, LayoutPoint};
use api::{BlobImageRenderer, BlobImageDescriptor, BlobImageError, BlobImageRequest};
use api::{BlobImageResources, BlobImageData};
use api::{DevicePoint, DeviceIntSize, DeviceUintRect, DeviceUintSize};
use api::{Epoch, FontInstanceKey, FontKey, FontTemplate};
use api::{GlyphDimensions, GlyphKey, GlyphInstance, IdNamespace};
use api::{ImageData, ImageDescriptor, ImageKey, ImageRendering, LayoutPoint};
use api::{SubpixelPoint, TileOffset, TileSize};
use api::{ExternalImageData, ExternalImageType, WebGLContextId};
use rayon::ThreadPool;
use glyph_rasterizer::{GlyphRasterizer, GlyphCache, GlyphRequest};

@@ -65,6 +66,14 @@ struct ImageResource {
dirty_rect: Option<DeviceUintRect>
}

#[derive(Debug)]
pub struct ImageTiling {
pub image_size: DeviceUintSize,
pub tile_size: TileSize,
}

pub type TiledImageMap = HashMap<ImageKey, ImageTiling, BuildHasherDefault<FnvHasher>>;

struct ImageTemplates {
images: HashMap<ImageKey, ImageResource, BuildHasherDefault<FnvHasher>>,
}
@@ -574,6 +583,16 @@ impl ResourceCache {
}
}

pub fn get_tiled_image_map(&self) -> TiledImageMap {
self.resources.image_templates.images.iter().filter_map(|(&key, template)|
template.tiling.map(|tile_size| (key, ImageTiling {
image_size: DeviceUintSize::new(template.descriptor.width,
template.descriptor.height),
tile_size,
}))
).collect()
}

pub fn get_webgl_texture(&self, context_id: &WebGLContextId) -> &WebGLTexture {
&self.webgl_textures[context_id]
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.