Index: src/gpu/GrGpu.cpp |
diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp |
index 4e0464a4ce6cb74f0e2c734b5fef8b1f3685e391..566f2be8e18264956a96d4ad32b608e3ee0954c0 100644 |
--- a/src/gpu/GrGpu.cpp |
+++ b/src/gpu/GrGpu.cpp |
@@ -47,7 +47,8 @@ GrVertices& GrVertices::operator =(const GrVertices& di) { |
GrGpu::GrGpu(GrContext* context) |
: fResetTimestamp(kExpiredTimestamp+1) |
, fResetBits(kAll_GrBackendState) |
- , fContext(context) { |
+ , fContext(context) |
+ , fNextSamplePatternID(1) { |
} |
GrGpu::~GrGpu() {} |
@@ -444,6 +445,57 @@ void GrGpu::resolveRenderTarget(GrRenderTarget* target) { |
this->onResolveRenderTarget(target); |
} |
+const GrGpu::MultisampleSpecs& GrGpu::getMultisampleSpecs(GrRenderTarget* rt, |
+ const GrStencilSettings& stencil) { |
+ skstd::unique_ptr<MultisampleSpecs>* specsPtr; |
+ bool willUseRasterMultisample = rt->hasMixedSamples() && stencil.isDisabled(); |
+ if (willUseRasterMultisample) { |
+ int rasterSampleCnt = rt->desc().fSampleCnt; |
+ SkASSERT(rasterSampleCnt > 0 && rasterSampleCnt <= this->caps()->maxRasterSamples()); |
+ fRasterMultisampleSpecs.resize_back(SkTMax(fRasterMultisampleSpecs.count(), |
+ rasterSampleCnt)); |
+ specsPtr = &fRasterMultisampleSpecs[rasterSampleCnt - 1]; |
+ } else { |
+ specsPtr = rt->renderTargetPriv().accessMultisampleSpecs(); |
+ } |
+ if (!specsPtr->get()) { |
+ MultisampleSpecs* specs = new MultisampleSpecs; |
+ SkSTArray<16, SkPoint, true> samplePattern; |
+ this->onGetMultisampleSpecs(rt, stencil, &specs->fEffectiveSampleCnt, &samplePattern); |
+ if (this->caps()->sampleLocationsSupport()) { |
+ SkASSERT(!samplePattern.empty()); |
+ const auto& result = fKnownSamplePatterns.emplace(samplePattern, fNextSamplePatternID); |
+ if (result.second) { |
+ // This sample pattern didn't exist already in the map. (We don't expect to see very |
+ // many unique sample patterns). |
+ SkASSERT(fKnownSamplePatterns.size() < 65535); |
+ do {} while (0 == ++fNextSamplePatternID); |
+ } |
+ specs->fSamplePatternID = result.first->second; |
+ specs->fSampleLocations = result.first->first.begin(); |
+ } |
+ specsPtr->reset(specs); |
+ } |
+ return *specsPtr->get(); |
+} |
+ |
+bool GrGpu::SamplePatternComparator::operator()(const SamplePattern& a, |
+ const SamplePattern& b) const { |
+ if (a.count() != b.count()) { |
+ return a.count() < b.count(); |
+ } |
+ for (int i = 0; i < a.count(); ++i) { |
+ // This doesn't have geometric meaning. We just need to define an ordering for std::map. |
+ if (a[i].x() != b[i].x()) { |
+ return a[i].x() < b[i].x(); |
+ } |
+ if (a[i].y() != b[i].y()) { |
+ return a[i].y() < b[i].y(); |
+ } |
+ } |
+ return false; // Equal. |
+} |
+ |
//////////////////////////////////////////////////////////////////////////////// |
void GrGpu::draw(const DrawArgs& args, const GrVertices& vertices) { |