98 {
101
102
103
104
105
107 if (!dContext) {
108 return {};
109 }
110
111 if (dContext->backend() != fBackendTexture.
backend()) {
112 return {};
113 }
114 if (
info.colorType() != this->getInfo().colorType()) {
115 return {};
116 }
117
119
120 fBorrowingMutex.acquire();
122 if (fRefHelper->fBorrowingContextID.isValid()) {
123 if (fRefHelper->fBorrowingContextID != dContext->directContextID()) {
124 fBorrowingMutex.release();
126 "GrBackendTextureImageGenerator: Trying to use texture on two GrContexts!\n");
127 return {};
128 } else {
129 SkASSERT(fRefHelper->fBorrowingContextReleaseProc);
130
131 releaseProcHelper =
sk_ref_sp(fRefHelper->fBorrowingContextReleaseProc);
132 }
133 } else {
134 SkASSERT(!fRefHelper->fBorrowingContextReleaseProc);
135
136
137 fRefHelper->ref();
138 releaseProcHelper =
140 fRefHelper->fBorrowingContextReleaseProc = releaseProcHelper.
get();
141 }
142 fRefHelper->fBorrowingContextID = dContext->directContextID();
143 if (!fRefHelper->fBorrowedTextureKey.isValid()) {
147 }
148 fBorrowingMutex.release();
149
150 SkASSERT(fRefHelper->fBorrowingContextID == dContext->directContextID());
151
154
156
159
160
161
164
165 skgpu::Swizzle readSwizzle = dContext->priv().caps()->getReadSwizzle(backendFormat,
166 grColorType);
167
168
169
171 [refHelper = fRefHelper, releaseProcHelper, backendTexture = fBackendTexture](
174 if (refHelper->fSemaphore) {
175 resourceProvider->priv().gpu()->waitSemaphore(refHelper->fSemaphore.get());
176 }
177
178
179
180
181
183 SkASSERT(refHelper->fBorrowedTextureKey.isValid());
185 refHelper->fBorrowedTextureKey);
189 } else {
190
191
192
193
194
195
196
197
201 if (!tex) {
202 return {};
203 }
205 tex->resourcePriv().setUniqueKey(refHelper->fBorrowedTextureKey);
206 }
207
208
209
211 },
212 backendFormat,
214 textureIsMipMapped,
215 mipmapStatus,
221 "BackendTextureImageGenerator");
222 if (!proxy) {
223 return {};
224 }
225
228
230 } else {
234
236 std::move(proxy),
237 fSurfaceOrigin,
238 mipmapped,
241 budgeted,
242 "BackendTextureImageGenerator_GenerateTexture");
243 return {std::move(
copy), fSurfaceOrigin, readSwizzle};
244 }
245}
@ kBorrow_GrWrapOwnership
#define SkASSERT_RELEASE(cond)
@ kNew_Uncached_Unbudgeted
sk_sp< T > sk_ref_sp(T *obj)
SkISize dimensions() const
GrBackendFormat getBackendFormat() const
GrBackendApi backend() const
virtual GrDirectContext * asDirectContext()
GrProxyProvider * proxyProvider()
void printWarningMessage(const char *msg) const
GrRecordingContextPriv priv()
std::enable_if< std::is_base_of< GrGpuResource, T >::value, sk_sp< T > >::type findByUniqueKey(const skgpu::UniqueKey &key)
sk_sp< GrTexture > wrapBackendTexture(const GrBackendTexture &tex, GrWrapOwnership, GrWrapCacheable, GrIOType)
static sk_sp< GrSurfaceProxy > Copy(GrRecordingContext *, sk_sp< GrSurfaceProxy > src, GrSurfaceOrigin, skgpu::Mipmapped, SkIRect srcRect, SkBackingFit, skgpu::Budgeted, std::string_view label, RectsMustMatch=RectsMustMatch::kNo, sk_sp< GrRenderTask > *outTask=nullptr)
void setRelease(sk_sp< skgpu::RefCntedCallback > releaseHelper)
skgpu::Mipmapped mipmapped() const
uint32_t uniqueID() const
static sk_sp< RefCntedCallback > Make(Callback proc, Context ctx)
static Domain GenerateDomain()
static constexpr SkIRect MakeWH(int32_t w, int32_t h)