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

Side by Side Diff: src/gpu/GrBitmapTextContext.cpp

Issue 659993003: Revert of Change drawText() to generate positions and send to drawPosText() (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 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
« no previous file with comments | « src/gpu/GrBitmapTextContext.h ('k') | src/gpu/GrDistanceFieldTextContext.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "GrBitmapTextContext.h" 8 #include "GrBitmapTextContext.h"
9 #include "GrAtlas.h" 9 #include "GrAtlas.h"
10 #include "GrDrawTarget.h" 10 #include "GrDrawTarget.h"
11 #include "GrFontScaler.h" 11 #include "GrFontScaler.h"
12 #include "GrIndexBuffer.h" 12 #include "GrIndexBuffer.h"
13 #include "GrStrokeInfo.h" 13 #include "GrStrokeInfo.h"
14 #include "GrTexturePriv.h" 14 #include "GrTexturePriv.h"
15 #include "GrTextStrike.h" 15 #include "GrTextStrike.h"
16 #include "GrTextStrike_impl.h" 16 #include "GrTextStrike_impl.h"
17 #include "effects/GrCustomCoordsTextureEffect.h" 17 #include "effects/GrCustomCoordsTextureEffect.h"
18 18
19 #include "SkAutoKern.h"
19 #include "SkColorPriv.h" 20 #include "SkColorPriv.h"
20 #include "SkDraw.h" 21 #include "SkDraw.h"
21 #include "SkDrawProcs.h" 22 #include "SkDrawProcs.h"
22 #include "SkGlyphCache.h" 23 #include "SkGlyphCache.h"
23 #include "SkGpuDevice.h" 24 #include "SkGpuDevice.h"
24 #include "SkGr.h" 25 #include "SkGr.h"
25 #include "SkPath.h" 26 #include "SkPath.h"
26 #include "SkRTConf.h" 27 #include "SkRTConf.h"
27 #include "SkStrokeRec.h" 28 #include "SkStrokeRec.h"
28 #include "SkTextMapStateProc.h" 29 #include "SkTextMapStateProc.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 84
84 fStrike = NULL; 85 fStrike = NULL;
85 86
86 fCurrTexture = NULL; 87 fCurrTexture = NULL;
87 fCurrVertex = 0; 88 fCurrVertex = 0;
88 89
89 fVertices = NULL; 90 fVertices = NULL;
90 fMaxVertices = 0; 91 fMaxVertices = 0;
91 } 92 }
92 93
94 void GrBitmapTextContext::onDrawText(const GrPaint& paint, const SkPaint& skPain t,
95 const char text[], size_t byteLength,
96 SkScalar x, SkScalar y) {
97 SkASSERT(byteLength == 0 || text != NULL);
98
99 // nothing to draw
100 if (text == NULL || byteLength == 0 /*|| fRC->isEmpty()*/) {
101 return;
102 }
103
104 this->init(paint, skPaint);
105
106 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
107
108 SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, &fContext->getMa trix());
109 SkGlyphCache* cache = autoCache.getCache();
110 GrFontScaler* fontScaler = GetGrFontScaler(cache);
111
112 // transform our starting point
113 {
114 SkPoint loc;
115 fContext->getMatrix().mapXY(x, y, &loc);
116 x = loc.fX;
117 y = loc.fY;
118 }
119
120 // need to measure first
121 if (fSkPaint.getTextAlign() != SkPaint::kLeft_Align) {
122 SkVector stop;
123
124 MeasureText(cache, glyphCacheProc, text, byteLength, &stop);
125
126 SkScalar stopX = stop.fX;
127 SkScalar stopY = stop.fY;
128
129 if (fSkPaint.getTextAlign() == SkPaint::kCenter_Align) {
130 stopX = SkScalarHalf(stopX);
131 stopY = SkScalarHalf(stopY);
132 }
133 x -= stopX;
134 y -= stopY;
135 }
136
137 const char* stop = text + byteLength;
138
139 SkAutoKern autokern;
140
141 SkFixed fxMask = ~0;
142 SkFixed fyMask = ~0;
143 SkFixed halfSampleX, halfSampleY;
144 if (cache->isSubpixel()) {
145 halfSampleX = halfSampleY = (SK_FixedHalf >> SkGlyph::kSubBits);
146 SkAxisAlignment baseline = SkComputeAxisAlignmentForHText(fContext->getM atrix());
147 if (kX_SkAxisAlignment == baseline) {
148 fyMask = 0;
149 halfSampleY = SK_FixedHalf;
150 } else if (kY_SkAxisAlignment == baseline) {
151 fxMask = 0;
152 halfSampleX = SK_FixedHalf;
153 }
154 } else {
155 halfSampleX = halfSampleY = SK_FixedHalf;
156 }
157
158 SkFixed fx = SkScalarToFixed(x) + halfSampleX;
159 SkFixed fy = SkScalarToFixed(y) + halfSampleY;
160
161 GrContext::AutoMatrix autoMatrix;
162 autoMatrix.setIdentity(fContext, &fPaint);
163
164 while (text < stop) {
165 const SkGlyph& glyph = glyphCacheProc(cache, &text, fx & fxMask, fy & fy Mask);
166
167 fx += autokern.adjust(glyph);
168
169 if (glyph.fWidth) {
170 this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(),
171 glyph.getSubXFixed(),
172 glyph.getSubYFixed()),
173 SkFixedFloorToFixed(fx),
174 SkFixedFloorToFixed(fy),
175 fontScaler);
176 }
177
178 fx += glyph.fAdvanceX;
179 fy += glyph.fAdvanceY;
180 }
181
182 this->finish();
183 }
184
93 void GrBitmapTextContext::onDrawPosText(const GrPaint& paint, const SkPaint& skP aint, 185 void GrBitmapTextContext::onDrawPosText(const GrPaint& paint, const SkPaint& skP aint,
94 const char text[], size_t byteLength, 186 const char text[], size_t byteLength,
95 const SkScalar pos[], int scalarsPerPositi on, 187 const SkScalar pos[], int scalarsPerPositi on,
96 const SkPoint& offset) { 188 const SkPoint& offset) {
97 SkASSERT(byteLength == 0 || text != NULL); 189 SkASSERT(byteLength == 0 || text != NULL);
98 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); 190 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
99 191
100 // nothing to draw 192 // nothing to draw
101 if (text == NULL || byteLength == 0/* || fRC->isEmpty()*/) { 193 if (text == NULL || byteLength == 0/* || fRC->isEmpty()*/) {
102 return; 194 return;
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 SkSafeSetNull(fCurrTexture); 611 SkSafeSetNull(fCurrTexture);
520 } 612 }
521 } 613 }
522 614
523 inline void GrBitmapTextContext::finish() { 615 inline void GrBitmapTextContext::finish() {
524 this->flush(); 616 this->flush();
525 617
526 GrTextContext::finish(); 618 GrTextContext::finish();
527 } 619 }
528 620
OLDNEW
« no previous file with comments | « src/gpu/GrBitmapTextContext.h ('k') | src/gpu/GrDistanceFieldTextContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698