| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 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 "GrTextContext.h" | 8 #include "GrTextContext.h" |
| 9 #include "GrContext.h" | 9 #include "GrContext.h" |
| 10 #include "GrDrawTarget.h" | 10 #include "GrDrawTarget.h" |
| 11 #include "GrFontScaler.h" | 11 #include "GrFontScaler.h" |
| 12 | 12 |
| 13 #include "SkAutoKern.h" | 13 #include "SkAutoKern.h" |
| 14 #include "SkDrawFilter.h" | 14 #include "SkDrawFilter.h" |
| 15 #include "SkDrawProcs.h" | 15 #include "SkDrawProcs.h" |
| 16 #include "SkGlyphCache.h" | 16 #include "SkGlyphCache.h" |
| 17 #include "SkGpuDevice.h" | 17 #include "SkGpuDevice.h" |
| 18 #include "SkTextBlob.h" | 18 #include "SkTextBlob.h" |
| 19 #include "SkTextMapStateProc.h" | 19 #include "SkTextMapStateProc.h" |
| 20 #include "SkTextToPathIter.h" | 20 #include "SkTextToPathIter.h" |
| 21 | 21 |
| 22 GrTextContext::GrTextContext(GrContext* context, SkGpuDevice* gpuDevice, | 22 GrTextContext::GrTextContext(GrContext* context, SkGpuDevice* gpuDevice, |
| 23 const SkDeviceProperties& properties) | 23 const SkDeviceProperties& properties) |
| 24 : fFallbackTextContext(NULL) | 24 : fFallbackTextContext(NULL) |
| 25 , fContext(context) | 25 , fContext(context) |
| 26 , fGpuDevice(gpuDevice) | 26 , fGpuDevice(gpuDevice) |
| 27 , fDeviceProperties(properties) | 27 , fDeviceProperties(properties) { |
| 28 , fDrawTarget(NULL) { | |
| 29 } | 28 } |
| 30 | 29 |
| 31 GrTextContext::~GrTextContext() { | 30 GrTextContext::~GrTextContext() { |
| 32 SkDELETE(fFallbackTextContext); | 31 SkDELETE(fFallbackTextContext); |
| 33 } | 32 } |
| 34 | 33 |
| 35 void GrTextContext::init(GrRenderTarget* rt, const GrClip& clip, const GrPaint&
grPaint, | 34 void GrTextContext::init(GrRenderTarget* rt, const GrClip& clip, const GrPaint&
grPaint, |
| 36 const SkPaint& skPaint, const SkIRect& regionClipBounds
) { | 35 const SkPaint& skPaint, const SkIRect& regionClipBounds
) { |
| 37 fClip = clip; | 36 fClip = clip; |
| 38 | 37 |
| 39 fRenderTarget.reset(SkRef(rt)); | 38 fRenderTarget.reset(SkRef(rt)); |
| 40 | 39 |
| 41 fRegionClipBounds = regionClipBounds; | 40 fRegionClipBounds = regionClipBounds; |
| 42 fClip.getConservativeBounds(fRenderTarget->width(), fRenderTarget->height(),
&fClipRect); | 41 fClip.getConservativeBounds(fRenderTarget->width(), fRenderTarget->height(),
&fClipRect); |
| 43 | 42 |
| 44 fDrawTarget = fContext->getTextTarget(); | |
| 45 | |
| 46 fPaint = grPaint; | 43 fPaint = grPaint; |
| 47 fSkPaint = skPaint; | 44 fSkPaint = skPaint; |
| 48 } | 45 } |
| 49 | 46 |
| 50 void GrTextContext::drawText(GrRenderTarget* rt, const GrClip& clip, const GrPai
nt& paint, | 47 void GrTextContext::drawText(GrRenderTarget* rt, const GrClip& clip, const GrPai
nt& paint, |
| 51 const SkPaint& skPaint, const SkMatrix& viewMatrix, | 48 const SkPaint& skPaint, const SkMatrix& viewMatrix, |
| 52 const char text[], size_t byteLength, | 49 const char text[], size_t byteLength, |
| 53 SkScalar x, SkScalar y, const SkIRect& clipBounds)
{ | 50 SkScalar x, SkScalar y, const SkIRect& clipBounds)
{ |
| 54 if (!fContext->getTextTarget()) { | 51 if (fContext->abandoned()) { |
| 55 return; | 52 return; |
| 56 } | 53 } |
| 57 | 54 |
| 58 GrTextContext* textContext = this; | 55 GrTextContext* textContext = this; |
| 59 do { | 56 do { |
| 60 if (textContext->canDraw(rt, clip, paint, skPaint, viewMatrix)) { | 57 if (textContext->canDraw(rt, clip, paint, skPaint, viewMatrix)) { |
| 61 textContext->onDrawText(rt, clip, paint, skPaint, viewMatrix, text,
byteLength, x, y, | 58 textContext->onDrawText(rt, clip, paint, skPaint, viewMatrix, text,
byteLength, x, y, |
| 62 clipBounds); | 59 clipBounds); |
| 63 return; | 60 return; |
| 64 } | 61 } |
| 65 textContext = textContext->fFallbackTextContext; | 62 textContext = textContext->fFallbackTextContext; |
| 66 } while (textContext); | 63 } while (textContext); |
| 67 | 64 |
| 68 // fall back to drawing as a path | 65 // fall back to drawing as a path |
| 69 SkASSERT(fGpuDevice); | 66 SkASSERT(fGpuDevice); |
| 70 this->drawTextAsPath(skPaint, viewMatrix, text, byteLength, x, y, clipBounds
); | 67 this->drawTextAsPath(skPaint, viewMatrix, text, byteLength, x, y, clipBounds
); |
| 71 } | 68 } |
| 72 | 69 |
| 73 void GrTextContext::drawPosText(GrRenderTarget* rt, const GrClip& clip, const Gr
Paint& paint, | 70 void GrTextContext::drawPosText(GrRenderTarget* rt, const GrClip& clip, const Gr
Paint& paint, |
| 74 const SkPaint& skPaint, const SkMatrix& viewMatr
ix, | 71 const SkPaint& skPaint, const SkMatrix& viewMatr
ix, |
| 75 const char text[], size_t byteLength, | 72 const char text[], size_t byteLength, |
| 76 const SkScalar pos[], int scalarsPerPosition, | 73 const SkScalar pos[], int scalarsPerPosition, |
| 77 const SkPoint& offset, const SkIRect& clipBounds
) { | 74 const SkPoint& offset, const SkIRect& clipBounds
) { |
| 78 if (!fContext->getTextTarget()) { | 75 if (fContext->abandoned()) { |
| 79 return; | 76 return; |
| 80 } | 77 } |
| 81 | 78 |
| 82 GrTextContext* textContext = this; | 79 GrTextContext* textContext = this; |
| 83 do { | 80 do { |
| 84 if (textContext->canDraw(rt, clip, paint, skPaint, viewMatrix)) { | 81 if (textContext->canDraw(rt, clip, paint, skPaint, viewMatrix)) { |
| 85 textContext->onDrawPosText(rt, clip, paint, skPaint, viewMatrix, tex
t, byteLength, pos, | 82 textContext->onDrawPosText(rt, clip, paint, skPaint, viewMatrix, tex
t, byteLength, pos, |
| 86 scalarsPerPosition, offset, clipBounds); | 83 scalarsPerPosition, offset, clipBounds); |
| 87 return; | 84 return; |
| 88 } | 85 } |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 if (cache->getAuxProcData(GlyphCacheAuxProc, &auxData)) { | 248 if (cache->getAuxProcData(GlyphCacheAuxProc, &auxData)) { |
| 252 scaler = (GrFontScaler*)auxData; | 249 scaler = (GrFontScaler*)auxData; |
| 253 } | 250 } |
| 254 if (NULL == scaler) { | 251 if (NULL == scaler) { |
| 255 scaler = SkNEW_ARGS(GrFontScaler, (cache)); | 252 scaler = SkNEW_ARGS(GrFontScaler, (cache)); |
| 256 cache->setAuxProc(GlyphCacheAuxProc, scaler); | 253 cache->setAuxProc(GlyphCacheAuxProc, scaler); |
| 257 } | 254 } |
| 258 | 255 |
| 259 return scaler; | 256 return scaler; |
| 260 } | 257 } |
| OLD | NEW |