tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

Image.h (7251B)


      1 //
      2 // Copyright 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.h: Defines the egl::Image class representing the EGLimage object.
      8 
      9 #ifndef LIBANGLE_IMAGE_H_
     10 #define LIBANGLE_IMAGE_H_
     11 
     12 #include "common/FastVector.h"
     13 #include "common/angleutils.h"
     14 #include "libANGLE/AttributeMap.h"
     15 #include "libANGLE/Debug.h"
     16 #include "libANGLE/Error.h"
     17 #include "libANGLE/FramebufferAttachment.h"
     18 #include "libANGLE/RefCountObject.h"
     19 #include "libANGLE/formatutils.h"
     20 
     21 namespace rx
     22 {
     23 class EGLImplFactory;
     24 class ImageImpl;
     25 class ExternalImageSiblingImpl;
     26 
     27 // Used for distinguishing dirty bit messages from gl::Texture/rx::TexureImpl/gl::Image.
     28 constexpr size_t kTextureImageImplObserverMessageIndex = 0;
     29 constexpr size_t kTextureImageSiblingMessageIndex      = 1;
     30 }  // namespace rx
     31 
     32 namespace egl
     33 {
     34 class Image;
     35 class Display;
     36 
     37 // Only currently Renderbuffers and Textures can be bound with images. This makes the relationship
     38 // explicit, and also ensures that an image sibling can determine if it's been initialized or not,
     39 // which is important for the robust resource init extension with Textures and EGLImages.
     40 class ImageSibling : public gl::FramebufferAttachmentObject
     41 {
     42  public:
     43    ImageSibling();
     44    ~ImageSibling() override;
     45 
     46    bool isEGLImageTarget() const;
     47    gl::InitState sourceEGLImageInitState() const;
     48    void setSourceEGLImageInitState(gl::InitState initState) const;
     49 
     50    bool isRenderable(const gl::Context *context,
     51                      GLenum binding,
     52                      const gl::ImageIndex &imageIndex) const override;
     53    bool isYUV() const override;
     54    bool isCreatedWithAHB() const override;
     55    bool hasProtectedContent() const override;
     56 
     57  protected:
     58    // Set the image target of this sibling
     59    void setTargetImage(const gl::Context *context, egl::Image *imageTarget);
     60 
     61    // Orphan all EGL image sources and targets
     62    angle::Result orphanImages(const gl::Context *context,
     63                               RefCountObjectReleaser<Image> *outReleaseImage);
     64 
     65    void notifySiblings(angle::SubjectMessage message);
     66 
     67  private:
     68    friend class Image;
     69 
     70    // Called from Image only to add a new source image
     71    void addImageSource(egl::Image *imageSource);
     72 
     73    // Called from Image only to remove a source image when the Image is being deleted
     74    void removeImageSource(egl::Image *imageSource);
     75 
     76    static constexpr size_t kSourcesOfSetSize = 2;
     77    angle::FlatUnorderedSet<Image *, kSourcesOfSetSize> mSourcesOf;
     78    BindingPointer<Image> mTargetOf;
     79 };
     80 
     81 // Wrapper for EGLImage sources that are not owned by ANGLE, these often have to do
     82 // platform-specific queries for format and size information.
     83 class ExternalImageSibling : public ImageSibling
     84 {
     85  public:
     86    ExternalImageSibling(rx::EGLImplFactory *factory,
     87                         const gl::Context *context,
     88                         EGLenum target,
     89                         EGLClientBuffer buffer,
     90                         const AttributeMap &attribs);
     91    ~ExternalImageSibling() override;
     92 
     93    void onDestroy(const egl::Display *display);
     94 
     95    Error initialize(const Display *display);
     96 
     97    gl::Extents getAttachmentSize(const gl::ImageIndex &imageIndex) const override;
     98    gl::Format getAttachmentFormat(GLenum binding, const gl::ImageIndex &imageIndex) const override;
     99    GLsizei getAttachmentSamples(const gl::ImageIndex &imageIndex) const override;
    100    GLuint getLevelCount() const;
    101    bool isRenderable(const gl::Context *context,
    102                      GLenum binding,
    103                      const gl::ImageIndex &imageIndex) const override;
    104    bool isTextureable(const gl::Context *context) const;
    105    bool isYUV() const override;
    106    bool isCubeMap() const;
    107    bool hasProtectedContent() const override;
    108 
    109    void onAttach(const gl::Context *context, rx::Serial framebufferSerial) override;
    110    void onDetach(const gl::Context *context, rx::Serial framebufferSerial) override;
    111    GLuint getId() const override;
    112 
    113    gl::InitState initState(GLenum binding, const gl::ImageIndex &imageIndex) const override;
    114    void setInitState(GLenum binding,
    115                      const gl::ImageIndex &imageIndex,
    116                      gl::InitState initState) override;
    117 
    118    rx::ExternalImageSiblingImpl *getImplementation() const;
    119 
    120  protected:
    121    rx::FramebufferAttachmentObjectImpl *getAttachmentImpl() const override;
    122 
    123  private:
    124    // ObserverInterface implementation.
    125    void onSubjectStateChange(angle::SubjectIndex index, angle::SubjectMessage message) override;
    126 
    127    std::unique_ptr<rx::ExternalImageSiblingImpl> mImplementation;
    128    angle::ObserverBinding mImplObserverBinding;
    129 };
    130 
    131 struct ImageState : private angle::NonCopyable
    132 {
    133    ImageState(EGLenum target, ImageSibling *buffer, const AttributeMap &attribs);
    134    ~ImageState();
    135 
    136    EGLLabelKHR label;
    137    EGLenum target;
    138    gl::ImageIndex imageIndex;
    139    ImageSibling *source;
    140 
    141    gl::Format format;
    142    bool yuv;
    143    bool cubeMap;
    144    gl::Extents size;
    145    size_t samples;
    146    GLuint levelCount;
    147    EGLenum sourceType;
    148    EGLenum colorspace;
    149    bool hasProtectedContent;
    150 
    151    mutable std::mutex targetsLock;
    152 
    153    static constexpr size_t kTargetsSetSize = 2;
    154    angle::FlatUnorderedSet<ImageSibling *, kTargetsSetSize> targets;
    155 };
    156 
    157 class Image final : public RefCountObject, public LabeledObject
    158 {
    159  public:
    160    Image(rx::EGLImplFactory *factory,
    161          const gl::Context *context,
    162          EGLenum target,
    163          ImageSibling *buffer,
    164          const AttributeMap &attribs);
    165 
    166    void onDestroy(const Display *display) override;
    167    ~Image() override;
    168 
    169    void setLabel(EGLLabelKHR label) override;
    170    EGLLabelKHR getLabel() const override;
    171 
    172    const gl::Format &getFormat() const;
    173    bool isRenderable(const gl::Context *context) const;
    174    bool isTexturable(const gl::Context *context) const;
    175    bool isYUV() const;
    176    bool isCreatedWithAHB() const;
    177    // Returns true only if the eglImage contains a complete cubemap
    178    bool isCubeMap() const;
    179    size_t getWidth() const;
    180    size_t getHeight() const;
    181    const gl::Extents &getExtents() const;
    182    bool isLayered() const;
    183    size_t getSamples() const;
    184    GLuint getLevelCount() const;
    185    bool hasProtectedContent() const;
    186 
    187    Error initialize(const Display *display);
    188 
    189    rx::ImageImpl *getImplementation() const;
    190 
    191    bool orphaned() const;
    192    gl::InitState sourceInitState() const;
    193    void setInitState(gl::InitState initState);
    194 
    195    Error exportVkImage(void *vkImage, void *vkImageCreateInfo);
    196 
    197  private:
    198    friend class ImageSibling;
    199 
    200    // Called from ImageSibling only notify the image that a new target sibling exists for state
    201    // tracking.
    202    void addTargetSibling(ImageSibling *sibling);
    203 
    204    // Called from ImageSibling only to notify the image that a sibling (source or target) has
    205    // been respecified and state tracking should be updated.
    206    angle::Result orphanSibling(const gl::Context *context, ImageSibling *sibling);
    207 
    208    void notifySiblings(const ImageSibling *notifier, angle::SubjectMessage message);
    209 
    210    ImageState mState;
    211    rx::ImageImpl *mImplementation;
    212    bool mOrphanedAndNeedsInit;
    213 };
    214 }  // namespace egl
    215 
    216 #endif  // LIBANGLE_IMAGE_H_