Add support for wrapped GrAttachments.
Bug: skia:10828
Change-Id: Ifab9c2b179fa981a94d03ff96718c3b31f745fee
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/331338
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
diff --git a/src/gpu/vk/GrVkAttachment.cpp b/src/gpu/vk/GrVkAttachment.cpp
index cefd207..1f965ac 100644
--- a/src/gpu/vk/GrVkAttachment.cpp
+++ b/src/gpu/vk/GrVkAttachment.cpp
@@ -27,6 +27,20 @@
this->registerWithCache(budgeted);
}
+GrVkAttachment::GrVkAttachment(GrVkGpu* gpu,
+ SkISize dimensions,
+ UsageFlags supportedUsages,
+ const GrVkImageInfo& info,
+ sk_sp<GrBackendSurfaceMutableStateImpl> mutableState,
+ sk_sp<const GrVkImageView> view,
+ GrBackendObjectOwnership ownership,
+ GrWrapCacheable cacheable)
+ : GrAttachment(gpu, dimensions, supportedUsages, info.fSampleCount, info.fProtected)
+ , GrVkImage(gpu, info, std::move(mutableState), ownership)
+ , fView(std::move(view)) {
+ this->registerWithCacheWrapped(cacheable);
+}
+
sk_sp<GrVkAttachment> GrVkAttachment::MakeStencil(GrVkGpu* gpu,
SkISize dimensions,
int sampleCnt,
@@ -98,6 +112,37 @@
budgeted));
}
+sk_sp<GrAttachment> GrVkAttachment::MakeWrapped(
+ GrVkGpu* gpu,
+ SkISize dimensions,
+ const GrVkImageInfo& info,
+ sk_sp<GrBackendSurfaceMutableStateImpl> mutableState,
+ UsageFlags attachmentUsages,
+ GrWrapOwnership ownership,
+ GrWrapCacheable cacheable) {
+ GrVkImageView::Type viewType;
+ if (attachmentUsages & UsageFlags::kStencil) {
+ // If we have stencil usage than we should not have any other usages
+ SkASSERT(attachmentUsages == UsageFlags::kStencil);
+ viewType = GrVkImageView::kStencil_Type;
+ } else {
+ viewType = GrVkImageView::kColor_Type;
+ }
+
+ sk_sp<const GrVkImageView> imageView = GrVkImageView::Make(
+ gpu, info.fImage, info.fFormat, viewType, info.fLevelCount, info.fYcbcrConversionInfo);
+ if (!imageView) {
+ return nullptr;
+ }
+
+ GrBackendObjectOwnership backendOwnership = kBorrow_GrWrapOwnership == ownership
+ ? GrBackendObjectOwnership::kBorrowed : GrBackendObjectOwnership::kOwned;
+
+ return sk_sp<GrVkAttachment>(new GrVkAttachment(gpu, dimensions, attachmentUsages, info,
+ std::move(mutableState), std::move(imageView),
+ backendOwnership, cacheable));
+}
+
GrVkAttachment::~GrVkAttachment() {
// should have been released or abandoned first
SkASSERT(!fView);
diff --git a/src/gpu/vk/GrVkAttachment.h b/src/gpu/vk/GrVkAttachment.h
index 4b93266..be4f113 100644
--- a/src/gpu/vk/GrVkAttachment.h
+++ b/src/gpu/vk/GrVkAttachment.h
@@ -28,6 +28,14 @@
VkFormat format,
GrProtected isProtected);
+ static sk_sp<GrAttachment> MakeWrapped(GrVkGpu* gpu,
+ SkISize dimensions,
+ const GrVkImageInfo&,
+ sk_sp<GrBackendSurfaceMutableStateImpl>,
+ UsageFlags attachmentUsages,
+ GrWrapOwnership,
+ GrWrapCacheable);
+
~GrVkAttachment() override;
GrBackendFormat backendFormat() const override { return this->getBackendFormat(); }
@@ -57,6 +65,15 @@
sk_sp<const GrVkImageView> view,
SkBudgeted);
+ GrVkAttachment(GrVkGpu* gpu,
+ SkISize dimensions,
+ UsageFlags supportedUsages,
+ const GrVkImageInfo&,
+ sk_sp<GrBackendSurfaceMutableStateImpl> mutableState,
+ sk_sp<const GrVkImageView> view,
+ GrBackendObjectOwnership,
+ GrWrapCacheable);
+
GrVkGpu* getVkGpu() const;
sk_sp<const GrVkImageView> fView;