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

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

Issue 1175553002: 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
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,
25 const SkDevicePropert ies& properties) 26 const SkDevicePropert ies& properties)
26 : GrTextContext(context, properties) 27 : GrTextContext(context, drawContext, properties, /* useDFT = */ false)
27 , fStroke(SkStrokeRec::kFill_InitStyle) 28 , fStroke(SkStrokeRec::kFill_InitStyle)
28 , fQueuedGlyphCount(0) 29 , fQueuedGlyphCount(0)
29 , fFallbackGlyphsIdx(kGlyphBufferSize) { 30 , fFallbackGlyphsIdx(kGlyphBufferSize) {
30 } 31 }
31 32
32 GrStencilAndCoverTextContext* 33 GrStencilAndCoverTextContext*
33 GrStencilAndCoverTextContext::Create(GrContext* context, const SkDevicePropertie s& props) { 34 GrStencilAndCoverTextContext::Create(GrContext* context, GrDrawContext* drawCont ext,
35 const SkDeviceProperties& props, bool fallb ackUsesDFT) {
34 GrStencilAndCoverTextContext* textContext = SkNEW_ARGS(GrStencilAndCoverText Context, 36 GrStencilAndCoverTextContext* textContext = SkNEW_ARGS(GrStencilAndCoverText Context,
35 (context, props)); 37 (context, drawContext , props));
36 textContext->fFallbackTextContext = GrAtlasTextContext::Create(context, prop s, false); 38 textContext->fFallbackTextContext = GrAtlasTextContext::Create(context, draw Context,
39 props, fallba ckUsesDFT);
37 40
38 return textContext; 41 return textContext;
39 } 42 }
40 43
41 GrStencilAndCoverTextContext::~GrStencilAndCoverTextContext() { 44 GrStencilAndCoverTextContext::~GrStencilAndCoverTextContext() {
42 } 45 }
43 46
44 bool GrStencilAndCoverTextContext::canDraw(const GrRenderTarget* rt, 47 bool GrStencilAndCoverTextContext::canDraw(const GrRenderTarget* rt,
45 const GrClip& clip, 48 const GrClip& clip,
46 const GrPaint& paint, 49 const GrPaint& paint,
(...skipping 17 matching lines...) Expand all
64 && viewMatrix.hasPerspective()) { 67 && viewMatrix.hasPerspective()) {
65 return false; 68 return false;
66 } 69 }
67 70
68 // No color bitmap fonts. 71 // No color bitmap fonts.
69 SkScalerContext::Rec rec; 72 SkScalerContext::Rec rec;
70 SkScalerContext::MakeRec(skPaint, &fDeviceProperties, NULL, &rec); 73 SkScalerContext::MakeRec(skPaint, &fDeviceProperties, NULL, &rec);
71 return rec.getFormat() != SkMask::kARGB32_Format; 74 return rec.getFormat() != SkMask::kARGB32_Format;
72 } 75 }
73 76
74 void GrStencilAndCoverTextContext::onDrawText(GrDrawContext* drawContext, GrRend erTarget* rt, 77 void GrStencilAndCoverTextContext::onDrawText(GrRenderTarget* rt,
75 const GrClip& clip, 78 const GrClip& clip,
76 const GrPaint& paint, 79 const GrPaint& paint,
77 const SkPaint& skPaint, 80 const SkPaint& skPaint,
78 const SkMatrix& viewMatrix, 81 const SkMatrix& viewMatrix,
79 const char text[], 82 const char text[],
80 size_t byteLength, 83 size_t byteLength,
81 SkScalar x, SkScalar y, 84 SkScalar x, SkScalar y,
82 const SkIRect& regionClipBounds) { 85 const SkIRect& regionClipBounds) {
83 SkASSERT(byteLength == 0 || text != NULL); 86 SkASSERT(byteLength == 0 || text != NULL);
84 87
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 SkAutoKern autokern; 150 SkAutoKern autokern;
148 151
149 SkFixed fixedSizeRatio = SkScalarToFixed(fTextRatio); 152 SkFixed fixedSizeRatio = SkScalarToFixed(fTextRatio);
150 153
151 SkFixed fx = SkScalarToFixed(x); 154 SkFixed fx = SkScalarToFixed(x);
152 SkFixed fy = SkScalarToFixed(y); 155 SkFixed fy = SkScalarToFixed(y);
153 while (text < stop) { 156 while (text < stop) {
154 const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &text, 0, 0); 157 const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &text, 0, 0);
155 fx += SkFixedMul(autokern.adjust(glyph), fixedSizeRatio); 158 fx += SkFixedMul(autokern.adjust(glyph), fixedSizeRatio);
156 if (glyph.fWidth) { 159 if (glyph.fWidth) {
157 this->appendGlyph(drawContext, glyph, 160 this->appendGlyph(glyph, SkPoint::Make(SkFixedToScalar(fx), SkFixedT oScalar(fy)));
158 SkPoint::Make(SkFixedToScalar(fx), SkFixedToScalar (fy)));
159 } 161 }
160 162
161 fx += SkFixedMul(glyph.fAdvanceX, fixedSizeRatio); 163 fx += SkFixedMul(glyph.fAdvanceX, fixedSizeRatio);
162 fy += SkFixedMul(glyph.fAdvanceY, fixedSizeRatio); 164 fy += SkFixedMul(glyph.fAdvanceY, fixedSizeRatio);
163 } 165 }
164 166
165 this->finish(drawContext); 167 this->finish();
166 } 168 }
167 169
168 void GrStencilAndCoverTextContext::onDrawPosText(GrDrawContext* drawContext, 170 void GrStencilAndCoverTextContext::onDrawPosText(GrRenderTarget* rt,
169 GrRenderTarget* rt,
170 const GrClip& clip, 171 const GrClip& clip,
171 const GrPaint& paint, 172 const GrPaint& paint,
172 const SkPaint& skPaint, 173 const SkPaint& skPaint,
173 const SkMatrix& viewMatrix, 174 const SkMatrix& viewMatrix,
174 const char text[], 175 const char text[],
175 size_t byteLength, 176 size_t byteLength,
176 const SkScalar pos[], 177 const SkScalar pos[],
177 int scalarsPerPosition, 178 int scalarsPerPosition,
178 const SkPoint& offset, 179 const SkPoint& offset,
179 const SkIRect& regionClipBounds ) { 180 const SkIRect& regionClipBounds ) {
(...skipping 23 matching lines...) Expand all
203 SkTextMapStateProc tmsProc(SkMatrix::I(), offset, scalarsPerPosition); 204 SkTextMapStateProc tmsProc(SkMatrix::I(), offset, scalarsPerPosition);
204 SkTextAlignProc alignProc(fSkPaint.getTextAlign()); 205 SkTextAlignProc alignProc(fSkPaint.getTextAlign());
205 while (text < stop) { 206 while (text < stop) {
206 const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &text, 0, 0); 207 const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &text, 0, 0);
207 if (glyph.fWidth) { 208 if (glyph.fWidth) {
208 SkPoint tmsLoc; 209 SkPoint tmsLoc;
209 tmsProc(pos, &tmsLoc); 210 tmsProc(pos, &tmsLoc);
210 SkPoint loc; 211 SkPoint loc;
211 alignProc(tmsLoc, glyph, &loc); 212 alignProc(tmsLoc, glyph, &loc);
212 213
213 this->appendGlyph(drawContext, glyph, loc); 214 this->appendGlyph(glyph, loc);
214 } 215 }
215 pos += scalarsPerPosition; 216 pos += scalarsPerPosition;
216 } 217 }
217 218
218 this->finish(drawContext); 219 this->finish();
219 } 220 }
220 221
221 static GrPathRange* get_gr_glyphs(GrContext* ctx, 222 static GrPathRange* get_gr_glyphs(GrContext* ctx,
222 const SkTypeface* typeface, 223 const SkTypeface* typeface,
223 const SkDescriptor* desc, 224 const SkDescriptor* desc,
224 const GrStrokeInfo& stroke) { 225 const GrStrokeInfo& stroke) {
225 226
226 static const GrUniqueKey::Domain kPathGlyphDomain = GrUniqueKey::GenerateDom ain(); 227 static const GrUniqueKey::Domain kPathGlyphDomain = GrUniqueKey::GenerateDom ain();
227 int strokeDataCount = stroke.computeUniqueKeyFragmentData32Cnt(); 228 int strokeDataCount = stroke.computeUniqueKeyFragmentData32Cnt();
228 GrUniqueKey glyphKey; 229 GrUniqueKey glyphKey;
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 } 402 }
402 inverse->preScale(1, -1); 403 inverse->preScale(1, -1);
403 } else { 404 } else {
404 inverse->setScale(1, -1); 405 inverse->setScale(1, -1);
405 const SkMatrix& unflip = *inverse; // unflip is equal to its own inverse . 406 const SkMatrix& unflip = *inverse; // unflip is equal to its own inverse .
406 fViewMatrix.preConcat(unflip); 407 fViewMatrix.preConcat(unflip);
407 } 408 }
408 return true; 409 return true;
409 } 410 }
410 411
411 inline void GrStencilAndCoverTextContext::appendGlyph(GrDrawContext* drawContext , 412 inline void GrStencilAndCoverTextContext::appendGlyph(const SkGlyph& glyph, cons t SkPoint& pos) {
412 const SkGlyph& glyph, cons t SkPoint& pos) {
413 if (fQueuedGlyphCount >= fFallbackGlyphsIdx) { 413 if (fQueuedGlyphCount >= fFallbackGlyphsIdx) {
414 SkASSERT(fQueuedGlyphCount == fFallbackGlyphsIdx); 414 SkASSERT(fQueuedGlyphCount == fFallbackGlyphsIdx);
415 this->flush(drawContext); 415 this->flush();
416 } 416 }
417 417
418 // Stick the glyphs we can't draw at the end of the buffer, growing backward s. 418 // Stick the glyphs we can't draw at the end of the buffer, growing backward s.
419 int index = (SkMask::kARGB32_Format == glyph.fMaskFormat) ? 419 int index = (SkMask::kARGB32_Format == glyph.fMaskFormat) ?
420 --fFallbackGlyphsIdx : fQueuedGlyphCount++; 420 --fFallbackGlyphsIdx : fQueuedGlyphCount++;
421 421
422 fGlyphIndices[index] = glyph.getGlyphID(); 422 fGlyphIndices[index] = glyph.getGlyphID();
423 fGlyphPositions[index].set(fTextInverseRatio * pos.x(), -fTextInverseRatio * pos.y()); 423 fGlyphPositions[index].set(fTextInverseRatio * pos.x(), -fTextInverseRatio * pos.y());
424 } 424 }
425 425
426 static const SkScalar* get_xy_scalar_array(const SkPoint* pointArray) { 426 static const SkScalar* get_xy_scalar_array(const SkPoint* pointArray) {
427 GR_STATIC_ASSERT(2 * sizeof(SkScalar) == sizeof(SkPoint)); 427 GR_STATIC_ASSERT(2 * sizeof(SkScalar) == sizeof(SkPoint));
428 GR_STATIC_ASSERT(0 == offsetof(SkPoint, fX)); 428 GR_STATIC_ASSERT(0 == offsetof(SkPoint, fX));
429 429
430 return &pointArray[0].fX; 430 return &pointArray[0].fX;
431 } 431 }
432 432
433 void GrStencilAndCoverTextContext::flush(GrDrawContext* drawContext) { 433 void GrStencilAndCoverTextContext::flush() {
434 if (fQueuedGlyphCount > 0) { 434 if (fQueuedGlyphCount > 0) {
435 SkAutoTUnref<GrPathProcessor> pp(GrPathProcessor::Create(fPaint.getColor (), 435 SkAutoTUnref<GrPathProcessor> pp(GrPathProcessor::Create(fPaint.getColor (),
436 fViewMatrix, 436 fViewMatrix,
437 fLocalMatrix)); 437 fLocalMatrix));
438 438
439 drawContext->drawPaths(&fPipelineBuilder, pp, fGlyphs, 439 fDrawContext->drawPaths(&fPipelineBuilder, pp, fGlyphs,
440 fGlyphIndices, GrPathRange::kU16_PathIndexType, 440 fGlyphIndices, GrPathRange::kU16_PathIndexType,
441 get_xy_scalar_array(fGlyphPositions), 441 get_xy_scalar_array(fGlyphPositions),
442 GrPathRendering::kTranslate_PathTransformType, 442 GrPathRendering::kTranslate_PathTransformType,
443 fQueuedGlyphCount, GrPathRendering::kWinding_Fill Type); 443 fQueuedGlyphCount, GrPathRendering::kWinding_Fil lType);
444 444
445 fQueuedGlyphCount = 0; 445 fQueuedGlyphCount = 0;
446 } 446 }
447 447
448 if (fFallbackGlyphsIdx < kGlyphBufferSize) { 448 if (fFallbackGlyphsIdx < kGlyphBufferSize) {
449 int fallbackGlyphCount = kGlyphBufferSize - fFallbackGlyphsIdx; 449 int fallbackGlyphCount = kGlyphBufferSize - fFallbackGlyphsIdx;
450 450
451 GrPaint paintFallback(fPaint); 451 GrPaint paintFallback(fPaint);
452 452
453 SkPaint skPaintFallback(fSkPaint); 453 SkPaint skPaintFallback(fSkPaint);
(...skipping 11 matching lines...) Expand all
465 fFallbackTextContext->drawPosText(fRenderTarget, fClip, paintFallback, s kPaintFallback, 465 fFallbackTextContext->drawPosText(fRenderTarget, fClip, paintFallback, s kPaintFallback,
466 fViewMatrix, (char*)&fGlyphIndices[fFa llbackGlyphsIdx], 466 fViewMatrix, (char*)&fGlyphIndices[fFa llbackGlyphsIdx],
467 2 * fallbackGlyphCount, 467 2 * fallbackGlyphCount,
468 get_xy_scalar_array(&fGlyphPositions[f FallbackGlyphsIdx]), 468 get_xy_scalar_array(&fGlyphPositions[f FallbackGlyphsIdx]),
469 2, SkPoint::Make(0, 0), fRegionClipBou nds); 469 2, SkPoint::Make(0, 0), fRegionClipBou nds);
470 470
471 fFallbackGlyphsIdx = kGlyphBufferSize; 471 fFallbackGlyphsIdx = kGlyphBufferSize;
472 } 472 }
473 } 473 }
474 474
475 void GrStencilAndCoverTextContext::finish(GrDrawContext* drawContext) { 475 void GrStencilAndCoverTextContext::finish() {
476 this->flush(drawContext); 476 this->flush();
477 477
478 fGlyphs->unref(); 478 fGlyphs->unref();
479 fGlyphs = NULL; 479 fGlyphs = NULL;
480 480
481 SkGlyphCache::AttachCache(fGlyphCache); 481 SkGlyphCache::AttachCache(fGlyphCache);
482 fGlyphCache = NULL; 482 fGlyphCache = NULL;
483 483
484 fPipelineBuilder.stencil()->setDisabled(); 484 fPipelineBuilder.stencil()->setDisabled();
485 fStateRestore.set(NULL); 485 fStateRestore.set(NULL);
486 fViewMatrix = fContextInitialMatrix; 486 fViewMatrix = fContextInitialMatrix;
487 } 487 }
488 488
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698