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

Side by Side Diff: cc/font_atlas.cc

Issue 11360178: Delete ThreadChecker from FontAtlas. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 1 month 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
« no previous file with comments | « cc/font_atlas.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
13 #include "third_party/skia/include/core/SkCanvas.h" 12 #include "third_party/skia/include/core/SkCanvas.h"
14 13
15 namespace cc { 14 namespace cc {
16 15
17 FontAtlas::FontAtlas(SkBitmap bitmap, gfx::Rect asciiToRectTable[128], int fontH eight) 16 FontAtlas::FontAtlas(SkBitmap bitmap, gfx::Rect asciiToRectTable[128], int fontH eight)
18 : m_atlas(bitmap) 17 : m_atlas(bitmap)
19 , m_fontHeight(fontHeight) 18 , m_fontHeight(fontHeight)
20 { 19 {
21 for (size_t i = 0; i < 128; ++i) 20 for (size_t i = 0; i < 128; ++i)
22 m_asciiToRectTable[i] = asciiToRectTable[i]; 21 m_asciiToRectTable[i] = asciiToRectTable[i];
23 } 22 }
24 23
25 FontAtlas::~FontAtlas() 24 FontAtlas::~FontAtlas()
26 { 25 {
27 } 26 }
28 27
29 void FontAtlas::drawText(SkCanvas* canvas, const SkPaint& paint, const std::stri ng& text, const gfx::Point& destPosition, const gfx::Size& clip) const 28 void FontAtlas::drawText(SkCanvas* canvas, const SkPaint& paint, const std::stri ng& text, const gfx::Point& destPosition, const gfx::Size& clip) const
30 { 29 {
31 DCHECK(m_threadChecker.CalledOnValidThread());
32
33 std::vector<std::string> lines; 30 std::vector<std::string> lines;
34 base::SplitString(text, '\n', &lines); 31 base::SplitString(text, '\n', &lines);
35 32
36 gfx::Point position = destPosition; 33 gfx::Point position = destPosition;
37 for (size_t i = 0; i < lines.size(); ++i) { 34 for (size_t i = 0; i < lines.size(); ++i) {
38 drawOneLineOfTextInternal(canvas, paint, lines[i], position); 35 drawOneLineOfTextInternal(canvas, paint, lines[i], position);
39 position.set_y(position.y() + m_fontHeight); 36 position.set_y(position.y() + m_fontHeight);
40 if (position.y() > clip.height()) 37 if (position.y() > clip.height())
41 return; 38 return;
42 } 39 }
43 } 40 }
44 41
45 void FontAtlas::drawOneLineOfTextInternal(SkCanvas* canvas, const SkPaint& paint , const std::string& textLine, const gfx::Point& destPosition) const 42 void FontAtlas::drawOneLineOfTextInternal(SkCanvas* canvas, const SkPaint& paint , const std::string& textLine, const gfx::Point& destPosition) const
46 { 43 {
47 DCHECK(m_threadChecker.CalledOnValidThread());
48
49 gfx::Point position = destPosition; 44 gfx::Point position = destPosition;
50 for (unsigned i = 0; i < textLine.length(); ++i) { 45 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. 46 // 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; 47 int asciiIndex = (textLine[i] < 128) ? textLine[i] : 0;
53 gfx::Rect glyphBounds = m_asciiToRectTable[asciiIndex]; 48 gfx::Rect glyphBounds = m_asciiToRectTable[asciiIndex];
54 SkIRect source = SkIRect::MakeXYWH(glyphBounds.x(), glyphBounds.y(), gly phBounds.width(), glyphBounds.height()); 49 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); 50 canvas->drawBitmapRect(m_atlas, &source, SkRect::MakeXYWH(position.x(), position.y(), glyphBounds.width(), glyphBounds.height()), &paint);
56 position.set_x(position.x() + glyphBounds.width()); 51 position.set_x(position.x() + glyphBounds.width());
57 } 52 }
58 } 53 }
(...skipping 12 matching lines...) Expand all
71 } 66 }
72 if (lineWidth > maxWidth) 67 if (lineWidth > maxWidth)
73 maxWidth = lineWidth; 68 maxWidth = lineWidth;
74 } 69 }
75 70
76 return gfx::Size(maxWidth, m_fontHeight * lines.size()); 71 return gfx::Size(maxWidth, m_fontHeight * lines.size());
77 } 72 }
78 73
79 void FontAtlas::drawDebugAtlas(SkCanvas* canvas, const gfx::Point& destPosition) const 74 void FontAtlas::drawDebugAtlas(SkCanvas* canvas, const gfx::Point& destPosition) const
80 { 75 {
81 DCHECK(m_threadChecker.CalledOnValidThread());
82
83 SkIRect source = SkIRect::MakeWH(m_atlas.width(), m_atlas.height()); 76 SkIRect source = SkIRect::MakeWH(m_atlas.width(), m_atlas.height());
84 canvas->drawBitmapRect(m_atlas, &source, SkRect::MakeXYWH(destPosition.x(), destPosition.y(), m_atlas.width(), m_atlas.height())); 77 canvas->drawBitmapRect(m_atlas, &source, SkRect::MakeXYWH(destPosition.x(), destPosition.y(), m_atlas.width(), m_atlas.height()));
85 } 78 }
86 79
87 } // namespace cc 80 } // namespace cc
OLDNEW
« no previous file with comments | « cc/font_atlas.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698