Revert of small cleanup of GrAtlas (patchset #2 id:20001 of https://codereview.chromium.org/1142263002/)
Reason for revert: Broke compile on Linux Original issue's description: > small cleanup of GrAtlas > > BUG=skia: > > Committed: https://skia.googlesource.com/skia/+/d706f11b6e3f4398ab93b23458a7599ee324be2c TBR=robertphillips@google.com,joshualitt@google.com,jvanverth@google.com,joshualitt@chromium.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=skia: Review URL: https://codereview.chromium.org/1142273002
This commit is contained in:
parent
d706f11b6e
commit
a65358c04d
@ -21,7 +21,8 @@ static int g_UploadCount = 0;
|
||||
#endif
|
||||
|
||||
GrPlot::GrPlot()
|
||||
: fID(-1)
|
||||
: fDrawToken(NULL, 0)
|
||||
, fID(-1)
|
||||
, fTexture(NULL)
|
||||
, fRects(NULL)
|
||||
, fAtlas(NULL)
|
||||
@ -105,6 +106,36 @@ 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();
|
||||
@ -227,3 +258,30 @@ 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -41,6 +41,11 @@ 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:
|
||||
@ -49,6 +54,9 @@ 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;
|
||||
@ -100,10 +108,16 @@ 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
|
||||
|
@ -202,6 +202,23 @@ 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:
|
||||
|
@ -34,6 +34,9 @@ public:
|
||||
|
||||
~GrInOrderDrawBuffer() override;
|
||||
|
||||
// tracking for draws
|
||||
DrawToken getCurrentDrawToken() override { return DrawToken(this, fDrawID); }
|
||||
|
||||
void clearStencilClip(const SkIRect& rect,
|
||||
bool insideClip,
|
||||
GrRenderTarget* renderTarget) override;
|
||||
|
Loading…
Reference in New Issue
Block a user