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

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: vk stubs Created 4 years, 9 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
« no previous file with comments | « src/gpu/GrGpu.h ('k') | src/gpu/GrProgramDesc.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrGpu.cpp
diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp
index 4e0464a4ce6cb74f0e2c734b5fef8b1f3685e391..c593f311e4d7a502a1242b824d31c1e59b47e16e 100644
--- a/src/gpu/GrGpu.cpp
+++ b/src/gpu/GrGpu.cpp
@@ -47,6 +47,7 @@ GrVertices& GrVertices::operator =(const GrVertices& di) {
GrGpu::GrGpu(GrContext* context)
: fResetTimestamp(kExpiredTimestamp+1)
, fResetBits(kAll_GrBackendState)
+ , fMultisampleSpecsAllocator(1)
, fContext(context) {
}
@@ -444,6 +445,61 @@ void GrGpu::resolveRenderTarget(GrRenderTarget* target) {
this->onResolveRenderTarget(target);
}
+inline static uint8_t multisample_specs_id(uint8_t numSamples, GrSurfaceOrigin origin,
+ const GrCaps& caps) {
+ if (!caps.sampleLocationsSupport()) {
+ return numSamples;
+ }
+
+ SkASSERT(numSamples < 128);
+ SkASSERT(kTopLeft_GrSurfaceOrigin == origin || kBottomLeft_GrSurfaceOrigin == origin);
+ return (numSamples << 1) | (origin - 1);
+
+ GR_STATIC_ASSERT(1 == kTopLeft_GrSurfaceOrigin);
+ GR_STATIC_ASSERT(2 == kBottomLeft_GrSurfaceOrigin);
+}
+
+const GrGpu::MultisampleSpecs& GrGpu::getMultisampleSpecs(GrRenderTarget* rt,
+ const GrStencilSettings& stencil) {
+ const GrSurfaceDesc& desc = rt->desc();
+ uint8_t surfDescKey = multisample_specs_id(desc.fSampleCnt, desc.fOrigin, *this->caps());
+ if (fMultisampleSpecsMap.count() > surfDescKey && fMultisampleSpecsMap[surfDescKey]) {
+#if !defined(SK_DEBUG)
+ // In debug mode we query the multisample info every time and verify the caching is correct.
+ return *fMultisampleSpecsMap[surfDescKey];
+#endif
+ }
+ int effectiveSampleCnt;
+ SkAutoTDeleteArray<SkPoint> locations(nullptr);
+ this->onGetMultisampleSpecs(rt, stencil, &effectiveSampleCnt, &locations);
+ SkASSERT(effectiveSampleCnt && effectiveSampleCnt >= desc.fSampleCnt);
+ uint8_t effectiveKey = multisample_specs_id(effectiveSampleCnt, desc.fOrigin, *this->caps());
+ if (fMultisampleSpecsMap.count() > effectiveKey && fMultisampleSpecsMap[effectiveKey]) {
+ const MultisampleSpecs& specs = *fMultisampleSpecsMap[effectiveKey];
+ SkASSERT(effectiveKey == specs.fUniqueID);
+ SkASSERT(effectiveSampleCnt == specs.fEffectiveSampleCnt);
+ SkASSERT(!this->caps()->sampleLocationsSupport() ||
+ !memcmp(locations.get(), specs.fSampleLocations.get(),
+ effectiveSampleCnt * sizeof(SkPoint)));
+ SkASSERT(surfDescKey <= effectiveKey);
+ SkASSERT(!fMultisampleSpecsMap[surfDescKey] || fMultisampleSpecsMap[surfDescKey] == &specs);
+ fMultisampleSpecsMap[surfDescKey] = &specs;
+ return specs;
+ }
+ const MultisampleSpecs& specs = *new (&fMultisampleSpecsAllocator)
+ MultisampleSpecs{effectiveKey, effectiveSampleCnt, locations.detach()};
+ if (fMultisampleSpecsMap.count() <= effectiveKey) {
+ int n = 1 + effectiveKey - fMultisampleSpecsMap.count();
+ fMultisampleSpecsMap.push_back_n(n, (const MultisampleSpecs*) nullptr);
+ }
+ fMultisampleSpecsMap[effectiveKey] = &specs;
+ if (effectiveSampleCnt != desc.fSampleCnt) {
+ SkASSERT(surfDescKey < effectiveKey);
+ fMultisampleSpecsMap[surfDescKey] = &specs;
+ }
+ return specs;
+}
+
////////////////////////////////////////////////////////////////////////////////
void GrGpu::draw(const DrawArgs& args, const GrVertices& vertices) {
« no previous file with comments | « src/gpu/GrGpu.h ('k') | src/gpu/GrProgramDesc.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698