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 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Bug 1607746 - Part 2: Clean up passing filter mode to shader r=nical

I removed the old opacity filter path in the brush_blend shader and cleaned up the filter mode
constants in the shader so there are less magic numbers. This should help if/when we move more
filters to their own shaders.

Depends on D59610

Differential Revision: https://phabricator.services.mozilla.com/D59611

[wrupdater] From https://hg.mozilla.org/mozilla-central/rev/5cd63d35010f9bf9538a37fb330127d459b7ccc0
  • Loading branch information
cbrewster authored and moz-gfx committed Jan 14, 2020
commit f7f68144c310cf59abf621babe2010fa75ab05e5
@@ -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;
@@ -1404,24 +1404,8 @@ impl BatchBuilder {
);
}
_ => {
let filter_mode = match filter {
Filter::Identity => 1, // matches `Contrast(1)`
Filter::Blur(..) => 0,
Filter::Contrast(..) => 1,
Filter::Grayscale(..) => 2,
Filter::HueRotate(..) => 3,
Filter::Invert(..) => 4,
Filter::Saturate(..) => 5,
Filter::Sepia(..) => 6,
Filter::Brightness(..) => 7,
Filter::Opacity(..) => 8,
Filter::DropShadows(..) => 9,
Filter::ColorMatrix(..) => 10,
Filter::SrgbToLinear => 11,
Filter::LinearToSrgb => 12,
Filter::ComponentTransfer => unreachable!(),
Filter::Flood(..) => 14,
};
// Must be kept in sync with brush_blend.glsl
let filter_mode = filter.as_int();

let user_data = match filter {
Filter::Identity => 0x10000i32, // matches `Contrast(1)`
@@ -1430,26 +1414,25 @@ impl BatchBuilder {
Filter::Invert(amount) |
Filter::Saturate(amount) |
Filter::Sepia(amount) |
Filter::Brightness(amount) |
Filter::Opacity(_, amount) => {
Filter::Brightness(amount) => {
(amount * 65536.0) as i32
}
Filter::SrgbToLinear | Filter::LinearToSrgb => 0,
Filter::HueRotate(angle) => {
(0.01745329251 * angle * 65536.0) as i32
}
// Go through different paths
Filter::Blur(..) |
Filter::DropShadows(..) => {
unreachable!();
}
Filter::ColorMatrix(_) => {
picture.extra_gpu_data_handles[0].as_int(gpu_cache)
}
Filter::ComponentTransfer => unreachable!(),
Filter::Flood(_) => {
picture.extra_gpu_data_handles[0].as_int(gpu_cache)
}

// These filters are handled via different paths.
Filter::ComponentTransfer |
Filter::Blur(..) |
Filter::DropShadows(..) |
Filter::Opacity(..) => unreachable!(),
};

let (uv_rect_address, textures) = render_tasks.resolve_surface(
@@ -1491,7 +1474,7 @@ impl BatchBuilder {
// except we store a little more data in the filter mode and
// a gpu cache handle in the user data.
let filter_data = &ctx.data_stores.filter_data[handle];
let filter_mode : i32 = 13 |
let filter_mode : i32 = Filter::ComponentTransfer.as_int() |
((filter_data.data.r_func.to_int() << 28 |
filter_data.data.g_func.to_int() << 24 |
filter_data.data.b_func.to_int() << 20 |
@@ -163,6 +163,29 @@ impl Filter {
Filter::Flood(..) => false,
}
}


pub fn as_int(&self) -> i32 {
// Must be kept in sync with brush_blend.glsl
match *self {
Filter::Identity => 0, // matches `Contrast(1)`
Filter::Contrast(..) => 0,
Filter::Grayscale(..) => 1,
Filter::HueRotate(..) => 2,
Filter::Invert(..) => 3,
Filter::Saturate(..) => 4,
Filter::Sepia(..) => 5,
Filter::Brightness(..) => 6,
Filter::ColorMatrix(..) => 7,
Filter::SrgbToLinear => 8,
Filter::LinearToSrgb => 9,
Filter::Flood(..) => 10,
Filter::ComponentTransfer => 11,
Filter::Blur(..) => 12,
Filter::DropShadows(..) => 13,
Filter::Opacity(..) => 14,
}
}
}

impl From<FilterOp> for Filter {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.