| 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 #if USE(ACCELERATED_COMPOSITING) | 7 #if USE(ACCELERATED_COMPOSITING) |
| 8 #include "CCFontAtlas.h" | 8 #include "CCFontAtlas.h" |
| 9 | 9 |
| 10 #include "base/string_split.h" |
| 10 #include "CCProxy.h" | 11 #include "CCProxy.h" |
| 11 #include "SkCanvas.h" | 12 #include "SkCanvas.h" |
| 13 #include <vector> |
| 12 | 14 |
| 13 namespace WebCore { | 15 namespace WebCore { |
| 14 | 16 |
| 15 using namespace std; | 17 using namespace std; |
| 16 | 18 |
| 17 CCFontAtlas::CCFontAtlas(SkBitmap bitmap, IntRect asciiToRectTable[128], int fon
tHeight) | 19 CCFontAtlas::CCFontAtlas(SkBitmap bitmap, IntRect asciiToRectTable[128], int fon
tHeight) |
| 18 : m_atlas(bitmap) | 20 : m_atlas(bitmap) |
| 19 , m_fontHeight(fontHeight) | 21 , m_fontHeight(fontHeight) |
| 20 { | 22 { |
| 21 for (size_t i = 0; i < 128; ++i) | 23 for (size_t i = 0; i < 128; ++i) |
| 22 m_asciiToRectTable[i] = asciiToRectTable[i]; | 24 m_asciiToRectTable[i] = asciiToRectTable[i]; |
| 23 } | 25 } |
| 24 | 26 |
| 25 CCFontAtlas::~CCFontAtlas() | 27 CCFontAtlas::~CCFontAtlas() |
| 26 { | 28 { |
| 27 } | 29 } |
| 28 | 30 |
| 29 void CCFontAtlas::drawText(SkCanvas* canvas, const SkPaint& paint, const String&
text, const IntPoint& destPosition, const IntSize& clip) const | 31 void CCFontAtlas::drawText(SkCanvas* canvas, const SkPaint& paint, const std::st
ring& text, const IntPoint& destPosition, const IntSize& clip) const |
| 30 { | 32 { |
| 31 ASSERT(CCProxy::isImplThread()); | 33 ASSERT(CCProxy::isImplThread()); |
| 32 | 34 |
| 33 Vector<String> lines; | 35 std::vector<std::string> lines; |
| 34 text.split('\n', lines); | 36 base::SplitString(text, '\n', &lines); |
| 35 | 37 |
| 36 IntPoint position = destPosition; | 38 IntPoint position = destPosition; |
| 37 for (size_t i = 0; i < lines.size(); ++i) { | 39 for (size_t i = 0; i < lines.size(); ++i) { |
| 38 drawOneLineOfTextInternal(canvas, paint, lines[i], position); | 40 drawOneLineOfTextInternal(canvas, paint, lines[i], position); |
| 39 position.setY(position.y() + m_fontHeight); | 41 position.setY(position.y() + m_fontHeight); |
| 40 if (position.y() > clip.height()) | 42 if (position.y() > clip.height()) |
| 41 return; | 43 return; |
| 42 } | 44 } |
| 43 } | 45 } |
| 44 | 46 |
| 45 void CCFontAtlas::drawOneLineOfTextInternal(SkCanvas* canvas, const SkPaint& pai
nt, const String& textLine, const IntPoint& destPosition) const | 47 void CCFontAtlas::drawOneLineOfTextInternal(SkCanvas* canvas, const SkPaint& pai
nt, const std::string& textLine, const IntPoint& destPosition) const |
| 46 { | 48 { |
| 47 ASSERT(CCProxy::isImplThread()); | 49 ASSERT(CCProxy::isImplThread()); |
| 48 | 50 |
| 49 IntPoint position = destPosition; | 51 IntPoint position = destPosition; |
| 50 for (unsigned i = 0; i < textLine.length(); ++i) { | 52 for (unsigned i = 0; i < textLine.length(); ++i) { |
| 51 // If the ASCII code is out of bounds, then index 0 is used, which is ju
st a plain rectangle glyph. | 53 // If the ASCII code is out of bounds, then index 0 is used, which is ju
st a plain rectangle glyph. |
| 52 int asciiIndex = (textLine[i] < 128) ? textLine[i] : 0; | 54 int asciiIndex = (textLine[i] < 128) ? textLine[i] : 0; |
| 53 IntRect glyphBounds = m_asciiToRectTable[asciiIndex]; | 55 IntRect glyphBounds = m_asciiToRectTable[asciiIndex]; |
| 54 SkIRect source = SkIRect::MakeXYWH(glyphBounds.x(), glyphBounds.y(), gly
phBounds.width(), glyphBounds.height()); | 56 SkIRect source = SkIRect::MakeXYWH(glyphBounds.x(), glyphBounds.y(), gly
phBounds.width(), glyphBounds.height()); |
| 55 canvas->drawBitmapRect(m_atlas, &source, SkRect::MakeXYWH(position.x(),
position.y(), glyphBounds.width(), glyphBounds.height()), &paint); | 57 canvas->drawBitmapRect(m_atlas, &source, SkRect::MakeXYWH(position.x(),
position.y(), glyphBounds.width(), glyphBounds.height()), &paint); |
| 56 position.setX(position.x() + glyphBounds.width()); | 58 position.setX(position.x() + glyphBounds.width()); |
| 57 } | 59 } |
| 58 } | 60 } |
| 59 | 61 |
| 60 void CCFontAtlas::drawDebugAtlas(SkCanvas* canvas, const IntPoint& destPosition)
const | 62 void CCFontAtlas::drawDebugAtlas(SkCanvas* canvas, const IntPoint& destPosition)
const |
| 61 { | 63 { |
| 62 ASSERT(CCProxy::isImplThread()); | 64 ASSERT(CCProxy::isImplThread()); |
| 63 | 65 |
| 64 SkIRect source = SkIRect::MakeWH(m_atlas.width(), m_atlas.height()); | 66 SkIRect source = SkIRect::MakeWH(m_atlas.width(), m_atlas.height()); |
| 65 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())); |
| 66 } | 68 } |
| 67 | 69 |
| 68 } // namespace WebCore | 70 } // namespace WebCore |
| 69 | 71 |
| 70 #endif // USE(ACCELERATED_COMPOSITING) | 72 #endif // USE(ACCELERATED_COMPOSITING) |
| OLD | NEW |