1 //
2 // Copyright 2018 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 // NativeBufferImageSiblingAndroid.cpp: Implements the NativeBufferImageSiblingAndroid class
8
9 #include "libANGLE/renderer/gl/egl/android/NativeBufferImageSiblingAndroid.h"
10
11 #include "common/android_util.h"
12
13 namespace rx
14 {
NativeBufferImageSiblingAndroid(EGLClientBuffer buffer,const egl::AttributeMap & attribs)15 NativeBufferImageSiblingAndroid::NativeBufferImageSiblingAndroid(EGLClientBuffer buffer,
16 const egl::AttributeMap &attribs)
17 : mBuffer(buffer), mFormat(GL_NONE), mYUV(false), mColorSpace(EGL_GL_COLORSPACE_LINEAR_KHR)
18 {
19 if (attribs.contains(EGL_GL_COLORSPACE_KHR))
20 {
21 mColorSpace = attribs.getAsInt(EGL_GL_COLORSPACE_KHR);
22 }
23 }
24
~NativeBufferImageSiblingAndroid()25 NativeBufferImageSiblingAndroid::~NativeBufferImageSiblingAndroid() {}
26
initialize(const egl::Display * display)27 egl::Error NativeBufferImageSiblingAndroid::initialize(const egl::Display *display)
28 {
29 int pixelFormat = 0;
30 uint64_t usage = 0;
31 angle::android::GetANativeWindowBufferProperties(
32 angle::android::ClientBufferToANativeWindowBuffer(mBuffer), &mSize.width, &mSize.height,
33 &mSize.depth, &pixelFormat, &usage);
34 mFormat = gl::Format(angle::android::NativePixelFormatToGLInternalFormat(pixelFormat));
35 mYUV = angle::android::NativePixelFormatIsYUV(pixelFormat);
36 mHasProtectedContent = false;
37
38 return egl::NoError();
39 }
40
getFormat() const41 gl::Format NativeBufferImageSiblingAndroid::getFormat() const
42 {
43 return mFormat;
44 }
45
isRenderable(const gl::Context * context) const46 bool NativeBufferImageSiblingAndroid::isRenderable(const gl::Context *context) const
47 {
48 return true;
49 }
50
isTexturable(const gl::Context * context) const51 bool NativeBufferImageSiblingAndroid::isTexturable(const gl::Context *context) const
52 {
53 return true;
54 }
55
isYUV() const56 bool NativeBufferImageSiblingAndroid::isYUV() const
57 {
58 return mYUV;
59 }
60
hasProtectedContent() const61 bool NativeBufferImageSiblingAndroid::hasProtectedContent() const
62 {
63 return mHasProtectedContent;
64 }
65
getSize() const66 gl::Extents NativeBufferImageSiblingAndroid::getSize() const
67 {
68 return mSize;
69 }
70
getSamples() const71 size_t NativeBufferImageSiblingAndroid::getSamples() const
72 {
73 return 0;
74 }
75
getBuffer() const76 EGLClientBuffer NativeBufferImageSiblingAndroid::getBuffer() const
77 {
78 return mBuffer;
79 }
80
getImageCreationAttributes(std::vector<EGLint> * outAttributes) const81 void NativeBufferImageSiblingAndroid::getImageCreationAttributes(
82 std::vector<EGLint> *outAttributes) const
83 {
84 if (mColorSpace != EGL_GL_COLORSPACE_LINEAR_KHR)
85 {
86 outAttributes->push_back(EGL_GL_COLORSPACE_KHR);
87 outAttributes->push_back(mColorSpace);
88 }
89 }
90
91 } // namespace rx
92