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

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: Fix nvpr config 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/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,
25 const SkDevicePropert ies& properties) 26 const SkDevicePropert ies& properties)
26 : GrTextContext(context, properties) 27 : GrTextContext(context, drawContext, properties)
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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 } 404 }
404 inverse->preScale(1, -1); 405 inverse->preScale(1, -1);
405 } else { 406 } else {
406 inverse->setScale(1, -1); 407 inverse->setScale(1, -1);
407 const SkMatrix& unflip = *inverse; // unflip is equal to its own inverse . 408 const SkMatrix& unflip = *inverse; // unflip is equal to its own inverse .
408 fViewMatrix.preConcat(unflip); 409 fViewMatrix.preConcat(unflip);
409 } 410 }
410 return true; 411 return true;
411 } 412 }
412 413
413 inline void GrStencilAndCoverTextContext::appendGlyph(GrDrawContext* drawContext , 414 inline void GrStencilAndCoverTextContext::appendGlyph(const SkGlyph& glyph, cons t SkPoint& pos) {
414 const SkGlyph& glyph, cons t SkPoint& pos) {
415 if (fQueuedGlyphCount >= fFallbackGlyphsIdx) { 415 if (fQueuedGlyphCount >= fFallbackGlyphsIdx) {
416 SkASSERT(fQueuedGlyphCount == fFallbackGlyphsIdx); 416 SkASSERT(fQueuedGlyphCount == fFallbackGlyphsIdx);
417 this->flush(drawContext); 417 this->flush();
418 } 418 }
419 419
420 // Stick the glyphs we can't draw at the end of the buffer, growing backward s. 420 // Stick the glyphs we can't draw at the end of the buffer, growing backward s.
421 int index = (SkMask::kARGB32_Format == glyph.fMaskFormat) ? 421 int index = (SkMask::kARGB32_Format == glyph.fMaskFormat) ?
422 --fFallbackGlyphsIdx : fQueuedGlyphCount++; 422 --fFallbackGlyphsIdx : fQueuedGlyphCount++;
423 423
424 fGlyphIndices[index] = glyph.getGlyphID(); 424 fGlyphIndices[index] = glyph.getGlyphID();
425 fGlyphPositions[index].set(fTextInverseRatio * pos.x(), -fTextInverseRatio * pos.y()); 425 fGlyphPositions[index].set(fTextInverseRatio * pos.x(), -fTextInverseRatio * pos.y());
426 } 426 }
427 427
428 static const SkScalar* get_xy_scalar_array(const SkPoint* pointArray) { 428 static const SkScalar* get_xy_scalar_array(const SkPoint* pointArray) {
429 GR_STATIC_ASSERT(2 * sizeof(SkScalar) == sizeof(SkPoint)); 429 GR_STATIC_ASSERT(2 * sizeof(SkScalar) == sizeof(SkPoint));
430 GR_STATIC_ASSERT(0 == offsetof(SkPoint, fX)); 430 GR_STATIC_ASSERT(0 == offsetof(SkPoint, fX));
431 431
432 return &pointArray[0].fX; 432 return &pointArray[0].fX;
433 } 433 }
434 434
435 void GrStencilAndCoverTextContext::flush(GrDrawContext* drawContext) { 435 void GrStencilAndCoverTextContext::flush() {
436 if (fQueuedGlyphCount > 0) { 436 if (fQueuedGlyphCount > 0) {
437 SkAutoTUnref<GrPathProcessor> pp(GrPathProcessor::Create(fPaint.getColor (), 437 SkAutoTUnref<GrPathProcessor> pp(GrPathProcessor::Create(fPaint.getColor (),
438 fViewMatrix, 438 fViewMatrix,
439 fLocalMatrix)); 439 fLocalMatrix));
440 440
441 drawContext->drawPaths(&fPipelineBuilder, pp, fGlyphs, 441 fDrawContext->drawPaths(&fPipelineBuilder, pp, fGlyphs,
442 fGlyphIndices, GrPathRange::kU16_PathIndexType, 442 fGlyphIndices, GrPathRange::kU16_PathIndexType,
443 get_xy_scalar_array(fGlyphPositions), 443 get_xy_scalar_array(fGlyphPositions),
444 GrPathRendering::kTranslate_PathTransformType, 444 GrPathRendering::kTranslate_PathTransformType,
445 fQueuedGlyphCount, GrPathRendering::kWinding_Fill Type); 445 fQueuedGlyphCount, GrPathRendering::kWinding_Fil lType);
446 446
447 fQueuedGlyphCount = 0; 447 fQueuedGlyphCount = 0;
448 } 448 }
449 449
450 if (fFallbackGlyphsIdx < kGlyphBufferSize) { 450 if (fFallbackGlyphsIdx < kGlyphBufferSize) {
451 int fallbackGlyphCount = kGlyphBufferSize - fFallbackGlyphsIdx; 451 int fallbackGlyphCount = kGlyphBufferSize - fFallbackGlyphsIdx;
452 452
453 GrPaint paintFallback(fPaint); 453 GrPaint paintFallback(fPaint);
454 454
455 SkPaint skPaintFallback(fSkPaint); 455 SkPaint skPaintFallback(fSkPaint);
(...skipping 11 matching lines...) Expand all
467 fFallbackTextContext->drawPosText(fRenderTarget, fClip, paintFallback, s kPaintFallback, 467 fFallbackTextContext->drawPosText(fRenderTarget, fClip, paintFallback, s kPaintFallback,
468 fViewMatrix, (char*)&fGlyphIndices[fFa llbackGlyphsIdx], 468 fViewMatrix, (char*)&fGlyphIndices[fFa llbackGlyphsIdx],
469 2 * fallbackGlyphCount, 469 2 * fallbackGlyphCount,
470 get_xy_scalar_array(&fGlyphPositions[f FallbackGlyphsIdx]), 470 get_xy_scalar_array(&fGlyphPositions[f FallbackGlyphsIdx]),
471 2, SkPoint::Make(0, 0), fRegionClipBou nds); 471 2, SkPoint::Make(0, 0), fRegionClipBou nds);
472 472
473 fFallbackGlyphsIdx = kGlyphBufferSize; 473 fFallbackGlyphsIdx = kGlyphBufferSize;
474 } 474 }
475 } 475 }
476 476
477 void GrStencilAndCoverTextContext::finish(GrDrawContext* drawContext) { 477 void GrStencilAndCoverTextContext::finish() {
478 this->flush(drawContext); 478 this->flush();
479 479
480 fGlyphs->unref(); 480 fGlyphs->unref();
481 fGlyphs = NULL; 481 fGlyphs = NULL;
482 482
483 SkGlyphCache::AttachCache(fGlyphCache); 483 SkGlyphCache::AttachCache(fGlyphCache);
484 fGlyphCache = NULL; 484 fGlyphCache = NULL;
485 485
486 fPipelineBuilder.stencil()->setDisabled(); 486 fPipelineBuilder.stencil()->setDisabled();
487 fStateRestore.set(NULL); 487 fStateRestore.set(NULL);
488 fViewMatrix = fContextInitialMatrix; 488 fViewMatrix = fContextInitialMatrix;
489 } 489 }
490 490
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