...
 
Commits (4)
......@@ -27,6 +27,18 @@ stable:test:
# image: "rustlang/rust:nightly"
# <<: *cargo_test
# Configure and run rustfmt on nightly
# Exits and build fails on bad format
rustfmt:
image: "rustlang/rust:nightly"
stage: lint
variables:
CFG_RELEASE_CHANNEL: "nightly"
script:
- rustc --version && cargo --version
- cargo install rustfmt-nightly --force
- cargo fmt --all -- --write-mode=diff
# Configure and run clippy on nightly
clippy:
image: "rustlang/rust:nightly"
......
unstable_features = true
indent_style = "Visual"
verbose = false
max_width = 100
comment_width = 100
wrap_comments = true
tab_spaces = 4
hard_tabs = false
newline_style = "Unix"
write_mode = "Overwrite"
condense_wildcard_suffixes = false
format_strings = true
# normalize_comments = true
reorder_imports = true
reorder_imported_names = true
reorder_imports_in_group = true
......@@ -24,24 +24,25 @@ use std::thread;
use std::time::Duration;
use structopt::StructOpt;
#[cfg_attr(rustfmt, rustfmt_skip)]
#[derive(StructOpt, Debug)]
#[structopt(name = "rsvg-bench", about = "Benchmarking utility for librsvg.")]
struct Opt {
#[structopt(short = "s",
long = "sleep",
help = "Number of seconds to sleep before starting to process SVGs",
long = "sleep",
help = "Number of seconds to sleep before starting to process SVGs",
default_value = "0")]
sleep_secs: usize,
#[structopt(short = "p",
long = "num-parse",
help = "Number of times to parse each file",
long = "num-parse",
help = "Number of times to parse each file",
default_value = "100")]
num_parse: usize,
#[structopt(short = "r",
long = "num-render",
help = "Number of times to render each file",
long = "num-render",
help = "Number of times to render each file",
default_value = "100")]
num_render: usize,
......@@ -49,20 +50,17 @@ struct Opt {
help = "Render to a GdkPixbuf instead of a Cairo image surface")]
render_to_pixbuf: bool,
#[structopt(help = "Input files or directories",
parse(from_os_str))]
inputs: Vec<PathBuf>
#[structopt(help = "Input files or directories", parse(from_os_str))]
inputs: Vec<PathBuf>,
}
#[derive(Debug, Fail)]
enum ProcessingError {
#[fail(display = "Cairo error: {:?}", status)]
CairoError {
status: cairo::Status
},
CairoError { status: cairo::Status },
#[fail(display = "Rendering error")]
RenderingError
RenderingError,
}
impl From<cairo::Status> for ProcessingError {
......@@ -106,7 +104,7 @@ fn process_file<P: AsRef<Path>>(opt: &Opt, path: P) -> Result<(), Error> {
assert!(opt.num_parse > 0);
for _ in 0 .. opt.num_parse - 1 {
for _ in 0..opt.num_parse - 1 {
// FIXME: this exercises the rsvg_handle_write() / rsvg_handle_close() path.
// Should we provide an option to use a GInputStream?
let _ = rsvg::Handle::new_from_data(bytes)?;
......@@ -114,7 +112,7 @@ fn process_file<P: AsRef<Path>>(opt: &Opt, path: P) -> Result<(), Error> {
let handle = rsvg::Handle::new_from_data(bytes)?;
for _ in 0 .. opt.num_render {
for _ in 0..opt.num_render {
if opt.render_to_pixbuf {
render_to_pixbuf(&handle)?;
} else {
......@@ -127,15 +125,13 @@ fn process_file<P: AsRef<Path>>(opt: &Opt, path: P) -> Result<(), Error> {
fn render_to_pixbuf(handle: &rsvg::Handle) -> Result<(), ProcessingError> {
handle.get_pixbuf()
.ok_or_else(|| ProcessingError::RenderingError)
.map(|_| ())
.ok_or_else(|| ProcessingError::RenderingError)
.map(|_| ())
}
fn render_to_cairo(handle: &rsvg::Handle) -> Result<(), ProcessingError> {
let dim = handle.get_dimensions();
let surface = cairo::ImageSurface::create(cairo::Format::ARgb32,
dim.width,
dim.height)?;
let surface = cairo::ImageSurface::create(cairo::Format::ARgb32, dim.width, dim.height)?;
let cr = cairo::Context::new(&surface);
......@@ -144,7 +140,6 @@ fn render_to_cairo(handle: &rsvg::Handle) -> Result<(), ProcessingError> {
} else {
Err(ProcessingError::RenderingError)
}
}
fn sleep(secs: usize) {
......@@ -162,7 +157,8 @@ fn print_options(opt: &Opt) {
"Cairo image surface"
});
}
println!("Sleeping for {} seconds before processing SVGs...", opt.sleep_secs);
println!("Sleeping for {} seconds before processing SVGs...",
opt.sleep_secs);
}
fn run(opt: &Opt) -> Result<(), Error> {
......