Commit a90be57f authored by Dan Sheppard's avatar Dan Sheppard
Browse files

Tidying at performance pinch-point for firefox.

parent 276c4a8c
use composit::SourceResponse;
use composit::Source;
use shape::DrawnShape;
use drawing::Drawing;
use drawing::DrawingSession;
use print::PrintEdition;
use print::Programs;
use shape::{ ShapeSpec, Shape };
pub struct DrawnResponse {
shapes: Option<Vec<DrawnShape>>,
shapes: Option<Vec<ShapeSpec>>,
drawings: Vec<Option<Drawing>>,
sr: SourceResponse,
part: Option<String>
}
impl DrawnResponse {
pub fn new(sr: SourceResponse, part: &Option<String>) -> DrawnResponse {
DrawnResponse { sr, shapes: None, part: part.clone() }
DrawnResponse {
sr,
shapes: None,
drawings: Vec::<Option<Drawing>>::new(),
part: part.clone()
}
}
fn populate(&mut self) {
let mut shapes = Vec::<DrawnShape>::new();
let specs = self.sr.get_shapes(&self.part);
shapes.reserve(specs.len());
for spec in specs {
shapes.push(DrawnShape::new(spec.to_shape()));
}
self.shapes = Some(shapes);
self.shapes = Some(specs);
}
#[allow(unused)]
pub fn size(&self) -> usize { self.shapes.as_ref().unwrap().len() }
pub fn get_response(&self) -> &SourceResponse { &self.sr }
pub fn is_done(&self) -> bool { self.sr.is_done() }
pub fn each_shape<F>(&mut self, mut cb: F) where F: FnMut(&mut DrawnShape) {
pub fn redraw(&mut self, ds: &mut DrawingSession) {
if self.sr.is_done() {
if self.shapes.is_none() {
self.populate();
}
self.drawings.clear();
for mut s in self.shapes.as_mut().unwrap().iter_mut() {
if let Some(a) = s.get_artist() {
let ocm = a.select_canvas(ds);
self.drawings.push(Some(ocm.add_request(a)));
} else {
self.drawings.push(None);
}
}
}
}
pub fn into_objects(&mut self, progs: &mut Programs,
ds: &mut DrawingSession, e: &mut PrintEdition) {
if self.sr.is_done() {
if self.shapes.is_none() {
self.populate();
}
let mut di = self.drawings.iter();
for mut s in self.shapes.as_mut().unwrap().iter_mut() {
cb(s);
let d = di.next();
let geom_name = s.get_geometry();
if let Some(geom) = progs.map.get_mut(&geom_name) {
let artwork = d.unwrap().as_ref().map(|r| r.artwork(ds));
s.into_objects(&mut geom.data,artwork,e);
}
}
}
}
......
......@@ -44,12 +44,12 @@ impl Carriage {
}
pub(in super) fn is_done(&self) -> bool {
self.response.as_ref().map(|x| x.get_response().is_done()).unwrap_or(false)
self.response.as_ref().map(|x| x.is_done()).unwrap_or(false)
}
pub fn draw_drawings(&mut self, ds: &mut DrawingSession) {
if let Some(ref mut response) = self.response {
response.each_shape(|s| s.redraw(ds));
response.redraw(ds);
}
}
......@@ -57,7 +57,7 @@ impl Carriage {
progs: &mut Programs,
ds: &mut DrawingSession, e: &mut PrintEdition) {
if let Some(ref mut response) = self.response {
response.each_shape(|s| s.into_objects(progs,ds,e));
response.into_objects(progs,ds,e);
}
}
......
......@@ -52,10 +52,6 @@ impl DrawingSession {
pub fn get_canvas_cache(&self) -> &CanvasCache {
&self.canvascache
}
pub fn redraw_component(&mut self, c: &mut Carriage) {
c.draw_drawings(self);
}
pub fn finalise(&mut self, aca: &mut AllCanvasAllocator) {
for (ref weave,ref mut ocm) in &mut self.canvases {
......
......@@ -35,7 +35,7 @@ impl LeafPrinter {
self.ds.finish(alloc);
self.ds = alloc.make_drawing_session();
for mut c in comps.iter_mut() {
self.ds.redraw_component(*c);
c.draw_drawings(&mut self.ds);
}
self.ds.finalise(alloc);
}
......@@ -59,6 +59,16 @@ impl LeafPrinter {
self.progs.finalize_objects(&self.ctx,&mut self.ds);
e.go(&mut self.progs);
}
fn redraw_carriages(&mut self, comps: &mut Vec<&mut Carriage>, aca: &mut AllCanvasAllocator, do_drawings: bool) {
self.init();
let mut e = self.new_edition();
if do_drawings {
self.redraw_drawings(aca,comps);
}
self.redraw_objects(comps,&mut e);
self.fini(&mut e);
}
pub fn into_objects(&mut self, leaf: &Leaf,
sc: &mut Train,
......@@ -67,14 +77,7 @@ impl LeafPrinter {
if level == ComponentRedo::None { return; }
if let Some(ref mut comps) = sc.get_carriages(leaf) {
if comps.len() > 0 {
self.init();
if level == ComponentRedo::Major {
self.redraw_drawings(aca,comps);
}
let mut e = self.new_edition();
self.redraw_objects(comps,&mut e);
/* Useful for debugging performance */
self.fini(&mut e);
self.redraw_carriages(comps,aca,level == ComponentRedo::Major);
}
}
}
......
......@@ -30,8 +30,9 @@ impl CanvasIdx {
if let Some(obj) = geom.get_object("uSampler") {
if let Some(m) = self.group.get(&geom_name) {
for (w,g) in m {
let idx = self.glindexes[w] as i32;
obj.set_uniform(Some(*g),UniformValue::Int(idx));
if let Some(idx) = self.glindexes.get(w) {
obj.set_uniform(Some(*g),UniformValue::Int(*idx as i32));
}
}
}
}
......
......@@ -11,7 +11,7 @@ mod texture;
mod boxshape;
pub use self::shapeimpl::{
Shape, DrawnShape,
Shape,
ColourSpec,
MathsShape,
};
......
......@@ -11,36 +11,6 @@ pub trait Shape {
fn get_geometry(&self) -> ProgramType;
}
pub struct DrawnShape {
shape: Box<Shape>,
drawing: Option<Drawing>
}
impl DrawnShape {
pub fn new(shape: Box<Shape>) -> DrawnShape {
DrawnShape {
shape,
drawing: None
}
}
pub fn redraw(&mut self, ds: &mut DrawingSession) {
if let Some(a) = self.shape.get_artist() {
let ocm = a.select_canvas(ds);
self.drawing = Some(ocm.add_request(a));
}
}
pub fn into_objects(&self, progs: &mut Programs,
ds: &mut DrawingSession, e: &mut PrintEdition) {
let geom_name = self.shape.get_geometry();
if let Some(geom) = progs.map.get_mut(&geom_name) {
let artwork = self.drawing.as_ref().map(|r| r.artwork(ds));
self.shape.into_objects(&mut geom.data,artwork,e);
}
}
}
#[derive(Clone,Copy,Debug)]
pub enum ColourSpec {
Colour(Colour),
......
use std::rc::Rc;
use shape::{
PinPolySpec, RectSpec, Shape, TextureSpec, StretchTextureSpec,
StretchWiggle, BoxSpec
};
use program::{ ProgramAttribs, DataGroupIndex, ProgramType };
use types::{ Colour };
use print::{ Programs, PrintEdition };
use drawing::{ Artist, Artwork, Drawing, DrawingSession };
#[derive(Clone)]
pub enum ShapeSpec {
PinPoly(PinPolySpec),
......@@ -14,7 +22,7 @@ pub enum ShapeSpec {
}
impl ShapeSpec {
pub fn to_shape(self) -> Box<Shape> {
pub fn as_shape(&self) -> Box<&Shape> {
match self {
ShapeSpec::PinPoly(pp) => Box::new(pp),
ShapeSpec::PinRect(pr) => Box::new(pr),
......@@ -25,3 +33,17 @@ impl ShapeSpec {
}
}
}
impl Shape for ShapeSpec {
fn get_artist(&self) -> Option<Rc<Artist>> {
self.as_shape().get_artist()
}
fn into_objects(&self, geom: &mut ProgramAttribs, art: Option<Artwork>,e: &mut PrintEdition) {
self.as_shape().into_objects(geom,art,e)
}
fn get_geometry(&self) -> ProgramType {
self.as_shape().get_geometry()
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment