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

Use brush_image for blurs, instead of 2d hardware composite. #2509

Merged
merged 2 commits into from Mar 13, 2018
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -16,6 +16,7 @@ flat varying vec4 vColor;

#ifdef WR_FEATURE_ALPHA_PASS
flat varying vec2 vSelect;
flat varying vec4 vUvClipBounds;
#endif

#ifdef WR_VERTEX_SHADER
@@ -26,6 +27,17 @@ flat varying vec2 vSelect;
#define IMAGE_SOURCE_MASK_FROM_COLOR 2
#endif

struct ImageBrush {
RectWithSize rendered_task_rect;
};

ImageBrush fetch_image_primitive(int address) {
vec4 data = fetch_from_resource_cache_1(address);
RectWithSize rendered_task_rect = RectWithSize(data.xy, data.zw);
ImageBrush brush = ImageBrush(rendered_task_rect);
return brush;
}

void brush_vs(
VertexInfo vi,
int prim_address,
@@ -48,17 +60,51 @@ void brush_vs(
vUv.z = res.layer;
vColor = res.color;

vec2 f = (vi.local_pos - local_rect.p0) / local_rect.size;
vUv.xy = mix(uv0, uv1, f);
vUv.xy /= texture_size;

// Handle case where the UV coords are inverted (e.g. from an
// external image).
vec2 min_uv = min(uv0, uv1);
vec2 max_uv = max(uv0, uv1);

vUvBounds = vec4(
min(uv0, uv1) + vec2(0.5),
max(uv0, uv1) - vec2(0.5)
min_uv + vec2(0.5),
max_uv - vec2(0.5)
) / texture_size.xyxy;

vec2 f;

#ifdef WR_FEATURE_ALPHA_PASS
// Derive the texture coordinates for this image, based on
// whether the source image is a local-space or screen-space
// image.
switch (user_data.z) {
case RASTER_SCREEN: {
ImageBrush image = fetch_image_primitive(prim_address);

f = (vi.snapped_device_pos - image.rendered_task_rect.p0) / image.rendered_task_rect.size;

vUvClipBounds = vec4(
min_uv,
max_uv
) / texture_size.xyxy;
break;
}
case RASTER_LOCAL:
default: {
f = (vi.local_pos - local_rect.p0) / local_rect.size;

// Set the clip bounds to a value that won't have any
// effect for local space images.
vUvClipBounds = vec4(0.0, 0.0, 1.0, 1.0);
break;
}
}
#else
f = (vi.local_pos - local_rect.p0) / local_rect.size;
#endif

vUv.xy = mix(uv0, uv1, f);
vUv.xy /= texture_size;

#ifdef WR_FEATURE_ALPHA_PASS
switch (user_data.y) {
case IMAGE_SOURCE_COLOR:
@@ -86,6 +132,10 @@ vec4 brush_fs() {
#ifdef WR_FEATURE_ALPHA_PASS
vec4 mask = mix(texel.rrrr, texel.aaaa, vSelect.x);
vec4 color = mix(texel, vColor * mask, vSelect.y) * init_transform_fs(vLocalPos);

// Fail-safe to ensure that we don't sample outside the rendered
// portion of a picture source.
color.a *= point_inside_rect(vUv.xy, vUvClipBounds.xy, vUvClipBounds.zw);
#else
vec4 color = texel;
#endif
@@ -16,6 +16,9 @@
#define SUBPX_DIR_HORIZONTAL 1
#define SUBPX_DIR_VERTICAL 2

#define RASTER_LOCAL 0
#define RASTER_SCREEN 1

#define EPSILON 0.0001

uniform sampler2DArray sCacheA8;
@@ -13,7 +13,7 @@ use euclid::{TypedTransform3D, vec3};
use glyph_rasterizer::GlyphFormat;
use gpu_cache::{GpuCache, GpuCacheAddress};
use gpu_types::{BrushFlags, BrushInstance, ClipChainRectIndex};
use gpu_types::{ClipMaskInstance, ClipScrollNodeIndex};
use gpu_types::{ClipMaskInstance, ClipScrollNodeIndex, RasterizationSpace};
use gpu_types::{CompositePrimitiveInstance, PrimitiveInstance, SimplePrimitiveInstance};
use internal_types::{FastHashMap, SavedTargetIndex, SourceTexture};
use picture::{ContentOrigin, PictureCompositeMode, PictureKind, PicturePrimitive};
@@ -919,7 +919,7 @@ impl AlphaBatchBuilder {
user_data: [
uv_rect_address,
BrushImageSourceKind::Color as i32,
0,
RasterizationSpace::Local as i32,
],
};
batch.push(PrimitiveInstance::from(instance));
@@ -966,25 +966,32 @@ impl AlphaBatchBuilder {
PictureCompositeMode::Filter(filter) => {
match filter {
FilterOp::Blur(..) => {
let src_task_address = render_tasks.get_task_address(source_id);
let key = BatchKey::new(
BatchKind::HardwareComposite,
BlendMode::PremultipliedAlpha,
BatchTextures::render_target_cache(),
let kind = BatchKind::Brush(
BrushBatchKind::Image(ImageBufferKind::Texture2DArray)
);
let key = BatchKey::new(kind, non_segmented_blend_mode, textures);
let batch = self.batch_list.get_suitable_batch(key, &task_relative_bounding_rect);
let item_bounding_rect = prim_metadata.screen_rect.expect("bug!!").clipped;
let instance = CompositePrimitiveInstance::new(
task_address,
src_task_address,
RenderTaskAddress(0),
item_bounding_rect.origin.x,
item_bounding_rect.origin.y,
z,
item_bounding_rect.size.width,
item_bounding_rect.size.height,
);

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

let 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: EdgeAaSegmentMask::empty(),
brush_flags: BrushFlags::empty(),
user_data: [
uv_rect_address,
BrushImageSourceKind::Color as i32,
RasterizationSpace::Screen as i32,
],
};
batch.push(PrimitiveInstance::from(instance));
}
FilterOp::DropShadow(offset, _, _) => {
@@ -1010,7 +1017,11 @@ impl AlphaBatchBuilder {
user_data: [
uv_rect_address,
BrushImageSourceKind::ColorAlphaMask as i32,
0,
// TODO(gw): This is totally wrong, but the drop-shadow code itself
// is completely wrong, and doesn't work correctly with
// transformed Picture sources. I'm leaving this as is for
// now, and will fix drop-shadows properly, as a follow up.
RasterizationSpace::Local as i32,
],
};

@@ -1309,7 +1320,7 @@ impl BrushPrimitive {
[
cache_item.uv_rect_handle.as_int(gpu_cache),
BrushImageSourceKind::Color as i32,
0,
RasterizationSpace::Local as i32,
],
))
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.