Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 1 | // |
| 2 | // Copyright (c) 2015 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 7 | // Image.cpp: Implements the egl::Image class representing the EGLimage object. |
| 8 | |
| 9 | #include "libANGLE/Image.h" |
| 10 | |
| 11 | #include "common/debug.h" |
| 12 | #include "common/utilities.h" |
Geoff Lang | 9d05b93 | 2018-07-27 15:47:18 -0400 | [diff] [blame] | 13 | #include "libANGLE/Context.h" |
Geoff Lang | e1a057e | 2018-06-07 15:09:00 -0400 | [diff] [blame] | 14 | #include "libANGLE/Renderbuffer.h" |
| 15 | #include "libANGLE/Texture.h" |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 16 | #include "libANGLE/angletypes.h" |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 17 | #include "libANGLE/formatutils.h" |
Jamie Madill | 76b8f46 | 2017-04-21 12:23:40 -0400 | [diff] [blame] | 18 | #include "libANGLE/renderer/EGLImplFactory.h" |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 19 | #include "libANGLE/renderer/ImageImpl.h" |
| 20 | |
| 21 | namespace egl |
| 22 | { |
Jamie Madill | 76b8f46 | 2017-04-21 12:23:40 -0400 | [diff] [blame] | 23 | |
| 24 | namespace |
| 25 | { |
| 26 | gl::ImageIndex GetImageIndex(EGLenum eglTarget, const egl::AttributeMap &attribs) |
| 27 | { |
Geoff Lang | c3ee7ec | 2018-09-21 16:15:03 -0400 | [diff] [blame] | 28 | if (!IsTextureTarget(eglTarget)) |
Jamie Madill | 76b8f46 | 2017-04-21 12:23:40 -0400 | [diff] [blame] | 29 | { |
Jamie Madill | cc12937 | 2018-04-12 09:13:18 -0400 | [diff] [blame] | 30 | return gl::ImageIndex(); |
Jamie Madill | 76b8f46 | 2017-04-21 12:23:40 -0400 | [diff] [blame] | 31 | } |
| 32 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 33 | gl::TextureTarget target = egl_gl::EGLImageTargetToTextureTarget(eglTarget); |
Geoff Lang | e1a057e | 2018-06-07 15:09:00 -0400 | [diff] [blame] | 34 | GLint mip = static_cast<GLint>(attribs.get(EGL_GL_TEXTURE_LEVEL_KHR, 0)); |
| 35 | GLint layer = static_cast<GLint>(attribs.get(EGL_GL_TEXTURE_ZOFFSET_KHR, 0)); |
Jamie Madill | 76b8f46 | 2017-04-21 12:23:40 -0400 | [diff] [blame] | 36 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 37 | if (target == gl::TextureTarget::_3D) |
Jamie Madill | 76b8f46 | 2017-04-21 12:23:40 -0400 | [diff] [blame] | 38 | { |
| 39 | return gl::ImageIndex::Make3D(mip, layer); |
| 40 | } |
| 41 | else |
| 42 | { |
| 43 | ASSERT(layer == 0); |
Jamie Madill | cc12937 | 2018-04-12 09:13:18 -0400 | [diff] [blame] | 44 | return gl::ImageIndex::MakeFromTarget(target, mip); |
Jamie Madill | 76b8f46 | 2017-04-21 12:23:40 -0400 | [diff] [blame] | 45 | } |
| 46 | } |
Geoff Lang | 9d05b93 | 2018-07-27 15:47:18 -0400 | [diff] [blame] | 47 | |
| 48 | const Display *DisplayFromContext(const gl::Context *context) |
| 49 | { |
| 50 | return (context ? context->getCurrentDisplay() : nullptr); |
| 51 | } |
| 52 | |
Jamie Madill | 76b8f46 | 2017-04-21 12:23:40 -0400 | [diff] [blame] | 53 | } // anonymous namespace |
| 54 | |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 55 | ImageSibling::ImageSibling() : FramebufferAttachmentObject(), mSourcesOf(), mTargetOf() {} |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 56 | |
| 57 | ImageSibling::~ImageSibling() |
| 58 | { |
| 59 | // EGL images should hold a ref to their targets and siblings, a Texture should not be deletable |
| 60 | // while it is attached to an EGL image. |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 61 | // Child class should orphan images before destruction. |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 62 | ASSERT(mSourcesOf.empty()); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 63 | ASSERT(mTargetOf.get() == nullptr); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 64 | } |
| 65 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 66 | void ImageSibling::setTargetImage(const gl::Context *context, egl::Image *imageTarget) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 67 | { |
| 68 | ASSERT(imageTarget != nullptr); |
Geoff Lang | 9d05b93 | 2018-07-27 15:47:18 -0400 | [diff] [blame] | 69 | mTargetOf.set(DisplayFromContext(context), imageTarget); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 70 | imageTarget->addTargetSibling(this); |
| 71 | } |
| 72 | |
Jamie Madill | 666818e | 2018-11-14 09:54:33 -0500 | [diff] [blame] | 73 | angle::Result ImageSibling::orphanImages(const gl::Context *context) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 74 | { |
| 75 | if (mTargetOf.get() != nullptr) |
| 76 | { |
| 77 | // Can't be a target and have sources. |
| 78 | ASSERT(mSourcesOf.empty()); |
| 79 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 80 | ANGLE_TRY(mTargetOf->orphanSibling(context, this)); |
Geoff Lang | 9d05b93 | 2018-07-27 15:47:18 -0400 | [diff] [blame] | 81 | mTargetOf.set(DisplayFromContext(context), nullptr); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 82 | } |
| 83 | else |
| 84 | { |
Geoff Lang | 9d05b93 | 2018-07-27 15:47:18 -0400 | [diff] [blame] | 85 | for (Image *sourceImage : mSourcesOf) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 86 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 87 | ANGLE_TRY(sourceImage->orphanSibling(context, this)); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 88 | } |
| 89 | mSourcesOf.clear(); |
| 90 | } |
| 91 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 92 | return angle::Result::Continue; |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | void ImageSibling::addImageSource(egl::Image *imageSource) |
| 96 | { |
| 97 | ASSERT(imageSource != nullptr); |
| 98 | mSourcesOf.insert(imageSource); |
| 99 | } |
| 100 | |
| 101 | void ImageSibling::removeImageSource(egl::Image *imageSource) |
| 102 | { |
| 103 | ASSERT(mSourcesOf.find(imageSource) != mSourcesOf.end()); |
| 104 | mSourcesOf.erase(imageSource); |
| 105 | } |
| 106 | |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 107 | bool ImageSibling::isEGLImageTarget() const |
| 108 | { |
| 109 | return (mTargetOf.get() != nullptr); |
| 110 | } |
| 111 | |
| 112 | gl::InitState ImageSibling::sourceEGLImageInitState() const |
| 113 | { |
| 114 | ASSERT(isEGLImageTarget()); |
| 115 | return mTargetOf->sourceInitState(); |
| 116 | } |
| 117 | |
| 118 | void ImageSibling::setSourceEGLImageInitState(gl::InitState initState) const |
| 119 | { |
| 120 | ASSERT(isEGLImageTarget()); |
| 121 | mTargetOf->setInitState(initState); |
| 122 | } |
| 123 | |
Yuly Novikov | 2eb5407 | 2018-08-22 16:41:26 -0400 | [diff] [blame] | 124 | bool ImageSibling::isRenderable(const gl::Context *context, |
| 125 | GLenum binding, |
| 126 | const gl::ImageIndex &imageIndex) const |
| 127 | { |
| 128 | ASSERT(isEGLImageTarget()); |
| 129 | return mTargetOf->isRenderable(context); |
| 130 | } |
| 131 | |
Geoff Lang | c3ee7ec | 2018-09-21 16:15:03 -0400 | [diff] [blame] | 132 | ExternalImageSibling::ExternalImageSibling(rx::EGLImplFactory *factory, |
| 133 | const gl::Context *context, |
| 134 | EGLenum target, |
| 135 | EGLClientBuffer buffer, |
| 136 | const AttributeMap &attribs) |
| 137 | : mImplementation(factory->createExternalImageSibling(context, target, buffer, attribs)) |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 138 | {} |
Geoff Lang | c3ee7ec | 2018-09-21 16:15:03 -0400 | [diff] [blame] | 139 | |
Jamie Madill | ab2bfa8 | 2019-01-15 19:06:47 -0500 | [diff] [blame] | 140 | ExternalImageSibling::~ExternalImageSibling() = default; |
| 141 | |
Geoff Lang | c3ee7ec | 2018-09-21 16:15:03 -0400 | [diff] [blame] | 142 | gl::Extents ExternalImageSibling::getAttachmentSize(const gl::ImageIndex &imageIndex) const |
| 143 | { |
| 144 | return mImplementation->getSize(); |
| 145 | } |
| 146 | |
| 147 | gl::Format ExternalImageSibling::getAttachmentFormat(GLenum binding, |
| 148 | const gl::ImageIndex &imageIndex) const |
| 149 | { |
| 150 | return mImplementation->getFormat(); |
| 151 | } |
| 152 | |
| 153 | GLsizei ExternalImageSibling::getAttachmentSamples(const gl::ImageIndex &imageIndex) const |
| 154 | { |
| 155 | return mImplementation->getSamples(); |
| 156 | } |
| 157 | |
| 158 | bool ExternalImageSibling::isRenderable(const gl::Context *context, |
| 159 | GLenum binding, |
| 160 | const gl::ImageIndex &imageIndex) const |
| 161 | { |
| 162 | return mImplementation->isRenderable(context); |
| 163 | } |
| 164 | |
| 165 | bool ExternalImageSibling::isTextureable(const gl::Context *context) const |
| 166 | { |
| 167 | return mImplementation->isTexturable(context); |
| 168 | } |
| 169 | |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 170 | void ExternalImageSibling::onAttach(const gl::Context *context) {} |
Geoff Lang | c3ee7ec | 2018-09-21 16:15:03 -0400 | [diff] [blame] | 171 | |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 172 | void ExternalImageSibling::onDetach(const gl::Context *context) {} |
Geoff Lang | c3ee7ec | 2018-09-21 16:15:03 -0400 | [diff] [blame] | 173 | |
| 174 | GLuint ExternalImageSibling::getId() const |
| 175 | { |
| 176 | UNREACHABLE(); |
| 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | gl::InitState ExternalImageSibling::initState(const gl::ImageIndex &imageIndex) const |
| 181 | { |
| 182 | return gl::InitState::Initialized; |
| 183 | } |
| 184 | |
| 185 | void ExternalImageSibling::setInitState(const gl::ImageIndex &imageIndex, gl::InitState initState) |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 186 | {} |
Geoff Lang | c3ee7ec | 2018-09-21 16:15:03 -0400 | [diff] [blame] | 187 | |
| 188 | rx::ExternalImageSiblingImpl *ExternalImageSibling::getImplementation() const |
| 189 | { |
| 190 | return mImplementation.get(); |
| 191 | } |
| 192 | |
| 193 | rx::FramebufferAttachmentObjectImpl *ExternalImageSibling::getAttachmentImpl() const |
| 194 | { |
| 195 | return mImplementation.get(); |
| 196 | } |
| 197 | |
Jamie Madill | 76b8f46 | 2017-04-21 12:23:40 -0400 | [diff] [blame] | 198 | ImageState::ImageState(EGLenum target, ImageSibling *buffer, const AttributeMap &attribs) |
Geoff Lang | 0bc81b6 | 2018-07-30 13:34:50 -0400 | [diff] [blame] | 199 | : label(nullptr), |
Geoff Lang | fe59f6b | 2019-01-16 09:34:30 -0500 | [diff] [blame^] | 200 | target(target), |
Geoff Lang | 0bc81b6 | 2018-07-30 13:34:50 -0400 | [diff] [blame] | 201 | imageIndex(GetImageIndex(target, attribs)), |
| 202 | source(buffer), |
| 203 | targets(), |
| 204 | format(buffer->getAttachmentFormat(GL_NONE, imageIndex)), |
| 205 | size(buffer->getAttachmentSize(imageIndex)), |
Yuly Novikov | 2eb5407 | 2018-08-22 16:41:26 -0400 | [diff] [blame] | 206 | samples(buffer->getAttachmentSamples(imageIndex)), |
| 207 | sourceType(target) |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 208 | {} |
Jamie Madill | 76b8f46 | 2017-04-21 12:23:40 -0400 | [diff] [blame] | 209 | |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 210 | ImageState::~ImageState() {} |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 211 | |
Jamie Madill | 76b8f46 | 2017-04-21 12:23:40 -0400 | [diff] [blame] | 212 | Image::Image(rx::EGLImplFactory *factory, |
Geoff Lang | cd7cd2a | 2018-07-19 11:25:54 -0400 | [diff] [blame] | 213 | const gl::Context *context, |
Jamie Madill | 76b8f46 | 2017-04-21 12:23:40 -0400 | [diff] [blame] | 214 | EGLenum target, |
| 215 | ImageSibling *buffer, |
| 216 | const AttributeMap &attribs) |
Geoff Lang | 9d05b93 | 2018-07-27 15:47:18 -0400 | [diff] [blame] | 217 | : mState(target, buffer, attribs), |
Geoff Lang | cd7cd2a | 2018-07-19 11:25:54 -0400 | [diff] [blame] | 218 | mImplementation(factory->createImage(mState, context, target, attribs)), |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 219 | mOrphanedAndNeedsInit(false) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 220 | { |
| 221 | ASSERT(mImplementation != nullptr); |
| 222 | ASSERT(buffer != nullptr); |
| 223 | |
Jamie Madill | 76b8f46 | 2017-04-21 12:23:40 -0400 | [diff] [blame] | 224 | mState.source->addImageSource(this); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 225 | } |
| 226 | |
Jamie Madill | 1c7f08c | 2018-10-10 16:13:02 -0400 | [diff] [blame] | 227 | void Image::onDestroy(const Display *display) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 228 | { |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 229 | // All targets should hold a ref to the egl image and it should not be deleted until there are |
| 230 | // no siblings left. |
Jamie Madill | 76b8f46 | 2017-04-21 12:23:40 -0400 | [diff] [blame] | 231 | ASSERT(mState.targets.empty()); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 232 | |
| 233 | // Tell the source that it is no longer used by this image |
Geoff Lang | 9d05b93 | 2018-07-27 15:47:18 -0400 | [diff] [blame] | 234 | if (mState.source != nullptr) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 235 | { |
Jamie Madill | 76b8f46 | 2017-04-21 12:23:40 -0400 | [diff] [blame] | 236 | mState.source->removeImageSource(this); |
Geoff Lang | c3ee7ec | 2018-09-21 16:15:03 -0400 | [diff] [blame] | 237 | |
| 238 | // If the source is an external object, delete it |
| 239 | if (IsExternalImageTarget(mState.sourceType)) |
| 240 | { |
| 241 | delete mState.source; |
| 242 | } |
| 243 | |
Geoff Lang | 9d05b93 | 2018-07-27 15:47:18 -0400 | [diff] [blame] | 244 | mState.source = nullptr; |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 245 | } |
Geoff Lang | fe59f6b | 2019-01-16 09:34:30 -0500 | [diff] [blame^] | 246 | |
| 247 | mImplementation->onDestroy(display); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 248 | } |
| 249 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 250 | Image::~Image() |
| 251 | { |
Jamie Madill | 71c88b3 | 2017-09-14 22:20:29 -0400 | [diff] [blame] | 252 | SafeDelete(mImplementation); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 253 | } |
| 254 | |
Geoff Lang | 7535966 | 2018-04-11 01:42:27 -0400 | [diff] [blame] | 255 | void Image::setLabel(EGLLabelKHR label) |
| 256 | { |
| 257 | mState.label = label; |
| 258 | } |
| 259 | |
| 260 | EGLLabelKHR Image::getLabel() const |
| 261 | { |
| 262 | return mState.label; |
| 263 | } |
| 264 | |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 265 | void Image::addTargetSibling(ImageSibling *sibling) |
| 266 | { |
Jamie Madill | 76b8f46 | 2017-04-21 12:23:40 -0400 | [diff] [blame] | 267 | mState.targets.insert(sibling); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 268 | } |
| 269 | |
Jamie Madill | 666818e | 2018-11-14 09:54:33 -0500 | [diff] [blame] | 270 | angle::Result Image::orphanSibling(const gl::Context *context, ImageSibling *sibling) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 271 | { |
Geoff Lang | 9d05b93 | 2018-07-27 15:47:18 -0400 | [diff] [blame] | 272 | ASSERT(sibling != nullptr); |
| 273 | |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 274 | // notify impl |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 275 | ANGLE_TRY(mImplementation->orphan(context, sibling)); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 276 | |
Geoff Lang | 9d05b93 | 2018-07-27 15:47:18 -0400 | [diff] [blame] | 277 | if (mState.source == sibling) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 278 | { |
Geoff Lang | c3ee7ec | 2018-09-21 16:15:03 -0400 | [diff] [blame] | 279 | // The external source of an image cannot be redefined so it cannot be orpahend. |
| 280 | ASSERT(!IsExternalImageTarget(mState.sourceType)); |
| 281 | |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 282 | // If the sibling is the source, it cannot be a target. |
Jamie Madill | 76b8f46 | 2017-04-21 12:23:40 -0400 | [diff] [blame] | 283 | ASSERT(mState.targets.find(sibling) == mState.targets.end()); |
Geoff Lang | 9d05b93 | 2018-07-27 15:47:18 -0400 | [diff] [blame] | 284 | mState.source = nullptr; |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 285 | mOrphanedAndNeedsInit = |
| 286 | (sibling->initState(mState.imageIndex) == gl::InitState::MayNeedInit); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 287 | } |
| 288 | else |
| 289 | { |
Jamie Madill | 76b8f46 | 2017-04-21 12:23:40 -0400 | [diff] [blame] | 290 | mState.targets.erase(sibling); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 291 | } |
| 292 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 293 | return angle::Result::Continue; |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 294 | } |
| 295 | |
Geoff Lang | 0bc81b6 | 2018-07-30 13:34:50 -0400 | [diff] [blame] | 296 | const gl::Format &Image::getFormat() const |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 297 | { |
Geoff Lang | 0bc81b6 | 2018-07-30 13:34:50 -0400 | [diff] [blame] | 298 | return mState.format; |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 299 | } |
| 300 | |
Yuly Novikov | 2eb5407 | 2018-08-22 16:41:26 -0400 | [diff] [blame] | 301 | bool Image::isRenderable(const gl::Context *context) const |
| 302 | { |
| 303 | if (IsTextureTarget(mState.sourceType)) |
| 304 | { |
| 305 | return mState.format.info->textureAttachmentSupport(context->getClientVersion(), |
| 306 | context->getExtensions()); |
| 307 | } |
Geoff Lang | c3ee7ec | 2018-09-21 16:15:03 -0400 | [diff] [blame] | 308 | else if (IsRenderbufferTarget(mState.sourceType)) |
Yuly Novikov | 2eb5407 | 2018-08-22 16:41:26 -0400 | [diff] [blame] | 309 | { |
| 310 | return mState.format.info->renderbufferSupport(context->getClientVersion(), |
| 311 | context->getExtensions()); |
| 312 | } |
Geoff Lang | c3ee7ec | 2018-09-21 16:15:03 -0400 | [diff] [blame] | 313 | else if (IsExternalImageTarget(mState.sourceType)) |
| 314 | { |
| 315 | ASSERT(mState.source != nullptr); |
| 316 | return mState.source->isRenderable(context, GL_NONE, gl::ImageIndex()); |
| 317 | } |
Yuly Novikov | 2eb5407 | 2018-08-22 16:41:26 -0400 | [diff] [blame] | 318 | |
| 319 | UNREACHABLE(); |
| 320 | return false; |
| 321 | } |
| 322 | |
| 323 | bool Image::isTexturable(const gl::Context *context) const |
| 324 | { |
| 325 | if (IsTextureTarget(mState.sourceType)) |
| 326 | { |
| 327 | return mState.format.info->textureSupport(context->getClientVersion(), |
| 328 | context->getExtensions()); |
| 329 | } |
Geoff Lang | c3ee7ec | 2018-09-21 16:15:03 -0400 | [diff] [blame] | 330 | else if (IsRenderbufferTarget(mState.sourceType)) |
Yuly Novikov | 2eb5407 | 2018-08-22 16:41:26 -0400 | [diff] [blame] | 331 | { |
| 332 | return true; |
| 333 | } |
Geoff Lang | c3ee7ec | 2018-09-21 16:15:03 -0400 | [diff] [blame] | 334 | else if (IsExternalImageTarget(mState.sourceType)) |
| 335 | { |
| 336 | ASSERT(mState.source != nullptr); |
| 337 | return rx::GetAs<ExternalImageSibling>(mState.source)->isTextureable(context); |
| 338 | } |
Yuly Novikov | 2eb5407 | 2018-08-22 16:41:26 -0400 | [diff] [blame] | 339 | |
| 340 | UNREACHABLE(); |
| 341 | return false; |
| 342 | } |
| 343 | |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 344 | size_t Image::getWidth() const |
| 345 | { |
Geoff Lang | 0bc81b6 | 2018-07-30 13:34:50 -0400 | [diff] [blame] | 346 | return mState.size.width; |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | size_t Image::getHeight() const |
| 350 | { |
Geoff Lang | 0bc81b6 | 2018-07-30 13:34:50 -0400 | [diff] [blame] | 351 | return mState.size.height; |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | size_t Image::getSamples() const |
| 355 | { |
Geoff Lang | 0bc81b6 | 2018-07-30 13:34:50 -0400 | [diff] [blame] | 356 | return mState.samples; |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 357 | } |
| 358 | |
Jamie Madill | 76b8f46 | 2017-04-21 12:23:40 -0400 | [diff] [blame] | 359 | rx::ImageImpl *Image::getImplementation() const |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 360 | { |
| 361 | return mImplementation; |
| 362 | } |
| 363 | |
Geoff Lang | cd7cd2a | 2018-07-19 11:25:54 -0400 | [diff] [blame] | 364 | Error Image::initialize(const Display *display) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 365 | { |
Geoff Lang | cd7cd2a | 2018-07-19 11:25:54 -0400 | [diff] [blame] | 366 | return mImplementation->initialize(display); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 367 | } |
Jamie Madill | 76b8f46 | 2017-04-21 12:23:40 -0400 | [diff] [blame] | 368 | |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 369 | bool Image::orphaned() const |
| 370 | { |
Geoff Lang | 9d05b93 | 2018-07-27 15:47:18 -0400 | [diff] [blame] | 371 | return (mState.source == nullptr); |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | gl::InitState Image::sourceInitState() const |
| 375 | { |
| 376 | if (orphaned()) |
| 377 | { |
| 378 | return mOrphanedAndNeedsInit ? gl::InitState::MayNeedInit : gl::InitState::Initialized; |
| 379 | } |
| 380 | |
| 381 | return mState.source->initState(mState.imageIndex); |
| 382 | } |
| 383 | |
| 384 | void Image::setInitState(gl::InitState initState) |
| 385 | { |
| 386 | if (orphaned()) |
| 387 | { |
| 388 | mOrphanedAndNeedsInit = false; |
| 389 | } |
| 390 | |
| 391 | return mState.source->setInitState(mState.imageIndex, initState); |
| 392 | } |
| 393 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 394 | } // namespace egl |