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

Fix drop-shadows and remove last use of hardware_composite shader. #2588

Merged
merged 2 commits into from Apr 3, 2018
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

Fix drop-shadows and remove last use of hardware_composite shader.

This commit reworks how drop-shadows are handled. We now add two
primitives, each one referencing the same Picture.

The first primitive draws the drop shadow by blurring the alpha
channel of the picture, and generating screen-space UVs after
applying a local offset.

The second primitive draws the main image with a normal
brush_image shader blit.

There are a couple of hacky bits of code to make this work, but
it's such an improvement on the current state of drop-shadows
that I think it's worth getting this merged and tidying those
up later (mentioned as TODO comments in the patch).

Also, finally remove the hardware composite shader, since this
removes the last use of it.

Fixes #2584.
Fixes #2374.
  • Loading branch information
gw3583 committed Apr 2, 2018
commit f022751a470d05c88d65b8a9497ae73c9329fd10
@@ -9,6 +9,7 @@ void brush_vs(
int prim_address,
RectWithSize local_rect,
ivec3 user_data,
mat4 transform,
PictureTask pic_task
);

@@ -146,6 +147,7 @@ void main(void) {
brush.prim_address + VECS_PER_BRUSH_PRIM,
brush_prim.local_rect,
brush.user_data,
scroll_node.transform,
pic_task
);
}
@@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#define VECS_PER_SPECIFIC_BRUSH 2
#define VECS_PER_SPECIFIC_BRUSH 0
#define FORCE_NO_PERSPECTIVE

#include shared,prim_shared,brush
@@ -22,6 +22,7 @@ void brush_vs(
int prim_address,
RectWithSize local_rect,
ivec3 user_data,
mat4 transform,
PictureTask pic_task
) {
PictureTask src_task = fetch_picture_task(user_data.x);
@@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#define VECS_PER_SPECIFIC_BRUSH 2
#define VECS_PER_SPECIFIC_BRUSH 0

#include shared,prim_shared,brush

@@ -29,21 +29,37 @@ flat varying vec4 vColor;

struct ImageBrush {
RectWithSize rendered_task_rect;
vec2 offset;
vec4 color;
};

ImageBrush fetch_image_primitive(int address) {
vec4[2] data = fetch_from_resource_cache_2(address);
vec4[3] data = fetch_from_resource_cache_3(address);
RectWithSize rendered_task_rect = RectWithSize(data[0].xy, data[0].zw);
ImageBrush brush = ImageBrush(rendered_task_rect, data[1]);
ImageBrush brush = ImageBrush(rendered_task_rect, data[1].xy, data[2]);
return brush;
}

#ifdef WR_FEATURE_ALPHA_PASS
vec2 transform_point_snapped(
vec2 local_pos,
RectWithSize local_rect,
mat4 transform
) {
vec2 snap_offset = compute_snap_offset(local_pos, transform, local_rect);
vec4 world_pos = transform * vec4(local_pos, 0.0, 1.0);
vec2 device_pos = world_pos.xy / world_pos.w * uDevicePixelRatio;

return device_pos + snap_offset;
}
#endif

void brush_vs(
VertexInfo vi,
int prim_address,
RectWithSize local_rect,
ivec3 user_data,
mat4 transform,
PictureTask pic_task
) {
// If this is in WR_FEATURE_TEXTURE_RECT mode, the rect and size use
@@ -73,23 +89,51 @@ void brush_vs(
vec2 f;

#ifdef WR_FEATURE_ALPHA_PASS
ImageBrush image = fetch_image_primitive(prim_address);
vColor = image.color;
int image_source = user_data.y >> 16;
int raster_space = user_data.y & 0xffff;

// 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:
f = (vi.snapped_device_pos - image.rendered_task_rect.p0) / image.rendered_task_rect.size;
switch (raster_space) {
case RASTER_SCREEN: {
ImageBrush image = fetch_image_primitive(user_data.z);
vColor = image.color;

vec2 snapped_device_pos;

// For drop-shadows, we need to apply a local offset
// in order to generate the correct screen-space UV.
// For other effects, we can use the 1:1 mapping of
// the vertex device position for the UV generation.
switch (image_source) {
case IMAGE_SOURCE_MASK_FROM_COLOR: {
vec2 local_pos = vi.local_pos - image.offset;
snapped_device_pos = transform_point_snapped(
local_pos,
local_rect,
transform
);
break;
}
case IMAGE_SOURCE_COLOR:
case IMAGE_SOURCE_ALPHA:
default:
snapped_device_pos = vi.snapped_device_pos;
break;
}

f = (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: {
vColor = vec4(1.0);
f = (vi.local_pos - local_rect.p0) / local_rect.size;

// Set the clip bounds to a value that won't have any
@@ -110,7 +154,7 @@ void brush_vs(
vUv.xy /= texture_size;

#ifdef WR_FEATURE_ALPHA_PASS
switch (user_data.y) {
switch (image_source) {
case IMAGE_SOURCE_ALPHA:
vSelect = vec2(0.0, 1.0);
break;
@@ -35,6 +35,7 @@ void brush_vs(
int prim_address,
RectWithSize local_rect,
ivec3 user_data,
mat4 transform,
PictureTask pic_task
) {
Gradient gradient = fetch_gradient(prim_address);
@@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#define VECS_PER_SPECIFIC_BRUSH 2
#define VECS_PER_SPECIFIC_BRUSH 0

#include shared,prim_shared,brush

@@ -17,6 +17,7 @@ void brush_vs(
int prim_address,
RectWithSize local_rect,
ivec3 user_data,
mat4 transform,
PictureTask pic_task
) {
vec2 texture_size = vec2(textureSize(sCacheRGBA8, 0));
@@ -36,6 +36,7 @@ void brush_vs(
int prim_address,
RectWithSize local_rect,
ivec3 user_data,
mat4 transform,
PictureTask pic_task
) {
RadialGradient gradient = fetch_radial_gradient(prim_address);
@@ -28,6 +28,7 @@ void brush_vs(
int prim_address,
RectWithSize local_rect,
ivec3 user_data,
mat4 transform,
PictureTask pic_task
) {
SolidBrush prim = fetch_solid_primitive(prim_address);
@@ -75,6 +75,7 @@ void brush_vs(
int prim_address,
RectWithSize local_rect,
ivec3 user_data,
mat4 transform,
PictureTask pic_task
) {
vec2 f = (vi.local_pos - local_rect.p0) / local_rect.size;
@@ -489,7 +489,7 @@ vec4 get_node_pos(vec2 pos, ClipScrollNode node) {
// Compute a snapping offset in world space (adjusted to pixel ratio),
// given local position on the scroll_node and a snap rectangle.
vec2 compute_snap_offset(vec2 local_pos,
ClipScrollNode scroll_node,
mat4 transform,
RectWithSize snap_rect) {
// Ensure that the snap rect is at *least* one device pixel in size.
// TODO(gw): It's not clear to me that this is "correct". Specifically,
@@ -500,8 +500,8 @@ vec2 compute_snap_offset(vec2 local_pos,
snap_rect.size = max(snap_rect.size, vec2(1.0 / uDevicePixelRatio));

// Transform the snap corners to the world space.
vec4 world_snap_p0 = scroll_node.transform * vec4(snap_rect.p0, 0.0, 1.0);
vec4 world_snap_p1 = scroll_node.transform * vec4(snap_rect.p0 + snap_rect.size, 0.0, 1.0);
vec4 world_snap_p0 = transform * vec4(snap_rect.p0, 0.0, 1.0);
vec4 world_snap_p1 = transform * vec4(snap_rect.p0 + snap_rect.size, 0.0, 1.0);
// Snap bounds in world coordinates, adjusted for pixel ratio. XY = top left, ZW = bottom right
vec4 world_snap = uDevicePixelRatio * vec4(world_snap_p0.xy, world_snap_p1.xy) /
vec4(world_snap_p0.ww, world_snap_p1.ww);
@@ -535,7 +535,11 @@ VertexInfo write_vertex(RectWithSize instance_rect,
vec2 clamped_local_pos = clamp_rect(local_pos, local_clip_rect);

/// Compute the snapping offset.
vec2 snap_offset = compute_snap_offset(clamped_local_pos, scroll_node, snap_rect);
vec2 snap_offset = compute_snap_offset(
clamped_local_pos,
scroll_node.transform,
snap_rect
);

// Transform the current vertex to world space.
vec4 world_pos = scroll_node.transform * vec4(clamped_local_pos, 0.0, 1.0);

This file was deleted.

@@ -50,7 +50,11 @@ VertexInfo write_text_vertex(vec2 clamped_local_pos,
final_pos += floor(world_snap_p0 + 0.5) - world_snap_p0;
#elif !defined(WR_FEATURE_TRANSFORM)
// Compute the snapping offset only if the scroll node transform is axis-aligned.
final_pos += compute_snap_offset(clamped_local_pos, scroll_node, snap_rect);
final_pos += compute_snap_offset(
clamped_local_pos,
scroll_node.transform,
snap_rect
);
#endif

gl_Position = uTransform * vec4(final_pos, z, 1.0);
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.