diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /gfx/wr/webrender/res/cs_scale.glsl | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'gfx/wr/webrender/res/cs_scale.glsl')
-rw-r--r-- | gfx/wr/webrender/res/cs_scale.glsl | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/gfx/wr/webrender/res/cs_scale.glsl b/gfx/wr/webrender/res/cs_scale.glsl new file mode 100644 index 0000000000..b046a2503d --- /dev/null +++ b/gfx/wr/webrender/res/cs_scale.glsl @@ -0,0 +1,67 @@ +/* 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/. */ + +#include shared,prim_shared + +varying vec2 vUv; +flat varying float vUvLayer; +flat varying vec4 vUvRect; + +#ifdef WR_VERTEX_SHADER + +PER_INSTANCE in vec4 aScaleTargetRect; +PER_INSTANCE in ivec4 aScaleSourceRect; +PER_INSTANCE in int aScaleSourceLayer; + +void main(void) { + RectWithSize src_rect = RectWithSize(vec2(aScaleSourceRect.xy), vec2(aScaleSourceRect.zw)); + + // If this is in WR_FEATURE_TEXTURE_RECT mode, the rect and size use + // non-normalized texture coordinates. +#ifdef WR_FEATURE_TEXTURE_RECT + vec2 texture_size = vec2(1, 1); +#else + vec2 texture_size = vec2(textureSize(sColor0, 0)); +#endif + + vUvLayer = float(aScaleSourceLayer); + + vUvRect = vec4(src_rect.p0 + vec2(0.5), + src_rect.p0 + src_rect.size - vec2(0.5)) / texture_size.xyxy; + + vec2 pos = aScaleTargetRect.xy + aScaleTargetRect.zw * aPosition.xy; + vUv = (src_rect.p0 + src_rect.size * aPosition.xy) / texture_size; + + gl_Position = uTransform * vec4(pos, 0.0, 1.0); +} + +#endif + +#ifdef WR_FRAGMENT_SHADER + +void main(void) { + vec2 st = clamp(vUv, vUvRect.xy, vUvRect.zw); + oFragColor = TEX_SAMPLE(sColor0, vec3(st, vUvLayer)); +} + +#ifdef SWGL +void swgl_drawSpanRGBA8() { + if (!swgl_isTextureRGBA8(sColor0)) { + return; + } + + int layer = swgl_textureLayerOffset(sColor0, vUvLayer); + vec2 uv = swgl_linearQuantize(sColor0, vUv); + vec2 min_uv = swgl_linearQuantize(sColor0, vUvRect.xy); + vec2 max_uv = swgl_linearQuantize(sColor0, vUvRect.zw); + vec2 step_uv = swgl_linearQuantizeStep(sColor0, swgl_interpStep(vUv)); + + while (swgl_SpanLength > 0) { + swgl_commitTextureLinearRGBA8(sColor0, clamp(uv, min_uv, max_uv), layer); + uv += step_uv; + } +} +#endif + +#endif |