25GrBackendTextureImageGenerator::RefHelper::RefHelper(
28 std::unique_ptr<GrSemaphore> semaphore)
30 , fOwningContextID(owningContextID)
31 , fBorrowingContextReleaseProc(nullptr)
32 , fSemaphore(
std::move(semaphore)) {}
34GrBackendTextureImageGenerator::RefHelper::~RefHelper() {
35 SkASSERT(!fBorrowingContextID.isValid());
41std::unique_ptr<GrTextureGenerator>
44 std::unique_ptr<GrSemaphore> semaphore,
61 std::move(semaphore)));
64GrBackendTextureImageGenerator::GrBackendTextureImageGenerator(
69 std::unique_ptr<GrSemaphore> semaphore)
71 , fRefHelper(new RefHelper(
texture, owningContextID,
std::move(semaphore)))
72 , fBackendTexture(
texture->getBackendTexture())
73 , fSurfaceOrigin(origin) {}
85void GrBackendTextureImageGenerator::ReleaseRefHelper_TextureReleaseProc(
void* ctx) {
86 RefHelper* refHelper =
static_cast<RefHelper*
>(ctx);
89 refHelper->fBorrowingContextReleaseProc =
nullptr;
90 refHelper->fBorrowingContextID.makeInvalid();
111 if (dContext->backend() != fBackendTexture.
backend()) {
114 if (
info.colorType() != this->getInfo().colorType()) {
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");
129 SkASSERT(fRefHelper->fBorrowingContextReleaseProc);
131 releaseProcHelper =
sk_ref_sp(fRefHelper->fBorrowingContextReleaseProc);
134 SkASSERT(!fRefHelper->fBorrowingContextReleaseProc);
140 fRefHelper->fBorrowingContextReleaseProc = releaseProcHelper.
get();
142 fRefHelper->fBorrowingContextID = dContext->directContextID();
143 if (!fRefHelper->fBorrowedTextureKey.isValid()) {
148 fBorrowingMutex.release();
150 SkASSERT(fRefHelper->fBorrowingContextID == dContext->directContextID());
165 skgpu::Swizzle readSwizzle = dContext->priv().caps()->getReadSwizzle(backendFormat,
171 [refHelper = fRefHelper, releaseProcHelper, backendTexture = fBackendTexture](
174 if (refHelper->fSemaphore) {
175 resourceProvider->priv().gpu()->waitSemaphore(refHelper->fSemaphore.get());
183 SkASSERT(refHelper->fBorrowedTextureKey.isValid());
185 refHelper->fBorrowedTextureKey);
205 tex->resourcePriv().setUniqueKey(refHelper->fBorrowedTextureKey);
221 "BackendTextureImageGenerator");
242 "BackendTextureImageGenerator_GenerateTexture");
243 return {std::move(
copy), fSurfaceOrigin, readSwizzle};
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
@ kBorrow_GrWrapOwnership
static constexpr GrColorType SkColorTypeToGrColorType(SkColorType ct)
#define SkASSERT_RELEASE(cond)
@ kNew_Uncached_Unbudgeted
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
#define INHERITED(method,...)
sk_sp< T > sk_ref_sp(T *obj)
~GrBackendTextureImageGenerator() override
GrSurfaceProxyView onGenerateTexture(GrRecordingContext *, const SkImageInfo &, skgpu::Mipmapped mipmapped, GrImageTexGenPolicy) override
static std::unique_ptr< GrTextureGenerator > Make(const sk_sp< GrTexture > &, GrSurfaceOrigin, std::unique_ptr< GrSemaphore >, SkColorType, SkAlphaType, sk_sp< SkColorSpace >)
bool onIsProtected() const override
SkISize dimensions() const
GrBackendFormat getBackendFormat() const
GrBackendApi backend() const
const GrCaps * caps() const
bool areColorTypeAndFormatCompatible(GrColorType grCT, const GrBackendFormat &format) const
virtual GrDirectContext * asDirectContext()
DirectContextID directContextID() const
GrDirectContextPriv priv()
GrProxyProvider * proxyProvider()
void printWarningMessage(const char *msg) const
GrRecordingContextPriv priv()
static std::enable_if_t< std::is_base_of_v< GrGpuResource, T >, void > ReturnResourceFromThread(sk_sp< T > &&resource, GrDirectContext::DirectContextID id)
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)
virtual GrSurfaceOrigin origin() const
skgpu::Mipmapped mipmapped() const
uint32_t uniqueID() const
static sk_sp< RefCntedCallback > Make(Callback proc, Context ctx)
static Domain GenerateDomain()
SK_API sk_sp< SkDocument > Make(SkWStream *dst, const SkSerialProcs *=nullptr, std::function< void(const SkPicture *)> onEndPage=nullptr)
static constexpr SkIRect MakeWH(int32_t w, int32_t h)