Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: ui/gfx/canvas.cc

Issue 1124223010: ui: Eliminate allocating gfx::Canvas on the heap for every view. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/canvas.h" 5 #include "ui/gfx/canvas.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 canvas_->scale(scale_scalar, scale_scalar); 56 canvas_->scale(scale_scalar, scale_scalar);
57 DrawImageInt(ImageSkia(image_rep), 0, 0); 57 DrawImageInt(ImageSkia(image_rep), 0, 0);
58 } 58 }
59 59
60 Canvas::Canvas() 60 Canvas::Canvas()
61 : image_scale_(1.0), 61 : image_scale_(1.0),
62 owned_canvas_(skia::AdoptRef(skia::CreatePlatformCanvas(0, 0, false))), 62 owned_canvas_(skia::AdoptRef(skia::CreatePlatformCanvas(0, 0, false))),
63 canvas_(owned_canvas_.get()) { 63 canvas_(owned_canvas_.get()) {
64 } 64 }
65 65
66 Canvas::Canvas(SkCanvas* canvas, float image_scale)
67 : image_scale_(image_scale), owned_canvas_(), canvas_(canvas) {
68 DCHECK(canvas);
69 }
70
66 Canvas::~Canvas() { 71 Canvas::~Canvas() {
67 } 72 }
68 73
69 // static
70 Canvas* Canvas::CreateCanvasWithoutScaling(SkCanvas* canvas,
71 float image_scale) {
72 return new Canvas(canvas, image_scale);
73 }
74
75 void Canvas::RecreateBackingCanvas(const Size& size, 74 void Canvas::RecreateBackingCanvas(const Size& size,
76 float image_scale, 75 float image_scale,
77 bool is_opaque) { 76 bool is_opaque) {
78 image_scale_ = image_scale; 77 image_scale_ = image_scale;
79 Size pixel_size = ToFlooredSize(ScaleSize(size, image_scale)); 78 Size pixel_size = ToFlooredSize(ScaleSize(size, image_scale));
80 owned_canvas_ = skia::AdoptRef(skia::CreatePlatformCanvas(pixel_size.width(), 79 owned_canvas_ = skia::AdoptRef(skia::CreatePlatformCanvas(pixel_size.width(),
81 pixel_size.height(), 80 pixel_size.height(),
82 is_opaque)); 81 is_opaque));
83 canvas_ = owned_canvas_.get(); 82 canvas_ = owned_canvas_.get();
84 SkScalar scale_scalar = SkFloatToScalar(image_scale); 83 SkScalar scale_scalar = SkFloatToScalar(image_scale);
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 } 540 }
542 541
543 void Canvas::EndPlatformPaint() { 542 void Canvas::EndPlatformPaint() {
544 skia::EndPlatformPaint(canvas_); 543 skia::EndPlatformPaint(canvas_);
545 } 544 }
546 545
547 void Canvas::Transform(const gfx::Transform& transform) { 546 void Canvas::Transform(const gfx::Transform& transform) {
548 canvas_->concat(transform.matrix()); 547 canvas_->concat(transform.matrix());
549 } 548 }
550 549
551 Canvas::Canvas(SkCanvas* canvas, float image_scale)
552 : image_scale_(image_scale),
553 owned_canvas_(),
554 canvas_(canvas) {
555 DCHECK(canvas);
556 }
557
558 bool Canvas::IntersectsClipRectInt(int x, int y, int w, int h) { 550 bool Canvas::IntersectsClipRectInt(int x, int y, int w, int h) {
559 SkRect clip; 551 SkRect clip;
560 return canvas_->getClipBounds(&clip) && 552 return canvas_->getClipBounds(&clip) &&
561 clip.intersect(SkIntToScalar(x), SkIntToScalar(y), SkIntToScalar(x + w), 553 clip.intersect(SkIntToScalar(x), SkIntToScalar(y), SkIntToScalar(x + w),
562 SkIntToScalar(y + h)); 554 SkIntToScalar(y + h));
563 } 555 }
564 556
565 bool Canvas::IntersectsClipRect(const Rect& rect) { 557 bool Canvas::IntersectsClipRect(const Rect& rect) {
566 return IntersectsClipRectInt(rect.x(), rect.y(), 558 return IntersectsClipRectInt(rect.x(), rect.y(),
567 rect.width(), rect.height()); 559 rect.width(), rect.height());
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 // by the paint). 625 // by the paint).
634 SkPaint p(paint); 626 SkPaint p(paint);
635 p.setFilterQuality(filter ? kLow_SkFilterQuality : kNone_SkFilterQuality); 627 p.setFilterQuality(filter ? kLow_SkFilterQuality : kNone_SkFilterQuality);
636 p.setShader(shader.get()); 628 p.setShader(shader.get());
637 629
638 // The rect will be filled by the bitmap. 630 // The rect will be filled by the bitmap.
639 canvas_->drawRect(dest_rect, p); 631 canvas_->drawRect(dest_rect, p);
640 } 632 }
641 633
642 } // namespace gfx 634 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698