gecko-dev/gfx/webrender/res/rect.glsl
Kartikaya Gupta 14a9b3751e Bug 1423203 - Update webrender to commit 22f472f0adb02bd71c472e426e47182f2b218f6d. r=jrmuizel
MozReview-Commit-ID: JJK2le2vpeN

--HG--
extra : rebase_source : 677e4433eddb14fea5e0d9a978f28b57912d21f8
2017-12-08 13:43:37 -05:00

49 lines
1.3 KiB
GLSL

/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/. */
struct RectWithSize {
vec2 p0;
vec2 size;
};
struct RectWithEndpoint {
vec2 p0;
vec2 p1;
};
RectWithEndpoint to_rect_with_endpoint(RectWithSize rect) {
RectWithEndpoint result;
result.p0 = rect.p0;
result.p1 = rect.p0 + rect.size;
return result;
}
RectWithSize to_rect_with_size(RectWithEndpoint rect) {
RectWithSize result;
result.p0 = rect.p0;
result.size = rect.p1 - rect.p0;
return result;
}
RectWithSize transform_rect(RectWithSize rect, mat2 transform) {
vec2 center = transform * (rect.p0 + rect.size * 0.5);
vec2 radius = mat2(abs(transform[0]), abs(transform[1])) * (rect.size * 0.5);
return RectWithSize(center - radius, radius * 2.0);
}
RectWithSize intersect_rects(RectWithSize a, RectWithSize b) {
RectWithSize result;
result.p0 = max(a.p0, b.p0);
result.size = min(a.p0 + a.size, b.p0 + b.size) - result.p0;
return result;
}
bool rect_inside_rect(RectWithSize little, RectWithSize big) {
return all(lessThanEqual(vec4(big.p0, little.p0 + little.size),
vec4(little.p0, big.p0 + big.size)));
}