ui: Eliminate allocating gfx::Canvas on the heap for every view.
PaintRecorder needs to present a gfx::Canvas instead of an SkCanvas.
Currently it does so via CreateCanvasWithoutScaling which returns
a new Canvas allocated on the heap. But mallocs are terrible, so
instead make it a constructor and have the canvas allocated as part
of ui::PaintRecorder on the stack.
This changes the time to record a single tab loading spinner from
0.138818 ms to 0.124487 ms per frame for a 10% reduction in time.
R=sky
BUG=466426
Review URL: https://codereview.chromium.org/1124223010
Cr-Commit-Position: refs/heads/master@{#329315}
diff --git a/ui/gfx/canvas.cc b/ui/gfx/canvas.cc
index 49822b7..0c4a5a0 100644
--- a/ui/gfx/canvas.cc
+++ b/ui/gfx/canvas.cc
@@ -59,13 +59,12 @@
canvas_(owned_canvas_.get()) {
}
-Canvas::~Canvas() {
+Canvas::Canvas(SkCanvas* canvas, float image_scale)
+ : image_scale_(image_scale), owned_canvas_(), canvas_(canvas) {
+ DCHECK(canvas);
}
-// static
-Canvas* Canvas::CreateCanvasWithoutScaling(SkCanvas* canvas,
- float image_scale) {
- return new Canvas(canvas, image_scale);
+Canvas::~Canvas() {
}
void Canvas::RecreateBackingCanvas(const Size& size,
@@ -544,13 +543,6 @@
canvas_->concat(transform.matrix());
}
-Canvas::Canvas(SkCanvas* canvas, float image_scale)
- : image_scale_(image_scale),
- owned_canvas_(),
- canvas_(canvas) {
- DCHECK(canvas);
-}
-
bool Canvas::IntersectsClipRectInt(int x, int y, int w, int h) {
SkRect clip;
return canvas_->getClipBounds(&clip) &&