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

Side by Side Diff: src/gpu/GrDistanceFieldTextContext.cpp

Issue 939623005: Pass Rendertarget into context (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: sampleapp Created 5 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/GrDistanceFieldTextContext.h ('k') | src/gpu/GrStencilAndCoverTextContext.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 2013 Google Inc. 2 * Copyright 2013 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 "GrDistanceFieldTextContext.h" 8 #include "GrDistanceFieldTextContext.h"
9 #include "GrAtlas.h" 9 #include "GrAtlas.h"
10 #include "GrBitmapTextContext.h" 10 #include "GrBitmapTextContext.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 } 105 }
106 106
107 // TODO: add some stroking support 107 // TODO: add some stroking support
108 if (paint.getStyle() != SkPaint::kFill_Style) { 108 if (paint.getStyle() != SkPaint::kFill_Style) {
109 return false; 109 return false;
110 } 110 }
111 111
112 return true; 112 return true;
113 } 113 }
114 114
115 inline void GrDistanceFieldTextContext::init(const GrPaint& paint, const SkPaint & skPaint) { 115 inline void GrDistanceFieldTextContext::init(GrRenderTarget* rt, const GrPaint& paint,
116 GrTextContext::init(paint, skPaint); 116 const SkPaint& skPaint) {
117 GrTextContext::init(rt, paint, skPaint);
117 118
118 fStrike = NULL; 119 fStrike = NULL;
119 120
120 const SkMatrix& ctm = fViewMatrix; 121 const SkMatrix& ctm = fViewMatrix;
121 122
122 // getMaxScale doesn't support perspective, so neither do we at the moment 123 // getMaxScale doesn't support perspective, so neither do we at the moment
123 SkASSERT(!ctm.hasPerspective()); 124 SkASSERT(!ctm.hasPerspective());
124 SkScalar maxScale = ctm.getMaxScale(); 125 SkScalar maxScale = ctm.getMaxScale();
125 SkScalar textSize = fSkPaint.getTextSize(); 126 SkScalar textSize = fSkPaint.getTextSize();
126 SkScalar scaledTextSize = textSize; 127 SkScalar scaledTextSize = textSize;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 if (NULL == *gammaTexture) { 200 if (NULL == *gammaTexture) {
200 return; 201 return;
201 } 202 }
202 203
203 (*gammaTexture)->writePixels(0, 0, width, height, 204 (*gammaTexture)->writePixels(0, 0, width, height,
204 (*gammaTexture)->config(), data.get(), 0, 205 (*gammaTexture)->config(), data.get(), 0,
205 GrContext::kDontFlush_PixelOpsFlag); 206 GrContext::kDontFlush_PixelOpsFlag);
206 } 207 }
207 } 208 }
208 209
209 void GrDistanceFieldTextContext::onDrawText(const GrPaint& paint, const SkPaint& skPaint, 210 void GrDistanceFieldTextContext::onDrawText(GrRenderTarget* rt, const GrPaint& p aint,
210 const SkMatrix& viewMatrix, 211 const SkPaint& skPaint, const SkMatr ix& viewMatrix,
211 const char text[], size_t byteLength , 212 const char text[], size_t byteLength ,
212 SkScalar x, SkScalar y) { 213 SkScalar x, SkScalar y) {
213 SkASSERT(byteLength == 0 || text != NULL); 214 SkASSERT(byteLength == 0 || text != NULL);
214 215
215 // nothing to draw 216 // nothing to draw
216 if (text == NULL || byteLength == 0) { 217 if (text == NULL || byteLength == 0) {
217 return; 218 return;
218 } 219 }
219 220
220 fViewMatrix = viewMatrix; 221 fViewMatrix = viewMatrix;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 alignX = SkScalarHalf(alignX); 261 alignX = SkScalarHalf(alignX);
261 alignY = SkScalarHalf(alignY); 262 alignY = SkScalarHalf(alignY);
262 } else if (skPaint.getTextAlign() == SkPaint::kLeft_Align) { 263 } else if (skPaint.getTextAlign() == SkPaint::kLeft_Align) {
263 alignX = 0; 264 alignX = 0;
264 alignY = 0; 265 alignY = 0;
265 } 266 }
266 x -= alignX; 267 x -= alignX;
267 y -= alignY; 268 y -= alignY;
268 SkPoint offset = SkPoint::Make(x, y); 269 SkPoint offset = SkPoint::Make(x, y);
269 270
270 this->drawPosText(paint, skPaint, viewMatrix, text, byteLength, positions.be gin(), 2, offset); 271 this->drawPosText(rt, paint, skPaint, viewMatrix, text, byteLength, position s.begin(), 2,
272 offset);
271 } 273 }
272 274
273 void GrDistanceFieldTextContext::onDrawPosText(const GrPaint& paint, const SkPai nt& skPaint, 275 void GrDistanceFieldTextContext::onDrawPosText(GrRenderTarget* rt, const GrPaint & paint,
274 const SkMatrix& viewMatrix, 276 const SkPaint& skPaint, const SkM atrix& viewMatrix,
275 const char text[], size_t byteLen gth, 277 const char text[], size_t byteLen gth,
276 const SkScalar pos[], int scalars PerPosition, 278 const SkScalar pos[], int scalars PerPosition,
277 const SkPoint& offset) { 279 const SkPoint& offset) {
278 280
279 SkASSERT(byteLength == 0 || text != NULL); 281 SkASSERT(byteLength == 0 || text != NULL);
280 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); 282 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
281 283
282 // nothing to draw 284 // nothing to draw
283 if (text == NULL || byteLength == 0 /* no raster clip? || fRC->isEmpty()*/) { 285 if (text == NULL || byteLength == 0 /* no raster clip? || fRC->isEmpty()*/) {
284 return; 286 return;
285 } 287 }
286 288
287 fViewMatrix = viewMatrix; 289 fViewMatrix = viewMatrix;
288 this->init(paint, skPaint); 290 this->init(rt, paint, skPaint);
289 291
290 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); 292 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
291 293
292 SkAutoGlyphCacheNoGamma autoCache(fSkPaint, &fDeviceProperties, NULL); 294 SkAutoGlyphCacheNoGamma autoCache(fSkPaint, &fDeviceProperties, NULL);
293 SkGlyphCache* cache = autoCache.getCache(); 295 SkGlyphCache* cache = autoCache.getCache();
294 GrFontScaler* fontScaler = GetGrFontScaler(cache); 296 GrFontScaler* fontScaler = GetGrFontScaler(cache);
295 297
296 setup_gamma_texture(fContext, cache, fDeviceProperties, &fGammaTexture); 298 setup_gamma_texture(fContext, cache, fDeviceProperties, &fGammaTexture);
297 299
298 int numGlyphs = fSkPaint.textToGlyphs(text, byteLength, NULL); 300 int numGlyphs = fSkPaint.textToGlyphs(text, byteLength, NULL);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 } 355 }
354 } 356 }
355 } 357 }
356 pos += scalarsPerPosition; 358 pos += scalarsPerPosition;
357 } 359 }
358 } 360 }
359 361
360 this->finish(); 362 this->finish();
361 363
362 if (fallbackTxt.count() > 0) { 364 if (fallbackTxt.count() > 0) {
363 fFallbackTextContext->drawPosText(paint, skPaint, viewMatrix, fallbackTx t.begin(), 365 fFallbackTextContext->drawPosText(rt, paint, skPaint, viewMatrix, fallba ckTxt.begin(),
364 fallbackTxt.count(), fallbackPos.begin (), 366 fallbackTxt.count(), fallbackPos.begin (),
365 scalarsPerPosition, offset); 367 scalarsPerPosition, offset);
366 } 368 }
367 } 369 }
368 370
369 static inline GrColor skcolor_to_grcolor_nopremultiply(SkColor c) { 371 static inline GrColor skcolor_to_grcolor_nopremultiply(SkColor c) {
370 unsigned r = SkColorGetR(c); 372 unsigned r = SkColorGetR(c);
371 unsigned g = SkColorGetG(c); 373 unsigned g = SkColorGetG(c);
372 unsigned b = SkColorGetB(c); 374 unsigned b = SkColorGetB(c);
373 return GrColorPackRGBA(r, g, b, 0xff); 375 return GrColorPackRGBA(r, g, b, 0xff);
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 this->flush(); 564 this->flush();
563 565
564 SkMatrix ctm; 566 SkMatrix ctm;
565 ctm.setScale(fTextRatio, fTextRatio); 567 ctm.setScale(fTextRatio, fTextRatio);
566 ctm.postTranslate(sx - dx, sy - dy); 568 ctm.postTranslate(sx - dx, sy - dy);
567 569
568 SkPath tmpPath(*glyph->fPath); 570 SkPath tmpPath(*glyph->fPath);
569 tmpPath.transform(ctm); 571 tmpPath.transform(ctm);
570 572
571 GrStrokeInfo strokeInfo(SkStrokeRec::kFill_InitStyle); 573 GrStrokeInfo strokeInfo(SkStrokeRec::kFill_InitStyle);
572 fContext->drawPath(fPaint, fViewMatrix, tmpPath, strokeInfo); 574 fContext->drawPath(fRenderTarget, fPaint, fViewMatrix, tmpPath, stro keInfo);
573 575
574 // remove this glyph from the vertices we need to allocate 576 // remove this glyph from the vertices we need to allocate
575 fTotalVertexCount -= kVerticesPerGlyph; 577 fTotalVertexCount -= kVerticesPerGlyph;
576 return true; 578 return true;
577 } 579 }
578 } 580 }
579 581
580 SkASSERT(glyph->fPlot); 582 SkASSERT(glyph->fPlot);
581 GrDrawTarget::DrawToken drawToken = fDrawTarget->getCurrentDrawToken(); 583 GrDrawTarget::DrawToken drawToken = fDrawTarget->getCurrentDrawToken();
582 glyph->fPlot->setDrawToken(drawToken); 584 glyph->fPlot->setDrawToken(drawToken);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 return true; 661 return true;
660 } 662 }
661 663
662 void GrDistanceFieldTextContext::flush() { 664 void GrDistanceFieldTextContext::flush() {
663 if (NULL == fDrawTarget) { 665 if (NULL == fDrawTarget) {
664 return; 666 return;
665 } 667 }
666 668
667 if (fCurrVertex > 0) { 669 if (fCurrVertex > 0) {
668 GrPipelineBuilder pipelineBuilder; 670 GrPipelineBuilder pipelineBuilder;
669 pipelineBuilder.setFromPaint(fPaint, fContext->getRenderTarget()); 671 pipelineBuilder.setFromPaint(fPaint, fRenderTarget);
670 672
671 // setup our sampler state for our text texture/atlas 673 // setup our sampler state for our text texture/atlas
672 SkASSERT(SkIsAlign4(fCurrVertex)); 674 SkASSERT(SkIsAlign4(fCurrVertex));
673 675
674 // get our current color 676 // get our current color
675 SkColor filteredColor; 677 SkColor filteredColor;
676 SkColorFilter* colorFilter = fSkPaint.getColorFilter(); 678 SkColorFilter* colorFilter = fSkPaint.getColorFilter();
677 if (colorFilter) { 679 if (colorFilter) {
678 filteredColor = colorFilter->filterColor(fSkPaint.getColor()); 680 filteredColor = colorFilter->filterColor(fSkPaint.getColor());
679 } else { 681 } else {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 } 715 }
714 } 716 }
715 717
716 inline void GrDistanceFieldTextContext::finish() { 718 inline void GrDistanceFieldTextContext::finish() {
717 this->flush(); 719 this->flush();
718 fTotalVertexCount = 0; 720 fTotalVertexCount = 0;
719 721
720 GrTextContext::finish(); 722 GrTextContext::finish();
721 } 723 }
722 724
OLDNEW
« no previous file with comments | « src/gpu/GrDistanceFieldTextContext.h ('k') | src/gpu/GrStencilAndCoverTextContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698