Skip to content
Merged
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
78 changes: 54 additions & 24 deletions webrender/src/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use clip::{ClipSource, ClipStore, ClipWorkItem};
use clip_scroll_tree::{CoordinateSystemId};
use euclid::{TypedTransform3D, vec3};
use glyph_rasterizer::GlyphFormat;
use gpu_cache::{GpuCache, GpuCacheAddress, GpuCacheHandle};
use gpu_cache::{GpuCache, GpuCacheAddress};
use gpu_types::{BrushFlags, BrushInstance, ClipChainRectIndex, ZBufferId, ZBufferIdGenerator};
use gpu_types::{ClipMaskInstance, ClipScrollNodeIndex, RasterizationSpace};
use gpu_types::{CompositePrimitiveInstance, PrimitiveInstance, SimplePrimitiveInstance};
Expand Down Expand Up @@ -677,7 +677,12 @@ impl AlphaBatchBuilder {
let kind = BatchKind::Brush(
BrushBatchKind::Image(ImageBufferKind::Texture2DArray)
);
let (uv_rect_address, textures) = surface.resolve(render_tasks);
let (uv_rect_address, textures) = surface
.resolve(
render_tasks,
ctx.resource_cache,
gpu_cache,
);
let key = BatchKey::new(
kind,
non_segmented_blend_mode,
Expand All @@ -696,7 +701,7 @@ impl AlphaBatchBuilder {
edge_flags: EdgeAaSegmentMask::empty(),
brush_flags: BrushFlags::empty(),
user_data: [
uv_rect_address.as_int(gpu_cache),
uv_rect_address.as_int(),
(BrushImageSourceKind::Color as i32) << 16 |
RasterizationSpace::Screen as i32,
picture.extra_gpu_data_handle.as_int(gpu_cache),
Expand Down Expand Up @@ -742,11 +747,11 @@ impl AlphaBatchBuilder {
// Retrieve the UV rect addresses for shadow/content.
let cache_task_id = surface.resolve_render_task_id();
let shadow_uv_rect_address = render_tasks[cache_task_id]
.get_texture_handle()
.as_int(gpu_cache);
.get_texture_address(gpu_cache)
.as_int();
let content_uv_rect_address = render_tasks[secondary_id]
.get_texture_handle()
.as_int(gpu_cache);
.get_texture_address(gpu_cache)
.as_int();

// Get the GPU cache address of the extra data handle.
let extra_data_address = gpu_cache.get_address(&picture.extra_gpu_data_handle);
Expand Down Expand Up @@ -933,8 +938,8 @@ impl AlphaBatchBuilder {
);

let uv_rect_address = render_tasks[cache_task_id]
.get_texture_handle()
.as_int(gpu_cache);
.get_texture_address(gpu_cache)
.as_int();

let instance = BrushInstance {
picture_address: task_address,
Expand Down Expand Up @@ -1077,8 +1082,14 @@ impl AlphaBatchBuilder {
deferred_resolves,
)
}
ImageSource::Cache { ref item, .. } => {
item.clone()
ImageSource::Cache { ref handle, .. } => {
let rt_handle = handle
.as_ref()
.expect("bug: render task handle not allocated");
let rt_cache_entry = ctx
.resource_cache
.get_cached_render_task(rt_handle);
ctx.resource_cache.get_texture_cache_item(&rt_cache_entry.handle)
}
};

Expand Down Expand Up @@ -1296,7 +1307,6 @@ impl BrushPrimitive {
) -> Option<(BrushBatchKind, BatchTextures, [i32; 3])> {
match self.kind {
BrushKind::Image { request, ref source, .. } => {

let cache_item = match *source {
ImageSource::Default => {
resolve_image(
Expand All @@ -1306,8 +1316,13 @@ impl BrushPrimitive {
deferred_resolves,
)
}
ImageSource::Cache { ref item, .. } => {
item.clone()
ImageSource::Cache { ref handle, .. } => {
let rt_handle = handle
.as_ref()
.expect("bug: render task handle not allocated");
let rt_cache_entry = resource_cache
.get_cached_render_task(rt_handle);
resource_cache.get_texture_cache_item(&rt_cache_entry.handle)
}
};

Expand Down Expand Up @@ -1477,20 +1492,27 @@ impl AlphaBatchHelpers for PrimitiveStore {

impl PictureSurface {
// Retrieve the uv rect handle, and texture for a picture surface.
fn resolve<'a>(
&'a self,
render_tasks: &'a RenderTaskTree,
) -> (&'a GpuCacheHandle, BatchTextures) {
fn resolve(
&self,
render_tasks: &RenderTaskTree,
resource_cache: &ResourceCache,
gpu_cache: &GpuCache,
) -> (GpuCacheAddress, BatchTextures) {
match *self {
PictureSurface::TextureCache(ref cache_item) => {
PictureSurface::TextureCache(ref handle) => {
let rt_cache_entry = resource_cache
.get_cached_render_task(handle);
let cache_item = resource_cache
.get_texture_cache_item(&rt_cache_entry.handle);

(
&cache_item.uv_rect_handle,
gpu_cache.get_address(&cache_item.uv_rect_handle),
BatchTextures::color(cache_item.texture_id),
)
}
PictureSurface::RenderTask(task_id) => {
(
render_tasks[task_id].get_texture_handle(),
render_tasks[task_id].get_texture_address(gpu_cache),
BatchTextures::render_target_cache(),
)
}
Expand Down Expand Up @@ -1690,14 +1712,22 @@ impl ClipBatcher {
});
}
ClipSource::BoxShadow(ref info) => {
debug_assert_ne!(info.cache_item.texture_id, SourceTexture::Invalid);
let rt_handle = info
.cache_handle
.as_ref()
.expect("bug: render task handle not allocated");
let rt_cache_entry = resource_cache
.get_cached_render_task(rt_handle);
let cache_item = resource_cache
.get_texture_cache_item(&rt_cache_entry.handle);
debug_assert_ne!(cache_item.texture_id, SourceTexture::Invalid);

self.box_shadows
.entry(info.cache_item.texture_id)
.entry(cache_item.texture_id)
.or_insert(Vec::new())
.push(ClipMaskInstance {
clip_data_address: gpu_address,
resource_address: gpu_cache.get_address(&info.cache_item.uv_rect_handle),
resource_address: gpu_cache.get_address(&cache_item.uv_rect_handle),
..instance
});
}
Expand Down
4 changes: 2 additions & 2 deletions webrender/src/box_shadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use gpu_cache::GpuCacheHandle;
use gpu_types::BoxShadowStretchMode;
use prim_store::{BrushKind, BrushPrimitive, PrimitiveContainer};
use prim_store::ScrollNodeAndClipChain;
use resource_cache::CacheItem;
use render_task::RenderTaskCacheEntryHandle;
use util::RectHelpers;

#[derive(Debug)]
Expand All @@ -25,7 +25,7 @@ pub struct BoxShadowClipSource {
// The current cache key (in device-pixels), and handles
// to the cached clip region and blurred texture.
pub cache_key: Option<(DeviceIntSize, BoxShadowCacheKey)>,
pub cache_item: CacheItem,
pub cache_handle: Option<RenderTaskCacheEntryHandle>,
pub clip_data_handle: GpuCacheHandle,

// Local-space size of the required render task size.
Expand Down
13 changes: 8 additions & 5 deletions webrender/src/clip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ use gpu_cache::{GpuCache, GpuCacheHandle, ToGpuBlocks};
use gpu_types::{BoxShadowStretchMode, ClipScrollNodeIndex};
use prim_store::{ClipData, ImageMaskData};
use render_task::to_cache_size;
use resource_cache::{CacheItem, ImageRequest, ResourceCache};
use resource_cache::{ImageRequest, ResourceCache};
use util::{LayerToWorldFastTransform, MaxRect, calculate_screen_bounding_rect};
use util::{extract_inner_rect_safe, pack_as_float};
use std::sync::Arc;

pub type ClipStore = FreeList<ClipSources>;
pub type ClipSourcesHandle = FreeListHandle<ClipSources>;
pub type ClipSourcesWeakHandle = WeakFreeListHandle<ClipSources>;
#[derive(Debug)]
pub enum ClipStoreMarker {}

pub type ClipStore = FreeList<ClipSources, ClipStoreMarker>;
pub type ClipSourcesHandle = FreeListHandle<ClipStoreMarker>;
pub type ClipSourcesWeakHandle = WeakFreeListHandle<ClipStoreMarker>;

#[derive(Debug)]
pub struct LineDecorationClipSource {
Expand Down Expand Up @@ -237,7 +240,7 @@ impl ClipSource {
clip_mode,
stretch_mode_x,
stretch_mode_y,
cache_item: CacheItem::invalid(),
cache_handle: None,
cache_key: None,
clip_data_handle: GpuCacheHandle::new(),
minimal_shadow_rect,
Expand Down
2 changes: 1 addition & 1 deletion webrender/src/frame_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ impl FrameBuilder {

let gpu_cache_frame_id = gpu_cache.end_frame(gpu_cache_profile);

render_tasks.build();
render_tasks.write_task_data();

resource_cache.end_frame();

Expand Down
41 changes: 22 additions & 19 deletions webrender/src/freelist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ struct Epoch(u32);
#[derive(Debug)]
#[cfg_attr(feature = "capture", derive(Serialize))]
#[cfg_attr(feature = "replay", derive(Deserialize))]
pub struct FreeListHandle<T> {
pub struct FreeListHandle<M> {
index: u32,
epoch: Epoch,
_marker: PhantomData<T>,
_marker: PhantomData<M>,
}

impl<T> FreeListHandle<T> {
pub fn weak(&self) -> WeakFreeListHandle<T> {
impl<M> FreeListHandle<M> {
pub fn weak(&self) -> WeakFreeListHandle<M> {
WeakFreeListHandle {
index: self.index,
epoch: self.epoch,
Expand All @@ -33,7 +33,7 @@ impl<T> FreeListHandle<T> {
}
}

impl<T> Clone for WeakFreeListHandle<T> {
impl<M> Clone for WeakFreeListHandle<M> {
fn clone(&self) -> Self {
WeakFreeListHandle {
index: self.index,
Expand All @@ -46,10 +46,10 @@ impl<T> Clone for WeakFreeListHandle<T> {
#[derive(Debug)]
#[cfg_attr(feature = "capture", derive(Serialize))]
#[cfg_attr(feature = "replay", derive(Deserialize))]
pub struct WeakFreeListHandle<T> {
pub struct WeakFreeListHandle<M> {
index: u32,
epoch: Epoch,
_marker: PhantomData<T>,
_marker: PhantomData<M>,
}

#[cfg_attr(feature = "capture", derive(Serialize))]
Expand All @@ -62,31 +62,34 @@ struct Slot<T> {

#[cfg_attr(feature = "capture", derive(Serialize))]
#[cfg_attr(feature = "replay", derive(Deserialize))]
pub struct FreeList<T> {
pub struct FreeList<T, M> {
slots: Vec<Slot<T>>,
free_list_head: Option<u32>,
active_count: usize,
_marker: PhantomData<M>,
}

pub enum UpsertResult<T> {
pub enum UpsertResult<T, M> {
Updated(T),
Inserted(FreeListHandle<T>),
Inserted(FreeListHandle<M>),
}

impl<T> FreeList<T> {
impl<T, M> FreeList<T, M> {
pub fn new() -> Self {
FreeList {
slots: Vec::new(),
free_list_head: None,
active_count: 0,
_marker: PhantomData,
}
}

pub fn recycle(self) -> FreeList<T> {
pub fn recycle(self) -> FreeList<T, M> {
FreeList {
slots: recycle_vec(self.slots),
free_list_head: None,
active_count: 0,
_marker: PhantomData,
}
}

Expand All @@ -97,16 +100,16 @@ impl<T> FreeList<T> {
}

#[allow(dead_code)]
pub fn get(&self, id: &FreeListHandle<T>) -> &T {
pub fn get(&self, id: &FreeListHandle<M>) -> &T {
self.slots[id.index as usize].value.as_ref().unwrap()
}

#[allow(dead_code)]
pub fn get_mut(&mut self, id: &FreeListHandle<T>) -> &mut T {
pub fn get_mut(&mut self, id: &FreeListHandle<M>) -> &mut T {
self.slots[id.index as usize].value.as_mut().unwrap()
}

pub fn get_opt(&self, id: &WeakFreeListHandle<T>) -> Option<&T> {
pub fn get_opt(&self, id: &WeakFreeListHandle<M>) -> Option<&T> {
let slot = &self.slots[id.index as usize];
if slot.epoch == id.epoch {
slot.value.as_ref()
Expand All @@ -115,7 +118,7 @@ impl<T> FreeList<T> {
}
}

pub fn get_opt_mut(&mut self, id: &WeakFreeListHandle<T>) -> Option<&mut T> {
pub fn get_opt_mut(&mut self, id: &WeakFreeListHandle<M>) -> Option<&mut T> {
let slot = &mut self.slots[id.index as usize];
if slot.epoch == id.epoch {
slot.value.as_mut()
Expand All @@ -128,7 +131,7 @@ impl<T> FreeList<T> {
// handle is a valid entry, update the value and return the
// previous data. If the provided handle is invalid, then
// insert the data into a new slot and return the new handle.
pub fn upsert(&mut self, id: &WeakFreeListHandle<T>, data: T) -> UpsertResult<T> {
pub fn upsert(&mut self, id: &WeakFreeListHandle<M>, data: T) -> UpsertResult<T, M> {
if self.slots[id.index as usize].epoch == id.epoch {
let slot = &mut self.slots[id.index as usize];
let result = UpsertResult::Updated(slot.value.take().unwrap());
Expand All @@ -139,7 +142,7 @@ impl<T> FreeList<T> {
}
}

pub fn insert(&mut self, item: T) -> FreeListHandle<T> {
pub fn insert(&mut self, item: T) -> FreeListHandle<M> {
self.active_count += 1;

match self.free_list_head {
Expand Down Expand Up @@ -176,7 +179,7 @@ impl<T> FreeList<T> {
}
}

pub fn free(&mut self, id: FreeListHandle<T>) -> T {
pub fn free(&mut self, id: FreeListHandle<M>) -> T {
self.active_count -= 1;
let slot = &mut self.slots[id.index as usize];
slot.next = self.free_list_head;
Expand Down
Loading