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 mFormat = gl::Format(angle::DrmFourCCFormatToGLInternalFormat(fourCCFormat, &mYUV));
28 }
29
~DmaBufImageSiblingEGL()30 DmaBufImageSiblingEGL::~DmaBufImageSiblingEGL() {}
31
initialize(const egl::Display * display)32 egl::Error DmaBufImageSiblingEGL::initialize(const egl::Display *display)
33 {
34 return egl::NoError();
35 }
36
getFormat() const37 gl::Format DmaBufImageSiblingEGL::getFormat() const
38 {
39 return mFormat;
40 }
41
isRenderable(const gl::Context * context) const42 bool DmaBufImageSiblingEGL::isRenderable(const gl::Context *context) const
43 {
44 return true;
45 }
46
isTexturable(const gl::Context * context) const47 bool DmaBufImageSiblingEGL::isTexturable(const gl::Context *context) const
48 {
49 return true;
50 }
51
isYUV() const52 bool DmaBufImageSiblingEGL::isYUV() const
53 {
54 return mYUV;
55 }
56
hasProtectedContent() const57 bool DmaBufImageSiblingEGL::hasProtectedContent() const
58 {
59 return mHasProtectedContent;
60 }
61
getSize() const62 gl::Extents DmaBufImageSiblingEGL::getSize() const
63 {
64 return mSize;
65 }
66
getSamples() const67 size_t DmaBufImageSiblingEGL::getSamples() const
68 {
69 return 0;
70 }
71
getBuffer() const72 EGLClientBuffer DmaBufImageSiblingEGL::getBuffer() const
73 {
74 return nullptr;
75 }
76
getImageCreationAttributes(std::vector<EGLint> * outAttributes) const77 void DmaBufImageSiblingEGL::getImageCreationAttributes(std::vector<EGLint> *outAttributes) const
78 {
79 EGLenum kForwardedAttribs[] = {EGL_WIDTH,
80 EGL_HEIGHT,
81 EGL_PROTECTED_CONTENT_EXT,
82 EGL_LINUX_DRM_FOURCC_EXT,
83 EGL_DMA_BUF_PLANE0_FD_EXT,
84 EGL_DMA_BUF_PLANE0_OFFSET_EXT,
85 EGL_DMA_BUF_PLANE0_PITCH_EXT,
86 EGL_DMA_BUF_PLANE1_FD_EXT,
87 EGL_DMA_BUF_PLANE1_OFFSET_EXT,
88 EGL_DMA_BUF_PLANE1_PITCH_EXT,
89 EGL_DMA_BUF_PLANE2_FD_EXT,
90 EGL_DMA_BUF_PLANE2_OFFSET_EXT,
91 EGL_DMA_BUF_PLANE2_PITCH_EXT,
92 EGL_YUV_COLOR_SPACE_HINT_EXT,
93 EGL_SAMPLE_RANGE_HINT_EXT,
94 EGL_YUV_CHROMA_HORIZONTAL_SITING_HINT_EXT,
95 EGL_YUV_CHROMA_VERTICAL_SITING_HINT_EXT,
96
97 EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT,
98 EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT,
99 EGL_DMA_BUF_PLANE1_MODIFIER_LO_EXT,
100 EGL_DMA_BUF_PLANE1_MODIFIER_HI_EXT,
101 EGL_DMA_BUF_PLANE2_MODIFIER_LO_EXT,
102 EGL_DMA_BUF_PLANE2_MODIFIER_HI_EXT,
103 EGL_DMA_BUF_PLANE3_FD_EXT,
104 EGL_DMA_BUF_PLANE3_OFFSET_EXT,
105 EGL_DMA_BUF_PLANE3_PITCH_EXT,
106 EGL_DMA_BUF_PLANE3_MODIFIER_LO_EXT,
107 EGL_DMA_BUF_PLANE3_MODIFIER_HI_EXT};
108
109 for (EGLenum forwardedAttrib : kForwardedAttribs)
110 {
111 if (mAttribs.contains(forwardedAttrib))
112 {
113 outAttributes->push_back(forwardedAttrib);
114 outAttributes->push_back(mAttribs.getAsInt(forwardedAttrib));
115 }
116 }
117 }
118
119 } // namespace rx
120