Refactor to separate backend object lifecycle and GpuResource budget decision
Refactor GrGpuResource to contain two different pieces of state:
a) instance is budgeted or not budgeted
b) instance references wrapped backend objects or not
The "object lifecycle" was also attached to backend object
handles (ids), which made the code a bit unclear. Backend objects
would be associated with GrGpuResource::LifeCycle, even though
GrGpuResource::LifeCycle refers to the GpuResource, and individual
backend objects in one GpuResource might be governed with different
"lifecycle".
Mark the budgeted/not budgeted with SkBudgeted::kYes, SkBudgeted::kNo.
This was previously GrGpuResource::kCached_LifeCycle,
GrGpuResource::kUncached_LifeCycle.
Mark the "references wrapped object" with boolean. This was previously
GrGpuResource::kBorrowed_LifeCycle,
GrGpuResource::kAdopted_LifeCycle for GrGpuResource.
Associate the backend object ownership status with
GrBackendObjectOwnership for the backend object handles.
The resource type leaf constuctors, such has GrGLTexture or
GrGLTextureRenderTarget take "budgeted" parameter. This parameter
is passed to GrGpuResource::registerWithCache().
The resource type intermediary constructors, such as GrGLTexture
constructors for class GrGLTextureRenderTarget do not take "budgeted"
parameters, intermediary construtors do not call registerWithCache.
Removes the need for tagging GrGpuResource -derived subclass
constructors with "Derived" parameter.
Makes instances that wrap backend objects be registered with
a new function GrGpuResource::registerWithCacheWrapped().
Removes "budgeted" parameter from classes such as StencilAttahment, as
they are always cached and never wrap any external backend objects.
Removes the use of concept "external" from the member function names.
The API refers to the objects as "wrapped", so make all related
functions use the term consistently.
No change in functionality. Resources referencing wrapped objects are
always inserted to the cache with budget decision kNo.
BUG=594928
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1862043002
Review URL: https://codereview.chromium.org/1862043002
diff --git a/src/gpu/vk/GrVkTextureRenderTarget.cpp b/src/gpu/vk/GrVkTextureRenderTarget.cpp
index 7c085a3..6bfdf3e 100644
--- a/src/gpu/vk/GrVkTextureRenderTarget.cpp
+++ b/src/gpu/vk/GrVkTextureRenderTarget.cpp
@@ -16,13 +16,12 @@
#define VK_CALL(GPU, X) GR_VK_CALL(GPU->vkInterface(), X)
-GrVkTextureRenderTarget*
-GrVkTextureRenderTarget::Create(GrVkGpu* gpu,
- const GrSurfaceDesc& desc,
- GrGpuResource::LifeCycle lifeCycle,
- VkFormat format,
- const GrVkImage::Resource* imageResource) {
-
+template<typename ResourceType>
+GrVkTextureRenderTarget* GrVkTextureRenderTarget::Create(GrVkGpu* gpu,
+ ResourceType resourceType,
+ const GrSurfaceDesc& desc,
+ VkFormat format,
+ const GrVkImage::Resource* imageResource) {
VkImage image = imageResource->fImage;
// Create the texture ImageView
const GrVkImageView* imageView = GrVkImageView::Create(gpu, image, format,
@@ -99,16 +98,15 @@
return nullptr;
}
}
-
GrVkTextureRenderTarget* texRT;
if (msaaImageResource) {
- texRT = new GrVkTextureRenderTarget(gpu, desc, lifeCycle,
+ texRT = new GrVkTextureRenderTarget(gpu, resourceType, desc,
imageResource, imageView, msaaImageResource,
colorAttachmentView,
resolveAttachmentView);
msaaImageResource->unref(gpu);
} else {
- texRT = new GrVkTextureRenderTarget(gpu, desc, lifeCycle,
+ texRT = new GrVkTextureRenderTarget(gpu, resourceType, desc,
imageResource, imageView,
colorAttachmentView);
}
@@ -117,9 +115,9 @@
GrVkTextureRenderTarget*
GrVkTextureRenderTarget::CreateNewTextureRenderTarget(GrVkGpu* gpu,
- const GrSurfaceDesc& desc,
- GrGpuResource::LifeCycle lifeCycle,
- const GrVkImage::ImageDesc& imageDesc) {
+ SkBudgeted budgeted,
+ const GrSurfaceDesc& desc,
+ const GrVkImage::ImageDesc& imageDesc) {
SkASSERT(imageDesc.fUsageFlags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
SkASSERT(imageDesc.fUsageFlags & VK_IMAGE_USAGE_SAMPLED_BIT);
@@ -129,8 +127,8 @@
return nullptr;
}
- GrVkTextureRenderTarget* trt = GrVkTextureRenderTarget::Create(gpu, desc, lifeCycle,
- imageDesc.fFormat, imageRsrc);
+ GrVkTextureRenderTarget* trt = Create(gpu, budgeted, desc, imageDesc.fFormat,
+ imageRsrc);
// Create() will increment the refCount of the image resource if it succeeds
imageRsrc->unref(gpu);
@@ -140,7 +138,7 @@
GrVkTextureRenderTarget*
GrVkTextureRenderTarget::CreateWrappedTextureRenderTarget(GrVkGpu* gpu,
const GrSurfaceDesc& desc,
- GrGpuResource::LifeCycle lifeCycle,
+ GrWrapOwnership ownership,
VkFormat format,
const GrVkTextureInfo* info) {
SkASSERT(info);
@@ -151,7 +149,7 @@
? Resource::kLinearTiling_Flag : Resource::kNo_Flags;
const GrVkImage::Resource* imageResource;
- if (kBorrowed_LifeCycle == lifeCycle) {
+ if (kBorrow_GrWrapOwnership == ownership) {
imageResource = new GrVkImage::BorrowedResource(info->fImage,
info->fAlloc,
flags,
@@ -162,9 +160,7 @@
if (!imageResource) {
return nullptr;
}
-
- GrVkTextureRenderTarget* trt = GrVkTextureRenderTarget::Create(gpu, desc, lifeCycle,
- format, imageResource);
+ GrVkTextureRenderTarget* trt = Create(gpu, kWrapped, desc, format, imageResource);
if (trt) {
trt->fCurrentLayout = info->fImageLayout;
}