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 "GrAtlasTextContext.h" | 9 #include "GrAtlasTextContext.h" |
10 #include "GrDrawContext.h" | 10 #include "GrDrawContext.h" |
(...skipping 18 matching lines...) Expand all Loading... | |
29 template<typename Key, typename Val> static void delete_hash_map_entry(const Key &, Val* val) { | 29 template<typename Key, typename Val> static void delete_hash_map_entry(const Key &, Val* val) { |
30 SkASSERT(*val); | 30 SkASSERT(*val); |
31 delete *val; | 31 delete *val; |
32 } | 32 } |
33 | 33 |
34 template<typename T> static void delete_hash_table_entry(T* val) { | 34 template<typename T> static void delete_hash_table_entry(T* val) { |
35 SkASSERT(*val); | 35 SkASSERT(*val); |
36 delete *val; | 36 delete *val; |
37 } | 37 } |
38 | 38 |
39 GrStencilAndCoverTextContext::GrStencilAndCoverTextContext(GrContext* context) | 39 GrStencilAndCoverTextContext::GrStencilAndCoverTextContext() |
40 : INHERITED(context), | 40 : fCacheSize(0) { |
41 fCacheSize(0) { | |
42 } | 41 } |
43 | 42 |
44 GrStencilAndCoverTextContext* | 43 GrStencilAndCoverTextContext* |
45 GrStencilAndCoverTextContext::Create(GrContext* context) { | 44 GrStencilAndCoverTextContext::Create() { |
46 GrStencilAndCoverTextContext* textContext = | 45 GrStencilAndCoverTextContext* textContext = new GrStencilAndCoverTextContext (); |
47 new GrStencilAndCoverTextContext(context); | 46 textContext->fFallbackTextContext = GrAtlasTextContext::Create(); |
48 textContext->fFallbackTextContext = GrAtlasTextContext::Create(context); | |
49 | 47 |
50 return textContext; | 48 return textContext; |
51 } | 49 } |
52 | 50 |
53 GrStencilAndCoverTextContext::~GrStencilAndCoverTextContext() { | 51 GrStencilAndCoverTextContext::~GrStencilAndCoverTextContext() { |
54 delete fFallbackTextContext; | 52 delete fFallbackTextContext; |
55 fBlobIdCache.foreach(delete_hash_map_entry<uint32_t, TextBlob*>); | 53 fBlobIdCache.foreach(delete_hash_map_entry<uint32_t, TextBlob*>); |
56 fBlobKeyCache.foreach(delete_hash_table_entry<TextBlob*>); | 54 fBlobKeyCache.foreach(delete_hash_table_entry<TextBlob*>); |
57 } | 55 } |
58 | 56 |
59 bool GrStencilAndCoverTextContext::internalCanDraw(const SkPaint& skPaint) { | 57 bool GrStencilAndCoverTextContext::internalCanDraw(const SkPaint& skPaint) { |
60 if (skPaint.getRasterizer()) { | 58 if (skPaint.getRasterizer()) { |
61 return false; | 59 return false; |
62 } | 60 } |
63 if (skPaint.getMaskFilter()) { | 61 if (skPaint.getMaskFilter()) { |
64 return false; | 62 return false; |
65 } | 63 } |
66 if (SkPathEffect* pe = skPaint.getPathEffect()) { | 64 if (SkPathEffect* pe = skPaint.getPathEffect()) { |
67 if (pe->asADash(nullptr) != SkPathEffect::kDash_DashType) { | 65 if (pe->asADash(nullptr) != SkPathEffect::kDash_DashType) { |
68 return false; | 66 return false; |
69 } | 67 } |
70 } | 68 } |
71 // No hairlines. They would require new paths with customized strokes for ev ery new draw matrix. | 69 // No hairlines. They would require new paths with customized strokes for ev ery new draw matrix. |
72 return SkPaint::kStroke_Style != skPaint.getStyle() || 0 != skPaint.getStrok eWidth(); | 70 return SkPaint::kStroke_Style != skPaint.getStyle() || 0 != skPaint.getStrok eWidth(); |
73 } | 71 } |
74 | 72 |
75 void GrStencilAndCoverTextContext::drawText(GrDrawContext* dc, | 73 void GrStencilAndCoverTextContext::drawText(GrContext* context, GrDrawContext* d c, |
76 const GrClip& clip, const GrPaint& p aint, | 74 const GrClip& clip, const GrPaint& p aint, |
77 const SkPaint& skPaint, const SkMatr ix& viewMatrix, | 75 const SkPaint& skPaint, const SkMatr ix& viewMatrix, |
78 const SkSurfaceProps& props, | 76 const SkSurfaceProps& props, |
79 const char text[], size_t byteLength , | 77 const char text[], size_t byteLength , |
80 SkScalar x, SkScalar y, const SkIRec t& clipBounds) { | 78 SkScalar x, SkScalar y, const SkIRec t& clipBounds) { |
81 if (fContext->abandoned()) { | 79 if (context->abandoned()) { |
82 return; | 80 return; |
83 } else if (this->canDraw(skPaint, viewMatrix)) { | 81 } else if (this->canDraw(skPaint, viewMatrix)) { |
84 TextRun run(skPaint); | 82 TextRun run(skPaint); |
85 GrPipelineBuilder pipelineBuilder(paint, dc->accessRenderTarget(), clip) ; | 83 GrPipelineBuilder pipelineBuilder(paint, dc->accessRenderTarget(), clip) ; |
86 run.setText(text, byteLength, x, y); | 84 run.setText(text, byteLength, x, y); |
robertphillips
2016/02/10 19:44:39
can this guy just take a resource provider ?
| |
87 run.draw(fContext, dc, &pipelineBuilder, paint.getColor(), viewMatrix, p rops, 0, 0, | 85 run.draw(context, dc, &pipelineBuilder, paint.getColor(), viewMatrix, pr ops, 0, 0, |
88 clipBounds, fFallbackTextContext, skPaint); | 86 clipBounds, fFallbackTextContext, skPaint); |
89 return; | 87 return; |
90 } else if (fFallbackTextContext->canDraw(skPaint, viewMatrix, props)) { | 88 } else if (fFallbackTextContext->canDraw(skPaint, viewMatrix, props, |
91 fFallbackTextContext->drawText(dc, clip, paint, skPaint, viewMatrix, pro ps, text, | 89 *context->caps()->shaderCaps())) { |
90 fFallbackTextContext->drawText(context, dc, clip, paint, skPaint, viewMa trix, props, text, | |
92 byteLength, x, y, clipBounds); | 91 byteLength, x, y, clipBounds); |
93 return; | 92 return; |
94 } | 93 } |
95 | 94 |
96 // fall back to drawing as a path | 95 // fall back to drawing as a path |
97 GrTextUtils::DrawTextAsPath(fContext, dc, clip, skPaint, viewMatrix, text, b yteLength, x, y, | 96 GrTextUtils::DrawTextAsPath(context, dc, clip, skPaint, viewMatrix, text, by teLength, x, y, |
98 clipBounds); | 97 clipBounds); |
99 } | 98 } |
100 | 99 |
101 void GrStencilAndCoverTextContext::drawPosText(GrDrawContext* dc, | 100 void GrStencilAndCoverTextContext::drawPosText(GrContext* context, GrDrawContext * dc, |
102 const GrClip& clip, | 101 const GrClip& clip, |
103 const GrPaint& paint, | 102 const GrPaint& paint, |
104 const SkPaint& skPaint, | 103 const SkPaint& skPaint, |
105 const SkMatrix& viewMatrix, | 104 const SkMatrix& viewMatrix, |
106 const SkSurfaceProps& props, | 105 const SkSurfaceProps& props, |
107 const char text[], | 106 const char text[], |
108 size_t byteLength, | 107 size_t byteLength, |
109 const SkScalar pos[], | 108 const SkScalar pos[], |
110 int scalarsPerPosition, | 109 int scalarsPerPosition, |
111 const SkPoint& offset, | 110 const SkPoint& offset, |
112 const SkIRect& clipBounds) { | 111 const SkIRect& clipBounds) { |
113 if (fContext->abandoned()) { | 112 if (context->abandoned()) { |
114 return; | 113 return; |
115 } else if (this->canDraw(skPaint, viewMatrix)) { | 114 } else if (this->canDraw(skPaint, viewMatrix)) { |
116 TextRun run(skPaint); | 115 TextRun run(skPaint); |
117 GrPipelineBuilder pipelineBuilder(paint, dc->accessRenderTarget(), clip) ; | 116 GrPipelineBuilder pipelineBuilder(paint, dc->accessRenderTarget(), clip) ; |
118 run.setPosText(text, byteLength, pos, scalarsPerPosition, offset); | 117 run.setPosText(text, byteLength, pos, scalarsPerPosition, offset); |
119 run.draw(fContext, dc, &pipelineBuilder, paint.getColor(), viewMatrix, p rops, 0, 0, | 118 run.draw(context, dc, &pipelineBuilder, paint.getColor(), viewMatrix, pr ops, 0, 0, |
120 clipBounds, fFallbackTextContext, skPaint); | 119 clipBounds, fFallbackTextContext, skPaint); |
121 return; | 120 return; |
122 } else if (fFallbackTextContext->canDraw(skPaint, viewMatrix, props)) { | 121 } else if (fFallbackTextContext->canDraw(skPaint, viewMatrix, props, |
123 fFallbackTextContext->drawPosText(dc, clip, paint, skPaint, viewMatrix, props, | 122 *context->caps()->shaderCaps())) { |
123 fFallbackTextContext->drawPosText(context, dc, clip, paint, skPaint, vie wMatrix, props, | |
124 text, byteLength, pos, | 124 text, byteLength, pos, |
125 scalarsPerPosition, offset, clipBounds ); | 125 scalarsPerPosition, offset, clipBounds ); |
126 return; | 126 return; |
127 } | 127 } |
128 | 128 |
129 // fall back to drawing as a path | 129 // fall back to drawing as a path |
130 GrTextUtils::DrawPosTextAsPath(fContext, dc, props, clip, skPaint, viewMatri x, text, | 130 GrTextUtils::DrawPosTextAsPath(context, dc, props, clip, skPaint, viewMatrix , text, |
131 byteLength, pos, scalarsPerPosition, offset, clipBounds); | 131 byteLength, pos, scalarsPerPosition, offset, clipBounds); |
132 } | 132 } |
133 | 133 |
134 void GrStencilAndCoverTextContext::drawTextBlob(GrDrawContext* dc, | 134 void GrStencilAndCoverTextContext::drawTextBlob(GrContext* context, GrDrawContex t* dc, |
135 const GrClip& clip, const SkPain t& skPaint, | 135 const GrClip& clip, const SkPain t& skPaint, |
136 const SkMatrix& viewMatrix, | 136 const SkMatrix& viewMatrix, |
137 const SkSurfaceProps& props, | 137 const SkSurfaceProps& props, |
138 const SkTextBlob* skBlob, SkScal ar x, SkScalar y, | 138 const SkTextBlob* skBlob, SkScal ar x, SkScalar y, |
139 SkDrawFilter* drawFilter, | 139 SkDrawFilter* drawFilter, |
140 const SkIRect& clipBounds) { | 140 const SkIRect& clipBounds) { |
141 if (fContext->abandoned()) { | 141 if (context->abandoned()) { |
142 return; | 142 return; |
143 } | 143 } |
144 | 144 |
145 if (!this->internalCanDraw(skPaint)) { | 145 if (!this->internalCanDraw(skPaint)) { |
146 fFallbackTextContext->drawTextBlob(dc, clip, skPaint, viewMatrix, props, skBlob, x, y, | 146 fFallbackTextContext->drawTextBlob(context, dc, clip, skPaint, viewMatri x, props, skBlob, |
147 drawFilter, clipBounds); | 147 x, y, drawFilter, clipBounds); |
148 return; | 148 return; |
149 } | 149 } |
150 | 150 |
151 if (drawFilter || skPaint.getPathEffect()) { | 151 if (drawFilter || skPaint.getPathEffect()) { |
152 // This draw can't be cached. | 152 // This draw can't be cached. |
153 fFallbackTextContext->drawTextBlob(dc, clip, skPaint, viewMatrix, props, skBlob, x, y, | 153 fFallbackTextContext->drawTextBlob(context, dc, clip, skPaint, viewMatri x, props, skBlob, |
154 drawFilter, clipBounds); | 154 x, y, drawFilter, clipBounds); |
155 return; | 155 return; |
156 } | 156 } |
157 | 157 |
158 GrPaint paint; | 158 GrPaint paint; |
159 if (!SkPaintToGrPaint(fContext, skPaint, viewMatrix, &paint)) { | 159 if (!SkPaintToGrPaint(context, skPaint, viewMatrix, &paint)) { |
160 return; | 160 return; |
161 } | 161 } |
162 | 162 |
163 const TextBlob& blob = this->findOrCreateTextBlob(skBlob, skPaint); | 163 const TextBlob& blob = this->findOrCreateTextBlob(skBlob, skPaint); |
164 GrPipelineBuilder pipelineBuilder(paint, dc->accessRenderTarget(), clip); | 164 GrPipelineBuilder pipelineBuilder(paint, dc->accessRenderTarget(), clip); |
165 | 165 |
166 TextBlob::Iter iter(blob); | 166 TextBlob::Iter iter(blob); |
167 for (TextRun* run = iter.get(); run; run = iter.next()) { | 167 for (TextRun* run = iter.get(); run; run = iter.next()) { |
168 run->draw(fContext, dc, &pipelineBuilder, paint.getColor(), viewMatrix, props, x, y, | 168 run->draw(context, dc, &pipelineBuilder, paint.getColor(), viewMatrix, p rops, x, y, |
169 clipBounds, fFallbackTextContext, skPaint); | 169 clipBounds, fFallbackTextContext, skPaint); |
170 run->releaseGlyphCache(); | 170 run->releaseGlyphCache(); |
171 } | 171 } |
172 } | 172 } |
173 | 173 |
174 const GrStencilAndCoverTextContext::TextBlob& | 174 const GrStencilAndCoverTextContext::TextBlob& |
175 GrStencilAndCoverTextContext::findOrCreateTextBlob(const SkTextBlob* skBlob, | 175 GrStencilAndCoverTextContext::findOrCreateTextBlob(const SkTextBlob* skBlob, |
176 const SkPaint& skPaint) { | 176 const SkPaint& skPaint) { |
177 // The font-related parameters are baked into the text blob and will overrid e this skPaint, so | 177 // The font-related parameters are baked into the text blob and will overrid e this skPaint, so |
178 // the only remaining properties that can affect a TextBlob are the ones rel ated to stroke. | 178 // the only remaining properties that can affect a TextBlob are the ones rel ated to stroke. |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
553 dc->drawPathBatch(*pipelineBuilder, batch); | 553 dc->drawPathBatch(*pipelineBuilder, batch); |
554 } | 554 } |
555 | 555 |
556 if (fFallbackTextBlob) { | 556 if (fFallbackTextBlob) { |
557 SkPaint fallbackSkPaint(originalSkPaint); | 557 SkPaint fallbackSkPaint(originalSkPaint); |
558 fStroke.applyToPaint(&fallbackSkPaint); | 558 fStroke.applyToPaint(&fallbackSkPaint); |
559 if (!fStroke.isFillStyle()) { | 559 if (!fStroke.isFillStyle()) { |
560 fallbackSkPaint.setStrokeWidth(fStroke.getWidth() * fTextRatio); | 560 fallbackSkPaint.setStrokeWidth(fStroke.getWidth() * fTextRatio); |
561 } | 561 } |
562 | 562 |
563 fallbackTextContext->drawTextBlob(dc, pipelineBuilder->clip(), fallbackS kPaint, viewMatrix, | 563 fallbackTextContext->drawTextBlob(ctx, dc, pipelineBuilder->clip(), fall backSkPaint, |
564 props, fFallbackTextBlob, x, y, nullpt r, clipBounds); | 564 viewMatrix, props, fFallbackTextBlob, x, y, nullptr, |
565 clipBounds); | |
565 } | 566 } |
566 } | 567 } |
567 | 568 |
568 SkGlyphCache* GrStencilAndCoverTextContext::TextRun::getGlyphCache() const { | 569 SkGlyphCache* GrStencilAndCoverTextContext::TextRun::getGlyphCache() const { |
569 if (!fDetachedGlyphCache) { | 570 if (!fDetachedGlyphCache) { |
570 fDetachedGlyphCache = fFont.detachCache(nullptr, nullptr, true /*ignoreG amma*/); | 571 fDetachedGlyphCache = fFont.detachCache(nullptr, nullptr, true /*ignoreG amma*/); |
571 } | 572 } |
572 return fDetachedGlyphCache; | 573 return fDetachedGlyphCache; |
573 } | 574 } |
574 | 575 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
635 } | 636 } |
636 | 637 |
637 const SkTextBlob* GrStencilAndCoverTextContext::FallbackBlobBuilder::buildIfNeed ed(int *count) { | 638 const SkTextBlob* GrStencilAndCoverTextContext::FallbackBlobBuilder::buildIfNeed ed(int *count) { |
638 *count = fCount; | 639 *count = fCount; |
639 if (fCount) { | 640 if (fCount) { |
640 this->flush(); | 641 this->flush(); |
641 return fBuilder->build(); | 642 return fBuilder->build(); |
642 } | 643 } |
643 return nullptr; | 644 return nullptr; |
644 } | 645 } |
OLD | NEW |