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 #ifndef CCFontAtlas_h | 5 #ifndef CCFontAtlas_h |
6 #define CCFontAtlas_h | 6 #define CCFontAtlas_h |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "IntRect.h" | |
13 #include "third_party/skia/include/core/SkBitmap.h" | 12 #include "third_party/skia/include/core/SkBitmap.h" |
| 13 #include "ui/gfx/rect.h" |
14 | 14 |
15 class SkCanvas; | 15 class SkCanvas; |
16 | 16 |
17 namespace gfx { | 17 namespace gfx { |
18 class Point; | 18 class Point; |
19 class Size; | 19 class Size; |
20 } | 20 } |
21 | 21 |
22 namespace cc { | 22 namespace cc { |
23 | 23 |
24 // This class provides basic ability to draw text onto the heads-up display. | 24 // This class provides basic ability to draw text onto the heads-up display. |
25 class FontAtlas { | 25 class FontAtlas { |
26 public: | 26 public: |
27 static scoped_ptr<FontAtlas> create(SkBitmap bitmap, IntRect asciiToRectTabl
e[128], int fontHeight) | 27 static scoped_ptr<FontAtlas> create(SkBitmap bitmap, gfx::Rect asciiToRectTa
ble[128], int fontHeight) |
28 { | 28 { |
29 return make_scoped_ptr(new FontAtlas(bitmap, asciiToRectTable, fontHeigh
t)); | 29 return make_scoped_ptr(new FontAtlas(bitmap, asciiToRectTable, fontHeigh
t)); |
30 } | 30 } |
31 ~FontAtlas(); | 31 ~FontAtlas(); |
32 | 32 |
33 // Draws multiple lines of text where each line of text is separated by '\n'
. | 33 // Draws multiple lines of text where each line of text is separated by '\n'
. |
34 // - Correct glyphs will be drawn for ASCII codes in the range 32-127; any c
haracters | 34 // - Correct glyphs will be drawn for ASCII codes in the range 32-127; any c
haracters |
35 // outside that range will be displayed as a default rectangle glyph. | 35 // outside that range will be displayed as a default rectangle glyph. |
36 // - gfx::Size clip is used to avoid wasting time drawing things that are ou
tside the | 36 // - gfx::Size clip is used to avoid wasting time drawing things that are ou
tside the |
37 // target canvas bounds. | 37 // target canvas bounds. |
38 // - Should only be called only on the impl thread. | 38 // - Should only be called only on the impl thread. |
39 void drawText(SkCanvas*, const SkPaint&, const std::string& text, const gfx:
:Point& destPosition, const gfx::Size& clip) const; | 39 void drawText(SkCanvas*, const SkPaint&, const std::string& text, const gfx:
:Point& destPosition, const gfx::Size& clip) const; |
40 | 40 |
41 // Draws the entire atlas at the specified position, just for debugging purp
oses. | 41 // Draws the entire atlas at the specified position, just for debugging purp
oses. |
42 void drawDebugAtlas(SkCanvas*, const gfx::Point& destPosition) const; | 42 void drawDebugAtlas(SkCanvas*, const gfx::Point& destPosition) const; |
43 | 43 |
44 private: | 44 private: |
45 FontAtlas(SkBitmap, IntRect asciiToRectTable[128], int fontHeight); | 45 FontAtlas(SkBitmap, gfx::Rect asciiToRectTable[128], int fontHeight); |
46 | 46 |
47 void drawOneLineOfTextInternal(SkCanvas*, const SkPaint&, const std::string&
, const gfx::Point& destPosition) const; | 47 void drawOneLineOfTextInternal(SkCanvas*, const SkPaint&, const std::string&
, const gfx::Point& destPosition) const; |
48 | 48 |
49 // The actual texture atlas containing all the pre-rendered glyphs. | 49 // The actual texture atlas containing all the pre-rendered glyphs. |
50 SkBitmap m_atlas; | 50 SkBitmap m_atlas; |
51 | 51 |
52 // The look-up tables mapping ascii characters to their IntRect locations on
the atlas. | 52 // The look-up tables mapping ascii characters to their gfx::Rect locations
on the atlas. |
53 IntRect m_asciiToRectTable[128]; | 53 gfx::Rect m_asciiToRectTable[128]; |
54 | 54 |
55 int m_fontHeight; | 55 int m_fontHeight; |
56 | 56 |
57 DISALLOW_COPY_AND_ASSIGN(FontAtlas); | 57 DISALLOW_COPY_AND_ASSIGN(FontAtlas); |
58 }; | 58 }; |
59 | 59 |
60 } // namespace cc | 60 } // namespace cc |
61 | 61 |
62 #endif | 62 #endif |
OLD | NEW |