@@ -16,7 +16,7 @@ use device::{TextureFilter, VAOId, VertexUsageHint, FileWatcherHandler, TextureT
16
16
use euclid:: Matrix4D ;
17
17
use fnv:: FnvHasher ;
18
18
use internal_types:: { CacheTextureId , RendererFrame , ResultMsg , TextureUpdateOp } ;
19
- use internal_types:: { TextureUpdateList , PackedVertex , RenderTargetMode } ;
19
+ use internal_types:: { ExternalImageUpdateList , TextureUpdateList , PackedVertex , RenderTargetMode } ;
20
20
use internal_types:: { ORTHO_NEAR_PLANE , ORTHO_FAR_PLANE , SourceTexture } ;
21
21
use internal_types:: { BatchTextures , TextureSampler , GLContextHandleWrapper } ;
22
22
use profiler:: { Profiler , BackendProfileCounters } ;
@@ -710,10 +710,12 @@ impl Renderer {
710
710
// Pull any pending results and return the most recent.
711
711
while let Ok ( msg) = self . result_rx . try_recv ( ) {
712
712
match msg {
713
- ResultMsg :: UpdateTextureCache ( update_list) => {
714
- self . pending_texture_updates . push ( update_list) ;
715
- }
716
- ResultMsg :: NewFrame ( frame, profile_counters) => {
713
+ ResultMsg :: NewFrame ( frame, texture_update_list, external_image_update_list, profile_counters) => {
714
+ self . pending_texture_updates . push ( texture_update_list) ;
715
+
716
+ // When a new frame is ready, we could start to update all pending external image requests here.
717
+ self . release_external_images ( external_image_update_list) ;
718
+
717
719
self . backend_profile_counters = profile_counters;
718
720
719
721
// Update the list of available epochs for use during reftests.
@@ -1262,7 +1264,7 @@ impl Renderer {
1262
1264
let props = & deferred_resolve. image_properties ;
1263
1265
let external_id = props. external_id
1264
1266
. expect ( "BUG: Deferred resolves must be external images!" ) ;
1265
- let image = handler. get ( external_id) ;
1267
+ let image = handler. lock ( external_id) ;
1266
1268
1267
1269
let texture_id = match image. source {
1268
1270
ExternalImageSource :: NativeTexture ( texture_id) => TextureId :: new ( texture_id) ,
@@ -1277,13 +1279,25 @@ impl Renderer {
1277
1279
}
1278
1280
}
1279
1281
1280
- fn release_external_textures ( & mut self ) {
1282
+ fn unlock_external_images ( & mut self ) {
1281
1283
if !self . external_images . is_empty ( ) {
1282
1284
let handler = self . external_image_handler
1283
1285
. as_mut ( )
1284
1286
. expect ( "Found external image, but no handler set!" ) ;
1285
1287
1286
1288
for ( external_id, _) in self . external_images . drain ( ) {
1289
+ handler. unlock ( external_id) ;
1290
+ }
1291
+ }
1292
+ }
1293
+
1294
+ fn release_external_images ( & mut self , mut pending_external_image_updates : ExternalImageUpdateList ) {
1295
+ if !pending_external_image_updates. is_empty ( ) {
1296
+ let handler = self . external_image_handler
1297
+ . as_mut ( )
1298
+ . expect ( "found external image updates, but no handler set!" ) ;
1299
+
1300
+ for external_id in pending_external_image_updates. drain ( ..) {
1287
1301
handler. release ( external_id) ;
1288
1302
}
1289
1303
}
@@ -1388,7 +1402,7 @@ impl Renderer {
1388
1402
}
1389
1403
}
1390
1404
1391
- self . release_external_textures ( ) ;
1405
+ self . unlock_external_images ( ) ;
1392
1406
}
1393
1407
1394
1408
pub fn debug_renderer < ' a > ( & ' a mut self ) -> & ' a mut DebugRenderer {
@@ -1427,10 +1441,19 @@ pub struct ExternalImage {
1427
1441
pub source : ExternalImageSource ,
1428
1442
}
1429
1443
1430
- /// Interface that an application can implement
1431
- /// to support providing external image buffers.
1444
+ /// The interfaces that an application can implement to support providing
1445
+ /// external image buffers.
1446
+ /// When the the application passes an external image to WR, it should kepp that
1447
+ /// external image life time untile the release() call.
1432
1448
pub trait ExternalImageHandler {
1433
- fn get ( & mut self , key : ExternalImageId ) -> ExternalImage ;
1449
+ /// Lock the external image. Then, WR could start to read the image content.
1450
+ /// The WR client should not change the image content until the unlock()
1451
+ /// call.
1452
+ fn lock ( & mut self , key : ExternalImageId ) -> ExternalImage ;
1453
+ /// Unlock the external image. The WR should not read the image content
1454
+ /// after this call.
1455
+ fn unlock ( & mut self , key : ExternalImageId ) ;
1456
+ /// Tell the WR client that it could start to release this external image.
1434
1457
fn release ( & mut self , key : ExternalImageId ) ;
1435
1458
}
1436
1459
0 commit comments