OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "GrBitmapTextContext.h" | 8 #include "GrBitmapTextContext.h" |
9 #include "GrAtlas.h" | 9 #include "GrAtlas.h" |
10 #include "GrDefaultGeoProcFactory.h" | 10 #include "GrDefaultGeoProcFactory.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "SkStrokeRec.h" | 28 #include "SkStrokeRec.h" |
29 #include "SkTextMapStateProc.h" | 29 #include "SkTextMapStateProc.h" |
30 | 30 |
31 #include "effects/GrCustomCoordsTextureEffect.h" | 31 #include "effects/GrCustomCoordsTextureEffect.h" |
32 #include "effects/GrSimpleTextureEffect.h" | 32 #include "effects/GrSimpleTextureEffect.h" |
33 | 33 |
34 SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false, | 34 SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false, |
35 "Dump the contents of the font cache before every purge."); | 35 "Dump the contents of the font cache before every purge."); |
36 | 36 |
37 namespace { | 37 namespace { |
38 // position + texture coord | |
39 extern const GrVertexAttrib gLCDVertexAttribs[] = { | |
40 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding
}, | |
41 {kVec2f_GrVertexAttribType, sizeof(SkPoint), kGeometryProcessor_GrVertexAttr
ibBinding} | |
42 }; | |
43 | |
44 static const size_t kLCDTextVASize = 2 * sizeof(SkPoint); | 38 static const size_t kLCDTextVASize = 2 * sizeof(SkPoint); |
45 | 39 |
46 // position + local coord | 40 // position + local coord |
47 static const size_t kColorTextVASize = 2 * sizeof(SkPoint); | 41 static const size_t kColorTextVASize = 2 * sizeof(SkPoint); |
48 | 42 |
49 // position + color + texture coord | |
50 extern const GrVertexAttrib gGrayVertexAttribs[] = { | |
51 {kVec2f_GrVertexAttribType, 0, kPosition_Gr
VertexAttribBinding}, | |
52 {kVec4ub_GrVertexAttribType, sizeof(SkPoint), kColor_GrVer
texAttribBinding}, | |
53 {kVec2f_GrVertexAttribType, sizeof(SkPoint) + sizeof(GrColor), kGeometryPro
cessor_GrVertexAttribBinding} | |
54 }; | |
55 | |
56 static const size_t kGrayTextVASize = 2 * sizeof(SkPoint) + sizeof(GrColor); | 43 static const size_t kGrayTextVASize = 2 * sizeof(SkPoint) + sizeof(GrColor); |
57 | 44 |
58 static const int kVerticesPerGlyph = 4; | 45 static const int kVerticesPerGlyph = 4; |
59 static const int kIndicesPerGlyph = 6; | 46 static const int kIndicesPerGlyph = 6; |
60 }; | 47 }; |
61 | 48 |
62 GrBitmapTextContext::GrBitmapTextContext(GrContext* context, | 49 GrBitmapTextContext::GrBitmapTextContext(GrContext* context, |
63 const SkDeviceProperties& properties) | 50 const SkDeviceProperties& properties) |
64 : GrTextContext(context, properties) { | 51 : GrTextContext(context, properties) { |
65 fStrike = NULL; | 52 fStrike = NULL; |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 switch (maskFormat) { | 334 switch (maskFormat) { |
348 case kA8_GrMaskFormat: | 335 case kA8_GrMaskFormat: |
349 return kGrayTextVASize; | 336 return kGrayTextVASize; |
350 case kARGB_GrMaskFormat: | 337 case kARGB_GrMaskFormat: |
351 return kColorTextVASize; | 338 return kColorTextVASize; |
352 default: | 339 default: |
353 return kLCDTextVASize; | 340 return kLCDTextVASize; |
354 } | 341 } |
355 } | 342 } |
356 | 343 |
357 static void set_vertex_attributes(GrDrawState* drawState, GrMaskFormat maskForma
t) { | |
358 if (kA8_GrMaskFormat == maskFormat) { | |
359 drawState->setVertexAttribs<gGrayVertexAttribs>( | |
360 SK_ARRAY_COUNT(gGrayVertexAttribs), kGrayTex
tVASize); | |
361 } else if (kARGB_GrMaskFormat == maskFormat) { | |
362 GrDefaultGeoProcFactory::SetAttribs(drawState, | |
363 GrDefaultGeoProcFactory::kLocalCoord
_GPType); | |
364 } else { | |
365 drawState->setVertexAttribs<gLCDVertexAttribs>( | |
366 SK_ARRAY_COUNT(gLCDVertexAttribs), kLCDTextV
ASize); | |
367 } | |
368 } | |
369 | |
370 static void* alloc_vertices(GrDrawTarget* drawTarget, | 344 static void* alloc_vertices(GrDrawTarget* drawTarget, |
371 int numVertices, | 345 int numVertices, |
372 GrMaskFormat maskFormat) { | 346 GrMaskFormat maskFormat) { |
373 if (numVertices <= 0) { | 347 if (numVertices <= 0) { |
374 return NULL; | 348 return NULL; |
375 } | 349 } |
376 | 350 |
377 // set up attributes | 351 // set up attributes |
378 void* vertices = NULL; | 352 void* vertices = NULL; |
379 bool success = drawTarget->reserveVertexAndIndexSpace(numVertices, | 353 bool success = drawTarget->reserveVertexAndIndexSpace(numVertices, |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 | 519 |
546 void GrBitmapTextContext::flush() { | 520 void GrBitmapTextContext::flush() { |
547 if (NULL == fDrawTarget) { | 521 if (NULL == fDrawTarget) { |
548 return; | 522 return; |
549 } | 523 } |
550 | 524 |
551 if (fCurrVertex > 0) { | 525 if (fCurrVertex > 0) { |
552 GrDrawState drawState; | 526 GrDrawState drawState; |
553 drawState.setFromPaint(fPaint, SkMatrix::I(), fContext->getRenderTarget(
)); | 527 drawState.setFromPaint(fPaint, SkMatrix::I(), fContext->getRenderTarget(
)); |
554 | 528 |
555 set_vertex_attributes(&drawState, fCurrMaskFormat); | |
556 | |
557 // setup our sampler state for our text texture/atlas | 529 // setup our sampler state for our text texture/atlas |
558 SkASSERT(SkIsAlign4(fCurrVertex)); | 530 SkASSERT(SkIsAlign4(fCurrVertex)); |
559 SkASSERT(fCurrTexture); | 531 SkASSERT(fCurrTexture); |
560 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kNon
e_FilterMode); | |
561 | 532 |
562 // This effect could be stored with one of the cache objects (atlas?) | 533 // This effect could be stored with one of the cache objects (atlas?) |
| 534 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kNon
e_FilterMode); |
563 if (kARGB_GrMaskFormat == fCurrMaskFormat) { | 535 if (kARGB_GrMaskFormat == fCurrMaskFormat) { |
564 drawState.setGeometryProcessor(GrDefaultGeoProcFactory::Create(true)
)->unref(); | 536 uint32_t flags = GrDefaultGeoProcFactory::kLocalCoord_GPType; |
| 537 drawState.setGeometryProcessor(GrDefaultGeoProcFactory::Create(flags
))->unref(); |
565 GrFragmentProcessor* fragProcessor = GrSimpleTextureEffect::Create(f
CurrTexture, | 538 GrFragmentProcessor* fragProcessor = GrSimpleTextureEffect::Create(f
CurrTexture, |
566 S
kMatrix::I(), | 539 S
kMatrix::I(), |
567 p
arams); | 540 p
arams); |
568 drawState.addColorProcessor(fragProcessor)->unref(); | 541 drawState.addColorProcessor(fragProcessor)->unref(); |
569 } else { | 542 } else { |
570 uint32_t textureUniqueID = fCurrTexture->getUniqueID(); | 543 uint32_t textureUniqueID = fCurrTexture->getUniqueID(); |
571 if (textureUniqueID != fEffectTextureUniqueID) { | 544 if (textureUniqueID != fEffectTextureUniqueID) { |
| 545 bool hasColor = kA8_GrMaskFormat == fCurrMaskFormat; |
572 fCachedGeometryProcessor.reset(GrCustomCoordsTextureEffect::Crea
te(fCurrTexture, | 546 fCachedGeometryProcessor.reset(GrCustomCoordsTextureEffect::Crea
te(fCurrTexture, |
573
params)); | 547
params, |
| 548
hasColor)); |
574 fEffectTextureUniqueID = textureUniqueID; | 549 fEffectTextureUniqueID = textureUniqueID; |
575 } | 550 } |
576 | |
577 drawState.setGeometryProcessor(fCachedGeometryProcessor.get()); | 551 drawState.setGeometryProcessor(fCachedGeometryProcessor.get()); |
578 } | 552 } |
579 | 553 |
580 SkASSERT(fStrike); | 554 SkASSERT(fStrike); |
581 switch (fCurrMaskFormat) { | 555 switch (fCurrMaskFormat) { |
582 // Color bitmap text | 556 // Color bitmap text |
583 case kARGB_GrMaskFormat: | 557 case kARGB_GrMaskFormat: |
584 SkASSERT(!drawState.hasColorVertexAttribute()); | 558 SkASSERT(!drawState.hasColorVertexAttribute()); |
585 drawState.setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDstB
lendCoeff()); | 559 drawState.setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDstB
lendCoeff()); |
586 drawState.setAlpha(fSkPaint.getAlpha()); | 560 drawState.setAlpha(fSkPaint.getAlpha()); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 } | 611 } |
638 } | 612 } |
639 | 613 |
640 inline void GrBitmapTextContext::finish() { | 614 inline void GrBitmapTextContext::finish() { |
641 this->flush(); | 615 this->flush(); |
642 fTotalVertexCount = 0; | 616 fTotalVertexCount = 0; |
643 | 617 |
644 GrTextContext::finish(); | 618 GrTextContext::finish(); |
645 } | 619 } |
646 | 620 |
OLD | NEW |