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

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

Issue 269423007: Add CPU backing store for GrAtlas to reduce texture uploads (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Turn on texture update for distance fields Created 6 years, 7 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/GrAtlas.h ('k') | src/gpu/GrBitmapTextContext.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 /* 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"
(...skipping 11 matching lines...) Expand all
22 GrPlot::GrPlot() : fDrawToken(NULL, 0) 22 GrPlot::GrPlot() : fDrawToken(NULL, 0)
23 , fTexture(NULL) 23 , fTexture(NULL)
24 , fRects(NULL) 24 , fRects(NULL)
25 , fAtlasMgr(NULL) 25 , fAtlasMgr(NULL)
26 , fBytesPerPixel(1) 26 , fBytesPerPixel(1)
27 { 27 {
28 fOffset.set(0, 0); 28 fOffset.set(0, 0);
29 } 29 }
30 30
31 GrPlot::~GrPlot() { 31 GrPlot::~GrPlot() {
32 SkDELETE_ARRAY(fPlotData);
33 fPlotData = NULL;
32 delete fRects; 34 delete fRects;
33 } 35 }
34 36
35 void GrPlot::init(GrAtlasMgr* mgr, int offX, int offY, int width, int height, si ze_t bpp) { 37 void GrPlot::init(GrAtlasMgr* mgr, int offX, int offY, int width, int height, si ze_t bpp) {
36 fRects = GrRectanizer::Factory(width, height); 38 fRects = GrRectanizer::Factory(width, height);
37 fAtlasMgr = mgr; 39 fAtlasMgr = mgr;
38 fOffset.set(offX * width, offY * height); 40 fOffset.set(offX * width, offY * height);
39 fBytesPerPixel = bpp; 41 fBytesPerPixel = bpp;
42 fPlotData = NULL;
43 fDirtyRect.setEmpty();
44 fDirty = false;
40 } 45 }
41 46
42 static inline void adjust_for_offset(GrIPoint16* loc, const GrIPoint16& offset) { 47 static inline void adjust_for_offset(GrIPoint16* loc, const GrIPoint16& offset) {
43 loc->fX += offset.fX; 48 loc->fX += offset.fX;
44 loc->fY += offset.fY; 49 loc->fY += offset.fY;
45 } 50 }
46 51
47 bool GrPlot::addSubImage(int width, int height, const void* image, 52 bool GrPlot::addSubImage(int width, int height, const void* image,
48 GrIPoint16* loc) { 53 GrIPoint16* loc) {
54 float percentFull = fRects->percentFull();
49 if (!fRects->addRect(width, height, loc)) { 55 if (!fRects->addRect(width, height, loc)) {
50 return false; 56 return false;
51 } 57 }
52 58
53 SkAutoSMalloc<1024> storage; 59 // create backing memory on first use
robertphillips 2014/05/12 19:45:52 // Once the plot is nearly full we will revert to
jvanverth1 2014/05/12 20:44:04 Done.
54 adjust_for_offset(loc, fOffset); 60 int plotWidth = fRects->width();
55 GrContext* context = fTexture->getContext(); 61 int plotHeight = fRects->height();
56 // We pass the flag that does not force a flush. We assume our caller is 62 if (NULL == fPlotData && 0.0f == percentFull) {
57 // smart and hasn't referenced the part of the texture we're about to update 63 fPlotData = SkNEW_ARRAY(unsigned char, fBytesPerPixel*plotWidth*plotHeig ht);
58 // since the last flush. 64 memset(fPlotData, 0, fBytesPerPixel*plotWidth*plotHeight);
59 context->writeTexturePixels(fTexture, 65 }
60 loc->fX, loc->fY, width, height, 66
61 fTexture->config(), image, 0, 67 // if we have backing memory, copy to the memory and set for future upload
62 GrContext::kDontFlush_PixelOpsFlag); 68 if (NULL != fPlotData) {
robertphillips 2014/05/12 19:45:52 const unsigned char* ?
jvanverth1 2014/05/12 20:44:04 Done.
69 unsigned char* imagePtr = (unsigned char*) image;
70 // point ourselves at the right starting spot
71 unsigned char* dataPtr = fPlotData;
72 dataPtr += fBytesPerPixel*plotWidth*loc->fY;
73 dataPtr += fBytesPerPixel*loc->fX;
74 // copy into the data buffer
75 for (int i = 0; i < height; ++i) {
76 memcpy(dataPtr, imagePtr, fBytesPerPixel*width);
77 dataPtr += fBytesPerPixel*plotWidth;
78 imagePtr += fBytesPerPixel*width;
79 }
80
81 fDirtyRect.join(loc->fX, loc->fY, loc->fX + width, loc->fY + height);
82 adjust_for_offset(loc, fOffset);
83 fDirty = true;
84 // otherwise, just upload the image directly
85 } else {
86 adjust_for_offset(loc, fOffset);
87 GrContext* context = fTexture->getContext();
88 context->writeTexturePixels(fTexture,
89 loc->fX, loc->fY, width, height,
90 fTexture->config(), image, 0,
91 GrContext::kDontFlush_PixelOpsFlag);
92 }
63 93
64 #if FONT_CACHE_STATS 94 #if FONT_CACHE_STATS
65 ++g_UploadCount; 95 ++g_UploadCount;
66 #endif 96 #endif
67 97
68 return true; 98 return true;
69 } 99 }
70 100
101 void GrPlot::uploadToTexture() {
102 if (fDirty && NULL != fTexture) {
103 GrContext* context = fTexture->getContext();
104 // We pass the flag that does not force a flush. We assume our caller is
105 // smart and hasn't referenced the part of the texture we're about to up date
106 // since the last flush.
107 int rowBytes = fBytesPerPixel*fRects->width();
robertphillips 2014/05/12 19:45:52 const unsigned char* ?
jvanverth1 2014/05/12 20:44:04 Done.
108 unsigned char* dataPtr = fPlotData;
109 dataPtr += rowBytes*fDirtyRect.fTop;
110 dataPtr += fBytesPerPixel*fDirtyRect.fLeft;
111 context->writeTexturePixels(fTexture,
112 fOffset.fX + fDirtyRect.fLeft, fOffset.fY + fDirtyRect.fTop,
113 fDirtyRect.width(), fDirtyRect.height(),
114 fTexture->config(), dataPtr,
115 rowBytes,
116 GrContext::kDontFlush_PixelOpsFlag);
117 fDirtyRect.setEmpty();
118 // If the Plot is nearly full, anything else we add will probably be sma ll and one
119 // at a time, so free up the memory and upload any new images directly.
robertphillips 2014/05/12 19:45:52 static const int kNearlyFullTolerance = 0.85f; ?
jvanverth1 2014/05/12 20:44:04 Done.
120 if (fRects->percentFull() > 0.85f) {
121 SkDELETE_ARRAY(fPlotData);
122 fPlotData = NULL;
123 }
124 }
robertphillips 2014/05/12 19:45:52 It seems like if we're going to clear fDirty out h
jvanverth1 2014/05/12 20:44:04 Cleaned up. We shouldn't hit the 'if' block unless
125 fDirty = false;
126 }
127
71 void GrPlot::resetRects() { 128 void GrPlot::resetRects() {
72 SkASSERT(NULL != fRects); 129 SkASSERT(NULL != fRects);
73 fRects->reset(); 130 fRects->reset();
74 } 131 }
75 132
76 /////////////////////////////////////////////////////////////////////////////// 133 ///////////////////////////////////////////////////////////////////////////////
77 134
78 GrAtlasMgr::GrAtlasMgr(GrGpu* gpu, GrPixelConfig config, 135 GrAtlasMgr::GrAtlasMgr(GrGpu* gpu, GrPixelConfig config,
79 const SkISize& backingTextureSize, 136 const SkISize& backingTextureSize,
80 int numPlotsX, int numPlotsY) { 137 int numPlotsX, int numPlotsY) {
81 fGpu = SkRef(gpu); 138 fGpu = SkRef(gpu);
82 fPixelConfig = config; 139 fPixelConfig = config;
83 fBackingTextureSize = backingTextureSize; 140 fBackingTextureSize = backingTextureSize;
84 fNumPlotsX = numPlotsX; 141 fNumPlotsX = numPlotsX;
85 fNumPlotsY = numPlotsY; 142 fNumPlotsY = numPlotsY;
86 fTexture = NULL; 143 fTexture = NULL;
87 144
88 int plotWidth = fBackingTextureSize.width() / fNumPlotsX; 145 int textureWidth = fBackingTextureSize.width();
89 int plotHeight = fBackingTextureSize.height() / fNumPlotsY; 146 int textureHeight = fBackingTextureSize.height();
90 147
91 SkASSERT(plotWidth * fNumPlotsX == fBackingTextureSize.width()); 148 int plotWidth = textureWidth / fNumPlotsX;
92 SkASSERT(plotHeight * fNumPlotsY == fBackingTextureSize.height()); 149 int plotHeight = textureHeight / fNumPlotsY;
150
151 SkASSERT(plotWidth * fNumPlotsX == textureWidth);
152 SkASSERT(plotHeight * fNumPlotsY == textureHeight);
93 153
94 // set up allocated plots 154 // set up allocated plots
95 size_t bpp = GrBytesPerPixel(fPixelConfig); 155 size_t bpp = GrBytesPerPixel(fPixelConfig);
96 fPlotArray = SkNEW_ARRAY(GrPlot, (fNumPlotsX*fNumPlotsY)); 156 fPlotArray = SkNEW_ARRAY(GrPlot, (fNumPlotsX*fNumPlotsY));
97 157
98 GrPlot* currPlot = fPlotArray; 158 GrPlot* currPlot = fPlotArray;
99 for (int y = numPlotsY-1; y >= 0; --y) { 159 for (int y = numPlotsY-1; y >= 0; --y) {
100 for (int x = numPlotsX-1; x >= 0; --x) { 160 for (int x = numPlotsX-1; x >= 0; --x) {
101 currPlot->init(this, x, y, plotWidth, plotHeight, bpp); 161 currPlot->init(this, x, y, plotWidth, plotHeight, bpp);
102 162
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 GrPlot* plot; 254 GrPlot* plot;
195 while (NULL != (plot = plotIter.get())) { 255 while (NULL != (plot = plotIter.get())) {
196 if (plot->drawToken().isIssued()) { 256 if (plot->drawToken().isIssued()) {
197 return plot; 257 return plot;
198 } 258 }
199 plotIter.prev(); 259 plotIter.prev();
200 } 260 }
201 261
202 return NULL; 262 return NULL;
203 } 263 }
264
265 void GrAtlasMgr::uploadPlotsToTexture() {
266 GrPlotList::Iter plotIter;
267 plotIter.init(fPlotList, GrPlotList::Iter::kHead_IterStart);
268 GrPlot* plot;
269 while (NULL != (plot = plotIter.get())) {
270 plot->uploadToTexture();
271 plotIter.next();
272 }
273 }
OLDNEW
« no previous file with comments | « src/gpu/GrAtlas.h ('k') | src/gpu/GrBitmapTextContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698