Skip to content

Commit

Permalink
Address missing feedback from #38 (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
wkozyra95 authored Aug 2, 2023
1 parent 6c4513d commit 8608847
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 29 deletions.
2 changes: 1 addition & 1 deletion compositor_render/src/render_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub(super) fn populate_inputs(
) {
for (input_id, (node, input_textures)) in &mut scene.inputs {
let frame = frames.remove(input_id).unwrap();
node.output.ensure_size(ctx.wgpu_ctx, &frame.resolution);
node.output.ensure_size(ctx.wgpu_ctx, frame.resolution);
input_textures.upload(ctx.wgpu_ctx, frame);
}

Expand Down
2 changes: 1 addition & 1 deletion compositor_render/src/renderer/color_converter_pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ impl RGBAToYUVConverter {
}),
store: true,
},
view: &dst.plain(plane).view,
view: &dst.plane(plane).view,
resolve_target: None,
})],
depth_stencil_attachment: None,
Expand Down
8 changes: 4 additions & 4 deletions compositor_render/src/renderer/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl Node {
inputs: Vec<Arc<Node>>,
) -> Result<Self, GetError> {
let node = TransformNode::new(ctx, &spec.transform_params)?;
let output = NodeTexture::new(ctx.wgpu_ctx, &spec.resolution);
let output = NodeTexture::new(ctx.wgpu_ctx, spec.resolution);
Ok(Self {
node_id: spec.node_id.clone(),
transform: node,
Expand All @@ -94,7 +94,7 @@ impl Node {
}

pub fn new_input(ctx: &RenderCtx, spec: &InputSpec) -> Result<Self, GetError> {
let output = NodeTexture::new(ctx.wgpu_ctx, &spec.resolution);
let output = NodeTexture::new(ctx.wgpu_ctx, spec.resolution);

Ok(Self {
node_id: spec.input_id.0.clone(),
Expand Down Expand Up @@ -140,7 +140,7 @@ impl Scene {
.iter()
.map(|output| {
let node = self.ensure_node(ctx, &output.input_pad, &spec, &mut new_nodes)?;
let buffers = OutputTexture::new(ctx.wgpu_ctx, &node.resolution);
let buffers = OutputTexture::new(ctx.wgpu_ctx, node.resolution);
Ok((output.output_id.clone(), (node, buffers)))
})
.collect::<Result<_, _>>()?;
Expand Down Expand Up @@ -187,7 +187,7 @@ impl Scene {
InputId(node_id.clone()),
(
node.clone(),
InputTexture::new(ctx.wgpu_ctx, &input.resolution),
InputTexture::new(ctx.wgpu_ctx, input.resolution),
),
);
return Ok(node);
Expand Down
26 changes: 12 additions & 14 deletions compositor_render/src/renderer/texture.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::{
io::Write,
mem,
ops::DerefMut,
sync::{Arc, Mutex},
};

Expand Down Expand Up @@ -32,20 +30,20 @@ pub struct InputTexture {
}

impl InputTexture {
pub fn new(ctx: &WgpuCtx, resolution: &Resolution) -> Self {
pub fn new(ctx: &WgpuCtx, resolution: Resolution) -> Self {
let textures = YUVTextures::new(ctx, resolution);
let bind_group = textures.new_bind_group(ctx, &ctx.yuv_bind_group_layout);

Self {
textures,
bind_group,
resolution: *resolution,
resolution,
}
}

pub fn upload(&mut self, ctx: &WgpuCtx, frame: Arc<Frame>) {
if frame.resolution != self.resolution {
self.textures = YUVTextures::new(ctx, &frame.resolution);
self.textures = YUVTextures::new(ctx, frame.resolution);
self.bind_group = self
.textures
.new_bind_group(ctx, &ctx.yuv_bind_group_layout);
Expand All @@ -69,7 +67,7 @@ struct InnerNodeTexture {
}

impl InnerNodeTexture {
pub fn new(ctx: &WgpuCtx, resolution: &Resolution) -> Self {
pub fn new(ctx: &WgpuCtx, resolution: Resolution) -> Self {
let texture = RGBATexture::new(ctx, resolution);
let bind_group = texture.new_bind_group(ctx, &ctx.rgba_bind_group_layout);

Expand All @@ -86,18 +84,18 @@ pub struct NodeTexture {
}

impl NodeTexture {
pub fn new(ctx: &WgpuCtx, resolution: &Resolution) -> Self {
pub fn new(ctx: &WgpuCtx, resolution: Resolution) -> Self {
Self {
inner: InnerNodeTexture::new(ctx, resolution).into(),
resolution: *resolution,
resolution,
}
}

pub fn ensure_size(&self, ctx: &WgpuCtx, resolution: &Resolution) {
if *resolution != self.resolution {
pub fn ensure_size(&self, ctx: &WgpuCtx, resolution: Resolution) {
if resolution != self.resolution {
let new_inner = InnerNodeTexture::new(ctx, resolution);
let mut guard = self.inner.lock().unwrap();
let _ = mem::replace(guard.deref_mut(), new_inner);
*guard = new_inner;
}
}

Expand All @@ -119,7 +117,7 @@ pub struct OutputTexture {
}

impl OutputTexture {
pub fn new(ctx: &WgpuCtx, resolution: &Resolution) -> Self {
pub fn new(ctx: &WgpuCtx, resolution: Resolution) -> Self {
let textures = YUVTextures::new(ctx, resolution);
let buffers = textures.new_download_buffers(ctx);
Self {
Expand All @@ -133,8 +131,8 @@ impl OutputTexture {
&self.textures
}

pub fn resolution(&self) -> &Resolution {
&self.resolution
pub fn resolution(&self) -> Resolution {
self.resolution
}

pub fn start_download<'a>(
Expand Down
2 changes: 1 addition & 1 deletion compositor_render/src/renderer/texture/rgba.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use super::base::Texture;
pub struct RGBATexture(Texture);

impl RGBATexture {
pub fn new(ctx: &WgpuCtx, resolution: &Resolution) -> Self {
pub fn new(ctx: &WgpuCtx, resolution: Resolution) -> Self {
Self(Texture::new(
ctx,
None,
Expand Down
10 changes: 5 additions & 5 deletions compositor_render/src/renderer/texture/yuv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ where
y,
u,
v,
_phantom: Default::default(),
_phantom: PhantomData,
}
}

Expand All @@ -48,7 +48,7 @@ pub struct YUVTextures {
}

impl YUVTextures {
pub fn new(ctx: &WgpuCtx, resolution: &Resolution) -> Self {
pub fn new(ctx: &WgpuCtx, resolution: Resolution) -> Self {
Self {
planes: [
Self::new_plane(ctx, resolution.width, resolution.height),
Expand All @@ -58,7 +58,7 @@ impl YUVTextures {
}
}

pub fn plain(&self, i: usize) -> &Texture {
pub fn plane(&self, i: usize) -> &Texture {
&self.planes[i]
}

Expand Down Expand Up @@ -125,8 +125,8 @@ impl YUVTextures {
]
}

fn new_download_buffer(&self, ctx: &WgpuCtx, plain: usize) -> Buffer {
let size = self.planes[plain].size();
fn new_download_buffer(&self, ctx: &WgpuCtx, plane: usize) -> Buffer {
let size = self.planes[plane].size();
ctx.device.create_buffer(&wgpu::BufferDescriptor {
label: Some("output texture buffer"),
mapped_at_creation: false,
Expand Down
2 changes: 1 addition & 1 deletion compositor_render/src/transformations/web_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl WebRenderer {
let session_id = ctx
.electron
.client
.new_session(&params.url, &params.resolution)?;
.new_session(&params.url, params.resolution)?;

Ok(Self { session_id, params })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl ElectronApiClient {
pub fn new_session(
&self,
url: &str,
resolution: &Resolution,
resolution: Resolution,
) -> Result<SessionId, ElectronApiError> {
let resp: NewSessionResponse = self
.client
Expand Down Expand Up @@ -56,7 +56,7 @@ impl ElectronApiClient {
#[derive(Serialize)]
struct NewSessionRequest<'a> {
url: &'a str,
resolution: &'a Resolution,
resolution: Resolution,
}

#[derive(Deserialize)]
Expand Down

0 comments on commit 8608847

Please sign in to comment.