Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
GrBackendTextureImageGenerator Class Reference

#include <GrBackendTextureImageGenerator.h>

Inheritance diagram for GrBackendTextureImageGenerator:
GrTextureGenerator SkImageGenerator

Public Member Functions

 ~GrBackendTextureImageGenerator () override
 
- Public Member Functions inherited from GrTextureGenerator
bool isTextureGenerator () const final
 
GrSurfaceProxyView generateTexture (GrRecordingContext *, const SkImageInfo &info, skgpu::Mipmapped mipmapped, GrImageTexGenPolicy)
 
virtual GrSurfaceProxyView onGenerateTexture (GrRecordingContext *, const SkImageInfo &, skgpu::Mipmapped, GrImageTexGenPolicy)=0
 
virtual GrSurfaceOrigin origin () const
 
- Public Member Functions inherited from SkImageGenerator
virtual ~SkImageGenerator ()
 
uint32_t uniqueID () const
 
sk_sp< SkDatarefEncodedData ()
 
const SkImageInfogetInfo () const
 
bool isValid (GrRecordingContext *context) const
 
bool isProtected () const
 
bool getPixels (const SkImageInfo &info, void *pixels, size_t rowBytes)
 
bool getPixels (const SkPixmap &pm)
 
bool queryYUVAInfo (const SkYUVAPixmapInfo::SupportedDataTypes &supportedDataTypes, SkYUVAPixmapInfo *yuvaPixmapInfo) const
 
bool getYUVAPlanes (const SkYUVAPixmaps &yuvaPixmaps)
 
virtual bool isTextureGenerator () const
 

Static Public Member Functions

static std::unique_ptr< GrTextureGeneratorMake (const sk_sp< GrTexture > &, GrSurfaceOrigin, std::unique_ptr< GrSemaphore >, SkColorType, SkAlphaType, sk_sp< SkColorSpace >)
 

Protected Member Functions

bool onIsValid (GrRecordingContext *context) const override
 
bool onIsProtected () const override
 
GrSurfaceProxyView onGenerateTexture (GrRecordingContext *, const SkImageInfo &, skgpu::Mipmapped mipmapped, GrImageTexGenPolicy) override
 
- Protected Member Functions inherited from GrTextureGenerator
 GrTextureGenerator (const SkImageInfo &info, uint32_t uniqueId=kNeedNewImageUniqueID)
 
- Protected Member Functions inherited from SkImageGenerator
 SkImageGenerator (const SkImageInfo &info, uint32_t uniqueId=kNeedNewImageUniqueID)
 
virtual sk_sp< SkDataonRefEncodedData ()
 
virtual bool onGetPixels (const SkImageInfo &, void *, size_t, const Options &)
 
virtual bool onIsValid (GrRecordingContext *) const
 
virtual bool onIsProtected () const
 
virtual bool onQueryYUVAInfo (const SkYUVAPixmapInfo::SupportedDataTypes &, SkYUVAPixmapInfo *) const
 
virtual bool onGetYUVAPlanes (const SkYUVAPixmaps &)
 

Additional Inherited Members

- Protected Attributes inherited from SkImageGenerator
const SkImageInfo fInfo
 
- Static Protected Attributes inherited from SkImageGenerator
static constexpr int kNeedNewImageUniqueID = 0
 

Detailed Description

Definition at line 33 of file GrBackendTextureImageGenerator.h.

Constructor & Destructor Documentation

◆ ~GrBackendTextureImageGenerator()

GrBackendTextureImageGenerator::~GrBackendTextureImageGenerator ( )
override

Definition at line 75 of file GrBackendTextureImageGenerator.cpp.

75 {
76 fRefHelper->unref();
77}

Member Function Documentation

◆ Make()

std::unique_ptr< GrTextureGenerator > GrBackendTextureImageGenerator::Make ( const sk_sp< GrTexture > &  texture,
GrSurfaceOrigin  origin,
std::unique_ptr< GrSemaphore semaphore,
SkColorType  colorType,
SkAlphaType  alphaType,
sk_sp< SkColorSpace colorSpace 
)
static

Definition at line 42 of file GrBackendTextureImageGenerator.cpp.

47 {
48 GrDirectContext* dContext = texture->getContext();
49
50 if (!dContext->priv().caps()->areColorTypeAndFormatCompatible(
51 SkColorTypeToGrColorType(colorType), texture->backendFormat())) {
52 return nullptr;
53 }
54
55 SkColorInfo info(colorType, alphaType, std::move(colorSpace));
56 return std::unique_ptr<GrTextureGenerator>(new GrBackendTextureImageGenerator(
57 info,
58 texture,
59 origin,
60 dContext->directContextID(),
61 std::move(semaphore)));
62}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
static constexpr GrColorType SkColorTypeToGrColorType(SkColorType ct)
Definition: GrTypesPriv.h:629
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
const GrCaps * caps() const
bool areColorTypeAndFormatCompatible(GrColorType grCT, const GrBackendFormat &format) const
Definition: GrCaps.cpp:428
DirectContextID directContextID() const
GrDirectContextPriv priv()
virtual GrSurfaceOrigin origin() const
FlTexture * texture

◆ onGenerateTexture()

GrSurfaceProxyView GrBackendTextureImageGenerator::onGenerateTexture ( GrRecordingContext rContext,
const SkImageInfo info,
skgpu::Mipmapped  mipmapped,
GrImageTexGenPolicy  texGenPolicy 
)
overrideprotectedvirtual

Implements GrTextureGenerator.

Definition at line 94 of file GrBackendTextureImageGenerator.cpp.

98 {
99 SkASSERT(rContext);
100 SkASSERT_RELEASE(info.dimensions() == fBackendTexture.dimensions());
101
102 // We currently limit GrBackendTextureImageGenerators to direct contexts since
103 // only Flutter uses them and doesn't use recording/DDL contexts. Ideally, the
104 // cross context texture functionality can be subsumed by the thread-safe cache
105 // working with utility contexts.
106 auto dContext = rContext->asDirectContext();
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
118 auto proxyProvider = dContext->priv().proxyProvider();
119
120 fBorrowingMutex.acquire();
121 sk_sp<skgpu::RefCntedCallback> releaseProcHelper;
122 if (fRefHelper->fBorrowingContextID.isValid()) {
123 if (fRefHelper->fBorrowingContextID != dContext->directContextID()) {
124 fBorrowingMutex.release();
125 rContext->priv().printWarningMessage(
126 "GrBackendTextureImageGenerator: Trying to use texture on two GrContexts!\n");
127 return {};
128 } else {
129 SkASSERT(fRefHelper->fBorrowingContextReleaseProc);
130 // Ref the release proc to be held by the proxy we make below
131 releaseProcHelper = sk_ref_sp(fRefHelper->fBorrowingContextReleaseProc);
132 }
133 } else {
134 SkASSERT(!fRefHelper->fBorrowingContextReleaseProc);
135 // The ref we add to fRefHelper here will be passed into and owned by the
136 // skgpu::RefCntedCallback.
137 fRefHelper->ref();
138 releaseProcHelper =
139 skgpu::RefCntedCallback::Make(ReleaseRefHelper_TextureReleaseProc, fRefHelper);
140 fRefHelper->fBorrowingContextReleaseProc = releaseProcHelper.get();
141 }
142 fRefHelper->fBorrowingContextID = dContext->directContextID();
143 if (!fRefHelper->fBorrowedTextureKey.isValid()) {
144 static const auto kDomain = skgpu::UniqueKey::GenerateDomain();
145 skgpu::UniqueKey::Builder builder(&fRefHelper->fBorrowedTextureKey, kDomain, 1);
146 builder[0] = this->uniqueID();
147 }
148 fBorrowingMutex.release();
149
150 SkASSERT(fRefHelper->fBorrowingContextID == dContext->directContextID());
151
152 GrBackendFormat backendFormat = fBackendTexture.getBackendFormat();
153 SkASSERT(backendFormat.isValid());
154
155 GrColorType grColorType = SkColorTypeToGrColorType(info.colorType());
156
157 skgpu::Mipmapped textureIsMipMapped =
159
160 // Ganesh assumes that, when wrapping a mipmapped backend texture from a client, that its
161 // mipmaps are fully fleshed out.
162 GrMipmapStatus mipmapStatus = fBackendTexture.hasMipmaps()
164
165 skgpu::Swizzle readSwizzle = dContext->priv().caps()->getReadSwizzle(backendFormat,
166 grColorType);
167
168 // Must make copies of member variables to capture in the lambda since this image generator may
169 // be deleted before we actually execute the lambda.
170 sk_sp<GrTextureProxy> proxy = proxyProvider->createLazyProxy(
171 [refHelper = fRefHelper, releaseProcHelper, backendTexture = fBackendTexture](
172 GrResourceProvider* resourceProvider,
174 if (refHelper->fSemaphore) {
175 resourceProvider->priv().gpu()->waitSemaphore(refHelper->fSemaphore.get());
176 }
177
178 // If a client re-draws the same image multiple times, the texture we return
179 // will be cached and re-used. If they draw a subset, though, we may be
180 // re-called. In that case, we want to re-use the borrowed texture we've
181 // previously created.
183 SkASSERT(refHelper->fBorrowedTextureKey.isValid());
184 auto surf = resourceProvider->findByUniqueKey<GrSurface>(
185 refHelper->fBorrowedTextureKey);
186 if (surf) {
187 SkASSERT(surf->asTexture());
188 tex = sk_ref_sp(surf->asTexture());
189 } else {
190 // We just gained access to the texture. If we're on the original
191 // context, we could use the original texture, but we'd have no way of
192 // detecting that it's no longer in-use. So we always make a wrapped
193 // copy, where the release proc informs us that the context is done with
194 // it. This is unfortunate - we'll have two texture objects referencing
195 // the same GPU object. However, no client can ever see the original
196 // texture, so this should be safe. We make the texture uncacheable so
197 // that the release proc is called ASAP.
198 tex = resourceProvider->wrapBackendTexture(
201 if (!tex) {
202 return {};
203 }
204 tex->setRelease(releaseProcHelper);
205 tex->resourcePriv().setUniqueKey(refHelper->fBorrowedTextureKey);
206 }
207 // We use keys to avoid re-wrapping the GrBackendTexture in a GrTexture.
208 // This is unrelated to the whatever SkImage key may be assigned to the
209 // proxy.
210 return {std::move(tex), true, GrSurfaceProxy::LazyInstantiationKeyMode::kUnsynced};
211 },
212 backendFormat,
213 fBackendTexture.dimensions(),
214 textureIsMipMapped,
215 mipmapStatus,
221 "BackendTextureImageGenerator");
222 if (!proxy) {
223 return {};
224 }
225
226 if (texGenPolicy == GrImageTexGenPolicy::kDraw &&
227 (mipmapped == skgpu::Mipmapped::kNo || proxy->mipmapped() == skgpu::Mipmapped::kYes)) {
228 // If we have the correct mip support, we're done
229 return GrSurfaceProxyView(std::move(proxy), fSurfaceOrigin, readSwizzle);
230 } else {
234
235 auto copy = GrSurfaceProxy::Copy(dContext,
236 std::move(proxy),
237 fSurfaceOrigin,
238 mipmapped,
239 SkIRect::MakeWH(info.width(), info.height()),
241 budgeted,
242 /*label=*/"BackendTextureImageGenerator_GenerateTexture");
243 return {std::move(copy), fSurfaceOrigin, readSwizzle};
244 }
245}
@ kRead_GrIOType
Definition: GrTypesPriv.h:403
GrMipmapStatus
Definition: GrTypesPriv.h:523
@ kBorrow_GrWrapOwnership
Definition: GrTypesPriv.h:79
GrColorType
Definition: GrTypesPriv.h:540
#define SkASSERT_RELEASE(cond)
Definition: SkAssert.h:100
#define SkASSERT(cond)
Definition: SkAssert.h:116
sk_sp< T > sk_ref_sp(T *obj)
Definition: SkRefCnt.h:381
bool isValid() const
SkISize dimensions() const
GrBackendFormat getBackendFormat() const
bool hasMipmaps() 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)
Definition: GrSurface.cpp:60
skgpu::Mipmapped mipmapped() const
uint32_t uniqueID() const
T * get() const
Definition: SkRefCnt.h:303
static sk_sp< RefCntedCallback > Make(Callback proc, Context ctx)
static Domain GenerateDomain()
Definition: ResourceKey.cpp:27
if(end==-1)
Definition: copy.py:1
Budgeted
Definition: GpuTypes.h:35
Mipmapped
Definition: GpuTypes.h:53
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition: SkRect.h:56

◆ onIsProtected()

bool GrBackendTextureImageGenerator::onIsProtected ( ) const
overrideprotectedvirtual

Reimplemented from SkImageGenerator.

Definition at line 79 of file GrBackendTextureImageGenerator.cpp.

79 {
80 return fBackendTexture.isProtected();
81}
bool isProtected() const

◆ onIsValid()

bool GrBackendTextureImageGenerator::onIsValid ( GrRecordingContext context) const
inlineoverrideprotectedvirtual

Reimplemented from SkImageGenerator.

Definition at line 42 of file GrBackendTextureImageGenerator.h.

42 {
43 if (context && context->abandoned()) {
44 return false;
45 }
46 return true;
47 }
bool abandoned() override

The documentation for this class was generated from the following files: