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

Side by Side Diff: src/gpu/batches/GrAtlasTextBatch.cpp

Issue 2041113004: sk_sp for gpu. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Reserve correctly. Created 4 years, 6 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/batches/GrAtlasTextBatch.h ('k') | src/gpu/batches/GrDefaultPathRenderer.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 2015 Google Inc. 2 * Copyright 2015 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 "GrAtlasTextBatch.h" 8 #include "GrAtlasTextBatch.h"
9 9
10 #include "GrBatchFlushState.h" 10 #include "GrBatchFlushState.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 GrTexture* texture = fFontCache->getTexture(this->maskFormat()); 93 GrTexture* texture = fFontCache->getTexture(this->maskFormat());
94 if (!texture) { 94 if (!texture) {
95 SkDebugf("Could not allocate backing texture for atlas\n"); 95 SkDebugf("Could not allocate backing texture for atlas\n");
96 return; 96 return;
97 } 97 }
98 98
99 GrMaskFormat maskFormat = this->maskFormat(); 99 GrMaskFormat maskFormat = this->maskFormat();
100 100
101 FlushInfo flushInfo; 101 FlushInfo flushInfo;
102 if (this->usesDistanceFields()) { 102 if (this->usesDistanceFields()) {
103 flushInfo.fGeometryProcessor.reset( 103 flushInfo.fGeometryProcessor =
104 this->setupDfProcessor(this->viewMatrix(), fFilteredColor, this->col or(), texture)); 104 this->setupDfProcessor(this->viewMatrix(), fFilteredColor, this->col or(), texture);
105 } else { 105 } else {
106 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kNone _FilterMode); 106 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kNone _FilterMode);
107 flushInfo.fGeometryProcessor.reset( 107 flushInfo.fGeometryProcessor = GrBitmapTextGeoProc::Make(this->color(),
108 GrBitmapTextGeoProc::Create(this->color(), 108 texture,
109 texture, 109 params,
110 params, 110 maskFormat,
111 maskFormat, 111 localMatrix,
112 localMatrix, 112 this->usesLocal Coords());
113 this->usesLocalCoords()));
114 } 113 }
115 114
116 flushInfo.fGlyphsToFlush = 0; 115 flushInfo.fGlyphsToFlush = 0;
117 size_t vertexStride = flushInfo.fGeometryProcessor->getVertexStride(); 116 size_t vertexStride = flushInfo.fGeometryProcessor->getVertexStride();
118 SkASSERT(vertexStride == GrAtlasTextBlob::GetVertexStride(maskFormat)); 117 SkASSERT(vertexStride == GrAtlasTextBlob::GetVertexStride(maskFormat));
119 118
120 int glyphCount = this->numGlyphs(); 119 int glyphCount = this->numGlyphs();
121 const GrBuffer* vertexBuffer; 120 const GrBuffer* vertexBuffer;
122 121
123 void* vertices = target->makeVertexSpace(vertexStride, 122 void* vertices = target->makeVertexSpace(vertexStride,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 } 170 }
172 171
173 void GrAtlasTextBatch::flush(GrVertexBatch::Target* target, FlushInfo* flushInfo ) const { 172 void GrAtlasTextBatch::flush(GrVertexBatch::Target* target, FlushInfo* flushInfo ) const {
174 GrMesh mesh; 173 GrMesh mesh;
175 int maxGlyphsPerDraw = 174 int maxGlyphsPerDraw =
176 static_cast<int>(flushInfo->fIndexBuffer->gpuMemorySize() / sizeof(uint1 6_t) / 6); 175 static_cast<int>(flushInfo->fIndexBuffer->gpuMemorySize() / sizeof(uint1 6_t) / 6);
177 mesh.initInstanced(kTriangles_GrPrimitiveType, flushInfo->fVertexBuffer, 176 mesh.initInstanced(kTriangles_GrPrimitiveType, flushInfo->fVertexBuffer,
178 flushInfo->fIndexBuffer, flushInfo->fVertexOffset, 177 flushInfo->fIndexBuffer, flushInfo->fVertexOffset,
179 kVerticesPerGlyph, kIndicesPerGlyph, flushInfo->fGlyphsTo Flush, 178 kVerticesPerGlyph, kIndicesPerGlyph, flushInfo->fGlyphsTo Flush,
180 maxGlyphsPerDraw); 179 maxGlyphsPerDraw);
181 target->draw(flushInfo->fGeometryProcessor, mesh); 180 target->draw(flushInfo->fGeometryProcessor.get(), mesh);
182 flushInfo->fVertexOffset += kVerticesPerGlyph * flushInfo->fGlyphsToFlush; 181 flushInfo->fVertexOffset += kVerticesPerGlyph * flushInfo->fGlyphsToFlush;
183 flushInfo->fGlyphsToFlush = 0; 182 flushInfo->fGlyphsToFlush = 0;
184 } 183 }
185 184
186 bool GrAtlasTextBatch::onCombineIfPossible(GrBatch* t, const GrCaps& caps) { 185 bool GrAtlasTextBatch::onCombineIfPossible(GrBatch* t, const GrCaps& caps) {
187 GrAtlasTextBatch* that = t->cast<GrAtlasTextBatch>(); 186 GrAtlasTextBatch* that = t->cast<GrAtlasTextBatch>();
188 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeli ne(), 187 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeli ne(),
189 that->bounds(), caps)) { 188 that->bounds(), caps)) {
190 return false; 189 return false;
191 } 190 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 #endif 238 #endif
240 that->fGeoCount = 0; 239 that->fGeoCount = 0;
241 fGeoCount = newGeoCount; 240 fGeoCount = newGeoCount;
242 241
243 this->joinBounds(that->bounds()); 242 this->joinBounds(that->bounds());
244 return true; 243 return true;
245 } 244 }
246 245
247 // TODO just use class params 246 // TODO just use class params
248 // TODO trying to figure out why lcd is so whack 247 // TODO trying to figure out why lcd is so whack
249 GrGeometryProcessor* GrAtlasTextBatch::setupDfProcessor(const SkMatrix& viewMatr ix, 248 sk_sp<GrGeometryProcessor> GrAtlasTextBatch::setupDfProcessor(const SkMatrix& vi ewMatrix,
250 SkColor filteredColor, 249 SkColor filteredCo lor,
251 GrColor color, GrTexture * texture) const { 250 GrColor color,
251 GrTexture* texture ) const {
252 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kBilerp_F ilterMode); 252 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kBilerp_F ilterMode);
253 bool isLCD = this->isLCD(); 253 bool isLCD = this->isLCD();
254 // set up any flags 254 // set up any flags
255 uint32_t flags = viewMatrix.isSimilarity() ? kSimilarity_DistanceFieldEffect Flag : 0; 255 uint32_t flags = viewMatrix.isSimilarity() ? kSimilarity_DistanceFieldEffect Flag : 0;
256 flags |= viewMatrix.isScaleTranslate() ? kScaleOnly_DistanceFieldEffectFlag : 0; 256 flags |= viewMatrix.isScaleTranslate() ? kScaleOnly_DistanceFieldEffectFlag : 0;
257 flags |= fUseGammaCorrectDistanceTable ? kGammaCorrect_DistanceFieldEffectFl ag : 0; 257 flags |= fUseGammaCorrectDistanceTable ? kGammaCorrect_DistanceFieldEffectFl ag : 0;
258 258
259 // see if we need to create a new effect 259 // see if we need to create a new effect
260 if (isLCD) { 260 if (isLCD) {
261 flags |= kUseLCD_DistanceFieldEffectFlag; 261 flags |= kUseLCD_DistanceFieldEffectFlag;
262 flags |= fUseBGR ? kBGR_DistanceFieldEffectFlag : 0; 262 flags |= fUseBGR ? kBGR_DistanceFieldEffectFlag : 0;
263 263
264 GrColor colorNoPreMul = skcolor_to_grcolor_nopremultiply(filteredColor); 264 GrColor colorNoPreMul = skcolor_to_grcolor_nopremultiply(filteredColor);
265 265
266 float redCorrection = fDistanceAdjustTable->getAdjustment( 266 float redCorrection = fDistanceAdjustTable->getAdjustment(
267 GrColorUnpackR(colorNoPreMul) >> kDistanceAdjustLumShift, 267 GrColorUnpackR(colorNoPreMul) >> kDistanceAdjustLumShift,
268 fUseGammaCorrectDistanceTable); 268 fUseGammaCorrectDistanceTable);
269 float greenCorrection = fDistanceAdjustTable->getAdjustment( 269 float greenCorrection = fDistanceAdjustTable->getAdjustment(
270 GrColorUnpackG(colorNoPreMul) >> kDistanceAdjustLumShift, 270 GrColorUnpackG(colorNoPreMul) >> kDistanceAdjustLumShift,
271 fUseGammaCorrectDistanceTable); 271 fUseGammaCorrectDistanceTable);
272 float blueCorrection = fDistanceAdjustTable->getAdjustment( 272 float blueCorrection = fDistanceAdjustTable->getAdjustment(
273 GrColorUnpackB(colorNoPreMul) >> kDistanceAdjustLumShift, 273 GrColorUnpackB(colorNoPreMul) >> kDistanceAdjustLumShift,
274 fUseGammaCorrectDistanceTable); 274 fUseGammaCorrectDistanceTable);
275 GrDistanceFieldLCDTextGeoProc::DistanceAdjust widthAdjust = 275 GrDistanceFieldLCDTextGeoProc::DistanceAdjust widthAdjust =
276 GrDistanceFieldLCDTextGeoProc::DistanceAdjust::Make(redCorrection, 276 GrDistanceFieldLCDTextGeoProc::DistanceAdjust::Make(redCorrection,
277 greenCorrection, 277 greenCorrection,
278 blueCorrection); 278 blueCorrection);
279 279
280 return GrDistanceFieldLCDTextGeoProc::Create(color, 280 return GrDistanceFieldLCDTextGeoProc::Make(color,
281 viewMatrix, 281 viewMatrix,
282 texture, 282 texture,
283 params, 283 params,
284 widthAdjust, 284 widthAdjust,
285 flags, 285 flags,
286 this->usesLocalCoords()); 286 this->usesLocalCoords());
287 } else { 287 } else {
288 #ifdef SK_GAMMA_APPLY_TO_A8 288 #ifdef SK_GAMMA_APPLY_TO_A8
289 U8CPU lum = SkColorSpaceLuminance::computeLuminance(SK_GAMMA_EXPONENT, f ilteredColor); 289 U8CPU lum = SkColorSpaceLuminance::computeLuminance(SK_GAMMA_EXPONENT, f ilteredColor);
290 float correction = fDistanceAdjustTable->getAdjustment( 290 float correction = fDistanceAdjustTable->getAdjustment(
291 lum >> kDistanceAdjustLumShift, fUseGammaCorrectDistanceTable); 291 lum >> kDistanceAdjustLumShift, fUseGammaCorrectDistanceTable);
292 return GrDistanceFieldA8TextGeoProc::Create(color, 292 return GrDistanceFieldA8TextGeoProc::Make(color,
293 viewMatrix, 293 viewMatrix,
294 texture, 294 texture,
295 params, 295 params,
296 correction, 296 correction,
297 flags, 297 flags,
298 this->usesLocalCoords()); 298 this->usesLocalCoords());
299 #else 299 #else
300 return GrDistanceFieldA8TextGeoProc::Create(color, 300 return GrDistanceFieldA8TextGeoProc::Make(color,
301 viewMatrix, 301 viewMatrix,
302 texture, 302 texture,
303 params, 303 params,
304 flags, 304 flags,
305 this->usesLocalCoords()); 305 this->usesLocalCoords());
306 #endif 306 #endif
307 } 307 }
308 308
309 } 309 }
310 310
311 void GrBlobRegenHelper::flush() { 311 void GrBlobRegenHelper::flush() {
312 fBatch->flush(fTarget, fFlushInfo); 312 fBatch->flush(fTarget, fFlushInfo);
313 } 313 }
OLDNEW
« no previous file with comments | « src/gpu/batches/GrAtlasTextBatch.h ('k') | src/gpu/batches/GrDefaultPathRenderer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698