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

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

Issue 1178383003: Revert of Make GrTextContext be owned by the GrDrawContext (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 6 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 "GrBlurUtils.h" 9 #include "GrBlurUtils.h"
10 #include "GrContext.h" 10 #include "GrContext.h"
11 #include "GrDrawContext.h" 11 #include "GrDrawContext.h"
12 #include "GrFontScaler.h" 12 #include "GrFontScaler.h"
13 13
14 #include "SkAutoKern.h" 14 #include "SkAutoKern.h"
15 #include "SkDrawFilter.h" 15 #include "SkDrawFilter.h"
16 #include "SkDrawProcs.h" 16 #include "SkDrawProcs.h"
17 #include "SkGlyphCache.h" 17 #include "SkGlyphCache.h"
18 #include "SkGpuDevice.h" 18 #include "SkGpuDevice.h"
19 #include "SkTextBlob.h" 19 #include "SkTextBlob.h"
20 #include "SkTextMapStateProc.h" 20 #include "SkTextMapStateProc.h"
21 #include "SkTextToPathIter.h" 21 #include "SkTextToPathIter.h"
22 22
23 GrTextContext::GrTextContext(GrContext* context, GrDrawContext* drawContext, 23 GrTextContext::GrTextContext(GrContext* context, const SkDeviceProperties& prope rties)
24 const SkDeviceProperties& properties)
25 : fFallbackTextContext(NULL) 24 : fFallbackTextContext(NULL)
26 , fContext(context) 25 , fContext(context)
27 , fDeviceProperties(properties) 26 , fDeviceProperties(properties) {
28 , fDrawContext(drawContext) {
29 } 27 }
30 28
31 GrTextContext::~GrTextContext() { 29 GrTextContext::~GrTextContext() {
32 SkDELETE(fFallbackTextContext); 30 SkDELETE(fFallbackTextContext);
33 } 31 }
34 32
35 void GrTextContext::init(GrRenderTarget* rt, const GrClip& clip, const GrPaint& grPaint, 33 void GrTextContext::init(GrRenderTarget* rt, const GrClip& clip, const GrPaint& grPaint,
36 const SkPaint& skPaint, const SkIRect& regionClipBounds ) { 34 const SkPaint& skPaint, const SkIRect& regionClipBounds ) {
37 fClip = clip; 35 fClip = clip;
38 36
39 fRenderTarget.reset(SkRef(rt)); 37 fRenderTarget.reset(SkRef(rt));
40 38
41 fRegionClipBounds = regionClipBounds; 39 fRegionClipBounds = regionClipBounds;
42 fClip.getConservativeBounds(fRenderTarget->width(), fRenderTarget->height(), &fClipRect); 40 fClip.getConservativeBounds(fRenderTarget->width(), fRenderTarget->height(), &fClipRect);
43 41
44 fPaint = grPaint; 42 fPaint = grPaint;
45 fSkPaint = skPaint; 43 fSkPaint = skPaint;
46 } 44 }
47 45
48 void GrTextContext::drawText(GrRenderTarget* rt, const GrClip& clip, const GrPai nt& paint, 46 void GrTextContext::drawText(GrRenderTarget* rt, const GrClip& clip, const GrPai nt& paint,
49 const SkPaint& skPaint, const SkMatrix& viewMatrix, 47 const SkPaint& skPaint, const SkMatrix& viewMatrix,
50 const char text[], size_t byteLength, 48 const char text[], size_t byteLength,
51 SkScalar x, SkScalar y, const SkIRect& clipBounds) { 49 SkScalar x, SkScalar y, const SkIRect& clipBounds) {
52 if (fContext->abandoned() || !fDrawContext) { 50 if (fContext->abandoned()) {
51 return;
52 }
53
54 GrDrawContext* drawContext = fContext->drawContext();
55 if (!drawContext) {
53 return; 56 return;
54 } 57 }
55 58
56 GrTextContext* textContext = this; 59 GrTextContext* textContext = this;
57 do { 60 do {
58 if (textContext->canDraw(rt, clip, paint, skPaint, viewMatrix)) { 61 if (textContext->canDraw(rt, clip, paint, skPaint, viewMatrix)) {
59 textContext->onDrawText(rt, clip, paint, skPaint, viewMatrix, 62 textContext->onDrawText(drawContext, rt, clip, paint, skPaint, viewM atrix,
60 text, byteLength, x, y, clipBounds); 63 text, byteLength, x, y, clipBounds);
61 return; 64 return;
62 } 65 }
63 textContext = textContext->fFallbackTextContext; 66 textContext = textContext->fFallbackTextContext;
64 } while (textContext); 67 } while (textContext);
65 68
66 // fall back to drawing as a path 69 // fall back to drawing as a path
67 this->drawTextAsPath(rt, clip, skPaint, viewMatrix, 70 this->drawTextAsPath(drawContext, rt, clip, skPaint, viewMatrix,
68 text, byteLength, x, y, clipBounds); 71 text, byteLength, x, y, clipBounds);
69 } 72 }
70 73
71 void GrTextContext::drawPosText(GrRenderTarget* rt, const GrClip& clip, const Gr Paint& paint, 74 void GrTextContext::drawPosText(GrRenderTarget* rt, const GrClip& clip, const Gr Paint& paint,
72 const SkPaint& skPaint, const SkMatrix& viewMatr ix, 75 const SkPaint& skPaint, const SkMatrix& viewMatr ix,
73 const char text[], size_t byteLength, 76 const char text[], size_t byteLength,
74 const SkScalar pos[], int scalarsPerPosition, 77 const SkScalar pos[], int scalarsPerPosition,
75 const SkPoint& offset, const SkIRect& clipBounds ) { 78 const SkPoint& offset, const SkIRect& clipBounds ) {
76 if (fContext->abandoned() || !fDrawContext) { 79 if (fContext->abandoned()) {
80 return;
81 }
82
83 GrDrawContext* drawContext = fContext->drawContext();
84 if (!drawContext) {
77 return; 85 return;
78 } 86 }
79 87
80 GrTextContext* textContext = this; 88 GrTextContext* textContext = this;
81 do { 89 do {
82 if (textContext->canDraw(rt, clip, paint, skPaint, viewMatrix)) { 90 if (textContext->canDraw(rt, clip, paint, skPaint, viewMatrix)) {
83 textContext->onDrawPosText(rt, clip, paint, skPaint, viewMatrix, 91 textContext->onDrawPosText(drawContext, rt, clip, paint, skPaint, vi ewMatrix,
84 text, byteLength, pos, 92 text, byteLength, pos,
85 scalarsPerPosition, offset, clipBounds); 93 scalarsPerPosition, offset, clipBounds);
86 return; 94 return;
87 } 95 }
88 textContext = textContext->fFallbackTextContext; 96 textContext = textContext->fFallbackTextContext;
89 } while (textContext); 97 } while (textContext);
90 98
91 // fall back to drawing as a path 99 // fall back to drawing as a path
92 this->drawPosTextAsPath(rt, clip, skPaint, viewMatrix, text, byteLength, pos , 100 this->drawPosTextAsPath(drawContext, rt, clip, skPaint, viewMatrix, text, by teLength, pos,
93 scalarsPerPosition, offset, clipBounds); 101 scalarsPerPosition, offset, clipBounds);
94 } 102 }
95 103
96 bool GrTextContext::ShouldDisableLCD(const SkPaint& paint) { 104 bool GrTextContext::ShouldDisableLCD(const SkPaint& paint) {
97 if (paint.getShader() || 105 if (paint.getShader() ||
98 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode) || 106 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode) ||
99 paint.getMaskFilter() || 107 paint.getMaskFilter() ||
100 paint.getRasterizer() || 108 paint.getRasterizer() ||
101 paint.getColorFilter() || 109 paint.getColorFilter() ||
102 paint.getPathEffect() || 110 paint.getPathEffect() ||
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 SkFAIL("unhandled positioning mode"); 176 SkFAIL("unhandled positioning mode");
169 } 177 }
170 178
171 if (drawFilter) { 179 if (drawFilter) {
172 // A draw filter may change the paint arbitrarily, so we must re-see d in this case. 180 // A draw filter may change the paint arbitrarily, so we must re-see d in this case.
173 runPaint = skPaint; 181 runPaint = skPaint;
174 } 182 }
175 } 183 }
176 } 184 }
177 185
178 void GrTextContext::drawTextAsPath(GrRenderTarget* rt, 186 void GrTextContext::drawTextAsPath(GrDrawContext* drawContext, GrRenderTarget* r t,
179 const GrClip& clip, 187 const GrClip& clip,
180 const SkPaint& skPaint, const SkMatrix& viewM atrix, 188 const SkPaint& skPaint, const SkMatrix& viewM atrix,
181 const char text[], size_t byteLength, SkScala r x, SkScalar y, 189 const char text[], size_t byteLength, SkScala r x, SkScalar y,
182 const SkIRect& clipBounds) { 190 const SkIRect& clipBounds) {
183 SkTextToPathIter iter(text, byteLength, skPaint, true); 191 SkTextToPathIter iter(text, byteLength, skPaint, true);
184 192
185 SkMatrix matrix; 193 SkMatrix matrix;
186 matrix.setScale(iter.getPathScale(), iter.getPathScale()); 194 matrix.setScale(iter.getPathScale(), iter.getPathScale());
187 matrix.postTranslate(x, y); 195 matrix.postTranslate(x, y);
188 196
189 const SkPath* iterPath; 197 const SkPath* iterPath;
190 SkScalar xpos, prevXPos = 0; 198 SkScalar xpos, prevXPos = 0;
191 199
192 while (iter.next(&iterPath, &xpos)) { 200 while (iter.next(&iterPath, &xpos)) {
193 matrix.postTranslate(xpos - prevXPos, 0); 201 matrix.postTranslate(xpos - prevXPos, 0);
194 if (iterPath) { 202 if (iterPath) {
195 const SkPaint& pnt = iter.getPaint(); 203 const SkPaint& pnt = iter.getPaint();
196 GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext, rt, clip , *iterPath, 204 GrBlurUtils::drawPathWithMaskFilter(fContext, drawContext, rt, clip, *iterPath,
197 pnt, viewMatrix, &matrix, clipBo unds, false); 205 pnt, viewMatrix, &matrix, clipBo unds, false);
198 } 206 }
199 prevXPos = xpos; 207 prevXPos = xpos;
200 } 208 }
201 } 209 }
202 210
203 void GrTextContext::drawPosTextAsPath(GrRenderTarget* rt, 211 void GrTextContext::drawPosTextAsPath(GrDrawContext* drawContext, GrRenderTarget * rt,
204 const GrClip& clip, 212 const GrClip& clip,
205 const SkPaint& origPaint, const SkMatrix& viewMatrix, 213 const SkPaint& origPaint, const SkMatrix& viewMatrix,
206 const char text[], size_t byteLength, 214 const char text[], size_t byteLength,
207 const SkScalar pos[], int scalarsPerPositi on, 215 const SkScalar pos[], int scalarsPerPositi on,
208 const SkPoint& offset, const SkIRect& clip Bounds) { 216 const SkPoint& offset, const SkIRect& clip Bounds) {
209 // setup our std paint, in hopes of getting hits in the cache 217 // setup our std paint, in hopes of getting hits in the cache
210 SkPaint paint(origPaint); 218 SkPaint paint(origPaint);
211 SkScalar matrixScale = paint.setupForAsPaths(); 219 SkScalar matrixScale = paint.setupForAsPaths();
212 220
213 SkMatrix matrix; 221 SkMatrix matrix;
(...skipping 20 matching lines...) Expand all
234 if (glyph.fWidth) { 242 if (glyph.fWidth) {
235 const SkPath* path = cache->findPath(glyph); 243 const SkPath* path = cache->findPath(glyph);
236 if (path) { 244 if (path) {
237 SkPoint tmsLoc; 245 SkPoint tmsLoc;
238 tmsProc(pos, &tmsLoc); 246 tmsProc(pos, &tmsLoc);
239 SkPoint loc; 247 SkPoint loc;
240 alignProc(tmsLoc, glyph, &loc); 248 alignProc(tmsLoc, glyph, &loc);
241 249
242 matrix[SkMatrix::kMTransX] = loc.fX; 250 matrix[SkMatrix::kMTransX] = loc.fX;
243 matrix[SkMatrix::kMTransY] = loc.fY; 251 matrix[SkMatrix::kMTransY] = loc.fY;
244 GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext, rt, clip, *path, paint, 252 GrBlurUtils::drawPathWithMaskFilter(fContext, drawContext, rt, c lip, *path, paint,
245 viewMatrix, &matrix, clipBou nds, false); 253 viewMatrix, &matrix, clipBou nds, false);
246 } 254 }
247 } 255 }
248 pos += scalarsPerPosition; 256 pos += scalarsPerPosition;
249 } 257 }
250 } 258 }
251 259
252 //*** change to output positions? 260 //*** change to output positions?
253 int GrTextContext::MeasureText(SkGlyphCache* cache, SkDrawCacheProc glyphCachePr oc, 261 int GrTextContext::MeasureText(SkGlyphCache* cache, SkDrawCacheProc glyphCachePr oc,
254 const char text[], size_t byteLength, SkVector* stopVector) { 262 const char text[], size_t byteLength, SkVector* stopVector) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 if (cache->getAuxProcData(GlyphCacheAuxProc, &auxData)) { 294 if (cache->getAuxProcData(GlyphCacheAuxProc, &auxData)) {
287 scaler = (GrFontScaler*)auxData; 295 scaler = (GrFontScaler*)auxData;
288 } 296 }
289 if (NULL == scaler) { 297 if (NULL == scaler) {
290 scaler = SkNEW_ARGS(GrFontScaler, (cache)); 298 scaler = SkNEW_ARGS(GrFontScaler, (cache));
291 cache->setAuxProc(GlyphCacheAuxProc, scaler); 299 cache->setAuxProc(GlyphCacheAuxProc, scaler);
292 } 300 }
293 301
294 return scaler; 302 return scaler;
295 } 303 }
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