| 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 "GrDrawTarget.h" | 9 #include "GrDrawTarget.h" |
| 10 #include "GrGpu.h" | 10 #include "GrGpu.h" |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 fContextInitialMatrix.mapXY(x, y, &loc); | 160 fContextInitialMatrix.mapXY(x, y, &loc); |
| 161 x = loc.fX; | 161 x = loc.fX; |
| 162 y = loc.fY; | 162 y = loc.fY; |
| 163 glyphCacheTransform = &fContextInitialMatrix; | 163 glyphCacheTransform = &fContextInitialMatrix; |
| 164 } | 164 } |
| 165 | 165 |
| 166 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); | 166 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); |
| 167 SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, glyphCacheTransform
); | 167 SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, glyphCacheTransform
); |
| 168 fGlyphCache = autoCache.getCache(); | 168 fGlyphCache = autoCache.getCache(); |
| 169 fGlyphs = GlyphPathRange::Create(fContext, fGlyphCache, fStroke); | 169 fGlyphs = GlyphPathRange::Create(fContext, fGlyphCache, fStroke); |
| 170 fTransformType = GrDrawTarget::kTranslate_PathTransformType; | 170 fTransformType = GrPathRendering::kTranslate_PathTransformType; |
| 171 | 171 |
| 172 const char* stop = text + byteLength; | 172 const char* stop = text + byteLength; |
| 173 | 173 |
| 174 // Measure first if needed. | 174 // Measure first if needed. |
| 175 if (fSkPaint.getTextAlign() != SkPaint::kLeft_Align) { | 175 if (fSkPaint.getTextAlign() != SkPaint::kLeft_Align) { |
| 176 SkFixed stopX = 0; | 176 SkFixed stopX = 0; |
| 177 SkFixed stopY = 0; | 177 SkFixed stopY = 0; |
| 178 | 178 |
| 179 const char* textPtr = text; | 179 const char* textPtr = text; |
| 180 while (textPtr < stop) { | 180 while (textPtr < stop) { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); | 248 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); |
| 249 | 249 |
| 250 SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, NULL); | 250 SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, NULL); |
| 251 fGlyphCache = autoCache.getCache(); | 251 fGlyphCache = autoCache.getCache(); |
| 252 fGlyphs = GlyphPathRange::Create(fContext, fGlyphCache, fStroke); | 252 fGlyphs = GlyphPathRange::Create(fContext, fGlyphCache, fStroke); |
| 253 | 253 |
| 254 const char* stop = text + byteLength; | 254 const char* stop = text + byteLength; |
| 255 | 255 |
| 256 if (SkPaint::kLeft_Align == fSkPaint.getTextAlign()) { | 256 if (SkPaint::kLeft_Align == fSkPaint.getTextAlign()) { |
| 257 if (1 == scalarsPerPosition) { | 257 if (1 == scalarsPerPosition) { |
| 258 fTransformType = GrDrawTarget::kTranslateX_PathTransformType; | 258 fTransformType = GrPathRendering::kTranslateX_PathTransformType; |
| 259 while (text < stop) { | 259 while (text < stop) { |
| 260 const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &text, 0, 0); | 260 const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &text, 0, 0); |
| 261 if (glyph.fWidth) { | 261 if (glyph.fWidth) { |
| 262 this->appendGlyph(glyph.getGlyphID(), *pos); | 262 this->appendGlyph(glyph.getGlyphID(), *pos); |
| 263 } | 263 } |
| 264 pos++; | 264 pos++; |
| 265 } | 265 } |
| 266 } else { | 266 } else { |
| 267 SkASSERT(2 == scalarsPerPosition); | 267 SkASSERT(2 == scalarsPerPosition); |
| 268 fTransformType = GrDrawTarget::kTranslate_PathTransformType; | 268 fTransformType = GrPathRendering::kTranslate_PathTransformType; |
| 269 while (text < stop) { | 269 while (text < stop) { |
| 270 const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &text, 0, 0); | 270 const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &text, 0, 0); |
| 271 if (glyph.fWidth) { | 271 if (glyph.fWidth) { |
| 272 this->appendGlyph(glyph.getGlyphID(), pos[0], pos[1]); | 272 this->appendGlyph(glyph.getGlyphID(), pos[0], pos[1]); |
| 273 } | 273 } |
| 274 pos += 2; | 274 pos += 2; |
| 275 } | 275 } |
| 276 } | 276 } |
| 277 } else { | 277 } else { |
| 278 fTransformType = GrDrawTarget::kTranslate_PathTransformType; | 278 fTransformType = GrPathRendering::kTranslate_PathTransformType; |
| 279 SkTextMapStateProc tmsProc(SkMatrix::I(), 0, scalarsPerPosition); | 279 SkTextMapStateProc tmsProc(SkMatrix::I(), 0, scalarsPerPosition); |
| 280 SkTextAlignProcScalar alignProc(fSkPaint.getTextAlign()); | 280 SkTextAlignProcScalar alignProc(fSkPaint.getTextAlign()); |
| 281 while (text < stop) { | 281 while (text < stop) { |
| 282 const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &text, 0, 0); | 282 const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &text, 0, 0); |
| 283 if (glyph.fWidth) { | 283 if (glyph.fWidth) { |
| 284 SkPoint tmsLoc; | 284 SkPoint tmsLoc; |
| 285 tmsProc(pos, &tmsLoc); | 285 tmsProc(pos, &tmsLoc); |
| 286 SkPoint loc; | 286 SkPoint loc; |
| 287 alignProc(tmsLoc, glyph, &loc); | 287 alignProc(tmsLoc, glyph, &loc); |
| 288 | 288 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 0xffff, | 401 0xffff, |
| 402 0x0000, | 402 0x0000, |
| 403 0xffff); | 403 0xffff); |
| 404 | 404 |
| 405 *fDrawTarget->drawState()->stencil() = kStencilPass; | 405 *fDrawTarget->drawState()->stencil() = kStencilPass; |
| 406 | 406 |
| 407 SkASSERT(0 == fPendingGlyphCount); | 407 SkASSERT(0 == fPendingGlyphCount); |
| 408 } | 408 } |
| 409 | 409 |
| 410 inline void GrStencilAndCoverTextContext::appendGlyph(uint16_t glyphID, float x)
{ | 410 inline void GrStencilAndCoverTextContext::appendGlyph(uint16_t glyphID, float x)
{ |
| 411 SkASSERT(GrDrawTarget::kTranslateX_PathTransformType == fTransformType); | 411 SkASSERT(GrPathRendering::kTranslateX_PathTransformType == fTransformType); |
| 412 | 412 |
| 413 if (fPendingGlyphCount >= kGlyphBufferSize) { | 413 if (fPendingGlyphCount >= kGlyphBufferSize) { |
| 414 this->flush(); | 414 this->flush(); |
| 415 } | 415 } |
| 416 | 416 |
| 417 fGlyphs->preloadGlyph(glyphID, fGlyphCache); | 417 fGlyphs->preloadGlyph(glyphID, fGlyphCache); |
| 418 | 418 |
| 419 fIndexBuffer[fPendingGlyphCount] = glyphID; | 419 fIndexBuffer[fPendingGlyphCount] = glyphID; |
| 420 fTransformBuffer[fPendingGlyphCount] = fTextInverseRatio * x; | 420 fTransformBuffer[fPendingGlyphCount] = fTextInverseRatio * x; |
| 421 | 421 |
| 422 ++fPendingGlyphCount; | 422 ++fPendingGlyphCount; |
| 423 } | 423 } |
| 424 | 424 |
| 425 inline void GrStencilAndCoverTextContext::appendGlyph(uint16_t glyphID, float x,
float y) { | 425 inline void GrStencilAndCoverTextContext::appendGlyph(uint16_t glyphID, float x,
float y) { |
| 426 SkASSERT(GrDrawTarget::kTranslate_PathTransformType == fTransformType); | 426 SkASSERT(GrPathRendering::kTranslate_PathTransformType == fTransformType); |
| 427 | 427 |
| 428 if (fPendingGlyphCount >= kGlyphBufferSize) { | 428 if (fPendingGlyphCount >= kGlyphBufferSize) { |
| 429 this->flush(); | 429 this->flush(); |
| 430 } | 430 } |
| 431 | 431 |
| 432 fGlyphs->preloadGlyph(glyphID, fGlyphCache); | 432 fGlyphs->preloadGlyph(glyphID, fGlyphCache); |
| 433 | 433 |
| 434 fIndexBuffer[fPendingGlyphCount] = glyphID; | 434 fIndexBuffer[fPendingGlyphCount] = glyphID; |
| 435 fTransformBuffer[2 * fPendingGlyphCount] = fTextInverseRatio * x; | 435 fTransformBuffer[2 * fPendingGlyphCount] = fTextInverseRatio * x; |
| 436 fTransformBuffer[2 * fPendingGlyphCount + 1] = fTextInverseRatio * y; | 436 fTransformBuffer[2 * fPendingGlyphCount + 1] = fTextInverseRatio * y; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 455 SkSafeUnref(fGlyphs); | 455 SkSafeUnref(fGlyphs); |
| 456 fGlyphs = NULL; | 456 fGlyphs = NULL; |
| 457 fGlyphCache = NULL; | 457 fGlyphCache = NULL; |
| 458 | 458 |
| 459 fDrawTarget->drawState()->stencil()->setDisabled(); | 459 fDrawTarget->drawState()->stencil()->setDisabled(); |
| 460 fStateRestore.set(NULL); | 460 fStateRestore.set(NULL); |
| 461 fContext->setMatrix(fContextInitialMatrix); | 461 fContext->setMatrix(fContextInitialMatrix); |
| 462 GrTextContext::finish(); | 462 GrTextContext::finish(); |
| 463 } | 463 } |
| 464 | 464 |
| OLD | NEW |