Skip to content

Commit

Permalink
Rustfmt net_traits crate
Browse files Browse the repository at this point in the history
  • Loading branch information
pyfisch committed Nov 3, 2018
1 parent f512e26 commit d41be1d
Show file tree
Hide file tree
Showing 10 changed files with 229 additions and 131 deletions.
35 changes: 30 additions & 5 deletions components/net_traits/filemanager_thread.rs
Expand Up @@ -114,21 +114,46 @@ pub struct SelectedFile {
#[derive(Debug, Deserialize, Serialize)]
pub enum FileManagerThreadMsg {
/// Select a single file. Last field is pre-selected file path for testing
SelectFile(Vec<FilterPattern>, IpcSender<FileManagerResult<SelectedFile>>, FileOrigin, Option<String>),
SelectFile(
Vec<FilterPattern>,
IpcSender<FileManagerResult<SelectedFile>>,
FileOrigin,
Option<String>,
),

/// Select multiple files. Last field is pre-selected file paths for testing
SelectFiles(Vec<FilterPattern>, IpcSender<FileManagerResult<Vec<SelectedFile>>>, FileOrigin, Option<Vec<String>>),
SelectFiles(
Vec<FilterPattern>,
IpcSender<FileManagerResult<Vec<SelectedFile>>>,
FileOrigin,
Option<Vec<String>>,
),

/// Read FileID-indexed file in chunks, optionally check URL validity based on boolean flag
ReadFile(IpcSender<FileManagerResult<ReadFileProgress>>, Uuid, bool, FileOrigin),
ReadFile(
IpcSender<FileManagerResult<ReadFileProgress>>,
Uuid,
bool,
FileOrigin,
),

/// Add an entry as promoted memory-based blob and send back the associated FileID
/// as part of a valid/invalid Blob URL depending on the boolean flag
PromoteMemory(BlobBuf, bool, IpcSender<Result<Uuid, BlobURLStoreError>>, FileOrigin),
PromoteMemory(
BlobBuf,
bool,
IpcSender<Result<Uuid, BlobURLStoreError>>,
FileOrigin,
),

/// Add a sliced entry pointing to the parent FileID, and send back the associated FileID
/// as part of a valid Blob URL
AddSlicedURLEntry(Uuid, RelativePos, IpcSender<Result<Uuid, BlobURLStoreError>>, FileOrigin),
AddSlicedURLEntry(
Uuid,
RelativePos,
IpcSender<Result<Uuid, BlobURLStoreError>>,
FileOrigin,
),

/// Decrease reference count and send back the acknowledgement
DecRef(Uuid, FileOrigin, IpcSender<Result<(), BlobURLStoreError>>),
Expand Down
48 changes: 24 additions & 24 deletions components/net_traits/image/base.rs
Expand Up @@ -33,8 +33,11 @@ pub struct Image {

impl fmt::Debug for Image {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Image {{ width: {}, height: {}, format: {:?}, ..., id: {:?} }}",
self.width, self.height, self.format, self.id)
write!(
f,
"Image {{ width: {}, height: {}, format: {:?}, ..., id: {:?} }}",
self.width, self.height, self.format, self.id
)
}
}

Expand All @@ -58,32 +61,29 @@ pub fn load_from_memory(buffer: &[u8]) -> Option<Image> {
debug!("{}", msg);
None
},
Ok(_) => {
match piston_image::load_from_memory(buffer) {
Ok(image) => {
let mut rgba = match image {
DynamicImage::ImageRgba8(rgba) => rgba,
image => image.to_rgba(),
};
pixels::byte_swap_colors_inplace(&mut *rgba);
Some(Image {
width: rgba.width(),
height: rgba.height(),
format: PixelFormat::BGRA8,
bytes: IpcSharedMemory::from_bytes(&*rgba),
id: None,
})
},
Err(e) => {
debug!("Image decoding error: {:?}", e);
None
},
}
Ok(_) => match piston_image::load_from_memory(buffer) {
Ok(image) => {
let mut rgba = match image {
DynamicImage::ImageRgba8(rgba) => rgba,
image => image.to_rgba(),
};
pixels::byte_swap_colors_inplace(&mut *rgba);
Some(Image {
width: rgba.width(),
height: rgba.height(),
format: PixelFormat::BGRA8,
bytes: IpcSharedMemory::from_bytes(&*rgba),
id: None,
})
},
Err(e) => {
debug!("Image decoding error: {:?}", e);
None
},
},
}
}


// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img
pub fn detect_image_format(buffer: &[u8]) -> Result<ImageFormat, &str> {
if is_gif(buffer) {
Expand Down
15 changes: 9 additions & 6 deletions components/net_traits/image_cache.rs
Expand Up @@ -101,16 +101,19 @@ pub enum UsePlaceholder {
// ======================================================================

pub trait ImageCache: Sync + Send {
fn new(webrender_api: webrender_api::RenderApi) -> Self where Self: Sized;
fn new(webrender_api: webrender_api::RenderApi) -> Self
where
Self: Sized;

/// Return any available metadata or image for the given URL,
/// or an indication that the image is not yet available if it is in progress,
/// or else reserve a slot in the cache for the URL if the consumer can request images.
fn find_image_or_metadata(&self,
url: ServoUrl,
use_placeholder: UsePlaceholder,
can_request: CanRequestImages)
-> Result<ImageOrMetadataAvailable, ImageState>;
fn find_image_or_metadata(
&self,
url: ServoUrl,
use_placeholder: UsePlaceholder,
can_request: CanRequestImages,
) -> Result<ImageOrMetadataAvailable, ImageState>;

/// Add a new listener for the given pending image id. If the image is already present,
/// the responder will still receive the expected response.
Expand Down

0 comments on commit d41be1d

Please sign in to comment.