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

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

Issue 1320323004: Make GrTextContext no longer store a GrDrawContext (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add newline Created 5 years, 3 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 "GrAtlasTextContext.h" 9 #include "GrAtlasTextContext.h"
10 #include "GrDrawContext.h" 10 #include "GrDrawContext.h"
11 #include "GrDrawTarget.h" 11 #include "GrDrawTarget.h"
12 #include "GrPath.h" 12 #include "GrPath.h"
13 #include "GrPathRange.h" 13 #include "GrPathRange.h"
14 #include "GrResourceProvider.h" 14 #include "GrResourceProvider.h"
15 #include "SkAutoKern.h" 15 #include "SkAutoKern.h"
16 #include "SkDraw.h" 16 #include "SkDraw.h"
17 #include "SkDrawProcs.h" 17 #include "SkDrawProcs.h"
18 #include "SkGlyphCache.h" 18 #include "SkGlyphCache.h"
19 #include "SkGpuDevice.h" 19 #include "SkGpuDevice.h"
20 #include "SkPath.h" 20 #include "SkPath.h"
21 #include "SkTextMapStateProc.h" 21 #include "SkTextMapStateProc.h"
22 #include "SkTextFormatParams.h" 22 #include "SkTextFormatParams.h"
23 23
24 GrStencilAndCoverTextContext::GrStencilAndCoverTextContext(GrContext* context, 24 GrStencilAndCoverTextContext::GrStencilAndCoverTextContext(GrContext* context,
25 GrDrawContext* drawCo ntext,
26 const SkSurfaceProps& surfaceProps) 25 const SkSurfaceProps& surfaceProps)
27 : GrTextContext(context, drawContext, surfaceProps) 26 : GrTextContext(context, surfaceProps)
28 , fStroke(SkStrokeRec::kFill_InitStyle) 27 , fStroke(SkStrokeRec::kFill_InitStyle)
29 , fQueuedGlyphCount(0) 28 , fQueuedGlyphCount(0)
30 , fFallbackGlyphsIdx(kGlyphBufferSize) { 29 , fFallbackGlyphsIdx(kGlyphBufferSize) {
31 } 30 }
32 31
33 GrStencilAndCoverTextContext* 32 GrStencilAndCoverTextContext*
34 GrStencilAndCoverTextContext::Create(GrContext* context, GrDrawContext* drawCont ext, 33 GrStencilAndCoverTextContext::Create(GrContext* context, const SkSurfaceProps& s urfaceProps) {
35 const SkSurfaceProps& surfaceProps) { 34 GrStencilAndCoverTextContext* textContext =
36 GrStencilAndCoverTextContext* textContext = 35 new GrStencilAndCoverTextContext(context, surfaceProps);
37 new GrStencilAndCoverTextContext(context, drawContext, surfaceProps) ; 36 textContext->fFallbackTextContext = GrAtlasTextContext::Create(context, surf aceProps);
38 textContext->fFallbackTextContext = GrAtlasTextContext::Create(context, draw Context, surfaceProps);
39 37
40 return textContext; 38 return textContext;
41 } 39 }
42 40
43 GrStencilAndCoverTextContext::~GrStencilAndCoverTextContext() { 41 GrStencilAndCoverTextContext::~GrStencilAndCoverTextContext() {
44 } 42 }
45 43
46 bool GrStencilAndCoverTextContext::canDraw(const GrRenderTarget* rt, 44 bool GrStencilAndCoverTextContext::canDraw(const GrRenderTarget* rt,
47 const GrClip& clip, 45 const GrClip& clip,
48 const GrPaint& paint, 46 const GrPaint& paint,
(...skipping 17 matching lines...) Expand all
66 && viewMatrix.hasPerspective()) { 64 && viewMatrix.hasPerspective()) {
67 return false; 65 return false;
68 } 66 }
69 67
70 // No color bitmap fonts. 68 // No color bitmap fonts.
71 SkScalerContext::Rec rec; 69 SkScalerContext::Rec rec;
72 SkScalerContext::MakeRec(skPaint, &fSurfaceProps, nullptr, &rec); 70 SkScalerContext::MakeRec(skPaint, &fSurfaceProps, nullptr, &rec);
73 return rec.getFormat() != SkMask::kARGB32_Format; 71 return rec.getFormat() != SkMask::kARGB32_Format;
74 } 72 }
75 73
76 void GrStencilAndCoverTextContext::onDrawText(GrRenderTarget* rt, 74 void GrStencilAndCoverTextContext::onDrawText(GrDrawContext* dc, GrRenderTarget* rt,
77 const GrClip& clip, 75 const GrClip& clip,
78 const GrPaint& paint, 76 const GrPaint& paint,
79 const SkPaint& skPaint, 77 const SkPaint& skPaint,
80 const SkMatrix& viewMatrix, 78 const SkMatrix& viewMatrix,
81 const char text[], 79 const char text[],
82 size_t byteLength, 80 size_t byteLength,
83 SkScalar x, SkScalar y, 81 SkScalar x, SkScalar y,
84 const SkIRect& regionClipBounds) { 82 const SkIRect& regionClipBounds) {
85 SkASSERT(byteLength == 0 || text != nullptr); 83 SkASSERT(byteLength == 0 || text != nullptr);
86 84
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 SkAutoKern autokern; 147 SkAutoKern autokern;
150 148
151 SkFixed fixedSizeRatio = SkScalarToFixed(fTextRatio); 149 SkFixed fixedSizeRatio = SkScalarToFixed(fTextRatio);
152 150
153 SkFixed fx = SkScalarToFixed(x); 151 SkFixed fx = SkScalarToFixed(x);
154 SkFixed fy = SkScalarToFixed(y); 152 SkFixed fy = SkScalarToFixed(y);
155 while (text < stop) { 153 while (text < stop) {
156 const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &text, 0, 0); 154 const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &text, 0, 0);
157 fx += SkFixedMul(autokern.adjust(glyph), fixedSizeRatio); 155 fx += SkFixedMul(autokern.adjust(glyph), fixedSizeRatio);
158 if (glyph.fWidth) { 156 if (glyph.fWidth) {
159 this->appendGlyph(glyph, SkPoint::Make(SkFixedToScalar(fx), SkFixedT oScalar(fy))); 157 this->appendGlyph(dc, glyph, SkPoint::Make(SkFixedToScalar(fx), SkFi xedToScalar(fy)));
160 } 158 }
161 159
162 fx += SkFixedMul(glyph.fAdvanceX, fixedSizeRatio); 160 fx += SkFixedMul(glyph.fAdvanceX, fixedSizeRatio);
163 fy += SkFixedMul(glyph.fAdvanceY, fixedSizeRatio); 161 fy += SkFixedMul(glyph.fAdvanceY, fixedSizeRatio);
164 } 162 }
165 163
166 this->finish(); 164 this->finish(dc);
167 } 165 }
168 166
169 void GrStencilAndCoverTextContext::onDrawPosText(GrRenderTarget* rt, 167 void GrStencilAndCoverTextContext::onDrawPosText(GrDrawContext* dc, GrRenderTarg et* rt,
170 const GrClip& clip, 168 const GrClip& clip,
171 const GrPaint& paint, 169 const GrPaint& paint,
172 const SkPaint& skPaint, 170 const SkPaint& skPaint,
173 const SkMatrix& viewMatrix, 171 const SkMatrix& viewMatrix,
174 const char text[], 172 const char text[],
175 size_t byteLength, 173 size_t byteLength,
176 const SkScalar pos[], 174 const SkScalar pos[],
177 int scalarsPerPosition, 175 int scalarsPerPosition,
178 const SkPoint& offset, 176 const SkPoint& offset,
179 const SkIRect& regionClipBounds ) { 177 const SkIRect& regionClipBounds ) {
(...skipping 23 matching lines...) Expand all
203 SkTextMapStateProc tmsProc(SkMatrix::I(), offset, scalarsPerPosition); 201 SkTextMapStateProc tmsProc(SkMatrix::I(), offset, scalarsPerPosition);
204 SkTextAlignProc alignProc(fSkPaint.getTextAlign()); 202 SkTextAlignProc alignProc(fSkPaint.getTextAlign());
205 while (text < stop) { 203 while (text < stop) {
206 const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &text, 0, 0); 204 const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &text, 0, 0);
207 if (glyph.fWidth) { 205 if (glyph.fWidth) {
208 SkPoint tmsLoc; 206 SkPoint tmsLoc;
209 tmsProc(pos, &tmsLoc); 207 tmsProc(pos, &tmsLoc);
210 SkPoint loc; 208 SkPoint loc;
211 alignProc(tmsLoc, glyph, &loc); 209 alignProc(tmsLoc, glyph, &loc);
212 210
213 this->appendGlyph(glyph, loc); 211 this->appendGlyph(dc, glyph, loc);
214 } 212 }
215 pos += scalarsPerPosition; 213 pos += scalarsPerPosition;
216 } 214 }
217 215
218 this->finish(); 216 this->finish(dc);
219 } 217 }
220 218
221 static GrPathRange* get_gr_glyphs(GrContext* ctx, 219 static GrPathRange* get_gr_glyphs(GrContext* ctx,
222 const SkTypeface* typeface, 220 const SkTypeface* typeface,
223 const SkDescriptor* desc, 221 const SkDescriptor* desc,
224 const GrStrokeInfo& stroke) { 222 const GrStrokeInfo& stroke) {
225 223
226 static const GrUniqueKey::Domain kPathGlyphDomain = GrUniqueKey::GenerateDom ain(); 224 static const GrUniqueKey::Domain kPathGlyphDomain = GrUniqueKey::GenerateDom ain();
227 int strokeDataCount = stroke.computeUniqueKeyFragmentData32Cnt(); 225 int strokeDataCount = stroke.computeUniqueKeyFragmentData32Cnt();
228 GrUniqueKey glyphKey; 226 GrUniqueKey glyphKey;
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 } 391 }
394 inverse->preScale(1, -1); 392 inverse->preScale(1, -1);
395 } else { 393 } else {
396 inverse->setScale(1, -1); 394 inverse->setScale(1, -1);
397 const SkMatrix& unflip = *inverse; // unflip is equal to its own inverse . 395 const SkMatrix& unflip = *inverse; // unflip is equal to its own inverse .
398 fViewMatrix.preConcat(unflip); 396 fViewMatrix.preConcat(unflip);
399 } 397 }
400 return true; 398 return true;
401 } 399 }
402 400
403 inline void GrStencilAndCoverTextContext::appendGlyph(const SkGlyph& glyph, cons t SkPoint& pos) { 401 inline void GrStencilAndCoverTextContext::appendGlyph(GrDrawContext* dc,
402 const SkGlyph& glyph,
403 const SkPoint& pos) {
404 if (fQueuedGlyphCount >= fFallbackGlyphsIdx) { 404 if (fQueuedGlyphCount >= fFallbackGlyphsIdx) {
405 SkASSERT(fQueuedGlyphCount == fFallbackGlyphsIdx); 405 SkASSERT(fQueuedGlyphCount == fFallbackGlyphsIdx);
406 this->flush(); 406 this->flush(dc);
407 } 407 }
408 408
409 // Stick the glyphs we can't draw at the end of the buffer, growing backward s. 409 // Stick the glyphs we can't draw at the end of the buffer, growing backward s.
410 int index = (SkMask::kARGB32_Format == glyph.fMaskFormat) ? 410 int index = (SkMask::kARGB32_Format == glyph.fMaskFormat) ?
411 --fFallbackGlyphsIdx : fQueuedGlyphCount++; 411 --fFallbackGlyphsIdx : fQueuedGlyphCount++;
412 412
413 fGlyphIndices[index] = glyph.getGlyphID(); 413 fGlyphIndices[index] = glyph.getGlyphID();
414 fGlyphPositions[index].set(fTextInverseRatio * pos.x(), -fTextInverseRatio * pos.y()); 414 fGlyphPositions[index].set(fTextInverseRatio * pos.x(), -fTextInverseRatio * pos.y());
415 } 415 }
416 416
417 static const SkScalar* get_xy_scalar_array(const SkPoint* pointArray) { 417 static const SkScalar* get_xy_scalar_array(const SkPoint* pointArray) {
418 GR_STATIC_ASSERT(2 * sizeof(SkScalar) == sizeof(SkPoint)); 418 GR_STATIC_ASSERT(2 * sizeof(SkScalar) == sizeof(SkPoint));
419 GR_STATIC_ASSERT(0 == offsetof(SkPoint, fX)); 419 GR_STATIC_ASSERT(0 == offsetof(SkPoint, fX));
420 420
421 return &pointArray[0].fX; 421 return &pointArray[0].fX;
422 } 422 }
423 423
424 void GrStencilAndCoverTextContext::flush() { 424 void GrStencilAndCoverTextContext::flush(GrDrawContext* dc) {
425 if (fQueuedGlyphCount > 0) { 425 if (fQueuedGlyphCount > 0) {
426 SkAutoTUnref<GrPathProcessor> pp(GrPathProcessor::Create(fPaint.getColor (), 426 SkAutoTUnref<GrPathProcessor> pp(GrPathProcessor::Create(fPaint.getColor (),
427 fViewMatrix, 427 fViewMatrix,
428 fLocalMatrix)); 428 fLocalMatrix));
429 429
430 // We should only be flushing about once every run. However, if this im pacts performance 430 // We should only be flushing about once every run. However, if this im pacts performance
431 // we could move the creation of the GrPipelineBuilder earlier. 431 // we could move the creation of the GrPipelineBuilder earlier.
432 GrPipelineBuilder pipelineBuilder(fPaint, fRenderTarget, fClip); 432 GrPipelineBuilder pipelineBuilder(fPaint, fRenderTarget, fClip);
433 SkASSERT(fRenderTarget->isStencilBufferMultisampled() || !fPaint.isAntiA lias()); 433 SkASSERT(fRenderTarget->isStencilBufferMultisampled() || !fPaint.isAntiA lias());
434 pipelineBuilder.setState(GrPipelineBuilder::kHWAntialias_Flag, fPaint.is AntiAlias()); 434 pipelineBuilder.setState(GrPipelineBuilder::kHWAntialias_Flag, fPaint.is AntiAlias());
435 435
436 GR_STATIC_CONST_SAME_STENCIL(kStencilPass, 436 GR_STATIC_CONST_SAME_STENCIL(kStencilPass,
437 kZero_StencilOp, 437 kZero_StencilOp,
438 kKeep_StencilOp, 438 kKeep_StencilOp,
439 kNotEqual_StencilFunc, 439 kNotEqual_StencilFunc,
440 0xffff, 440 0xffff,
441 0x0000, 441 0x0000,
442 0xffff); 442 0xffff);
443 443
444 *pipelineBuilder.stencil() = kStencilPass; 444 *pipelineBuilder.stencil() = kStencilPass;
445 445
446 SkASSERT(0 == fQueuedGlyphCount); 446 SkASSERT(0 == fQueuedGlyphCount);
447 SkASSERT(kGlyphBufferSize == fFallbackGlyphsIdx); 447 SkASSERT(kGlyphBufferSize == fFallbackGlyphsIdx);
448 448
449 fDrawContext->drawPaths(&pipelineBuilder, pp, fGlyphs, 449 dc->drawPaths(&pipelineBuilder, pp, fGlyphs,
450 fGlyphIndices, GrPathRange::kU16_PathIndexType, 450 fGlyphIndices, GrPathRange::kU16_PathIndexType,
451 get_xy_scalar_array(fGlyphPositions), 451 get_xy_scalar_array(fGlyphPositions),
452 GrPathRendering::kTranslate_PathTransformType, 452 GrPathRendering::kTranslate_PathTransformType,
453 fQueuedGlyphCount, GrPathRendering::kWinding_Fil lType); 453 fQueuedGlyphCount, GrPathRendering::kWinding_FillType);
454 454
455 fQueuedGlyphCount = 0; 455 fQueuedGlyphCount = 0;
456 } 456 }
457 457
458 if (fFallbackGlyphsIdx < kGlyphBufferSize) { 458 if (fFallbackGlyphsIdx < kGlyphBufferSize) {
459 int fallbackGlyphCount = kGlyphBufferSize - fFallbackGlyphsIdx; 459 int fallbackGlyphCount = kGlyphBufferSize - fFallbackGlyphsIdx;
460 460
461 GrPaint paintFallback(fPaint); 461 GrPaint paintFallback(fPaint);
462 462
463 SkPaint skPaintFallback(fSkPaint); 463 SkPaint skPaintFallback(fSkPaint);
464 if (!fUsingDeviceSpaceGlyphs) { 464 if (!fUsingDeviceSpaceGlyphs) {
465 fStroke.applyToPaint(&skPaintFallback); 465 fStroke.applyToPaint(&skPaintFallback);
466 } 466 }
467 skPaintFallback.setTextAlign(SkPaint::kLeft_Align); // Align has already been accounted for. 467 skPaintFallback.setTextAlign(SkPaint::kLeft_Align); // Align has already been accounted for.
468 skPaintFallback.setTextEncoding(SkPaint::kGlyphID_TextEncoding); 468 skPaintFallback.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
469 469
470 SkMatrix inverse; 470 SkMatrix inverse;
471 if (this->mapToFallbackContext(&inverse)) { 471 if (this->mapToFallbackContext(&inverse)) {
472 inverse.mapPoints(&fGlyphPositions[fFallbackGlyphsIdx], fallbackGlyp hCount); 472 inverse.mapPoints(&fGlyphPositions[fFallbackGlyphsIdx], fallbackGlyp hCount);
473 } 473 }
474 474
475 fFallbackTextContext->drawPosText(fRenderTarget, fClip, paintFallback, s kPaintFallback, 475 fFallbackTextContext->drawPosText(dc, fRenderTarget, fClip, paintFallbac k, skPaintFallback,
476 fViewMatrix, (char*)&fGlyphIndices[fFa llbackGlyphsIdx], 476 fViewMatrix, (char*)&fGlyphIndices[fFa llbackGlyphsIdx],
477 2 * fallbackGlyphCount, 477 2 * fallbackGlyphCount,
478 get_xy_scalar_array(&fGlyphPositions[f FallbackGlyphsIdx]), 478 get_xy_scalar_array(&fGlyphPositions[f FallbackGlyphsIdx]),
479 2, SkPoint::Make(0, 0), fRegionClipBou nds); 479 2, SkPoint::Make(0, 0), fRegionClipBou nds);
480 480
481 fFallbackGlyphsIdx = kGlyphBufferSize; 481 fFallbackGlyphsIdx = kGlyphBufferSize;
482 } 482 }
483 } 483 }
484 484
485 void GrStencilAndCoverTextContext::finish() { 485 void GrStencilAndCoverTextContext::finish(GrDrawContext* dc) {
486 this->flush(); 486 this->flush(dc);
487 487
488 fGlyphs->unref(); 488 fGlyphs->unref();
489 fGlyphs = nullptr; 489 fGlyphs = nullptr;
490 490
491 SkGlyphCache::AttachCache(fGlyphCache); 491 SkGlyphCache::AttachCache(fGlyphCache);
492 fGlyphCache = nullptr; 492 fGlyphCache = nullptr;
493 493
494 fViewMatrix = fContextInitialMatrix; 494 fViewMatrix = fContextInitialMatrix;
495 } 495 }
496 496
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