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

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

Issue 12531015: Adds local coords to GrEffect system. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « src/gpu/GrSWMaskHelper.cpp ('k') | src/gpu/effects/GrConfigConversionEffect.cpp » ('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 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 8
9 9
10 #include "GrTextContext.h" 10 #include "GrTextContext.h"
11 #include "GrAtlas.h" 11 #include "GrAtlas.h"
12 #include "GrContext.h" 12 #include "GrContext.h"
13 #include "GrDrawTarget.h" 13 #include "GrDrawTarget.h"
14 #include "GrFontScaler.h" 14 #include "GrFontScaler.h"
15 #include "GrIndexBuffer.h" 15 #include "GrIndexBuffer.h"
16 #include "GrTextStrike.h" 16 #include "GrTextStrike.h"
17 #include "GrTextStrike_impl.h" 17 #include "GrTextStrike_impl.h"
18 #include "SkPath.h" 18 #include "SkPath.h"
19 #include "SkStrokeRec.h" 19 #include "SkStrokeRec.h"
20 20
21 enum { 21 // glyph rendering shares this stage with edge rendering (kEdgeEffectStage in Gr Context) && SW path
22 // glyph rendering shares this stage with edge rendering 22 // rendering (kPathMaskStage in GrSWMaskHelper)
23 // (kEdgeEffectStage in GrContext) && SW path rendering 23 static const int kGlyphMaskStage = GrPaint::kTotalStages;
24 // (kPathMaskStage in GrSWMaskHelper) 24 static const int kGlyphCoordsAttributeIndex = 1;
25 kGlyphMaskStage = GrPaint::kTotalStages,
26 };
27 25
28 void GrTextContext::flushGlyphs() { 26 void GrTextContext::flushGlyphs() {
29 if (NULL == fDrawTarget) { 27 if (NULL == fDrawTarget) {
30 return; 28 return;
31 } 29 }
32 GrDrawState* drawState = fDrawTarget->drawState(); 30 GrDrawState* drawState = fDrawTarget->drawState();
33 if (fCurrVertex > 0) { 31 if (fCurrVertex > 0) {
34 // setup our sampler state for our text texture/atlas 32 // setup our sampler state for our text texture/atlas
35 GrAssert(GrIsALIGN4(fCurrVertex)); 33 GrAssert(GrIsALIGN4(fCurrVertex));
36 GrAssert(fCurrTexture); 34 GrAssert(fCurrTexture);
37 GrTextureParams params(SkShader::kRepeat_TileMode, false); 35 GrTextureParams params(SkShader::kRepeat_TileMode, false);
38 drawState->createTextureEffect(kGlyphMaskStage, fCurrTexture, SkMatrix:: I(), params); 36
37 // This effect could be stored with one of the cache objects (atlas?)
38 drawState->setEffect(kGlyphMaskStage,
39 GrSimpleTextureEffect::CreateWithCustomCoords(fCurr Texture, params),
40 kGlyphCoordsAttributeIndex)->unref();
39 41
40 if (!GrPixelConfigIsAlphaOnly(fCurrTexture->config())) { 42 if (!GrPixelConfigIsAlphaOnly(fCurrTexture->config())) {
41 if (kOne_GrBlendCoeff != fPaint.getSrcBlendCoeff() || 43 if (kOne_GrBlendCoeff != fPaint.getSrcBlendCoeff() ||
42 kISA_GrBlendCoeff != fPaint.getDstBlendCoeff() || 44 kISA_GrBlendCoeff != fPaint.getDstBlendCoeff() ||
43 fPaint.hasColorStage()) { 45 fPaint.hasColorStage()) {
44 GrPrintf("LCD Text will not draw correctly.\n"); 46 GrPrintf("LCD Text will not draw correctly.\n");
45 } 47 }
46 // setup blend so that we get mask * paintColor + (1-mask)*dstColor 48 // setup blend so that we get mask * paintColor + (1-mask)*dstColor
47 drawState->setBlendConstant(fPaint.getColor()); 49 drawState->setBlendConstant(fPaint.getColor());
48 drawState->setBlendFunc(kConstC_GrBlendCoeff, kISC_GrBlendCoeff); 50 drawState->setBlendFunc(kConstC_GrBlendCoeff, kISC_GrBlendCoeff);
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 fCurrTexture = texture; 190 fCurrTexture = texture;
189 fCurrTexture->ref(); 191 fCurrTexture->ref();
190 } 192 }
191 193
192 if (NULL == fVertices) { 194 if (NULL == fVertices) {
193 // position + texture coord 195 // position + texture coord
194 static const GrVertexAttrib kVertexAttribs[] = { 196 static const GrVertexAttrib kVertexAttribs[] = {
195 {kVec2f_GrVertexAttribType, 0}, 197 {kVec2f_GrVertexAttribType, 0},
196 {kVec2f_GrVertexAttribType, sizeof(GrPoint)} 198 {kVec2f_GrVertexAttribType, sizeof(GrPoint)}
197 }; 199 };
198 static const GrAttribBindings kAttribBindings = GrDrawState::ExplicitTex CoordAttribBindingsBit(kGlyphMaskStage); 200 static const GrAttribBindings kAttribBindings = 0;
199 201
200 // If we need to reserve vertices allow the draw target to suggest 202 // If we need to reserve vertices allow the draw target to suggest
201 // a number of verts to reserve and whether to perform a flush. 203 // a number of verts to reserve and whether to perform a flush.
202 fMaxVertices = kMinRequestedVerts; 204 fMaxVertices = kMinRequestedVerts;
203 bool flush = false; 205 bool flush = false;
204 fDrawTarget = fContext->getTextTarget(fPaint); 206 fDrawTarget = fContext->getTextTarget(fPaint);
205 if (NULL != fDrawTarget) { 207 if (NULL != fDrawTarget) {
206 fDrawTarget->drawState()->setVertexAttribs(kVertexAttribs, SK_ARRAY_ COUNT(kVertexAttribs)); 208 fDrawTarget->drawState()->setVertexAttribs(kVertexAttribs, SK_ARRAY_ COUNT(kVertexAttribs));
207 flush = fDrawTarget->geometryHints(&fMaxVertices, NULL); 209 flush = fDrawTarget->geometryHints(&fMaxVertices, NULL);
208 } 210 }
209 if (flush) { 211 if (flush) {
210 this->flushGlyphs(); 212 this->flushGlyphs();
211 fContext->flush(); 213 fContext->flush();
212 // flushGlyphs() will reset fDrawTarget to NULL. 214 // flushGlyphs() will reset fDrawTarget to NULL.
213 fDrawTarget = fContext->getTextTarget(fPaint); 215 fDrawTarget = fContext->getTextTarget(fPaint);
214 fDrawTarget->drawState()->setVertexAttribs(kVertexAttribs, SK_ARRAY_ COUNT(kVertexAttribs)); 216 fDrawTarget->drawState()->setVertexAttribs(kVertexAttribs, SK_ARRAY_ COUNT(kVertexAttribs));
215 } 217 }
216 fDrawTarget->drawState()->setAttribIndex(GrDrawState::kPosition_AttribIn dex, 0); 218 fDrawTarget->drawState()->setAttribIndex(GrDrawState::kPosition_AttribIn dex, 0);
217 fDrawTarget->drawState()->setAttribIndex(GrDrawState::kTexCoord_AttribIn dex, 1);
218 fDrawTarget->drawState()->setAttribBindings(kAttribBindings); 219 fDrawTarget->drawState()->setAttribBindings(kAttribBindings);
219 fMaxVertices = kDefaultRequestedVerts; 220 fMaxVertices = kDefaultRequestedVerts;
220 // ignore return, no point in flushing again. 221 // ignore return, no point in flushing again.
221 fDrawTarget->geometryHints(&fMaxVertices, NULL); 222 fDrawTarget->geometryHints(&fMaxVertices, NULL);
222 223
223 int maxQuadVertices = 4 * fContext->getQuadIndexBuffer()->maxQuads(); 224 int maxQuadVertices = 4 * fContext->getQuadIndexBuffer()->maxQuads();
224 if (fMaxVertices < kMinRequestedVerts) { 225 if (fMaxVertices < kMinRequestedVerts) {
225 fMaxVertices = kDefaultRequestedVerts; 226 fMaxVertices = kDefaultRequestedVerts;
226 } else if (fMaxVertices > maxQuadVertices) { 227 } else if (fMaxVertices > maxQuadVertices) {
227 // don't exceed the limit of the index buffer 228 // don't exceed the limit of the index buffer
(...skipping 16 matching lines...) Expand all
244 SkFixedToFloat(vx + width), 245 SkFixedToFloat(vx + width),
245 SkFixedToFloat(vy + height), 246 SkFixedToFloat(vy + height),
246 2 * sizeof(SkPoint)); 247 2 * sizeof(SkPoint));
247 fVertices[2*fCurrVertex+1].setRectFan(SkFixedToFloat(texture->normalizeFixed X(tx)), 248 fVertices[2*fCurrVertex+1].setRectFan(SkFixedToFloat(texture->normalizeFixed X(tx)),
248 SkFixedToFloat(texture->normalizeFixed Y(ty)), 249 SkFixedToFloat(texture->normalizeFixed Y(ty)),
249 SkFixedToFloat(texture->normalizeFixed X(tx + width)), 250 SkFixedToFloat(texture->normalizeFixed X(tx + width)),
250 SkFixedToFloat(texture->normalizeFixed Y(ty + height)), 251 SkFixedToFloat(texture->normalizeFixed Y(ty + height)),
251 2 * sizeof(SkPoint)); 252 2 * sizeof(SkPoint));
252 fCurrVertex += 4; 253 fCurrVertex += 4;
253 } 254 }
OLDNEW
« no previous file with comments | « src/gpu/GrSWMaskHelper.cpp ('k') | src/gpu/effects/GrConfigConversionEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698