1 // 2 // Copyright 2021 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 // ImageMtl.h: 7 // Defines the class interface for ImageMtl, implementing ImageImpl. 8 // 9 10 #ifndef LIBANGLE_RENDERER_METAL_IMAGEMTL_H 11 #define LIBANGLE_RENDERER_METAL_IMAGEMTL_H 12 13 #include "libANGLE/renderer/ImageImpl.h" 14 #include "libANGLE/renderer/metal/mtl_resources.h" 15 16 namespace rx 17 { 18 19 class DisplayMtl; 20 21 class TextureImageSiblingMtl : public ExternalImageSiblingImpl 22 { 23 public: 24 TextureImageSiblingMtl(EGLClientBuffer buffer, const egl::AttributeMap &attribs); 25 ~TextureImageSiblingMtl() override; 26 27 static egl::Error ValidateClientBuffer(const DisplayMtl *display, 28 EGLClientBuffer buffer, 29 const egl::AttributeMap &attribs); 30 31 egl::Error initialize(const egl::Display *display) override; 32 void onDestroy(const egl::Display *display) override; 33 34 // ExternalImageSiblingImpl interface 35 gl::Format getFormat() const override; 36 bool isRenderable(const gl::Context *context) const override; 37 bool isTexturable(const gl::Context *context) const override; 38 gl::Extents getSize() const override; 39 size_t getSamples() const override; 40 41 bool isYUV() const override; 42 bool hasProtectedContent() const override; 43 getTexture()44 const mtl::TextureRef &getTexture() const { return mNativeTexture; } getFormatMtl()45 const mtl::Format &getFormatMtl() const { return mFormat; } 46 47 private: 48 angle::Result initImpl(DisplayMtl *display); 49 50 EGLClientBuffer mBuffer; 51 egl::AttributeMap mAttribs; 52 gl::Format mGLFormat; 53 mtl::Format mFormat; 54 55 bool mRenderable = false; 56 bool mTextureable = false; 57 58 mtl::TextureRef mNativeTexture; 59 }; 60 61 class ImageMtl : public ImageImpl 62 { 63 public: 64 ImageMtl(const egl::ImageState &state, const gl::Context *context); 65 ~ImageMtl() override; 66 void onDestroy(const egl::Display *display) override; 67 68 egl::Error initialize(const egl::Display *display) override; 69 70 angle::Result orphan(const gl::Context *context, egl::ImageSibling *sibling) override; 71 getTexture()72 const mtl::TextureRef &getTexture() const { return mNativeTexture; } getImageTextureType()73 gl::TextureType getImageTextureType() const { return mImageTextureType; } getImageLevel()74 uint32_t getImageLevel() const { return mImageLevel; } getImageLayer()75 uint32_t getImageLayer() const { return mImageLayer; } 76 77 private: 78 gl::TextureType mImageTextureType; 79 uint32_t mImageLevel = 0; 80 uint32_t mImageLayer = 0; 81 82 mtl::TextureRef mNativeTexture; 83 }; 84 } // namespace rx 85 86 #endif /* LIBANGLE_RENDERER_METAL_IMAGEMTL_H */ 87