| 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" |
| 11 #include "GrFontScaler.h" |
| 10 | 12 |
| 11 #include "SkAutoKern.h" | 13 #include "SkAutoKern.h" |
| 12 #include "SkGlyphCache.h" | 14 #include "SkGlyphCache.h" |
| 13 #include "GrFontScaler.h" | |
| 14 | 15 |
| 15 GrTextContext::GrTextContext(GrContext* context, const SkDeviceProperties& prope
rties) : | 16 GrTextContext::GrTextContext(GrContext* context, const SkDeviceProperties& prope
rties) : |
| 16 fFallbackTextContext(NULL), | 17 fFallbackTextContext(NULL), |
| 17 fContext(context), fDeviceProperties(properties), fD
rawTarget(NULL) { | 18 fContext(context), fDeviceProperties(properties), |
| 19 fDrawTarget(NULL) { |
| 18 } | 20 } |
| 19 | 21 |
| 20 GrTextContext::~GrTextContext() { | 22 GrTextContext::~GrTextContext() { |
| 21 SkDELETE(fFallbackTextContext); | 23 SkDELETE(fFallbackTextContext); |
| 22 } | 24 } |
| 23 | 25 |
| 24 void GrTextContext::init(GrRenderTarget* rt, const GrPaint& grPaint, const SkPai
nt& skPaint) { | 26 void GrTextContext::init(GrRenderTarget* rt, const GrClip& clip, const GrPaint&
grPaint, |
| 25 fClip = fContext->getClip(); | 27 const SkPaint& skPaint) { |
| 28 fClip = clip; |
| 26 | 29 |
| 27 fRenderTarget.reset(SkRef(rt)); | 30 fRenderTarget.reset(SkRef(rt)); |
| 28 | 31 |
| 29 fClip->getConservativeBounds(fRenderTarget->width(), fRenderTarget->height()
, &fClipRect); | 32 fClip.getConservativeBounds(fRenderTarget->width(), fRenderTarget->height(),
&fClipRect); |
| 30 | 33 |
| 31 fDrawTarget = fContext->getTextTarget(); | 34 fDrawTarget = fContext->getTextTarget(); |
| 32 | 35 |
| 33 fPaint = grPaint; | 36 fPaint = grPaint; |
| 34 fSkPaint = skPaint; | 37 fSkPaint = skPaint; |
| 35 } | 38 } |
| 36 | 39 |
| 37 bool GrTextContext::drawText(GrRenderTarget* rt, const GrPaint& paint, const SkP
aint& skPaint, | 40 bool GrTextContext::drawText(GrRenderTarget* rt, const GrClip& clip, const GrPai
nt& paint, |
| 38 const SkMatrix& viewMatrix, | 41 const SkPaint& skPaint, const SkMatrix& viewMatrix, |
| 39 const char text[], size_t byteLength, | 42 const char text[], size_t byteLength, |
| 40 SkScalar x, SkScalar y) { | 43 SkScalar x, SkScalar y) { |
| 41 | 44 |
| 42 GrTextContext* textContext = this; | 45 GrTextContext* textContext = this; |
| 43 do { | 46 do { |
| 44 if (textContext->canDraw(skPaint, viewMatrix)) { | 47 if (textContext->canDraw(skPaint, viewMatrix)) { |
| 45 textContext->onDrawText(rt, paint, skPaint, viewMatrix, text, byteLe
ngth, x, y); | 48 textContext->onDrawText(rt, clip, paint, skPaint, viewMatrix, text,
byteLength, x, y); |
| 46 return true; | 49 return true; |
| 47 } | 50 } |
| 48 textContext = textContext->fFallbackTextContext; | 51 textContext = textContext->fFallbackTextContext; |
| 49 } while (textContext); | 52 } while (textContext); |
| 50 | 53 |
| 51 return false; | 54 return false; |
| 52 } | 55 } |
| 53 | 56 |
| 54 bool GrTextContext::drawPosText(GrRenderTarget* rt, const GrPaint& paint, const
SkPaint& skPaint, | 57 bool GrTextContext::drawPosText(GrRenderTarget* rt, const GrClip& clip, const Gr
Paint& paint, |
| 55 const SkMatrix& viewMatrix, | 58 const SkPaint& skPaint, const SkMatrix& viewMatr
ix, |
| 56 const char text[], size_t byteLength, | 59 const char text[], size_t byteLength, |
| 57 const SkScalar pos[], int scalarsPerPosition, | 60 const SkScalar pos[], int scalarsPerPosition, |
| 58 const SkPoint& offset) { | 61 const SkPoint& offset) { |
| 59 | 62 |
| 60 GrTextContext* textContext = this; | 63 GrTextContext* textContext = this; |
| 61 do { | 64 do { |
| 62 if (textContext->canDraw(skPaint, viewMatrix)) { | 65 if (textContext->canDraw(skPaint, viewMatrix)) { |
| 63 textContext->onDrawPosText(rt, paint, skPaint, viewMatrix, text, byt
eLength, pos, | 66 textContext->onDrawPosText(rt, clip, paint, skPaint, viewMatrix, tex
t, byteLength, pos, |
| 64 scalarsPerPosition, offset); | 67 scalarsPerPosition, offset); |
| 65 return true; | 68 return true; |
| 66 } | 69 } |
| 67 textContext = textContext->fFallbackTextContext; | 70 textContext = textContext->fFallbackTextContext; |
| 68 } while (textContext); | 71 } while (textContext); |
| 69 | 72 |
| 70 return false; | 73 return false; |
| 71 } | 74 } |
| 72 | 75 |
| 73 | 76 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 if (cache->getAuxProcData(GlyphCacheAuxProc, &auxData)) { | 111 if (cache->getAuxProcData(GlyphCacheAuxProc, &auxData)) { |
| 109 scaler = (GrFontScaler*)auxData; | 112 scaler = (GrFontScaler*)auxData; |
| 110 } | 113 } |
| 111 if (NULL == scaler) { | 114 if (NULL == scaler) { |
| 112 scaler = SkNEW_ARGS(GrFontScaler, (cache)); | 115 scaler = SkNEW_ARGS(GrFontScaler, (cache)); |
| 113 cache->setAuxProc(GlyphCacheAuxProc, scaler); | 116 cache->setAuxProc(GlyphCacheAuxProc, scaler); |
| 114 } | 117 } |
| 115 | 118 |
| 116 return scaler; | 119 return scaler; |
| 117 } | 120 } |
| OLD | NEW |