@@ -6,6 +6,11 @@ pub mod viewport;
66pub mod window;
77
88pub mod internal {
9+ use std:: {
10+ borrow:: Borrow ,
11+ rc:: Rc ,
12+ } ;
13+
914 use lambda_platform:: gfx:: api:: RenderingAPI as RenderContext ;
1015 pub type RenderBackend = RenderContext :: Backend ;
1116
@@ -60,14 +65,14 @@ pub mod internal {
6065 /// Gets the surface for the given render context.
6166 pub fn surface_for_context (
6267 context : & super :: RenderContext ,
63- ) -> & Surface < RenderBackend > {
64- return & context. surface ;
68+ ) -> Rc < Surface < RenderBackend > > {
69+ return context. surface . clone ( ) ;
6570 }
6671}
6772
6873use std:: {
69- borrow:: Borrow ,
7074 mem:: swap,
75+ rc:: Rc ,
7176} ;
7277
7378use lambda_platform:: gfx:: {
@@ -152,7 +157,7 @@ impl RenderContextBuilder {
152157 name,
153158 instance,
154159 gpu,
155- surface : Box :: new ( surface) ,
160+ surface : Rc :: new ( surface) ,
156161 submission_fence : Some ( submission_fence) ,
157162 render_semaphore : Some ( render_semaphore) ,
158163 command_pool : Some ( command_pool) ,
@@ -168,7 +173,7 @@ pub struct RenderContext {
168173 name : String ,
169174 instance : internal:: Instance < internal:: RenderBackend > ,
170175 gpu : internal:: Gpu < internal:: RenderBackend > ,
171- surface : Box < internal:: Surface < internal:: RenderBackend > > ,
176+ surface : Rc < internal:: Surface < internal:: RenderBackend > > ,
172177 submission_fence :
173178 Option < internal:: RenderSubmissionFence < internal:: RenderBackend > > ,
174179 render_semaphore : Option < internal:: RenderSemaphore < internal:: RenderBackend > > ,
@@ -193,8 +198,10 @@ impl RenderContext {
193198 render_pass. take ( ) . unwrap ( ) . destroy ( & self ) ;
194199 }
195200
196- self . surface . remove_swapchain ( & self . gpu ) ;
197- self . surface . destroy ( & self . instance ) ;
201+ // Takes the inner surface and destroys it.
202+ let mut surface = Rc :: try_unwrap ( self . surface ) . ok ( ) . unwrap ( ) ;
203+ surface. remove_swapchain ( & self . gpu ) ;
204+ surface. destroy ( & self . instance ) ;
198205 }
199206
200207 /// Allocates a command buffer and records commands to the GPU.
@@ -220,7 +227,7 @@ impl RenderContext {
220227 self
221228 . gpu
222229 . render_to_surface (
223- & mut self . surface ,
230+ Rc :: get_mut ( & mut self . surface ) . expect ( "" ) ,
224231 self . render_semaphore . as_mut ( ) . unwrap ( ) ,
225232 )
226233 . expect ( "Failed to render to the surface" ) ;
0 commit comments