Skip to content

Commit

Permalink
Final tweaks: use expect and remove unnecessary crate attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
ferjm committed Jul 4, 2019
1 parent 63920da commit 208473c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 55 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion components/constellation/constellation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ pub struct InitialConstellationState {

/// The XR device registry
pub webxr_registry: webxr_api::Registry,

pub glplayer_threads: Option<GLPlayerThreads>,

/// Application window's GL Context for Media player
Expand Down
2 changes: 1 addition & 1 deletion components/constellation/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ pub struct InitialPipelineState {

/// The XR device registry
pub webxr_registry: webxr_api::Registry,

/// Application window's GL Context for Media player
pub player_context: WindowGLContext,
}
Expand Down
2 changes: 0 additions & 2 deletions components/media/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

#![crate_name = "media"]
#![crate_type = "rlib"]
#![deny(unsafe_code)]

#[macro_use]
Expand Down
78 changes: 31 additions & 47 deletions components/webrender_traits/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

#![crate_name = "webrender_traits"]
#![crate_type = "rlib"]
#![deny(unsafe_code)]

use euclid::Size2D;
Expand Down Expand Up @@ -110,56 +108,42 @@ impl webrender::ExternalImageHandler for WebrenderExternalImageHandlers {
_channel_index: u8,
_rendering: webrender_api::ImageRendering,
) -> webrender::ExternalImage {
if let Some(handler_type) = self.external_images.lock().unwrap().get(&key) {
let (texture_id, uv) = match handler_type {
WebrenderImageHandlerType::WebGL => {
let (texture_id, size) = self.webgl_handler.as_mut().unwrap().lock(key.0);
(
texture_id,
webrender_api::TexelRect::new(
0.0,
size.height as f32,
size.width as f32,
0.0,
),
)
},
WebrenderImageHandlerType::Media => {
let (texture_id, size) = self.media_handler.as_mut().unwrap().lock(key.0);
(
texture_id,
webrender_api::TexelRect::new(
0.0,
0.0,
size.width as f32,
size.height as f32,
),
)
},
};
webrender::ExternalImage {
uv,
source: webrender::ExternalImageSource::NativeTexture(texture_id),
}
} else {
unreachable!()
let external_images = self.external_images.lock().unwrap();
let handler_type = external_images
.get(&key)
.expect("Tried to get unknown external image");
let (texture_id, uv) = match handler_type {
WebrenderImageHandlerType::WebGL => {
let (texture_id, size) = self.webgl_handler.as_mut().unwrap().lock(key.0);
(
texture_id,
webrender_api::TexelRect::new(0.0, size.height as f32, size.width as f32, 0.0),
)
},
WebrenderImageHandlerType::Media => {
let (texture_id, size) = self.media_handler.as_mut().unwrap().lock(key.0);
(
texture_id,
webrender_api::TexelRect::new(0.0, 0.0, size.width as f32, size.height as f32),
)
},
};
webrender::ExternalImage {
uv,
source: webrender::ExternalImageSource::NativeTexture(texture_id),
}
}

/// Unlock the external image. The WR should not read the image
/// content after this call.
fn unlock(&mut self, key: webrender_api::ExternalImageId, _channel_index: u8) {
if let Some(handler_type) = self.external_images.lock().unwrap().get(&key) {
match handler_type {
WebrenderImageHandlerType::WebGL => {
self.webgl_handler.as_mut().unwrap().unlock(key.0)
},
WebrenderImageHandlerType::Media => {
self.media_handler.as_mut().unwrap().unlock(key.0)
},
};
} else {
unreachable!();
}
let external_images = self.external_images.lock().unwrap();
let handler_type = external_images
.get(&key)
.expect("Tried to get unknown external image");
match handler_type {
WebrenderImageHandlerType::WebGL => self.webgl_handler.as_mut().unwrap().unlock(key.0),
WebrenderImageHandlerType::Media => self.media_handler.as_mut().unwrap().unlock(key.0),
};
}
}

0 comments on commit 208473c

Please sign in to comment.