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

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

Issue 1157773003: Move SkGpuDevice::internalDrawPath to GrBlurUtils::drawPathWithMaskFilter (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: more cleanup Created 5 years, 7 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 SkGpuDevice* gpuDevic e,
26 const SkDevicePropert ies& properties) 25 const SkDevicePropert ies& properties)
27 : GrTextContext(context, gpuDevice, properties) 26 : GrTextContext(context, properties)
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, SkGpuDevice* gpuDevice, 33 GrStencilAndCoverTextContext::Create(GrContext* context, const SkDevicePropertie s& props) {
35 const SkDeviceProperties& props) {
36 GrStencilAndCoverTextContext* textContext = SkNEW_ARGS(GrStencilAndCoverText Context, 34 GrStencilAndCoverTextContext* textContext = SkNEW_ARGS(GrStencilAndCoverText Context,
37 (context, gpuDevice, props)); 35 (context, props));
38 textContext->fFallbackTextContext = GrAtlasTextContext::Create(context, gpuD evice, props, 36 textContext->fFallbackTextContext = GrAtlasTextContext::Create(context, prop s, false);
39 false);
40 37
41 return textContext; 38 return textContext;
42 } 39 }
43 40
44 GrStencilAndCoverTextContext::~GrStencilAndCoverTextContext() { 41 GrStencilAndCoverTextContext::~GrStencilAndCoverTextContext() {
45 } 42 }
46 43
47 bool GrStencilAndCoverTextContext::canDraw(const GrRenderTarget* rt, 44 bool GrStencilAndCoverTextContext::canDraw(const GrRenderTarget* rt,
48 const GrClip& clip, 45 const GrClip& clip,
49 const GrPaint& paint, 46 const GrPaint& paint,
(...skipping 17 matching lines...) Expand all
67 && viewMatrix.hasPerspective()) { 64 && viewMatrix.hasPerspective()) {
68 return false; 65 return false;
69 } 66 }
70 67
71 // No color bitmap fonts. 68 // No color bitmap fonts.
72 SkScalerContext::Rec rec; 69 SkScalerContext::Rec rec;
73 SkScalerContext::MakeRec(skPaint, &fDeviceProperties, NULL, &rec); 70 SkScalerContext::MakeRec(skPaint, &fDeviceProperties, NULL, &rec);
74 return rec.getFormat() != SkMask::kARGB32_Format; 71 return rec.getFormat() != SkMask::kARGB32_Format;
75 } 72 }
76 73
77 void GrStencilAndCoverTextContext::onDrawText(GrRenderTarget* rt, 74 void GrStencilAndCoverTextContext::onDrawText(GrDrawContext* drawContext, GrRend erTarget* rt,
78 const GrClip& clip, 75 const GrClip& clip,
79 const GrPaint& paint, 76 const GrPaint& paint,
80 const SkPaint& skPaint, 77 const SkPaint& skPaint,
81 const SkMatrix& viewMatrix, 78 const SkMatrix& viewMatrix,
82 const char text[], 79 const char text[],
83 size_t byteLength, 80 size_t byteLength,
84 SkScalar x, SkScalar y, 81 SkScalar x, SkScalar y,
85 const SkIRect& regionClipBounds) { 82 const SkIRect& regionClipBounds) {
86 SkASSERT(byteLength == 0 || text != NULL); 83 SkASSERT(byteLength == 0 || text != NULL);
87 84
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 SkAutoKern autokern; 147 SkAutoKern autokern;
151 148
152 SkFixed fixedSizeRatio = SkScalarToFixed(fTextRatio); 149 SkFixed fixedSizeRatio = SkScalarToFixed(fTextRatio);
153 150
154 SkFixed fx = SkScalarToFixed(x); 151 SkFixed fx = SkScalarToFixed(x);
155 SkFixed fy = SkScalarToFixed(y); 152 SkFixed fy = SkScalarToFixed(y);
156 while (text < stop) { 153 while (text < stop) {
157 const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &text, 0, 0); 154 const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &text, 0, 0);
158 fx += SkFixedMul(autokern.adjust(glyph), fixedSizeRatio); 155 fx += SkFixedMul(autokern.adjust(glyph), fixedSizeRatio);
159 if (glyph.fWidth) { 156 if (glyph.fWidth) {
160 this->appendGlyph(glyph, SkPoint::Make(SkFixedToScalar(fx), SkFixedT oScalar(fy))); 157 this->appendGlyph(drawContext, glyph,
158 SkPoint::Make(SkFixedToScalar(fx), SkFixedToScalar (fy)));
161 } 159 }
162 160
163 fx += SkFixedMul(glyph.fAdvanceX, fixedSizeRatio); 161 fx += SkFixedMul(glyph.fAdvanceX, fixedSizeRatio);
164 fy += SkFixedMul(glyph.fAdvanceY, fixedSizeRatio); 162 fy += SkFixedMul(glyph.fAdvanceY, fixedSizeRatio);
165 } 163 }
166 164
167 this->finish(); 165 this->finish(drawContext);
168 } 166 }
169 167
170 void GrStencilAndCoverTextContext::onDrawPosText(GrRenderTarget* rt, 168 void GrStencilAndCoverTextContext::onDrawPosText(GrDrawContext* drawContext,
169 GrRenderTarget* rt,
171 const GrClip& clip, 170 const GrClip& clip,
172 const GrPaint& paint, 171 const GrPaint& paint,
173 const SkPaint& skPaint, 172 const SkPaint& skPaint,
174 const SkMatrix& viewMatrix, 173 const SkMatrix& viewMatrix,
175 const char text[], 174 const char text[],
176 size_t byteLength, 175 size_t byteLength,
177 const SkScalar pos[], 176 const SkScalar pos[],
178 int scalarsPerPosition, 177 int scalarsPerPosition,
179 const SkPoint& offset, 178 const SkPoint& offset,
180 const SkIRect& regionClipBounds ) { 179 const SkIRect& regionClipBounds ) {
(...skipping 23 matching lines...) Expand all
204 SkTextMapStateProc tmsProc(SkMatrix::I(), offset, scalarsPerPosition); 203 SkTextMapStateProc tmsProc(SkMatrix::I(), offset, scalarsPerPosition);
205 SkTextAlignProc alignProc(fSkPaint.getTextAlign()); 204 SkTextAlignProc alignProc(fSkPaint.getTextAlign());
206 while (text < stop) { 205 while (text < stop) {
207 const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &text, 0, 0); 206 const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &text, 0, 0);
208 if (glyph.fWidth) { 207 if (glyph.fWidth) {
209 SkPoint tmsLoc; 208 SkPoint tmsLoc;
210 tmsProc(pos, &tmsLoc); 209 tmsProc(pos, &tmsLoc);
211 SkPoint loc; 210 SkPoint loc;
212 alignProc(tmsLoc, glyph, &loc); 211 alignProc(tmsLoc, glyph, &loc);
213 212
214 this->appendGlyph(glyph, loc); 213 this->appendGlyph(drawContext, glyph, loc);
215 } 214 }
216 pos += scalarsPerPosition; 215 pos += scalarsPerPosition;
217 } 216 }
218 217
219 this->finish(); 218 this->finish(drawContext);
220 } 219 }
221 220
222 static GrPathRange* get_gr_glyphs(GrContext* ctx, 221 static GrPathRange* get_gr_glyphs(GrContext* ctx,
223 const SkTypeface* typeface, 222 const SkTypeface* typeface,
224 const SkDescriptor* desc, 223 const SkDescriptor* desc,
225 const GrStrokeInfo& stroke) { 224 const GrStrokeInfo& stroke) {
226 225
227 static const GrUniqueKey::Domain kPathGlyphDomain = GrUniqueKey::GenerateDom ain(); 226 static const GrUniqueKey::Domain kPathGlyphDomain = GrUniqueKey::GenerateDom ain();
228 int strokeDataCount = stroke.computeUniqueKeyFragmentData32Cnt(); 227 int strokeDataCount = stroke.computeUniqueKeyFragmentData32Cnt();
229 GrUniqueKey glyphKey; 228 GrUniqueKey glyphKey;
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 } 401 }
403 inverse->preScale(1, -1); 402 inverse->preScale(1, -1);
404 } else { 403 } else {
405 inverse->setScale(1, -1); 404 inverse->setScale(1, -1);
406 const SkMatrix& unflip = *inverse; // unflip is equal to its own inverse . 405 const SkMatrix& unflip = *inverse; // unflip is equal to its own inverse .
407 fViewMatrix.preConcat(unflip); 406 fViewMatrix.preConcat(unflip);
408 } 407 }
409 return true; 408 return true;
410 } 409 }
411 410
412 inline void GrStencilAndCoverTextContext::appendGlyph(const SkGlyph& glyph, cons t SkPoint& pos) { 411 inline void GrStencilAndCoverTextContext::appendGlyph(GrDrawContext* drawContext ,
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(); 415 this->flush(drawContext);
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() { 433 void GrStencilAndCoverTextContext::flush(GrDrawContext* drawContext) {
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 GrDrawContext* drawContext = fContext->drawContext();
440 if (!drawContext) {
441 return;
442 }
443
444 drawContext->drawPaths(&fPipelineBuilder, pp, fGlyphs, 439 drawContext->drawPaths(&fPipelineBuilder, pp, fGlyphs,
445 fGlyphIndices, GrPathRange::kU16_PathIndexType, 440 fGlyphIndices, GrPathRange::kU16_PathIndexType,
446 get_xy_scalar_array(fGlyphPositions), 441 get_xy_scalar_array(fGlyphPositions),
447 GrPathRendering::kTranslate_PathTransformType, 442 GrPathRendering::kTranslate_PathTransformType,
448 fQueuedGlyphCount, GrPathRendering::kWinding_Fill Type); 443 fQueuedGlyphCount, GrPathRendering::kWinding_Fill Type);
449 444
450 fQueuedGlyphCount = 0; 445 fQueuedGlyphCount = 0;
451 } 446 }
452 447
453 if (fFallbackGlyphsIdx < kGlyphBufferSize) { 448 if (fFallbackGlyphsIdx < kGlyphBufferSize) {
(...skipping 16 matching lines...) Expand all
470 fFallbackTextContext->drawPosText(fRenderTarget, fClip, paintFallback, s kPaintFallback, 465 fFallbackTextContext->drawPosText(fRenderTarget, fClip, paintFallback, s kPaintFallback,
471 fViewMatrix, (char*)&fGlyphIndices[fFa llbackGlyphsIdx], 466 fViewMatrix, (char*)&fGlyphIndices[fFa llbackGlyphsIdx],
472 2 * fallbackGlyphCount, 467 2 * fallbackGlyphCount,
473 get_xy_scalar_array(&fGlyphPositions[f FallbackGlyphsIdx]), 468 get_xy_scalar_array(&fGlyphPositions[f FallbackGlyphsIdx]),
474 2, SkPoint::Make(0, 0), fRegionClipBou nds); 469 2, SkPoint::Make(0, 0), fRegionClipBou nds);
475 470
476 fFallbackGlyphsIdx = kGlyphBufferSize; 471 fFallbackGlyphsIdx = kGlyphBufferSize;
477 } 472 }
478 } 473 }
479 474
480 void GrStencilAndCoverTextContext::finish() { 475 void GrStencilAndCoverTextContext::finish(GrDrawContext* drawContext) {
481 this->flush(); 476 this->flush(drawContext);
482 477
483 fGlyphs->unref(); 478 fGlyphs->unref();
484 fGlyphs = NULL; 479 fGlyphs = NULL;
485 480
486 SkGlyphCache::AttachCache(fGlyphCache); 481 SkGlyphCache::AttachCache(fGlyphCache);
487 fGlyphCache = NULL; 482 fGlyphCache = NULL;
488 483
489 fPipelineBuilder.stencil()->setDisabled(); 484 fPipelineBuilder.stencil()->setDisabled();
490 fStateRestore.set(NULL); 485 fStateRestore.set(NULL);
491 fViewMatrix = fContextInitialMatrix; 486 fViewMatrix = fContextInitialMatrix;
492 } 487 }
493 488
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