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

Apply device pixel snapping to axis-aligned clip masks. #2608

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Apply device pixel snapping to axis-aligned clip masks.

Fixes #2501.
  • Loading branch information
gw3583 committed Apr 4, 2018
commit fbd7d43451bed6873f9c38628ef6d7b4ee9e731a
@@ -51,7 +51,25 @@ RectWithSize intersect_rect(RectWithSize a, RectWithSize b) {
ClipVertexInfo write_clip_tile_vertex(RectWithSize local_clip_rect,
ClipScrollNode scroll_node,
ClipArea area) {
vec2 actual_pos = area.screen_origin + aPosition.xy * area.common_data.task_rect.size;
vec2 device_pos = area.screen_origin + aPosition.xy * area.common_data.task_rect.size;
vec2 actual_pos = device_pos;

if (scroll_node.is_axis_aligned) {
vec4 snap_positions = compute_snap_positions(
scroll_node.transform,
local_clip_rect
);

vec2 snap_offsets = compute_snap_offset_impl(
device_pos,
scroll_node.transform,
local_clip_rect,
RectWithSize(snap_positions.xy, snap_positions.zw - snap_positions.xy),
snap_positions
);

actual_pos -= snap_offsets;
}

vec4 node_pos;

@@ -64,7 +82,7 @@ ClipVertexInfo write_clip_tile_vertex(RectWithSize local_clip_rect,
}

// compute the point position inside the scroll node, in CSS space
vec2 vertex_pos = actual_pos +
vec2 vertex_pos = device_pos +
area.common_data.task_rect.p0 -
area.screen_origin;

@@ -486,11 +486,8 @@ vec4 get_node_pos(vec2 pos, ClipScrollNode node) {
return untransform(pos, n, a, node.inv_transform);
}

// 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,
mat4 transform,
RectWithSize snap_rect) {
// Compute a snapping offset in world space (adjusted to pixel ratio)
vec4 compute_snap_positions(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,
// how should it interact with sub-pixel snap rects when there
@@ -505,15 +502,47 @@ vec2 compute_snap_offset(vec2 local_pos,
// 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);
return world_snap;
}

vec2 compute_snap_offset_impl(
vec2 reference_pos,
mat4 transform,
RectWithSize snap_rect,
RectWithSize reference_rect,
vec4 snap_positions) {

/// World offsets applied to the corners of the snap rectangle.
vec4 snap_offsets = floor(world_snap + 0.5) - world_snap;
vec4 snap_offsets = floor(snap_positions + 0.5) - snap_positions;

/// Compute the position of this vertex inside the snap rectangle.
vec2 normalized_snap_pos = (local_pos - snap_rect.p0) / snap_rect.size;
vec2 normalized_snap_pos = (reference_pos - reference_rect.p0) / reference_rect.size;

/// Compute the actual world offset for this vertex needed to make it snap.
return mix(snap_offsets.xy, snap_offsets.zw, normalized_snap_pos);
}

// 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,
mat4 transform,
RectWithSize snap_rect) {
vec4 snap_positions = compute_snap_positions(
transform,
snap_rect
);

vec2 snap_offsets = compute_snap_offset_impl(
local_pos,
transform,
snap_rect,
snap_rect,
snap_positions
);

return snap_offsets;
}

struct VertexInfo {
vec2 local_pos;
vec2 screen_pos;
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -9,3 +9,4 @@
== fixed-position-clipping.yaml fixed-position-clipping-ref.yaml
== segmentation-with-other-coordinate-system-clip.yaml segmentation-with-other-coordinate-system-clip-ref.yaml
== stacking-context-clip.yaml stacking-context-clip-ref.yaml
== snapping.yaml snapping-ref.yaml
@@ -0,0 +1,17 @@
---
root:
items:
- type: clip
bounds: [0, 0, 1000, 1000]
complex:
- rect: [50, 50, 100, 100]
radius: 16
items:
- type: rect
bounds: 50 50 100 100
color: red

- type: rect
bounds: 200 50 100 100
color: green

@@ -0,0 +1,17 @@
---
root:
items:
- type: clip
bounds: [0, 0, 1000, 1000]
complex:
- rect: [50.3, 50.3, 100, 100]
radius: 16
items:
- type: rect
bounds: 50.3 50.3 100 100
color: red

- type: rect
bounds: 200.3 50.3 100 100
color: green

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.