OLD | NEW |
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" |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 fViewMatrix.preConcat(textMatrix); | 371 fViewMatrix.preConcat(textMatrix); |
372 fLocalMatrix = textMatrix; | 372 fLocalMatrix = textMatrix; |
373 | 373 |
374 fGlyphCache = fSkPaint.detachCache(&fSurfaceProps, NULL, true /*ignoreGa
mma*/); | 374 fGlyphCache = fSkPaint.detachCache(&fSurfaceProps, NULL, true /*ignoreGa
mma*/); |
375 fGlyphs = canUseRawPaths ? | 375 fGlyphs = canUseRawPaths ? |
376 get_gr_glyphs(fContext, fSkPaint.getTypeface(), NULL, fStr
oke) : | 376 get_gr_glyphs(fContext, fSkPaint.getTypeface(), NULL, fStr
oke) : |
377 get_gr_glyphs(fContext, fGlyphCache->getScalerContext()->g
etTypeface(), | 377 get_gr_glyphs(fContext, fGlyphCache->getScalerContext()->g
etTypeface(), |
378 &fGlyphCache->getDescriptor(), fStroke); | 378 &fGlyphCache->getDescriptor(), fStroke); |
379 } | 379 } |
380 | 380 |
381 fStateRestore.set(&fPipelineBuilder); | |
382 | |
383 fPipelineBuilder.setFromPaint(fPaint, fRenderTarget, fClip); | |
384 SkASSERT(fRenderTarget->isStencilBufferMultisampled() || !fPaint.isAntiAlias
()); | |
385 fPipelineBuilder.setState(GrPipelineBuilder::kHWAntialias_Flag, fPaint.isAnt
iAlias()); | |
386 | |
387 GR_STATIC_CONST_SAME_STENCIL(kStencilPass, | |
388 kZero_StencilOp, | |
389 kZero_StencilOp, | |
390 kNotEqual_StencilFunc, | |
391 0xffff, | |
392 0x0000, | |
393 0xffff); | |
394 | |
395 *fPipelineBuilder.stencil() = kStencilPass; | |
396 | |
397 SkASSERT(0 == fQueuedGlyphCount); | |
398 SkASSERT(kGlyphBufferSize == fFallbackGlyphsIdx); | |
399 } | 381 } |
400 | 382 |
401 bool GrStencilAndCoverTextContext::mapToFallbackContext(SkMatrix* inverse) { | 383 bool GrStencilAndCoverTextContext::mapToFallbackContext(SkMatrix* inverse) { |
402 // The current view matrix is flipped because GPU path rendering glyphs have
an | 384 // The current view matrix is flipped because GPU path rendering glyphs have
an |
403 // inverted y-direction. Unflip the view matrix for the fallback context. If
using | 385 // inverted y-direction. Unflip the view matrix for the fallback context. If
using |
404 // device-space glyphs, we'll also need to restore the original view matrix
since | 386 // device-space glyphs, we'll also need to restore the original view matrix
since |
405 // we moved that transfomation into our local glyph cache for this scenario.
Also | 387 // we moved that transfomation into our local glyph cache for this scenario.
Also |
406 // track the inverse operation so the caller can unmap the paint and glyph p
ositions. | 388 // track the inverse operation so the caller can unmap the paint and glyph p
ositions. |
407 if (fUsingDeviceSpaceGlyphs) { | 389 if (fUsingDeviceSpaceGlyphs) { |
408 fViewMatrix = fContextInitialMatrix; | 390 fViewMatrix = fContextInitialMatrix; |
(...skipping 29 matching lines...) Expand all Loading... |
438 | 420 |
439 return &pointArray[0].fX; | 421 return &pointArray[0].fX; |
440 } | 422 } |
441 | 423 |
442 void GrStencilAndCoverTextContext::flush() { | 424 void GrStencilAndCoverTextContext::flush() { |
443 if (fQueuedGlyphCount > 0) { | 425 if (fQueuedGlyphCount > 0) { |
444 SkAutoTUnref<GrPathProcessor> pp(GrPathProcessor::Create(fPaint.getColor
(), | 426 SkAutoTUnref<GrPathProcessor> pp(GrPathProcessor::Create(fPaint.getColor
(), |
445 fViewMatrix, | 427 fViewMatrix, |
446 fLocalMatrix)); | 428 fLocalMatrix)); |
447 | 429 |
448 fDrawContext->drawPaths(&fPipelineBuilder, pp, fGlyphs, | 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. |
| 432 GrPipelineBuilder pipelineBuilder(fPaint, fRenderTarget, fClip); |
| 433 SkASSERT(fRenderTarget->isStencilBufferMultisampled() || !fPaint.isAntiA
lias()); |
| 434 pipelineBuilder.setState(GrPipelineBuilder::kHWAntialias_Flag, fPaint.is
AntiAlias()); |
| 435 |
| 436 GR_STATIC_CONST_SAME_STENCIL(kStencilPass, |
| 437 kZero_StencilOp, |
| 438 kZero_StencilOp, |
| 439 kNotEqual_StencilFunc, |
| 440 0xffff, |
| 441 0x0000, |
| 442 0xffff); |
| 443 |
| 444 *pipelineBuilder.stencil() = kStencilPass; |
| 445 |
| 446 SkASSERT(0 == fQueuedGlyphCount); |
| 447 SkASSERT(kGlyphBufferSize == fFallbackGlyphsIdx); |
| 448 |
| 449 fDrawContext->drawPaths(&pipelineBuilder, pp, fGlyphs, |
449 fGlyphIndices, GrPathRange::kU16_PathIndexType, | 450 fGlyphIndices, GrPathRange::kU16_PathIndexType, |
450 get_xy_scalar_array(fGlyphPositions), | 451 get_xy_scalar_array(fGlyphPositions), |
451 GrPathRendering::kTranslate_PathTransformType, | 452 GrPathRendering::kTranslate_PathTransformType, |
452 fQueuedGlyphCount, GrPathRendering::kWinding_Fil
lType); | 453 fQueuedGlyphCount, GrPathRendering::kWinding_Fil
lType); |
453 | 454 |
454 fQueuedGlyphCount = 0; | 455 fQueuedGlyphCount = 0; |
455 } | 456 } |
456 | 457 |
457 if (fFallbackGlyphsIdx < kGlyphBufferSize) { | 458 if (fFallbackGlyphsIdx < kGlyphBufferSize) { |
458 int fallbackGlyphCount = kGlyphBufferSize - fFallbackGlyphsIdx; | 459 int fallbackGlyphCount = kGlyphBufferSize - fFallbackGlyphsIdx; |
(...skipping 24 matching lines...) Expand all Loading... |
483 | 484 |
484 void GrStencilAndCoverTextContext::finish() { | 485 void GrStencilAndCoverTextContext::finish() { |
485 this->flush(); | 486 this->flush(); |
486 | 487 |
487 fGlyphs->unref(); | 488 fGlyphs->unref(); |
488 fGlyphs = NULL; | 489 fGlyphs = NULL; |
489 | 490 |
490 SkGlyphCache::AttachCache(fGlyphCache); | 491 SkGlyphCache::AttachCache(fGlyphCache); |
491 fGlyphCache = NULL; | 492 fGlyphCache = NULL; |
492 | 493 |
493 fPipelineBuilder.stencil()->setDisabled(); | |
494 fStateRestore.set(NULL); | |
495 fViewMatrix = fContextInitialMatrix; | 494 fViewMatrix = fContextInitialMatrix; |
496 } | 495 } |
497 | 496 |
OLD | NEW |