Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(813)

Side by Side Diff: src/gpu/text/GrStencilAndCoverTextContext.cpp

Issue 1685653004: Move surface props off of GrTextContext (Closed) Base URL: https://skia.googlesource.com/skia.git@tc-cleanup-3
Patch Set: rebase Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/text/GrStencilAndCoverTextContext.h ('k') | src/gpu/text/GrTextContext.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 19 matching lines...) Expand all
30 template<typename Key, typename Val> static void delete_hash_map_entry(const Key &, Val* val) { 30 template<typename Key, typename Val> static void delete_hash_map_entry(const Key &, Val* val) {
31 SkASSERT(*val); 31 SkASSERT(*val);
32 delete *val; 32 delete *val;
33 } 33 }
34 34
35 template<typename T> static void delete_hash_table_entry(T* val) { 35 template<typename T> static void delete_hash_table_entry(T* val) {
36 SkASSERT(*val); 36 SkASSERT(*val);
37 delete *val; 37 delete *val;
38 } 38 }
39 39
40 GrStencilAndCoverTextContext::GrStencilAndCoverTextContext(GrContext* context, 40 GrStencilAndCoverTextContext::GrStencilAndCoverTextContext(GrContext* context)
41 const SkSurfaceProps& surfaceProps) 41 : INHERITED(context)
42 : INHERITED(context, surfaceProps)
43 , fFallbackTextContext(nullptr) 42 , fFallbackTextContext(nullptr)
44 , fCacheSize(0) { 43 , fCacheSize(0) {
45 } 44 }
46 45
47 GrStencilAndCoverTextContext* 46 GrStencilAndCoverTextContext*
48 GrStencilAndCoverTextContext::Create(GrContext* context, const SkSurfaceProps& s urfaceProps) { 47 GrStencilAndCoverTextContext::Create(GrContext* context) {
49 GrStencilAndCoverTextContext* textContext = 48 GrStencilAndCoverTextContext* textContext =
50 new GrStencilAndCoverTextContext(context, surfaceProps); 49 new GrStencilAndCoverTextContext(context);
51 textContext->fFallbackTextContext = GrAtlasTextContext::Create(context, surf aceProps); 50 textContext->fFallbackTextContext = GrAtlasTextContext::Create(context);
52 51
53 return textContext; 52 return textContext;
54 } 53 }
55 54
56 GrStencilAndCoverTextContext::~GrStencilAndCoverTextContext() { 55 GrStencilAndCoverTextContext::~GrStencilAndCoverTextContext() {
57 delete fFallbackTextContext; 56 delete fFallbackTextContext;
58 fBlobIdCache.foreach(delete_hash_map_entry<uint32_t, TextBlob*>); 57 fBlobIdCache.foreach(delete_hash_map_entry<uint32_t, TextBlob*>);
59 fBlobKeyCache.foreach(delete_hash_table_entry<TextBlob*>); 58 fBlobKeyCache.foreach(delete_hash_table_entry<TextBlob*>);
60 } 59 }
61 60
62 bool GrStencilAndCoverTextContext::internalCanDraw(const SkPaint& skPaint) { 61 bool GrStencilAndCoverTextContext::internalCanDraw(const SkPaint& skPaint) {
63 if (skPaint.getRasterizer()) { 62 if (skPaint.getRasterizer()) {
64 return false; 63 return false;
65 } 64 }
66 if (skPaint.getMaskFilter()) { 65 if (skPaint.getMaskFilter()) {
67 return false; 66 return false;
68 } 67 }
69 if (SkPathEffect* pe = skPaint.getPathEffect()) { 68 if (SkPathEffect* pe = skPaint.getPathEffect()) {
70 if (pe->asADash(nullptr) != SkPathEffect::kDash_DashType) { 69 if (pe->asADash(nullptr) != SkPathEffect::kDash_DashType) {
71 return false; 70 return false;
72 } 71 }
73 } 72 }
74 // No hairlines. They would require new paths with customized strokes for ev ery new draw matrix. 73 // No hairlines. They would require new paths with customized strokes for ev ery new draw matrix.
75 return SkPaint::kStroke_Style != skPaint.getStyle() || 0 != skPaint.getStrok eWidth(); 74 return SkPaint::kStroke_Style != skPaint.getStyle() || 0 != skPaint.getStrok eWidth();
76 } 75 }
77 76
78 void GrStencilAndCoverTextContext::drawText(GrDrawContext* dc, 77 void GrStencilAndCoverTextContext::drawText(GrDrawContext* dc,
79 const GrClip& clip, const GrPaint& p aint, 78 const GrClip& clip, const GrPaint& p aint,
80 const SkPaint& skPaint, const SkMatr ix& viewMatrix, 79 const SkPaint& skPaint, const SkMatr ix& viewMatrix,
80 const SkSurfaceProps& props,
81 const char text[], size_t byteLength , 81 const char text[], size_t byteLength ,
82 SkScalar x, SkScalar y, const SkIRec t& clipBounds) { 82 SkScalar x, SkScalar y, const SkIRec t& clipBounds) {
83 if (fContext->abandoned()) { 83 if (fContext->abandoned()) {
84 return; 84 return;
85 } else if (this->canDraw(skPaint, viewMatrix)) { 85 } else if (this->canDraw(skPaint, viewMatrix)) {
86 TextRun run(skPaint); 86 TextRun run(skPaint);
87 GrPipelineBuilder pipelineBuilder(paint, dc->accessRenderTarget(), clip) ; 87 GrPipelineBuilder pipelineBuilder(paint, dc->accessRenderTarget(), clip) ;
88 run.setText(text, byteLength, x, y); 88 run.setText(text, byteLength, x, y);
89 run.draw(fContext, dc, &pipelineBuilder, paint.getColor(), viewMatrix, 0 , 0, clipBounds, 89 run.draw(fContext, dc, &pipelineBuilder, paint.getColor(), viewMatrix, p rops, 0, 0,
90 fFallbackTextContext, skPaint); 90 clipBounds, fFallbackTextContext, skPaint);
91 return; 91 return;
92 } else if (fFallbackTextContext->canDraw(skPaint, viewMatrix)) { 92 } else if (fFallbackTextContext->canDraw(skPaint, viewMatrix, props)) {
93 fFallbackTextContext->drawText(dc, clip, paint, skPaint, viewMatrix, tex t, 93 fFallbackTextContext->drawText(dc, clip, paint, skPaint, viewMatrix, pro ps, text,
94 byteLength, x, y, clipBounds); 94 byteLength, x, y, clipBounds);
95 return; 95 return;
96 } 96 }
97 97
98 // fall back to drawing as a path 98 // fall back to drawing as a path
99 GrTextUtils::DrawTextAsPath(fContext, dc, clip, skPaint, viewMatrix, text, b yteLength, x, y, 99 GrTextUtils::DrawTextAsPath(fContext, dc, clip, skPaint, viewMatrix, text, b yteLength, x, y,
100 clipBounds); 100 clipBounds);
101 } 101 }
102 102
103 void GrStencilAndCoverTextContext::drawPosText(GrDrawContext* dc, 103 void GrStencilAndCoverTextContext::drawPosText(GrDrawContext* dc,
104 const GrClip& clip, 104 const GrClip& clip,
105 const GrPaint& paint, 105 const GrPaint& paint,
106 const SkPaint& skPaint, 106 const SkPaint& skPaint,
107 const SkMatrix& viewMatrix, 107 const SkMatrix& viewMatrix,
108 const SkSurfaceProps& props,
108 const char text[], 109 const char text[],
109 size_t byteLength, 110 size_t byteLength,
110 const SkScalar pos[], 111 const SkScalar pos[],
111 int scalarsPerPosition, 112 int scalarsPerPosition,
112 const SkPoint& offset, 113 const SkPoint& offset,
113 const SkIRect& clipBounds) { 114 const SkIRect& clipBounds) {
114 if (fContext->abandoned()) { 115 if (fContext->abandoned()) {
115 return; 116 return;
116 } else if (this->canDraw(skPaint, viewMatrix)) { 117 } else if (this->canDraw(skPaint, viewMatrix)) {
117 TextRun run(skPaint); 118 TextRun run(skPaint);
118 GrPipelineBuilder pipelineBuilder(paint, dc->accessRenderTarget(), clip) ; 119 GrPipelineBuilder pipelineBuilder(paint, dc->accessRenderTarget(), clip) ;
119 run.setPosText(text, byteLength, pos, scalarsPerPosition, offset); 120 run.setPosText(text, byteLength, pos, scalarsPerPosition, offset);
120 run.draw(fContext, dc, &pipelineBuilder, paint.getColor(), viewMatrix, 0 , 0, clipBounds, 121 run.draw(fContext, dc, &pipelineBuilder, paint.getColor(), viewMatrix, p rops, 0, 0,
121 fFallbackTextContext, skPaint); 122 clipBounds, fFallbackTextContext, skPaint);
122 return; 123 return;
123 } else if (fFallbackTextContext->canDraw(skPaint, viewMatrix)) { 124 } else if (fFallbackTextContext->canDraw(skPaint, viewMatrix, props)) {
124 fFallbackTextContext->drawPosText(dc, clip, paint, skPaint, viewMatrix, 125 fFallbackTextContext->drawPosText(dc, clip, paint, skPaint, viewMatrix, props,
125 text, byteLength, pos, 126 text, byteLength, pos,
126 scalarsPerPosition, offset, clipBounds ); 127 scalarsPerPosition, offset, clipBounds );
127 return; 128 return;
128 } 129 }
129 130
130 // fall back to drawing as a path 131 // fall back to drawing as a path
131 GrTextUtils::DrawPosTextAsPath(fContext, dc, fSurfaceProps, clip, skPaint, v iewMatrix, text, 132 GrTextUtils::DrawPosTextAsPath(fContext, dc, props, clip, skPaint, viewMatri x, text,
132 byteLength, pos, scalarsPerPosition, offset, clipBounds); 133 byteLength, pos, scalarsPerPosition, offset, clipBounds);
133 } 134 }
134 135
135 void GrStencilAndCoverTextContext::uncachedDrawTextBlob(GrDrawContext* dc, 136 void GrStencilAndCoverTextContext::uncachedDrawTextBlob(GrDrawContext* dc,
136 const GrClip& clip, cons t SkPaint& skPaint, 137 const GrClip& clip, cons t SkPaint& skPaint,
137 const SkMatrix& viewMatr ix, 138 const SkMatrix& viewMatr ix,
139 const SkSurfaceProps& pr ops,
138 const SkTextBlob* blob, 140 const SkTextBlob* blob,
139 SkScalar x, SkScalar y, 141 SkScalar x, SkScalar y,
140 SkDrawFilter* drawFilter , 142 SkDrawFilter* drawFilter ,
141 const SkIRect& clipBound s) { 143 const SkIRect& clipBound s) {
142 SkPaint runPaint = skPaint; 144 SkPaint runPaint = skPaint;
143 145
144 SkTextBlobRunIterator it(blob); 146 SkTextBlobRunIterator it(blob);
145 for (;!it.done(); it.next()) { 147 for (;!it.done(); it.next()) {
146 size_t textLen = it.glyphCount() * sizeof(uint16_t); 148 size_t textLen = it.glyphCount() * sizeof(uint16_t);
147 const SkPoint& offset = it.offset(); 149 const SkPoint& offset = it.offset();
148 150
149 // applyFontToPaint() always overwrites the exact same attributes, 151 // applyFontToPaint() always overwrites the exact same attributes,
150 // so it is safe to not re-seed the paint for this reason. 152 // so it is safe to not re-seed the paint for this reason.
151 it.applyFontToPaint(&runPaint); 153 it.applyFontToPaint(&runPaint);
152 154
153 if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Typ e)) { 155 if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Typ e)) {
154 // A false return from filter() means we should abort the current dr aw. 156 // A false return from filter() means we should abort the current dr aw.
155 runPaint = skPaint; 157 runPaint = skPaint;
156 continue; 158 continue;
157 } 159 }
158 160
159 runPaint.setFlags(FilterTextFlags(fSurfaceProps, runPaint)); 161 runPaint.setFlags(FilterTextFlags(props, runPaint));
160 162
161 GrPaint grPaint; 163 GrPaint grPaint;
162 if (!SkPaintToGrPaint(fContext, runPaint, viewMatrix, &grPaint)) { 164 if (!SkPaintToGrPaint(fContext, runPaint, viewMatrix, &grPaint)) {
163 return; 165 return;
164 } 166 }
165 167
166 switch (it.positioning()) { 168 switch (it.positioning()) {
167 case SkTextBlob::kDefault_Positioning: 169 case SkTextBlob::kDefault_Positioning:
168 this->drawText(dc, clip, grPaint, runPaint, viewMatrix, (const c har *)it.glyphs(), 170 this->drawText(dc, clip, grPaint, runPaint, viewMatrix, props,
171 (const char *)it.glyphs(),
169 textLen, x + offset.x(), y + offset.y(), clipBoun ds); 172 textLen, x + offset.x(), y + offset.y(), clipBoun ds);
170 break; 173 break;
171 case SkTextBlob::kHorizontal_Positioning: 174 case SkTextBlob::kHorizontal_Positioning:
172 this->drawPosText(dc, clip, grPaint, runPaint, viewMatrix, (cons t char*)it.glyphs(), 175 this->drawPosText(dc, clip, grPaint, runPaint, viewMatrix, props ,
176 (const char*)it.glyphs(),
173 textLen, it.pos(), 1, SkPoint::Make(x, y + off set.y()), 177 textLen, it.pos(), 1, SkPoint::Make(x, y + off set.y()),
174 clipBounds); 178 clipBounds);
175 break; 179 break;
176 case SkTextBlob::kFull_Positioning: 180 case SkTextBlob::kFull_Positioning:
177 this->drawPosText(dc, clip, grPaint, runPaint, viewMatrix, (cons t char*)it.glyphs(), 181 this->drawPosText(dc, clip, grPaint, runPaint, viewMatrix, props ,
182 (const char*)it.glyphs(),
178 textLen, it.pos(), 2, SkPoint::Make(x, y), cli pBounds); 183 textLen, it.pos(), 2, SkPoint::Make(x, y), cli pBounds);
179 break; 184 break;
180 } 185 }
181 186
182 if (drawFilter) { 187 if (drawFilter) {
183 // A draw filter may change the paint arbitrarily, so we must re-see d in this case. 188 // A draw filter may change the paint arbitrarily, so we must re-see d in this case.
184 runPaint = skPaint; 189 runPaint = skPaint;
185 } 190 }
186 } 191 }
187 } 192 }
188 193
189 void GrStencilAndCoverTextContext::drawTextBlob(GrDrawContext* dc, 194 void GrStencilAndCoverTextContext::drawTextBlob(GrDrawContext* dc,
190 const GrClip& clip, const SkPain t& skPaint, 195 const GrClip& clip, const SkPain t& skPaint,
191 const SkMatrix& viewMatrix, 196 const SkMatrix& viewMatrix,
197 const SkSurfaceProps& props,
192 const SkTextBlob* skBlob, SkScal ar x, SkScalar y, 198 const SkTextBlob* skBlob, SkScal ar x, SkScalar y,
193 SkDrawFilter* drawFilter, 199 SkDrawFilter* drawFilter,
194 const SkIRect& clipBounds) { 200 const SkIRect& clipBounds) {
195 if (fContext->abandoned()) { 201 if (fContext->abandoned()) {
196 return; 202 return;
197 } 203 }
198 204
199 if (!this->internalCanDraw(skPaint)) { 205 if (!this->internalCanDraw(skPaint)) {
200 fFallbackTextContext->drawTextBlob(dc, clip, skPaint, viewMatrix, skBlob , x, y, 206 fFallbackTextContext->drawTextBlob(dc, clip, skPaint, viewMatrix, props, skBlob, x, y,
201 drawFilter, clipBounds); 207 drawFilter, clipBounds);
202 return; 208 return;
203 } 209 }
204 210
205 if (drawFilter || skPaint.getPathEffect()) { 211 if (drawFilter || skPaint.getPathEffect()) {
206 // This draw can't be cached. 212 // This draw can't be cached.
207 this->uncachedDrawTextBlob(dc, clip, skPaint, viewMatrix, skBlob, x, y, drawFilter, 213 this->uncachedDrawTextBlob(dc, clip, skPaint, viewMatrix, props, skBlob, x, y, drawFilter,
208 clipBounds); 214 clipBounds);
209 return; 215 return;
210 } 216 }
211 217
212 GrPaint paint; 218 GrPaint paint;
213 if (!SkPaintToGrPaint(fContext, skPaint, viewMatrix, &paint)) { 219 if (!SkPaintToGrPaint(fContext, skPaint, viewMatrix, &paint)) {
214 return; 220 return;
215 } 221 }
216 222
217 const TextBlob& blob = this->findOrCreateTextBlob(skBlob, skPaint); 223 const TextBlob& blob = this->findOrCreateTextBlob(skBlob, skPaint);
218 GrPipelineBuilder pipelineBuilder(paint, dc->accessRenderTarget(), clip); 224 GrPipelineBuilder pipelineBuilder(paint, dc->accessRenderTarget(), clip);
219 225
220 TextBlob::Iter iter(blob); 226 TextBlob::Iter iter(blob);
221 for (TextRun* run = iter.get(); run; run = iter.next()) { 227 for (TextRun* run = iter.get(); run; run = iter.next()) {
222 run->draw(fContext, dc, &pipelineBuilder, paint.getColor(), viewMatrix, x, y, clipBounds, 228 run->draw(fContext, dc, &pipelineBuilder, paint.getColor(), viewMatrix, props, x, y,
223 fFallbackTextContext, skPaint); 229 clipBounds, fFallbackTextContext, skPaint);
224 run->releaseGlyphCache(); 230 run->releaseGlyphCache();
225 } 231 }
226 } 232 }
227 233
228 const GrStencilAndCoverTextContext::TextBlob& 234 const GrStencilAndCoverTextContext::TextBlob&
229 GrStencilAndCoverTextContext::findOrCreateTextBlob(const SkTextBlob* skBlob, 235 GrStencilAndCoverTextContext::findOrCreateTextBlob(const SkTextBlob* skBlob,
230 const SkPaint& skPaint) { 236 const SkPaint& skPaint) {
231 // The font-related parameters are baked into the text blob and will overrid e this skPaint, so 237 // The font-related parameters are baked into the text blob and will overrid e this skPaint, so
232 // the only remaining properties that can affect a TextBlob are the ones rel ated to stroke. 238 // the only remaining properties that can affect a TextBlob are the ones rel ated to stroke.
233 if (SkPaint::kFill_Style == skPaint.getStyle()) { // Fast path. 239 if (SkPaint::kFill_Style == skPaint.getStyle()) { // Fast path.
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 fInstanceData->append(glyph.getGlyphID(), fTextInverseRatio * pos.x(), 561 fInstanceData->append(glyph.getGlyphID(), fTextInverseRatio * pos.x(),
556 fTextInverseRatio * pos.y()); 562 fTextInverseRatio * pos.y());
557 } 563 }
558 } 564 }
559 565
560 void GrStencilAndCoverTextContext::TextRun::draw(GrContext* ctx, 566 void GrStencilAndCoverTextContext::TextRun::draw(GrContext* ctx,
561 GrDrawContext* dc, 567 GrDrawContext* dc,
562 GrPipelineBuilder* pipelineBuil der, 568 GrPipelineBuilder* pipelineBuil der,
563 GrColor color, 569 GrColor color,
564 const SkMatrix& viewMatrix, 570 const SkMatrix& viewMatrix,
571 const SkSurfaceProps& props,
565 SkScalar x, SkScalar y, 572 SkScalar x, SkScalar y,
566 const SkIRect& clipBounds, 573 const SkIRect& clipBounds,
567 GrTextContext* fallbackTextCont ext, 574 GrTextContext* fallbackTextCont ext,
568 const SkPaint& originalSkPaint) const { 575 const SkPaint& originalSkPaint) const {
569 SkASSERT(fInstanceData); 576 SkASSERT(fInstanceData);
570 SkASSERT(dc->accessRenderTarget()->isStencilBufferMultisampled() || !fFont.i sAntiAlias()); 577 SkASSERT(dc->accessRenderTarget()->isStencilBufferMultisampled() || !fFont.i sAntiAlias());
571 578
572 if (fInstanceData->count()) { 579 if (fInstanceData->count()) {
573 pipelineBuilder->setState(GrPipelineBuilder::kHWAntialias_Flag, fFont.is AntiAlias()); 580 pipelineBuilder->setState(GrPipelineBuilder::kHWAntialias_Flag, fFont.is AntiAlias());
574 581
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 } 614 }
608 615
609 if (fFallbackTextBlob) { 616 if (fFallbackTextBlob) {
610 SkPaint fallbackSkPaint(originalSkPaint); 617 SkPaint fallbackSkPaint(originalSkPaint);
611 fStroke.applyToPaint(&fallbackSkPaint); 618 fStroke.applyToPaint(&fallbackSkPaint);
612 if (!fStroke.isFillStyle()) { 619 if (!fStroke.isFillStyle()) {
613 fallbackSkPaint.setStrokeWidth(fStroke.getWidth() * fTextRatio); 620 fallbackSkPaint.setStrokeWidth(fStroke.getWidth() * fTextRatio);
614 } 621 }
615 622
616 fallbackTextContext->drawTextBlob(dc, pipelineBuilder->clip(), fallbackS kPaint, viewMatrix, 623 fallbackTextContext->drawTextBlob(dc, pipelineBuilder->clip(), fallbackS kPaint, viewMatrix,
617 fFallbackTextBlob, x, y, nullptr, clip Bounds); 624 props, fFallbackTextBlob, x, y, nullpt r, clipBounds);
618 } 625 }
619 } 626 }
620 627
621 SkGlyphCache* GrStencilAndCoverTextContext::TextRun::getGlyphCache() const { 628 SkGlyphCache* GrStencilAndCoverTextContext::TextRun::getGlyphCache() const {
622 if (!fDetachedGlyphCache) { 629 if (!fDetachedGlyphCache) {
623 fDetachedGlyphCache = fFont.detachCache(nullptr, nullptr, true /*ignoreG amma*/); 630 fDetachedGlyphCache = fFont.detachCache(nullptr, nullptr, true /*ignoreG amma*/);
624 } 631 }
625 return fDetachedGlyphCache; 632 return fDetachedGlyphCache;
626 } 633 }
627 634
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 } 695 }
689 696
690 const SkTextBlob* GrStencilAndCoverTextContext::FallbackBlobBuilder::buildIfNeed ed(int *count) { 697 const SkTextBlob* GrStencilAndCoverTextContext::FallbackBlobBuilder::buildIfNeed ed(int *count) {
691 *count = fCount; 698 *count = fCount;
692 if (fCount) { 699 if (fCount) {
693 this->flush(); 700 this->flush();
694 return fBuilder->build(); 701 return fBuilder->build();
695 } 702 }
696 return nullptr; 703 return nullptr;
697 } 704 }
OLDNEW
« no previous file with comments | « src/gpu/text/GrStencilAndCoverTextContext.h ('k') | src/gpu/text/GrTextContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698