Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync changes from mozilla-central #3831

Merged
merged 3 commits into from Jan 14, 2020
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -90,6 +90,7 @@ FWD_DECLARE_VS_FUNCTION(mix_blend_brush_vs)
FWD_DECLARE_VS_FUNCTION(linear_gradient_brush_vs)
FWD_DECLARE_VS_FUNCTION(radial_gradient_brush_vs)
FWD_DECLARE_VS_FUNCTION(yuv_brush_vs)
FWD_DECLARE_VS_FUNCTION(opacity_brush_vs)

void multi_brush_vs(
VertexInfo vi,
@@ -255,6 +256,7 @@ Fragment mix_blend_brush_fs();
Fragment linear_gradient_brush_fs();
Fragment radial_gradient_brush_fs();
Fragment yuv_brush_fs();
Fragment opacity_brush_fs();
Fragment multi_brush_fs(int brush_kind);

void main(void) {
@@ -14,6 +14,21 @@
#define COMPONENT_TRANSFER_LINEAR 3
#define COMPONENT_TRANSFER_GAMMA 4

// Must be kept in sync with `Filter::as_int` in internal_types.rs
// Not all filters are defined here because some filter use different shaders.
#define FILTER_CONTRAST 0
#define FILTER_GRAYSCALE 1
#define FILTER_HUE_ROTATE 2
#define FILTER_INVERT 3
#define FILTER_SATURATE 4
#define FILTER_SEPIA 5
#define FILTER_BRIGHTNESS 6
#define FILTER_COLOR_MATRIX 7
#define FILTER_SRGB_TO_LINEAR 8
#define FILTER_LINEAR_TO_SRGB 9
#define FILTER_FLOOD 10
#define FILTER_COMPONENT_TRANSFER 11

#include shared,prim_shared,brush

// Interpolated UV coordinates to sample.
@@ -100,8 +115,7 @@ void blend_brush_vs(
vFuncs[3] = (prim_user_data.y >> 16) & 0xf; // A

switch (V_OP) {
case 2: {
// Grayscale
case FILTER_GRAYSCALE: {
vColorMat = mat4(
vec4(lumR + oneMinusLumR * invAmount, lumR - lumR * invAmount, lumR - lumR * invAmount, 0.0),
vec4(lumG - lumG * invAmount, lumG + oneMinusLumG * invAmount, lumG - lumG * invAmount, 0.0),
@@ -111,8 +125,7 @@ void blend_brush_vs(
V_COLOR_OFFSET = vec4(0.0);
break;
}
case 3: {
// HueRotate
case FILTER_HUE_ROTATE: {
float c = cos(amount);
float s = sin(amount);
vColorMat = mat4(
@@ -124,8 +137,7 @@ void blend_brush_vs(
V_COLOR_OFFSET = vec4(0.0);
break;
}
case 5: {
// Saturate
case FILTER_SATURATE: {
vColorMat = mat4(
vec4(invAmount * lumR + amount, invAmount * lumR, invAmount * lumR, 0.0),
vec4(invAmount * lumG, invAmount * lumG + amount, invAmount * lumG, 0.0),
@@ -135,8 +147,7 @@ void blend_brush_vs(
V_COLOR_OFFSET = vec4(0.0);
break;
}
case 6: {
// Sepia
case FILTER_SEPIA: {
vColorMat = mat4(
vec4(0.393 + 0.607 * invAmount, 0.349 - 0.349 * invAmount, 0.272 - 0.272 * invAmount, 0.0),
vec4(0.769 - 0.769 * invAmount, 0.686 + 0.314 * invAmount, 0.534 - 0.534 * invAmount, 0.0),
@@ -146,21 +157,18 @@ void blend_brush_vs(
V_COLOR_OFFSET = vec4(0.0);
break;
}
case 10: {
// Color Matrix
case FILTER_COLOR_MATRIX: {
vec4 mat_data[4] = fetch_from_gpu_cache_4(prim_user_data.z);
vec4 offset_data = fetch_from_gpu_cache_1(prim_user_data.z + 4);
vColorMat = mat4(mat_data[0], mat_data[1], mat_data[2], mat_data[3]);
V_COLOR_OFFSET = offset_data;
break;
}
case 13: {
// Component Transfer
case FILTER_COMPONENT_TRANSFER: {
V_TABLE_ADDRESS = prim_user_data.z;
break;
}
case 14: {
// Flood
case FILTER_FLOOD: {
V_FLOOD_COLOR = fetch_from_gpu_cache_1(prim_user_data.z);
break;
}
@@ -269,40 +277,35 @@ Fragment blend_brush_fs() {
vec3 color = alpha != 0.0 ? Cs.rgb / alpha : Cs.rgb;

switch (V_OP) {
case 0:
break;
case 1:
case FILTER_CONTRAST:
color = Contrast(color, V_AMOUNT);
break;
case 4:
case FILTER_INVERT:
color = Invert(color, V_AMOUNT);
break;
case 7:
case FILTER_BRIGHTNESS:
color = Brightness(color, V_AMOUNT);
break;
case 8: // Opacity
alpha *= V_AMOUNT;
break;
case 11:
case FILTER_SRGB_TO_LINEAR:
color = SrgbToLinear(color);
break;
case 12:
case FILTER_LINEAR_TO_SRGB:
color = LinearToSrgb(color);
break;
case 13: {
// Component Transfer
case FILTER_COMPONENT_TRANSFER: {
// Get the unpremultiplied color with alpha.
vec4 colora = vec4(color, alpha);
colora = ComponentTransfer(colora);
color = colora.rgb;
alpha = colora.a;
break;
}
case 14: // Flood
case FILTER_FLOOD:
color = V_FLOOD_COLOR.rgb;
alpha = V_FLOOD_COLOR.a;
break;
default:
// Color matrix type filters (sepia, hue-rotate, etc...)
vec4 result = vColorMat * vec4(color, alpha) + V_COLOR_OFFSET;
result = clamp(result, vec4(0.0), vec4(1.0));
color = result.rgb;
@@ -21,6 +21,7 @@
#define BRUSH_KIND_BLEND 6
#define BRUSH_KIND_MIX_BLEND 7
#define BRUSH_KIND_YV 8
#define BRUSH_KIND_OPACITY 9

int vecs_per_brush(int brush_kind);

@@ -70,6 +71,14 @@ int vecs_per_brush(int brush_kind);
#include brush_radial_gradient
#endif

#undef VECS_PER_SPECIFIC_BRUSH
#undef WR_BRUSH_VS_FUNCTION
#undef WR_BRUSH_FS_FUNCTION

#ifdef WR_FEATURE_OPACITY_BRUSH
#include brush_opacity
#endif

int vecs_per_brush(int brush_kind) {
switch (brush_kind) {
// The default arm should never be taken, we let it point to whichever shader
@@ -99,6 +108,10 @@ int vecs_per_brush(int brush_kind) {
#ifdef WR_FEATURE_RADIAL_GRADIENT_BRUSH
case BRUSH_KIND_RADIAL_GRADIENT: return VECS_PER_RADIAL_GRADIENT_BRUSH;
#endif

#ifdef WR_FEATURE_OPACITY_BRUSH
case BRUSH_KIND_OPACITY: return VECS_PER_OPACITY_BRUSH;
#endif
}
}

@@ -159,6 +172,12 @@ void multi_brush_vs(
radial_gradient_brush_vs(BRUSH_VS_PARAMS);
break;
#endif

#ifdef WR_FEATURE_OPACITY_BRUSH
case BRUSH_KIND_OPACITY:
opacity_brush_vs(BRUSH_VS_PARAMS);
break;
#endif
}
}

@@ -193,6 +212,10 @@ Fragment multi_brush_fs(int brush_kind) {
#ifdef WR_FEATURE_RADIAL_GRADIENT_BRUSH
case BRUSH_KIND_RADIAL_GRADIENT: return radial_gradient_brush_fs();
#endif

#ifdef WR_FEATURE_OPACITY_BRUSH
case BRUSH_KIND_OPACITY: return opacity_brush_fs();
#endif
}
}

@@ -0,0 +1,91 @@
/* 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/. */

#define VECS_PER_OPACITY_BRUSH 3
#define VECS_PER_SPECIFIC_BRUSH VECS_PER_OPACITY_BRUSH

#define WR_BRUSH_VS_FUNCTION opacity_brush_vs
#define WR_BRUSH_FS_FUNCTION opacity_brush_fs

#include shared,prim_shared,brush

// Interpolated UV coordinates to sample.
#define V_UV varying_vec4_0.zw
#define V_LOCAL_POS varying_vec4_0.xy

// Normalized bounds of the source image in the texture.
#define V_UV_BOUNDS flat_varying_vec4_1

// Layer index to sample.
#define V_LAYER flat_varying_vec4_2.x
// Flag to allow perspective interpolation of UV.
#define V_PERSPECTIVE flat_varying_vec4_2.y

#define V_OPACITY flat_varying_vec4_2.z

#ifdef WR_VERTEX_SHADER
void opacity_brush_vs(
VertexInfo vi,
int prim_address,
RectWithSize local_rect,
RectWithSize segment_rect,
ivec4 prim_user_data,
int specific_resource_address,
mat4 transform,
PictureTask pic_task,
int brush_flags,
vec4 unused
) {
ImageResource res = fetch_image_resource(prim_user_data.x);
vec2 uv0 = res.uv_rect.p0;
vec2 uv1 = res.uv_rect.p1;

vec2 texture_size = vec2(textureSize(sColor0, 0).xy);
vec2 f = (vi.local_pos - local_rect.p0) / local_rect.size;
f = get_image_quad_uv(prim_user_data.x, f);
vec2 uv = mix(uv0, uv1, f);
float perspective_interpolate = (brush_flags & BRUSH_FLAG_PERSPECTIVE_INTERPOLATION) != 0 ? 1.0 : 0.0;

V_UV = uv / texture_size * mix(vi.world_pos.w, 1.0, perspective_interpolate);
V_LAYER = res.layer;
V_PERSPECTIVE = perspective_interpolate;

// TODO: The image shader treats this differently: deflate the rect by half a pixel on each side and
// clamp the uv in the frame shader. Does it make sense to do the same here?
V_UV_BOUNDS = vec4(uv0, uv1) / texture_size.xyxy;
V_LOCAL_POS = vi.local_pos;

V_OPACITY = float(prim_user_data.y) / 65536.0;
}
#endif

#ifdef WR_FRAGMENT_SHADER
Fragment opacity_brush_fs() {
float perspective_divisor = mix(gl_FragCoord.w, 1.0, V_PERSPECTIVE);
vec2 uv = V_UV * perspective_divisor;
vec4 Cs = texture(sColor0, vec3(uv, V_LAYER));

// Un-premultiply the input.
float alpha = Cs.a;
vec3 color = alpha != 0.0 ? Cs.rgb / alpha : Cs.rgb;

alpha *= V_OPACITY;

// Fail-safe to ensure that we don't sample outside the rendered
// portion of a blend source.
alpha *= min(point_inside_rect(uv, V_UV_BOUNDS.xy, V_UV_BOUNDS.zw),
init_transform_fs(V_LOCAL_POS));

// Pre-multiply the alpha into the output value.
return Fragment(alpha * vec4(color, 1.0));
}
#endif

// Undef macro names that could be re-defined by other shaders.
#undef V_UV
#undef V_LOCAL_POS
#undef V_UV_BOUNDS
#undef V_LAYER
#undef V_PERSPECTIVE
#undef V_OPACITY
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.