Handle the empty case in GrDrawingManager::insertTaskBeforeLast

Change-Id: I3c0f042b28cc39cc6df2f63b52a0f431cee6bda4
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/421826
Reviewed-by: Kevin Lubick <kjlubick@google.com>
Reviewed-by: Adlai Holler <adlai@google.com>
Commit-Queue: Chris Dalton <csmartdalton@google.com>
This commit is contained in:
Chris Dalton 2021-06-25 13:16:24 -06:00 committed by Skia Commit-Bot
parent 9d92d0ff29
commit 061aa81252
2 changed files with 32 additions and 7 deletions

View File

@ -23,17 +23,27 @@ namespace skiagm {
* now, but we decided to keep the test.
*/
class ManyPathAtlasesGM : public GpuGM {
public:
ManyPathAtlasesGM(int maxAtlasSize) : fMaxAtlasSize(maxAtlasSize) {}
private:
SkString onShortName() override { return SkString("manypathatlases"); }
SkString onShortName() override { return SkStringPrintf("manypathatlases_%i", fMaxAtlasSize); }
SkISize onISize() override { return SkISize::Make(128, 128); }
void modifyGrContextOptions(GrContextOptions* ctxOptions) override {
ctxOptions->fMaxTextureAtlasSize = 128; // Put each path in its own atlas.
// This will test the case where the atlas runs out of room if fMaxAtlasSize is small.
ctxOptions->fMaxTextureAtlasSize = fMaxAtlasSize;
}
DrawResult onDraw(GrRecordingContext*, GrSurfaceDrawContext*, SkCanvas* canvas,
DrawResult onDraw(GrRecordingContext* rContext, GrSurfaceDrawContext*, SkCanvas* canvas,
SkString* errorMsg) override {
canvas->clear({1,1,0,1});
// Flush the context to make the DAG empty. This will test the case where we try to add an
// atlas task to an empty DAG.
if (auto dContext = rContext->asDirectContext()) {
dContext->flush();
}
SkPath clip = SkPath().moveTo(-50, 20)
.cubicTo(-50, -20, 50, -20, 50, 40)
.cubicTo(20, 0, -20, 0, -50, 20);
@ -56,8 +66,11 @@ private:
canvas->drawPath(path, teal);
return DrawResult::kOk;
}
const int fMaxAtlasSize;
};
DEF_GM( return new ManyPathAtlasesGM(); )
DEF_GM( return new ManyPathAtlasesGM(128); ) // Atlas runs out of room.
DEF_GM( return new ManyPathAtlasesGM(2048); ) // Atlas does not run out of room.
} // namespace skiagm

View File

@ -452,10 +452,12 @@ void GrDrawingManager::closeAllTasks() {
}
GrRenderTask* GrDrawingManager::insertTaskBeforeLast(sk_sp<GrRenderTask> task) {
SkASSERT(!fDAG.empty());
if (!task) {
return nullptr;
}
if (fDAG.empty()) {
return fDAG.push_back(std::move(task)).get();
}
// Release 'fDAG.back()' and grab the raw pointer, in case the SkTArray grows
// and reallocates during emplace_back.
// TODO: Either use std::vector that can do this for us, or use SkSTArray to get the
@ -662,8 +664,18 @@ void GrDrawingManager::validate() const {
}
}
if (!fDAG.empty() && !fDAG.back()->isClosed()) {
SkASSERT(fActiveOpsTask == fDAG.back().get());
// The active opsTask, if any, should always be at the back of the DAG.
if (!fDAG.empty()) {
if (fDAG.back()->isSetFlag(GrRenderTask::kAtlas_Flag)) {
SkASSERT(fActiveOpsTask == nullptr);
SkASSERT(!fDAG.back()->isClosed());
} else if (fDAG.back()->isClosed()) {
SkASSERT(fActiveOpsTask == nullptr);
} else {
SkASSERT(fActiveOpsTask == fDAG.back().get());
}
} else {
SkASSERT(fActiveOpsTask == nullptr);
}
}
#endif