Commit 3fd0b2db by Geoff Lang Committed by Commit Bot

Implement EGL_ANDROID_get_native_client_buffer.

BUG=angleproject:2508 Change-Id: I21e6251cd1341c1f85f1ba16ba08f5876a8ff8de Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1238885 Commit-Queue: Geoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 55efe37c
......@@ -89,6 +89,7 @@ supported_extensions = sorted(angle_extensions + gles1_extensions + gles_extensi
supported_egl_extensions = [
"EGL_ANDROID_blob_cache",
"EGL_ANDROID_get_frame_timestamps",
"EGL_ANDROID_get_native_client_buffer",
"EGL_ANDROID_presentation_time",
"EGL_ANGLE_d3d_share_handle_client_buffer",
"EGL_ANGLE_device_creation",
......
......@@ -100,7 +100,7 @@
"GL/EGL entry points:scripts/gl_angle_ext.xml":
"bed6b56a38621721e689ebc19601a556",
"GL/EGL entry points:scripts/registry_xml.py":
"683a498150204f16c44264714e2bed07",
"24fa69f5641ed09c8e8a2f9c64fd0260",
"GL/EGL entry points:scripts/wgl.xml":
"aa96419c582af2f6673430e2847693f4",
"GL/EGL entry points:src/libANGLE/Context_gl_1_0_autogen.h":
......@@ -212,9 +212,9 @@
"GL/EGL entry points:src/libGLESv2/libGLESv2_autogen.cpp":
"229577015686414a6d094533c2210cea",
"GL/EGL entry points:src/libGLESv2/libGLESv2_autogen.def":
"5973958936850835cc48a57bba9bd33a",
"fca8c7d5ec90a68a6ad062fc4edf67e4",
"GL/EGL entry points:src/libGLESv2/libGLESv2_with_capture_autogen.def":
"a2973e5317d62329e5aa761058afd2ad",
"45eecb859db4e21d7591e5819ebd81dd",
"GL/EGL entry points:src/openGL32/entry_points_gl_1_0_autogen.cpp":
"f388cf1698bfd71f25939123f7a3952c",
"GL/EGL entry points:src/openGL32/entry_points_gl_1_0_autogen.h":
......@@ -266,17 +266,17 @@
"GL/EGL/WGL loader:scripts/generate_loader.py":
"5a7cd014230fe04664d9613e65399d42",
"GL/EGL/WGL loader:scripts/registry_xml.py":
"683a498150204f16c44264714e2bed07",
"24fa69f5641ed09c8e8a2f9c64fd0260",
"GL/EGL/WGL loader:scripts/wgl.xml":
"aa96419c582af2f6673430e2847693f4",
"GL/EGL/WGL loader:src/libEGL/egl_loader_autogen.cpp":
"0ebe5668fba36b5b4ad5abb64c21ca32",
"84c8b518af7051faa89702a5d553e87e",
"GL/EGL/WGL loader:src/libEGL/egl_loader_autogen.h":
"adfee42620344b47b5f2c934e4c58e37",
"a8f0278a7dec5c9d6e1ca0854e9542e9",
"GL/EGL/WGL loader:util/egl_loader_autogen.cpp":
"5e2ea1c54813036aa363eac2c1388f4a",
"4b23b703a6598a75ea753e9b4aa6ea0f",
"GL/EGL/WGL loader:util/egl_loader_autogen.h":
"a4f0d640554d9c2b4f90f1f2271a1104",
"7ae6f818846fff1a734bc975c82319b2",
"GL/EGL/WGL loader:util/gles_loader_autogen.cpp":
"335463406e64c6dc9bf00502cb25d53c",
"GL/EGL/WGL loader:util/gles_loader_autogen.h":
......@@ -574,11 +574,11 @@
"proc table:scripts/gl_angle_ext.xml":
"bed6b56a38621721e689ebc19601a556",
"proc table:scripts/registry_xml.py":
"683a498150204f16c44264714e2bed07",
"24fa69f5641ed09c8e8a2f9c64fd0260",
"proc table:scripts/wgl.xml":
"aa96419c582af2f6673430e2847693f4",
"proc table:src/libGLESv2/proc_table_egl_autogen.cpp":
"6ab624dce9ebcdeaea091b27d98ed1ce",
"35653e6a70519374b768c7240081fbd1",
"proc table:src/openGL32/proc_table_wgl_autogen.cpp":
"cadecfe9956fc200c643b635b425c15a",
"uniform type:src/common/gen_uniform_type_table.py":
......
......@@ -8,6 +8,8 @@
#include "common/android_util.h"
#include <cstdint>
// Taken from cutils/native_handle.h:
// https://android.googlesource.com/platform/system/core/+/master/libcutils/include/cutils/native_handle.h
typedef struct native_handle
......@@ -163,6 +165,20 @@ enum {
namespace
{
// In the Android system:
// - AHardwareBuffer is essentially a typedef of GraphicBuffer. Conversion functions simply
// reinterpret_cast.
// - GraphicBuffer inherits from two base classes, ANativeWindowBuffer and RefBase.
//
// GraphicBuffer implements a getter for ANativeWindowBuffer (getNativeBuffer) by static_casting
// itself to its base class ANativeWindowBuffer. The offset of the ANativeWindowBuffer pointer
// from the GraphicBuffer pointer is 16 bytes. This is likely due to two pointers: The vtable of
// GraphicBuffer and the one pointer member of the RefBase class.
//
// This is not future proof at all. We need to look into getting utilities added to Android to
// perform this cast for us.
constexpr int kAHardwareBufferToANativeWindowBufferOffset = static_cast<int>(sizeof(void *)) * 2;
template <typename T1, typename T2>
T1 *offsetPointer(T2 *ptr, int bytes)
{
......@@ -177,12 +193,12 @@ namespace angle
namespace android
{
struct ANativeWindowBuffer *ClientBufferToANativeWindowBuffer(EGLClientBuffer clientBuffer)
ANativeWindowBuffer *ClientBufferToANativeWindowBuffer(EGLClientBuffer clientBuffer)
{
return reinterpret_cast<struct ANativeWindowBuffer *>(clientBuffer);
return reinterpret_cast<ANativeWindowBuffer *>(clientBuffer);
}
void GetANativeWindowBufferProperties(const struct ANativeWindowBuffer *buffer,
void GetANativeWindowBufferProperties(const ANativeWindowBuffer *buffer,
int *width,
int *height,
int *depth,
......@@ -236,23 +252,16 @@ GLenum NativePixelFormatToGLInternalFormat(int pixelFormat)
}
}
struct AHardwareBuffer *ANativeWindowBufferToAHardwareBuffer(
struct ANativeWindowBuffer *windowBuffer)
AHardwareBuffer *ANativeWindowBufferToAHardwareBuffer(ANativeWindowBuffer *windowBuffer)
{
return offsetPointer<AHardwareBuffer>(windowBuffer,
-kAHardwareBufferToANativeWindowBufferOffset);
}
EGLClientBuffer AHardwareBufferToClientBuffer(const AHardwareBuffer *hardwareBuffer)
{
// In the Android system:
// - AHardwareBuffer is essentially a typedef of GraphicBuffer. Conversion functions simply
// reinterpret_cast.
// - GraphicBuffer inherits from two base classes, ANativeWindowBuffer and RefBase.
//
// GraphicBuffer implements a getter for ANativeWindowBuffer (getNativeBuffer) by static_casting
// itself to its base class ANativeWindowBuffer. The offset of the ANativeWindowBuffer pointer
// from the GraphicBuffer pointer is 16 bytes. This is likely due to two pointers: The vtable of
// GraphicBuffer and the one pointer member of the RefBase class.
//
// This is not future proof at all. We need to look into getting utilities added to Android to
// perform this cast for us.
int offset = -(static_cast<int>(sizeof(void *)) * 2);
return offsetPointer<struct AHardwareBuffer>(windowBuffer, offset);
return offsetPointer<EGLClientBuffer>(hardwareBuffer,
kAHardwareBufferToANativeWindowBufferOffset);
}
} // namespace android
......
......@@ -21,17 +21,17 @@ namespace angle
namespace android
{
struct ANativeWindowBuffer *ClientBufferToANativeWindowBuffer(EGLClientBuffer clientBuffer);
ANativeWindowBuffer *ClientBufferToANativeWindowBuffer(EGLClientBuffer clientBuffer);
EGLClientBuffer AHardwareBufferToClientBuffer(const AHardwareBuffer *hardwareBuffer);
void GetANativeWindowBufferProperties(const struct ANativeWindowBuffer *buffer,
void GetANativeWindowBufferProperties(const ANativeWindowBuffer *buffer,
int *width,
int *height,
int *depth,
int *pixelFormat);
GLenum NativePixelFormatToGLInternalFormat(int pixelFormat);
struct AHardwareBuffer *ANativeWindowBufferToAHardwareBuffer(
struct ANativeWindowBuffer *windowBuffer);
AHardwareBuffer *ANativeWindowBufferToAHardwareBuffer(ANativeWindowBuffer *windowBuffer);
} // namespace android
} // namespace angle
......
......@@ -1482,6 +1482,7 @@ std::vector<std::string> DisplayExtensions::getStrings() const
InsertExtensionString("EGL_ANDROID_recordable", recordable, &extensionStrings);
InsertExtensionString("EGL_ANGLE_power_preference", powerPreference, &extensionStrings);
InsertExtensionString("EGL_ANGLE_image_d3d11_texture", imageD3D11Texture, &extensionStrings);
InsertExtensionString("EGL_ANDROID_get_native_client_buffer", getNativeClientBufferANDROID, &extensionStrings);
// TODO(jmadill): Enable this when complete.
//InsertExtensionString("KHR_create_context_no_error", createContextNoError, &extensionStrings);
// clang-format on
......
......@@ -896,6 +896,9 @@ struct DisplayExtensions
// EGL_ANGLE_image_d3d11_texture
bool imageD3D11Texture;
// EGL_ANDROID_get_native_client_buffer
bool getNativeClientBufferANDROID = false;
};
struct DeviceExtensions
......
......@@ -19,6 +19,7 @@
#include <EGL/eglext.h>
#include <platform/Platform.h>
#include "common/android_util.h"
#include "common/debug.h"
#include "common/mathutil.h"
#include "common/platform.h"
......@@ -1129,6 +1130,12 @@ void Display::setBlobCacheFuncs(EGLSetBlobFuncANDROID set, EGLGetBlobFuncANDROID
mImplementation->setBlobCacheFuncs(set, get);
}
// static
EGLClientBuffer Display::GetNativeClientBuffer(const AHardwareBuffer *buffer)
{
return angle::android::AHardwareBufferToClientBuffer(buffer);
}
Error Display::waitClient(const gl::Context *context)
{
return mImplementation->waitClient(context);
......
......@@ -165,6 +165,8 @@ class Display final : public LabeledObject, angle::NonCopyable
bool areBlobCacheFuncsSet() const { return mBlobCache.areBlobCacheFuncsSet(); }
BlobCache &getBlobCache() { return mBlobCache; }
static EGLClientBuffer GetNativeClientBuffer(const struct AHardwareBuffer *buffer);
Error waitClient(const gl::Context *context);
Error waitNative(const gl::Context *context, EGLint engine);
......
......@@ -146,6 +146,9 @@ void DisplayEGL::generateExtensions(egl::DisplayExtensions *outExtensions) const
outExtensions->waitSync =
eglVersion >= gl::Version(1, 5) || mEGL->hasExtension("EGL_KHR_wait_sync");
outExtensions->getNativeClientBufferANDROID =
mEGL->hasExtension("EGL_ANDROID_get_native_client_buffer");
DisplayGL::generateExtensions(outExtensions);
}
......
......@@ -3857,4 +3857,16 @@ Error ValidateQueryDisplayAttribANGLE(const Display *display, const EGLint attri
return NoError();
}
Error ValidateGetNativeClientBufferANDROID(const AHardwareBuffer *buffer)
{
// No extension check is done because no display is passed to eglGetNativeClientBufferANDROID
// despite it being a display extension. No display is needed for the implementation though.
if (buffer == nullptr)
{
return EglBadParameter() << "NULL buffer.";
}
return NoError();
}
} // namespace egl
......@@ -326,6 +326,9 @@ Error ValidateQueryStringiANGLE(const Display *display, EGLint name, EGLint inde
Error ValidateQueryDisplayAttribEXT(const Display *display, const EGLint attribute);
Error ValidateQueryDisplayAttribANGLE(const Display *display, const EGLint attribute);
// EGL_ANDROID_get_native_client_buffer
Error ValidateGetNativeClientBufferANDROID(const struct AHardwareBuffer *buffer);
} // namespace egl
#define ANGLE_EGL_TRY(THREAD, EXPR, FUNCNAME, LABELOBJECT) \
......
......@@ -60,6 +60,7 @@ PFNEGLGETCOMPOSITORTIMINGSUPPORTEDANDROIDPROC EGL_GetCompositorTimingSupportedAN
PFNEGLGETFRAMETIMESTAMPSUPPORTEDANDROIDPROC EGL_GetFrameTimestampSupportedANDROID;
PFNEGLGETFRAMETIMESTAMPSANDROIDPROC EGL_GetFrameTimestampsANDROID;
PFNEGLGETNEXTFRAMEIDANDROIDPROC EGL_GetNextFrameIdANDROID;
PFNEGLGETNATIVECLIENTBUFFERANDROIDPROC EGL_GetNativeClientBufferANDROID;
PFNEGLPRESENTATIONTIMEANDROIDPROC EGL_PresentationTimeANDROID;
PFNEGLCREATEDEVICEANGLEPROC EGL_CreateDeviceANGLE;
PFNEGLRELEASEDEVICEANGLEPROC EGL_ReleaseDeviceANGLE;
......@@ -175,6 +176,8 @@ void LoadEGL_EGL(LoadProc loadProc)
loadProc("EGL_GetFrameTimestampsANDROID"));
EGL_GetNextFrameIdANDROID =
reinterpret_cast<PFNEGLGETNEXTFRAMEIDANDROIDPROC>(loadProc("EGL_GetNextFrameIdANDROID"));
EGL_GetNativeClientBufferANDROID = reinterpret_cast<PFNEGLGETNATIVECLIENTBUFFERANDROIDPROC>(
loadProc("EGL_GetNativeClientBufferANDROID"));
EGL_PresentationTimeANDROID = reinterpret_cast<PFNEGLPRESENTATIONTIMEANDROIDPROC>(
loadProc("EGL_PresentationTimeANDROID"));
EGL_CreateDeviceANGLE =
......
......@@ -64,6 +64,7 @@ extern PFNEGLGETCOMPOSITORTIMINGSUPPORTEDANDROIDPROC EGL_GetCompositorTimingSupp
extern PFNEGLGETFRAMETIMESTAMPSUPPORTEDANDROIDPROC EGL_GetFrameTimestampSupportedANDROID;
extern PFNEGLGETFRAMETIMESTAMPSANDROIDPROC EGL_GetFrameTimestampsANDROID;
extern PFNEGLGETNEXTFRAMEIDANDROIDPROC EGL_GetNextFrameIdANDROID;
extern PFNEGLGETNATIVECLIENTBUFFERANDROIDPROC EGL_GetNativeClientBufferANDROID;
extern PFNEGLPRESENTATIONTIMEANDROIDPROC EGL_PresentationTimeANDROID;
extern PFNEGLCREATEDEVICEANGLEPROC EGL_CreateDeviceANGLE;
extern PFNEGLRELEASEDEVICEANGLEPROC EGL_ReleaseDeviceANGLE;
......
......@@ -693,4 +693,11 @@ const char *EGLAPIENTRY eglQueryStringiANGLE(EGLDisplay dpy, EGLint name, EGLint
EnsureEGLLoaded();
return EGL_QueryStringiANGLE(dpy, name, index);
}
EGLClientBuffer EGLAPIENTRY eglGetNativeClientBufferANDROID(const struct AHardwareBuffer *buffer)
{
EnsureEGLLoaded();
return EGL_GetNativeClientBufferANDROID(buffer);
}
} // extern "C"
......@@ -72,6 +72,7 @@ EXPORTS
eglSetBlobCacheFuncsANDROID @78
eglQueryDisplayAttribANGLE @79
eglQueryStringiANGLE @80
eglGetNativeClientBufferANDROID @81
; 1.5 entry points
eglCreateSync @38
......
......@@ -21,6 +21,8 @@ libangle_common_sources = [
"src/common/PoolAlloc.h",
"src/common/aligned_memory.cpp",
"src/common/aligned_memory.h",
"src/common/android_util.cpp",
"src/common/android_util.h",
"src/common/angleutils.cpp",
"src/common/angleutils.h",
"src/common/bitset_utils.h",
......@@ -88,13 +90,6 @@ if (is_win) {
angle_system_utils_sources += [ "src/common/system_utils_win.cpp" ]
}
if (is_android) {
angle_system_utils_sources += [
"src/common/android_util.cpp",
"src/common/android_util.h",
]
}
libangle_image_util_sources = [
"src/image_util/copyimage.cpp",
"src/image_util/copyimage.h",
......
......@@ -1440,4 +1440,18 @@ ANGLE_EXPORT const char *EGLAPIENTRY EGL_QueryStringiANGLE(EGLDisplay dpy,
return display->queryStringi(name, index);
}
EGLClientBuffer EGLAPIENTRY EGL_GetNativeClientBufferANDROID(const struct AHardwareBuffer *buffer)
{
ANGLE_SCOPED_GLOBAL_LOCK();
EVENT("(const struct AHardwareBuffer *buffer = 0x%016" PRIxPTR ")", (uintptr_t)buffer);
Thread *thread = egl::GetCurrentThread();
ANGLE_EGL_TRY_RETURN(thread, ValidateGetNativeClientBufferANDROID(buffer),
"eglGetNativeClientBufferANDROID", nullptr, nullptr);
thread->setSuccess();
return egl::Display::GetNativeClientBuffer(buffer);
}
} // extern "C"
......@@ -210,6 +210,10 @@ ANGLE_EXPORT const char *EGLAPIENTRY EGL_QueryStringiANGLE(EGLDisplay dpy,
EGLint name,
EGLint index);
// EGL_ANDROID_get_native_client_buffer
ANGLE_EXPORT EGLClientBuffer EGLAPIENTRY
EGL_GetNativeClientBufferANDROID(const struct AHardwareBuffer *buffer);
} // extern "C"
#endif // LIBGLESV2_ENTRYPOINTSEGLEXT_H_
......@@ -1489,6 +1489,9 @@ EXPORTS
EGL_GetFrameTimestampsANDROID
EGL_GetNextFrameIdANDROID
; EGL_ANDROID_get_native_client_buffer
EGL_GetNativeClientBufferANDROID
; EGL_ANDROID_presentation_time
EGL_PresentationTimeANDROID
......
......@@ -1489,6 +1489,9 @@ EXPORTS
EGL_GetFrameTimestampsANDROID
EGL_GetNextFrameIdANDROID
; EGL_ANDROID_get_native_client_buffer
EGL_GetNativeClientBufferANDROID
; EGL_ANDROID_presentation_time
EGL_PresentationTimeANDROID
......
......@@ -69,6 +69,7 @@ ProcEntry g_procTable[] = {
{"eglGetError", P(EGL_GetError)},
{"eglGetFrameTimestampSupportedANDROID", P(EGL_GetFrameTimestampSupportedANDROID)},
{"eglGetFrameTimestampsANDROID", P(EGL_GetFrameTimestampsANDROID)},
{"eglGetNativeClientBufferANDROID", P(EGL_GetNativeClientBufferANDROID)},
{"eglGetNextFrameIdANDROID", P(EGL_GetNextFrameIdANDROID)},
{"eglGetPlatformDisplay", P(EGL_GetPlatformDisplay)},
{"eglGetPlatformDisplayEXT", P(EGL_GetPlatformDisplayEXT)},
......@@ -1489,5 +1490,5 @@ ProcEntry g_procTable[] = {
{"glWeightPointerOES", P(gl::WeightPointerOES)},
{"glWeightPointerOESContextANGLE", P(gl::WeightPointerOESContextANGLE)}};
size_t g_numProcs = 1400;
size_t g_numProcs = 1401;
} // namespace egl
......@@ -69,6 +69,7 @@ ProcEntry g_procTable[] = {
{"eglGetError", P(EGL_GetError)},
{"eglGetFrameTimestampSupportedANDROID", P(EGL_GetFrameTimestampSupportedANDROID)},
{"eglGetFrameTimestampsANDROID", P(EGL_GetFrameTimestampsANDROID)},
{"eglGetNativeClientBufferANDROID", P(EGL_GetNativeClientBufferANDROID)},
{"eglGetNextFrameIdANDROID", P(EGL_GetNextFrameIdANDROID)},
{"eglGetPlatformDisplay", P(EGL_GetPlatformDisplay)},
{"eglGetPlatformDisplayEXT", P(EGL_GetPlatformDisplayEXT)},
......@@ -1489,5 +1490,5 @@ ProcEntry g_procTable[] = {
{"glWeightPointerOES", P(gl::WeightPointerOES)},
{"glWeightPointerOESContextANGLE", P(gl::WeightPointerOESContextANGLE)}};
size_t g_numProcs = 1400;
size_t g_numProcs = 1401;
} // namespace egl
......@@ -61,6 +61,7 @@ ANGLE_UTIL_EXPORT PFNEGLGETCOMPOSITORTIMINGSUPPORTEDANDROIDPROC
ANGLE_UTIL_EXPORT PFNEGLGETFRAMETIMESTAMPSUPPORTEDANDROIDPROC eglGetFrameTimestampSupportedANDROID;
ANGLE_UTIL_EXPORT PFNEGLGETFRAMETIMESTAMPSANDROIDPROC eglGetFrameTimestampsANDROID;
ANGLE_UTIL_EXPORT PFNEGLGETNEXTFRAMEIDANDROIDPROC eglGetNextFrameIdANDROID;
ANGLE_UTIL_EXPORT PFNEGLGETNATIVECLIENTBUFFERANDROIDPROC eglGetNativeClientBufferANDROID;
ANGLE_UTIL_EXPORT PFNEGLPRESENTATIONTIMEANDROIDPROC eglPresentationTimeANDROID;
ANGLE_UTIL_EXPORT PFNEGLCREATEDEVICEANGLEPROC eglCreateDeviceANGLE;
ANGLE_UTIL_EXPORT PFNEGLRELEASEDEVICEANGLEPROC eglReleaseDeviceANGLE;
......@@ -179,6 +180,8 @@ void LoadEGL(LoadProc loadProc)
loadProc("eglGetFrameTimestampsANDROID"));
eglGetNextFrameIdANDROID =
reinterpret_cast<PFNEGLGETNEXTFRAMEIDANDROIDPROC>(loadProc("eglGetNextFrameIdANDROID"));
eglGetNativeClientBufferANDROID = reinterpret_cast<PFNEGLGETNATIVECLIENTBUFFERANDROIDPROC>(
loadProc("eglGetNativeClientBufferANDROID"));
eglPresentationTimeANDROID =
reinterpret_cast<PFNEGLPRESENTATIONTIMEANDROIDPROC>(loadProc("eglPresentationTimeANDROID"));
eglCreateDeviceANGLE =
......
......@@ -68,6 +68,7 @@ ANGLE_UTIL_EXPORT extern PFNEGLGETFRAMETIMESTAMPSUPPORTEDANDROIDPROC
eglGetFrameTimestampSupportedANDROID;
ANGLE_UTIL_EXPORT extern PFNEGLGETFRAMETIMESTAMPSANDROIDPROC eglGetFrameTimestampsANDROID;
ANGLE_UTIL_EXPORT extern PFNEGLGETNEXTFRAMEIDANDROIDPROC eglGetNextFrameIdANDROID;
ANGLE_UTIL_EXPORT extern PFNEGLGETNATIVECLIENTBUFFERANDROIDPROC eglGetNativeClientBufferANDROID;
ANGLE_UTIL_EXPORT extern PFNEGLPRESENTATIONTIMEANDROIDPROC eglPresentationTimeANDROID;
ANGLE_UTIL_EXPORT extern PFNEGLCREATEDEVICEANGLEPROC eglCreateDeviceANGLE;
ANGLE_UTIL_EXPORT extern PFNEGLRELEASEDEVICEANGLEPROC eglReleaseDeviceANGLE;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment