From 7a5fe8b08c8c095adced2f9a1e6024c0d075680d Mon Sep 17 00:00:00 2001 From: Nicolas Silva Date: Tue, 23 Feb 2021 14:47:10 +0000 Subject: [PATCH] Bug 1692250 - Make image borders use ImageSourceHandle. r=gw Differential Revision: https://phabricator.services.mozilla.com/D105950 --- gfx/wr/webrender/src/batch.rs | 23 ++++----- gfx/wr/webrender/src/frame_graph.rs | 1 - gfx/wr/webrender/src/image_source.rs | 1 + gfx/wr/webrender/src/prepare.rs | 9 ++-- gfx/wr/webrender/src/prim_store/borders.rs | 56 +++++++++++++--------- gfx/wr/webrender/src/render_task_graph.rs | 1 + gfx/wr/webrender/src/visibility.rs | 10 ---- 7 files changed, 51 insertions(+), 50 deletions(-) diff --git a/gfx/wr/webrender/src/batch.rs b/gfx/wr/webrender/src/batch.rs index a1e3edca3b1f..e40b82a6f3e7 100644 --- a/gfx/wr/webrender/src/batch.rs +++ b/gfx/wr/webrender/src/batch.rs @@ -2197,19 +2197,14 @@ impl BatchBuilder { let common_data = &prim_data.common; let border_data = &prim_data.kind; - let cache_item = resolve_image( - border_data.request, - ctx.resource_cache, - gpu_cache, - deferred_resolves, - ); - if cache_item.texture_id == TextureSource::Invalid { - return; - } + let (uv_rect_address, texture) = match border_data.src_color.resolve(render_tasks, ctx, gpu_cache) { + Some(src) => src, + None => { + return; + } + }; - let textures = TextureSet::prim_textured( - cache_item.texture_id, - ); + let textures = TextureSet::prim_textured(texture); let prim_cache_address = gpu_cache.get_address(&common_data.gpu_cache_handle); let specified_blend_mode = BlendMode::PremultipliedAlpha; let non_segmented_blend_mode = if !common_data.opacity.is_opaque || @@ -2229,7 +2224,7 @@ impl BatchBuilder { }; let batch_params = BrushBatchParameters::shared( - BrushBatchKind::Image(cache_item.texture_id.image_buffer_kind()), + BrushBatchKind::Image(texture.image_buffer_kind()), textures, ImageBrushData { color_mode: ShaderColorMode::Image, @@ -2237,7 +2232,7 @@ impl BatchBuilder { raster_space: RasterizationSpace::Local, opacity: 1.0, }.encode(), - cache_item.uv_rect_handle.as_int(gpu_cache), + uv_rect_address.as_int(), ); let prim_header_index = prim_headers.push( diff --git a/gfx/wr/webrender/src/frame_graph.rs b/gfx/wr/webrender/src/frame_graph.rs index 68527b0e3144..051d79d8340d 100644 --- a/gfx/wr/webrender/src/frame_graph.rs +++ b/gfx/wr/webrender/src/frame_graph.rs @@ -190,7 +190,6 @@ impl FrameGraphBuilder { } } - #[cfg(debug_assertions)] pub fn frame_id(&self) -> FrameId { self.frame_id } diff --git a/gfx/wr/webrender/src/image_source.rs b/gfx/wr/webrender/src/image_source.rs index a8e3aef1b88c..5fb577816156 100644 --- a/gfx/wr/webrender/src/image_source.rs +++ b/gfx/wr/webrender/src/image_source.rs @@ -29,6 +29,7 @@ use crate::internal_types::{TextureSource, DeferredResolveIndex}; /// enumerating the details of how it was produced. Hopefully we can get there /// incrementally). #[derive(Debug)] +#[derive(MallocSizeOf)] #[cfg_attr(feature = "capture", derive(Serialize))] #[cfg_attr(feature = "replay", derive(Deserialize))] pub enum ImageSourceHandle { diff --git a/gfx/wr/webrender/src/prepare.rs b/gfx/wr/webrender/src/prepare.rs index 90e8735b7206..872e76b70f5c 100644 --- a/gfx/wr/webrender/src/prepare.rs +++ b/gfx/wr/webrender/src/prepare.rs @@ -517,12 +517,15 @@ fn prepare_interned_prim_for_render( profile_scope!("ImageBorder"); let prim_data = &mut data_stores.image_border[*data_handle]; - // TODO: get access to the ninepatch and to check whwther we need support + // TODO: get access to the ninepatch and to check whether we need support // for repetitions in the shader. - // Update the template this instane references, which may refresh the GPU + // Update the template this instance references, which may refresh the GPU // cache with any shared template data. - prim_data.kind.update(&mut prim_data.common, frame_state); + prim_data.kind.update( + &mut prim_data.common, + frame_state + ); } PrimitiveInstanceKind::Rectangle { data_handle, segment_instance_index, color_binding_index, .. } => { profile_scope!("Rectangle"); diff --git a/gfx/wr/webrender/src/prim_store/borders.rs b/gfx/wr/webrender/src/prim_store/borders.rs index 561f4a8ada04..b5952fc38722 100644 --- a/gfx/wr/webrender/src/prim_store/borders.rs +++ b/gfx/wr/webrender/src/prim_store/borders.rs @@ -8,7 +8,7 @@ use crate::border::create_border_segments; use crate::border::NormalBorderAu; use crate::scene_building::{CreateShadow, IsVisible}; use crate::frame_builder::{FrameBuildingState}; -use crate::gpu_cache::{GpuCache, GpuDataRequest}; +use crate::gpu_cache::GpuDataRequest; use crate::intern; use crate::internal_types::LayoutPrimitiveInfo; use crate::prim_store::{ @@ -17,7 +17,10 @@ use crate::prim_store::{ PrimitiveInstanceKind, PrimitiveOpacity, PrimitiveStore, InternablePrimitive, }; -use crate::resource_cache::{ImageRequest, ResourceCache}; +use crate::resource_cache::ImageRequest; +use crate::image_source::ImageSourceHandle; +use crate::render_task::RenderTask; +use crate::render_backend::FrameId; use super::storage; @@ -229,6 +232,9 @@ pub struct ImageBorderData { #[ignore_malloc_size_of = "Arc"] pub request: ImageRequest, pub brush_segments: Vec, + pub src_color: ImageSourceHandle, + pub frame_id: FrameId, + pub is_opaque: bool, } impl ImageBorderData { @@ -246,28 +252,31 @@ impl ImageBorderData { self.write_segment_gpu_blocks(request); } - let image_properties = frame_state - .resource_cache - .get_image_properties(self.request.key); + let frame_id = frame_state.rg_builder.frame_id(); + if self.frame_id != frame_id { + self.frame_id = frame_id; - common.opacity = if let Some(image_properties) = image_properties { - PrimitiveOpacity { - is_opaque: image_properties.descriptor.is_opaque(), - } - } else { - PrimitiveOpacity::opaque() + let size = frame_state.resource_cache.request_image( + self.request, + frame_state.gpu_cache, + ); + + let task_id = frame_state.rg_builder.add().init( + RenderTask::new_image(size, self.request) + ); + + self.src_color = ImageSourceHandle::RenderTask(task_id); + + let image_properties = frame_state + .resource_cache + .get_image_properties(self.request.key); + + self.is_opaque = image_properties + .map(|properties| properties.descriptor.is_opaque()) + .unwrap_or(true); } - } - pub fn request_resources( - &mut self, - resource_cache: &mut ResourceCache, - gpu_cache: &mut GpuCache, - ) { - resource_cache.request_image( - self.request, - gpu_cache, - ); + common.opacity = PrimitiveOpacity { is_opaque: self.is_opaque }; } fn write_prim_gpu_blocks( @@ -314,6 +323,9 @@ impl From for ImageBorderTemplate { kind: ImageBorderData { request: key.kind.request, brush_segments, + src_color: ImageSourceHandle::None, + frame_id: FrameId::INVALID, + is_opaque: false, } } } @@ -371,6 +383,6 @@ fn test_struct_sizes() { assert_eq!(mem::size_of::(), 216, "NormalBorderTemplate size changed"); assert_eq!(mem::size_of::(), 104, "NormalBorderKey size changed"); assert_eq!(mem::size_of::(), 84, "ImageBorder size changed"); - assert_eq!(mem::size_of::(), 80, "ImageBorderTemplate size changed"); + assert_eq!(mem::size_of::(), 104, "ImageBorderTemplate size changed"); assert_eq!(mem::size_of::(), 104, "ImageBorderKey size changed"); } diff --git a/gfx/wr/webrender/src/render_task_graph.rs b/gfx/wr/webrender/src/render_task_graph.rs index ece1f2e39ae8..cd2fb5c8e774 100644 --- a/gfx/wr/webrender/src/render_task_graph.rs +++ b/gfx/wr/webrender/src/render_task_graph.rs @@ -38,6 +38,7 @@ impl<'l> RenderTaskAllocation<'l> { } #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +#[derive(MallocSizeOf)] #[cfg_attr(feature = "capture", derive(Serialize))] #[cfg_attr(feature = "replay", derive(Deserialize))] pub struct RenderTaskId { diff --git a/gfx/wr/webrender/src/visibility.rs b/gfx/wr/webrender/src/visibility.rs index c57c9f3102bb..65d061c21845 100644 --- a/gfx/wr/webrender/src/visibility.rs +++ b/gfx/wr/webrender/src/visibility.rs @@ -727,16 +727,6 @@ fn update_prim_post_visibility( // TODO(gw): We might be able to detect simple cases of this earlier, // during the picture traversal. But it's probably not worth it? } - PrimitiveInstanceKind::Image { .. } => { - - } - PrimitiveInstanceKind::ImageBorder { data_handle, .. } => { - let prim_data = &mut frame_state.data_stores.image_border[data_handle]; - prim_data.kind.request_resources( - frame_state.resource_cache, - frame_state.gpu_cache, - ); - } PrimitiveInstanceKind::YuvImage { data_handle, .. } => { let prim_data = &mut frame_state.data_stores.yuv_image[data_handle]; prim_data.kind.request_resources(