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

Side by Side Diff: src/gpu/text/GrFontScaler.cpp

Issue 1985163002: Remove GrFontScaler class (Closed) Base URL: https://chromium.googlesource.com/skia.git@rmkey
Patch Set: remove comments Created 4 years, 7 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
OLDNEW
(Empty)
1 /*
2 * Copyright 2010 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "GrFontScaler.h"
9 #include "SkDescriptor.h"
10 #include "SkDistanceFieldGen.h"
11 #include "SkGlyphCache.h"
12
13 ///////////////////////////////////////////////////////////////////////////////
14
15 GrFontScaler::GrFontScaler(SkGlyphCache* strike) {
16 fStrike = strike;
17 }
18
19 const SkDescriptor& GrFontScaler::getKey() { return fStrike->getDescriptor(); }
20
21 GrMaskFormat GrFontScaler::getPackedGlyphMaskFormat(const SkGlyph& glyph) const {
22 SkMask::Format format = static_cast<SkMask::Format>(glyph.fMaskFormat);
23 switch (format) {
24 case SkMask::kBW_Format:
25 // fall through to kA8 -- we store BW glyphs in our 8-bit cache
26 case SkMask::kA8_Format:
27 return kA8_GrMaskFormat;
28 case SkMask::kLCD16_Format:
29 return kA565_GrMaskFormat;
30 case SkMask::kARGB32_Format:
31 return kARGB_GrMaskFormat;
32 default:
33 SkDEBUGFAIL("unsupported SkMask::Format");
34 return kA8_GrMaskFormat;
35 }
36 }
37
38 bool GrFontScaler::getPackedGlyphBounds(const SkGlyph& glyph, SkIRect* bounds) {
39 #if 1
40 // crbug:510931
41 // Retrieving the image from the cache can actually change the mask format.
42 fStrike->findImage(glyph);
43 #endif
44 bounds->setXYWH(glyph.fLeft, glyph.fTop, glyph.fWidth, glyph.fHeight);
45
46 return true;
47 }
48
49 bool GrFontScaler::getPackedGlyphDFBounds(const SkGlyph& glyph, SkIRect* bounds) {
50 #if 1
51 // crbug:510931
52 // Retrieving the image from the cache can actually change the mask format.
53 fStrike->findImage(glyph);
54 #endif
55 bounds->setXYWH(glyph.fLeft, glyph.fTop, glyph.fWidth, glyph.fHeight);
56 bounds->outset(SK_DistanceFieldPad, SK_DistanceFieldPad);
57
58 return true;
59 }
60
61 namespace {
62 // expands each bit in a bitmask to 0 or ~0 of type INT_TYPE. Used to expand a B W glyph mask to
63 // A8, RGB565, or RGBA8888.
64 template <typename INT_TYPE>
65 void expand_bits(INT_TYPE* dst,
66 const uint8_t* src,
67 int width,
68 int height,
69 int dstRowBytes,
70 int srcRowBytes) {
71 for (int i = 0; i < height; ++i) {
72 int rowWritesLeft = width;
73 const uint8_t* s = src;
74 INT_TYPE* d = dst;
75 while (rowWritesLeft > 0) {
76 unsigned mask = *s++;
77 for (int i = 7; i >= 0 && rowWritesLeft; --i, --rowWritesLeft) {
78 *d++ = (mask & (1 << i)) ? (INT_TYPE)(~0UL) : 0;
79 }
80 }
81 dst = reinterpret_cast<INT_TYPE*>(reinterpret_cast<intptr_t>(dst) + dstR owBytes);
82 src += srcRowBytes;
83 }
84 }
85 }
86
87 bool GrFontScaler::getPackedGlyphImage(const SkGlyph& glyph, int width, int heig ht, int dstRB,
88 GrMaskFormat expectedMaskFormat, void* ds t) {
89 SkASSERT(glyph.fWidth == width);
90 SkASSERT(glyph.fHeight == height);
91 const void* src = fStrike->findImage(glyph);
92 if (nullptr == src) {
93 return false;
94 }
95
96 // crbug:510931
97 // Retrieving the image from the cache can actually change the mask format. This case is very
98 // uncommon so for now we just draw a clear box for these glyphs.
99 if (getPackedGlyphMaskFormat(glyph) != expectedMaskFormat) {
100 const int bpp = GrMaskFormatBytesPerPixel(expectedMaskFormat);
101 for (int y = 0; y < height; y++) {
102 sk_bzero(dst, width * bpp);
103 dst = (char*)dst + dstRB;
104 }
105 return true;
106 }
107
108 int srcRB = glyph.rowBytes();
109 // The windows font host sometimes has BW glyphs in a non-BW strike. So it i s important here to
110 // check the glyph's format, not the strike's format, and to be able to conv ert to any of the
111 // GrMaskFormats.
112 if (SkMask::kBW_Format == glyph.fMaskFormat) {
113 // expand bits to our mask type
114 const uint8_t* bits = reinterpret_cast<const uint8_t*>(src);
115 switch (expectedMaskFormat) {
116 case kA8_GrMaskFormat:{
117 uint8_t* bytes = reinterpret_cast<uint8_t*>(dst);
118 expand_bits(bytes, bits, width, height, dstRB, srcRB);
119 break;
120 }
121 case kA565_GrMaskFormat: {
122 uint16_t* rgb565 = reinterpret_cast<uint16_t*>(dst);
123 expand_bits(rgb565, bits, width, height, dstRB, srcRB);
124 break;
125 }
126 default:
127 SkFAIL("Invalid GrMaskFormat");
128 }
129 } else if (srcRB == dstRB) {
130 memcpy(dst, src, dstRB * height);
131 } else {
132 const int bbp = GrMaskFormatBytesPerPixel(expectedMaskFormat);
133 for (int y = 0; y < height; y++) {
134 memcpy(dst, src, width * bbp);
135 src = (const char*)src + srcRB;
136 dst = (char*)dst + dstRB;
137 }
138 }
139 return true;
140 }
141
142 bool GrFontScaler::getPackedGlyphDFImage(const SkGlyph& glyph, int width, int he ight, void* dst) {
143 SkASSERT(glyph.fWidth + 2*SK_DistanceFieldPad == width);
144 SkASSERT(glyph.fHeight + 2*SK_DistanceFieldPad == height);
145 const void* image = fStrike->findImage(glyph);
146 if (nullptr == image) {
147 return false;
148 }
149 // now generate the distance field
150 SkASSERT(dst);
151 SkMask::Format maskFormat = static_cast<SkMask::Format>(glyph.fMaskFormat);
152 if (SkMask::kA8_Format == maskFormat) {
153 // make the distance field from the image
154 SkGenerateDistanceFieldFromA8Image((unsigned char*)dst,
155 (unsigned char*)image,
156 glyph.fWidth, glyph.fHeight,
157 glyph.rowBytes());
158 } else if (SkMask::kBW_Format == maskFormat) {
159 // make the distance field from the image
160 SkGenerateDistanceFieldFromBWImage((unsigned char*)dst,
161 (unsigned char*)image,
162 glyph.fWidth, glyph.fHeight,
163 glyph.rowBytes());
164 } else {
165 return false;
166 }
167
168 return true;
169 }
170
171 const SkPath* GrFontScaler::getGlyphPath(const SkGlyph& glyph) {
172 return fStrike->findPath(glyph);
173 }
174
175 const SkGlyph& GrFontScaler::grToSkGlyph(GrGlyph::PackedID id) {
176 return fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(id),
177 GrGlyph::UnpackFixedX(id),
178 GrGlyph::UnpackFixedY(id));
179 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698