Bug 1857841 - pt 3. Add a new page kind named "fresh" r=glandium
[gecko.git] / gfx / wr / webrender / res / rect.glsl
blob2a080ee39355c3a4e54259a472920610c69fba0b
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 struct RectWithSize {
6     vec2 p0;
7     vec2 size;
8 };
10 struct RectWithEndpoint {
11     vec2 p0;
12     vec2 p1;
15 float point_inside_rect(vec2 p, vec2 p0, vec2 p1) {
16     vec2 s = step(p0, p) - step(p1, p);
17     return s.x * s.y;
20 vec2 signed_distance_rect_xy(vec2 pos, vec2 p0, vec2 p1) {
21     // Instead of using a true signed distance to rect here, we just use the
22     // simpler approximation of the maximum distance on either axis from the
23     // outside of the rectangle. This avoids expensive use of length() and only
24     // causes mostly imperceptible differences at corner pixels.
25     return max(p0 - pos, pos - p1);
28 float signed_distance_rect(vec2 pos, vec2 p0, vec2 p1) {
29     // Collapse the per-axis distances to edges to a single approximate value.
30     vec2 d = signed_distance_rect_xy(pos, p0, p1);
31     return max(d.x, d.y);
34 vec2 rect_clamp(RectWithEndpoint rect, vec2 pt) {
35     return clamp(pt, rect.p0, rect.p1);
38 vec2 rect_size(RectWithEndpoint rect) {
39     return rect.p1 - rect.p0;