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

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

Issue 917373002: Use uint16s for texture coordinates when rendering text. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase to ToT Created 5 years, 10 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
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
11 #include "GrAtlas.h" 11 #include "GrAtlas.h"
12 #include "GrContext.h" 12 #include "GrContext.h"
13 #include "GrPipelineBuilder.h" 13 #include "GrPipelineBuilder.h"
14 #include "GrSurfacePriv.h" 14 #include "GrSurfacePriv.h"
15 #include "GrSWMaskHelper.h" 15 #include "GrSWMaskHelper.h"
16 #include "GrTexturePriv.h" 16 #include "GrTexturePriv.h"
17 #include "effects/GrDistanceFieldTextureEffect.h" 17 #include "effects/GrDistanceFieldTextureEffect.h"
18 18
19 #include "SkDistanceFieldGen.h" 19 #include "SkDistanceFieldGen.h"
20 #include "SkRTConf.h" 20 #include "SkRTConf.h"
21 21
22 #define ATLAS_TEXTURE_WIDTH 1024 22 #define ATLAS_TEXTURE_WIDTH 1024
23 #define ATLAS_TEXTURE_HEIGHT 2048 23 #define ATLAS_TEXTURE_HEIGHT 2048
24 #define PLOT_WIDTH 256 24 #define PLOT_WIDTH 256
25 #define PLOT_HEIGHT 256 25 #define PLOT_HEIGHT 256
26 26
27 #define NUM_PLOTS_X (ATLAS_TEXTURE_WIDTH / PLOT_WIDTH) 27 #define NUM_PLOTS_X (ATLAS_TEXTURE_WIDTH / PLOT_WIDTH)
28 #define NUM_PLOTS_Y (ATLAS_TEXTURE_HEIGHT / PLOT_HEIGHT) 28 #define NUM_PLOTS_Y (ATLAS_TEXTURE_HEIGHT / PLOT_HEIGHT)
29 29
30 SK_CONF_DECLARE(bool, c_DumpPathCache, "gpu.dumpPathCache", false, 30 SK_CONF_DECLARE(bool, c_DumpPathCache, "gpu.dumpPathCache", false,
31 "Dump the contents of the path cache before every purge."); 31 "Dump the contents of the path cache before every purge.");
32 32
33 #ifdef DF_PATH_TRACKING 33 #ifdef DF_PATH_TRACKING
34 static int g_NumCachedPaths = 0; 34 static int g_NumCachedPaths = 0;
35 static int g_NumFreedPaths = 0; 35 static int g_NumFreedPaths = 0;
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 params, 335 params,
336 flags, 336 flags,
337 false)); 337 false));
338 fEffectFlags = flags; 338 fEffectFlags = flags;
339 } 339 }
340 340
341 void* vertices = NULL; 341 void* vertices = NULL;
342 bool success = target->reserveVertexAndIndexSpace(4, 342 bool success = target->reserveVertexAndIndexSpace(4,
343 fCachedGeometryProcessor-> getVertexStride(), 343 fCachedGeometryProcessor-> getVertexStride(),
344 0, &vertices, NULL); 344 0, &vertices, NULL);
345 SkASSERT(fCachedGeometryProcessor->getVertexStride() == 2 * sizeof(SkPoint)) ; 345 SkASSERT(fCachedGeometryProcessor->getVertexStride() == sizeof(SkPoint) + si zeof(SkIPoint16));
346 GrAlwaysAssert(success); 346 GrAlwaysAssert(success);
347 347
348 SkScalar dx = pathData->fBounds.fLeft; 348 SkScalar dx = pathData->fBounds.fLeft;
349 SkScalar dy = pathData->fBounds.fTop; 349 SkScalar dy = pathData->fBounds.fTop;
robertphillips 2015/02/13 16:10:41 round_out_WH ? comment ? Would it not be better to
jvanverth1 2015/02/13 19:58:56 Rounding out the bounds seems to add an extra texe
350 SkScalar width = pathData->fBounds.width(); 350 int iwidth = static_cast<int>(pathData->fBounds.width() + 0.99f);
351 SkScalar height = pathData->fBounds.height(); 351 int iheight = static_cast<int>(pathData->fBounds.height() + 0.99f);
352 SkScalar width = iwidth;
353 SkScalar height = iheight;
352 354
353 SkScalar invScale = 1.0f/pathData->fScale; 355 SkScalar invScale = 1.0f/pathData->fScale;
354 dx *= invScale; 356 dx *= invScale;
355 dy *= invScale; 357 dy *= invScale;
356 width *= invScale; 358 width *= invScale;
357 height *= invScale; 359 height *= invScale;
358 360
359 SkFixed tx = SkIntToFixed(pathData->fAtlasLocation.fX); 361 int u0 = pathData->fAtlasLocation.fX;
360 SkFixed ty = SkIntToFixed(pathData->fAtlasLocation.fY); 362 int v0 = pathData->fAtlasLocation.fY;
361 SkFixed tw = SkScalarToFixed(pathData->fBounds.width()); 363 int u1 = u0 + iwidth;
362 SkFixed th = SkScalarToFixed(pathData->fBounds.height()); 364 int v1 = v0 + iheight;
363
364 // vertex positions 365 // vertex positions
365 SkRect r = SkRect::MakeXYWH(dx, dy, width, height); 366 SkRect r = SkRect::MakeXYWH(dx, dy, width, height);
366 size_t vertSize = 2 * sizeof(SkPoint); 367 size_t vertSize = sizeof(SkPoint) + sizeof(SkIPoint16);
367 SkPoint* positions = reinterpret_cast<SkPoint*>(vertices); 368 SkPoint* positions = reinterpret_cast<SkPoint*>(vertices);
368 positions->setRectFan(r.left(), r.top(), r.right(), r.bottom(), vertSize); 369 positions->setRectFan(r.left(), r.top(), r.right(), r.bottom(), vertSize);
369 370
370 // vertex texture coords 371 // vertex texture coords
371 intptr_t intPtr = reinterpret_cast<intptr_t>(positions); 372 intptr_t textureCoords = reinterpret_cast<intptr_t>(positions) + vertSize - sizeof(SkIPoint16);
372 SkPoint* textureCoords = reinterpret_cast<SkPoint*>(intPtr + vertSize - size of(SkPoint)); 373 ((SkIPoint16*)(textureCoords + 0 * vertSize))->set(u0, v0);
373 textureCoords->setRectFan(SkFixedToFloat(texture->texturePriv().normalizeFix edX(tx)), 374 ((SkIPoint16*)(textureCoords + 1 * vertSize))->set(u0, v1);
374 SkFixedToFloat(texture->texturePriv().normalizeFix edY(ty)), 375 ((SkIPoint16*)(textureCoords + 2 * vertSize))->set(u1, v1);
375 SkFixedToFloat(texture->texturePriv().normalizeFix edX(tx + tw)), 376 ((SkIPoint16*)(textureCoords + 3 * vertSize))->set(u1, v0);
376 SkFixedToFloat(texture->texturePriv().normalizeFix edY(ty + th)),
377 vertSize);
378 377
379 viewMatrix.mapRect(&r); 378 viewMatrix.mapRect(&r);
380 target->setIndexSourceToBuffer(fContext->getQuadIndexBuffer()); 379 target->setIndexSourceToBuffer(fContext->getQuadIndexBuffer());
381 target->drawIndexedInstances(pipelineBuilder, fCachedGeometryProcessor.get() , 380 target->drawIndexedInstances(pipelineBuilder, fCachedGeometryProcessor.get() ,
382 kTriangles_GrPrimitiveType, 1, 4, 6, &r); 381 kTriangles_GrPrimitiveType, 1, 4, 6, &r);
383 target->resetVertexSource(); 382 target->resetVertexSource();
384 383
385 return true; 384 return true;
386 } 385 }
387 386
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698