| 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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 fContextInitialMatrix.mapXY(x, y, &loc); | 148 fContextInitialMatrix.mapXY(x, y, &loc); |
| 149 x = loc.fX; | 149 x = loc.fX; |
| 150 y = loc.fY; | 150 y = loc.fY; |
| 151 glyphCacheTransform = &fContextInitialMatrix; | 151 glyphCacheTransform = &fContextInitialMatrix; |
| 152 } | 152 } |
| 153 | 153 |
| 154 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); | 154 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); |
| 155 SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, glyphCacheTransform
); | 155 SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, glyphCacheTransform
); |
| 156 fGlyphCache = autoCache.getCache(); | 156 fGlyphCache = autoCache.getCache(); |
| 157 fGlyphs = GlyphPathRange::Create(fContext, fGlyphCache, fStroke); | 157 fGlyphs = GlyphPathRange::Create(fContext, fGlyphCache, fStroke); |
| 158 fTransformType = GrDrawTarget::kTranslate_PathTransformType; | 158 fTransformType = GrPathRendering::kTranslate_PathTransformType; |
| 159 | 159 |
| 160 const char* stop = text + byteLength; | 160 const char* stop = text + byteLength; |
| 161 | 161 |
| 162 // Measure first if needed. | 162 // Measure first if needed. |
| 163 if (fSkPaint.getTextAlign() != SkPaint::kLeft_Align) { | 163 if (fSkPaint.getTextAlign() != SkPaint::kLeft_Align) { |
| 164 SkFixed stopX = 0; | 164 SkFixed stopX = 0; |
| 165 SkFixed stopY = 0; | 165 SkFixed stopY = 0; |
| 166 | 166 |
| 167 const char* textPtr = text; | 167 const char* textPtr = text; |
| 168 while (textPtr < stop) { | 168 while (textPtr < stop) { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); | 236 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); |
| 237 | 237 |
| 238 SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, NULL); | 238 SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, NULL); |
| 239 fGlyphCache = autoCache.getCache(); | 239 fGlyphCache = autoCache.getCache(); |
| 240 fGlyphs = GlyphPathRange::Create(fContext, fGlyphCache, fStroke); | 240 fGlyphs = GlyphPathRange::Create(fContext, fGlyphCache, fStroke); |
| 241 | 241 |
| 242 const char* stop = text + byteLength; | 242 const char* stop = text + byteLength; |
| 243 | 243 |
| 244 if (SkPaint::kLeft_Align == fSkPaint.getTextAlign()) { | 244 if (SkPaint::kLeft_Align == fSkPaint.getTextAlign()) { |
| 245 if (1 == scalarsPerPosition) { | 245 if (1 == scalarsPerPosition) { |
| 246 fTransformType = GrDrawTarget::kTranslateX_PathTransformType; | 246 fTransformType = GrPathRendering::kTranslateX_PathTransformType; |
| 247 while (text < stop) { | 247 while (text < stop) { |
| 248 const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &text, 0, 0); | 248 const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &text, 0, 0); |
| 249 if (glyph.fWidth) { | 249 if (glyph.fWidth) { |
| 250 this->appendGlyph(glyph.getGlyphID(), *pos); | 250 this->appendGlyph(glyph.getGlyphID(), *pos); |
| 251 } | 251 } |
| 252 pos++; | 252 pos++; |
| 253 } | 253 } |
| 254 } else { | 254 } else { |
| 255 SkASSERT(2 == scalarsPerPosition); | 255 SkASSERT(2 == scalarsPerPosition); |
| 256 fTransformType = GrDrawTarget::kTranslate_PathTransformType; | 256 fTransformType = GrPathRendering::kTranslate_PathTransformType; |
| 257 while (text < stop) { | 257 while (text < stop) { |
| 258 const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &text, 0, 0); | 258 const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &text, 0, 0); |
| 259 if (glyph.fWidth) { | 259 if (glyph.fWidth) { |
| 260 this->appendGlyph(glyph.getGlyphID(), pos[0], pos[1]); | 260 this->appendGlyph(glyph.getGlyphID(), pos[0], pos[1]); |
| 261 } | 261 } |
| 262 pos += 2; | 262 pos += 2; |
| 263 } | 263 } |
| 264 } | 264 } |
| 265 } else { | 265 } else { |
| 266 fTransformType = GrDrawTarget::kTranslate_PathTransformType; | 266 fTransformType = GrPathRendering::kTranslate_PathTransformType; |
| 267 SkTextMapStateProc tmsProc(SkMatrix::I(), 0, scalarsPerPosition); | 267 SkTextMapStateProc tmsProc(SkMatrix::I(), 0, scalarsPerPosition); |
| 268 SkTextAlignProcScalar alignProc(fSkPaint.getTextAlign()); | 268 SkTextAlignProcScalar alignProc(fSkPaint.getTextAlign()); |
| 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 SkPoint tmsLoc; | 272 SkPoint tmsLoc; |
| 273 tmsProc(pos, &tmsLoc); | 273 tmsProc(pos, &tmsLoc); |
| 274 SkPoint loc; | 274 SkPoint loc; |
| 275 alignProc(tmsLoc, glyph, &loc); | 275 alignProc(tmsLoc, glyph, &loc); |
| 276 | 276 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 0xffff, | 389 0xffff, |
| 390 0x0000, | 390 0x0000, |
| 391 0xffff); | 391 0xffff); |
| 392 | 392 |
| 393 *fDrawTarget->drawState()->stencil() = kStencilPass; | 393 *fDrawTarget->drawState()->stencil() = kStencilPass; |
| 394 | 394 |
| 395 SkASSERT(0 == fPendingGlyphCount); | 395 SkASSERT(0 == fPendingGlyphCount); |
| 396 } | 396 } |
| 397 | 397 |
| 398 inline void GrStencilAndCoverTextContext::appendGlyph(uint16_t glyphID, float x)
{ | 398 inline void GrStencilAndCoverTextContext::appendGlyph(uint16_t glyphID, float x)
{ |
| 399 SkASSERT(GrDrawTarget::kTranslateX_PathTransformType == fTransformType); | 399 SkASSERT(GrPathRendering::kTranslateX_PathTransformType == fTransformType); |
| 400 | 400 |
| 401 if (fPendingGlyphCount >= kGlyphBufferSize) { | 401 if (fPendingGlyphCount >= kGlyphBufferSize) { |
| 402 this->flush(); | 402 this->flush(); |
| 403 } | 403 } |
| 404 | 404 |
| 405 fGlyphs->preloadGlyph(glyphID, fGlyphCache); | 405 fGlyphs->preloadGlyph(glyphID, fGlyphCache); |
| 406 | 406 |
| 407 fIndexBuffer[fPendingGlyphCount] = glyphID; | 407 fIndexBuffer[fPendingGlyphCount] = glyphID; |
| 408 fTransformBuffer[fPendingGlyphCount] = fTextInverseRatio * x; | 408 fTransformBuffer[fPendingGlyphCount] = fTextInverseRatio * x; |
| 409 | 409 |
| 410 ++fPendingGlyphCount; | 410 ++fPendingGlyphCount; |
| 411 } | 411 } |
| 412 | 412 |
| 413 inline void GrStencilAndCoverTextContext::appendGlyph(uint16_t glyphID, float x,
float y) { | 413 inline void GrStencilAndCoverTextContext::appendGlyph(uint16_t glyphID, float x,
float y) { |
| 414 SkASSERT(GrDrawTarget::kTranslate_PathTransformType == fTransformType); | 414 SkASSERT(GrPathRendering::kTranslate_PathTransformType == fTransformType); |
| 415 | 415 |
| 416 if (fPendingGlyphCount >= kGlyphBufferSize) { | 416 if (fPendingGlyphCount >= kGlyphBufferSize) { |
| 417 this->flush(); | 417 this->flush(); |
| 418 } | 418 } |
| 419 | 419 |
| 420 fGlyphs->preloadGlyph(glyphID, fGlyphCache); | 420 fGlyphs->preloadGlyph(glyphID, fGlyphCache); |
| 421 | 421 |
| 422 fIndexBuffer[fPendingGlyphCount] = glyphID; | 422 fIndexBuffer[fPendingGlyphCount] = glyphID; |
| 423 fTransformBuffer[2 * fPendingGlyphCount] = fTextInverseRatio * x; | 423 fTransformBuffer[2 * fPendingGlyphCount] = fTextInverseRatio * x; |
| 424 fTransformBuffer[2 * fPendingGlyphCount + 1] = fTextInverseRatio * y; | 424 fTransformBuffer[2 * fPendingGlyphCount + 1] = fTextInverseRatio * y; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 443 SkSafeUnref(fGlyphs); | 443 SkSafeUnref(fGlyphs); |
| 444 fGlyphs = NULL; | 444 fGlyphs = NULL; |
| 445 fGlyphCache = NULL; | 445 fGlyphCache = NULL; |
| 446 | 446 |
| 447 fDrawTarget->drawState()->stencil()->setDisabled(); | 447 fDrawTarget->drawState()->stencil()->setDisabled(); |
| 448 fStateRestore.set(NULL); | 448 fStateRestore.set(NULL); |
| 449 fContext->setMatrix(fContextInitialMatrix); | 449 fContext->setMatrix(fContextInitialMatrix); |
| 450 GrTextContext::finish(); | 450 GrTextContext::finish(); |
| 451 } | 451 } |
| 452 | 452 |
| OLD | NEW |