Refactor gpu for strict Clippy checks

This commit is contained in:
Dylan M. Taylor committed 2026-10-27 23:47:06 +00:00
1 parent 2ed75b4ec3
commit 6ebc0180da
14 files changed
+326 -142

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
use super::convert::{W, words};
use super::textures::Resident;
use super::*;
use super::{DeviceHealth, F, I, Kernel, Plan, Rect, TILE_SIZE, TileCoord, U, plan, timing};
/// The uniform record of a pass.
pub(crate) fn op_words(p: &plan::Pass<'_>, tex: Option<[i32; 4]>, mask: Option<[i32; 4]>, map: Option<Rect>) -> Vec<u8> {
+1 -1
View File
@@ -4,7 +4,7 @@ use super::convert::{convert_tile, convert_tiles, keep_overlap, put_tiles, words
use super::kit::{Bound, FrameRes, texture_group, uniform_group};
use super::paging::cell_rect;
use super::textures::{CachedPattern, Cell, ChunkOut, ResKey, Resident, ResidentRef, Stats, Tex, TexKind};
use super::*;
use super::{Arc, Compositor, DocId, HashMap, I, Kernel, Pattern, Plan, Rect, Role, Surface, TILE_SIZE, TileCoord, plan};
impl Compositor {
/// Bring the pages of `cell` that `plan` samples up to date and resolve its effect maps.
+1 -1
View File
@@ -1,6 +1,6 @@
use super::batch::write_tile;
use super::textures::{Resident, TexKind};
use super::*;
use super::{Arc, F, HashMap, I, PixelFormat, Rect, SampleType, Surface, TILE_SIZE, Tile, TileCoord, U, fx};
/// Distinct tiles converted per parallel batch: bounds the converted bytes held at once (64 tiles
/// of a 16-bit page are 32 MiB).
+1 -1
View File
@@ -4,7 +4,7 @@ use super::convert::lut_texture;
use super::kit::FrameRes;
use super::paging::{OVER_BUDGET, cell_rect, first_error, grid_rect_count, grid_rects, lru_victims, scoped_work, uniform_buffer_len};
use super::textures::{ChunkOut, FxKey, ResKey, Resident, Stats};
use super::*;
use super::{Compositor, Document, LayerId, Plan, Rect, Surface, Unsupported, plan, timing};
impl Compositor {
/// Composite `region` of `doc`. Each finished chunk is passed to `sink` while its encoder is
+86 -85
View File
@@ -301,71 +301,96 @@ pub(crate) fn program(e: &Effect, light: &GlobalLight, vector_shape: bool) -> Ma
program_with(e, light, vector_shape, &[], (0.0, 0.0))
}
fn shadow_program(b: &mut B, s: &photocraft_doc::Shadow, inner: bool, light: &GlobalLight) -> usize {
let angle = if s.use_global_light { light.angle } else { s.angle };
let (dx, dy) = offset(angle, s.distance);
let src = b.shift(In::Shape, dx, dy, if inner { 1.0 } else { 0.0 }, inner);
let (r, bw) = photocraft_compose::effects::spread_split(s.size, s.spread);
let mut m = src;
if r > 0.0 {
let f = b.field(if inner { FieldKind::ChokeInside } else { FieldKind::StrokeOutside }, r);
let d = if dx == 0.0 && dy == 0.0 {
f
} else {
b.push(stage(Kernel::MShift, Some(f), None, [dx, dy, if inner { -0.5 } else { 1e10 }, 0.0], dx.abs().max(dy.abs()) as i32))
};
m = b.dilate(src, d, r);
}
let m = b.blur(m, bw);
b.finish(m, None, false, &s.contour, inner, 0);
1
}
fn glow_program(b: &mut B, g: &photocraft_doc::Glow, inner: bool) -> usize {
let center = inner && g.source == GlowSource::Center;
match g.technique {
GlowTechnique::Precise => {
let d = b.field(if inner { FieldKind::Inside } else { FieldKind::Outside }, g.size);
let solid = g.size * g.spread;
let soft = (g.size + 1.0 - solid).max(1e-3);
let m = b.push(stage(Kernel::MGlow, Some(d), None, [solid, soft, 0.0, 0.0], 0));
b.finish_glow(m, photocraft_compose::effects::glow_lut(g), inner, center);
}
GlowTechnique::Softer => {
let m = softer_glow_map(b, g, inner);
b.finish_glow(m, photocraft_compose::effects::glow_lut(g), inner, center);
}
}
1
}
fn softer_glow_map(b: &mut B, g: &photocraft_doc::Glow, inner: bool) -> In {
let src = if inner { b.shift(In::Shape, 0.0, 0.0, 0.0, true) } else { In::Shape };
let (r, bw) = photocraft_compose::effects::spread_split(g.size, g.spread);
let mut map = src;
if r > 0.0 {
let distance = b.field(if inner { FieldKind::ChokeInside } else { FieldKind::StrokeOutside }, r);
map = b.dilate(src, distance, r);
}
b.blur(map, bw)
}
fn satin_program(b: &mut B, s: &photocraft_doc::Satin) -> usize {
let (dx, dy) = offset(s.angle, photocraft_compose::effects::satin_distance(s));
let a = b.shift(In::Shape, dx, dy, 0.0, false);
let a = b.conv(a, photocraft_compose::effects::tent_kernel(s.size));
let c = b.shift(In::Shape, -dx, -dy, 0.0, false);
let c = b.conv(c, photocraft_compose::effects::tent_kernel(s.size));
b.finish_lut(a, Some(c), s.invert, photocraft_compose::effects::satin_lut(&s.contour), true, 0);
1
}
fn stroke_program(b: &mut B, st: &photocraft_doc::StrokeFx, vector_shape: bool) -> usize {
let (in_w, out_w) = stroke_widths(st);
if out_w > 0.0 {
let kind = match (vector_shape, photocraft_compose::effects::stroke_outside_exact(out_w)) {
(true, true) => FieldKind::StrokeOutsideVector,
(true, false) => FieldKind::StrokeOutsideVectorChamfer,
(false, true) => FieldKind::StrokeOutsideExact,
(false, false) => FieldKind::StrokeOutside,
};
let d = b.field(kind, out_w);
let mut s = stage(Kernel::MStroke, Some(d), None, [out_w, 0.0, 0.0, 0.0], 0);
s.out = Some(0);
b.stages.push(s);
}
if in_w > 0.0 {
let d = b.field(FieldKind::StrokeInside, in_w);
let mut s = stage(Kernel::MStroke, Some(d), None, [in_w, 0.0, 0.0, 0.0], 0);
s.out = Some(1);
b.stages.push(s);
}
2
}
/// The map program of one enabled effect (`build_maps`); bevel textures tile `patterns` from
/// `anchor` (`effects::TextureCtx`).
pub(crate) fn program_with(e: &Effect, light: &GlobalLight, vector_shape: bool, patterns: &[Pattern], anchor: (f64, f64)) -> MapProgram {
let mut b = B { stages: Vec::new(), fields: Vec::new() };
let maps = match e {
Effect::DropShadow(s) | Effect::InnerShadow(s) => {
// shadow_map
let inner = matches!(e, Effect::InnerShadow(_));
let angle = if s.use_global_light { light.angle } else { s.angle };
let (dx, dy) = offset(angle, s.distance);
let src = b.shift(In::Shape, dx, dy, if inner { 1.0 } else { 0.0 }, inner);
let (r, bw) = photocraft_compose::effects::spread_split(s.size, s.spread);
let mut m = src;
if r > 0.0 {
// dist_outside of the shifted map is the shifted field (integer offsets; shifted-in
// pixels are far away for a drop shadow, inside for an inner shadow).
let f = b.field(if inner { FieldKind::ChokeInside } else { FieldKind::StrokeOutside }, r);
let d = if dx == 0.0 && dy == 0.0 {
f
} else {
b.push(stage(Kernel::MShift, Some(f), None, [dx, dy, if inner { -0.5 } else { 1e10 }, 0.0], dx.abs().max(dy.abs()) as i32))
};
m = b.dilate(src, d, r);
}
let m = b.blur(m, bw);
b.finish(m, None, false, &s.contour, inner, 0);
1
}
Effect::OuterGlow(g) | Effect::InnerGlow(g) => {
// glow_map
let inner = matches!(e, Effect::InnerGlow(_));
let center = inner && g.source == GlowSource::Center;
match g.technique {
GlowTechnique::Precise => {
let d = b.field(if inner { FieldKind::Inside } else { FieldKind::Outside }, g.size);
let solid = g.size * g.spread;
let soft = (g.size + 1.0 - solid).max(1e-3);
let m = b.push(stage(Kernel::MGlow, Some(d), None, [solid, soft, 0.0, 0.0], 0));
b.finish_glow(m, photocraft_compose::effects::glow_lut(g), inner, center);
}
GlowTechnique::Softer => {
// Inner glows (edge, and centre as 1 - the edge result) spread 1 - alpha.
let src = if inner { b.shift(In::Shape, 0.0, 0.0, 0.0, true) } else { In::Shape };
let (r, bw) = photocraft_compose::effects::spread_split(g.size, g.spread);
let mut m = src;
if r > 0.0 {
let d = b.field(if inner { FieldKind::ChokeInside } else { FieldKind::StrokeOutside }, r);
m = b.dilate(src, d, r);
}
let m = b.blur(m, bw);
b.finish_glow(m, photocraft_compose::effects::glow_lut(g), inner, center);
}
}
1
}
Effect::Satin(s) => {
// satin_map
let (dx, dy) = offset(s.angle, photocraft_compose::effects::satin_distance(s));
let a = b.shift(In::Shape, dx, dy, 0.0, false);
let a = b.conv(a, photocraft_compose::effects::tent_kernel(s.size));
let c = b.shift(In::Shape, -dx, -dy, 0.0, false);
let c = b.conv(c, photocraft_compose::effects::tent_kernel(s.size));
b.finish_lut(a, Some(c), s.invert, photocraft_compose::effects::satin_lut(&s.contour), true, 0);
1
}
Effect::DropShadow(s) | Effect::InnerShadow(s) => shadow_program(&mut b, s, matches!(e, Effect::InnerShadow(_)), light),
Effect::OuterGlow(g) | Effect::InnerGlow(g) => glow_program(&mut b, g, matches!(e, Effect::InnerGlow(_))),
Effect::Satin(s) => satin_program(&mut b, s),
Effect::BevelEmboss(bv) => {
// bevel_maps: height map (tent blur of the shape, or chiselled distance ramps), then
// highlight / shadow shading inside and / or outside the shape.
@@ -434,31 +459,7 @@ pub(crate) fn program_with(e: &Effect, light: &GlobalLight, vector_shape: bool,
}
out
}
Effect::Stroke(st) => {
// composite_with_effects' stroke bands (maps 0 outside, 1 inside)
let (in_w, out_w) = stroke_widths(st);
if out_w > 0.0 {
// Narrow strokes keep the fitted chamfer, wide ones the exact transform (#3646);
// the CPU picks the same field by the same width (`stroke_outside_exact`).
let kind = match (vector_shape, photocraft_compose::effects::stroke_outside_exact(out_w)) {
(true, true) => FieldKind::StrokeOutsideVector,
(true, false) => FieldKind::StrokeOutsideVectorChamfer,
(false, true) => FieldKind::StrokeOutsideExact,
(false, false) => FieldKind::StrokeOutside,
};
let d = b.field(kind, out_w);
let mut s = stage(Kernel::MStroke, Some(d), None, [out_w, 0.0, 0.0, 0.0], 0);
s.out = Some(0);
b.stages.push(s);
}
if in_w > 0.0 {
let d = b.field(FieldKind::StrokeInside, in_w);
let mut s = stage(Kernel::MStroke, Some(d), None, [in_w, 0.0, 0.0, 0.0], 0);
s.out = Some(1);
b.stages.push(s);
}
2
}
Effect::Stroke(st) => stroke_program(&mut b, st, vector_shape),
Effect::ColorOverlay { .. } | Effect::GradientOverlay { .. } | Effect::PatternOverlay { .. } => return MapProgram::empty(),
};
let mut h = std::collections::hash_map::DefaultHasher::new();
+1 -1
View File
@@ -3,7 +3,7 @@ use super::consts::{MAP16, MAP32};
use super::kit::MapDraw;
use super::paging::field_reaches;
use super::textures::{FxEntry, FxKey, ProgState, Stats, Tex};
use super::*;
use super::{Arc, Compositor, Document, FieldKind, HashMap, LayerContent, Rect, Unsupported, fx, plan};
impl Compositor {
/// Build or update the effect maps of one layer over `region`: its whole effect region, or
+1 -1
View File
@@ -1,7 +1,7 @@
use super::consts::{CHUNK_UNIFORM, OP_UNIFORM, STRIDE};
use super::convert::{lut_texture, words};
use super::textures::{ResKey, ResidentRef};
use super::*;
use super::{Arc, HashMap, I, Kernel, NonZeroU64, Rect};
/// Pipelines and layouts, shared by cheap clones (wgpu handles are reference counted).
#[derive(Clone)]
+1 -1
View File
@@ -1,6 +1,6 @@
use super::consts::STRIDE;
use super::textures::Cell;
use super::*;
use super::{DeviceHealth, FieldKind, HashMap, Rect, Unsupported, fx};
/// Document pixels of page cell `c`.
pub(crate) fn cell_rect(c: Cell, page: u32) -> Rect {
+1 -1
View File
@@ -1,5 +1,5 @@
use super::types::Unsupported;
use super::*;
use super::{Adjustment, BlendMode, Fill, Gradient, Layer, LayerContent, Pattern, StrokePosition, ToneSpace, Transfer, adjust, lut3d_len};
/// Paint source of an effect.
pub(super) enum Paint<'a> {
+226 -45
View File
@@ -2,7 +2,7 @@ use super::lower::{
Paint, adjustment_on_gpu, adjustment_program, check_gradient_stops, gradient_rows, placement, single_content_pass, stroke_widths, style_index,
};
use super::types::{Checkpoint, DocCtx, FxLayer, Kernel, MapRef, MaskUse, Pass, Role, SurfaceRef, TexUse, Unsupported};
use super::*;
use super::{Adjustment, BlendMode, Effect, Fill, FxPaint, Glow, Layer, LayerContent, LayerId, Plan, Rect, Slot, Surface, bounds, has_effects};
pub(super) struct Planner<'a> {
passes: Vec<Pass<'a>>,
@@ -29,6 +29,27 @@ enum Cov {
One,
}
struct EffectState<'a> {
layer: &'a Layer,
items: Vec<&'a Effect>,
rev: Vec<(usize, &'a Effect)>,
fx: usize,
content: Slot,
lay_src: Slot,
vstroke: Option<Slot>,
backdrop: Slot,
w: Slot,
l: Slot,
clip: Rect,
sb: Rect,
anchor: (f64, f64),
outline: bool,
relative: bool,
vector_shape: bool,
atop: bool,
premerge: bool,
}
/// Shader flags for effect passes (keep in sync with compose.wgsl). Coverage `m` of a paint, with
/// `a` the layer's alpha and `inside` = `a > 0.5/255`:
/// knockout `m × (1 − a × k)` (k in `p4.w`); gate `inside ? m : 0`; rel `inside ? min(m / a, 1) : 0`;
@@ -133,6 +154,28 @@ pub const INIT_OUTLINE: i32 = 7;
/// `MapRef::item` of the layer's effect shape (`compose::layer_shape`) instead of an effect map.
pub const SHAPE_MAP: usize = usize::MAX;
fn check_effect_gradients(items: &[&Effect]) -> Result<(), Unsupported> {
for effect in items {
let gradient = match effect {
Effect::GradientOverlay { gradient, .. } => Some(gradient),
Effect::Stroke(stroke) => match &stroke.paint {
FxPaint::Gradient(g) => Some(g),
_ => None,
},
Effect::OuterGlow(glow) | Effect::InnerGlow(glow) => match &glow.paint {
FxPaint::Gradient(g) => Some(g),
_ => None,
},
_ => None,
};
if let Some(gradient) = gradient {
check_gradient_stops(&gradient.stops)?;
check_gradient_stops(&gradient.opacity_stops)?;
}
}
Ok(())
}
impl<'a> Planner<'a> {
pub(super) fn new(cx: DocCtx<'a>) -> Self {
Planner { passes: Vec::new(), free: Vec::new(), refs: Vec::new(), cx, fx: Vec::new(), checkpoints: Vec::new(), visits: 0 }
@@ -724,10 +767,11 @@ impl<'a> Planner<'a> {
Ok(self.emit(p))
}
/// `composite_with_effects` (atop = false) or the clipped-layer variant of `composite_atop`
/// (atop = true: effects over the base treated as opaque, keeping the base's alpha).
/// Plans enabled layer effects in the same phase order as the CPU compositor.
/// Consumes `backdrop`.
fn effects(&mut self, layer: &'a Layer, clipped: &[&'a Layer], backdrop: Slot, atop: bool) -> Result<Slot, Unsupported> {
let items: Vec<&'a Effect> = layer.effects.items.iter().filter(|e| e.enabled()).collect();
check_effect_gradients(&items)?;
let canvas = self.cx.canvas;
let region = bounds::effect_region(layer, canvas);
let sb = photocraft_compose::paint_bounds(layer).unwrap_or_else(|| bounds::layer_bounds(layer, canvas));
@@ -792,44 +836,67 @@ impl<'a> Planner<'a> {
content = self.emit(p);
}
let items: Vec<&'a Effect> = layer.effects.items.iter().filter(|e| e.enabled()).collect();
for e in &items {
let gradient = match e {
Effect::GradientOverlay { gradient, .. } => Some(gradient),
Effect::Stroke(s) => match &s.paint {
FxPaint::Gradient(g) => Some(g),
_ => None,
},
Effect::OuterGlow(g) | Effect::InnerGlow(g) => match &g.paint {
FxPaint::Gradient(g) => Some(g),
_ => None,
},
_ => None,
};
if let Some(g) = gradient {
check_gradient_stops(&g.stops)?;
check_gradient_stops(&g.opacity_stops)?;
}
}
// Linked patterns tile from the effects reference point (else the layer's top-left).
let premerge = photocraft_compose::effects::premerges_layer(layer);
let anchor = layer.effects.reference.unwrap_or((f64::from(sb.x0), f64::from(sb.y0)));
let vector_shape = matches!(layer.content, LayerContent::Shape(_)) && !outline;
let map = |item: usize, map: usize| MapRef { fx, item, map };
let rev: Vec<(usize, &'a Effect)> = items.iter().copied().enumerate().rev().collect();
let init = |s: &mut Self, src: Slot, b: Option<Slot>, kind: i32, opacity: f32| {
let mut p = Pass::new(Kernel::FxInit, 0);
p.a = Some(src);
p.b = b;
p.adjust_kind = kind;
p.opacity = opacity;
p.clip = Some(clip);
s.emit(p)
let rev = items.iter().copied().enumerate().rev().collect();
let mut work = EffectState {
layer,
items,
rev,
fx,
content,
lay_src,
vstroke,
backdrop,
w: backdrop,
l: lay_src,
clip,
sb,
anchor,
outline,
relative,
vector_shape,
atop,
premerge,
};
if let Some(merged) = self.effect_exterior(&mut work) {
self.release(work.content);
return Ok(merged);
}
self.effect_layer_base(&mut work);
self.effect_paints(&mut work);
self.effect_vector_stroke(&mut work);
self.effect_inside_strokes(&mut work);
self.effect_inner_bevel(&mut work);
self.effect_alpha(&mut work);
self.effect_outside_strokes(&mut work);
self.effect_outer_bevel(&mut work);
let merged = self.effect_merge(&mut work);
self.release(work.content);
Ok(self.write_back(work.backdrop, merged, work.clip))
}
fn effect_exterior(&mut self, work: &mut EffectState<'a>) -> Option<Slot> {
let layer = work.layer;
let items = work.items.clone();
let rev = work.rev.clone();
let fx = work.fx;
let content = work.content;
let lay_src = work.lay_src;
let backdrop = work.backdrop;
let clip = work.clip;
let sb = work.sb;
let atop = work.atop;
let relative = work.relative;
let premerge = work.premerge;
let anchor = work.anchor;
let map = |item: usize, map: usize| MapRef { fx, item, map };
// Exterior effects over the backdrop (an opaque copy of it for clipped layers).
let mut w = if atop {
let b = self.retain(backdrop);
init(self, b, None, INIT_OPAQUE, 1.0)
self.fx_init(clip, b, None, INIT_OPAQUE, 1.0)
} else {
self.retain(backdrop)
};
@@ -866,7 +933,6 @@ impl<'a> Planner<'a> {
// Only exterior effects (drop shadows, outer glows): nothing is painted between the
// layer's colour inside its shape and the shape's alpha, so the merge derives both from
// the shape (`F_LAYER_SHAPE`) instead of two passes building the layer.
let premerge = photocraft_compose::effects::premerges_layer(layer);
if !relative && !premerge && items.iter().all(|e| matches!(e, Effect::DropShadow(_) | Effect::OuterGlow(_))) {
let mut p = Pass::new(Kernel::FxMerge, 0);
p.a = Some(w);
@@ -879,16 +945,28 @@ impl<'a> Planner<'a> {
p.extra[3] = photocraft_compose::text_gamma(layer);
p.clip = Some(clip);
let merged = self.emit(p);
self.release(content);
return Ok(self.write_back(backdrop, merged, clip));
let merged = self.write_back(backdrop, merged, clip);
return Some(merged);
}
work.w = w;
None
}
fn effect_layer_base(&mut self, work: &mut EffectState<'a>) {
let layer = work.layer;
let content = work.content;
let lay_src = work.lay_src;
let w = work.w;
let clip = work.clip;
let relative = work.relative;
let premerge = work.premerge;
// The layer: its colour at fill opacity inside its shape; interior effects are painted
// relative to the shape (coverage within it), then the shape's alpha applies.
let mut l = if relative {
let c = self.retain(content);
init(self, lay_src, Some(c), INIT_RELATIVE, layer.fill_opacity)
self.fx_init(clip, lay_src, Some(c), INIT_RELATIVE, layer.fill_opacity)
} else {
init(self, lay_src, None, INIT_INSIDE, layer.fill_opacity)
self.fx_init(clip, lay_src, None, INIT_INSIDE, layer.fill_opacity)
};
// Blend Interior Effects as Group off: the layer merges in its mode first and the
// interior effects paint over the result (`effects::premerges_layer`).
@@ -902,6 +980,18 @@ impl<'a> Planner<'a> {
p.clip = Some(clip);
l = self.emit(p);
}
work.l = l;
}
fn effect_paints(&mut self, work: &mut EffectState<'a>) {
let rev = work.rev.clone();
let fx = work.fx;
let content = work.content;
let mut l = work.l;
let clip = work.clip;
let sb = work.sb;
let anchor = work.anchor;
let map = |item: usize, map: usize| MapRef { fx, item, map };
for &(_, e) in &rev {
if let Effect::PatternOverlay { common, name, id, scale, angle, link, phase } = e
&& let Some(pat) = photocraft_doc::pattern::find(self.cx.patterns, id, name).filter(|p| p.is_paintable())
@@ -936,6 +1026,15 @@ impl<'a> Planner<'a> {
l = self.paint(l, content, Cov::Map(map(i, 0), 0.0), &Paint::Color(s.color.to_rgb()), s.common.blend, s.common.opacity, F_REL, clip, sb);
}
}
work.l = l;
}
fn effect_vector_stroke(&mut self, work: &mut EffectState<'a>) {
let layer = work.layer;
let content = work.content;
let mut l = work.l;
let vstroke = work.vstroke;
let clip = work.clip;
if let Some(s) = vstroke {
let mut p = Pass::new(Kernel::FxInit, 0);
p.a = Some(l);
@@ -946,6 +1045,19 @@ impl<'a> Planner<'a> {
p.clip = Some(clip);
l = self.emit(p);
}
work.l = l;
}
fn effect_inside_strokes(&mut self, work: &mut EffectState<'a>) {
let layer = work.layer;
let rev = work.rev.clone();
let fx = work.fx;
let content = work.content;
let mut l = work.l;
let clip = work.clip;
let sb = work.sb;
let anchor = work.anchor;
let map = |item: usize, map: usize| MapRef { fx, item, map };
// Inside stroke parts are painted over the layer (bottom instance first).
for &(i, e) in &rev {
if let Effect::Stroke(st) = e {
@@ -966,6 +1078,17 @@ impl<'a> Planner<'a> {
}
}
}
work.l = l;
}
fn effect_inner_bevel(&mut self, work: &mut EffectState<'a>) {
let rev = work.rev.clone();
let fx = work.fx;
let content = work.content;
let mut l = work.l;
let clip = work.clip;
let sb = work.sb;
let map = |item: usize, map: usize| MapRef { fx, item, map };
let bevel_paint = |b: &photocraft_doc::Bevel| photocraft_compose::effects::bevel_geom(b).paint;
for &(i, e) in &rev {
if let Effect::BevelEmboss(b) = e
@@ -985,9 +1108,32 @@ impl<'a> Planner<'a> {
l = self.paint(l, content, Cov::Map(map(i, 1), 0.0), &Paint::Color(b.shadow_color.to_rgb()), b.shadow.blend, b.shadow.opacity, F_REL, clip, sb);
}
}
work.l = l;
}
fn effect_alpha(&mut self, work: &mut EffectState<'a>) {
let content = work.content;
let mut l = work.l;
let clip = work.clip;
// The shape's own alpha.
let c = self.retain(content);
l = init(self, l, Some(c), INIT_ALPHA, 1.0);
l = self.fx_init(clip, l, Some(c), INIT_ALPHA, 1.0);
work.l = l;
}
fn effect_outside_strokes(&mut self, work: &mut EffectState<'a>) {
let layer = work.layer;
let items = work.items.clone();
let fx = work.fx;
let content = work.content;
let mut w = work.w;
let l = work.l;
let clip = work.clip;
let sb = work.sb;
let anchor = work.anchor;
let outline = work.outline;
let vector_shape = work.vector_shape;
let map = |item: usize, map: usize| MapRef { fx, item, map };
// Outside stroke parts lie beneath the layer and blend onto the exterior result with their
// own mode; a higher stroke covers the ones below it (each takes its coverage × opacity
// not yet taken above it, blended over the result as it was before the strokes).
@@ -1004,7 +1150,7 @@ impl<'a> Planner<'a> {
// The layer's alpha rides along the coverage: `effects::outline_share`, and for
// pixel layers the stroke's share beneath a partly covering layer (fill < 100 %).
let ll = self.retain(l);
cover = Some(init(self, ll, None, INIT_COVER, 1.0));
cover = Some(self.fx_init(clip, ll, None, INIT_COVER, 1.0));
}
for (n, &(i, st)) in outs.iter().enumerate() {
let paint = self.fx_paint(&st.paint, anchor);
@@ -1046,6 +1192,18 @@ impl<'a> Planner<'a> {
p.clip = Some(clip);
w = self.emit(p);
}
work.w = w;
}
fn effect_outer_bevel(&mut self, work: &mut EffectState<'a>) {
let rev = work.rev.clone();
let bevel_paint = |b: &photocraft_doc::Bevel| photocraft_compose::effects::bevel_geom(b).paint;
let fx = work.fx;
let content = work.content;
let mut w = work.w;
let clip = work.clip;
let sb = work.sb;
let map = |item: usize, map: usize| MapRef { fx, item, map };
for &(i, e) in &rev {
if let Effect::BevelEmboss(b) = e
&& bevel_paint(b) == photocraft_compose::effects::BevelPaint::Outer
@@ -1066,13 +1224,30 @@ impl<'a> Planner<'a> {
}
}
work.w = w;
}
fn effect_merge(&mut self, work: &mut EffectState<'a>) -> Slot {
let layer = work.layer;
let rev = work.rev.clone();
let fx = work.fx;
let content = work.content;
let w = work.w;
let l = work.l;
let backdrop = work.backdrop;
let clip = work.clip;
let sb = work.sb;
let atop = work.atop;
let premerge = work.premerge;
let bevel_paint = |b: &photocraft_doc::Bevel| photocraft_compose::effects::bevel_geom(b).paint;
let map = |item: usize, map: usize| MapRef { fx, item, map };
let mode = if premerge || layer.blend == BlendMode::PassThrough { BlendMode::Normal } else { layer.blend };
let late: Vec<(usize, &'a photocraft_doc::Bevel)> = rev
.iter()
.filter_map(|&(i, e)| if let Effect::BevelEmboss(b) = e { Some((i, b)) } else { None })
.filter(|(_, b)| bevel_paint(b) == photocraft_compose::effects::BevelPaint::Both)
.collect();
let merged = if late.is_empty() {
if late.is_empty() {
let mut p = Pass::new(Kernel::FxMerge, 0);
p.a = Some(w);
p.b = Some(l);
@@ -1110,11 +1285,17 @@ impl<'a> Planner<'a> {
p.flags = if atop { F_ATOP } else { 0 } | F_NO_LAYER;
p.clip = Some(clip);
self.emit(p)
};
self.release(content);
}
}
// Write the clipped result back into the backdrop (in place when nothing else holds it).
Ok(self.write_back(backdrop, merged, clip))
fn fx_init(&mut self, clip: Rect, src: Slot, b: Option<Slot>, kind: i32, opacity: f32) -> Slot {
let mut pass = Pass::new(Kernel::FxInit, 0);
pass.a = Some(src);
pass.b = b;
pass.adjust_kind = kind;
pass.opacity = opacity;
pass.clip = Some(clip);
self.emit(pass)
}
fn fx_paint(&self, p: &'a FxPaint, anchor: (f64, f64)) -> Paint<'a> {
+1 -1
View File
@@ -1,4 +1,4 @@
use super::*;
use super::{BlendMode, Document, GlobalLight, Layer, LayerId, Pattern, Rect, Slot, Surface, Transfer};
/// Pipeline (fragment entry point) of a pass.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
+1 -1
View File
@@ -1,5 +1,5 @@
use super::textures::Stats;
use super::*;
use super::{Compositor, Document, Rect, Unsupported};
/// Blocking readback of a composite (native tests and tools).
#[cfg(not(target_arch = "wasm32"))]
+3 -1
View File
@@ -3,7 +3,9 @@ use super::consts::{ACC_FORMAT, CHUNK, CHUNK_UNIFORM, FX_BUDGET, MAP16, MAP32, O
use super::kit::{Kit, SHADER, tex_entry, uniform_entry};
use super::paging::{cell_rect, field_reaches, first_error, grid_rects};
use super::textures::{FxEntry, Resident, Tex, TexKind};
use super::*;
use super::{
Compositor, DeviceHealth, DocId, Document, Fault, HashMap, Kernel, LayerContent, Plan, Rect, Role, TILE_SIZE, Unsupported, fx, plan, prefix, timing,
};
impl Compositor {
/// Create a compositor with the default accumulation format ([`ACC_FORMAT`]).
+1 -1
View File
@@ -1,4 +1,4 @@
use super::*;
use super::{Arc, DocId, FieldKind, HashMap, LayerId, PixelFormat, Rect, Role, SampleType, Tile, TileCoord, fx, timing};
/// A finished chunk: straight-alpha RGBA32F pixels of `rect` (document coordinates) at the
/// texture's origin.