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

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

Issue 956083002: Revert of Pass clip to context (Closed) Base URL: https://skia.googlesource.com/skia.git@pass_down_rendertarget
Patch Set: Created 5 years, 10 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/GrStencilAndCoverTextContext.h ('k') | src/gpu/GrTextContext.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 2014 Google Inc. 2 * Copyright 2014 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 "GrStencilAndCoverTextContext.h" 8 #include "GrStencilAndCoverTextContext.h"
9 #include "GrBitmapTextContext.h" 9 #include "GrBitmapTextContext.h"
10 #include "GrDrawTarget.h" 10 #include "GrDrawTarget.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 return false; 58 return false;
59 } 59 }
60 60
61 // No color bitmap fonts. 61 // No color bitmap fonts.
62 SkScalerContext::Rec rec; 62 SkScalerContext::Rec rec;
63 SkScalerContext::MakeRec(paint, &fDeviceProperties, NULL, &rec); 63 SkScalerContext::MakeRec(paint, &fDeviceProperties, NULL, &rec);
64 return rec.getFormat() != SkMask::kARGB32_Format; 64 return rec.getFormat() != SkMask::kARGB32_Format;
65 } 65 }
66 66
67 void GrStencilAndCoverTextContext::onDrawText(GrRenderTarget* rt, 67 void GrStencilAndCoverTextContext::onDrawText(GrRenderTarget* rt,
68 const GrClip& clip,
69 const GrPaint& paint, 68 const GrPaint& paint,
70 const SkPaint& skPaint, 69 const SkPaint& skPaint,
71 const SkMatrix& viewMatrix, 70 const SkMatrix& viewMatrix,
72 const char text[], 71 const char text[],
73 size_t byteLength, 72 size_t byteLength,
74 SkScalar x, SkScalar y) { 73 SkScalar x, SkScalar y) {
75 SkASSERT(byteLength == 0 || text != NULL); 74 SkASSERT(byteLength == 0 || text != NULL);
76 75
77 if (text == NULL || byteLength == 0 /*|| fRC->isEmpty()*/) { 76 if (text == NULL || byteLength == 0 /*|| fRC->isEmpty()*/) {
78 return; 77 return;
79 } 78 }
80 79
81 // This is the slow path, mainly used by Skia unit tests. The other 80 // This is the slow path, mainly used by Skia unit tests. The other
82 // backends (8888, gpu, ...) use device-space dependent glyph caches. In 81 // backends (8888, gpu, ...) use device-space dependent glyph caches. In
83 // order to match the glyph positions that the other code paths produce, we 82 // order to match the glyph positions that the other code paths produce, we
84 // must also use device-space dependent glyph cache. This has the 83 // must also use device-space dependent glyph cache. This has the
85 // side-effect that the glyph shape outline will be in device-space, 84 // side-effect that the glyph shape outline will be in device-space,
86 // too. This in turn has the side-effect that NVPR can not stroke the paths, 85 // too. This in turn has the side-effect that NVPR can not stroke the paths,
87 // as the stroke in NVPR is defined in object-space. 86 // as the stroke in NVPR is defined in object-space.
88 // NOTE: here we have following coincidence that works at the moment: 87 // NOTE: here we have following coincidence that works at the moment:
89 // - When using the device-space glyphs, the transforms we pass to NVPR 88 // - When using the device-space glyphs, the transforms we pass to NVPR
90 // instanced drawing are the global transforms, and the view transform is 89 // instanced drawing are the global transforms, and the view transform is
91 // identity. NVPR can not use non-affine transforms in the instanced 90 // identity. NVPR can not use non-affine transforms in the instanced
92 // drawing. This is taken care of by SkDraw::ShouldDrawTextAsPaths since it 91 // drawing. This is taken care of by SkDraw::ShouldDrawTextAsPaths since it
93 // will turn off the use of device-space glyphs when perspective transforms 92 // will turn off the use of device-space glyphs when perspective transforms
94 // are in use. 93 // are in use.
95 94
96 this->init(rt, clip, paint, skPaint, byteLength, kMaxAccuracy_RenderMode, vi ewMatrix); 95 this->init(rt, paint, skPaint, byteLength, kMaxAccuracy_RenderMode, viewMatr ix);
97 96
98 // Transform our starting point. 97 // Transform our starting point.
99 if (fUsingDeviceSpaceGlyphs) { 98 if (fUsingDeviceSpaceGlyphs) {
100 SkPoint loc; 99 SkPoint loc;
101 fContextInitialMatrix.mapXY(x, y, &loc); 100 fContextInitialMatrix.mapXY(x, y, &loc);
102 x = loc.fX; 101 x = loc.fX;
103 y = loc.fY; 102 y = loc.fY;
104 } 103 }
105 104
106 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); 105 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 } 148 }
150 149
151 fx += SkFixedMul_portable(glyph.fAdvanceX, fixedSizeRatio); 150 fx += SkFixedMul_portable(glyph.fAdvanceX, fixedSizeRatio);
152 fy += SkFixedMul_portable(glyph.fAdvanceY, fixedSizeRatio); 151 fy += SkFixedMul_portable(glyph.fAdvanceY, fixedSizeRatio);
153 } 152 }
154 153
155 this->finish(); 154 this->finish();
156 } 155 }
157 156
158 void GrStencilAndCoverTextContext::onDrawPosText(GrRenderTarget* rt, 157 void GrStencilAndCoverTextContext::onDrawPosText(GrRenderTarget* rt,
159 const GrClip& clip,
160 const GrPaint& paint, 158 const GrPaint& paint,
161 const SkPaint& skPaint, 159 const SkPaint& skPaint,
162 const SkMatrix& viewMatrix, 160 const SkMatrix& viewMatrix,
163 const char text[], 161 const char text[],
164 size_t byteLength, 162 size_t byteLength,
165 const SkScalar pos[], 163 const SkScalar pos[],
166 int scalarsPerPosition, 164 int scalarsPerPosition,
167 const SkPoint& offset) { 165 const SkPoint& offset) {
168 SkASSERT(byteLength == 0 || text != NULL); 166 SkASSERT(byteLength == 0 || text != NULL);
169 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); 167 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
170 168
171 // nothing to draw 169 // nothing to draw
172 if (text == NULL || byteLength == 0/* || fRC->isEmpty()*/) { 170 if (text == NULL || byteLength == 0/* || fRC->isEmpty()*/) {
173 return; 171 return;
174 } 172 }
175 173
176 // This is the fast path. Here we do not bake in the device-transform to 174 // This is the fast path. Here we do not bake in the device-transform to
177 // the glyph outline or the advances. This is because we do not need to 175 // the glyph outline or the advances. This is because we do not need to
178 // position the glyphs at all, since the caller has done the positioning. 176 // position the glyphs at all, since the caller has done the positioning.
179 // The positioning is based on SkPaint::measureText of individual 177 // The positioning is based on SkPaint::measureText of individual
180 // glyphs. That already uses glyph cache without device transforms. Device 178 // glyphs. That already uses glyph cache without device transforms. Device
181 // transform is not part of SkPaint::measureText API, and thus we use the 179 // transform is not part of SkPaint::measureText API, and thus we use the
182 // same glyphs as what were measured. 180 // same glyphs as what were measured.
183 181
184 this->init(rt, clip, paint, skPaint, byteLength, kMaxPerformance_RenderMode, viewMatrix); 182 this->init(rt, paint, skPaint, byteLength, kMaxPerformance_RenderMode, viewM atrix);
185 183
186 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); 184 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
187 185
188 const char* stop = text + byteLength; 186 const char* stop = text + byteLength;
189 187
190 SkTextMapStateProc tmsProc(SkMatrix::I(), offset, scalarsPerPosition); 188 SkTextMapStateProc tmsProc(SkMatrix::I(), offset, scalarsPerPosition);
191 SkTextAlignProcScalar alignProc(fSkPaint.getTextAlign()); 189 SkTextAlignProcScalar alignProc(fSkPaint.getTextAlign());
192 while (text < stop) { 190 while (text < stop) {
193 const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &text, 0, 0); 191 const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &text, 0, 0);
194 if (glyph.fWidth) { 192 if (glyph.fWidth) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 static_cast<GrPathRange*>(ctx->findAndRefCachedResource(key))); 225 static_cast<GrPathRange*>(ctx->findAndRefCachedResource(key)));
228 if (NULL == glyphs || (NULL != desc && !glyphs->isEqualTo(*desc))) { 226 if (NULL == glyphs || (NULL != desc && !glyphs->isEqualTo(*desc))) {
229 glyphs.reset(ctx->getGpu()->pathRendering()->createGlyphs(typeface, desc , stroke)); 227 glyphs.reset(ctx->getGpu()->pathRendering()->createGlyphs(typeface, desc , stroke));
230 ctx->addResourceToCache(key, glyphs); 228 ctx->addResourceToCache(key, glyphs);
231 } 229 }
232 230
233 return glyphs.detach(); 231 return glyphs.detach();
234 } 232 }
235 233
236 void GrStencilAndCoverTextContext::init(GrRenderTarget* rt, 234 void GrStencilAndCoverTextContext::init(GrRenderTarget* rt,
237 const GrClip& clip,
238 const GrPaint& paint, 235 const GrPaint& paint,
239 const SkPaint& skPaint, 236 const SkPaint& skPaint,
240 size_t textByteLength, 237 size_t textByteLength,
241 RenderMode renderMode, 238 RenderMode renderMode,
242 const SkMatrix& viewMatrix) { 239 const SkMatrix& viewMatrix) {
243 GrTextContext::init(rt, clip, paint, skPaint); 240 GrTextContext::init(rt, paint, skPaint);
244 241
245 fContextInitialMatrix = viewMatrix; 242 fContextInitialMatrix = viewMatrix;
246 fViewMatrix = viewMatrix; 243 fViewMatrix = viewMatrix;
247 fLocalMatrix = SkMatrix::I(); 244 fLocalMatrix = SkMatrix::I();
248 245
249 const bool otherBackendsWillDrawAsPaths = 246 const bool otherBackendsWillDrawAsPaths =
250 SkDraw::ShouldDrawTextAsPaths(skPaint, fContextInitialMatrix); 247 SkDraw::ShouldDrawTextAsPaths(skPaint, fContextInitialMatrix);
251 248
252 fUsingDeviceSpaceGlyphs = !otherBackendsWillDrawAsPaths && 249 fUsingDeviceSpaceGlyphs = !otherBackendsWillDrawAsPaths &&
253 kMaxAccuracy_RenderMode == renderMode && 250 kMaxAccuracy_RenderMode == renderMode &&
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 fStroke.applyToPaint(&skPaintFallback); 435 fStroke.applyToPaint(&skPaintFallback);
439 } 436 }
440 skPaintFallback.setTextAlign(SkPaint::kLeft_Align); // Align has already been accounted for. 437 skPaintFallback.setTextAlign(SkPaint::kLeft_Align); // Align has already been accounted for.
441 skPaintFallback.setTextEncoding(SkPaint::kGlyphID_TextEncoding); 438 skPaintFallback.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
442 439
443 SkMatrix inverse; 440 SkMatrix inverse;
444 if (this->mapToFallbackContext(&inverse)) { 441 if (this->mapToFallbackContext(&inverse)) {
445 inverse.mapPoints(&fGlyphPositions[fFallbackGlyphsIdx], fallbackGlyp hCount); 442 inverse.mapPoints(&fGlyphPositions[fFallbackGlyphsIdx], fallbackGlyp hCount);
446 } 443 }
447 444
448 fFallbackTextContext->drawPosText(fRenderTarget, fClip, paintFallback, s kPaintFallback, 445 fFallbackTextContext->drawPosText(fRenderTarget, paintFallback, skPaintF allback,
449 fViewMatrix, (char*)&fGlyphIndices[fFa llbackGlyphsIdx], 446 fViewMatrix, (char*)&fGlyphIndices[fFa llbackGlyphsIdx],
450 2 * fallbackGlyphCount, 447 2 * fallbackGlyphCount,
451 get_xy_scalar_array(&fGlyphPositions[f FallbackGlyphsIdx]), 448 get_xy_scalar_array(&fGlyphPositions[f FallbackGlyphsIdx]),
452 2, SkPoint::Make(0, 0)); 449 2, SkPoint::Make(0, 0));
453 450
454 fFallbackGlyphsIdx = kGlyphBufferSize; 451 fFallbackGlyphsIdx = kGlyphBufferSize;
455 } 452 }
456 } 453 }
457 454
458 void GrStencilAndCoverTextContext::finish() { 455 void GrStencilAndCoverTextContext::finish() {
459 this->flush(); 456 this->flush();
460 457
461 fGlyphs->unref(); 458 fGlyphs->unref();
462 fGlyphs = NULL; 459 fGlyphs = NULL;
463 460
464 SkGlyphCache::AttachCache(fGlyphCache); 461 SkGlyphCache::AttachCache(fGlyphCache);
465 fGlyphCache = NULL; 462 fGlyphCache = NULL;
466 463
467 fPipelineBuilder.stencil()->setDisabled(); 464 fPipelineBuilder.stencil()->setDisabled();
468 fStateRestore.set(NULL); 465 fStateRestore.set(NULL);
469 fViewMatrix = fContextInitialMatrix; 466 fViewMatrix = fContextInitialMatrix;
470 GrTextContext::finish(); 467 GrTextContext::finish();
471 } 468 }
472 469
OLDNEW
« no previous file with comments | « src/gpu/GrStencilAndCoverTextContext.h ('k') | src/gpu/GrTextContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698