tor-browser

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

Stream.h (3797B)


      1 //
      2 // Copyright 2016 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 // Stream.h: Defines the egl::Stream class, representing the stream
      8 // where frames are streamed in. Implements EGLStreanKHR.
      9 
     10 #ifndef LIBANGLE_STREAM_H_
     11 #define LIBANGLE_STREAM_H_
     12 
     13 #include <array>
     14 
     15 #include <EGL/egl.h>
     16 #include <EGL/eglext.h>
     17 
     18 #include "common/angleutils.h"
     19 #include "libANGLE/AttributeMap.h"
     20 #include "libANGLE/Debug.h"
     21 
     22 namespace rx
     23 {
     24 class StreamProducerImpl;
     25 }
     26 
     27 namespace gl
     28 {
     29 class Context;
     30 class Texture;
     31 }  // namespace gl
     32 
     33 namespace egl
     34 {
     35 class Display;
     36 class Error;
     37 class Thread;
     38 
     39 class Stream final : public LabeledObject, angle::NonCopyable
     40 {
     41  public:
     42    Stream(Display *display, const AttributeMap &attribs);
     43    ~Stream() override;
     44 
     45    void setLabel(EGLLabelKHR label) override;
     46    EGLLabelKHR getLabel() const override;
     47 
     48    enum class ConsumerType
     49    {
     50        NoConsumer,
     51        GLTextureRGB,
     52        GLTextureYUV,
     53    };
     54 
     55    enum class ProducerType
     56    {
     57        NoProducer,
     58        D3D11Texture,
     59    };
     60 
     61    // A GL texture interpretation of a part of a producer frame. For use with GL texture consumers
     62    struct GLTextureDescription
     63    {
     64        unsigned int width;
     65        unsigned int height;
     66        unsigned int internalFormat;
     67        unsigned int mipLevels;
     68    };
     69 
     70    EGLenum getState() const;
     71 
     72    void setConsumerLatency(EGLint latency);
     73    EGLint getConsumerLatency() const;
     74 
     75    EGLuint64KHR getProducerFrame() const;
     76    EGLuint64KHR getConsumerFrame() const;
     77 
     78    void setConsumerAcquireTimeout(EGLint timeout);
     79    EGLint getConsumerAcquireTimeout() const;
     80 
     81    ConsumerType getConsumerType() const;
     82    ProducerType getProducerType() const;
     83 
     84    EGLint getPlaneCount() const;
     85 
     86    rx::StreamProducerImpl *getImplementation();
     87 
     88    // Consumer creation methods
     89    Error createConsumerGLTextureExternal(const AttributeMap &attributes, gl::Context *context);
     90 
     91    // Producer creation methods
     92    Error createProducerD3D11Texture(const AttributeMap &attributes);
     93 
     94    // Consumer methods
     95    Error consumerAcquire(const gl::Context *context);
     96    Error consumerRelease(const gl::Context *context);
     97 
     98    // Some consumers are bound to GL contexts. This validates that a given context is bound to the
     99    // stream's consumer
    100    bool isConsumerBoundToContext(const gl::Context *context) const;
    101 
    102    // Producer methods
    103    Error validateD3D11Texture(const void *texture, const AttributeMap &attributes) const;
    104    Error postD3D11Texture(void *texture, const AttributeMap &attributes);
    105 
    106  private:
    107    EGLLabelKHR mLabel;
    108 
    109    // Associated display
    110    Display *mDisplay;
    111 
    112    // Producer Implementation
    113    rx::StreamProducerImpl *mProducerImplementation;
    114 
    115    // Associated GL context. Note that this is a weak pointer used for validation purposes only,
    116    // and should never be arbitrarily dereferenced without knowing the context still exists as it
    117    // can become dangling at any time.
    118    gl::Context *mContext;
    119 
    120    // EGL defined attributes
    121    EGLint mState;
    122    EGLuint64KHR mProducerFrame;
    123    EGLuint64KHR mConsumerFrame;
    124    EGLint mConsumerLatency;
    125 
    126    // EGL gltexture consumer attributes
    127    EGLint mConsumerAcquireTimeout;
    128 
    129    // EGL gltexture yuv consumer attributes
    130    EGLint mPlaneCount;
    131    struct PlaneTexture
    132    {
    133        EGLint textureUnit;
    134        gl::Texture *texture;
    135    };
    136    // Texture units and textures for all the planes
    137    std::array<PlaneTexture, 3> mPlanes;
    138 
    139    // Consumer and producer types
    140    ConsumerType mConsumerType;
    141    ProducerType mProducerType;
    142 
    143    // ANGLE-only method, used internally
    144    friend class gl::Texture;
    145    void releaseTextures();
    146 };
    147 }  // namespace egl
    148 
    149 #endif  // LIBANGLE_STREAM_H_