Bug 1857841 - pt 3. Add a new page kind named "fresh" r=glandium
[gecko.git] / gfx / wr / webrender / res / cs_scale.glsl
blob0b4f5d744bf88cfbb9765a57469a63179214ed17
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 // This shader must remain compatible with ESSL 1, at least for the
6 // WR_FEATURE_TEXTURE_EXTERNAL_ESSL1 feature, so that it can be used to render
7 // video on GLES devices without GL_OES_EGL_image_external_essl3 support.
8 // This means we cannot use textureSize(), int inputs/outputs, etc.
10 #include shared
12 varying highp vec2 vUv;
13 flat varying highp vec4 vUvRect;
14 #ifdef WR_FEATURE_TEXTURE_EXTERNAL_ESSL1
15 uniform vec2 uTextureSize;
16 #endif
18 #ifdef WR_VERTEX_SHADER
20 PER_INSTANCE attribute vec4 aScaleTargetRect;
21 PER_INSTANCE attribute vec4 aScaleSourceRect;
23 void main(void) {
24     vec2 src_offset = aScaleSourceRect.xy;
25     vec2 src_size = aScaleSourceRect.zw - aScaleSourceRect.xy;
27     // If this is in WR_FEATURE_TEXTURE_RECT mode, the rect and size use
28     // non-normalized texture coordinates.
29 #ifdef WR_FEATURE_TEXTURE_RECT
30     vec2 texture_size = vec2(1, 1);
31 #elif defined(WR_FEATURE_TEXTURE_EXTERNAL_ESSL1)
32     vec2 texture_size = uTextureSize;
33 #else
34     vec2 texture_size = vec2(TEX_SIZE(sColor0));
35 #endif
37     // The uvs may be inverted, so use the min and max for the bounds
38     vUvRect = vec4(min(aScaleSourceRect.xy, aScaleSourceRect.zw) + vec2(0.5),
39                    max(aScaleSourceRect.xy, aScaleSourceRect.zw) - vec2(0.5)) / texture_size.xyxy;
41     vec2 pos = mix(aScaleTargetRect.xy, aScaleTargetRect.zw, aPosition.xy);
42     vUv = (src_offset + src_size * aPosition.xy) / texture_size;
44     gl_Position = uTransform * vec4(pos, 0.0, 1.0);
47 #endif
49 #ifdef WR_FRAGMENT_SHADER
51 void main(void) {
52     vec2 st = clamp(vUv, vUvRect.xy, vUvRect.zw);
53     oFragColor = TEX_SAMPLE(sColor0, st);
56 #ifdef SWGL_DRAW_SPAN
57 void swgl_drawSpanRGBA8() {
58     swgl_commitTextureLinearRGBA8(sColor0, vUv, vUvRect);
60 #endif
62 #endif