| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "cc/font_atlas.h" | 7 #include "cc/font_atlas.h" |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/string_split.h" | 11 #include "base/string_split.h" |
| 12 #include "cc/proxy.h" | 12 #include "cc/proxy.h" |
| 13 #include "third_party/skia/include/core/SkCanvas.h" | 13 #include "third_party/skia/include/core/SkCanvas.h" |
| 14 #include "ui/gfx/point.h" | 14 #include "ui/gfx/point.h" |
| 15 #include "ui/gfx/size.h" |
| 15 | 16 |
| 16 namespace cc { | 17 namespace cc { |
| 17 | 18 |
| 18 using namespace std; | |
| 19 | |
| 20 FontAtlas::FontAtlas(SkBitmap bitmap, IntRect asciiToRectTable[128], int fontHei
ght) | 19 FontAtlas::FontAtlas(SkBitmap bitmap, IntRect asciiToRectTable[128], int fontHei
ght) |
| 21 : m_atlas(bitmap) | 20 : m_atlas(bitmap) |
| 22 , m_fontHeight(fontHeight) | 21 , m_fontHeight(fontHeight) |
| 23 { | 22 { |
| 24 for (size_t i = 0; i < 128; ++i) | 23 for (size_t i = 0; i < 128; ++i) |
| 25 m_asciiToRectTable[i] = asciiToRectTable[i]; | 24 m_asciiToRectTable[i] = asciiToRectTable[i]; |
| 26 } | 25 } |
| 27 | 26 |
| 28 FontAtlas::~FontAtlas() | 27 FontAtlas::~FontAtlas() |
| 29 { | 28 { |
| 30 } | 29 } |
| 31 | 30 |
| 32 void FontAtlas::drawText(SkCanvas* canvas, const SkPaint& paint, const std::stri
ng& text, const gfx::Point& destPosition, const IntSize& clip) const | 31 void FontAtlas::drawText(SkCanvas* canvas, const SkPaint& paint, const std::stri
ng& text, const gfx::Point& destPosition, const gfx::Size& clip) const |
| 33 { | 32 { |
| 34 DCHECK(Proxy::isImplThread()); | 33 DCHECK(Proxy::isImplThread()); |
| 35 | 34 |
| 36 std::vector<std::string> lines; | 35 std::vector<std::string> lines; |
| 37 base::SplitString(text, '\n', &lines); | 36 base::SplitString(text, '\n', &lines); |
| 38 | 37 |
| 39 gfx::Point position = destPosition; | 38 gfx::Point position = destPosition; |
| 40 for (size_t i = 0; i < lines.size(); ++i) { | 39 for (size_t i = 0; i < lines.size(); ++i) { |
| 41 drawOneLineOfTextInternal(canvas, paint, lines[i], position); | 40 drawOneLineOfTextInternal(canvas, paint, lines[i], position); |
| 42 position.set_y(position.y() + m_fontHeight); | 41 position.set_y(position.y() + m_fontHeight); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 61 } | 60 } |
| 62 | 61 |
| 63 void FontAtlas::drawDebugAtlas(SkCanvas* canvas, const gfx::Point& destPosition)
const | 62 void FontAtlas::drawDebugAtlas(SkCanvas* canvas, const gfx::Point& destPosition)
const |
| 64 { | 63 { |
| 65 DCHECK(Proxy::isImplThread()); | 64 DCHECK(Proxy::isImplThread()); |
| 66 | 65 |
| 67 SkIRect source = SkIRect::MakeWH(m_atlas.width(), m_atlas.height()); | 66 SkIRect source = SkIRect::MakeWH(m_atlas.width(), m_atlas.height()); |
| 68 canvas->drawBitmapRect(m_atlas, &source, SkRect::MakeXYWH(destPosition.x(),
destPosition.y(), m_atlas.width(), m_atlas.height())); | 67 canvas->drawBitmapRect(m_atlas, &source, SkRect::MakeXYWH(destPosition.x(),
destPosition.y(), m_atlas.width(), m_atlas.height())); |
| 69 } | 68 } |
| 70 | 69 |
| 71 } // namespace cc | 70 } // namespace cc |
| OLD | NEW |