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

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: Rebase to ToT 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
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 fStrike = NULL;
28
29 fCurrTexture = NULL;
30 fCurrVertex = 0;
31
32 fVertices = NULL;
33 fMaxVertices = 0;
34 }
35
36 GrBitmapTextContext::~GrBitmapTextContext() {
37 this->flushGlyphs();
38 }
39
40 void GrBitmapTextContext::flush() {
41 this->flushGlyphs();
42 }
43
44 void GrBitmapTextContext::flushGlyphs() {
29 if (NULL == fDrawTarget) { 45 if (NULL == fDrawTarget) {
30 return; 46 return;
31 } 47 }
32 48
33 GrDrawState* drawState = fDrawTarget->drawState(); 49 GrDrawState* drawState = fDrawTarget->drawState();
34 GrDrawState::AutoRestoreEffects are(drawState); 50 GrDrawState::AutoRestoreEffects are(drawState);
35 drawState->setFromPaint(fPaint, SkMatrix::I(), fContext->getRenderTarget()); 51 drawState->setFromPaint(fPaint, SkMatrix::I(), fContext->getRenderTarget());
36 52
37 if (fCurrVertex > 0) { 53 if (fCurrVertex > 0) {
38 // setup our sampler state for our text texture/atlas 54 // setup our sampler state for our text texture/atlas
(...skipping 30 matching lines...) Expand all
69 nGlyphs, 85 nGlyphs,
70 4, 6); 86 4, 6);
71 fDrawTarget->resetVertexSource(); 87 fDrawTarget->resetVertexSource();
72 fVertices = NULL; 88 fVertices = NULL;
73 fMaxVertices = 0; 89 fMaxVertices = 0;
74 fCurrVertex = 0; 90 fCurrVertex = 0;
75 SkSafeSetNull(fCurrTexture); 91 SkSafeSetNull(fCurrTexture);
76 } 92 }
77 } 93 }
78 94
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 { 95 namespace {
115 96
116 // position + texture coord 97 // position + texture coord
117 extern const GrVertexAttrib gTextVertexAttribs[] = { 98 extern const GrVertexAttrib gTextVertexAttribs[] = {
118 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding }, 99 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding },
119 {kVec2f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribBinding} 100 {kVec2f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribBinding}
120 }; 101 };
121 102
122 }; 103 };
123 104
124 void GrTextContext::drawPackedGlyph(GrGlyph::PackedID packed, 105 void GrBitmapTextContext::drawPackedGlyph(GrGlyph::PackedID packed,
125 GrFixed vx, GrFixed vy, 106 GrFixed vx, GrFixed vy,
126 GrFontScaler* scaler) { 107 GrFontScaler* scaler) {
127 if (NULL == fDrawTarget) { 108 if (NULL == fDrawTarget) {
128 return; 109 return;
129 } 110 }
130 if (NULL == fStrike) { 111 if (NULL == fStrike) {
131 fStrike = fContext->getFontCache()->getStrike(scaler); 112 fStrike = fContext->getFontCache()->getStrike(scaler);
132 } 113 }
133 114
134 GrGlyph* glyph = fStrike->getGlyph(packed, scaler); 115 GrGlyph* glyph = fStrike->getGlyph(packed, scaler);
135 if (NULL == glyph || glyph->fBounds.isEmpty()) { 116 if (NULL == glyph || glyph->fBounds.isEmpty()) {
136 return; 117 return;
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 SkFixedToFloat(vx + width), 241 SkFixedToFloat(vx + width),
261 SkFixedToFloat(vy + height), 242 SkFixedToFloat(vy + height),
262 2 * sizeof(SkPoint)); 243 2 * sizeof(SkPoint));
263 fVertices[2*fCurrVertex+1].setRectFan(SkFixedToFloat(texture->normalizeFixed X(tx)), 244 fVertices[2*fCurrVertex+1].setRectFan(SkFixedToFloat(texture->normalizeFixed X(tx)),
264 SkFixedToFloat(texture->normalizeFixed Y(ty)), 245 SkFixedToFloat(texture->normalizeFixed Y(ty)),
265 SkFixedToFloat(texture->normalizeFixed X(tx + width)), 246 SkFixedToFloat(texture->normalizeFixed X(tx + width)),
266 SkFixedToFloat(texture->normalizeFixed Y(ty + height)), 247 SkFixedToFloat(texture->normalizeFixed Y(ty + height)),
267 2 * sizeof(SkPoint)); 248 2 * sizeof(SkPoint));
268 fCurrVertex += 4; 249 fCurrVertex += 4;
269 } 250 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698