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

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

Issue 663423003: Allocate only the vertices we need for text. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Address comments Created 6 years, 1 month 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/GrTextContext.h ('k') | no next file » | 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 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 10
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 return true; 69 return true;
70 } 70 }
71 textContext = textContext->fFallbackTextContext; 71 textContext = textContext->fFallbackTextContext;
72 } while (textContext); 72 } while (textContext);
73 73
74 return false; 74 return false;
75 } 75 }
76 76
77 77
78 //*** change to output positions? 78 //*** change to output positions?
79 void GrTextContext::MeasureText(SkGlyphCache* cache, SkDrawCacheProc glyphCacheP roc, 79 int GrTextContext::MeasureText(SkGlyphCache* cache, SkDrawCacheProc glyphCachePr oc,
80 const char text[], size_t byteLength, SkVector* stopVector) { 80 const char text[], size_t byteLength, SkVector* stopVector) {
81 SkFixed x = 0, y = 0; 81 SkFixed x = 0, y = 0;
82 const char* stop = text + byteLength; 82 const char* stop = text + byteLength;
83 83
84 SkAutoKern autokern; 84 SkAutoKern autokern;
85 85
86 int numGlyphs = 0;
86 while (text < stop) { 87 while (text < stop) {
87 // don't need x, y here, since all subpixel variants will have the 88 // don't need x, y here, since all subpixel variants will have the
88 // same advance 89 // same advance
89 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); 90 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0);
90 91
91 x += autokern.adjust(glyph) + glyph.fAdvanceX; 92 x += autokern.adjust(glyph) + glyph.fAdvanceX;
92 y += glyph.fAdvanceY; 93 y += glyph.fAdvanceY;
94 ++numGlyphs;
93 } 95 }
94 stopVector->set(SkFixedToScalar(x), SkFixedToScalar(y)); 96 stopVector->set(SkFixedToScalar(x), SkFixedToScalar(y));
95 97
96 SkASSERT(text == stop); 98 SkASSERT(text == stop);
99
100 return numGlyphs;
97 } 101 }
98 102
99 static void GlyphCacheAuxProc(void* data) { 103 static void GlyphCacheAuxProc(void* data) {
100 GrFontScaler* scaler = (GrFontScaler*)data; 104 GrFontScaler* scaler = (GrFontScaler*)data;
101 SkSafeUnref(scaler); 105 SkSafeUnref(scaler);
102 } 106 }
103 107
104 GrFontScaler* GrTextContext::GetGrFontScaler(SkGlyphCache* cache) { 108 GrFontScaler* GrTextContext::GetGrFontScaler(SkGlyphCache* cache) {
105 void* auxData; 109 void* auxData;
106 GrFontScaler* scaler = NULL; 110 GrFontScaler* scaler = NULL;
107 111
108 if (cache->getAuxProcData(GlyphCacheAuxProc, &auxData)) { 112 if (cache->getAuxProcData(GlyphCacheAuxProc, &auxData)) {
109 scaler = (GrFontScaler*)auxData; 113 scaler = (GrFontScaler*)auxData;
110 } 114 }
111 if (NULL == scaler) { 115 if (NULL == scaler) {
112 scaler = SkNEW_ARGS(GrFontScaler, (cache)); 116 scaler = SkNEW_ARGS(GrFontScaler, (cache));
113 cache->setAuxProc(GlyphCacheAuxProc, scaler); 117 cache->setAuxProc(GlyphCacheAuxProc, scaler);
114 } 118 }
115 119
116 return scaler; 120 return scaler;
117 } 121 }
OLDNEW
« no previous file with comments | « src/gpu/GrTextContext.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698