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/GrBitmapTextContext.cpp

Issue 27199002: Split out GrBitmapTextContext from GrTextContext. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Update based on comments Created 7 years, 2 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 | « include/gpu/GrTextContext.h ('k') | src/gpu/GrTextContext.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 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 8 #include "GrBitmapTextContext.h"
9
10 #include "GrTextContext.h"
11 #include "GrAtlas.h" 9 #include "GrAtlas.h"
12 #include "GrContext.h"
13 #include "GrDrawTarget.h" 10 #include "GrDrawTarget.h"
14 #include "GrFontScaler.h" 11 #include "GrFontScaler.h"
15 #include "GrIndexBuffer.h" 12 #include "GrIndexBuffer.h"
16 #include "GrTextStrike.h" 13 #include "GrTextStrike.h"
17 #include "GrTextStrike_impl.h" 14 #include "GrTextStrike_impl.h"
18 #include "SkPath.h" 15 #include "SkPath.h"
19 #include "SkRTConf.h" 16 #include "SkRTConf.h"
20 #include "SkStrokeRec.h" 17 #include "SkStrokeRec.h"
21 #include "effects/GrCustomCoordsTextureEffect.h" 18 #include "effects/GrCustomCoordsTextureEffect.h"
22 19
23 static const int kGlyphCoordsAttributeIndex = 1; 20 static const int kGlyphCoordsAttributeIndex = 1;
24 21
25 SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false, 22 SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false,
26 "Dump the contents of the font cache before every purge."); 23 "Dump the contents of the font cache before every purge.");
27 24
28 void GrTextContext::flushGlyphs() { 25 GrBitmapTextContext::GrBitmapTextContext(GrContext* context, const GrPaint& pain t) :
26 GrTextContext(context, paint) {
27 fAutoMatrix.setIdentity(fContext, &fPaint);
28
29 fStrike = NULL;
30
31 fCurrTexture = NULL;
32 fCurrVertex = 0;
33
34 fVertices = NULL;
35 fMaxVertices = 0;
36 }
37
38 GrBitmapTextContext::~GrBitmapTextContext() {
39 this->flushGlyphs();
40 }
41
42 void GrBitmapTextContext::flushGlyphs() {
29 if (NULL == fDrawTarget) { 43 if (NULL == fDrawTarget) {
30 return; 44 return;
31 } 45 }
32 46
33 GrDrawState* drawState = fDrawTarget->drawState(); 47 GrDrawState* drawState = fDrawTarget->drawState();
34 GrDrawState::AutoRestoreEffects are(drawState); 48 GrDrawState::AutoRestoreEffects are(drawState);
35 drawState->setFromPaint(fPaint, SkMatrix::I(), fContext->getRenderTarget()); 49 drawState->setFromPaint(fPaint, SkMatrix::I(), fContext->getRenderTarget());
36 50
37 if (fCurrVertex > 0) { 51 if (fCurrVertex > 0) {
38 // setup our sampler state for our text texture/atlas 52 // setup our sampler state for our text texture/atlas
(...skipping 30 matching lines...) Expand all
69 nGlyphs, 83 nGlyphs,
70 4, 6); 84 4, 6);
71 fDrawTarget->resetVertexSource(); 85 fDrawTarget->resetVertexSource();
72 fVertices = NULL; 86 fVertices = NULL;
73 fMaxVertices = 0; 87 fMaxVertices = 0;
74 fCurrVertex = 0; 88 fCurrVertex = 0;
75 SkSafeSetNull(fCurrTexture); 89 SkSafeSetNull(fCurrTexture);
76 } 90 }
77 } 91 }
78 92
79 GrTextContext::GrTextContext(GrContext* context, const GrPaint& paint) : fPaint( paint) {
80 fContext = context;
81 fStrike = NULL;
82
83 fCurrTexture = NULL;
84 fCurrVertex = 0;
85
86 const GrClipData* clipData = context->getClip();
87
88 SkRect devConservativeBound;
89 clipData->fClipStack->getConservativeBounds(
90 -clipData->fOrigin.fX,
91 -clipData->fOrigin.fY,
92 context->getRenderTarget()->width(),
93 context->getRenderTarget()->height(),
94 &devConservativeBound);
95
96 devConservativeBound.roundOut(&fClipRect);
97
98 fAutoMatrix.setIdentity(fContext, &fPaint);
99
100 fDrawTarget = fContext->getTextTarget();
101
102 fVertices = NULL;
103 fMaxVertices = 0;
104 }
105
106 GrTextContext::~GrTextContext() {
107 this->flushGlyphs();
108 }
109
110 void GrTextContext::flush() {
111 this->flushGlyphs();
112 }
113
114 namespace { 93 namespace {
115 94
116 // position + texture coord 95 // position + texture coord
117 extern const GrVertexAttrib gTextVertexAttribs[] = { 96 extern const GrVertexAttrib gTextVertexAttribs[] = {
118 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding }, 97 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding },
119 {kVec2f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribBinding} 98 {kVec2f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribBinding}
120 }; 99 };
121 100
122 }; 101 };
123 102
124 void GrTextContext::drawPackedGlyph(GrGlyph::PackedID packed, 103 void GrBitmapTextContext::drawPackedGlyph(GrGlyph::PackedID packed,
125 GrFixed vx, GrFixed vy, 104 GrFixed vx, GrFixed vy,
126 GrFontScaler* scaler) { 105 GrFontScaler* scaler) {
127 if (NULL == fDrawTarget) { 106 if (NULL == fDrawTarget) {
128 return; 107 return;
129 } 108 }
130 if (NULL == fStrike) { 109 if (NULL == fStrike) {
131 fStrike = fContext->getFontCache()->getStrike(scaler); 110 fStrike = fContext->getFontCache()->getStrike(scaler);
132 } 111 }
133 112
134 GrGlyph* glyph = fStrike->getGlyph(packed, scaler); 113 GrGlyph* glyph = fStrike->getGlyph(packed, scaler);
135 if (NULL == glyph || glyph->fBounds.isEmpty()) { 114 if (NULL == glyph || glyph->fBounds.isEmpty()) {
136 return; 115 return;
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 SkFixedToFloat(vx + width), 239 SkFixedToFloat(vx + width),
261 SkFixedToFloat(vy + height), 240 SkFixedToFloat(vy + height),
262 2 * sizeof(SkPoint)); 241 2 * sizeof(SkPoint));
263 fVertices[2*fCurrVertex+1].setRectFan(SkFixedToFloat(texture->normalizeFixed X(tx)), 242 fVertices[2*fCurrVertex+1].setRectFan(SkFixedToFloat(texture->normalizeFixed X(tx)),
264 SkFixedToFloat(texture->normalizeFixed Y(ty)), 243 SkFixedToFloat(texture->normalizeFixed Y(ty)),
265 SkFixedToFloat(texture->normalizeFixed X(tx + width)), 244 SkFixedToFloat(texture->normalizeFixed X(tx + width)),
266 SkFixedToFloat(texture->normalizeFixed Y(ty + height)), 245 SkFixedToFloat(texture->normalizeFixed Y(ty + height)),
267 2 * sizeof(SkPoint)); 246 2 * sizeof(SkPoint));
268 fCurrVertex += 4; 247 fCurrVertex += 4;
269 } 248 }
OLDNEW
« no previous file with comments | « include/gpu/GrTextContext.h ('k') | src/gpu/GrTextContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698