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

Implement filter: brightness. #422

Merged
merged 1 commit into from Sep 27, 2016
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Implement filter: brightness.

Fixes #421.
  • Loading branch information
gw3583 committed Sep 27, 2016
commit 5e5b3ae3537db9fec0ddcaafd054713d0f32d2d0
@@ -6,5 +6,5 @@ uniform sampler2D sCache;

void main(void) {
vec4 color = texture(sCache, vUv);
oFragColor = vec4(color.rgb, color.a * vOpacity);
oFragColor = vec4(color.rgb * vBrightnessOpacity.x, color.a * vBrightnessOpacity.y);
}
@@ -3,4 +3,4 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

varying vec2 vUv;
varying float vOpacity;
varying vec2 vBrightnessOpacity;
@@ -15,7 +15,7 @@ void main(void) {
vec2 st0 = vec2(src.target_rect.xy) / 2048.0;
vec2 st1 = vec2(src.target_rect.xy + src.target_rect.zw) / 2048.0;
vUv = mix(st0, st1, aPosition.xy);
vOpacity = blend.src_id_target_id_opacity.z;
vBrightnessOpacity = blend.src_id_target_id_opacity.zw;

gl_Position = uTransform * vec4(local_pos, 0, 1);
}
@@ -225,10 +225,15 @@ impl AlphaBatcher {
info);
debug_assert!(ok)
}
AlphaRenderItem::Blend(src_id, opacity) => {
AlphaRenderItem::Blend(src_id, info) => {
let (opacity, brightness) = match info {
SimpleCompositeInfo::Opacity(opacity) => (opacity, 1.0),
SimpleCompositeInfo::Brightness(brightness) => (1.0, brightness),
};
let ok = batch.pack_blend(render_tasks.get_task_index(&src_id),
render_tasks.get_task_index(&task.task_id),
opacity);
opacity,
brightness);
debug_assert!(ok)
}
AlphaRenderItem::Primitive(sc_index, prim_index) => {
@@ -374,7 +379,7 @@ enum RenderTaskLocation {
#[derive(Debug)]
enum AlphaRenderItem {
Primitive(StackingContextIndex, PrimitiveIndex),
Blend(RenderTaskId, f32),
Blend(RenderTaskId, SimpleCompositeInfo),
Composite(RenderTaskId, RenderTaskId, PackedCompositeInfo),
}

@@ -1951,8 +1956,8 @@ pub struct PackedBoxShadowPrimitive {
pub struct PackedBlendPrimitive {
src_task_id: f32,
target_task_id: f32,
brightness: f32,
opacity: f32,
padding: f32,
}

#[derive(Debug, Copy, Clone)]
@@ -2057,14 +2062,15 @@ impl PrimitiveBatch {
fn pack_blend(&mut self,
src_rect_index: RenderTaskIndex,
target_rect_index: RenderTaskIndex,
opacity: f32) -> bool {
opacity: f32,
brightness: f32) -> bool {
match &mut self.data {
&mut PrimitiveBatchData::Blend(ref mut ubo_data) => {
ubo_data.push(PackedBlendPrimitive {
src_task_id: pack_as_float(src_rect_index.0 as u32),
target_task_id: pack_as_float(target_rect_index.0 as u32),
opacity: opacity,
padding: 0.0,
brightness: brightness,
});

true
@@ -2189,10 +2195,18 @@ impl Default for PackedStackingContext {
}
}

#[derive(Debug, Copy, Clone)]
enum SimpleCompositeInfo {
Opacity(f32),
Brightness(f32),
}

#[derive(Debug, Copy, Clone)]
enum CompositeKind {

This comment has been minimized.

@pcwalton

pcwalton Sep 27, 2016

Collaborator

Add a small comment here explaining what the difference is between simple and complex.

None,
Simple(f32),
// Requires only a single texture as input (e.g. most filters)
Simple(SimpleCompositeInfo),
// Requires two source textures (e.g. mix-blend-mode)
Complex(PackedCompositeInfo),
}

@@ -2211,9 +2225,13 @@ impl CompositeKind {
if opacity == 1.0 {
return CompositeKind::None;
} else {
return CompositeKind::Simple(opacity);
return CompositeKind::Simple(SimpleCompositeInfo::Opacity(opacity));
}
}
LowLevelFilterOp::Brightness(amount) => {
let amount = amount.to_f32_px();
return CompositeKind::Simple(SimpleCompositeInfo::Brightness(amount));
}
_ => {}
}
}
@@ -2234,7 +2252,8 @@ impl StackingContext {
fn can_contribute_to_scene(&self) -> bool {
match self.composite_kind {
CompositeKind::None | CompositeKind::Complex(..) => true,
CompositeKind::Simple(opacity) => opacity > 0.0,
CompositeKind::Simple(SimpleCompositeInfo::Brightness(..)) => true,
CompositeKind::Simple(SimpleCompositeInfo::Opacity(opacity)) => opacity > 0.0,
}
}
}
@@ -2523,10 +2542,10 @@ impl ScreenTile {
let layer = &ctx.layer_store[sc_index.0];
match layer.composite_kind {
CompositeKind::None => {}
CompositeKind::Simple(opacity) => {
CompositeKind::Simple(info) => {
let mut prev_task = alpha_task_stack.pop().unwrap();
prev_task.as_alpha_batch().items.push(AlphaRenderItem::Blend(current_task.id,
opacity));
info));
prev_task.children.push(current_task);
current_task = prev_task;
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.