Make GrFragmentProcessor be non-refcounted and use std::unique_ptr.
Change-Id: I985e54a071338e99292a5aa2f42c92bc115b4008
Reviewed-on: https://skia-review.googlesource.com/32760
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
diff --git a/src/gpu/GrProcessorSet.cpp b/src/gpu/GrProcessorSet.cpp
index 20d6745..cb4a25f 100644
--- a/src/gpu/GrProcessorSet.cpp
+++ b/src/gpu/GrProcessorSet.cpp
@@ -29,11 +29,11 @@
int i = 0;
for (auto& fp : paint.fColorFragmentProcessors) {
SkASSERT(fp.get());
- fFragmentProcessors[i++] = fp.release();
+ fFragmentProcessors[i++] = std::move(fp);
}
for (auto& fp : paint.fCoverageFragmentProcessors) {
SkASSERT(fp.get());
- fFragmentProcessors[i++] = fp.release();
+ fFragmentProcessors[i++] = std::move(fp);
}
} else {
SkDebugf("Insane number of color fragment processors in paint. Dropping all processors.");
@@ -47,14 +47,14 @@
, fFragmentProcessorOffset(0)
, fFlags(0) {}
-GrProcessorSet::GrProcessorSet(sk_sp<GrFragmentProcessor> colorFP)
+GrProcessorSet::GrProcessorSet(std::unique_ptr<GrFragmentProcessor> colorFP)
: fFragmentProcessors(1)
, fXP((const GrXPFactory*)nullptr)
, fColorFragmentProcessorCnt(1)
, fFragmentProcessorOffset(0)
, fFlags(0) {
SkASSERT(colorFP);
- fFragmentProcessors[0] = colorFP.release();
+ fFragmentProcessors[0] = std::move(colorFP);
}
GrProcessorSet::GrProcessorSet(GrProcessorSet&& that)
@@ -64,20 +64,14 @@
, fFlags(that.fFlags) {
fFragmentProcessors.reset(that.fFragmentProcessors.count() - that.fFragmentProcessorOffset);
for (int i = 0; i < fFragmentProcessors.count(); ++i) {
- fFragmentProcessors[i] = that.fFragmentProcessors[i + that.fFragmentProcessorOffset];
+ fFragmentProcessors[i] =
+ std::move(that.fFragmentProcessors[i + that.fFragmentProcessorOffset]);
}
that.fColorFragmentProcessorCnt = 0;
that.fFragmentProcessors.reset(0);
}
GrProcessorSet::~GrProcessorSet() {
- for (int i = fFragmentProcessorOffset; i < fFragmentProcessors.count(); ++i) {
- if (this->isFinalized()) {
- fFragmentProcessors[i]->completedExecution();
- } else {
- fFragmentProcessors[i]->unref();
- }
- }
if (this->isFinalized() && this->xferProcessor()) {
this->xferProcessor()->unref();
}
@@ -173,8 +167,10 @@
analysis.fCompatibleWithCoverageAsAlpha = GrProcessorAnalysisCoverage::kLCD != coverageInput;
const GrFragmentProcessor* clipFP = clip ? clip->clipCoverageFragmentProcessor() : nullptr;
- const GrFragmentProcessor* const* fps = fFragmentProcessors.get() + fFragmentProcessorOffset;
- GrColorFragmentProcessorAnalysis colorAnalysis(colorInput, fps, fColorFragmentProcessorCnt);
+ const std::unique_ptr<const GrFragmentProcessor>* fps =
+ fFragmentProcessors.get() + fFragmentProcessorOffset;
+ GrColorFragmentProcessorAnalysis colorAnalysis(
+ colorInput, unique_ptr_address_as_pointer_address(fps), fColorFragmentProcessorCnt);
analysis.fCompatibleWithCoverageAsAlpha &=
colorAnalysis.allProcessorsCompatibleWithCoverageAsAlpha();
fps += fColorFragmentProcessorCnt;
@@ -236,12 +232,10 @@
analysis.fUsesLocalCoords = coverageUsesLocalCoords | colorAnalysis.usesLocalCoords();
}
for (int i = 0; i < colorFPsToEliminate; ++i) {
- fFragmentProcessors[i]->unref();
- fFragmentProcessors[i] = nullptr;
+ fFragmentProcessors[i].reset(nullptr);
}
for (int i = colorFPsToEliminate; i < fFragmentProcessors.count(); ++i) {
- fFragmentProcessors[i]->addPendingExecution();
- fFragmentProcessors[i]->unref();
+ fFragmentProcessors[i]->markPendingExecution();
}
fFragmentProcessorOffset = colorFPsToEliminate;
fColorFragmentProcessorCnt -= colorFPsToEliminate;