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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 SizeStringFloat(text, font_list, &width, &height, 0, NO_ELLIPSIS); | 97 SizeStringFloat(text, font_list, &width, &height, 0, NO_ELLIPSIS); |
98 return width; | 98 return width; |
99 } | 99 } |
100 | 100 |
101 // static | 101 // static |
102 int Canvas::DefaultCanvasTextAlignment() { | 102 int Canvas::DefaultCanvasTextAlignment() { |
103 return base::i18n::IsRTL() ? TEXT_ALIGN_RIGHT : TEXT_ALIGN_LEFT; | 103 return base::i18n::IsRTL() ? TEXT_ALIGN_RIGHT : TEXT_ALIGN_LEFT; |
104 } | 104 } |
105 | 105 |
106 ImageSkiaRep Canvas::ExtractImageRep() const { | 106 ImageSkiaRep Canvas::ExtractImageRep() const { |
107 // Make a bitmap to return, and a canvas to draw into it. We don't just want | 107 DCHECK(bitmap_); |
108 // to call extractSubset or the copy constructor, since we want an actual copy | 108 SkBitmap bitmap_copy; |
109 // of the bitmap. | 109 // copyTo() will perform a deep copy, which is what we want. |
110 const SkISize size = canvas_->getBaseLayerSize(); | 110 bool result = bitmap_->copyTo(&bitmap_copy); |
111 SkBitmap result; | 111 // This should succeed since the destination bitmap is empty to begin with. |
112 result.allocN32Pixels(size.width(), size.height()); | 112 // The only failure is an allocation failure, which we want to DCHECK anyway. |
113 | 113 DCHECK(result); |
114 canvas_->readPixels(&result, 0, 0); | 114 return ImageSkiaRep(bitmap_copy, image_scale_); |
115 return ImageSkiaRep(result, image_scale_); | |
116 } | 115 } |
117 | 116 |
118 void Canvas::DrawDashedRect(const Rect& rect, SkColor color) { | 117 void Canvas::DrawDashedRect(const Rect& rect, SkColor color) { |
119 DrawDashedRect(RectF(rect), color); | 118 DrawDashedRect(RectF(rect), color); |
120 } | 119 } |
121 | 120 |
122 void Canvas::DrawDashedRect(const RectF& rect, SkColor color) { | 121 void Canvas::DrawDashedRect(const RectF& rect, SkColor color) { |
123 if (rect.IsEmpty()) | 122 if (rect.IsEmpty()) |
124 return; | 123 return; |
125 // Create a 2D bitmap containing alternating on/off pixels - we do this | 124 // Create a 2D bitmap containing alternating on/off pixels - we do this |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 bitmap_.emplace(); | 613 bitmap_.emplace(); |
615 bitmap_->allocPixels(info); | 614 bitmap_->allocPixels(info); |
616 // Ensure that the bitmap is zeroed, since the code expects that. | 615 // Ensure that the bitmap is zeroed, since the code expects that. |
617 memset(bitmap_->getPixels(), 0, bitmap_->getSafeSize()); | 616 memset(bitmap_->getPixels(), 0, bitmap_->getSafeSize()); |
618 | 617 |
619 owned_canvas_ = cc::SkiaPaintCanvas(bitmap_.value()); | 618 owned_canvas_ = cc::SkiaPaintCanvas(bitmap_.value()); |
620 return &owned_canvas_.value(); | 619 return &owned_canvas_.value(); |
621 } | 620 } |
622 | 621 |
623 } // namespace gfx | 622 } // namespace gfx |
OLD | NEW |