OLD | NEW |
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 canvas_->scale(scale_scalar, scale_scalar); | 52 canvas_->scale(scale_scalar, scale_scalar); |
53 DrawImageInt(ImageSkia(image_rep), 0, 0); | 53 DrawImageInt(ImageSkia(image_rep), 0, 0); |
54 } | 54 } |
55 | 55 |
56 Canvas::Canvas() | 56 Canvas::Canvas() |
57 : image_scale_(1.0), | 57 : image_scale_(1.0), |
58 owned_canvas_(skia::AdoptRef(skia::CreatePlatformCanvas(0, 0, false))), | 58 owned_canvas_(skia::AdoptRef(skia::CreatePlatformCanvas(0, 0, false))), |
59 canvas_(owned_canvas_.get()) { | 59 canvas_(owned_canvas_.get()) { |
60 } | 60 } |
61 | 61 |
| 62 Canvas::Canvas(SkCanvas* canvas, float image_scale) |
| 63 : image_scale_(image_scale), owned_canvas_(), canvas_(canvas) { |
| 64 DCHECK(canvas); |
| 65 } |
| 66 |
62 Canvas::~Canvas() { | 67 Canvas::~Canvas() { |
63 } | 68 } |
64 | 69 |
65 // static | |
66 Canvas* Canvas::CreateCanvasWithoutScaling(SkCanvas* canvas, | |
67 float image_scale) { | |
68 return new Canvas(canvas, image_scale); | |
69 } | |
70 | |
71 void Canvas::RecreateBackingCanvas(const Size& size, | 70 void Canvas::RecreateBackingCanvas(const Size& size, |
72 float image_scale, | 71 float image_scale, |
73 bool is_opaque) { | 72 bool is_opaque) { |
74 image_scale_ = image_scale; | 73 image_scale_ = image_scale; |
75 Size pixel_size = ToFlooredSize(ScaleSize(size, image_scale)); | 74 Size pixel_size = ToFlooredSize(ScaleSize(size, image_scale)); |
76 owned_canvas_ = skia::AdoptRef(skia::CreatePlatformCanvas(pixel_size.width(), | 75 owned_canvas_ = skia::AdoptRef(skia::CreatePlatformCanvas(pixel_size.width(), |
77 pixel_size.height(), | 76 pixel_size.height(), |
78 is_opaque)); | 77 is_opaque)); |
79 canvas_ = owned_canvas_.get(); | 78 canvas_ = owned_canvas_.get(); |
80 SkScalar scale_scalar = SkFloatToScalar(image_scale); | 79 SkScalar scale_scalar = SkFloatToScalar(image_scale); |
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 } | 536 } |
538 | 537 |
539 void Canvas::EndPlatformPaint() { | 538 void Canvas::EndPlatformPaint() { |
540 skia::EndPlatformPaint(canvas_); | 539 skia::EndPlatformPaint(canvas_); |
541 } | 540 } |
542 | 541 |
543 void Canvas::Transform(const gfx::Transform& transform) { | 542 void Canvas::Transform(const gfx::Transform& transform) { |
544 canvas_->concat(transform.matrix()); | 543 canvas_->concat(transform.matrix()); |
545 } | 544 } |
546 | 545 |
547 Canvas::Canvas(SkCanvas* canvas, float image_scale) | |
548 : image_scale_(image_scale), | |
549 owned_canvas_(), | |
550 canvas_(canvas) { | |
551 DCHECK(canvas); | |
552 } | |
553 | |
554 bool Canvas::IntersectsClipRectInt(int x, int y, int w, int h) { | 546 bool Canvas::IntersectsClipRectInt(int x, int y, int w, int h) { |
555 SkRect clip; | 547 SkRect clip; |
556 return canvas_->getClipBounds(&clip) && | 548 return canvas_->getClipBounds(&clip) && |
557 clip.intersect(SkIntToScalar(x), SkIntToScalar(y), SkIntToScalar(x + w), | 549 clip.intersect(SkIntToScalar(x), SkIntToScalar(y), SkIntToScalar(x + w), |
558 SkIntToScalar(y + h)); | 550 SkIntToScalar(y + h)); |
559 } | 551 } |
560 | 552 |
561 bool Canvas::IntersectsClipRect(const Rect& rect) { | 553 bool Canvas::IntersectsClipRect(const Rect& rect) { |
562 return IntersectsClipRectInt(rect.x(), rect.y(), | 554 return IntersectsClipRectInt(rect.x(), rect.y(), |
563 rect.width(), rect.height()); | 555 rect.width(), rect.height()); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 // by the paint). | 621 // by the paint). |
630 SkPaint p(paint); | 622 SkPaint p(paint); |
631 p.setFilterQuality(filter ? kLow_SkFilterQuality : kNone_SkFilterQuality); | 623 p.setFilterQuality(filter ? kLow_SkFilterQuality : kNone_SkFilterQuality); |
632 p.setShader(shader.get()); | 624 p.setShader(shader.get()); |
633 | 625 |
634 // The rect will be filled by the bitmap. | 626 // The rect will be filled by the bitmap. |
635 canvas_->drawRect(dest_rect, p); | 627 canvas_->drawRect(dest_rect, p); |
636 } | 628 } |
637 | 629 |
638 } // namespace gfx | 630 } // namespace gfx |
OLD | NEW |