xref: /aosp_15_r20/external/angle/src/libANGLE/renderer/gl/egl/DmaBufImageSiblingEGL.cpp (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 //
2 // Copyright 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 // DmaBufImageSiblingEGL.cpp: Defines the DmaBufImageSiblingEGL to wrap EGL images
8 // created from dma_buf objects
9 
10 #include "libANGLE/renderer/gl/egl/DmaBufImageSiblingEGL.h"
11 
12 #include "common/linux/dma_buf_utils.h"
13 
14 namespace rx
15 {
DmaBufImageSiblingEGL(const egl::AttributeMap & attribs)16 DmaBufImageSiblingEGL::DmaBufImageSiblingEGL(const egl::AttributeMap &attribs)
17     : mAttribs(attribs), mFormat(GL_NONE), mYUV(false), mHasProtectedContent(false)
18 {
19     ASSERT(mAttribs.contains(EGL_WIDTH));
20     mSize.width = mAttribs.getAsInt(EGL_WIDTH);
21     ASSERT(mAttribs.contains(EGL_HEIGHT));
22     mSize.height         = mAttribs.getAsInt(EGL_HEIGHT);
23     mSize.depth          = 1;
24     mHasProtectedContent = false;
25 
26     int fourCCFormat      = mAttribs.getAsInt(EGL_LINUX_DRM_FOURCC_EXT);
27     GLenum internalFormat = angle::DrmFourCCFormatToGLInternalFormat(fourCCFormat, &mYUV);
28     // These ANGLE formats are used exclusively with the Vulkan backend.
29     if (internalFormat == GL_RGBX8_ANGLE || internalFormat == GL_BGRX8_ANGLEX)
30     {
31         internalFormat = GL_RGB8;
32     }
33     mFormat = gl::Format(internalFormat);
34 }
35 
~DmaBufImageSiblingEGL()36 DmaBufImageSiblingEGL::~DmaBufImageSiblingEGL() {}
37 
initialize(const egl::Display * display)38 egl::Error DmaBufImageSiblingEGL::initialize(const egl::Display *display)
39 {
40     return egl::NoError();
41 }
42 
getFormat() const43 gl::Format DmaBufImageSiblingEGL::getFormat() const
44 {
45     return mFormat;
46 }
47 
isRenderable(const gl::Context * context) const48 bool DmaBufImageSiblingEGL::isRenderable(const gl::Context *context) const
49 {
50     return true;
51 }
52 
isTexturable(const gl::Context * context) const53 bool DmaBufImageSiblingEGL::isTexturable(const gl::Context *context) const
54 {
55     return true;
56 }
57 
isYUV() const58 bool DmaBufImageSiblingEGL::isYUV() const
59 {
60     return mYUV;
61 }
62 
hasProtectedContent() const63 bool DmaBufImageSiblingEGL::hasProtectedContent() const
64 {
65     return mHasProtectedContent;
66 }
67 
getSize() const68 gl::Extents DmaBufImageSiblingEGL::getSize() const
69 {
70     return mSize;
71 }
72 
getSamples() const73 size_t DmaBufImageSiblingEGL::getSamples() const
74 {
75     return 0;
76 }
77 
getBuffer() const78 EGLClientBuffer DmaBufImageSiblingEGL::getBuffer() const
79 {
80     return nullptr;
81 }
82 
getImageCreationAttributes(std::vector<EGLint> * outAttributes) const83 void DmaBufImageSiblingEGL::getImageCreationAttributes(std::vector<EGLint> *outAttributes) const
84 {
85     EGLenum kForwardedAttribs[] = {EGL_WIDTH,
86                                    EGL_HEIGHT,
87                                    EGL_PROTECTED_CONTENT_EXT,
88                                    EGL_LINUX_DRM_FOURCC_EXT,
89                                    EGL_DMA_BUF_PLANE0_FD_EXT,
90                                    EGL_DMA_BUF_PLANE0_OFFSET_EXT,
91                                    EGL_DMA_BUF_PLANE0_PITCH_EXT,
92                                    EGL_DMA_BUF_PLANE1_FD_EXT,
93                                    EGL_DMA_BUF_PLANE1_OFFSET_EXT,
94                                    EGL_DMA_BUF_PLANE1_PITCH_EXT,
95                                    EGL_DMA_BUF_PLANE2_FD_EXT,
96                                    EGL_DMA_BUF_PLANE2_OFFSET_EXT,
97                                    EGL_DMA_BUF_PLANE2_PITCH_EXT,
98                                    EGL_YUV_COLOR_SPACE_HINT_EXT,
99                                    EGL_SAMPLE_RANGE_HINT_EXT,
100                                    EGL_YUV_CHROMA_HORIZONTAL_SITING_HINT_EXT,
101                                    EGL_YUV_CHROMA_VERTICAL_SITING_HINT_EXT,
102 
103                                    EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT,
104                                    EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT,
105                                    EGL_DMA_BUF_PLANE1_MODIFIER_LO_EXT,
106                                    EGL_DMA_BUF_PLANE1_MODIFIER_HI_EXT,
107                                    EGL_DMA_BUF_PLANE2_MODIFIER_LO_EXT,
108                                    EGL_DMA_BUF_PLANE2_MODIFIER_HI_EXT,
109                                    EGL_DMA_BUF_PLANE3_FD_EXT,
110                                    EGL_DMA_BUF_PLANE3_OFFSET_EXT,
111                                    EGL_DMA_BUF_PLANE3_PITCH_EXT,
112                                    EGL_DMA_BUF_PLANE3_MODIFIER_LO_EXT,
113                                    EGL_DMA_BUF_PLANE3_MODIFIER_HI_EXT};
114 
115     for (EGLenum forwardedAttrib : kForwardedAttribs)
116     {
117         if (mAttribs.contains(forwardedAttrib))
118         {
119             outAttributes->push_back(forwardedAttrib);
120             outAttributes->push_back(mAttribs.getAsInt(forwardedAttrib));
121         }
122     }
123 }
124 
125 }  // namespace rx
126