Commit 98c585cf authored by Jean-Yves Avenard's avatar Jean-Yves Avenard
Browse files

Bug 1659015 - P1. Add YUV identity support (rgb) to WR. r=gw

parent 5be22726
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -780,6 +780,8 @@ static inline wr::WrYuvColorSpace ToWrYuvColorSpace(
      return wr::WrYuvColorSpace::Rec709;
    case gfx::YUVColorSpace::BT2020:
      return wr::WrYuvColorSpace::Rec2020;
    case gfx::YUVColorSpace::Identity:
      return wr::WrYuvColorSpace::Identity;
    default:
      MOZ_ASSERT_UNREACHABLE("Tried to convert invalid YUVColorSpace.");
  }
+3 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ flat varying vec4 vUvBounds_V;

flat varying float vCoefficient;
flat varying mat3 vYuvColorMatrix;
flat varying vec3 vYuvOffsetVector;
flat varying int vFormat;

#ifdef WR_VERTEX_SHADER
@@ -60,6 +61,7 @@ void yuv_brush_vs(
    vCoefficient = prim.coefficient;

    vYuvColorMatrix = get_yuv_color_matrix(prim.color_space);
    vYuvOffsetVector = get_yuv_offset_vector(prim.color_space);
    vFormat = prim.yuv_format;

#ifdef WR_FEATURE_ALPHA_PASS
@@ -94,6 +96,7 @@ Fragment yuv_brush_fs() {
    vec4 color = sample_yuv(
        vFormat,
        vYuvColorMatrix,
        vYuvOffsetVector,
        vCoefficient,
        vYuvLayers,
        vUv_Y,
+3 −0
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@

#ifdef WR_FEATURE_YUV
flat varying mat3 vYuvColorMatrix;
flat varying vec3 vYuvOffsetVector;
flat varying float vYuvCoefficient;
flat varying int vYuvFormat;
flat varying vec3 vYuvLayers;
@@ -59,6 +60,7 @@ void main(void) {
    float yuv_coefficient = aParams.w;

    vYuvColorMatrix = get_yuv_color_matrix(yuv_color_space);
    vYuvOffsetVector = get_yuv_offset_vector(yuv_color_space);
    vYuvCoefficient = yuv_coefficient;
    vYuvFormat = yuv_format;

@@ -120,6 +122,7 @@ void main(void) {
    vec4 color = sample_yuv(
        vYuvFormat,
        vYuvColorMatrix,
        vYuvOffsetVector,
        vYuvCoefficient,
        vYuvLayers,
        vUV_y,
+22 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
#define YUV_COLOR_SPACE_REC601      0
#define YUV_COLOR_SPACE_REC709      1
#define YUV_COLOR_SPACE_REC2020     2
#define YUV_COLOR_SPACE_IDENTITY    3

// The constants added to the Y, U and V components are applied in the fragment shader.

@@ -64,17 +65,36 @@ const mat3 YuvColorMatrixRec2020 = mat3(
    1.67867410714286 , -0.650424318505057,  0.0
);

// The matrix is stored in column-major.
// Identity is stored as GBR
const mat3 IdentityColorMatrix = mat3(
    0.0              ,  1.0,                0.0,
    0.0              ,  0.0,                1.0,
    1.0              ,  0.0,                0.0
);

mat3 get_yuv_color_matrix(int color_space) {
    switch (color_space) {
        case YUV_COLOR_SPACE_REC601:
            return YuvColorMatrixRec601;
        case YUV_COLOR_SPACE_REC709:
            return YuvColorMatrixRec709;
        case YUV_COLOR_SPACE_IDENTITY:
            return IdentityColorMatrix;
        default:
            return YuvColorMatrixRec2020;
    }
}

vec3 get_yuv_offset_vector(int color_space) {
    switch (color_space) {
        case YUV_COLOR_SPACE_IDENTITY:
            return vec3(0.0, 0.0, 0.0);
        default:
            return vec3(0.06275, 0.50196, 0.50196);
    }
}

void write_uv_rect(
    vec2 uv0,
    vec2 uv1,
@@ -99,6 +119,7 @@ void write_uv_rect(
vec4 sample_yuv(
    int format,
    mat3 yuv_color_matrix,
    vec3 yuv_offset_vector,
    float coefficient,
    vec3 yuv_layers,
    vec2 in_uv_y,
@@ -148,7 +169,7 @@ vec4 sample_yuv(
    }

    // See the YuvColorMatrix definition for an explanation of where the constants come from.
    vec3 rgb = yuv_color_matrix * (yuv_value * coefficient - vec3(0.06275, 0.50196, 0.50196));
    vec3 rgb = yuv_color_matrix * (yuv_value * coefficient - yuv_offset_vector);
    vec4 color = vec4(rgb, 1.0);

    return color;
+1 −0
Original line number Diff line number Diff line
@@ -1293,6 +1293,7 @@ pub enum YuvColorSpace {
    Rec601 = 0,
    Rec709 = 1,
    Rec2020 = 2,
    Identity = 3, // aka RGB as per ISO/IEC 23091-2:2019
}

#[repr(u8)]