I know very little about the overall graphics system design, but I've had to use and review code using ImageSkia and Image a bit, so here are my 2
All image manipulation still appears to happen on SkBitmaps, generally using a class like:
// orig_rep.scale_factor() is not necessarily == scale_factor.
SkBitmap orig_bitmap = orig_rep.sk_bitmap();
SkBitmap transformed_bitmap = Whatever(orig_bitmap);
return ImageSkiaRep(transformed_bitmap, orig_rep.scale_factor());
}
private:
ImageSkia orig_;
}It's easy to get this wrong by passing |scale_factor| instead of |orig_rep.scale_factor()| into the returned ImageSkiaRep.
You'd think that the CanvasImageSource would help reduce the boilerplate, but it always returns the requested scale factor instead of propagating the scale provided by the underlying image.
The good graphics folks have started providing some utility functions in ui/gfx/image/image_skia_operations.h that work on gfx::ImageSkia, but they haven't done the same for gfx::Image, which means that any transformation on gfx::Image takes an extra unwrapping/wrapping step.
gfx::Image saves redundant conversions if you can save it in a data structure and use it for multiple platform operations. However, if you're computing a new gfx::Image for each platform operation, then it saves no conversions and just costs a couple extra allocations for its internal storage.
Therefore, the guideline I'm gradually settling on is that data structures that store images, that will be drawn directly on a UI with no transformation between the data structure and the UI, should hold gfx::Images, while functions that compute or transform images should operate on ImageSkias.
Have I missed anything or gotten anything wrong?
Jeffrey
P.S. I would love to read the design doc for this system, if one exists.