Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: cc/CCFontAtlas.cpp

Issue 11122003: [cc] Rename all cc/ filenames to Chromium style (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/CCFontAtlas.h ('k') | cc/CCFrameRateController.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "config.h"
6
7 #if USE(ACCELERATED_COMPOSITING)
8 #include "CCFontAtlas.h"
9
10 #include "base/string_split.h"
11 #include "ui/gfx/point.h"
12 #include "CCProxy.h"
13 #include "SkCanvas.h"
14 #include <vector>
15
16 namespace cc {
17
18 using namespace std;
19
20 CCFontAtlas::CCFontAtlas(SkBitmap bitmap, IntRect asciiToRectTable[128], int fon tHeight)
21 : m_atlas(bitmap)
22 , m_fontHeight(fontHeight)
23 {
24 for (size_t i = 0; i < 128; ++i)
25 m_asciiToRectTable[i] = asciiToRectTable[i];
26 }
27
28 CCFontAtlas::~CCFontAtlas()
29 {
30 }
31
32 void CCFontAtlas::drawText(SkCanvas* canvas, const SkPaint& paint, const std::st ring& text, const gfx::Point& destPosition, const IntSize& clip) const
33 {
34 ASSERT(CCProxy::isImplThread());
35
36 std::vector<std::string> lines;
37 base::SplitString(text, '\n', &lines);
38
39 gfx::Point position = destPosition;
40 for (size_t i = 0; i < lines.size(); ++i) {
41 drawOneLineOfTextInternal(canvas, paint, lines[i], position);
42 position.set_y(position.y() + m_fontHeight);
43 if (position.y() > clip.height())
44 return;
45 }
46 }
47
48 void CCFontAtlas::drawOneLineOfTextInternal(SkCanvas* canvas, const SkPaint& pai nt, const std::string& textLine, const gfx::Point& destPosition) const
49 {
50 ASSERT(CCProxy::isImplThread());
51
52 gfx::Point position = destPosition;
53 for (unsigned i = 0; i < textLine.length(); ++i) {
54 // If the ASCII code is out of bounds, then index 0 is used, which is ju st a plain rectangle glyph.
55 int asciiIndex = (textLine[i] < 128) ? textLine[i] : 0;
56 IntRect glyphBounds = m_asciiToRectTable[asciiIndex];
57 SkIRect source = SkIRect::MakeXYWH(glyphBounds.x(), glyphBounds.y(), gly phBounds.width(), glyphBounds.height());
58 canvas->drawBitmapRect(m_atlas, &source, SkRect::MakeXYWH(position.x(), position.y(), glyphBounds.width(), glyphBounds.height()), &paint);
59 position.set_x(position.x() + glyphBounds.width());
60 }
61 }
62
63 void CCFontAtlas::drawDebugAtlas(SkCanvas* canvas, const gfx::Point& destPositio n) const
64 {
65 ASSERT(CCProxy::isImplThread());
66
67 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()));
69 }
70
71 } // namespace cc
72
73 #endif // USE(ACCELERATED_COMPOSITING)
OLDNEW
« no previous file with comments | « cc/CCFontAtlas.h ('k') | cc/CCFrameRateController.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698