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. |
sky
2017/04/05 03:00:24
Generally we use |s for references to variables an
vmpstr
2017/04/05 19:13:39
Done.
| |
110 const SkISize size = canvas_->getBaseLayerSize(); | 110 bool result = bitmap_->copyTo(&bitmap_copy); |
111 SkBitmap result; | 111 DCHECK(result); |
sky
2017/04/05 03:00:24
Document why result should be true here.
vmpstr
2017/04/05 19:13:39
Done.
| |
112 result.allocN32Pixels(size.width(), size.height()); | 112 return ImageSkiaRep(bitmap_copy, image_scale_); |
113 | |
114 canvas_->readPixels(&result, 0, 0); | |
115 return ImageSkiaRep(result, image_scale_); | |
116 } | 113 } |
117 | 114 |
118 void Canvas::DrawDashedRect(const Rect& rect, SkColor color) { | 115 void Canvas::DrawDashedRect(const Rect& rect, SkColor color) { |
119 DrawDashedRect(RectF(rect), color); | 116 DrawDashedRect(RectF(rect), color); |
120 } | 117 } |
121 | 118 |
122 void Canvas::DrawDashedRect(const RectF& rect, SkColor color) { | 119 void Canvas::DrawDashedRect(const RectF& rect, SkColor color) { |
123 if (rect.IsEmpty()) | 120 if (rect.IsEmpty()) |
124 return; | 121 return; |
125 // Create a 2D bitmap containing alternating on/off pixels - we do this | 122 // 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(); | 611 bitmap_.emplace(); |
615 bitmap_->allocPixels(info); | 612 bitmap_->allocPixels(info); |
616 // Ensure that the bitmap is zeroed, since the code expects that. | 613 // Ensure that the bitmap is zeroed, since the code expects that. |
617 memset(bitmap_->getPixels(), 0, bitmap_->getSafeSize()); | 614 memset(bitmap_->getPixels(), 0, bitmap_->getSafeSize()); |
618 | 615 |
619 owned_canvas_ = cc::SkiaPaintCanvas(bitmap_.value()); | 616 owned_canvas_ = cc::SkiaPaintCanvas(bitmap_.value()); |
620 return &owned_canvas_.value(); | 617 return &owned_canvas_.value(); |
621 } | 618 } |
622 | 619 |
623 } // namespace gfx | 620 } // namespace gfx |
OLD | NEW |