Skip to content
Closed
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
106 changes: 0 additions & 106 deletions webrender/res/ps_image.glsl

This file was deleted.

153 changes: 100 additions & 53 deletions webrender/src/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const OPAQUE_TASK_ADDRESS: RenderTaskAddress = RenderTaskAddress(0x7fff);
#[cfg_attr(feature = "replay", derive(Deserialize))]
pub enum TransformBatchKind {
TextRun(GlyphFormat),
Image(ImageBufferKind),
BorderCorner,
BorderEdge,
}
Expand Down Expand Up @@ -613,7 +612,10 @@ impl AlphaBatchBuilder {
screen_rect.unclipped.size,
);

let prim_cache_address = gpu_cache.get_address(&prim_metadata.gpu_location);
// Tiled images have a cache handle per visible tile and an invalid handle in the
// primitive metadata.
let prim_cache_address = gpu_cache.try_get_address(&prim_metadata.gpu_location);

let no_textures = BatchTextures::no_texture();
let clip_task_address = prim_metadata
.clip_task_id
Expand Down Expand Up @@ -980,6 +982,32 @@ impl AlphaBatchBuilder {
);
}
}
BrushKind::Image { request, ref visible_tiles, .. } if !visible_tiles.is_empty() => {
for tile in visible_tiles {
if let Some((batch_kind, textures, user_data)) = get_image_tile_params(
ctx.resource_cache,
gpu_cache,
deferred_resolves,
request.with_tile(tile.tile_offset),
) {
let prim_cache_address = gpu_cache.get_address(&tile.handle);
self.add_image_tile_to_batch(
batch_kind,
specified_blend_mode,
textures,
clip_chain_rect_index,
clip_task_address,
&task_relative_bounding_rect,
prim_cache_address,
scroll_id,
task_address,
z,
user_data,
tile.edge_flags
);
}
}
}
_ => {
if let Some((batch_kind, textures, user_data)) = brush.get_batch_params(
ctx.resource_cache,
Expand Down Expand Up @@ -1070,50 +1098,6 @@ impl AlphaBatchBuilder {
}
}
}
PrimitiveKind::Image => {
let image_cpu = &ctx.prim_store.cpu_images[prim_metadata.cpu_prim_index.0];

let cache_item = match image_cpu.source {
ImageSource::Default => {
resolve_image(
image_cpu.key.request,
ctx.resource_cache,
gpu_cache,
deferred_resolves,
)
}
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)
}
};

if cache_item.texture_id == SourceTexture::Invalid {
warn!("Warnings: skip a PrimitiveKind::Image");
debug!("at {:?}.", task_relative_bounding_rect);
return;
}

let batch_kind = TransformBatchKind::Image(get_buffer_kind(cache_item.texture_id));
let key = BatchKey::new(
BatchKind::Transformable(transform_kind, batch_kind),
non_segmented_blend_mode,
BatchTextures {
colors: [
cache_item.texture_id,
SourceTexture::Invalid,
SourceTexture::Invalid,
],
},
);
let batch = self.batch_list.get_suitable_batch(key, &task_relative_bounding_rect);
batch.push(base_instance.build(cache_item.uv_rect_handle.as_int(gpu_cache), 0, 0));
}
PrimitiveKind::TextRun => {
let text_cpu =
&ctx.prim_store.cpu_text_runs[prim_metadata.cpu_prim_index.0];
Expand Down Expand Up @@ -1191,6 +1175,45 @@ impl AlphaBatchBuilder {
}
}

fn add_image_tile_to_batch(
&mut self,
batch_kind: BrushBatchKind,
blend_mode: BlendMode,
textures: BatchTextures,
clip_chain_rect_index: ClipChainRectIndex,
clip_task_address: RenderTaskAddress,
task_relative_bounding_rect: &DeviceIntRect,
prim_cache_address: GpuCacheAddress,
scroll_id: ClipScrollNodeIndex,
task_address: RenderTaskAddress,
z: ZBufferId,
user_data: [i32; 3],
edge_flags: EdgeAaSegmentMask,
) {
let base_instance = BrushInstance {
picture_address: task_address,
prim_address: prim_cache_address,
clip_chain_rect_index,
scroll_id,
clip_task_address,
z,
segment_index: 0,
edge_flags,
brush_flags: BrushFlags::PERSPECTIVE_INTERPOLATION,
user_data,
};

self.batch_list.add_bounding_rect(task_relative_bounding_rect);

let batch_key = BatchKey {
blend_mode,
kind: BatchKind::Brush(batch_kind),
textures,
};
let batch = self.batch_list.get_suitable_batch(batch_key, task_relative_bounding_rect);
batch.push(PrimitiveInstance::from(base_instance));
}

fn add_brush_to_batch(
&mut self,
brush: &BrushPrimitive,
Expand Down Expand Up @@ -1286,6 +1309,37 @@ impl AlphaBatchBuilder {
}
}

fn get_image_tile_params(
resource_cache: &ResourceCache,
gpu_cache: &mut GpuCache,
deferred_resolves: &mut Vec<DeferredResolve>,
request: ImageRequest,
) -> Option<(BrushBatchKind, BatchTextures, [i32; 3])> {

let cache_item = resolve_image(
request,
resource_cache,
gpu_cache,
deferred_resolves,
);

if cache_item.texture_id == SourceTexture::Invalid {
None
} else {
let textures = BatchTextures::color(cache_item.texture_id);
Some((
BrushBatchKind::Image(get_buffer_kind(cache_item.texture_id)),
textures,
[
cache_item.uv_rect_handle.as_int(gpu_cache),
(BrushImageSourceKind::Color as i32) << 16 |
RasterizationSpace::Local as i32,
0,
],
))
}
}

impl BrushPrimitive {
pub fn get_picture_index(&self) -> PictureIndex {
match self.kind {
Expand Down Expand Up @@ -1479,13 +1533,6 @@ impl AlphaBatchHelpers for PrimitiveStore {
}
}
}
PrimitiveKind::Image => {
let image_cpu = &self.cpu_images[metadata.cpu_prim_index.0];
match image_cpu.alpha_type {
AlphaType::PremultipliedAlpha => BlendMode::PremultipliedAlpha,
AlphaType::Alpha => BlendMode::Alpha,
}
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions webrender/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1250,8 +1250,8 @@ impl Device {
src_rect.origin.y + src_rect.size.height,
dest_rect.origin.x,
dest_rect.origin.y,
dest_rect.origin.x + dest_rect.size.width,
dest_rect.origin.y + dest_rect.size.height,
dest_rect.origin.x + src_rect.size.width,
dest_rect.origin.y + src_rect.size.height,
gl::COLOR_BUFFER_BIT,
gl::LINEAR,
);
Expand Down
Loading