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

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

Issue 761563002: First step to moving vertex attributes to the geometryProcessor (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: more cleanup Created 6 years 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
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2014 Google Inc. 3 * Copyright 2014 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "GrAADistanceFieldPathRenderer.h" 9 #include "GrAADistanceFieldPathRenderer.h"
10 10
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 GrPathRenderer::StencilSupport 96 GrPathRenderer::StencilSupport
97 GrAADistanceFieldPathRenderer::onGetStencilSupport(const GrDrawTarget*, 97 GrAADistanceFieldPathRenderer::onGetStencilSupport(const GrDrawTarget*,
98 const GrDrawState*, 98 const GrDrawState*,
99 const SkPath&, 99 const SkPath&,
100 const SkStrokeRec&) const { 100 const SkStrokeRec&) const {
101 return GrPathRenderer::kNoSupport_StencilSupport; 101 return GrPathRenderer::kNoSupport_StencilSupport;
102 } 102 }
103 103
104 //////////////////////////////////////////////////////////////////////////////// 104 ////////////////////////////////////////////////////////////////////////////////
105 105
106 // position + texture coord
107 extern const GrVertexAttrib gSDFPathVertexAttribs[] = {
108 { kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding },
109 { kVec2f_GrVertexAttribType, sizeof(SkPoint), kGeometryProcessor_GrVertexAtt ribBinding }
110 };
111 static const size_t kSDFPathVASize = 2 * sizeof(SkPoint);
112
113 bool GrAADistanceFieldPathRenderer::onDrawPath(GrDrawTarget* target, 106 bool GrAADistanceFieldPathRenderer::onDrawPath(GrDrawTarget* target,
114 GrDrawState* drawState, 107 GrDrawState* drawState,
115 const SkPath& path, 108 const SkPath& path,
116 const SkStrokeRec& stroke, 109 const SkStrokeRec& stroke,
117 bool antiAlias) { 110 bool antiAlias) {
118 // we've already bailed on inverse filled paths, so this is safe 111 // we've already bailed on inverse filled paths, so this is safe
119 if (path.isEmpty()) { 112 if (path.isEmpty()) {
120 return true; 113 return true;
121 } 114 }
122 115
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 GrDrawState* drawState, 308 GrDrawState* drawState,
316 const SkPath& path, 309 const SkPath& path,
317 const PathData* pathData) { 310 const PathData* pathData) {
318 GrTexture* texture = fAtlas->getTexture(); 311 GrTexture* texture = fAtlas->getTexture();
319 GrDrawState::AutoRestoreEffects are(drawState); 312 GrDrawState::AutoRestoreEffects are(drawState);
320 313
321 SkASSERT(pathData->fPlot); 314 SkASSERT(pathData->fPlot);
322 GrDrawTarget::DrawToken drawToken = target->getCurrentDrawToken(); 315 GrDrawTarget::DrawToken drawToken = target->getCurrentDrawToken();
323 pathData->fPlot->setDrawToken(drawToken); 316 pathData->fPlot->setDrawToken(drawToken);
324 317
325 // make me some vertices 318 // set up any flags
326 drawState->setVertexAttribs<gSDFPathVertexAttribs>(SK_ARRAY_COUNT(gSDFPathVe rtexAttribs), 319 uint32_t flags = 0;
327 kSDFPathVASize); 320 const SkMatrix& vm = drawState->getViewMatrix();
321 flags |= vm.isSimilarity() ? kSimilarity_DistanceFieldEffectFlag : 0;
322
323 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBilerp_ FilterMode);
324 if (flags != fEffectFlags) {
325 fCachedGeometryProcessor.reset(GrDistanceFieldNoGammaTextureEffect::Crea te(texture,
326 params,
327 flags));
328 fEffectFlags = flags;
329 }
330 drawState->setGeometryProcessor(fCachedGeometryProcessor.get());
331
328 void* vertices = NULL; 332 void* vertices = NULL;
329 bool success = target->reserveVertexAndIndexSpace(4, drawState->getVertexStr ide(), 0, &vertices, 333 bool success = target->reserveVertexAndIndexSpace(4,
330 NULL); 334 fCachedGeometryProcessor-> getVertexStride(),
335 0, &vertices, NULL);
331 GrAlwaysAssert(success); 336 GrAlwaysAssert(success);
332 337
333 SkScalar dx = pathData->fBounds.fLeft; 338 SkScalar dx = pathData->fBounds.fLeft;
334 SkScalar dy = pathData->fBounds.fTop; 339 SkScalar dy = pathData->fBounds.fTop;
335 SkScalar width = pathData->fBounds.width(); 340 SkScalar width = pathData->fBounds.width();
336 SkScalar height = pathData->fBounds.height(); 341 SkScalar height = pathData->fBounds.height();
337 342
338 SkScalar invScale = 1.0f/pathData->fScale; 343 SkScalar invScale = 1.0f/pathData->fScale;
339 dx *= invScale; 344 dx *= invScale;
340 dy *= invScale; 345 dy *= invScale;
(...skipping 13 matching lines...) Expand all
354 359
355 // vertex texture coords 360 // vertex texture coords
356 intptr_t intPtr = reinterpret_cast<intptr_t>(positions); 361 intptr_t intPtr = reinterpret_cast<intptr_t>(positions);
357 SkPoint* textureCoords = reinterpret_cast<SkPoint*>(intPtr + vertSize - size of(SkPoint)); 362 SkPoint* textureCoords = reinterpret_cast<SkPoint*>(intPtr + vertSize - size of(SkPoint));
358 textureCoords->setRectFan(SkFixedToFloat(texture->texturePriv().normalizeFix edX(tx)), 363 textureCoords->setRectFan(SkFixedToFloat(texture->texturePriv().normalizeFix edX(tx)),
359 SkFixedToFloat(texture->texturePriv().normalizeFix edY(ty)), 364 SkFixedToFloat(texture->texturePriv().normalizeFix edY(ty)),
360 SkFixedToFloat(texture->texturePriv().normalizeFix edX(tx + tw)), 365 SkFixedToFloat(texture->texturePriv().normalizeFix edX(tx + tw)),
361 SkFixedToFloat(texture->texturePriv().normalizeFix edY(ty + th)), 366 SkFixedToFloat(texture->texturePriv().normalizeFix edY(ty + th)),
362 vertSize); 367 vertSize);
363 368
364 // set up any flags
365 uint32_t flags = 0;
366 const SkMatrix& vm = drawState->getViewMatrix();
367 flags |= vm.isSimilarity() ? kSimilarity_DistanceFieldEffectFlag : 0;
368
369 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBilerp_ FilterMode);
370 if (flags != fEffectFlags) {
371 fCachedGeometryProcessor.reset(GrDistanceFieldNoGammaTextureEffect::Crea te(texture,
372 params,
373 flags));
374 fEffectFlags = flags;
375 }
376 drawState->setGeometryProcessor(fCachedGeometryProcessor.get());
377
378 vm.mapRect(&r); 369 vm.mapRect(&r);
379 target->setIndexSourceToBuffer(fContext->getQuadIndexBuffer()); 370 target->setIndexSourceToBuffer(fContext->getQuadIndexBuffer());
380 target->drawIndexedInstances(drawState, kTriangles_GrPrimitiveType, 1, 4, 6, &r); 371 target->drawIndexedInstances(drawState, kTriangles_GrPrimitiveType, 1, 4, 6, &r);
381 target->resetVertexSource(); 372 target->resetVertexSource();
382 373
383 return true; 374 return true;
384 } 375 }
385 376
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698