Commit bbafa0bc authored by Nicolas Silva's avatar Nicolas Silva
Browse files

Bug 1900022 - Rename SAMPLE_AS_MASK into IS_MASK and move to the base quad shader. r=gw

The feature could be used by other shaders, for example gradient masks currently fall back to blob images but we should use shaders for them instead.

Differential Revision: https://phabricator.services.mozilla.com/D212276
parent d09dbe04
Loading
Loading
Loading
Loading
+23 −6
Original line number Diff line number Diff line
@@ -37,9 +37,13 @@
#include shared,rect,transform,render_task,gpu_buffer

flat varying mediump vec4 v_color;
// z: is_mask
// w: has edge flags
// x,y,z are avaible for patterns to use.
// x,y are avaible for patterns to use.
flat varying lowp ivec4 v_flags;
#define v_flags_is_mask v_flags.z
#define v_flags_has_edge_mask v_flags.w


#ifndef SWGL_ANTIALIAS
varying highp vec2 vLocalPos;
@@ -63,7 +67,7 @@ varying highp vec2 vLocalPos;
#define QF_APPLY_DEVICE_CLIP    2
#define QF_IGNORE_DEVICE_SCALE  4
#define QF_USE_AA_SEGMENTS      8
#define QF_SAMPLE_AS_MASK       16
#define QF_IS_MASK              16

#define INVALID_SEGMENT_INDEX   0xff

@@ -363,15 +367,22 @@ void antialiasing_vertex(PrimitiveInfo prim) {
    vLocalPos = prim.local_pos;

    if (prim.edge_flags == 0) {
        v_flags.w = 0;
        v_flags_has_edge_mask = 0;
    } else {
        v_flags.w = 1;
        v_flags_has_edge_mask = 1;
    }
#endif
}

void main() {
    PrimitiveInfo prim = quad_primive_info();

    if ((prim.quad_flags & QF_IS_MASK) != 0) {
        v_flags_is_mask = 1;
    } else {
        v_flags_is_mask = 0;
    }

    antialiasing_vertex(prim);
    pattern_vertex(prim);
}
@@ -383,7 +394,7 @@ vec4 pattern_fragment(vec4 base_color);
float antialiasing_fragment() {
    float alpha = 1.0;
#ifndef SWGL_ANTIALIAS
    if (v_flags.w != 0) {
    if (v_flags_has_edge_mask != 0) {
        alpha = init_transform_fs(vLocalPos);
    }
#endif
@@ -393,7 +404,13 @@ float antialiasing_fragment() {
void main() {
    vec4 base_color = v_color;
    base_color *= antialiasing_fragment();
    oFragColor = pattern_fragment(base_color);
    vec4 output_color = pattern_fragment(base_color);

    if (v_flags_is_mask != 0) {
        output_color = output_color.rrrr;
    }

    oFragColor = output_color;
}

#endif
+1 −11
Original line number Diff line number Diff line
@@ -7,7 +7,6 @@
#include ps_quad,sample_color0

#define v_flags_textured v_flags.x
#define v_flags_sample_as_mask v_flags.y

#ifdef WR_VERTEX_SHADER

@@ -24,12 +23,6 @@ void pattern_vertex(PrimitiveInfo info) {
        // Solid color
        v_flags_textured = 0;
    }

    if ((info.quad_flags & QF_SAMPLE_AS_MASK) != 0) {
        v_flags_sample_as_mask = 1;
    } else {
        v_flags_sample_as_mask = 0;
    }
}

#endif
@@ -39,9 +32,6 @@ void pattern_vertex(PrimitiveInfo info) {
vec4 pattern_fragment(vec4 color) {
    if (v_flags_textured != 0) {
        vec4 texel = fs_sample_color0();
        if (v_flags_sample_as_mask != 0) {
            texel = texel.rrrr;
        }
        color *= texel;
    }

@@ -51,7 +41,7 @@ vec4 pattern_fragment(vec4 color) {
#if defined(SWGL_DRAW_SPAN)
void swgl_drawSpanRGBA8() {
    if (v_flags_textured != 0) {
        if (v_flags_sample_as_mask != 0) {
        if (v_flags_is_mask != 0) {
            // Fall back to fragment shader as we don't specialize for mask yet. Perhaps
            // we can use an existing swgl commit or add a new one though?
        } else {
+4 −2
Original line number Diff line number Diff line
@@ -86,8 +86,10 @@ bitflags! {
        /// If true, use segments for drawing the AA edges, to allow inner section to be opaque
        const USE_AA_SEGMENTS = 1 << 3;

        /// If true, apply texture sample as mask
        const SAMPLE_AS_MASK = 1 << 4;
        /// If true, render as a mask. This ignores the blue, green and alpha channels and replaces
        /// them with the red channel in the fragment shader. Used with multiply blending, on top
        /// of premultiplied alpha content, it has the effect of applying a mask to the content under ir.
        const IS_MASK = 1 << 4;
    }
}

+1 −1
Original line number Diff line number Diff line
@@ -1220,7 +1220,7 @@ fn build_mask_tasks(
                );

                let clip_needs_scissor_rect = !is_same_coord_system;
                let mut quad_flags = QuadFlags::SAMPLE_AS_MASK;
                let mut quad_flags = QuadFlags::IS_MASK;

                if is_same_coord_system {
                    quad_flags |= QuadFlags::APPLY_RENDER_TASK_CLIP;