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

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

Issue 217423014: Minor changes to GrFontCache system (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 6 years, 8 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 /* 2 /*
3 * Copyright 2010 Google Inc. 3 * Copyright 2010 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 "GrAtlas.h" 9 #include "GrAtlas.h"
10 #include "GrContext.h" 10 #include "GrContext.h"
11 #include "GrGpu.h" 11 #include "GrGpu.h"
12 #include "GrRectanizer.h" 12 #include "GrRectanizer.h"
13 13
14 #if 0
15 #define GR_PLOT_WIDTH 8
16 #define GR_PLOT_HEIGHT 4
17 #define GR_ATLAS_WIDTH 256
18 #define GR_ATLAS_HEIGHT 256
19
20 #define GR_ATLAS_TEXTURE_WIDTH (GR_PLOT_WIDTH * GR_ATLAS_WIDTH)
21 #define GR_ATLAS_TEXTURE_HEIGHT (GR_PLOT_HEIGHT * GR_ATLAS_HEIGHT)
22
23 #else
24
25 #define GR_ATLAS_TEXTURE_WIDTH 1024
26 #define GR_ATLAS_TEXTURE_HEIGHT 2048
27
28 #define GR_ATLAS_WIDTH 256
29 #define GR_ATLAS_HEIGHT 256
30
31 #define GR_PLOT_WIDTH (GR_ATLAS_TEXTURE_WIDTH / GR_ATLAS_WIDTH)
32 #define GR_PLOT_HEIGHT (GR_ATLAS_TEXTURE_HEIGHT / GR_ATLAS_HEIGHT)
33
34 #endif
35
36 /////////////////////////////////////////////////////////////////////////////// 14 ///////////////////////////////////////////////////////////////////////////////
37 15
38 // for testing 16 // for testing
39 #define FONT_CACHE_STATS 0 17 #define FONT_CACHE_STATS 0
40 #if FONT_CACHE_STATS 18 #if FONT_CACHE_STATS
41 static int g_UploadCount = 0; 19 static int g_UploadCount = 0;
42 #endif 20 #endif
43 21
44 GrPlot::GrPlot() : fDrawToken(NULL, 0) 22 GrPlot::GrPlot() : fDrawToken(NULL, 0)
45 , fTexture(NULL) 23 , fTexture(NULL)
24 , fRects(NULL)
46 , fAtlasMgr(NULL) 25 , fAtlasMgr(NULL)
47 , fBytesPerPixel(1) 26 , fBytesPerPixel(1)
48 { 27 {
49 fRects = GrRectanizer::Factory(GR_ATLAS_WIDTH,
50 GR_ATLAS_HEIGHT);
51 fOffset.set(0, 0); 28 fOffset.set(0, 0);
52 } 29 }
53 30
54 GrPlot::~GrPlot() { 31 GrPlot::~GrPlot() {
55 delete fRects; 32 delete fRects;
56 } 33 }
57 34
35 void GrPlot::init(GrAtlasMgr* mgr, int offX, int offY, int width, int height, si ze_t bpp) {
36 fRects = GrRectanizer::Factory(width, height);
37 fAtlasMgr = mgr;
38 fOffset.set(offX * width, offY * height);
39 fBytesPerPixel = bpp;
40 }
41
58 static inline void adjust_for_offset(GrIPoint16* loc, const GrIPoint16& offset) { 42 static inline void adjust_for_offset(GrIPoint16* loc, const GrIPoint16& offset) {
59 loc->fX += offset.fX * GR_ATLAS_WIDTH; 43 loc->fX += offset.fX;
60 loc->fY += offset.fY * GR_ATLAS_HEIGHT; 44 loc->fY += offset.fY;
61 } 45 }
62 46
63 bool GrPlot::addSubImage(int width, int height, const void* image, 47 bool GrPlot::addSubImage(int width, int height, const void* image,
64 GrIPoint16* loc) { 48 GrIPoint16* loc) {
65 if (!fRects->addRect(width, height, loc)) { 49 if (!fRects->addRect(width, height, loc)) {
66 return false; 50 return false;
67 } 51 }
68 52
69 SkAutoSMalloc<1024> storage; 53 SkAutoSMalloc<1024> storage;
70 adjust_for_offset(loc, fOffset); 54 adjust_for_offset(loc, fOffset);
(...skipping 13 matching lines...) Expand all
84 return true; 68 return true;
85 } 69 }
86 70
87 void GrPlot::resetRects() { 71 void GrPlot::resetRects() {
88 SkASSERT(NULL != fRects); 72 SkASSERT(NULL != fRects);
89 fRects->reset(); 73 fRects->reset();
90 } 74 }
91 75
92 /////////////////////////////////////////////////////////////////////////////// 76 ///////////////////////////////////////////////////////////////////////////////
93 77
94 GrAtlasMgr::GrAtlasMgr(GrGpu* gpu, GrPixelConfig config) { 78 GrAtlasMgr::GrAtlasMgr(GrGpu* gpu, GrPixelConfig config,
95 fGpu = gpu; 79 int backingTextureWidth, int backingTextureHeight,
jvanverth1 2014/04/01 15:32:43 One thing that might be worth considering is wheth
robertphillips 2014/04/01 15:45:54 Done.
80 int numPlotsX, int numPlotsY) {
81 fGpu = SkRef(gpu);
96 fPixelConfig = config; 82 fPixelConfig = config;
97 gpu->ref(); 83 fBackingTextureWidth = backingTextureWidth;
84 fBackingTextureHeight = backingTextureHeight;
85 fNumPlotsX = numPlotsX;
86 fNumPlotsY = numPlotsY;
98 fTexture = NULL; 87 fTexture = NULL;
99 88
89 int plotWidth = fBackingTextureWidth / fNumPlotsX;
90 int plotHeight = fBackingTextureHeight / fNumPlotsY;
91
92 SkASSERT(plotWidth * fNumPlotsX == fBackingTextureWidth);
93 SkASSERT(plotHeight * fNumPlotsY == fBackingTextureHeight);
94
100 // set up allocated plots 95 // set up allocated plots
101 size_t bpp = GrBytesPerPixel(fPixelConfig); 96 size_t bpp = GrBytesPerPixel(fPixelConfig);
102 fPlotArray = SkNEW_ARRAY(GrPlot, (GR_PLOT_WIDTH*GR_PLOT_HEIGHT)); 97 fPlotArray = SkNEW_ARRAY(GrPlot, (fNumPlotsX*fNumPlotsY));
103 98
104 GrPlot* currPlot = fPlotArray; 99 GrPlot* currPlot = fPlotArray;
105 for (int y = GR_PLOT_HEIGHT-1; y >= 0; --y) { 100 for (int y = numPlotsY-1; y >= 0; --y) {
106 for (int x = GR_PLOT_WIDTH-1; x >= 0; --x) { 101 for (int x = numPlotsX-1; x >= 0; --x) {
107 currPlot->fAtlasMgr = this; 102 currPlot->init(this, x, y, plotWidth, plotHeight, bpp);
108 currPlot->fOffset.set(x, y);
109 currPlot->fBytesPerPixel = bpp;
110 103
111 // build LRU list 104 // build LRU list
112 fPlotList.addToHead(currPlot); 105 fPlotList.addToHead(currPlot);
113 ++currPlot; 106 ++currPlot;
114 } 107 }
115 } 108 }
116 } 109 }
117 110
118 GrAtlasMgr::~GrAtlasMgr() { 111 GrAtlasMgr::~GrAtlasMgr() {
119 SkSafeUnref(fTexture); 112 SkSafeUnref(fTexture);
(...skipping 25 matching lines...) Expand all
145 this->moveToHead(plot); 138 this->moveToHead(plot);
146 return plot; 139 return plot;
147 } 140 }
148 } 141 }
149 142
150 // before we get a new plot, make sure we have a backing texture 143 // before we get a new plot, make sure we have a backing texture
151 if (NULL == fTexture) { 144 if (NULL == fTexture) {
152 // TODO: Update this to use the cache rather than directly creating a te xture. 145 // TODO: Update this to use the cache rather than directly creating a te xture.
153 GrTextureDesc desc; 146 GrTextureDesc desc;
154 desc.fFlags = kDynamicUpdate_GrTextureFlagBit; 147 desc.fFlags = kDynamicUpdate_GrTextureFlagBit;
155 desc.fWidth = GR_ATLAS_TEXTURE_WIDTH; 148 desc.fWidth = fBackingTextureWidth;
156 desc.fHeight = GR_ATLAS_TEXTURE_HEIGHT; 149 desc.fHeight = fBackingTextureHeight;
157 desc.fConfig = fPixelConfig; 150 desc.fConfig = fPixelConfig;
158 151
159 fTexture = fGpu->createTexture(desc, NULL, 0); 152 fTexture = fGpu->createTexture(desc, NULL, 0);
160 if (NULL == fTexture) { 153 if (NULL == fTexture) {
161 return NULL; 154 return NULL;
162 } 155 }
163 } 156 }
164 157
165 // now look through all allocated plots for one we can share, in MRU order 158 // now look through all allocated plots for one we can share, in MRU order
166 GrPlotList::Iter plotIter; 159 GrPlotList::Iter plotIter;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 GrPlot* plot; 195 GrPlot* plot;
203 while (NULL != (plot = plotIter.get())) { 196 while (NULL != (plot = plotIter.get())) {
204 if (plot->drawToken().isIssued()) { 197 if (plot->drawToken().isIssued()) {
205 return plot; 198 return plot;
206 } 199 }
207 plotIter.prev(); 200 plotIter.prev();
208 } 201 }
209 202
210 return NULL; 203 return NULL;
211 } 204 }
OLDNEW
« no previous file with comments | « src/gpu/GrAtlas.h ('k') | src/gpu/GrRectanizer_skyline.cpp » ('j') | src/gpu/GrTextStrike.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698