small cleanup of GrAtlas

BUG=skia:

Review URL: https://codereview.chromium.org/1142263002
This commit is contained in:
joshualitt 2015-05-19 14:41:41 -07:00 committed by Commit bot
parent bb87b2104b
commit d706f11b6e
4 changed files with 2 additions and 94 deletions

View File

@ -21,8 +21,7 @@ static int g_UploadCount = 0;
#endif
GrPlot::GrPlot()
: fDrawToken(NULL, 0)
, fID(-1)
: fID(-1)
, fTexture(NULL)
, fRects(NULL)
, fAtlas(NULL)
@ -106,36 +105,6 @@ bool GrPlot::addSubImage(int width, int height, const void* image, SkIPoint16* l
return true;
}
void GrPlot::uploadToTexture() {
static const float kNearlyFullTolerance = 0.85f;
// should only do this if batching is enabled
SkASSERT(fBatchUploads);
if (fDirty) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("skia.gpu"), "GrPlot::uploadToTexture");
SkASSERT(fTexture);
// We pass the flag that does not force a flush. We assume our caller is
// smart and hasn't referenced the part of the texture we're about to update
// since the last flush.
size_t rowBytes = fBytesPerPixel*fRects->width();
const unsigned char* dataPtr = fPlotData;
dataPtr += rowBytes*fDirtyRect.fTop;
dataPtr += fBytesPerPixel*fDirtyRect.fLeft;
fTexture->writePixels(fOffset.fX + fDirtyRect.fLeft, fOffset.fY + fDirtyRect.fTop,
fDirtyRect.width(), fDirtyRect.height(), fTexture->config(), dataPtr,
rowBytes, GrContext::kDontFlush_PixelOpsFlag);
fDirtyRect.setEmpty();
fDirty = false;
// If the Plot is nearly full, anything else we add will probably be small and one
// at a time, so free up the memory and after this upload any new images directly.
if (fRects->percentFull() > kNearlyFullTolerance) {
SkDELETE_ARRAY(fPlotData);
fPlotData = NULL;
}
}
}
void GrPlot::resetRects() {
SkASSERT(fRects);
fRects->reset();
@ -258,30 +227,3 @@ void GrAtlas::RemovePlot(ClientPlotUsage* usage, const GrPlot* plot) {
usage->fPlots.remove(index);
}
}
// get a plot that's not being used by the current draw
GrPlot* GrAtlas::getUnusedPlot() {
GrPlotList::Iter plotIter;
plotIter.init(fPlotList, GrPlotList::Iter::kTail_IterStart);
GrPlot* plot;
while ((plot = plotIter.get())) {
if (plot->drawToken().isIssued()) {
return plot;
}
plotIter.prev();
}
return NULL;
}
void GrAtlas::uploadPlotsToTexture() {
if (fBatchUploads) {
GrPlotList::Iter plotIter;
plotIter.init(fPlotList, GrPlotList::Iter::kHead_IterStart);
GrPlot* plot;
while ((plot = plotIter.get())) {
plot->uploadToTexture();
plotIter.next();
}
}
}

View File

@ -41,11 +41,6 @@ public:
bool addSubImage(int width, int height, const void*, SkIPoint16*);
GrDrawTarget::DrawToken drawToken() const { return fDrawToken; }
void setDrawToken(GrDrawTarget::DrawToken draw) { fDrawToken = draw; }
void uploadToTexture();
void resetRects();
private:
@ -54,9 +49,6 @@ private:
void init(GrAtlas* atlas, int id, int offX, int offY, int width, int height, size_t bpp,
bool batchUploads);
// for recycling
GrDrawTarget::DrawToken fDrawToken;
int fID;
unsigned char* fPlotData;
GrTexture* fTexture;
@ -108,16 +100,10 @@ public:
// remove reference to this plot
static void RemovePlot(ClientPlotUsage* usage, const GrPlot* plot);
// get a plot that's not being used by the current draw
// this allows us to overwrite this plot without flushing
GrPlot* getUnusedPlot();
GrTexture* getTexture() const {
return fTexture;
}
void uploadPlotsToTexture();
enum IterOrder {
kLRUFirst_IterOrder,
kMRUFirst_IterOrder
@ -125,7 +111,7 @@ public:
typedef GrPlotList::Iter PlotIter;
GrPlot* iterInit(PlotIter* iter, IterOrder order) {
return iter->init(fPlotList, kLRUFirst_IterOrder == order
return iter->init(fPlotList, kLRUFirst_IterOrder == order
? GrPlotList::Iter::kTail_IterStart
: GrPlotList::Iter::kHead_IterStart);
}

View File

@ -202,23 +202,6 @@ public:
*/
virtual void purgeResources() {};
///////////////////////////////////////////////////////////////////////////
// Draw execution tracking (for font atlases and other resources)
class DrawToken {
public:
DrawToken(GrDrawTarget* drawTarget, uint32_t drawID) :
fDrawTarget(drawTarget), fDrawID(drawID) {}
bool isIssued() { return fDrawTarget && fDrawTarget->isIssued(fDrawID); }
private:
GrDrawTarget* fDrawTarget;
uint32_t fDrawID; // this may wrap, but we're doing direct comparison
// so that should be okay
};
virtual DrawToken getCurrentDrawToken() { return DrawToken(this, 0); }
bool programUnitTest(int maxStages);
protected:

View File

@ -34,9 +34,6 @@ public:
~GrInOrderDrawBuffer() override;
// tracking for draws
DrawToken getCurrentDrawToken() override { return DrawToken(this, fDrawID); }
void clearStencilClip(const SkIRect& rect,
bool insideClip,
GrRenderTarget* renderTarget) override;