Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(438)

Unified Diff: src/gpu/GrGpu.cpp

Issue 1717393002: Add "sample locations" feature to GrProcessor (Closed) Base URL: https://skia.googlesource.com/skia.git@upload_getmultisamp
Patch Set: move into GrProcessor Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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) {

Powered by Google App Engine
This is Rietveld 408576698