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

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: Addressed code review comments 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
« no previous file with comments | « src/gpu/GrAtlas.h ('k') | src/gpu/GrRectanizer_skyline.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 /* 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 const SkISize& backingTextureSize,
80 int numPlotsX, int numPlotsY) {
81 fGpu = SkRef(gpu);
96 fPixelConfig = config; 82 fPixelConfig = config;
97 gpu->ref(); 83 fBackingTextureSize = backingTextureSize;
84 fNumPlotsX = numPlotsX;
85 fNumPlotsY = numPlotsY;
98 fTexture = NULL; 86 fTexture = NULL;
99 87
88 int plotWidth = fBackingTextureSize.width() / fNumPlotsX;
89 int plotHeight = fBackingTextureSize.height() / fNumPlotsY;
90
91 SkASSERT(plotWidth * fNumPlotsX == fBackingTextureSize.width());
92 SkASSERT(plotHeight * fNumPlotsY == fBackingTextureSize.height());
93
100 // set up allocated plots 94 // set up allocated plots
101 size_t bpp = GrBytesPerPixel(fPixelConfig); 95 size_t bpp = GrBytesPerPixel(fPixelConfig);
102 fPlotArray = SkNEW_ARRAY(GrPlot, (GR_PLOT_WIDTH*GR_PLOT_HEIGHT)); 96 fPlotArray = SkNEW_ARRAY(GrPlot, (fNumPlotsX*fNumPlotsY));
103 97
104 GrPlot* currPlot = fPlotArray; 98 GrPlot* currPlot = fPlotArray;
105 for (int y = GR_PLOT_HEIGHT-1; y >= 0; --y) { 99 for (int y = numPlotsY-1; y >= 0; --y) {
106 for (int x = GR_PLOT_WIDTH-1; x >= 0; --x) { 100 for (int x = numPlotsX-1; x >= 0; --x) {
107 currPlot->fAtlasMgr = this; 101 currPlot->init(this, x, y, plotWidth, plotHeight, bpp);
108 currPlot->fOffset.set(x, y);
109 currPlot->fBytesPerPixel = bpp;
110 102
111 // build LRU list 103 // build LRU list
112 fPlotList.addToHead(currPlot); 104 fPlotList.addToHead(currPlot);
113 ++currPlot; 105 ++currPlot;
114 } 106 }
115 } 107 }
116 } 108 }
117 109
118 GrAtlasMgr::~GrAtlasMgr() { 110 GrAtlasMgr::~GrAtlasMgr() {
119 SkSafeUnref(fTexture); 111 SkSafeUnref(fTexture);
(...skipping 25 matching lines...) Expand all
145 this->moveToHead(plot); 137 this->moveToHead(plot);
146 return plot; 138 return plot;
147 } 139 }
148 } 140 }
149 141
150 // before we get a new plot, make sure we have a backing texture 142 // before we get a new plot, make sure we have a backing texture
151 if (NULL == fTexture) { 143 if (NULL == fTexture) {
152 // TODO: Update this to use the cache rather than directly creating a te xture. 144 // TODO: Update this to use the cache rather than directly creating a te xture.
153 GrTextureDesc desc; 145 GrTextureDesc desc;
154 desc.fFlags = kDynamicUpdate_GrTextureFlagBit; 146 desc.fFlags = kDynamicUpdate_GrTextureFlagBit;
155 desc.fWidth = GR_ATLAS_TEXTURE_WIDTH; 147 desc.fWidth = fBackingTextureSize.width();
156 desc.fHeight = GR_ATLAS_TEXTURE_HEIGHT; 148 desc.fHeight = fBackingTextureSize.height();
157 desc.fConfig = fPixelConfig; 149 desc.fConfig = fPixelConfig;
158 150
159 fTexture = fGpu->createTexture(desc, NULL, 0); 151 fTexture = fGpu->createTexture(desc, NULL, 0);
160 if (NULL == fTexture) { 152 if (NULL == fTexture) {
161 return NULL; 153 return NULL;
162 } 154 }
163 } 155 }
164 156
165 // now look through all allocated plots for one we can share, in MRU order 157 // now look through all allocated plots for one we can share, in MRU order
166 GrPlotList::Iter plotIter; 158 GrPlotList::Iter plotIter;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 GrPlot* plot; 194 GrPlot* plot;
203 while (NULL != (plot = plotIter.get())) { 195 while (NULL != (plot = plotIter.get())) {
204 if (plot->drawToken().isIssued()) { 196 if (plot->drawToken().isIssued()) {
205 return plot; 197 return plot;
206 } 198 }
207 plotIter.prev(); 199 plotIter.prev();
208 } 200 }
209 201
210 return NULL; 202 return NULL;
211 } 203 }
OLDNEW
« no previous file with comments | « src/gpu/GrAtlas.h ('k') | src/gpu/GrRectanizer_skyline.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698