| 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 float width = 0, height = 0; | 96 float width = 0, height = 0; |
| 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 { | |
| 107 DCHECK(bitmap_); | |
| 108 SkBitmap bitmap_copy; | |
| 109 // copyTo() will perform a deep copy, which is what we want. | |
| 110 bool result = bitmap_->copyTo(&bitmap_copy); | |
| 111 // This should succeed since the destination bitmap is empty to begin with. | |
| 112 // The only failure is an allocation failure, which we want to DCHECK anyway. | |
| 113 DCHECK(result); | |
| 114 return ImageSkiaRep(bitmap_copy, image_scale_); | |
| 115 } | |
| 116 | |
| 117 void Canvas::DrawDashedRect(const RectF& rect, SkColor color) { | 106 void Canvas::DrawDashedRect(const RectF& rect, SkColor color) { |
| 118 if (rect.IsEmpty()) | 107 if (rect.IsEmpty()) |
| 119 return; | 108 return; |
| 120 // Create a 2D bitmap containing alternating on/off pixels - we do this | 109 // Create a 2D bitmap containing alternating on/off pixels - we do this |
| 121 // so that you never get two pixels of the same color around the edges | 110 // so that you never get two pixels of the same color around the edges |
| 122 // of the focus rect (this may mean that opposing edges of the rect may | 111 // of the focus rect (this may mean that opposing edges of the rect may |
| 123 // have a dot pattern out of phase to each other). | 112 // have a dot pattern out of phase to each other). |
| 124 static SkColor last_color; | 113 static SkColor last_color; |
| 125 static SkBitmap* dots = NULL; | 114 static SkBitmap* dots = NULL; |
| 126 if (!dots || last_color != color) { | 115 if (!dots || last_color != color) { |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 bitmap_.emplace(); | 590 bitmap_.emplace(); |
| 602 bitmap_->allocPixels(info); | 591 bitmap_->allocPixels(info); |
| 603 // Ensure that the bitmap is zeroed, since the code expects that. | 592 // Ensure that the bitmap is zeroed, since the code expects that. |
| 604 memset(bitmap_->getPixels(), 0, bitmap_->getSafeSize()); | 593 memset(bitmap_->getPixels(), 0, bitmap_->getSafeSize()); |
| 605 | 594 |
| 606 owned_canvas_ = cc::SkiaPaintCanvas(bitmap_.value()); | 595 owned_canvas_ = cc::SkiaPaintCanvas(bitmap_.value()); |
| 607 return &owned_canvas_.value(); | 596 return &owned_canvas_.value(); |
| 608 } | 597 } |
| 609 | 598 |
| 610 } // namespace gfx | 599 } // namespace gfx |
| OLD | NEW |