Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions webrender/res/ps_blend.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -91,33 +91,22 @@ void main(void) {
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

vec4 Contrast(vec4 Cs, float amount) {
return vec4(Cs.rgb * amount - 0.5 * amount + 0.5, 1.0);
return vec4(Cs.rgb * amount - 0.5 * amount + 0.5, Cs.a);
}

vec4 Invert(vec4 Cs, float amount) {
Cs.rgb /= Cs.a;

vec3 color = mix(Cs.rgb, vec3(1.0) - Cs.rgb, amount);

// Pre-multiply the alpha into the output value.
return vec4(color.rgb * Cs.a, Cs.a);
return vec4(mix(Cs.rgb, vec3(1.0) - Cs.rgb, amount), Cs.a);
}

vec4 Brightness(vec4 Cs, float amount) {
// Un-premultiply the input.
Cs.rgb /= Cs.a;

// Apply the brightness factor.
// Resulting color needs to be clamped to output range
// since we are pre-multiplying alpha in the shader.
vec3 color = clamp(Cs.rgb * amount, vec3(0.0), vec3(1.0));

// Pre-multiply the alpha into the output value.
return vec4(color.rgb * Cs.a, Cs.a);
return vec4(clamp(Cs.rgb * amount, vec3(0.0), vec3(1.0)), Cs.a);
}

vec4 Opacity(vec4 Cs, float amount) {
return Cs * amount;
return vec4(Cs.rgb, Cs.a * amount);
}

void main(void) {
Expand All @@ -128,6 +117,9 @@ void main(void) {
discard;
}

// Un-premultiply the input.
Cs.rgb /= Cs.a;

switch (vOp) {
case 0:
oFragColor = Cs;
Expand All @@ -147,5 +139,8 @@ void main(void) {
default:
oFragColor = vColorMat * Cs;
}

// Pre-multiply the alpha into the output value.
oFragColor.rgb *= oFragColor.a;
}
#endif
13 changes: 13 additions & 0 deletions wrench/reftests/filters/filter-contrast-gray-alpha-1-ref.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
root:
items:
- type: stacking-context
bounds: [0, 0, 120, 120]
items:
- type: rect
bounds: [0, 0, 120, 120]
color: [255, 255, 255, 1]

- type: rect
bounds: [10, 10, 100, 100]
color: [223, 223, 223, 1]
13 changes: 13 additions & 0 deletions wrench/reftests/filters/filter-contrast-gray-alpha-1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
root:
items:
- type: stacking-context
bounds: [0, 0, 120, 120]
items:
- type: stacking-context
bounds: [10, 10, 100, 100]
filters: contrast(0)
items:
- type: rect
bounds: [0, 0, 100, 100]
color: [128, 128, 128, 0.25]
1 change: 1 addition & 0 deletions wrench/reftests/filters/reftest.list
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
== filter-brightness-2.yaml filter-brightness-2-ref.yaml
== filter-brightness-3.yaml filter-brightness-3-ref.yaml
== filter-brightness-4.yaml filter-brightness-4-ref.yaml
== filter-contrast-gray-alpha-1.yaml filter-contrast-gray-alpha-1-ref.yaml
== filter-invert.yaml filter-invert-ref.yaml
== filter-invert-2.yaml filter-invert-2-ref.yaml
== filter-large-blur-radius.yaml filter-large-blur-radius.png
Expand Down