1*8975f5c5SAndroid Build Coastguard Worker //
2*8975f5c5SAndroid Build Coastguard Worker // Copyright 2015 The ANGLE Project Authors. All rights reserved.
3*8975f5c5SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
4*8975f5c5SAndroid Build Coastguard Worker // found in the LICENSE file.
5*8975f5c5SAndroid Build Coastguard Worker //
6*8975f5c5SAndroid Build Coastguard Worker
7*8975f5c5SAndroid Build Coastguard Worker // Image.cpp: Implements the egl::Image class representing the EGLimage object.
8*8975f5c5SAndroid Build Coastguard Worker
9*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/Image.h"
10*8975f5c5SAndroid Build Coastguard Worker
11*8975f5c5SAndroid Build Coastguard Worker #include "common/debug.h"
12*8975f5c5SAndroid Build Coastguard Worker #include "common/utilities.h"
13*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/Context.h"
14*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/Renderbuffer.h"
15*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/Texture.h"
16*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/angletypes.h"
17*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/formatutils.h"
18*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/renderer/EGLImplFactory.h"
19*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/renderer/ImageImpl.h"
20*8975f5c5SAndroid Build Coastguard Worker
21*8975f5c5SAndroid Build Coastguard Worker namespace egl
22*8975f5c5SAndroid Build Coastguard Worker {
23*8975f5c5SAndroid Build Coastguard Worker
24*8975f5c5SAndroid Build Coastguard Worker namespace
25*8975f5c5SAndroid Build Coastguard Worker {
GetImageIndex(EGLenum eglTarget,const egl::AttributeMap & attribs)26*8975f5c5SAndroid Build Coastguard Worker gl::ImageIndex GetImageIndex(EGLenum eglTarget, const egl::AttributeMap &attribs)
27*8975f5c5SAndroid Build Coastguard Worker {
28*8975f5c5SAndroid Build Coastguard Worker if (!IsTextureTarget(eglTarget))
29*8975f5c5SAndroid Build Coastguard Worker {
30*8975f5c5SAndroid Build Coastguard Worker return gl::ImageIndex();
31*8975f5c5SAndroid Build Coastguard Worker }
32*8975f5c5SAndroid Build Coastguard Worker
33*8975f5c5SAndroid Build Coastguard Worker gl::TextureTarget target = egl_gl::EGLImageTargetToTextureTarget(eglTarget);
34*8975f5c5SAndroid Build Coastguard Worker GLint mip = static_cast<GLint>(attribs.get(EGL_GL_TEXTURE_LEVEL_KHR, 0));
35*8975f5c5SAndroid Build Coastguard Worker GLint layer = static_cast<GLint>(attribs.get(EGL_GL_TEXTURE_ZOFFSET_KHR, 0));
36*8975f5c5SAndroid Build Coastguard Worker
37*8975f5c5SAndroid Build Coastguard Worker if (target == gl::TextureTarget::_3D)
38*8975f5c5SAndroid Build Coastguard Worker {
39*8975f5c5SAndroid Build Coastguard Worker return gl::ImageIndex::Make3D(mip, layer);
40*8975f5c5SAndroid Build Coastguard Worker }
41*8975f5c5SAndroid Build Coastguard Worker else
42*8975f5c5SAndroid Build Coastguard Worker {
43*8975f5c5SAndroid Build Coastguard Worker ASSERT(layer == 0);
44*8975f5c5SAndroid Build Coastguard Worker return gl::ImageIndex::MakeFromTarget(target, mip, 1);
45*8975f5c5SAndroid Build Coastguard Worker }
46*8975f5c5SAndroid Build Coastguard Worker }
47*8975f5c5SAndroid Build Coastguard Worker
DisplayFromContext(const gl::Context * context)48*8975f5c5SAndroid Build Coastguard Worker const Display *DisplayFromContext(const gl::Context *context)
49*8975f5c5SAndroid Build Coastguard Worker {
50*8975f5c5SAndroid Build Coastguard Worker return (context ? context->getDisplay() : nullptr);
51*8975f5c5SAndroid Build Coastguard Worker }
52*8975f5c5SAndroid Build Coastguard Worker
53*8975f5c5SAndroid Build Coastguard Worker angle::SubjectIndex kExternalImageImplSubjectIndex = 0;
54*8975f5c5SAndroid Build Coastguard Worker } // anonymous namespace
55*8975f5c5SAndroid Build Coastguard Worker
ImageSibling()56*8975f5c5SAndroid Build Coastguard Worker ImageSibling::ImageSibling() : FramebufferAttachmentObject(), mSourcesOf(), mTargetOf() {}
57*8975f5c5SAndroid Build Coastguard Worker
~ImageSibling()58*8975f5c5SAndroid Build Coastguard Worker ImageSibling::~ImageSibling()
59*8975f5c5SAndroid Build Coastguard Worker {
60*8975f5c5SAndroid Build Coastguard Worker // EGL images should hold a ref to their targets and siblings, a Texture should not be deletable
61*8975f5c5SAndroid Build Coastguard Worker // while it is attached to an EGL image.
62*8975f5c5SAndroid Build Coastguard Worker // Child class should orphan images before destruction.
63*8975f5c5SAndroid Build Coastguard Worker ASSERT(mSourcesOf.empty());
64*8975f5c5SAndroid Build Coastguard Worker ASSERT(mTargetOf.get() == nullptr);
65*8975f5c5SAndroid Build Coastguard Worker }
66*8975f5c5SAndroid Build Coastguard Worker
setTargetImage(const gl::Context * context,egl::Image * imageTarget)67*8975f5c5SAndroid Build Coastguard Worker void ImageSibling::setTargetImage(const gl::Context *context, egl::Image *imageTarget)
68*8975f5c5SAndroid Build Coastguard Worker {
69*8975f5c5SAndroid Build Coastguard Worker ASSERT(imageTarget != nullptr);
70*8975f5c5SAndroid Build Coastguard Worker mTargetOf.set(DisplayFromContext(context), imageTarget);
71*8975f5c5SAndroid Build Coastguard Worker imageTarget->addTargetSibling(this);
72*8975f5c5SAndroid Build Coastguard Worker }
73*8975f5c5SAndroid Build Coastguard Worker
orphanImages(const gl::Context * context,RefCountObjectReleaser<Image> * outReleaseImage)74*8975f5c5SAndroid Build Coastguard Worker angle::Result ImageSibling::orphanImages(const gl::Context *context,
75*8975f5c5SAndroid Build Coastguard Worker RefCountObjectReleaser<Image> *outReleaseImage)
76*8975f5c5SAndroid Build Coastguard Worker {
77*8975f5c5SAndroid Build Coastguard Worker ASSERT(outReleaseImage != nullptr);
78*8975f5c5SAndroid Build Coastguard Worker
79*8975f5c5SAndroid Build Coastguard Worker if (mTargetOf.get() != nullptr)
80*8975f5c5SAndroid Build Coastguard Worker {
81*8975f5c5SAndroid Build Coastguard Worker // Can't be a target and have sources.
82*8975f5c5SAndroid Build Coastguard Worker ASSERT(mSourcesOf.empty());
83*8975f5c5SAndroid Build Coastguard Worker
84*8975f5c5SAndroid Build Coastguard Worker ANGLE_TRY(mTargetOf->orphanSibling(context, this));
85*8975f5c5SAndroid Build Coastguard Worker *outReleaseImage = mTargetOf.set(DisplayFromContext(context), nullptr);
86*8975f5c5SAndroid Build Coastguard Worker }
87*8975f5c5SAndroid Build Coastguard Worker else
88*8975f5c5SAndroid Build Coastguard Worker {
89*8975f5c5SAndroid Build Coastguard Worker for (Image *sourceImage : mSourcesOf)
90*8975f5c5SAndroid Build Coastguard Worker {
91*8975f5c5SAndroid Build Coastguard Worker ANGLE_TRY(sourceImage->orphanSibling(context, this));
92*8975f5c5SAndroid Build Coastguard Worker }
93*8975f5c5SAndroid Build Coastguard Worker mSourcesOf.clear();
94*8975f5c5SAndroid Build Coastguard Worker }
95*8975f5c5SAndroid Build Coastguard Worker
96*8975f5c5SAndroid Build Coastguard Worker return angle::Result::Continue;
97*8975f5c5SAndroid Build Coastguard Worker }
98*8975f5c5SAndroid Build Coastguard Worker
addImageSource(egl::Image * imageSource)99*8975f5c5SAndroid Build Coastguard Worker void ImageSibling::addImageSource(egl::Image *imageSource)
100*8975f5c5SAndroid Build Coastguard Worker {
101*8975f5c5SAndroid Build Coastguard Worker ASSERT(imageSource != nullptr);
102*8975f5c5SAndroid Build Coastguard Worker mSourcesOf.insert(imageSource);
103*8975f5c5SAndroid Build Coastguard Worker }
104*8975f5c5SAndroid Build Coastguard Worker
removeImageSource(egl::Image * imageSource)105*8975f5c5SAndroid Build Coastguard Worker void ImageSibling::removeImageSource(egl::Image *imageSource)
106*8975f5c5SAndroid Build Coastguard Worker {
107*8975f5c5SAndroid Build Coastguard Worker ASSERT(mSourcesOf.find(imageSource) != mSourcesOf.end());
108*8975f5c5SAndroid Build Coastguard Worker mSourcesOf.erase(imageSource);
109*8975f5c5SAndroid Build Coastguard Worker }
110*8975f5c5SAndroid Build Coastguard Worker
isEGLImageTarget() const111*8975f5c5SAndroid Build Coastguard Worker bool ImageSibling::isEGLImageTarget() const
112*8975f5c5SAndroid Build Coastguard Worker {
113*8975f5c5SAndroid Build Coastguard Worker return (mTargetOf.get() != nullptr);
114*8975f5c5SAndroid Build Coastguard Worker }
115*8975f5c5SAndroid Build Coastguard Worker
sourceEGLImageInitState() const116*8975f5c5SAndroid Build Coastguard Worker gl::InitState ImageSibling::sourceEGLImageInitState() const
117*8975f5c5SAndroid Build Coastguard Worker {
118*8975f5c5SAndroid Build Coastguard Worker ASSERT(isEGLImageTarget());
119*8975f5c5SAndroid Build Coastguard Worker return mTargetOf->sourceInitState();
120*8975f5c5SAndroid Build Coastguard Worker }
121*8975f5c5SAndroid Build Coastguard Worker
setSourceEGLImageInitState(gl::InitState initState) const122*8975f5c5SAndroid Build Coastguard Worker void ImageSibling::setSourceEGLImageInitState(gl::InitState initState) const
123*8975f5c5SAndroid Build Coastguard Worker {
124*8975f5c5SAndroid Build Coastguard Worker ASSERT(isEGLImageTarget());
125*8975f5c5SAndroid Build Coastguard Worker mTargetOf->setInitState(initState);
126*8975f5c5SAndroid Build Coastguard Worker }
127*8975f5c5SAndroid Build Coastguard Worker
isRenderable(const gl::Context * context,GLenum binding,const gl::ImageIndex & imageIndex) const128*8975f5c5SAndroid Build Coastguard Worker bool ImageSibling::isRenderable(const gl::Context *context,
129*8975f5c5SAndroid Build Coastguard Worker GLenum binding,
130*8975f5c5SAndroid Build Coastguard Worker const gl::ImageIndex &imageIndex) const
131*8975f5c5SAndroid Build Coastguard Worker {
132*8975f5c5SAndroid Build Coastguard Worker ASSERT(isEGLImageTarget());
133*8975f5c5SAndroid Build Coastguard Worker return mTargetOf->isRenderable(context);
134*8975f5c5SAndroid Build Coastguard Worker }
135*8975f5c5SAndroid Build Coastguard Worker
isYUV() const136*8975f5c5SAndroid Build Coastguard Worker bool ImageSibling::isYUV() const
137*8975f5c5SAndroid Build Coastguard Worker {
138*8975f5c5SAndroid Build Coastguard Worker return mTargetOf.get() && mTargetOf->isYUV();
139*8975f5c5SAndroid Build Coastguard Worker }
140*8975f5c5SAndroid Build Coastguard Worker
isExternalImageWithoutIndividualSync() const141*8975f5c5SAndroid Build Coastguard Worker bool ImageSibling::isExternalImageWithoutIndividualSync() const
142*8975f5c5SAndroid Build Coastguard Worker {
143*8975f5c5SAndroid Build Coastguard Worker return mTargetOf.get() && mTargetOf->isExternalImageWithoutIndividualSync();
144*8975f5c5SAndroid Build Coastguard Worker }
145*8975f5c5SAndroid Build Coastguard Worker
hasFrontBufferUsage() const146*8975f5c5SAndroid Build Coastguard Worker bool ImageSibling::hasFrontBufferUsage() const
147*8975f5c5SAndroid Build Coastguard Worker {
148*8975f5c5SAndroid Build Coastguard Worker return mTargetOf.get() && mTargetOf->hasFrontBufferUsage();
149*8975f5c5SAndroid Build Coastguard Worker }
150*8975f5c5SAndroid Build Coastguard Worker
hasProtectedContent() const151*8975f5c5SAndroid Build Coastguard Worker bool ImageSibling::hasProtectedContent() const
152*8975f5c5SAndroid Build Coastguard Worker {
153*8975f5c5SAndroid Build Coastguard Worker return mTargetOf.get() && mTargetOf->hasProtectedContent();
154*8975f5c5SAndroid Build Coastguard Worker }
155*8975f5c5SAndroid Build Coastguard Worker
notifySiblings(angle::SubjectMessage message)156*8975f5c5SAndroid Build Coastguard Worker void ImageSibling::notifySiblings(angle::SubjectMessage message)
157*8975f5c5SAndroid Build Coastguard Worker {
158*8975f5c5SAndroid Build Coastguard Worker if (mTargetOf.get())
159*8975f5c5SAndroid Build Coastguard Worker {
160*8975f5c5SAndroid Build Coastguard Worker mTargetOf->notifySiblings(this, message);
161*8975f5c5SAndroid Build Coastguard Worker }
162*8975f5c5SAndroid Build Coastguard Worker for (Image *source : mSourcesOf)
163*8975f5c5SAndroid Build Coastguard Worker {
164*8975f5c5SAndroid Build Coastguard Worker source->notifySiblings(this, message);
165*8975f5c5SAndroid Build Coastguard Worker }
166*8975f5c5SAndroid Build Coastguard Worker }
167*8975f5c5SAndroid Build Coastguard Worker
ExternalImageSibling(rx::EGLImplFactory * factory,const gl::Context * context,EGLenum target,EGLClientBuffer buffer,const AttributeMap & attribs)168*8975f5c5SAndroid Build Coastguard Worker ExternalImageSibling::ExternalImageSibling(rx::EGLImplFactory *factory,
169*8975f5c5SAndroid Build Coastguard Worker const gl::Context *context,
170*8975f5c5SAndroid Build Coastguard Worker EGLenum target,
171*8975f5c5SAndroid Build Coastguard Worker EGLClientBuffer buffer,
172*8975f5c5SAndroid Build Coastguard Worker const AttributeMap &attribs)
173*8975f5c5SAndroid Build Coastguard Worker : mImplementation(factory->createExternalImageSibling(context, target, buffer, attribs)),
174*8975f5c5SAndroid Build Coastguard Worker mImplObserverBinding(this, kExternalImageImplSubjectIndex)
175*8975f5c5SAndroid Build Coastguard Worker {
176*8975f5c5SAndroid Build Coastguard Worker mImplObserverBinding.bind(mImplementation.get());
177*8975f5c5SAndroid Build Coastguard Worker }
178*8975f5c5SAndroid Build Coastguard Worker
179*8975f5c5SAndroid Build Coastguard Worker ExternalImageSibling::~ExternalImageSibling() = default;
180*8975f5c5SAndroid Build Coastguard Worker
onDestroy(const egl::Display * display)181*8975f5c5SAndroid Build Coastguard Worker void ExternalImageSibling::onDestroy(const egl::Display *display)
182*8975f5c5SAndroid Build Coastguard Worker {
183*8975f5c5SAndroid Build Coastguard Worker mImplementation->onDestroy(display);
184*8975f5c5SAndroid Build Coastguard Worker }
185*8975f5c5SAndroid Build Coastguard Worker
initialize(const egl::Display * display,const gl::Context * context)186*8975f5c5SAndroid Build Coastguard Worker Error ExternalImageSibling::initialize(const egl::Display *display, const gl::Context *context)
187*8975f5c5SAndroid Build Coastguard Worker {
188*8975f5c5SAndroid Build Coastguard Worker return mImplementation->initialize(display);
189*8975f5c5SAndroid Build Coastguard Worker }
190*8975f5c5SAndroid Build Coastguard Worker
getAttachmentSize(const gl::ImageIndex & imageIndex) const191*8975f5c5SAndroid Build Coastguard Worker gl::Extents ExternalImageSibling::getAttachmentSize(const gl::ImageIndex &imageIndex) const
192*8975f5c5SAndroid Build Coastguard Worker {
193*8975f5c5SAndroid Build Coastguard Worker return mImplementation->getSize();
194*8975f5c5SAndroid Build Coastguard Worker }
195*8975f5c5SAndroid Build Coastguard Worker
getAttachmentFormat(GLenum binding,const gl::ImageIndex & imageIndex) const196*8975f5c5SAndroid Build Coastguard Worker gl::Format ExternalImageSibling::getAttachmentFormat(GLenum binding,
197*8975f5c5SAndroid Build Coastguard Worker const gl::ImageIndex &imageIndex) const
198*8975f5c5SAndroid Build Coastguard Worker {
199*8975f5c5SAndroid Build Coastguard Worker return mImplementation->getFormat();
200*8975f5c5SAndroid Build Coastguard Worker }
201*8975f5c5SAndroid Build Coastguard Worker
getAttachmentSamples(const gl::ImageIndex & imageIndex) const202*8975f5c5SAndroid Build Coastguard Worker GLsizei ExternalImageSibling::getAttachmentSamples(const gl::ImageIndex &imageIndex) const
203*8975f5c5SAndroid Build Coastguard Worker {
204*8975f5c5SAndroid Build Coastguard Worker return static_cast<GLsizei>(mImplementation->getSamples());
205*8975f5c5SAndroid Build Coastguard Worker }
206*8975f5c5SAndroid Build Coastguard Worker
getLevelCount() const207*8975f5c5SAndroid Build Coastguard Worker GLuint ExternalImageSibling::getLevelCount() const
208*8975f5c5SAndroid Build Coastguard Worker {
209*8975f5c5SAndroid Build Coastguard Worker return static_cast<GLuint>(mImplementation->getLevelCount());
210*8975f5c5SAndroid Build Coastguard Worker }
211*8975f5c5SAndroid Build Coastguard Worker
isRenderable(const gl::Context * context,GLenum binding,const gl::ImageIndex & imageIndex) const212*8975f5c5SAndroid Build Coastguard Worker bool ExternalImageSibling::isRenderable(const gl::Context *context,
213*8975f5c5SAndroid Build Coastguard Worker GLenum binding,
214*8975f5c5SAndroid Build Coastguard Worker const gl::ImageIndex &imageIndex) const
215*8975f5c5SAndroid Build Coastguard Worker {
216*8975f5c5SAndroid Build Coastguard Worker return mImplementation->isRenderable(context);
217*8975f5c5SAndroid Build Coastguard Worker }
218*8975f5c5SAndroid Build Coastguard Worker
isTextureable(const gl::Context * context) const219*8975f5c5SAndroid Build Coastguard Worker bool ExternalImageSibling::isTextureable(const gl::Context *context) const
220*8975f5c5SAndroid Build Coastguard Worker {
221*8975f5c5SAndroid Build Coastguard Worker return mImplementation->isTexturable(context);
222*8975f5c5SAndroid Build Coastguard Worker }
223*8975f5c5SAndroid Build Coastguard Worker
isYUV() const224*8975f5c5SAndroid Build Coastguard Worker bool ExternalImageSibling::isYUV() const
225*8975f5c5SAndroid Build Coastguard Worker {
226*8975f5c5SAndroid Build Coastguard Worker return mImplementation->isYUV();
227*8975f5c5SAndroid Build Coastguard Worker }
228*8975f5c5SAndroid Build Coastguard Worker
hasFrontBufferUsage() const229*8975f5c5SAndroid Build Coastguard Worker bool ExternalImageSibling::hasFrontBufferUsage() const
230*8975f5c5SAndroid Build Coastguard Worker {
231*8975f5c5SAndroid Build Coastguard Worker return mImplementation->hasFrontBufferUsage();
232*8975f5c5SAndroid Build Coastguard Worker }
233*8975f5c5SAndroid Build Coastguard Worker
isCubeMap() const234*8975f5c5SAndroid Build Coastguard Worker bool ExternalImageSibling::isCubeMap() const
235*8975f5c5SAndroid Build Coastguard Worker {
236*8975f5c5SAndroid Build Coastguard Worker return mImplementation->isCubeMap();
237*8975f5c5SAndroid Build Coastguard Worker }
238*8975f5c5SAndroid Build Coastguard Worker
hasProtectedContent() const239*8975f5c5SAndroid Build Coastguard Worker bool ExternalImageSibling::hasProtectedContent() const
240*8975f5c5SAndroid Build Coastguard Worker {
241*8975f5c5SAndroid Build Coastguard Worker return mImplementation->hasProtectedContent();
242*8975f5c5SAndroid Build Coastguard Worker }
243*8975f5c5SAndroid Build Coastguard Worker
onAttach(const gl::Context * context,rx::UniqueSerial framebufferSerial)244*8975f5c5SAndroid Build Coastguard Worker void ExternalImageSibling::onAttach(const gl::Context *context, rx::UniqueSerial framebufferSerial)
245*8975f5c5SAndroid Build Coastguard Worker {}
246*8975f5c5SAndroid Build Coastguard Worker
onDetach(const gl::Context * context,rx::UniqueSerial framebufferSerial)247*8975f5c5SAndroid Build Coastguard Worker void ExternalImageSibling::onDetach(const gl::Context *context, rx::UniqueSerial framebufferSerial)
248*8975f5c5SAndroid Build Coastguard Worker {}
249*8975f5c5SAndroid Build Coastguard Worker
getId() const250*8975f5c5SAndroid Build Coastguard Worker GLuint ExternalImageSibling::getId() const
251*8975f5c5SAndroid Build Coastguard Worker {
252*8975f5c5SAndroid Build Coastguard Worker UNREACHABLE();
253*8975f5c5SAndroid Build Coastguard Worker return 0;
254*8975f5c5SAndroid Build Coastguard Worker }
255*8975f5c5SAndroid Build Coastguard Worker
initState(GLenum binding,const gl::ImageIndex & imageIndex) const256*8975f5c5SAndroid Build Coastguard Worker gl::InitState ExternalImageSibling::initState(GLenum binding,
257*8975f5c5SAndroid Build Coastguard Worker const gl::ImageIndex &imageIndex) const
258*8975f5c5SAndroid Build Coastguard Worker {
259*8975f5c5SAndroid Build Coastguard Worker return gl::InitState::Initialized;
260*8975f5c5SAndroid Build Coastguard Worker }
261*8975f5c5SAndroid Build Coastguard Worker
setInitState(GLenum binding,const gl::ImageIndex & imageIndex,gl::InitState initState)262*8975f5c5SAndroid Build Coastguard Worker void ExternalImageSibling::setInitState(GLenum binding,
263*8975f5c5SAndroid Build Coastguard Worker const gl::ImageIndex &imageIndex,
264*8975f5c5SAndroid Build Coastguard Worker gl::InitState initState)
265*8975f5c5SAndroid Build Coastguard Worker {}
266*8975f5c5SAndroid Build Coastguard Worker
getImplementation() const267*8975f5c5SAndroid Build Coastguard Worker rx::ExternalImageSiblingImpl *ExternalImageSibling::getImplementation() const
268*8975f5c5SAndroid Build Coastguard Worker {
269*8975f5c5SAndroid Build Coastguard Worker return mImplementation.get();
270*8975f5c5SAndroid Build Coastguard Worker }
271*8975f5c5SAndroid Build Coastguard Worker
onSubjectStateChange(angle::SubjectIndex index,angle::SubjectMessage message)272*8975f5c5SAndroid Build Coastguard Worker void ExternalImageSibling::onSubjectStateChange(angle::SubjectIndex index,
273*8975f5c5SAndroid Build Coastguard Worker angle::SubjectMessage message)
274*8975f5c5SAndroid Build Coastguard Worker {
275*8975f5c5SAndroid Build Coastguard Worker onStateChange(message);
276*8975f5c5SAndroid Build Coastguard Worker }
277*8975f5c5SAndroid Build Coastguard Worker
getAttachmentImpl() const278*8975f5c5SAndroid Build Coastguard Worker rx::FramebufferAttachmentObjectImpl *ExternalImageSibling::getAttachmentImpl() const
279*8975f5c5SAndroid Build Coastguard Worker {
280*8975f5c5SAndroid Build Coastguard Worker return mImplementation.get();
281*8975f5c5SAndroid Build Coastguard Worker }
282*8975f5c5SAndroid Build Coastguard Worker
ImageState(ImageID id,EGLenum target,ImageSibling * buffer,const AttributeMap & attribs)283*8975f5c5SAndroid Build Coastguard Worker ImageState::ImageState(ImageID id,
284*8975f5c5SAndroid Build Coastguard Worker EGLenum target,
285*8975f5c5SAndroid Build Coastguard Worker ImageSibling *buffer,
286*8975f5c5SAndroid Build Coastguard Worker const AttributeMap &attribs)
287*8975f5c5SAndroid Build Coastguard Worker : id(id),
288*8975f5c5SAndroid Build Coastguard Worker label(nullptr),
289*8975f5c5SAndroid Build Coastguard Worker target(target),
290*8975f5c5SAndroid Build Coastguard Worker imageIndex(GetImageIndex(target, attribs)),
291*8975f5c5SAndroid Build Coastguard Worker source(buffer),
292*8975f5c5SAndroid Build Coastguard Worker format(GL_NONE),
293*8975f5c5SAndroid Build Coastguard Worker yuv(false),
294*8975f5c5SAndroid Build Coastguard Worker cubeMap(false),
295*8975f5c5SAndroid Build Coastguard Worker size(),
296*8975f5c5SAndroid Build Coastguard Worker samples(),
297*8975f5c5SAndroid Build Coastguard Worker levelCount(1),
298*8975f5c5SAndroid Build Coastguard Worker colorspace(
299*8975f5c5SAndroid Build Coastguard Worker static_cast<EGLenum>(attribs.get(EGL_GL_COLORSPACE, EGL_GL_COLORSPACE_DEFAULT_EXT))),
300*8975f5c5SAndroid Build Coastguard Worker hasProtectedContent(static_cast<bool>(attribs.get(EGL_PROTECTED_CONTENT_EXT, EGL_FALSE)))
301*8975f5c5SAndroid Build Coastguard Worker {}
302*8975f5c5SAndroid Build Coastguard Worker
~ImageState()303*8975f5c5SAndroid Build Coastguard Worker ImageState::~ImageState() {}
304*8975f5c5SAndroid Build Coastguard Worker
Image(rx::EGLImplFactory * factory,ImageID id,const gl::Context * context,EGLenum target,ImageSibling * buffer,const AttributeMap & attribs)305*8975f5c5SAndroid Build Coastguard Worker Image::Image(rx::EGLImplFactory *factory,
306*8975f5c5SAndroid Build Coastguard Worker ImageID id,
307*8975f5c5SAndroid Build Coastguard Worker const gl::Context *context,
308*8975f5c5SAndroid Build Coastguard Worker EGLenum target,
309*8975f5c5SAndroid Build Coastguard Worker ImageSibling *buffer,
310*8975f5c5SAndroid Build Coastguard Worker const AttributeMap &attribs)
311*8975f5c5SAndroid Build Coastguard Worker : mState(id, target, buffer, attribs),
312*8975f5c5SAndroid Build Coastguard Worker mImplementation(factory->createImage(mState, context, target, attribs)),
313*8975f5c5SAndroid Build Coastguard Worker mOrphanedAndNeedsInit(false),
314*8975f5c5SAndroid Build Coastguard Worker mContextMutex(nullptr)
315*8975f5c5SAndroid Build Coastguard Worker {
316*8975f5c5SAndroid Build Coastguard Worker ASSERT(mImplementation != nullptr);
317*8975f5c5SAndroid Build Coastguard Worker ASSERT(buffer != nullptr);
318*8975f5c5SAndroid Build Coastguard Worker
319*8975f5c5SAndroid Build Coastguard Worker if (kIsContextMutexEnabled)
320*8975f5c5SAndroid Build Coastguard Worker {
321*8975f5c5SAndroid Build Coastguard Worker if (context != nullptr)
322*8975f5c5SAndroid Build Coastguard Worker {
323*8975f5c5SAndroid Build Coastguard Worker mContextMutex = context->getContextMutex().getRoot();
324*8975f5c5SAndroid Build Coastguard Worker ASSERT(mContextMutex->isReferenced());
325*8975f5c5SAndroid Build Coastguard Worker }
326*8975f5c5SAndroid Build Coastguard Worker else
327*8975f5c5SAndroid Build Coastguard Worker {
328*8975f5c5SAndroid Build Coastguard Worker mContextMutex = new ContextMutex();
329*8975f5c5SAndroid Build Coastguard Worker }
330*8975f5c5SAndroid Build Coastguard Worker mContextMutex->addRef();
331*8975f5c5SAndroid Build Coastguard Worker }
332*8975f5c5SAndroid Build Coastguard Worker
333*8975f5c5SAndroid Build Coastguard Worker mState.source->addImageSource(this);
334*8975f5c5SAndroid Build Coastguard Worker }
335*8975f5c5SAndroid Build Coastguard Worker
onDestroy(const Display * display)336*8975f5c5SAndroid Build Coastguard Worker void Image::onDestroy(const Display *display)
337*8975f5c5SAndroid Build Coastguard Worker {
338*8975f5c5SAndroid Build Coastguard Worker // All targets should hold a ref to the egl image and it should not be deleted until there are
339*8975f5c5SAndroid Build Coastguard Worker // no siblings left.
340*8975f5c5SAndroid Build Coastguard Worker ASSERT([&] {
341*8975f5c5SAndroid Build Coastguard Worker std::unique_lock lock(mState.targetsLock);
342*8975f5c5SAndroid Build Coastguard Worker return mState.targets.empty();
343*8975f5c5SAndroid Build Coastguard Worker }());
344*8975f5c5SAndroid Build Coastguard Worker
345*8975f5c5SAndroid Build Coastguard Worker // Make sure the implementation gets a chance to clean up before we delete the source.
346*8975f5c5SAndroid Build Coastguard Worker mImplementation->onDestroy(display);
347*8975f5c5SAndroid Build Coastguard Worker
348*8975f5c5SAndroid Build Coastguard Worker // Tell the source that it is no longer used by this image
349*8975f5c5SAndroid Build Coastguard Worker if (mState.source != nullptr)
350*8975f5c5SAndroid Build Coastguard Worker {
351*8975f5c5SAndroid Build Coastguard Worker mState.source->removeImageSource(this);
352*8975f5c5SAndroid Build Coastguard Worker
353*8975f5c5SAndroid Build Coastguard Worker // If the source is an external object, delete it
354*8975f5c5SAndroid Build Coastguard Worker if (IsExternalImageTarget(mState.target))
355*8975f5c5SAndroid Build Coastguard Worker {
356*8975f5c5SAndroid Build Coastguard Worker ExternalImageSibling *externalSibling = rx::GetAs<ExternalImageSibling>(mState.source);
357*8975f5c5SAndroid Build Coastguard Worker externalSibling->onDestroy(display);
358*8975f5c5SAndroid Build Coastguard Worker delete externalSibling;
359*8975f5c5SAndroid Build Coastguard Worker }
360*8975f5c5SAndroid Build Coastguard Worker
361*8975f5c5SAndroid Build Coastguard Worker mState.source = nullptr;
362*8975f5c5SAndroid Build Coastguard Worker }
363*8975f5c5SAndroid Build Coastguard Worker }
364*8975f5c5SAndroid Build Coastguard Worker
~Image()365*8975f5c5SAndroid Build Coastguard Worker Image::~Image()
366*8975f5c5SAndroid Build Coastguard Worker {
367*8975f5c5SAndroid Build Coastguard Worker SafeDelete(mImplementation);
368*8975f5c5SAndroid Build Coastguard Worker
369*8975f5c5SAndroid Build Coastguard Worker if (mContextMutex != nullptr)
370*8975f5c5SAndroid Build Coastguard Worker {
371*8975f5c5SAndroid Build Coastguard Worker mContextMutex->release();
372*8975f5c5SAndroid Build Coastguard Worker mContextMutex = nullptr;
373*8975f5c5SAndroid Build Coastguard Worker }
374*8975f5c5SAndroid Build Coastguard Worker }
375*8975f5c5SAndroid Build Coastguard Worker
setLabel(EGLLabelKHR label)376*8975f5c5SAndroid Build Coastguard Worker void Image::setLabel(EGLLabelKHR label)
377*8975f5c5SAndroid Build Coastguard Worker {
378*8975f5c5SAndroid Build Coastguard Worker mState.label = label;
379*8975f5c5SAndroid Build Coastguard Worker }
380*8975f5c5SAndroid Build Coastguard Worker
getLabel() const381*8975f5c5SAndroid Build Coastguard Worker EGLLabelKHR Image::getLabel() const
382*8975f5c5SAndroid Build Coastguard Worker {
383*8975f5c5SAndroid Build Coastguard Worker return mState.label;
384*8975f5c5SAndroid Build Coastguard Worker }
385*8975f5c5SAndroid Build Coastguard Worker
addTargetSibling(ImageSibling * sibling)386*8975f5c5SAndroid Build Coastguard Worker void Image::addTargetSibling(ImageSibling *sibling)
387*8975f5c5SAndroid Build Coastguard Worker {
388*8975f5c5SAndroid Build Coastguard Worker std::unique_lock lock(mState.targetsLock);
389*8975f5c5SAndroid Build Coastguard Worker mState.targets.insert(sibling);
390*8975f5c5SAndroid Build Coastguard Worker }
391*8975f5c5SAndroid Build Coastguard Worker
orphanSibling(const gl::Context * context,ImageSibling * sibling)392*8975f5c5SAndroid Build Coastguard Worker angle::Result Image::orphanSibling(const gl::Context *context, ImageSibling *sibling)
393*8975f5c5SAndroid Build Coastguard Worker {
394*8975f5c5SAndroid Build Coastguard Worker ASSERT(sibling != nullptr);
395*8975f5c5SAndroid Build Coastguard Worker
396*8975f5c5SAndroid Build Coastguard Worker // notify impl
397*8975f5c5SAndroid Build Coastguard Worker ANGLE_TRY(mImplementation->orphan(context, sibling));
398*8975f5c5SAndroid Build Coastguard Worker
399*8975f5c5SAndroid Build Coastguard Worker if (mState.source == sibling)
400*8975f5c5SAndroid Build Coastguard Worker {
401*8975f5c5SAndroid Build Coastguard Worker // The external source of an image cannot be redefined so it cannot be orphaned.
402*8975f5c5SAndroid Build Coastguard Worker ASSERT(!IsExternalImageTarget(mState.target));
403*8975f5c5SAndroid Build Coastguard Worker
404*8975f5c5SAndroid Build Coastguard Worker // If the sibling is the source, it cannot be a target.
405*8975f5c5SAndroid Build Coastguard Worker ASSERT([&] {
406*8975f5c5SAndroid Build Coastguard Worker std::unique_lock lock(mState.targetsLock);
407*8975f5c5SAndroid Build Coastguard Worker return mState.targets.find(sibling) == mState.targets.end();
408*8975f5c5SAndroid Build Coastguard Worker }());
409*8975f5c5SAndroid Build Coastguard Worker mState.source = nullptr;
410*8975f5c5SAndroid Build Coastguard Worker mOrphanedAndNeedsInit =
411*8975f5c5SAndroid Build Coastguard Worker (sibling->initState(GL_NONE, mState.imageIndex) == gl::InitState::MayNeedInit);
412*8975f5c5SAndroid Build Coastguard Worker }
413*8975f5c5SAndroid Build Coastguard Worker else
414*8975f5c5SAndroid Build Coastguard Worker {
415*8975f5c5SAndroid Build Coastguard Worker std::unique_lock lock(mState.targetsLock);
416*8975f5c5SAndroid Build Coastguard Worker mState.targets.erase(sibling);
417*8975f5c5SAndroid Build Coastguard Worker }
418*8975f5c5SAndroid Build Coastguard Worker
419*8975f5c5SAndroid Build Coastguard Worker return angle::Result::Continue;
420*8975f5c5SAndroid Build Coastguard Worker }
421*8975f5c5SAndroid Build Coastguard Worker
getFormat() const422*8975f5c5SAndroid Build Coastguard Worker const gl::Format &Image::getFormat() const
423*8975f5c5SAndroid Build Coastguard Worker {
424*8975f5c5SAndroid Build Coastguard Worker return mState.format;
425*8975f5c5SAndroid Build Coastguard Worker }
426*8975f5c5SAndroid Build Coastguard Worker
isRenderable(const gl::Context * context) const427*8975f5c5SAndroid Build Coastguard Worker bool Image::isRenderable(const gl::Context *context) const
428*8975f5c5SAndroid Build Coastguard Worker {
429*8975f5c5SAndroid Build Coastguard Worker return mIsRenderable;
430*8975f5c5SAndroid Build Coastguard Worker }
431*8975f5c5SAndroid Build Coastguard Worker
isTexturable(const gl::Context * context) const432*8975f5c5SAndroid Build Coastguard Worker bool Image::isTexturable(const gl::Context *context) const
433*8975f5c5SAndroid Build Coastguard Worker {
434*8975f5c5SAndroid Build Coastguard Worker return mIsTexturable;
435*8975f5c5SAndroid Build Coastguard Worker }
436*8975f5c5SAndroid Build Coastguard Worker
isYUV() const437*8975f5c5SAndroid Build Coastguard Worker bool Image::isYUV() const
438*8975f5c5SAndroid Build Coastguard Worker {
439*8975f5c5SAndroid Build Coastguard Worker return mState.yuv;
440*8975f5c5SAndroid Build Coastguard Worker }
441*8975f5c5SAndroid Build Coastguard Worker
isExternalImageWithoutIndividualSync() const442*8975f5c5SAndroid Build Coastguard Worker bool Image::isExternalImageWithoutIndividualSync() const
443*8975f5c5SAndroid Build Coastguard Worker {
444*8975f5c5SAndroid Build Coastguard Worker // Only Vulkan images are individually synced.
445*8975f5c5SAndroid Build Coastguard Worker return IsExternalImageTarget(mState.target) && mState.target != EGL_VULKAN_IMAGE_ANGLE;
446*8975f5c5SAndroid Build Coastguard Worker }
447*8975f5c5SAndroid Build Coastguard Worker
hasFrontBufferUsage() const448*8975f5c5SAndroid Build Coastguard Worker bool Image::hasFrontBufferUsage() const
449*8975f5c5SAndroid Build Coastguard Worker {
450*8975f5c5SAndroid Build Coastguard Worker if (IsExternalImageTarget(mState.target))
451*8975f5c5SAndroid Build Coastguard Worker {
452*8975f5c5SAndroid Build Coastguard Worker ExternalImageSibling *externalSibling = rx::GetAs<ExternalImageSibling>(mState.source);
453*8975f5c5SAndroid Build Coastguard Worker return externalSibling->hasFrontBufferUsage();
454*8975f5c5SAndroid Build Coastguard Worker }
455*8975f5c5SAndroid Build Coastguard Worker
456*8975f5c5SAndroid Build Coastguard Worker return false;
457*8975f5c5SAndroid Build Coastguard Worker }
458*8975f5c5SAndroid Build Coastguard Worker
isCubeMap() const459*8975f5c5SAndroid Build Coastguard Worker bool Image::isCubeMap() const
460*8975f5c5SAndroid Build Coastguard Worker {
461*8975f5c5SAndroid Build Coastguard Worker return mState.cubeMap;
462*8975f5c5SAndroid Build Coastguard Worker }
463*8975f5c5SAndroid Build Coastguard Worker
getWidth() const464*8975f5c5SAndroid Build Coastguard Worker size_t Image::getWidth() const
465*8975f5c5SAndroid Build Coastguard Worker {
466*8975f5c5SAndroid Build Coastguard Worker return mState.size.width;
467*8975f5c5SAndroid Build Coastguard Worker }
468*8975f5c5SAndroid Build Coastguard Worker
getHeight() const469*8975f5c5SAndroid Build Coastguard Worker size_t Image::getHeight() const
470*8975f5c5SAndroid Build Coastguard Worker {
471*8975f5c5SAndroid Build Coastguard Worker return mState.size.height;
472*8975f5c5SAndroid Build Coastguard Worker }
473*8975f5c5SAndroid Build Coastguard Worker
getExtents() const474*8975f5c5SAndroid Build Coastguard Worker const gl::Extents &Image::getExtents() const
475*8975f5c5SAndroid Build Coastguard Worker {
476*8975f5c5SAndroid Build Coastguard Worker return mState.size;
477*8975f5c5SAndroid Build Coastguard Worker }
478*8975f5c5SAndroid Build Coastguard Worker
isLayered() const479*8975f5c5SAndroid Build Coastguard Worker bool Image::isLayered() const
480*8975f5c5SAndroid Build Coastguard Worker {
481*8975f5c5SAndroid Build Coastguard Worker return mState.imageIndex.isLayered();
482*8975f5c5SAndroid Build Coastguard Worker }
483*8975f5c5SAndroid Build Coastguard Worker
getSamples() const484*8975f5c5SAndroid Build Coastguard Worker size_t Image::getSamples() const
485*8975f5c5SAndroid Build Coastguard Worker {
486*8975f5c5SAndroid Build Coastguard Worker return mState.samples;
487*8975f5c5SAndroid Build Coastguard Worker }
488*8975f5c5SAndroid Build Coastguard Worker
getLevelCount() const489*8975f5c5SAndroid Build Coastguard Worker GLuint Image::getLevelCount() const
490*8975f5c5SAndroid Build Coastguard Worker {
491*8975f5c5SAndroid Build Coastguard Worker return mState.levelCount;
492*8975f5c5SAndroid Build Coastguard Worker }
493*8975f5c5SAndroid Build Coastguard Worker
hasProtectedContent() const494*8975f5c5SAndroid Build Coastguard Worker bool Image::hasProtectedContent() const
495*8975f5c5SAndroid Build Coastguard Worker {
496*8975f5c5SAndroid Build Coastguard Worker return mState.hasProtectedContent;
497*8975f5c5SAndroid Build Coastguard Worker }
498*8975f5c5SAndroid Build Coastguard Worker
isFixedRatedCompression(const gl::Context * context) const499*8975f5c5SAndroid Build Coastguard Worker bool Image::isFixedRatedCompression(const gl::Context *context) const
500*8975f5c5SAndroid Build Coastguard Worker {
501*8975f5c5SAndroid Build Coastguard Worker return mImplementation->isFixedRatedCompression(context);
502*8975f5c5SAndroid Build Coastguard Worker }
503*8975f5c5SAndroid Build Coastguard Worker
getImplementation() const504*8975f5c5SAndroid Build Coastguard Worker rx::ImageImpl *Image::getImplementation() const
505*8975f5c5SAndroid Build Coastguard Worker {
506*8975f5c5SAndroid Build Coastguard Worker return mImplementation;
507*8975f5c5SAndroid Build Coastguard Worker }
508*8975f5c5SAndroid Build Coastguard Worker
initialize(const Display * display,const gl::Context * context)509*8975f5c5SAndroid Build Coastguard Worker Error Image::initialize(const Display *display, const gl::Context *context)
510*8975f5c5SAndroid Build Coastguard Worker {
511*8975f5c5SAndroid Build Coastguard Worker if (IsExternalImageTarget(mState.target))
512*8975f5c5SAndroid Build Coastguard Worker {
513*8975f5c5SAndroid Build Coastguard Worker ExternalImageSibling *externalSibling = rx::GetAs<ExternalImageSibling>(mState.source);
514*8975f5c5SAndroid Build Coastguard Worker ANGLE_TRY(externalSibling->initialize(display, context));
515*8975f5c5SAndroid Build Coastguard Worker
516*8975f5c5SAndroid Build Coastguard Worker mState.hasProtectedContent = externalSibling->hasProtectedContent();
517*8975f5c5SAndroid Build Coastguard Worker mState.levelCount = externalSibling->getLevelCount();
518*8975f5c5SAndroid Build Coastguard Worker mState.cubeMap = externalSibling->isCubeMap();
519*8975f5c5SAndroid Build Coastguard Worker
520*8975f5c5SAndroid Build Coastguard Worker // External siblings can be YUV
521*8975f5c5SAndroid Build Coastguard Worker mState.yuv = externalSibling->isYUV();
522*8975f5c5SAndroid Build Coastguard Worker }
523*8975f5c5SAndroid Build Coastguard Worker
524*8975f5c5SAndroid Build Coastguard Worker mState.format = mState.source->getAttachmentFormat(GL_NONE, mState.imageIndex);
525*8975f5c5SAndroid Build Coastguard Worker
526*8975f5c5SAndroid Build Coastguard Worker if (mState.colorspace != EGL_GL_COLORSPACE_DEFAULT_EXT)
527*8975f5c5SAndroid Build Coastguard Worker {
528*8975f5c5SAndroid Build Coastguard Worker GLenum nonLinearFormat = mState.format.info->sizedInternalFormat;
529*8975f5c5SAndroid Build Coastguard Worker if (!gl::ColorspaceFormatOverride(mState.colorspace, &nonLinearFormat))
530*8975f5c5SAndroid Build Coastguard Worker {
531*8975f5c5SAndroid Build Coastguard Worker // the colorspace format is not supported
532*8975f5c5SAndroid Build Coastguard Worker return egl::EglBadMatch();
533*8975f5c5SAndroid Build Coastguard Worker }
534*8975f5c5SAndroid Build Coastguard Worker mState.format = gl::Format(nonLinearFormat);
535*8975f5c5SAndroid Build Coastguard Worker }
536*8975f5c5SAndroid Build Coastguard Worker
537*8975f5c5SAndroid Build Coastguard Worker if (!IsExternalImageTarget(mState.target))
538*8975f5c5SAndroid Build Coastguard Worker {
539*8975f5c5SAndroid Build Coastguard Worker // Account for the fact that GL_ANGLE_yuv_internal_format extension maybe enabled,
540*8975f5c5SAndroid Build Coastguard Worker // in which case the internal format itself could be YUV.
541*8975f5c5SAndroid Build Coastguard Worker mState.yuv = gl::IsYuvFormat(mState.format.info->sizedInternalFormat);
542*8975f5c5SAndroid Build Coastguard Worker }
543*8975f5c5SAndroid Build Coastguard Worker
544*8975f5c5SAndroid Build Coastguard Worker mState.size = mState.source->getAttachmentSize(mState.imageIndex);
545*8975f5c5SAndroid Build Coastguard Worker mState.samples = mState.source->getAttachmentSamples(mState.imageIndex);
546*8975f5c5SAndroid Build Coastguard Worker
547*8975f5c5SAndroid Build Coastguard Worker if (IsTextureTarget(mState.target))
548*8975f5c5SAndroid Build Coastguard Worker {
549*8975f5c5SAndroid Build Coastguard Worker mState.size.depth = 1;
550*8975f5c5SAndroid Build Coastguard Worker }
551*8975f5c5SAndroid Build Coastguard Worker
552*8975f5c5SAndroid Build Coastguard Worker Error error = mImplementation->initialize(display);
553*8975f5c5SAndroid Build Coastguard Worker if (error.isError())
554*8975f5c5SAndroid Build Coastguard Worker {
555*8975f5c5SAndroid Build Coastguard Worker return error;
556*8975f5c5SAndroid Build Coastguard Worker }
557*8975f5c5SAndroid Build Coastguard Worker
558*8975f5c5SAndroid Build Coastguard Worker if (IsTextureTarget(mState.target))
559*8975f5c5SAndroid Build Coastguard Worker {
560*8975f5c5SAndroid Build Coastguard Worker mIsTexturable = true;
561*8975f5c5SAndroid Build Coastguard Worker mIsRenderable = mState.format.info->textureAttachmentSupport(context->getClientVersion(),
562*8975f5c5SAndroid Build Coastguard Worker context->getExtensions());
563*8975f5c5SAndroid Build Coastguard Worker }
564*8975f5c5SAndroid Build Coastguard Worker else if (IsRenderbufferTarget(mState.target))
565*8975f5c5SAndroid Build Coastguard Worker {
566*8975f5c5SAndroid Build Coastguard Worker mIsTexturable = true;
567*8975f5c5SAndroid Build Coastguard Worker mIsRenderable = mState.format.info->renderbufferSupport(context->getClientVersion(),
568*8975f5c5SAndroid Build Coastguard Worker context->getExtensions());
569*8975f5c5SAndroid Build Coastguard Worker }
570*8975f5c5SAndroid Build Coastguard Worker else if (IsExternalImageTarget(mState.target))
571*8975f5c5SAndroid Build Coastguard Worker {
572*8975f5c5SAndroid Build Coastguard Worker ASSERT(mState.source != nullptr);
573*8975f5c5SAndroid Build Coastguard Worker mIsTexturable = rx::GetAs<ExternalImageSibling>(mState.source)->isTextureable(context);
574*8975f5c5SAndroid Build Coastguard Worker mIsRenderable = rx::GetAs<ExternalImageSibling>(mState.source)
575*8975f5c5SAndroid Build Coastguard Worker ->isRenderable(context, GL_NONE, gl::ImageIndex());
576*8975f5c5SAndroid Build Coastguard Worker }
577*8975f5c5SAndroid Build Coastguard Worker else
578*8975f5c5SAndroid Build Coastguard Worker {
579*8975f5c5SAndroid Build Coastguard Worker UNREACHABLE();
580*8975f5c5SAndroid Build Coastguard Worker }
581*8975f5c5SAndroid Build Coastguard Worker
582*8975f5c5SAndroid Build Coastguard Worker return NoError();
583*8975f5c5SAndroid Build Coastguard Worker }
584*8975f5c5SAndroid Build Coastguard Worker
orphaned() const585*8975f5c5SAndroid Build Coastguard Worker bool Image::orphaned() const
586*8975f5c5SAndroid Build Coastguard Worker {
587*8975f5c5SAndroid Build Coastguard Worker return (mState.source == nullptr);
588*8975f5c5SAndroid Build Coastguard Worker }
589*8975f5c5SAndroid Build Coastguard Worker
sourceInitState() const590*8975f5c5SAndroid Build Coastguard Worker gl::InitState Image::sourceInitState() const
591*8975f5c5SAndroid Build Coastguard Worker {
592*8975f5c5SAndroid Build Coastguard Worker if (orphaned())
593*8975f5c5SAndroid Build Coastguard Worker {
594*8975f5c5SAndroid Build Coastguard Worker return mOrphanedAndNeedsInit ? gl::InitState::MayNeedInit : gl::InitState::Initialized;
595*8975f5c5SAndroid Build Coastguard Worker }
596*8975f5c5SAndroid Build Coastguard Worker
597*8975f5c5SAndroid Build Coastguard Worker return mState.source->initState(GL_NONE, mState.imageIndex);
598*8975f5c5SAndroid Build Coastguard Worker }
599*8975f5c5SAndroid Build Coastguard Worker
setInitState(gl::InitState initState)600*8975f5c5SAndroid Build Coastguard Worker void Image::setInitState(gl::InitState initState)
601*8975f5c5SAndroid Build Coastguard Worker {
602*8975f5c5SAndroid Build Coastguard Worker if (orphaned())
603*8975f5c5SAndroid Build Coastguard Worker {
604*8975f5c5SAndroid Build Coastguard Worker mOrphanedAndNeedsInit = false;
605*8975f5c5SAndroid Build Coastguard Worker }
606*8975f5c5SAndroid Build Coastguard Worker
607*8975f5c5SAndroid Build Coastguard Worker return mState.source->setInitState(GL_NONE, mState.imageIndex, initState);
608*8975f5c5SAndroid Build Coastguard Worker }
609*8975f5c5SAndroid Build Coastguard Worker
exportVkImage(void * vkImage,void * vkImageCreateInfo)610*8975f5c5SAndroid Build Coastguard Worker Error Image::exportVkImage(void *vkImage, void *vkImageCreateInfo)
611*8975f5c5SAndroid Build Coastguard Worker {
612*8975f5c5SAndroid Build Coastguard Worker return mImplementation->exportVkImage(vkImage, vkImageCreateInfo);
613*8975f5c5SAndroid Build Coastguard Worker }
614*8975f5c5SAndroid Build Coastguard Worker
notifySiblings(const ImageSibling * notifier,angle::SubjectMessage message)615*8975f5c5SAndroid Build Coastguard Worker void Image::notifySiblings(const ImageSibling *notifier, angle::SubjectMessage message)
616*8975f5c5SAndroid Build Coastguard Worker {
617*8975f5c5SAndroid Build Coastguard Worker if (mState.source && mState.source != notifier)
618*8975f5c5SAndroid Build Coastguard Worker {
619*8975f5c5SAndroid Build Coastguard Worker mState.source->onSubjectStateChange(rx::kTextureImageSiblingMessageIndex, message);
620*8975f5c5SAndroid Build Coastguard Worker }
621*8975f5c5SAndroid Build Coastguard Worker
622*8975f5c5SAndroid Build Coastguard Worker std::unique_lock lock(mState.targetsLock);
623*8975f5c5SAndroid Build Coastguard Worker for (ImageSibling *target : mState.targets)
624*8975f5c5SAndroid Build Coastguard Worker {
625*8975f5c5SAndroid Build Coastguard Worker if (target != notifier)
626*8975f5c5SAndroid Build Coastguard Worker {
627*8975f5c5SAndroid Build Coastguard Worker target->onSubjectStateChange(rx::kTextureImageSiblingMessageIndex, message);
628*8975f5c5SAndroid Build Coastguard Worker }
629*8975f5c5SAndroid Build Coastguard Worker }
630*8975f5c5SAndroid Build Coastguard Worker }
631*8975f5c5SAndroid Build Coastguard Worker
632*8975f5c5SAndroid Build Coastguard Worker } // namespace egl
633