Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrVkTexture.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8
10
19
21
22#define VK_CALL(GPU, X) GR_VK_CALL(GPU->vkInterface(), X)
23
24// Because this class is virtually derived from GrSurface we must explicitly call its constructor.
26 skgpu::Budgeted budgeted,
27 SkISize dimensions,
29 GrMipmapStatus mipmapStatus,
30 std::string_view label)
31 : GrSurface(gpu,
32 dimensions,
33 texture->isProtected() ? GrProtected::kYes : GrProtected::kNo,
34 label)
35 , GrTexture(gpu,
36 dimensions,
37 texture->isProtected() ? GrProtected::kYes : GrProtected::kNo,
39 mipmapStatus,
40 label)
41 , fTexture(std::move(texture))
42 , fDescSetCache(kMaxCachedDescSets) {
43 SkASSERT((GrMipmapStatus::kNotAllocated == mipmapStatus) == (1 == fTexture->mipLevels()));
44 // We don't support creating external GrVkTextures
45 SkASSERT(!fTexture->ycbcrConversionInfo().isValid() ||
46 !fTexture->ycbcrConversionInfo().fExternalFormat);
47 SkASSERT(SkToBool(fTexture->vkUsageFlags() & VK_IMAGE_USAGE_SAMPLED_BIT));
48 this->registerWithCache(budgeted);
49 if (skgpu::VkFormatIsCompressed(fTexture->imageFormat())) {
50 this->setReadOnly();
51 }
52}
53
55 SkISize dimensions,
57 GrMipmapStatus mipmapStatus,
58 GrWrapCacheable cacheable,
59 GrIOType ioType,
60 bool isExternal,
61 std::string_view label)
62 : GrSurface(gpu,
63 dimensions,
64 texture->isProtected() ? GrProtected::kYes : GrProtected::kNo,
65 label)
66 , GrTexture(gpu,
67 dimensions,
68 texture->isProtected() ? GrProtected::kYes : GrProtected::kNo,
70 mipmapStatus,
71 label)
72 , fTexture(std::move(texture))
73 , fDescSetCache(kMaxCachedDescSets) {
74 SkASSERT((GrMipmapStatus::kNotAllocated == mipmapStatus) == (1 == fTexture->mipLevels()));
75 SkASSERT(SkToBool(fTexture->vkUsageFlags() & VK_IMAGE_USAGE_SAMPLED_BIT));
76 if (ioType == kRead_GrIOType) {
77 this->setReadOnly();
78 }
79 this->registerWithCacheWrapped(cacheable);
80}
81
82// Because this class is virtually derived from GrSurface we must explicitly call its constructor.
84 SkISize dimensions,
86 GrMipmapStatus mipmapStatus,
87 std::string_view label)
88 : GrSurface(gpu,
89 dimensions,
90 texture->isProtected() ? GrProtected::kYes : GrProtected::kNo,
91 label)
92 , GrTexture(gpu,
93 dimensions,
94 texture->isProtected() ? GrProtected::kYes : GrProtected::kNo,
96 mipmapStatus,
97 label)
98 , fTexture(std::move(texture))
99 , fDescSetCache(kMaxCachedDescSets) {
101 // Since this ctor is only called from GrVkTextureRenderTarget, we can't have a ycbcr conversion
102 // since we don't support that on render targets.
103 SkASSERT(!fTexture->ycbcrConversionInfo().isValid());
105}
106
108 skgpu::Budgeted budgeted,
109 SkISize dimensions,
111 uint32_t mipLevels,
112 GrProtected isProtected,
113 GrMipmapStatus mipmapStatus,
114 std::string_view label) {
116 gpu, dimensions, format, mipLevels, GrRenderable::kNo, /*numSamples=*/1, budgeted,
118
119 if (!texture) {
120 return nullptr;
121 }
123 gpu, budgeted, dimensions, std::move(texture), mipmapStatus, label));
124}
125
127 GrVkGpu* gpu, SkISize dimensions, GrWrapOwnership wrapOwnership, GrWrapCacheable cacheable,
128 GrIOType ioType, const GrVkImageInfo& info,
130 // Adopted textures require both image and allocation because we're responsible for freeing
131 SkASSERT(VK_NULL_HANDLE != info.fImage &&
132 (kBorrow_GrWrapOwnership == wrapOwnership || VK_NULL_HANDLE != info.fAlloc.fMemory));
133
136 info,
137 std::move(mutableState),
139 wrapOwnership,
140 cacheable,
141 "VkImage_MakeWrappedTexture");
142 if (!texture) {
143 return nullptr;
144 }
145
148
149 bool isExternal = info.fYcbcrConversionInfo.isValid() &&
150 (info.fYcbcrConversionInfo.fExternalFormat != 0);
151 isExternal |= (info.fImageTiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT);
152 return sk_sp<GrVkTexture>(new GrVkTexture(gpu,
154 std::move(texture),
156 cacheable,
157 ioType,
158 isExternal,
159 /*label=*/"Vk_MakeWrappedTexture"));
160}
161
163 // either release or abandon should have been called by the owner of this object.
164 SkASSERT(!fTexture);
165}
166
168 fTexture.reset();
169
170 fDescSetCache.reset();
171
173}
174
187
189 fTexture.reset();
190
191 fDescSetCache.reset();
192
194}
195
197 return GrBackendTextures::MakeVk(fTexture->width(),
198 fTexture->height(),
199 fTexture->vkImageInfo(),
200 fTexture->getMutableState());
201}
202
204 SkASSERT(!this->wasDestroyed());
205 return static_cast<GrVkGpu*>(this->getGpu());
206}
207
208const GrVkImageView* GrVkTexture::textureView() { return fTexture->textureView(); }
209
211 if (std::unique_ptr<DescriptorCacheEntry>* e = fDescSetCache.find(state)) {
212 return (*e)->fDescriptorSet;
213 }
214 return nullptr;
215}
216
218 SkASSERT(!fDescSetCache.find(state));
219 descSet->ref();
220 fDescSetCache.insert(state, std::make_unique<DescriptorCacheEntry>(descSet, this->getVkGpu()));
221}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
GrWrapCacheable
Definition GrTypesPriv.h:84
GrIOType
@ kRead_GrIOType
GrMipmapStatus
GrWrapOwnership
Definition GrTypesPriv.h:76
@ kBorrow_GrWrapOwnership
Definition GrTypesPriv.h:78
GrTextureType
#define SkASSERT(cond)
Definition SkAssert.h:116
@ kYes
Do pre-clip the geometry before applying the (perspective) matrix.
@ kNo
Don't pre-clip the geometry before applying the (perspective) matrix.
static constexpr bool SkToBool(const T &x)
Definition SkTo.h:35
virtual void onAbandon()
GrGpu * getGpu() const
bool wasDestroyed() const
virtual void onRelease()
SkISize dimensions() const
Definition GrSurface.h:27
bool isProtected() const
Definition GrSurface.h:87
int height() const
Definition GrSurface.h:37
int width() const
Definition GrSurface.h:32
GrMipmapStatus mipmapStatus() const
Definition GrTexture.h:66
const GrVkImageView * textureView() const
Definition GrVkImage.h:106
uint32_t mipLevels() const
Definition GrVkImage.h:93
const GrVkYcbcrConversionInfo & ycbcrConversionInfo() const
Definition GrVkImage.h:94
sk_sp< skgpu::MutableTextureState > getMutableState() const
Definition GrVkImage.h:130
VkImageUsageFlags vkUsageFlags()
Definition GrVkImage.h:100
static sk_sp< GrVkImage > MakeWrapped(GrVkGpu *gpu, SkISize dimensions, const GrVkImageInfo &, sk_sp< skgpu::MutableTextureState >, UsageFlags attachmentUsages, GrWrapOwnership, GrWrapCacheable, std::string_view label, bool forSecondaryCB=false)
static sk_sp< GrVkImage > MakeTexture(GrVkGpu *gpu, SkISize dimensions, VkFormat format, uint32_t mipLevels, GrRenderable renderable, int numSamples, skgpu::Budgeted budgeted, GrProtected isProtected)
Definition GrVkImage.cpp:65
const GrVkImageInfo & vkImageInfo() const
Definition GrVkImage.h:81
GrBackendTexture getBackendTexture() const override
void onRelease() override
const GrVkImageView * textureView()
GrVkGpu * getVkGpu() const
~GrVkTexture() override
void onAbandon() override
const GrVkDescriptorSet * cachedSingleDescSet(GrSamplerState)
void addDescriptorSetToCache(const GrVkDescriptorSet *, GrSamplerState)
GrVkTexture(GrVkGpu *, SkISize dimensions, sk_sp< GrVkImage > texture, GrMipmapStatus, std::string_view label)
static sk_sp< GrVkTexture > MakeWrappedTexture(GrVkGpu *, SkISize dimensions, GrWrapOwnership, GrWrapCacheable, GrIOType, const GrVkImageInfo &, sk_sp< skgpu::MutableTextureState >)
static sk_sp< GrVkTexture > MakeNewTexture(GrVkGpu *, skgpu::Budgeted budgeted, SkISize dimensions, VkFormat format, uint32_t mipLevels, GrProtected, GrMipmapStatus, std::string_view label)
void reset(T *ptr=nullptr)
Definition SkRefCnt.h:310
AtkStateType state
uint32_t uint32_t * format
FlTexture * texture
SK_API GrBackendTexture MakeVk(int width, int height, const GrVkImageInfo &, std::string_view label={})
Budgeted
Definition GpuTypes.h:35
static constexpr bool VkFormatIsCompressed(VkFormat vkFormat)
Protected
Definition GpuTypes.h:61
Definition ref_ptr.h:256
const GrVkDescriptorSet * fDescriptorSet
DescriptorCacheEntry(const GrVkDescriptorSet *fDescSet, GrVkGpu *gpu)
@ VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT
@ VK_IMAGE_USAGE_SAMPLED_BIT
#define VK_NULL_HANDLE
Definition vulkan_core.h:46
VkFormat