| 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 "GrBlurUtils.h" | 9 #include "GrBlurUtils.h" |
| 10 #include "GrContext.h" | 10 #include "GrContext.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 GrTextContext::GrTextContext(GrContext* context, const SkSurfaceProps& surfacePr
ops) | 24 GrTextContext::GrTextContext(GrContext* context, const SkSurfaceProps& surfacePr
ops) |
| 25 : fFallbackTextContext(nullptr) | 25 : fFallbackTextContext(nullptr) |
| 26 , fContext(context) | 26 , fContext(context) |
| 27 , fSurfaceProps(surfaceProps) { | 27 , fSurfaceProps(surfaceProps) { |
| 28 } | 28 } |
| 29 | 29 |
| 30 GrTextContext::~GrTextContext() { | 30 GrTextContext::~GrTextContext() { |
| 31 delete fFallbackTextContext; | 31 delete fFallbackTextContext; |
| 32 } | 32 } |
| 33 | 33 |
| 34 void GrTextContext::drawText(GrDrawContext* dc, GrRenderTarget* rt, | 34 void GrTextContext::drawText(GrDrawContext* dc, |
| 35 const GrClip& clip, const GrPaint& paint, | 35 const GrClip& clip, const GrPaint& paint, |
| 36 const SkPaint& skPaint, const SkMatrix& viewMatrix, | 36 const SkPaint& skPaint, const SkMatrix& viewMatrix, |
| 37 const char text[], size_t byteLength, | 37 const char text[], size_t byteLength, |
| 38 SkScalar x, SkScalar y, const SkIRect& clipBounds)
{ | 38 SkScalar x, SkScalar y, const SkIRect& clipBounds)
{ |
| 39 if (fContext->abandoned()) { | 39 if (fContext->abandoned()) { |
| 40 return; | 40 return; |
| 41 } | 41 } |
| 42 | 42 |
| 43 GrTextContext* textContext = this; | 43 GrTextContext* textContext = this; |
| 44 do { | 44 do { |
| 45 if (textContext->canDraw(skPaint, viewMatrix)) { | 45 if (textContext->canDraw(skPaint, viewMatrix)) { |
| 46 textContext->onDrawText(dc, rt, clip, paint, skPaint, viewMatrix, | 46 textContext->onDrawText(dc, clip, paint, skPaint, viewMatrix, |
| 47 text, byteLength, x, y, clipBounds); | 47 text, byteLength, x, y, clipBounds); |
| 48 return; | 48 return; |
| 49 } | 49 } |
| 50 textContext = textContext->fFallbackTextContext; | 50 textContext = textContext->fFallbackTextContext; |
| 51 } while (textContext); | 51 } while (textContext); |
| 52 | 52 |
| 53 // fall back to drawing as a path | 53 // fall back to drawing as a path |
| 54 this->drawTextAsPath(dc, clip, skPaint, viewMatrix, text, byteLength, x, y,
clipBounds); | 54 this->drawTextAsPath(dc, clip, skPaint, viewMatrix, text, byteLength, x, y,
clipBounds); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void GrTextContext::drawPosText(GrDrawContext* dc, GrRenderTarget* rt, | 57 void GrTextContext::drawPosText(GrDrawContext* dc, |
| 58 const GrClip& clip, const GrPaint& paint, | 58 const GrClip& clip, const GrPaint& paint, |
| 59 const SkPaint& skPaint, const SkMatrix& viewMatr
ix, | 59 const SkPaint& skPaint, const SkMatrix& viewMatr
ix, |
| 60 const char text[], size_t byteLength, | 60 const char text[], size_t byteLength, |
| 61 const SkScalar pos[], int scalarsPerPosition, | 61 const SkScalar pos[], int scalarsPerPosition, |
| 62 const SkPoint& offset, const SkIRect& clipBounds
) { | 62 const SkPoint& offset, const SkIRect& clipBounds
) { |
| 63 if (fContext->abandoned()) { | 63 if (fContext->abandoned()) { |
| 64 return; | 64 return; |
| 65 } | 65 } |
| 66 | 66 |
| 67 GrTextContext* textContext = this; | 67 GrTextContext* textContext = this; |
| 68 do { | 68 do { |
| 69 if (textContext->canDraw(skPaint, viewMatrix)) { | 69 if (textContext->canDraw(skPaint, viewMatrix)) { |
| 70 textContext->onDrawPosText(dc, rt, clip, paint, skPaint, viewMatrix, | 70 textContext->onDrawPosText(dc, clip, paint, skPaint, viewMatrix, |
| 71 text, byteLength, pos, | 71 text, byteLength, pos, |
| 72 scalarsPerPosition, offset, clipBounds); | 72 scalarsPerPosition, offset, clipBounds); |
| 73 return; | 73 return; |
| 74 } | 74 } |
| 75 textContext = textContext->fFallbackTextContext; | 75 textContext = textContext->fFallbackTextContext; |
| 76 } while (textContext); | 76 } while (textContext); |
| 77 | 77 |
| 78 // fall back to drawing as a path | 78 // fall back to drawing as a path |
| 79 this->drawPosTextAsPath(dc, clip, skPaint, viewMatrix, text, byteLength, pos
, | 79 this->drawPosTextAsPath(dc, clip, skPaint, viewMatrix, text, byteLength, pos
, |
| 80 scalarsPerPosition, offset, clipBounds); | 80 scalarsPerPosition, offset, clipBounds); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 101 } | 101 } |
| 102 | 102 |
| 103 if (kUnknown_SkPixelGeometry == surfaceProps.pixelGeometry() || ShouldDisabl
eLCD(paint)) { | 103 if (kUnknown_SkPixelGeometry == surfaceProps.pixelGeometry() || ShouldDisabl
eLCD(paint)) { |
| 104 flags &= ~SkPaint::kLCDRenderText_Flag; | 104 flags &= ~SkPaint::kLCDRenderText_Flag; |
| 105 flags |= SkPaint::kGenA8FromLCD_Flag; | 105 flags |= SkPaint::kGenA8FromLCD_Flag; |
| 106 } | 106 } |
| 107 | 107 |
| 108 return flags; | 108 return flags; |
| 109 } | 109 } |
| 110 | 110 |
| 111 void GrTextContext::drawTextBlob(GrDrawContext* dc, GrRenderTarget* rt, | 111 void GrTextContext::drawTextBlob(GrDrawContext* dc, |
| 112 const GrClip& clip, const SkPaint& skPaint, | 112 const GrClip& clip, const SkPaint& skPaint, |
| 113 const SkMatrix& viewMatrix, const SkTextBlob* b
lob, | 113 const SkMatrix& viewMatrix, const SkTextBlob* b
lob, |
| 114 SkScalar x, SkScalar y, | 114 SkScalar x, SkScalar y, |
| 115 SkDrawFilter* drawFilter, const SkIRect& clipBo
unds) { | 115 SkDrawFilter* drawFilter, const SkIRect& clipBo
unds) { |
| 116 SkPaint runPaint = skPaint; | 116 SkPaint runPaint = skPaint; |
| 117 | 117 |
| 118 SkTextBlobRunIterator it(blob); | 118 SkTextBlobRunIterator it(blob); |
| 119 for (;!it.done(); it.next()) { | 119 for (;!it.done(); it.next()) { |
| 120 size_t textLen = it.glyphCount() * sizeof(uint16_t); | 120 size_t textLen = it.glyphCount() * sizeof(uint16_t); |
| 121 const SkPoint& offset = it.offset(); | 121 const SkPoint& offset = it.offset(); |
| 122 // applyFontToPaint() always overwrites the exact same attributes, | 122 // applyFontToPaint() always overwrites the exact same attributes, |
| 123 // so it is safe to not re-seed the paint for this reason. | 123 // so it is safe to not re-seed the paint for this reason. |
| 124 it.applyFontToPaint(&runPaint); | 124 it.applyFontToPaint(&runPaint); |
| 125 | 125 |
| 126 if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Typ
e)) { | 126 if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Typ
e)) { |
| 127 // A false return from filter() means we should abort the current dr
aw. | 127 // A false return from filter() means we should abort the current dr
aw. |
| 128 runPaint = skPaint; | 128 runPaint = skPaint; |
| 129 continue; | 129 continue; |
| 130 } | 130 } |
| 131 | 131 |
| 132 runPaint.setFlags(FilterTextFlags(fSurfaceProps, runPaint)); | 132 runPaint.setFlags(FilterTextFlags(fSurfaceProps, runPaint)); |
| 133 | 133 |
| 134 GrPaint grPaint; | 134 GrPaint grPaint; |
| 135 if (!SkPaintToGrPaint(fContext, runPaint, viewMatrix, &grPaint)) { | 135 if (!SkPaintToGrPaint(fContext, runPaint, viewMatrix, &grPaint)) { |
| 136 return; | 136 return; |
| 137 } | 137 } |
| 138 | 138 |
| 139 switch (it.positioning()) { | 139 switch (it.positioning()) { |
| 140 case SkTextBlob::kDefault_Positioning: | 140 case SkTextBlob::kDefault_Positioning: |
| 141 this->drawText(dc, rt, clip, grPaint, runPaint, viewMatrix, (const c
har *)it.glyphs(), | 141 this->drawText(dc, clip, grPaint, runPaint, viewMatrix, (const char
*)it.glyphs(), |
| 142 textLen, x + offset.x(), y + offset.y(), clipBounds); | 142 textLen, x + offset.x(), y + offset.y(), clipBounds); |
| 143 break; | 143 break; |
| 144 case SkTextBlob::kHorizontal_Positioning: | 144 case SkTextBlob::kHorizontal_Positioning: |
| 145 this->drawPosText(dc, rt, clip, grPaint, runPaint, viewMatrix, (cons
t char*)it.glyphs(), | 145 this->drawPosText(dc, clip, grPaint, runPaint, viewMatrix, (const ch
ar*)it.glyphs(), |
| 146 textLen, it.pos(), 1, SkPoint::Make(x, y + offset.
y()), clipBounds); | 146 textLen, it.pos(), 1, SkPoint::Make(x, y + offset.
y()), clipBounds); |
| 147 break; | 147 break; |
| 148 case SkTextBlob::kFull_Positioning: | 148 case SkTextBlob::kFull_Positioning: |
| 149 this->drawPosText(dc, rt, clip, grPaint, runPaint, viewMatrix, (cons
t char*)it.glyphs(), | 149 this->drawPosText(dc, clip, grPaint, runPaint, viewMatrix, (const ch
ar*)it.glyphs(), |
| 150 textLen, it.pos(), 2, SkPoint::Make(x, y), clipBou
nds); | 150 textLen, it.pos(), 2, SkPoint::Make(x, y), clipBou
nds); |
| 151 break; | 151 break; |
| 152 default: | 152 default: |
| 153 SkFAIL("unhandled positioning mode"); | 153 SkFAIL("unhandled positioning mode"); |
| 154 } | 154 } |
| 155 | 155 |
| 156 if (drawFilter) { | 156 if (drawFilter) { |
| 157 // A draw filter may change the paint arbitrarily, so we must re-see
d in this case. | 157 // A draw filter may change the paint arbitrarily, so we must re-see
d in this case. |
| 158 runPaint = skPaint; | 158 runPaint = skPaint; |
| 159 } | 159 } |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 if (cache->getAuxProcData(GlyphCacheAuxProc, &auxData)) { | 271 if (cache->getAuxProcData(GlyphCacheAuxProc, &auxData)) { |
| 272 scaler = (GrFontScaler*)auxData; | 272 scaler = (GrFontScaler*)auxData; |
| 273 } | 273 } |
| 274 if (nullptr == scaler) { | 274 if (nullptr == scaler) { |
| 275 scaler = new GrFontScaler(cache); | 275 scaler = new GrFontScaler(cache); |
| 276 cache->setAuxProc(GlyphCacheAuxProc, scaler); | 276 cache->setAuxProc(GlyphCacheAuxProc, scaler); |
| 277 } | 277 } |
| 278 | 278 |
| 279 return scaler; | 279 return scaler; |
| 280 } | 280 } |
| OLD | NEW |