Skip to content

Commit

Permalink
Bug 1759526 - Refactor write_transform_vertex. r=gw
Browse files Browse the repository at this point in the history
This patch separates the antialiasing code from write_vertex. It should not introduce any behavior change, but the resulting code is easier to understand.

Differential Revision: https://phabricator.services.mozilla.com/D141479
  • Loading branch information
nical committed Apr 1, 2022
1 parent 9c3b4a3 commit 4a703b2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 42 deletions.
33 changes: 20 additions & 13 deletions gfx/wr/webrender/res/brush.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,13 @@ void brush_shader_main_vs(
segment_data = segment_info[1];
}

VertexInfo vi;
// Most of the time this is the segment rect, but when doing the edge AA
// it is inflated.
RectWithEndpoint adjusted_segment_rect = segment_rect;

// Write the normal vertex information out.
if (transform.is_axis_aligned) {

// Select the corner of the local rect that we are processing.
vec2 local_pos = mix(segment_rect.p0, segment_rect.p1, aPosition.xy);

vi = write_vertex(
local_pos,
ph.local_clip_rect,
ph.z,
transform,
pic_task
);

// TODO(gw): transform bounds may be referenced by
// the fragment shader when running in
// the alpha pass, even on non-transformed
Expand All @@ -142,7 +133,7 @@ void brush_shader_main_vs(
init_transform_vs(vec4(vec2(-1.0e16), vec2(1.0e16)));
#endif
} else {
vi = write_transform_vertex(
adjusted_segment_rect = clip_and_init_antialiasing(
segment_rect,
ph.local_rect,
ph.local_clip_rect,
Expand All @@ -151,8 +142,24 @@ void brush_shader_main_vs(
transform,
pic_task
);

// The clip was taken into account in clip_and_init_antialiasing, remove
// it so that it doesn't interfere with the aa.
ph.local_clip_rect.p0 = vec2(-1.0e16);
ph.local_clip_rect.p1 = vec2(1.0e16);
}

// Select the corner of the local rect that we are processing.
vec2 local_pos = mix(adjusted_segment_rect.p0, adjusted_segment_rect.p1, aPosition.xy);

VertexInfo vi = write_vertex(
local_pos,
ph.local_clip_rect,
ph.z,
transform,
pic_task
);

// For brush instances in the alpha pass, always write
// out clip information.
// TODO(gw): It's possible that we might want alpha
Expand Down
37 changes: 8 additions & 29 deletions gfx/wr/webrender/res/prim_shared.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,13 @@ vec2 intersect_lines(vec2 p0, vec2 p1, vec2 p2, vec2 p3) {
return vec2(nx / d, ny / d);
}

VertexInfo write_transform_vertex(RectWithEndpoint local_segment_rect,
RectWithEndpoint local_prim_rect,
RectWithEndpoint local_clip_rect,
int edge_flags,
float z,
Transform transform,
PictureTask task) {
RectWithEndpoint clip_and_init_antialiasing(RectWithEndpoint local_segment_rect,
RectWithEndpoint local_prim_rect,
RectWithEndpoint local_clip_rect,
int edge_flags,
float z,
Transform transform,
PictureTask task) {
// Calculate a clip rect from local_rect + local clip
RectWithEndpoint clip_rect = local_clip_rect;
RectWithEndpoint segment_rect = local_segment_rect;
Expand Down Expand Up @@ -209,28 +209,7 @@ VertexInfo write_transform_vertex(RectWithEndpoint local_segment_rect,
local_segment_rect.p1 += extrude_distance.zw;
#endif

// Select the corner of the local rect that we are processing.
vec2 local_pos = mix(local_segment_rect.p0, local_segment_rect.p1, aPosition.xy);

// Convert the world positions to device pixel space.
vec2 task_offset = task.task_rect.p0 - task.content_origin;

// Transform the current vertex to world space.
vec4 world_pos = transform.m * vec4(local_pos, 0.0, 1.0);
vec4 final_pos = vec4(
world_pos.xy * task.device_pixel_scale + task_offset * world_pos.w,
z * world_pos.w,
world_pos.w
);

gl_Position = uTransform * final_pos;

VertexInfo vi = VertexInfo(
local_pos,
world_pos
);

return vi;
return local_segment_rect;
}

void write_clip(vec4 world_pos, ClipArea area, PictureTask task) {
Expand Down

0 comments on commit 4a703b2

Please sign in to comment.