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

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

Issue 1019633002: Initial change to move text blob to GrTextContext (Closed) Base URL: https://skia.googlesource.com/skia.git@text-blob2
Patch Set: cleanup Created 5 years, 9 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/GrTextContext.h ('k') | src/gpu/SkGpuDevice.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 2010 Google Inc. 2 * Copyright 2010 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 "GrTextContext.h" 8 #include "GrTextContext.h"
9 #include "GrContext.h" 9 #include "GrContext.h"
10 #include "GrDrawTarget.h" 10 #include "GrDrawTarget.h"
11 #include "GrFontScaler.h" 11 #include "GrFontScaler.h"
12 12
13 #include "SkAutoKern.h" 13 #include "SkAutoKern.h"
14 #include "SkDrawFilter.h"
14 #include "SkDrawProcs.h" 15 #include "SkDrawProcs.h"
15 #include "SkGlyphCache.h" 16 #include "SkGlyphCache.h"
16 #include "SkGpuDevice.h" 17 #include "SkGpuDevice.h"
18 #include "SkTextBlob.h"
17 #include "SkTextMapStateProc.h" 19 #include "SkTextMapStateProc.h"
18 #include "SkTextToPathIter.h" 20 #include "SkTextToPathIter.h"
19 21
20 GrTextContext::GrTextContext(GrContext* context, SkGpuDevice* gpuDevice, 22 GrTextContext::GrTextContext(GrContext* context, SkGpuDevice* gpuDevice,
21 const SkDeviceProperties& properties) 23 const SkDeviceProperties& properties)
22 : fFallbackTextContext(NULL) 24 : fFallbackTextContext(NULL)
23 , fContext(context) 25 , fContext(context)
24 , fGpuDevice(gpuDevice) 26 , fGpuDevice(gpuDevice)
25 , fDeviceProperties(properties) 27 , fDeviceProperties(properties)
26 , fDrawTarget(NULL) { 28 , fDrawTarget(NULL) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 return; 86 return;
85 } 87 }
86 textContext = textContext->fFallbackTextContext; 88 textContext = textContext->fFallbackTextContext;
87 } while (textContext); 89 } while (textContext);
88 90
89 // fall back to drawing as a path 91 // fall back to drawing as a path
90 this->drawPosTextAsPath(skPaint, viewMatrix, text, byteLength, pos, scalarsP erPosition, offset, 92 this->drawPosTextAsPath(skPaint, viewMatrix, text, byteLength, pos, scalarsP erPosition, offset,
91 clipBounds); 93 clipBounds);
92 } 94 }
93 95
96 void GrTextContext::drawTextBlob(GrRenderTarget* rt, const GrClip& clip, const S kPaint& skPaint,
97 const SkMatrix& viewMatrix, const SkTextBlob* b lob,
98 SkScalar x, SkScalar y,
99 SkDrawFilter* drawFilter, const SkIRect& clipBo unds) {
100 if (!fContext->getTextTarget()) {
101 return;
102 }
103
104 GrTextContext* textContext = this;
105 do {
106 if (textContext->canDraw(skPaint, viewMatrix)) {
107 textContext->onDrawTextBlob(rt, clip, skPaint, viewMatrix, blob, x, y, drawFilter,
108 clipBounds);
109 return;
110 }
111 textContext = textContext->fFallbackTextContext;
112 } while (textContext);
113 }
114
94 void GrTextContext::drawTextAsPath(const SkPaint& skPaint, const SkMatrix& viewM atrix, 115 void GrTextContext::drawTextAsPath(const SkPaint& skPaint, const SkMatrix& viewM atrix,
95 const char text[], size_t byteLength, SkScala r x, SkScalar y, 116 const char text[], size_t byteLength, SkScala r x, SkScalar y,
96 const SkIRect& clipBounds) { 117 const SkIRect& clipBounds) {
97 SkTextToPathIter iter(text, byteLength, skPaint, true); 118 SkTextToPathIter iter(text, byteLength, skPaint, true);
98 119
99 SkMatrix matrix; 120 SkMatrix matrix;
100 matrix.setScale(iter.getPathScale(), iter.getPathScale()); 121 matrix.setScale(iter.getPathScale(), iter.getPathScale());
101 matrix.postTranslate(x, y); 122 matrix.postTranslate(x, y);
102 123
103 const SkPath* iterPath; 124 const SkPath* iterPath;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 173
153 matrix[SkMatrix::kMTransX] = loc.fX; 174 matrix[SkMatrix::kMTransX] = loc.fX;
154 matrix[SkMatrix::kMTransY] = loc.fY; 175 matrix[SkMatrix::kMTransY] = loc.fY;
155 fGpuDevice->internalDrawPath(*path, paint, viewMatrix, &matrix, clipBounds, false); 176 fGpuDevice->internalDrawPath(*path, paint, viewMatrix, &matrix, clipBounds, false);
156 } 177 }
157 } 178 }
158 pos += scalarsPerPosition; 179 pos += scalarsPerPosition;
159 } 180 }
160 } 181 }
161 182
183 void GrTextContext::onDrawTextBlob(GrRenderTarget* rt, const GrClip& clip,
184 const SkPaint& skPaint, const SkMatrix& viewM atrix,
185 const SkTextBlob* blob, SkScalar x, SkScalar y,
186 SkDrawFilter* drawFilter, const SkIRect& clip Bounds) {
187 SkPaint runPaint = skPaint;
188
189 SkTextBlob::RunIterator it(blob);
190 for (;!it.done(); it.next()) {
191 size_t textLen = it.glyphCount() * sizeof(uint16_t);
192 const SkPoint& offset = it.offset();
193 // applyFontToPaint() always overwrites the exact same attributes,
194 // so it is safe to not re-seed the paint for this reason.
195 it.applyFontToPaint(&runPaint);
196
197 if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Typ e)) {
198 // A false return from filter() means we should abort the current dr aw.
199 runPaint = skPaint;
200 continue;
201 }
202
203 runPaint.setFlags(fGpuDevice->filterTextFlags(runPaint));
204
205 GrPaint grPaint;
206 SkPaint2GrPaintShader(fContext, fRenderTarget, runPaint, viewMatrix, tru e, &grPaint);
207
208 switch (it.positioning()) {
209 case SkTextBlob::kDefault_Positioning:
210 this->drawText(rt, clip, grPaint, runPaint, viewMatrix, (const char *)it.glyphs(),
211 textLen, x + offset.x(), y + offset.y(), clipBounds);
212 break;
213 case SkTextBlob::kHorizontal_Positioning:
214 this->drawPosText(rt, clip, grPaint, runPaint, viewMatrix, (const ch ar*)it.glyphs(),
215 textLen, it.pos(), 1, SkPoint::Make(x, y + offset. y()), clipBounds);
216 break;
217 case SkTextBlob::kFull_Positioning:
218 this->drawPosText(rt, clip, grPaint, runPaint, viewMatrix, (const ch ar*)it.glyphs(),
219 textLen, it.pos(), 2, SkPoint::Make(x, y), clipBou nds);
220 break;
221 default:
222 SkFAIL("unhandled positioning mode");
223 }
224
225 if (drawFilter) {
226 // A draw filter may change the paint arbitrarily, so we must re-see d in this case.
227 runPaint = skPaint;
228 }
229 }
230 }
231
162 //*** change to output positions? 232 //*** change to output positions?
163 int GrTextContext::MeasureText(SkGlyphCache* cache, SkDrawCacheProc glyphCachePr oc, 233 int GrTextContext::MeasureText(SkGlyphCache* cache, SkDrawCacheProc glyphCachePr oc,
164 const char text[], size_t byteLength, SkVector* stopVector) { 234 const char text[], size_t byteLength, SkVector* stopVector) {
165 SkFixed x = 0, y = 0; 235 SkFixed x = 0, y = 0;
166 const char* stop = text + byteLength; 236 const char* stop = text + byteLength;
167 237
168 SkAutoKern autokern; 238 SkAutoKern autokern;
169 239
170 int numGlyphs = 0; 240 int numGlyphs = 0;
171 while (text < stop) { 241 while (text < stop) {
(...skipping 24 matching lines...) Expand all
196 if (cache->getAuxProcData(GlyphCacheAuxProc, &auxData)) { 266 if (cache->getAuxProcData(GlyphCacheAuxProc, &auxData)) {
197 scaler = (GrFontScaler*)auxData; 267 scaler = (GrFontScaler*)auxData;
198 } 268 }
199 if (NULL == scaler) { 269 if (NULL == scaler) {
200 scaler = SkNEW_ARGS(GrFontScaler, (cache)); 270 scaler = SkNEW_ARGS(GrFontScaler, (cache));
201 cache->setAuxProc(GlyphCacheAuxProc, scaler); 271 cache->setAuxProc(GlyphCacheAuxProc, scaler);
202 } 272 }
203 273
204 return scaler; 274 return scaler;
205 } 275 }
OLDNEW
« no previous file with comments | « src/gpu/GrTextContext.h ('k') | src/gpu/SkGpuDevice.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698