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

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

Issue 1260183006: Move atlas creation to internal to GrResourceProvider (Closed) Base URL: https://skia.googlesource.com/skia.git@debugatlas
Patch Set: tweak Created 5 years, 4 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/GrAADistanceFieldPathRenderer.cpp ('k') | src/gpu/GrResourceProvider.h » ('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 "GrBatchFontCache.h" 8 #include "GrBatchFontCache.h"
9 #include "GrContext.h" 9 #include "GrContext.h"
10 #include "GrFontAtlasSizes.h" 10 #include "GrFontAtlasSizes.h"
11 #include "GrGpu.h" 11 #include "GrGpu.h"
12 #include "GrRectanizer.h" 12 #include "GrRectanizer.h"
13 #include "GrResourceProvider.h" 13 #include "GrResourceProvider.h"
14 #include "GrSurfacePriv.h" 14 #include "GrSurfacePriv.h"
15 #include "SkString.h" 15 #include "SkString.h"
16 16
17 #include "SkDistanceFieldGen.h" 17 #include "SkDistanceFieldGen.h"
18 18
19 /////////////////////////////////////////////////////////////////////////////// 19 ///////////////////////////////////////////////////////////////////////////////
20 20
21 static GrBatchAtlas* make_atlas(GrContext* context, GrPixelConfig config,
22 int textureWidth, int textureHeight,
23 int numPlotsX, int numPlotsY) {
24 GrSurfaceDesc desc;
25 desc.fFlags = kNone_GrSurfaceFlags;
26 desc.fWidth = textureWidth;
27 desc.fHeight = textureHeight;
28 desc.fConfig = config;
29
30 // We don't want to flush the context so we claim we're in the middle of flu shing so as to
31 // guarantee we do not recieve a texture with pending IO
32 // TODO: Determine how to avoid having to do this. (http://skbug.com/4156)
33 static const uint32_t kFlags = GrResourceProvider::kNoPendingIO_Flag;
34 GrTexture* texture = context->resourceProvider()->createApproxTexture(desc, kFlags);
35 if (!texture) {
36 return NULL;
37 }
38 return SkNEW_ARGS(GrBatchAtlas, (texture, numPlotsX, numPlotsY));
39 }
40
41 bool GrBatchFontCache::initAtlas(GrMaskFormat format) { 21 bool GrBatchFontCache::initAtlas(GrMaskFormat format) {
42 int index = MaskFormatToAtlasIndex(format); 22 int index = MaskFormatToAtlasIndex(format);
43 if (!fAtlases[index]) { 23 if (!fAtlases[index]) {
44 GrPixelConfig config = MaskFormatToPixelConfig(format); 24 GrPixelConfig config = MaskFormatToPixelConfig(format);
25 int width = GR_FONT_ATLAS_TEXTURE_WIDTH;
26 int height = GR_FONT_ATLAS_TEXTURE_HEIGHT;
27 int numPlotsX = GR_FONT_ATLAS_NUM_PLOTS_X;
28 int numPlotsY = GR_FONT_ATLAS_NUM_PLOTS_Y;
29
45 if (kA8_GrMaskFormat == format) { 30 if (kA8_GrMaskFormat == format) {
46 fAtlases[index] = make_atlas(fContext, config, 31 width = GR_FONT_ATLAS_A8_TEXTURE_WIDTH;
47 GR_FONT_ATLAS_A8_TEXTURE_WIDTH, 32 numPlotsX = GR_FONT_ATLAS_A8_NUM_PLOTS_X;
48 GR_FONT_ATLAS_TEXTURE_HEIGHT,
49 GR_FONT_ATLAS_A8_NUM_PLOTS_X,
50 GR_FONT_ATLAS_NUM_PLOTS_Y);
51 } else {
52 fAtlases[index] = make_atlas(fContext, config,
53 GR_FONT_ATLAS_TEXTURE_WIDTH,
54 GR_FONT_ATLAS_TEXTURE_HEIGHT,
55 GR_FONT_ATLAS_NUM_PLOTS_X,
56 GR_FONT_ATLAS_NUM_PLOTS_Y);
57 } 33 }
58 34 fAtlases[index] =
59 // Atlas creation can fail 35 fContext->resourceProvider()->createAtlas(config, width, height,
60 if (fAtlases[index]) { 36 numPlotsX, numPlotsY,
61 fAtlases[index]->registerEvictionCallback(&GrBatchFontCache::HandleE viction, 37 &GrBatchFontCache::Han dleEviction,
62 (void*)this); 38 (void*)this);
63 } else { 39 if (!fAtlases[index]) {
64 return false; 40 return false;
65 } 41 }
66 } 42 }
67 return true; 43 return true;
68 } 44 }
69 45
70 GrBatchFontCache::GrBatchFontCache(GrContext* context) 46 GrBatchFontCache::GrBatchFontCache(GrContext* context)
71 : fContext(context) 47 : fContext(context)
72 , fPreserveStrike(NULL) { 48 , fPreserveStrike(NULL) {
73 for (int i = 0; i < kMaskFormatCount; ++i) { 49 for (int i = 0; i < kMaskFormatCount; ++i) {
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 202
227 bool success = fBatchFontCache->addToAtlas(this, &glyph->fID, batchTarget, e xpectedMaskFormat, 203 bool success = fBatchFontCache->addToAtlas(this, &glyph->fID, batchTarget, e xpectedMaskFormat,
228 glyph->width(), glyph->height(), 204 glyph->width(), glyph->height(),
229 storage.get(), &glyph->fAtlasLoca tion); 205 storage.get(), &glyph->fAtlasLoca tion);
230 if (success) { 206 if (success) {
231 SkASSERT(GrBatchAtlas::kInvalidAtlasID != glyph->fID); 207 SkASSERT(GrBatchAtlas::kInvalidAtlasID != glyph->fID);
232 fAtlasedGlyphs++; 208 fAtlasedGlyphs++;
233 } 209 }
234 return success; 210 return success;
235 } 211 }
OLDNEW
« no previous file with comments | « src/gpu/GrAADistanceFieldPathRenderer.cpp ('k') | src/gpu/GrResourceProvider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698