Add scratch msaa attachment creation to GrResourceProvider.
This basically adds the functionality to GrResourceProvider to handle
scrate MSAA attachments. There are not current users of this, but
users will be added in follow on changes.
Bug: skia:10727
Change-Id: Ieb8d247e034fb22ac9ff4fc549935310329a1c1e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/320267
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/GrResourceProvider.cpp b/src/gpu/GrResourceProvider.cpp
index 0521944..ce3cf90 100644
--- a/src/gpu/GrResourceProvider.cpp
+++ b/src/gpu/GrResourceProvider.cpp
@@ -533,6 +533,54 @@
return false;
}
+sk_sp<GrAttachment> GrResourceProvider::makeMSAAAttachment(SkISize dimensions,
+ const GrBackendFormat& format,
+ int sampleCnt,
+ GrProtected isProtected) {
+ ASSERT_SINGLE_OWNER
+
+ SkASSERT(sampleCnt > 1);
+
+ if (this->isAbandoned()) {
+ return nullptr;
+ }
+
+ if (!fCaps->validateSurfaceParams(dimensions, format, GrRenderable::kYes, sampleCnt,
+ GrMipMapped::kNo)) {
+ return nullptr;
+ }
+
+ auto scratch = this->refScratchMSAAAttachment(dimensions, format, sampleCnt, isProtected);
+ if (scratch) {
+ return scratch;
+ }
+
+ return fGpu->makeMSAAAttachment(dimensions, format, sampleCnt, isProtected);
+}
+
+sk_sp<GrAttachment> GrResourceProvider::refScratchMSAAAttachment(SkISize dimensions,
+ const GrBackendFormat& format,
+ int sampleCnt,
+ GrProtected isProtected) {
+ ASSERT_SINGLE_OWNER
+ SkASSERT(!this->isAbandoned());
+ SkASSERT(!this->caps()->isFormatCompressed(format));
+ SkASSERT(fCaps->validateSurfaceParams(dimensions, format, GrRenderable::kYes, sampleCnt,
+ GrMipmapped::kNo));
+
+ GrScratchKey key;
+ GrAttachment::ComputeScratchKey(*this->caps(), format, dimensions,
+ GrAttachment::UsageFlags::kMSAA, sampleCnt, isProtected, &key);
+ GrGpuResource* resource = fCache->findAndRefScratchResource(key);
+ if (resource) {
+ fGpu->stats()->incNumScratchMSAAAttachmentsReused();
+ GrAttachment* attachment = static_cast<GrAttachment*>(resource);
+ return sk_sp<GrAttachment>(attachment);
+ }
+
+ return nullptr;
+}
+
std::unique_ptr<GrSemaphore> SK_WARN_UNUSED_RESULT GrResourceProvider::makeSemaphore(
bool isOwned) {
return this->isAbandoned() ? nullptr : fGpu->makeSemaphore(isOwned);