Commit a6426d67 by Yuly Novikov Committed by Commit Bot

Android GL backend and end2end tests

Just the bare minimum implementation for end2end tests to run. BUG=angleproject:1362 TEST=angle_end2end_tests on Nexus 5X Change-Id: I92293e0f8bdc2ffaa5d4661927750d7cb3d931e6 Reviewed-on: https://chromium-review.googlesource.com/349353Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Yuly Novikov <ynovikov@chromium.org>
parent acccc6c9
......@@ -333,6 +333,16 @@ static_library("libANGLE") {
"QuartzCore.framework",
]
}
if (is_android) {
sources += rebase_path(gles_gypi.libangle_gl_egl_sources, ".", "src")
sources += rebase_path(gles_gypi.libangle_gl_egl_dl_sources, ".", "src")
sources +=
rebase_path(gles_gypi.libangle_gl_egl_android_sources, ".", "src")
libs += [
"android",
"log",
]
}
}
if (angle_enable_vulkan) {
......@@ -443,6 +453,17 @@ static_library("angle_util") {
sources += rebase_path(util_gypi.util_x11_sources, ".", "util")
}
if (is_android) {
# To prevent linux sources filtering on android
set_sources_assignment_filter([])
sources += rebase_path(util_gypi.util_linux_sources, ".", "util")
sources += rebase_path(util_gypi.util_android_sources, ".", "util")
libs = [
"android",
"log",
]
}
defines = [
"GL_GLEXT_PROTOTYPES",
"EGL_EGLEXT_PROTOTYPES",
......
......@@ -20,6 +20,8 @@ if (is_win) {
angle_enable_gl = true
} else if (is_mac) {
angle_enable_gl = true
} else if (is_android) {
angle_enable_gl = true
}
# TODO(gyp): Probably also want to angle_enable_gl = true if (use_ozone)
......
......@@ -40,6 +40,19 @@ bool AttributeMap::isEmpty() const
return mAttributes.empty();
}
std::vector<EGLint> AttributeMap::toIntVector() const
{
std::vector<EGLint> ret;
for (const auto &pair : mAttributes)
{
ret.push_back(pair.first);
ret.push_back(pair.second);
}
ret.push_back(EGL_NONE);
return ret;
}
AttributeMap::const_iterator AttributeMap::begin() const
{
return mAttributes.begin();
......
......@@ -11,6 +11,7 @@
#include <EGL/egl.h>
#include <map>
#include <vector>
namespace egl
{
......@@ -25,6 +26,7 @@ class AttributeMap final
EGLAttrib get(EGLAttrib key, EGLAttrib defaultValue) const;
EGLint getAsInt(EGLAttrib key, EGLint defaultValue) const;
bool isEmpty() const;
std::vector<EGLint> toIntVector() const;
typedef std::map<EGLAttrib, EGLAttrib>::const_iterator const_iterator;
......
......@@ -46,6 +46,8 @@
# include "libANGLE/renderer/gl/cgl/DisplayCGL.h"
# elif defined(ANGLE_USE_OZONE)
# include "libANGLE/renderer/gl/egl/ozone/DisplayOzone.h"
# elif defined(ANGLE_PLATFORM_ANDROID)
# include "libANGLE/renderer/gl/egl/android/DisplayAndroid.h"
# else
# error Unsupported OpenGL platform.
# endif
......@@ -150,6 +152,8 @@ rx::DisplayImpl *CreateDisplayFromAttribs(const AttributeMap &attribMap)
impl = new rx::DisplayCGL();
#elif defined(ANGLE_USE_OZONE)
impl = new rx::DisplayOzone();
#elif defined(ANGLE_PLATFORM_ANDROID)
impl = new rx::DisplayAndroid();
#else
// No display available
UNREACHABLE();
......@@ -177,6 +181,9 @@ rx::DisplayImpl *CreateDisplayFromAttribs(const AttributeMap &attribMap)
#elif defined(ANGLE_USE_OZONE)
// This might work but has never been tried, so disallow for now.
impl = nullptr;
#elif defined(ANGLE_PLATFORM_ANDROID)
// No GL support on this platform, fail display creation.
impl = nullptr;
#else
#error Unsupported OpenGL platform.
#endif
......@@ -188,16 +195,18 @@ rx::DisplayImpl *CreateDisplayFromAttribs(const AttributeMap &attribMap)
#if defined(ANGLE_ENABLE_OPENGL)
case EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE:
#if defined(ANGLE_PLATFORM_WINDOWS)
impl = new rx::DisplayWGL();
impl = new rx::DisplayWGL();
#elif defined(ANGLE_USE_X11)
impl = new rx::DisplayGLX();
impl = new rx::DisplayGLX();
#elif defined(ANGLE_USE_OZONE)
impl = new rx::DisplayOzone();
impl = new rx::DisplayOzone();
#elif defined(ANGLE_PLATFORM_ANDROID)
impl = new rx::DisplayAndroid();
#else
// No GLES support on this platform, fail display creation.
impl = nullptr;
// No GLES support on this platform, fail display creation.
impl = nullptr;
#endif
break;
break;
#endif
default:
......
......@@ -290,10 +290,13 @@ namespace rx
{
enum VendorID : uint32_t
{
VENDOR_ID_UNKNOWN = 0x0,
VENDOR_ID_AMD = 0x1002,
VENDOR_ID_INTEL = 0x8086,
VENDOR_ID_NVIDIA = 0x10DE,
VENDOR_ID_UNKNOWN = 0x0,
VENDOR_ID_AMD = 0x1002,
VENDOR_ID_INTEL = 0x8086,
VENDOR_ID_NVIDIA = 0x10DE,
// This is Qualcomm PCI Vendor ID.
// Android doesn't have a PCI bus, but all we need is a unique id.
VENDOR_ID_QUALCOMM = 0x5143,
};
// A macro that determines whether an object has a given runtime type.
......
//
// Copyright (c) 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// DisplayEGL.cpp: Common across EGL parts of platform specific egl::Display implementations
#include "libANGLE/renderer/gl/egl/DisplayEGL.h"
namespace rx
{
#define EGL_NO_CONFIG ((EGLConfig)0)
DisplayEGL::DisplayEGL()
: DisplayGL(),
mEGL(nullptr),
mConfig(EGL_NO_CONFIG),
mContext(EGL_NO_CONTEXT),
mFunctionsGL(nullptr)
{
}
DisplayEGL::~DisplayEGL()
{
}
std::string DisplayEGL::getVendorString() const
{
const char *vendor = mEGL->queryString(EGL_VENDOR);
ASSERT(vendor);
return vendor;
}
egl::Error DisplayEGL::initializeContext(const egl::AttributeMap &eglAttributes)
{
gl::Version eglVersion(mEGL->majorVersion, mEGL->minorVersion);
EGLint requestedMajor =
eglAttributes.getAsInt(EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE, EGL_DONT_CARE);
EGLint requestedMinor =
eglAttributes.getAsInt(EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE, EGL_DONT_CARE);
bool initializeRequested = requestedMajor != EGL_DONT_CARE && requestedMinor != EGL_DONT_CARE;
static_assert(EGL_CONTEXT_MAJOR_VERSION == EGL_CONTEXT_MAJOR_VERSION_KHR,
"Major Version define should match");
static_assert(EGL_CONTEXT_MINOR_VERSION == EGL_CONTEXT_MINOR_VERSION_KHR,
"Minor Version define should match");
std::vector<std::vector<EGLint>> contextAttribLists;
if (eglVersion >= gl::Version(1, 5) || mEGL->hasExtension("EGL_KHR_create_context"))
{
if (initializeRequested)
{
contextAttribLists.push_back({EGL_CONTEXT_MAJOR_VERSION, requestedMajor,
EGL_CONTEXT_MINOR_VERSION, requestedMinor, EGL_NONE});
}
else
{
// clang-format off
const gl::Version esVersionsFrom2_0[] = {
gl::Version(3, 2),
gl::Version(3, 1),
gl::Version(3, 0),
gl::Version(2, 0),
};
// clang-format on
for (const auto &version : esVersionsFrom2_0)
{
contextAttribLists.push_back(
{EGL_CONTEXT_MAJOR_VERSION, static_cast<EGLint>(version.major),
EGL_CONTEXT_MINOR_VERSION, static_cast<EGLint>(version.minor), EGL_NONE});
}
}
}
else
{
if (initializeRequested && (requestedMajor != 2 || requestedMinor != 0))
{
return egl::Error(EGL_BAD_ATTRIBUTE, "Unsupported requested context version");
}
contextAttribLists.push_back({EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE});
}
for (auto &attribList : contextAttribLists)
{
mContext = mEGL->createContext(mConfig, EGL_NO_CONTEXT, attribList.data());
if (mContext != EGL_NO_CONTEXT)
{
return egl::Error(EGL_SUCCESS);
}
}
return egl::Error(mEGL->getError(), "eglCreateContext failed");
}
void DisplayEGL::generateExtensions(egl::DisplayExtensions *outExtensions) const
{
outExtensions->createContextRobustness =
mEGL->hasExtension("EGL_EXT_create_context_robustness");
outExtensions->postSubBuffer = false; // Since SurfaceEGL::postSubBuffer is not implemented
}
void DisplayEGL::generateCaps(egl::Caps *outCaps) const
{
outCaps->textureNPOT = true; // Since we request GLES >= 2
}
const FunctionsGL *DisplayEGL::getFunctionsGL() const
{
return mFunctionsGL;
}
} // namespace rx
//
// Copyright (c) 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// DisplayEGL.h: Common across EGL parts of platform specific egl::Display implementations
#ifndef LIBANGLE_RENDERER_GL_EGL_DISPLAYEGL_H_
#define LIBANGLE_RENDERER_GL_EGL_DISPLAYEGL_H_
#include "libANGLE/renderer/gl/DisplayGL.h"
#include "libANGLE/renderer/gl/egl/FunctionsEGL.h"
namespace rx
{
class DisplayEGL : public DisplayGL
{
public:
DisplayEGL();
~DisplayEGL() override;
std::string getVendorString() const override;
protected:
egl::Error initializeContext(const egl::AttributeMap &eglAttributes);
FunctionsEGL *mEGL;
EGLConfig mConfig;
EGLContext mContext;
FunctionsGL *mFunctionsGL;
private:
void generateExtensions(egl::DisplayExtensions *outExtensions) const override;
void generateCaps(egl::Caps *outCaps) const override;
const FunctionsGL *getFunctionsGL() const override;
};
} // namespace rx
#endif /* LIBANGLE_RENDERER_GL_EGL_DISPLAYEGL_H_ */
......@@ -38,15 +38,24 @@ struct FunctionsEGL::EGLDispatchTable
: bindAPIPtr(nullptr),
chooseConfigPtr(nullptr),
createContextPtr(nullptr),
createPbufferSurfacePtr(nullptr),
createWindowSurfacePtr(nullptr),
destroyContextPtr(nullptr),
destroySurfacePtr(nullptr),
getConfigAttribPtr(nullptr),
getDisplayPtr(nullptr),
getErrorPtr(nullptr),
initializePtr(nullptr),
makeCurrentPtr(nullptr),
queryStringPtr(nullptr),
querySurfacePtr(nullptr),
swapBuffersPtr(nullptr),
terminatePtr(nullptr),
bindTexImagePtr(nullptr),
releaseTexImagePtr(nullptr),
swapIntervalPtr(nullptr),
createImageKHRPtr(nullptr),
destroyImageKHRPtr(nullptr),
......@@ -57,18 +66,29 @@ struct FunctionsEGL::EGLDispatchTable
{
}
// 1.0
PFNEGLBINDAPIPROC bindAPIPtr;
PFNEGLCHOOSECONFIGPROC chooseConfigPtr;
PFNEGLCREATECONTEXTPROC createContextPtr;
PFNEGLCREATEPBUFFERSURFACEPROC createPbufferSurfacePtr;
PFNEGLCREATEWINDOWSURFACEPROC createWindowSurfacePtr;
PFNEGLDESTROYCONTEXTPROC destroyContextPtr;
PFNEGLDESTROYSURFACEPROC destroySurfacePtr;
PFNEGLGETCONFIGATTRIBPROC getConfigAttribPtr;
PFNEGLGETDISPLAYPROC getDisplayPtr;
PFNEGLGETERRORPROC getErrorPtr;
PFNEGLINITIALIZEPROC initializePtr;
PFNEGLMAKECURRENTPROC makeCurrentPtr;
PFNEGLQUERYSTRINGPROC queryStringPtr;
PFNEGLQUERYSURFACEPROC querySurfacePtr;
PFNEGLSWAPBUFFERSPROC swapBuffersPtr;
PFNEGLTERMINATEPROC terminatePtr;
// 1.1
PFNEGLBINDTEXIMAGEPROC bindTexImagePtr;
PFNEGLRELEASETEXIMAGEPROC releaseTexImagePtr;
PFNEGLSWAPINTERVALPROC swapIntervalPtr;
// EGL_KHR_image
PFNEGLCREATEIMAGEKHRPROC createImageKHRPtr;
PFNEGLDESTROYIMAGEKHRPROC destroyImageKHRPtr;
......@@ -101,19 +121,28 @@ egl::Error FunctionsEGL::initialize(EGLNativeDisplayType nativeDisplay)
ANGLE_GET_PROC_OR_ERROR(&mFnPtrs->bindAPIPtr, eglBindAPI);
ANGLE_GET_PROC_OR_ERROR(&mFnPtrs->chooseConfigPtr, eglChooseConfig);
ANGLE_GET_PROC_OR_ERROR(&mFnPtrs->createContextPtr, eglCreateContext);
ANGLE_GET_PROC_OR_ERROR(&mFnPtrs->createPbufferSurfacePtr, eglCreatePbufferSurface);
ANGLE_GET_PROC_OR_ERROR(&mFnPtrs->createWindowSurfacePtr, eglCreateWindowSurface);
ANGLE_GET_PROC_OR_ERROR(&mFnPtrs->destroyContextPtr, eglDestroyContext);
ANGLE_GET_PROC_OR_ERROR(&mFnPtrs->destroySurfacePtr, eglDestroySurface);
ANGLE_GET_PROC_OR_ERROR(&mFnPtrs->getConfigAttribPtr, eglGetConfigAttrib);
ANGLE_GET_PROC_OR_ERROR(&mFnPtrs->getDisplayPtr, eglGetDisplay);
ANGLE_GET_PROC_OR_ERROR(&mFnPtrs->getErrorPtr, eglGetError);
ANGLE_GET_PROC_OR_ERROR(&mFnPtrs->initializePtr, eglInitialize);
ANGLE_GET_PROC_OR_ERROR(&mFnPtrs->makeCurrentPtr, eglMakeCurrent);
ANGLE_GET_PROC_OR_ERROR(&mFnPtrs->queryStringPtr, eglQueryString);
ANGLE_GET_PROC_OR_ERROR(&mFnPtrs->querySurfacePtr, eglQuerySurface);
ANGLE_GET_PROC_OR_ERROR(&mFnPtrs->swapBuffersPtr, eglSwapBuffers);
ANGLE_GET_PROC_OR_ERROR(&mFnPtrs->terminatePtr, eglTerminate);
ANGLE_GET_PROC_OR_ERROR(&mFnPtrs->bindTexImagePtr, eglBindTexImage);
ANGLE_GET_PROC_OR_ERROR(&mFnPtrs->releaseTexImagePtr, eglReleaseTexImage);
ANGLE_GET_PROC_OR_ERROR(&mFnPtrs->swapIntervalPtr, eglSwapInterval);
mEGLDisplay = mFnPtrs->getDisplayPtr(nativeDisplay);
if (mEGLDisplay == EGL_NO_DISPLAY)
{
return egl::Error(mFnPtrs->getErrorPtr(), "Failed to get system egl display");
return egl::Error(EGL_NOT_INITIALIZED, "Failed to get system egl display");
}
if (mFnPtrs->initializePtr(mEGLDisplay, &majorVersion, &minorVersion) != EGL_TRUE)
{
......@@ -194,15 +223,20 @@ EGLDisplay FunctionsEGL::getDisplay() const
return mEGLDisplay;
}
EGLint FunctionsEGL::getError() const
{
return mFnPtrs->getErrorPtr();
}
EGLBoolean FunctionsEGL::chooseConfig(EGLint const *attribList,
EGLConfig *configs,
EGLint configSize,
EGLint *numConfig)
EGLint *numConfig) const
{
return mFnPtrs->chooseConfigPtr(mEGLDisplay, attribList, configs, configSize, numConfig);
}
EGLBoolean FunctionsEGL::getConfigAttrib(EGLConfig config, EGLint attribute, EGLint *value)
EGLBoolean FunctionsEGL::getConfigAttrib(EGLConfig config, EGLint attribute, EGLint *value) const
{
return mFnPtrs->getConfigAttribPtr(mEGLDisplay, config, attribute, value);
}
......@@ -214,11 +248,28 @@ EGLContext FunctionsEGL::createContext(EGLConfig config,
return mFnPtrs->createContextPtr(mEGLDisplay, config, share_context, attrib_list);
}
EGLSurface FunctionsEGL::createPbufferSurface(EGLConfig config, const EGLint *attrib_list) const
{
return mFnPtrs->createPbufferSurfacePtr(mEGLDisplay, config, attrib_list);
}
EGLSurface FunctionsEGL::createWindowSurface(EGLConfig config,
EGLNativeWindowType win,
const EGLint *attrib_list) const
{
return mFnPtrs->createWindowSurfacePtr(mEGLDisplay, config, win, attrib_list);
}
EGLBoolean FunctionsEGL::destroyContext(EGLContext context) const
{
return mFnPtrs->destroyContextPtr(mEGLDisplay, context);
}
EGLBoolean FunctionsEGL::destroySurface(EGLSurface surface) const
{
return mFnPtrs->destroySurfacePtr(mEGLDisplay, surface);
}
EGLBoolean FunctionsEGL::makeCurrent(EGLSurface surface, EGLContext context) const
{
return mFnPtrs->makeCurrentPtr(mEGLDisplay, surface, surface, context);
......@@ -229,6 +280,31 @@ char const *FunctionsEGL::queryString(EGLint name) const
return mFnPtrs->queryStringPtr(mEGLDisplay, name);
}
EGLBoolean FunctionsEGL::querySurface(EGLSurface surface, EGLint attribute, EGLint *value) const
{
return mFnPtrs->querySurfacePtr(mEGLDisplay, surface, attribute, value);
}
EGLBoolean FunctionsEGL::swapBuffers(EGLSurface surface) const
{
return mFnPtrs->swapBuffersPtr(mEGLDisplay, surface);
}
EGLBoolean FunctionsEGL::bindTexImage(EGLSurface surface, EGLint buffer) const
{
return mFnPtrs->bindTexImagePtr(mEGLDisplay, surface, buffer);
}
EGLBoolean FunctionsEGL::releaseTexImage(EGLSurface surface, EGLint buffer) const
{
return mFnPtrs->releaseTexImagePtr(mEGLDisplay, surface, buffer);
}
EGLBoolean FunctionsEGL::swapInterval(EGLint interval) const
{
return mFnPtrs->swapIntervalPtr(mEGLDisplay, interval);
}
EGLImageKHR FunctionsEGL::createImageKHR(EGLContext context,
EGLenum target,
EGLClientBuffer buffer,
......
......@@ -31,26 +31,38 @@ class FunctionsEGL
int majorVersion;
int minorVersion;
virtual egl::Error initialize(EGLNativeDisplayType nativeDisplay);
virtual egl::Error terminate();
egl::Error initialize(EGLNativeDisplayType nativeDisplay);
egl::Error terminate();
virtual void *getProcAddress(const char *name) const = 0;
FunctionsGL *makeFunctionsGL() const;
bool hasExtension(const char *extension) const;
EGLDisplay getDisplay() const;
EGLint getError() const;
EGLBoolean chooseConfig(EGLint const *attrib_list,
EGLConfig *configs,
EGLint config_size,
EGLint *num_config);
EGLBoolean getConfigAttrib(EGLConfig config, EGLint attribute, EGLint *value);
EGLint *num_config) const;
EGLBoolean getConfigAttrib(EGLConfig config, EGLint attribute, EGLint *value) const;
EGLContext createContext(EGLConfig config,
EGLContext share_context,
EGLint const *attrib_list) const;
EGLSurface createPbufferSurface(EGLConfig config, const EGLint *attrib_list) const;
EGLSurface createWindowSurface(EGLConfig config,
EGLNativeWindowType win,
const EGLint *attrib_list) const;
EGLBoolean destroyContext(EGLContext context) const;
EGLBoolean destroySurface(EGLSurface surface) const;
EGLBoolean makeCurrent(EGLSurface surface, EGLContext context) const;
const char *queryString(EGLint name) const;
EGLBoolean querySurface(EGLSurface surface, EGLint attribute, EGLint *value) const;
EGLBoolean swapBuffers(EGLSurface surface) const;
EGLBoolean bindTexImage(EGLSurface surface, EGLint buffer) const;
EGLBoolean releaseTexImage(EGLSurface surface, EGLint buffer) const;
EGLBoolean swapInterval(EGLint interval) const;
EGLImageKHR createImageKHR(EGLContext context,
EGLenum target,
......
......@@ -32,7 +32,7 @@ DynamicLib::~DynamicLib()
// TODO(fjhenigman) File a bug and put a link here.
DynamicLib FunctionsEGLDL::sNativeLib;
FunctionsEGLDL::FunctionsEGLDL()
FunctionsEGLDL::FunctionsEGLDL() : mGetProcAddressPtr(nullptr)
{
}
......
......@@ -28,10 +28,10 @@ class FunctionsEGLDL : public FunctionsEGL
{
public:
FunctionsEGLDL();
virtual ~FunctionsEGLDL();
~FunctionsEGLDL() override;
egl::Error initialize(EGLNativeDisplayType nativeDisplay, const char *libName);
virtual void *getProcAddress(const char *name) const override;
void *getProcAddress(const char *name) const override;
private:
PFNEGLGETPROCADDRESSPROC mGetProcAddressPtr;
......
//
// Copyright (c) 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// PbufferSurfaceEGL.h: EGL implementation of egl::Surface for pbuffers
#include "libANGLE/renderer/gl/egl/PbufferSurfaceEGL.h"
namespace rx
{
PbufferSurfaceEGL::PbufferSurfaceEGL(const egl::SurfaceState &state,
const FunctionsEGL *egl,
EGLConfig config,
const std::vector<EGLint> &attribList,
EGLContext context,
RendererGL *renderer)
: SurfaceEGL(state, egl, config, attribList, context, renderer)
{
}
PbufferSurfaceEGL::~PbufferSurfaceEGL()
{
}
egl::Error PbufferSurfaceEGL::initialize()
{
mSurface = mEGL->createPbufferSurface(mConfig, mAttribList.data());
if (mSurface == EGL_NO_SURFACE)
{
return egl::Error(mEGL->getError(), "eglCreatePbufferSurface failed");
}
return egl::Error(EGL_SUCCESS);
}
} // namespace rx
//
// Copyright (c) 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// PbufferSurfaceEGL.h: EGL implementation of egl::Surface for pbuffers
#ifndef LIBANGLE_RENDERER_GL_EGL_PBUFFERSURFACEEGL_H_
#define LIBANGLE_RENDERER_GL_EGL_PBUFFERSURFACEEGL_H_
#include <vector>
#include <EGL/egl.h>
#include "libANGLE/renderer/gl/egl/SurfaceEGL.h"
namespace rx
{
class PbufferSurfaceEGL : public SurfaceEGL
{
public:
PbufferSurfaceEGL(const egl::SurfaceState &state,
const FunctionsEGL *egl,
EGLConfig config,
const std::vector<EGLint> &attribList,
EGLContext context,
RendererGL *renderer);
~PbufferSurfaceEGL() override;
egl::Error initialize() override;
};
} // namespace rx
#endif // LIBANGLE_RENDERER_GL_EGL_PBUFFERSURFACEEGL_H_
//
// Copyright (c) 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// SurfaceEGL.cpp: EGL implementation of egl::Surface
#include "libANGLE/renderer/gl/egl/SurfaceEGL.h"
#include "common/debug.h"
namespace rx
{
SurfaceEGL::SurfaceEGL(const egl::SurfaceState &state,
const FunctionsEGL *egl,
EGLConfig config,
const std::vector<EGLint> &attribList,
EGLContext context,
RendererGL *renderer)
: SurfaceGL(state, renderer),
mEGL(egl),
mConfig(config),
mAttribList(attribList),
mSurface(EGL_NO_SURFACE),
mContext(context)
{
}
SurfaceEGL::~SurfaceEGL()
{
if (mSurface != EGL_NO_SURFACE)
{
EGLBoolean success = mEGL->destroySurface(mSurface);
UNUSED_ASSERTION_VARIABLE(success);
ASSERT(success == EGL_TRUE);
}
}
egl::Error SurfaceEGL::makeCurrent()
{
EGLBoolean success = mEGL->makeCurrent(mSurface, mContext);
if (success == EGL_FALSE)
{
return egl::Error(mEGL->getError(), "eglMakeCurrent failed");
}
return egl::Error(EGL_SUCCESS);
}
egl::Error SurfaceEGL::swap()
{
EGLBoolean success = mEGL->swapBuffers(mSurface);
if (success == EGL_FALSE)
{
return egl::Error(mEGL->getError(), "eglSwapBuffers failed");
}
return egl::Error(EGL_SUCCESS);
}
egl::Error SurfaceEGL::postSubBuffer(EGLint x, EGLint y, EGLint width, EGLint height)
{
UNIMPLEMENTED();
return egl::Error(EGL_BAD_SURFACE);
}
egl::Error SurfaceEGL::querySurfacePointerANGLE(EGLint attribute, void **value)
{
UNIMPLEMENTED();
return egl::Error(EGL_BAD_SURFACE);
}
egl::Error SurfaceEGL::bindTexImage(gl::Texture *texture, EGLint buffer)
{
EGLBoolean success = mEGL->bindTexImage(mSurface, buffer);
if (success == EGL_FALSE)
{
return egl::Error(mEGL->getError(), "eglBindTexImage failed");
}
return egl::Error(EGL_SUCCESS);
}
egl::Error SurfaceEGL::releaseTexImage(EGLint buffer)
{
EGLBoolean success = mEGL->releaseTexImage(mSurface, buffer);
if (success == EGL_FALSE)
{
return egl::Error(mEGL->getError(), "eglReleaseTexImage failed");
}
return egl::Error(EGL_SUCCESS);
}
void SurfaceEGL::setSwapInterval(EGLint interval)
{
EGLBoolean success = mEGL->swapInterval(interval);
if (success == EGL_FALSE)
{
ERR("eglSwapInterval error 0x%04x", mEGL->getError());
ASSERT(false);
}
}
EGLint SurfaceEGL::getWidth() const
{
EGLint value;
EGLBoolean success = mEGL->querySurface(mSurface, EGL_WIDTH, &value);
UNUSED_ASSERTION_VARIABLE(success);
ASSERT(success == EGL_TRUE);
return value;
}
EGLint SurfaceEGL::getHeight() const
{
EGLint value;
EGLBoolean success = mEGL->querySurface(mSurface, EGL_HEIGHT, &value);
UNUSED_ASSERTION_VARIABLE(success);
ASSERT(success == EGL_TRUE);
return value;
}
EGLint SurfaceEGL::isPostSubBufferSupported() const
{
UNIMPLEMENTED();
return 0;
}
EGLint SurfaceEGL::getSwapBehavior() const
{
EGLint value;
EGLBoolean success = mEGL->querySurface(mSurface, EGL_SWAP_BEHAVIOR, &value);
UNUSED_ASSERTION_VARIABLE(success);
ASSERT(success == EGL_TRUE);
return value;
}
} // namespace rx
//
// Copyright (c) 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// SurfaceEGL.h: common interface for EGL surfaces
#ifndef LIBANGLE_RENDERER_GL_EGL_SURFACEEGL_H_
#define LIBANGLE_RENDERER_GL_EGL_SURFACEEGL_H_
#include <EGL/egl.h>
#include "libANGLE/renderer/gl/SurfaceGL.h"
#include "libANGLE/renderer/gl/egl/FunctionsEGL.h"
namespace rx
{
class SurfaceEGL : public SurfaceGL
{
public:
SurfaceEGL(const egl::SurfaceState &state,
const FunctionsEGL *egl,
EGLConfig config,
const std::vector<EGLint> &attribList,
EGLContext context,
RendererGL *renderer);
~SurfaceEGL() override;
egl::Error makeCurrent() override;
egl::Error swap() override;
egl::Error postSubBuffer(EGLint x, EGLint y, EGLint width, EGLint height) override;
egl::Error querySurfacePointerANGLE(EGLint attribute, void **value) override;
egl::Error bindTexImage(gl::Texture *texture, EGLint buffer) override;
egl::Error releaseTexImage(EGLint buffer) override;
void setSwapInterval(EGLint interval) override;
EGLint getWidth() const override;
EGLint getHeight() const override;
EGLint isPostSubBufferSupported() const override;
EGLint getSwapBehavior() const override;
protected:
const FunctionsEGL *mEGL;
EGLConfig mConfig;
std::vector<EGLint> mAttribList;
EGLSurface mSurface;
private:
EGLContext mContext;
};
} // namespace rx
#endif // LIBANGLE_RENDERER_GL_EGL_SURFACEEGL_H_
//
// Copyright (c) 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// WindowSurfaceEGL.h: EGL implementation of egl::Surface for windows
#include "libANGLE/renderer/gl/egl/WindowSurfaceEGL.h"
namespace rx
{
WindowSurfaceEGL::WindowSurfaceEGL(const egl::SurfaceState &state,
const FunctionsEGL *egl,
EGLConfig config,
EGLNativeWindowType window,
const std::vector<EGLint> &attribList,
EGLContext context,
RendererGL *renderer)
: SurfaceEGL(state, egl, config, attribList, context, renderer), mWindow(window)
{
}
WindowSurfaceEGL::~WindowSurfaceEGL()
{
}
egl::Error WindowSurfaceEGL::initialize()
{
mSurface = mEGL->createWindowSurface(mConfig, mWindow, mAttribList.data());
if (mSurface == EGL_NO_SURFACE)
{
return egl::Error(mEGL->getError(), "eglCreateWindowSurface failed");
}
return egl::Error(EGL_SUCCESS);
}
} // namespace rx
//
// Copyright (c) 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// WindowSurfaceEGL.h: EGL implementation of egl::Surface for windows
#ifndef LIBANGLE_RENDERER_GL_EGL_WINDOWSURFACEEGL_H_
#define LIBANGLE_RENDERER_GL_EGL_WINDOWSURFACEEGL_H_
#include "libANGLE/renderer/gl/egl/SurfaceEGL.h"
namespace rx
{
class WindowSurfaceEGL : public SurfaceEGL
{
public:
WindowSurfaceEGL(const egl::SurfaceState &state,
const FunctionsEGL *egl,
EGLConfig config,
EGLNativeWindowType window,
const std::vector<EGLint> &attribList,
EGLContext context,
RendererGL *renderer);
~WindowSurfaceEGL() override;
egl::Error initialize() override;
private:
EGLNativeWindowType mWindow;
};
} // namespace rx
#endif // LIBANGLE_RENDERER_GL_EGL_WINDOWSURFACEEGL_H_
//
// Copyright (c) 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// DisplayAndroid.cpp: Android implementation of egl::Display
#include <android/native_window.h>
#include "common/debug.h"
#include "libANGLE/Display.h"
#include "libANGLE/renderer/gl/renderergl_utils.h"
#include "libANGLE/renderer/gl/egl/android/DisplayAndroid.h"
#include "libANGLE/renderer/gl/egl/FunctionsEGLDL.h"
#include "libANGLE/renderer/gl/egl/PbufferSurfaceEGL.h"
#include "libANGLE/renderer/gl/egl/WindowSurfaceEGL.h"
namespace rx
{
DisplayAndroid::DisplayAndroid() : DisplayEGL(), mDummyPbuffer(EGL_NO_SURFACE)
{
}
DisplayAndroid::~DisplayAndroid()
{
}
egl::Error DisplayAndroid::initialize(egl::Display *display)
{
FunctionsEGLDL *egl = new FunctionsEGLDL();
mEGL = egl;
ANGLE_TRY(egl->initialize(display->getNativeDisplayId(), "libEGL.so"));
gl::Version eglVersion(mEGL->majorVersion, mEGL->minorVersion);
ASSERT(eglVersion >= gl::Version(1, 4));
static_assert(EGL_OPENGL_ES3_BIT == EGL_OPENGL_ES3_BIT_KHR, "Extension define must match core");
EGLint esBit = (eglVersion >= gl::Version(1, 5) || mEGL->hasExtension("EGL_KHR_create_context"))
? EGL_OPENGL_ES3_BIT
: EGL_OPENGL_ES2_BIT;
// clang-format off
mConfigAttribList =
{
// Choose RGBA8888
EGL_COLOR_BUFFER_TYPE, EGL_RGB_BUFFER,
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 8,
// EGL1.5 spec Section 2.2 says that depth, multisample and stencil buffer depths
// must match for contexts to be compatible.
EGL_DEPTH_SIZE, 24,
EGL_STENCIL_SIZE, 8,
EGL_SAMPLE_BUFFERS, 0,
// Android doesn't support pixmaps
EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT,
EGL_CONFIG_CAVEAT, EGL_NONE,
EGL_CONFORMANT, esBit,
EGL_RENDERABLE_TYPE, esBit,
EGL_NONE
};
// clang-format on
EGLint numConfig;
EGLBoolean success = mEGL->chooseConfig(mConfigAttribList.data(), &mConfig, 1, &numConfig);
if (success == EGL_FALSE)
{
return egl::Error(mEGL->getError(), "eglChooseConfig failed");
}
ANGLE_TRY(initializeContext(display->getAttributeMap()));
int dummyPbufferAttribs[] = {
EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE,
};
mDummyPbuffer = mEGL->createPbufferSurface(mConfig, dummyPbufferAttribs);
if (mDummyPbuffer == EGL_NO_SURFACE)
{
return egl::Error(mEGL->getError(), "eglCreatePbufferSurface failed");
}
success = mEGL->makeCurrent(mDummyPbuffer, mContext);
if (success == EGL_FALSE)
{
return egl::Error(mEGL->getError(), "eglMakeCurrent failed");
}
mFunctionsGL = mEGL->makeFunctionsGL();
mFunctionsGL->initialize();
return DisplayGL::initialize(display);
}
void DisplayAndroid::terminate()
{
DisplayGL::terminate();
EGLBoolean success = mEGL->makeCurrent(EGL_NO_SURFACE, EGL_NO_CONTEXT);
if (success == EGL_FALSE)
{
ERR("eglMakeCurrent error 0x%04x", mEGL->getError());
}
if (mDummyPbuffer != EGL_NO_SURFACE)
{
success = mEGL->destroySurface(mDummyPbuffer);
mDummyPbuffer = EGL_NO_SURFACE;
if (success == EGL_FALSE)
{
ERR("eglDestroySurface error 0x%04x", mEGL->getError());
}
}
if (mContext != EGL_NO_CONTEXT)
{
success = mEGL->destroyContext(mContext);
mContext = EGL_NO_CONTEXT;
if (success == EGL_FALSE)
{
ERR("eglDestroyContext error 0x%04x", mEGL->getError());
}
}
egl::Error result = mEGL->terminate();
if (result.isError())
{
ERR("eglTerminate error 0x%04x", result.getCode());
}
SafeDelete(mEGL);
SafeDelete(mFunctionsGL);
}
SurfaceImpl *DisplayAndroid::createWindowSurface(const egl::SurfaceState &state,
const egl::Config *configuration,
EGLNativeWindowType window,
const egl::AttributeMap &attribs)
{
EGLConfig config;
EGLint numConfig;
EGLBoolean success;
const EGLint configAttribList[] = {EGL_CONFIG_ID, mConfigIds[configuration->configID],
EGL_NONE};
success = mEGL->chooseConfig(configAttribList, &config, 1, &numConfig);
ASSERT(success && numConfig == 1);
return new WindowSurfaceEGL(state, mEGL, config, window, attribs.toIntVector(), mContext,
getRenderer());
}
SurfaceImpl *DisplayAndroid::createPbufferSurface(const egl::SurfaceState &state,
const egl::Config *configuration,
const egl::AttributeMap &attribs)
{
EGLConfig config;
EGLint numConfig;
EGLBoolean success;
const EGLint configAttribList[] = {EGL_CONFIG_ID, mConfigIds[configuration->configID],
EGL_NONE};
success = mEGL->chooseConfig(configAttribList, &config, 1, &numConfig);
ASSERT(success && numConfig == 1);
return new PbufferSurfaceEGL(state, mEGL, config, attribs.toIntVector(), mContext,
getRenderer());
}
SurfaceImpl *DisplayAndroid::createPbufferFromClientBuffer(const egl::SurfaceState &state,
const egl::Config *configuration,
EGLClientBuffer shareHandle,
const egl::AttributeMap &attribs)
{
UNIMPLEMENTED();
return nullptr;
}
SurfaceImpl *DisplayAndroid::createPixmapSurface(const egl::SurfaceState &state,
const egl::Config *configuration,
NativePixmapType nativePixmap,
const egl::AttributeMap &attribs)
{
UNIMPLEMENTED();
return nullptr;
}
ImageImpl *DisplayAndroid::createImage(EGLenum target,
egl::ImageSibling *buffer,
const egl::AttributeMap &attribs)
{
UNIMPLEMENTED();
return DisplayGL::createImage(target, buffer, attribs);
}
template <typename T>
void DisplayAndroid::getConfigAttrib(EGLConfig config, EGLint attribute, T *value) const
{
EGLint tmp;
EGLBoolean success = mEGL->getConfigAttrib(config, attribute, &tmp);
UNUSED_ASSERTION_VARIABLE(success);
ASSERT(success == EGL_TRUE);
*value = tmp;
}
egl::ConfigSet DisplayAndroid::generateConfigs()
{
egl::ConfigSet configSet;
mConfigIds.clear();
EGLint numConfigs;
EGLBoolean success = mEGL->chooseConfig(mConfigAttribList.data(), nullptr, 0, &numConfigs);
ASSERT(success == EGL_TRUE && numConfigs > 0);
std::vector<EGLConfig> configs(numConfigs);
EGLint numConfigs2;
success =
mEGL->chooseConfig(mConfigAttribList.data(), configs.data(), numConfigs, &numConfigs2);
ASSERT(success == EGL_TRUE && numConfigs2 == numConfigs);
for (int i = 0; i < numConfigs; i++)
{
egl::Config config;
getConfigAttrib(configs[i], EGL_BUFFER_SIZE, &config.bufferSize);
getConfigAttrib(configs[i], EGL_RED_SIZE, &config.redSize);
getConfigAttrib(configs[i], EGL_GREEN_SIZE, &config.greenSize);
getConfigAttrib(configs[i], EGL_BLUE_SIZE, &config.blueSize);
getConfigAttrib(configs[i], EGL_LUMINANCE_SIZE, &config.luminanceSize);
getConfigAttrib(configs[i], EGL_ALPHA_SIZE, &config.alphaSize);
getConfigAttrib(configs[i], EGL_ALPHA_MASK_SIZE, &config.alphaMaskSize);
getConfigAttrib(configs[i], EGL_BIND_TO_TEXTURE_RGB, &config.bindToTextureRGB);
getConfigAttrib(configs[i], EGL_BIND_TO_TEXTURE_RGBA, &config.bindToTextureRGBA);
getConfigAttrib(configs[i], EGL_COLOR_BUFFER_TYPE, &config.colorBufferType);
getConfigAttrib(configs[i], EGL_CONFIG_CAVEAT, &config.configCaveat);
getConfigAttrib(configs[i], EGL_CONFIG_ID, &config.configID);
getConfigAttrib(configs[i], EGL_CONFORMANT, &config.conformant);
getConfigAttrib(configs[i], EGL_DEPTH_SIZE, &config.depthSize);
getConfigAttrib(configs[i], EGL_LEVEL, &config.level);
getConfigAttrib(configs[i], EGL_MAX_PBUFFER_WIDTH, &config.maxPBufferWidth);
getConfigAttrib(configs[i], EGL_MAX_PBUFFER_HEIGHT, &config.maxPBufferHeight);
getConfigAttrib(configs[i], EGL_MAX_PBUFFER_PIXELS, &config.maxPBufferPixels);
getConfigAttrib(configs[i], EGL_MAX_SWAP_INTERVAL, &config.maxSwapInterval);
getConfigAttrib(configs[i], EGL_MIN_SWAP_INTERVAL, &config.minSwapInterval);
getConfigAttrib(configs[i], EGL_NATIVE_RENDERABLE, &config.nativeRenderable);
getConfigAttrib(configs[i], EGL_NATIVE_VISUAL_ID, &config.nativeVisualID);
getConfigAttrib(configs[i], EGL_NATIVE_VISUAL_TYPE, &config.nativeVisualType);
getConfigAttrib(configs[i], EGL_RENDERABLE_TYPE, &config.renderableType);
getConfigAttrib(configs[i], EGL_SAMPLE_BUFFERS, &config.sampleBuffers);
getConfigAttrib(configs[i], EGL_SAMPLES, &config.samples);
getConfigAttrib(configs[i], EGL_STENCIL_SIZE, &config.stencilSize);
getConfigAttrib(configs[i], EGL_SURFACE_TYPE, &config.surfaceType);
getConfigAttrib(configs[i], EGL_TRANSPARENT_TYPE, &config.transparentType);
getConfigAttrib(configs[i], EGL_TRANSPARENT_RED_VALUE, &config.transparentRedValue);
getConfigAttrib(configs[i], EGL_TRANSPARENT_GREEN_VALUE, &config.transparentGreenValue);
getConfigAttrib(configs[i], EGL_TRANSPARENT_BLUE_VALUE, &config.transparentBlueValue);
if (config.colorBufferType == EGL_RGB_BUFFER)
{
if (config.redSize == 8 && config.greenSize == 8 && config.blueSize == 8 &&
config.alphaSize == 8)
{
config.renderTargetFormat = GL_RGBA8;
}
else if (config.redSize == 8 && config.greenSize == 8 && config.blueSize == 8 &&
config.alphaSize == 0)
{
config.renderTargetFormat = GL_RGB8;
}
else if (config.redSize == 5 && config.greenSize == 6 && config.blueSize == 5 &&
config.alphaSize == 0)
{
config.renderTargetFormat = GL_RGB565;
}
else
{
UNREACHABLE();
}
}
else
{
UNREACHABLE();
}
if (config.depthSize == 0 && config.stencilSize == 0)
{
config.depthStencilFormat = GL_ZERO;
}
else if (config.depthSize == 16 && config.stencilSize == 0)
{
config.depthStencilFormat = GL_DEPTH_COMPONENT16;
}
else if (config.depthSize == 24 && config.stencilSize == 0)
{
config.depthStencilFormat = GL_DEPTH_COMPONENT24;
}
else if (config.depthSize == 24 && config.stencilSize == 8)
{
config.depthStencilFormat = GL_DEPTH24_STENCIL8;
}
else if (config.depthSize == 0 && config.stencilSize == 8)
{
config.depthStencilFormat = GL_STENCIL_INDEX8;
}
else
{
UNREACHABLE();
}
config.matchNativePixmap = EGL_NONE;
config.optimalOrientation = 0;
int internalId = configSet.add(config);
mConfigIds[internalId] = config.configID;
}
return configSet;
}
bool DisplayAndroid::isDeviceLost() const
{
return false;
}
bool DisplayAndroid::testDeviceLost()
{
return false;
}
egl::Error DisplayAndroid::restoreLostDevice()
{
UNIMPLEMENTED();
return egl::Error(EGL_SUCCESS);
}
bool DisplayAndroid::isValidNativeWindow(EGLNativeWindowType window) const
{
return ANativeWindow_getFormat(window) >= 0;
}
egl::Error DisplayAndroid::getDevice(DeviceImpl **device)
{
UNIMPLEMENTED();
return egl::Error(EGL_SUCCESS);
}
egl::Error DisplayAndroid::waitClient() const
{
UNIMPLEMENTED();
return egl::Error(EGL_SUCCESS);
}
egl::Error DisplayAndroid::waitNative(EGLint engine,
egl::Surface *drawSurface,
egl::Surface *readSurface) const
{
UNIMPLEMENTED();
return egl::Error(EGL_SUCCESS);
}
egl::Error DisplayAndroid::getDriverVersion(std::string *version) const
{
VendorID vendor = GetVendorID(mFunctionsGL);
switch (vendor)
{
case VENDOR_ID_QUALCOMM:
*version = reinterpret_cast<const char *>(mFunctionsGL->getString(GL_VERSION));
return egl::Error(EGL_SUCCESS);
default:
*version = "";
return egl::Error(EGL_SUCCESS);
}
}
} // namespace rx
//
// Copyright (c) 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// DisplayAndroid.h: Android implementation of egl::Display
#ifndef LIBANGLE_RENDERER_GL_EGL_ANDROID_DISPLAYANDROID_H_
#define LIBANGLE_RENDERER_GL_EGL_ANDROID_DISPLAYANDROID_H_
#include <map>
#include <string>
#include <vector>
#include "libANGLE/renderer/gl/egl/DisplayEGL.h"
namespace rx
{
class DisplayAndroid : public DisplayEGL
{
public:
DisplayAndroid();
~DisplayAndroid() override;
egl::Error initialize(egl::Display *display) override;
void terminate() override;
SurfaceImpl *createWindowSurface(const egl::SurfaceState &state,
const egl::Config *configuration,
EGLNativeWindowType window,
const egl::AttributeMap &attribs) override;
SurfaceImpl *createPbufferSurface(const egl::SurfaceState &state,
const egl::Config *configuration,
const egl::AttributeMap &attribs) override;
SurfaceImpl *createPbufferFromClientBuffer(const egl::SurfaceState &state,
const egl::Config *configuration,
EGLClientBuffer shareHandle,
const egl::AttributeMap &attribs) override;
SurfaceImpl *createPixmapSurface(const egl::SurfaceState &state,
const egl::Config *configuration,
NativePixmapType nativePixmap,
const egl::AttributeMap &attribs) override;
ImageImpl *createImage(EGLenum target,
egl::ImageSibling *buffer,
const egl::AttributeMap &attribs) override;
egl::ConfigSet generateConfigs() override;
bool isDeviceLost() const override;
bool testDeviceLost() override;
egl::Error restoreLostDevice() override;
bool isValidNativeWindow(EGLNativeWindowType window) const override;
egl::Error getDevice(DeviceImpl **device) override;
egl::Error waitClient() const override;
egl::Error waitNative(EGLint engine,
egl::Surface *drawSurface,
egl::Surface *readSurface) const override;
egl::Error getDriverVersion(std::string *version) const override;
private:
template <typename T>
void getConfigAttrib(EGLConfig config, EGLint attribute, T *value) const;
std::vector<EGLint> mConfigAttribList;
std::map<EGLint, EGLint> mConfigIds;
EGLSurface mDummyPbuffer;
};
} // namespace rx
#endif // LIBANGLE_RENDERER_GL_EGL_ANDROID_DISPLAYANDROID_H_
......@@ -26,6 +26,7 @@
#include "libANGLE/renderer/gl/FramebufferGL.h"
#include "libANGLE/renderer/gl/RendererGL.h"
#include "libANGLE/renderer/gl/StateManagerGL.h"
#include "libANGLE/renderer/gl/egl/FunctionsEGLDL.h"
#include "libANGLE/renderer/gl/egl/ozone/SurfaceOzone.h"
#include "platform/Platform.h"
......@@ -325,14 +326,11 @@ void DisplayOzone::Buffer::present()
}
DisplayOzone::DisplayOzone()
: mContextConfig(nullptr),
mContext(nullptr),
: DisplayEGL(),
mSwapControl(SwapControl::ABSENT),
mMinSwapInterval(0),
mMaxSwapInterval(0),
mCurrentSwapInterval(-1),
mEGL(nullptr),
mFunctionsGL(nullptr),
mGBM(nullptr),
mConnector(nullptr),
mMode(nullptr),
......@@ -446,12 +444,9 @@ egl::Error DisplayOzone::initialize(egl::Display *display)
// couldn't use LD_LIBRARY_PATH which is often useful during development. Instead we take
// advantage of the fact that the system lib is available under multiple names (for example
// with a .1 suffix) while Angle only installs libEGL.so.
mEGL = new FunctionsEGLDL();
egl::Error result = mEGL->initialize(display->getNativeDisplayId(), "libEGL.so.1");
if (result.isError())
{
return result;
}
FunctionsEGLDL *egl = new FunctionsEGLDL();
mEGL = egl;
ANGLE_TRY(egl->initialize(display->getNativeDisplayId(), "libEGL.so.1"));
const char *necessaryExtensions[] = {
"EGL_KHR_image_base", "EGL_EXT_image_dma_buf_import", "EGL_KHR_surfaceless_context",
......@@ -466,7 +461,7 @@ egl::Error DisplayOzone::initialize(egl::Display *display)
if (mEGL->hasExtension("EGL_MESA_configless_context"))
{
mContextConfig = EGL_NO_CONFIG_MESA;
mConfig = EGL_NO_CONFIG_MESA;
}
else
{
......@@ -489,14 +484,10 @@ egl::Error DisplayOzone::initialize(egl::Display *display)
{
return egl::Error(EGL_NOT_INITIALIZED, "Could not get EGL config.");
}
mContextConfig = config[0];
mConfig = config[0];
}
mContext = initializeContext(mContextConfig, display->getAttributeMap());
if (mContext == EGL_NO_CONTEXT)
{
return egl::Error(EGL_NOT_INITIALIZED, "Could not create GLES context.");
}
ANGLE_TRY(initializeContext(display->getAttributeMap()));
if (!mEGL->makeCurrent(EGL_NO_SURFACE, mContext))
{
......@@ -883,46 +874,6 @@ egl::Error DisplayOzone::getDevice(DeviceImpl **device)
return egl::Error(EGL_BAD_DISPLAY);
}
EGLContext DisplayOzone::initializeContext(EGLConfig config, const egl::AttributeMap &eglAttributes)
{
if (!(mEGL->majorVersion > 1 || mEGL->minorVersion > 4 ||
mEGL->hasExtension("EGL_KHR_create_context")))
{
const EGLint attrib[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
return mEGL->createContext(config, EGL_NO_CONTEXT, attrib);
}
std::vector<gl::Version> versions;
EGLint major = eglAttributes.get(EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE, EGL_DONT_CARE);
EGLint minor = eglAttributes.get(EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE, EGL_DONT_CARE);
if (major != EGL_DONT_CARE && minor != EGL_DONT_CARE)
{
// If specific version requested, only try that one.
versions.push_back(gl::Version(major, minor));
}
else
{
// Acceptable versions, from most to least preferred.
versions.push_back(gl::Version(3, 0));
versions.push_back(gl::Version(2, 0));
}
for (auto &version : versions)
{
const EGLint attrib[] = {EGL_CONTEXT_MAJOR_VERSION_KHR, UnsignedToSigned(version.major),
EGL_CONTEXT_MINOR_VERSION_KHR, UnsignedToSigned(version.minor),
EGL_NONE};
auto context = mEGL->createContext(config, EGL_NO_CONTEXT, attrib);
if (context != EGL_NO_CONTEXT)
{
return context;
}
}
return EGL_NO_CONTEXT;
}
egl::ConfigSet DisplayOzone::generateConfigs()
{
egl::ConfigSet configs;
......@@ -963,11 +914,6 @@ bool DisplayOzone::isValidNativeWindow(EGLNativeWindowType window) const
return true;
}
std::string DisplayOzone::getVendorString() const
{
return "";
}
egl::Error DisplayOzone::getDriverVersion(std::string *version) const
{
*version = "";
......@@ -993,18 +939,4 @@ void DisplayOzone::setSwapInterval(EGLSurface drawable, SwapControlData *data)
ASSERT(data != nullptr);
}
const FunctionsGL *DisplayOzone::getFunctionsGL() const
{
return mFunctionsGL;
}
void DisplayOzone::generateExtensions(egl::DisplayExtensions *outExtensions) const
{
}
void DisplayOzone::generateCaps(egl::Caps *outCaps) const
{
outCaps->textureNPOT = true;
}
} // namespace rx
......@@ -14,12 +14,16 @@
#include <string>
#include "libANGLE/renderer/gl/DisplayGL.h"
#include "libANGLE/renderer/gl/egl/FunctionsEGLDL.h"
#include "libANGLE/renderer/gl/egl/DisplayEGL.h"
struct gbm_device;
struct gbm_bo;
namespace gl
{
class FramebufferState;
}
namespace rx
{
......@@ -40,7 +44,7 @@ struct SwapControlData final
int currentSwapInterval;
};
class DisplayOzone final : public DisplayGL
class DisplayOzone final : public DisplayEGL
{
public:
struct NativeWindow
......@@ -135,8 +139,6 @@ class DisplayOzone final : public DisplayGL
egl::Error getDevice(DeviceImpl **device) override;
std::string getVendorString() const override;
egl::Error waitClient() const override;
egl::Error waitNative(EGLint engine,
egl::Surface *drawSurface,
......@@ -151,13 +153,6 @@ class DisplayOzone final : public DisplayGL
egl::Error getDriverVersion(std::string *version) const override;
private:
const FunctionsGL *getFunctionsGL() const override;
EGLContext initializeContext(EGLConfig config, const egl::AttributeMap &eglAttributes);
void generateExtensions(egl::DisplayExtensions *outExtensions) const override;
void generateCaps(egl::Caps *outCaps) const override;
GLuint makeShader(GLuint type, const char *src);
void drawBuffer(Buffer *buffer);
void drawWithBlit(Buffer *buffer);
......@@ -171,9 +166,6 @@ class DisplayOzone final : public DisplayGL
void *data);
void pageFlipHandler(unsigned int sequence, uint64_t tv);
EGLConfig mContextConfig;
EGLContext mContext;
// TODO(fjhenigman) Implement swap control. The following stuff will be used for that.
enum class SwapControl
{
......@@ -187,9 +179,6 @@ class DisplayOzone final : public DisplayGL
int mMaxSwapInterval;
int mCurrentSwapInterval;
FunctionsEGLDL *mEGL;
FunctionsGL *mFunctionsGL;
gbm_device *mGBM;
drmModeConnectorPtr mConnector;
drmModeModeInfoPtr mMode;
......
......@@ -38,6 +38,10 @@ VendorID GetVendorID(const FunctionsGL *functions)
{
return VENDOR_ID_AMD;
}
else if (nativeVendorString.find("Qualcomm") != std::string::npos)
{
return VENDOR_ID_QUALCOMM;
}
else
{
return VENDOR_ID_UNKNOWN;
......
......@@ -513,9 +513,17 @@
],
'libangle_gl_egl_sources':
[
'libANGLE/renderer/gl/egl/DisplayEGL.cpp',
'libANGLE/renderer/gl/egl/DisplayEGL.h',
'libANGLE/renderer/gl/egl/FunctionsEGL.cpp',
'libANGLE/renderer/gl/egl/FunctionsEGL.h',
'libANGLE/renderer/gl/egl/functionsegl_typedefs.h',
'libANGLE/renderer/gl/egl/PbufferSurfaceEGL.cpp',
'libANGLE/renderer/gl/egl/PbufferSurfaceEGL.h',
'libANGLE/renderer/gl/egl/SurfaceEGL.cpp',
'libANGLE/renderer/gl/egl/SurfaceEGL.h',
'libANGLE/renderer/gl/egl/WindowSurfaceEGL.cpp',
'libANGLE/renderer/gl/egl/WindowSurfaceEGL.h',
],
'libangle_gl_egl_dl_sources':
[
......@@ -529,6 +537,11 @@
'libANGLE/renderer/gl/egl/ozone/SurfaceOzone.cpp',
'libANGLE/renderer/gl/egl/ozone/SurfaceOzone.h',
],
'libangle_gl_egl_android_sources':
[
'libANGLE/renderer/gl/egl/android/DisplayAndroid.cpp',
'libANGLE/renderer/gl/egl/android/DisplayAndroid.h',
],
'libangle_gl_cgl_sources':
[
'libANGLE/renderer/gl/cgl/DisplayCGL.mm',
......
......@@ -40,7 +40,7 @@ test("angle_unittests") {
]
}
if (is_win || is_linux || is_mac) {
if (is_win || is_linux || is_mac || is_android) {
end2end_gypi = exec_script("//build/gypi_to_gn.py",
[
rebase_path("angle_end2end_tests.gypi"),
......@@ -56,6 +56,10 @@ if (is_win || is_linux || is_mac) {
"../../util",
]
if (is_android) {
use_native_activity = true
}
sources =
rebase_path(end2end_gypi.angle_end2end_tests_sources, ".", "../..")
......
//
// Copyright (c) 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// AndroidWindow.cpp: Implementation of OSWindow for Android
#include "android/AndroidWindow.h"
#include <pthread.h>
#include "android/third_party/android_native_app_glue.h"
#include "common/debug.h"
namespace
{
struct android_app *sApp = nullptr;
pthread_mutex_t sInitWindowMutex;
pthread_cond_t sInitWindowCond;
bool sInitWindowDone = false;
} // namespace
AndroidWindow::AndroidWindow()
{
}
AndroidWindow::~AndroidWindow()
{
}
bool AndroidWindow::initialize(const std::string &name, size_t width, size_t height)
{
return resize(width, height);
}
void AndroidWindow::destroy()
{
}
EGLNativeWindowType AndroidWindow::getNativeWindow() const
{
// Return the entire Activity Surface for now
// sApp->window is valid only after sInitWindowDone, which is true after initialize()
return sApp->window;
}
EGLNativeDisplayType AndroidWindow::getNativeDisplay() const
{
return EGL_DEFAULT_DISPLAY;
}
void AndroidWindow::messageLoop()
{
// TODO: accumulate events in the real message loop of android_main,
// and process them here
}
void AndroidWindow::setMousePosition(int x, int y)
{
UNIMPLEMENTED();
}
bool AndroidWindow::setPosition(int x, int y)
{
UNIMPLEMENTED();
return false;
}
bool AndroidWindow::resize(int width, int height)
{
mWidth = width;
mHeight = height;
// sApp->window used below is valid only after Activity Surface is created
pthread_mutex_lock(&sInitWindowMutex);
while (!sInitWindowDone)
{
pthread_cond_wait(&sInitWindowCond, &sInitWindowMutex);
}
pthread_mutex_unlock(&sInitWindowMutex);
// TODO: figure out a way to set the format as well,
// which is available only after EGLWindow initialization
int32_t err = ANativeWindow_setBuffersGeometry(sApp->window, mWidth, mHeight, 0);
return err == 0;
}
void AndroidWindow::setVisible(bool isVisible)
{
}
void AndroidWindow::signalTestEvent()
{
UNIMPLEMENTED();
}
OSWindow *CreateOSWindow()
{
// There should be only one live instance of AndroidWindow at a time,
// as there is only one Activity Surface behind it.
// Creating a new AndroidWindow each time works for ANGLETest,
// as it destroys an old window before creating a new one.
// TODO: use GLSurfaceView to support multiple windows
return new AndroidWindow();
}
static void onAppCmd(struct android_app *app, int32_t cmd)
{
switch (cmd)
{
case APP_CMD_INIT_WINDOW:
pthread_mutex_lock(&sInitWindowMutex);
sInitWindowDone = true;
pthread_cond_broadcast(&sInitWindowCond);
pthread_mutex_unlock(&sInitWindowMutex);
break;
// TODO: process other commands and pass them to AndroidWindow for handling
// TODO: figure out how to handle APP_CMD_PAUSE,
// which should immediately halt all the rendering,
// since Activity Surface is no longer available.
// Currently tests crash when paused, for example, due to device changing orientation
}
}
static int32_t onInputEvent(struct android_app *app, AInputEvent *event)
{
// TODO: Handle input events
return 0; // 0 == not handled
}
void android_main(struct android_app *app)
{
int events;
struct android_poll_source *source;
sApp = app;
pthread_mutex_init(&sInitWindowMutex, nullptr);
pthread_cond_init(&sInitWindowCond, nullptr);
// Event handlers, invoked from source->process()
app->onAppCmd = onAppCmd;
app->onInputEvent = onInputEvent;
// Message loop, polling for events indefinitely (due to -1 timeout)
// Must be here in order to handle APP_CMD_INIT_WINDOW event,
// which occurs after AndroidWindow::initialize(), but before AndroidWindow::messageLoop
while (ALooper_pollAll(-1, nullptr, &events, reinterpret_cast<void **>(&source)) >= 0)
{
if (source != nullptr)
{
source->process(app, source);
}
}
}
//
// Copyright (c) 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// AndroidWindow.h: Definition of the implementation of OSWindow for Android
#ifndef UTIL_ANDROID_WINDOW_H_
#define UTIL_ANDROID_WINDOW_H_
#include "OSWindow.h"
class AndroidWindow : public OSWindow
{
public:
AndroidWindow();
~AndroidWindow() override;
bool initialize(const std::string &name, size_t width, size_t height) override;
void destroy() override;
EGLNativeWindowType getNativeWindow() const override;
EGLNativeDisplayType getNativeDisplay() const override;
void messageLoop() override;
void setMousePosition(int x, int y) override;
bool setPosition(int x, int y) override;
bool resize(int width, int height) override;
void setVisible(bool isVisible) override;
void signalTestEvent() override;
};
#endif /* UTIL_ANDROID_WINDOW_H_ */
Name: android_native_app_glue
URL: https://android.googlesource.com/platform/ndk/+/65966d5033af36134135d1308bdc62b216a5a414/sources/android/native_app_glue
Version: 65966d5033af36134135d1308bdc62b216a5a414
License: Apache License, Version 2.0
License File: http://www.apache.org/licenses/LICENSE-2.0
Description:
Helper glue code for ANativeActivity implementations
\ No newline at end of file
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include <jni.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/resource.h>
#include "android_native_app_glue.h"
#include <android/log.h>
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "threaded_app", __VA_ARGS__))
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, "threaded_app", __VA_ARGS__))
/* For debug builds, always enable the debug traces in this library */
#ifndef NDEBUG
# define LOGV(...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, "threaded_app", __VA_ARGS__))
#else
# define LOGV(...) ((void)0)
#endif
static void free_saved_state(struct android_app* android_app) {
pthread_mutex_lock(&android_app->mutex);
if (android_app->savedState != NULL) {
free(android_app->savedState);
android_app->savedState = NULL;
android_app->savedStateSize = 0;
}
pthread_mutex_unlock(&android_app->mutex);
}
int8_t android_app_read_cmd(struct android_app* android_app) {
int8_t cmd;
if (read(android_app->msgread, &cmd, sizeof(cmd)) == sizeof(cmd)) {
switch (cmd) {
case APP_CMD_SAVE_STATE:
free_saved_state(android_app);
break;
}
return cmd;
} else {
LOGE("No data on command pipe!");
}
return -1;
}
static void print_cur_config(struct android_app* android_app) {
char lang[2], country[2];
AConfiguration_getLanguage(android_app->config, lang);
AConfiguration_getCountry(android_app->config, country);
LOGV("Config: mcc=%d mnc=%d lang=%c%c cnt=%c%c orien=%d touch=%d dens=%d "
"keys=%d nav=%d keysHid=%d navHid=%d sdk=%d size=%d long=%d "
"modetype=%d modenight=%d",
AConfiguration_getMcc(android_app->config),
AConfiguration_getMnc(android_app->config),
lang[0], lang[1], country[0], country[1],
AConfiguration_getOrientation(android_app->config),
AConfiguration_getTouchscreen(android_app->config),
AConfiguration_getDensity(android_app->config),
AConfiguration_getKeyboard(android_app->config),
AConfiguration_getNavigation(android_app->config),
AConfiguration_getKeysHidden(android_app->config),
AConfiguration_getNavHidden(android_app->config),
AConfiguration_getSdkVersion(android_app->config),
AConfiguration_getScreenSize(android_app->config),
AConfiguration_getScreenLong(android_app->config),
AConfiguration_getUiModeType(android_app->config),
AConfiguration_getUiModeNight(android_app->config));
}
void android_app_pre_exec_cmd(struct android_app* android_app, int8_t cmd) {
switch (cmd) {
case APP_CMD_INPUT_CHANGED:
LOGV("APP_CMD_INPUT_CHANGED\n");
pthread_mutex_lock(&android_app->mutex);
if (android_app->inputQueue != NULL) {
AInputQueue_detachLooper(android_app->inputQueue);
}
android_app->inputQueue = android_app->pendingInputQueue;
if (android_app->inputQueue != NULL) {
LOGV("Attaching input queue to looper");
AInputQueue_attachLooper(android_app->inputQueue,
android_app->looper, LOOPER_ID_INPUT, NULL,
&android_app->inputPollSource);
}
pthread_cond_broadcast(&android_app->cond);
pthread_mutex_unlock(&android_app->mutex);
break;
case APP_CMD_INIT_WINDOW:
LOGV("APP_CMD_INIT_WINDOW\n");
pthread_mutex_lock(&android_app->mutex);
android_app->window = android_app->pendingWindow;
pthread_cond_broadcast(&android_app->cond);
pthread_mutex_unlock(&android_app->mutex);
break;
case APP_CMD_TERM_WINDOW:
LOGV("APP_CMD_TERM_WINDOW\n");
pthread_cond_broadcast(&android_app->cond);
break;
case APP_CMD_RESUME:
case APP_CMD_START:
case APP_CMD_PAUSE:
case APP_CMD_STOP:
LOGV("activityState=%d\n", cmd);
pthread_mutex_lock(&android_app->mutex);
android_app->activityState = cmd;
pthread_cond_broadcast(&android_app->cond);
pthread_mutex_unlock(&android_app->mutex);
break;
case APP_CMD_CONFIG_CHANGED:
LOGV("APP_CMD_CONFIG_CHANGED\n");
AConfiguration_fromAssetManager(android_app->config,
android_app->activity->assetManager);
print_cur_config(android_app);
break;
case APP_CMD_DESTROY:
LOGV("APP_CMD_DESTROY\n");
android_app->destroyRequested = 1;
break;
}
}
void android_app_post_exec_cmd(struct android_app* android_app, int8_t cmd) {
switch (cmd) {
case APP_CMD_TERM_WINDOW:
LOGV("APP_CMD_TERM_WINDOW\n");
pthread_mutex_lock(&android_app->mutex);
android_app->window = NULL;
pthread_cond_broadcast(&android_app->cond);
pthread_mutex_unlock(&android_app->mutex);
break;
case APP_CMD_SAVE_STATE:
LOGV("APP_CMD_SAVE_STATE\n");
pthread_mutex_lock(&android_app->mutex);
android_app->stateSaved = 1;
pthread_cond_broadcast(&android_app->cond);
pthread_mutex_unlock(&android_app->mutex);
break;
case APP_CMD_RESUME:
free_saved_state(android_app);
break;
}
}
void app_dummy() {
}
static void android_app_destroy(struct android_app* android_app) {
LOGV("android_app_destroy!");
free_saved_state(android_app);
pthread_mutex_lock(&android_app->mutex);
if (android_app->inputQueue != NULL) {
AInputQueue_detachLooper(android_app->inputQueue);
}
AConfiguration_delete(android_app->config);
android_app->destroyed = 1;
pthread_cond_broadcast(&android_app->cond);
pthread_mutex_unlock(&android_app->mutex);
// Can't touch android_app object after this.
}
static void process_input(struct android_app* app, struct android_poll_source* source) {
AInputEvent* event = NULL;
while (AInputQueue_getEvent(app->inputQueue, &event) >= 0) {
LOGV("New input event: type=%d\n", AInputEvent_getType(event));
if (AInputQueue_preDispatchEvent(app->inputQueue, event)) {
continue;
}
int32_t handled = 0;
if (app->onInputEvent != NULL) handled = app->onInputEvent(app, event);
AInputQueue_finishEvent(app->inputQueue, event, handled);
}
}
static void process_cmd(struct android_app* app, struct android_poll_source* source) {
int8_t cmd = android_app_read_cmd(app);
android_app_pre_exec_cmd(app, cmd);
if (app->onAppCmd != NULL) app->onAppCmd(app, cmd);
android_app_post_exec_cmd(app, cmd);
}
static void* android_app_entry(void* param) {
struct android_app* android_app = (struct android_app*)param;
android_app->config = AConfiguration_new();
AConfiguration_fromAssetManager(android_app->config, android_app->activity->assetManager);
print_cur_config(android_app);
android_app->cmdPollSource.id = LOOPER_ID_MAIN;
android_app->cmdPollSource.app = android_app;
android_app->cmdPollSource.process = process_cmd;
android_app->inputPollSource.id = LOOPER_ID_INPUT;
android_app->inputPollSource.app = android_app;
android_app->inputPollSource.process = process_input;
ALooper* looper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS);
ALooper_addFd(looper, android_app->msgread, LOOPER_ID_MAIN, ALOOPER_EVENT_INPUT, NULL,
&android_app->cmdPollSource);
android_app->looper = looper;
pthread_mutex_lock(&android_app->mutex);
android_app->running = 1;
pthread_cond_broadcast(&android_app->cond);
pthread_mutex_unlock(&android_app->mutex);
android_main(android_app);
android_app_destroy(android_app);
return NULL;
}
// --------------------------------------------------------------------
// Native activity interaction (called from main thread)
// --------------------------------------------------------------------
static struct android_app* android_app_create(ANativeActivity* activity,
void* savedState, size_t savedStateSize) {
struct android_app* android_app = (struct android_app*)malloc(sizeof(struct android_app));
memset(android_app, 0, sizeof(struct android_app));
android_app->activity = activity;
pthread_mutex_init(&android_app->mutex, NULL);
pthread_cond_init(&android_app->cond, NULL);
if (savedState != NULL) {
android_app->savedState = malloc(savedStateSize);
android_app->savedStateSize = savedStateSize;
memcpy(android_app->savedState, savedState, savedStateSize);
}
int msgpipe[2];
if (pipe(msgpipe)) {
LOGE("could not create pipe: %s", strerror(errno));
return NULL;
}
android_app->msgread = msgpipe[0];
android_app->msgwrite = msgpipe[1];
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
pthread_create(&android_app->thread, &attr, android_app_entry, android_app);
// Wait for thread to start.
pthread_mutex_lock(&android_app->mutex);
while (!android_app->running) {
pthread_cond_wait(&android_app->cond, &android_app->mutex);
}
pthread_mutex_unlock(&android_app->mutex);
return android_app;
}
static void android_app_write_cmd(struct android_app* android_app, int8_t cmd) {
if (write(android_app->msgwrite, &cmd, sizeof(cmd)) != sizeof(cmd)) {
LOGE("Failure writing android_app cmd: %s\n", strerror(errno));
}
}
static void android_app_set_input(struct android_app* android_app, AInputQueue* inputQueue) {
pthread_mutex_lock(&android_app->mutex);
android_app->pendingInputQueue = inputQueue;
android_app_write_cmd(android_app, APP_CMD_INPUT_CHANGED);
while (android_app->inputQueue != android_app->pendingInputQueue) {
pthread_cond_wait(&android_app->cond, &android_app->mutex);
}
pthread_mutex_unlock(&android_app->mutex);
}
static void android_app_set_window(struct android_app* android_app, ANativeWindow* window) {
pthread_mutex_lock(&android_app->mutex);
if (android_app->pendingWindow != NULL) {
android_app_write_cmd(android_app, APP_CMD_TERM_WINDOW);
}
android_app->pendingWindow = window;
if (window != NULL) {
android_app_write_cmd(android_app, APP_CMD_INIT_WINDOW);
}
while (android_app->window != android_app->pendingWindow) {
pthread_cond_wait(&android_app->cond, &android_app->mutex);
}
pthread_mutex_unlock(&android_app->mutex);
}
static void android_app_set_activity_state(struct android_app* android_app, int8_t cmd) {
pthread_mutex_lock(&android_app->mutex);
android_app_write_cmd(android_app, cmd);
while (android_app->activityState != cmd) {
pthread_cond_wait(&android_app->cond, &android_app->mutex);
}
pthread_mutex_unlock(&android_app->mutex);
}
static void android_app_free(struct android_app* android_app) {
pthread_mutex_lock(&android_app->mutex);
android_app_write_cmd(android_app, APP_CMD_DESTROY);
while (!android_app->destroyed) {
pthread_cond_wait(&android_app->cond, &android_app->mutex);
}
pthread_mutex_unlock(&android_app->mutex);
close(android_app->msgread);
close(android_app->msgwrite);
pthread_cond_destroy(&android_app->cond);
pthread_mutex_destroy(&android_app->mutex);
free(android_app);
}
static void onDestroy(ANativeActivity* activity) {
LOGV("Destroy: %p\n", activity);
android_app_free((struct android_app*)activity->instance);
}
static void onStart(ANativeActivity* activity) {
LOGV("Start: %p\n", activity);
android_app_set_activity_state((struct android_app*)activity->instance, APP_CMD_START);
}
static void onResume(ANativeActivity* activity) {
LOGV("Resume: %p\n", activity);
android_app_set_activity_state((struct android_app*)activity->instance, APP_CMD_RESUME);
}
static void* onSaveInstanceState(ANativeActivity* activity, size_t* outLen) {
struct android_app* android_app = (struct android_app*)activity->instance;
void* savedState = NULL;
LOGV("SaveInstanceState: %p\n", activity);
pthread_mutex_lock(&android_app->mutex);
android_app->stateSaved = 0;
android_app_write_cmd(android_app, APP_CMD_SAVE_STATE);
while (!android_app->stateSaved) {
pthread_cond_wait(&android_app->cond, &android_app->mutex);
}
if (android_app->savedState != NULL) {
savedState = android_app->savedState;
*outLen = android_app->savedStateSize;
android_app->savedState = NULL;
android_app->savedStateSize = 0;
}
pthread_mutex_unlock(&android_app->mutex);
return savedState;
}
static void onPause(ANativeActivity* activity) {
LOGV("Pause: %p\n", activity);
android_app_set_activity_state((struct android_app*)activity->instance, APP_CMD_PAUSE);
}
static void onStop(ANativeActivity* activity) {
LOGV("Stop: %p\n", activity);
android_app_set_activity_state((struct android_app*)activity->instance, APP_CMD_STOP);
}
static void onConfigurationChanged(ANativeActivity* activity) {
struct android_app* android_app = (struct android_app*)activity->instance;
LOGV("ConfigurationChanged: %p\n", activity);
android_app_write_cmd(android_app, APP_CMD_CONFIG_CHANGED);
}
static void onLowMemory(ANativeActivity* activity) {
struct android_app* android_app = (struct android_app*)activity->instance;
LOGV("LowMemory: %p\n", activity);
android_app_write_cmd(android_app, APP_CMD_LOW_MEMORY);
}
static void onWindowFocusChanged(ANativeActivity* activity, int focused) {
LOGV("WindowFocusChanged: %p -- %d\n", activity, focused);
android_app_write_cmd((struct android_app*)activity->instance,
focused ? APP_CMD_GAINED_FOCUS : APP_CMD_LOST_FOCUS);
}
static void onNativeWindowCreated(ANativeActivity* activity, ANativeWindow* window) {
LOGV("NativeWindowCreated: %p -- %p\n", activity, window);
android_app_set_window((struct android_app*)activity->instance, window);
}
static void onNativeWindowDestroyed(ANativeActivity* activity, ANativeWindow* window) {
LOGV("NativeWindowDestroyed: %p -- %p\n", activity, window);
android_app_set_window((struct android_app*)activity->instance, NULL);
}
static void onInputQueueCreated(ANativeActivity* activity, AInputQueue* queue) {
LOGV("InputQueueCreated: %p -- %p\n", activity, queue);
android_app_set_input((struct android_app*)activity->instance, queue);
}
static void onInputQueueDestroyed(ANativeActivity* activity, AInputQueue* queue) {
LOGV("InputQueueDestroyed: %p -- %p\n", activity, queue);
android_app_set_input((struct android_app*)activity->instance, NULL);
}
__attribute__((visibility("default"))) void ANativeActivity_onCreate(ANativeActivity* activity,
void* savedState, size_t savedStateSize) {
LOGV("Creating: %p\n", activity);
activity->callbacks->onDestroy = onDestroy;
activity->callbacks->onStart = onStart;
activity->callbacks->onResume = onResume;
activity->callbacks->onSaveInstanceState = onSaveInstanceState;
activity->callbacks->onPause = onPause;
activity->callbacks->onStop = onStop;
activity->callbacks->onConfigurationChanged = onConfigurationChanged;
activity->callbacks->onLowMemory = onLowMemory;
activity->callbacks->onWindowFocusChanged = onWindowFocusChanged;
activity->callbacks->onNativeWindowCreated = onNativeWindowCreated;
activity->callbacks->onNativeWindowDestroyed = onNativeWindowDestroyed;
activity->callbacks->onInputQueueCreated = onInputQueueCreated;
activity->callbacks->onInputQueueDestroyed = onInputQueueDestroyed;
activity->instance = android_app_create(activity, savedState, savedStateSize);
}
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef _ANDROID_NATIVE_APP_GLUE_H
#define _ANDROID_NATIVE_APP_GLUE_H
#include <poll.h>
#include <pthread.h>
#include <sched.h>
#include <android/configuration.h>
#include <android/looper.h>
#include <android/native_activity.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* The native activity interface provided by <android/native_activity.h>
* is based on a set of application-provided callbacks that will be called
* by the Activity's main thread when certain events occur.
*
* This means that each one of this callbacks _should_ _not_ block, or they
* risk having the system force-close the application. This programming
* model is direct, lightweight, but constraining.
*
* The 'android_native_app_glue' static library is used to provide a different
* execution model where the application can implement its own main event
* loop in a different thread instead. Here's how it works:
*
* 1/ The application must provide a function named "android_main()" that
* will be called when the activity is created, in a new thread that is
* distinct from the activity's main thread.
*
* 2/ android_main() receives a pointer to a valid "android_app" structure
* that contains references to other important objects, e.g. the
* ANativeActivity obejct instance the application is running in.
*
* 3/ the "android_app" object holds an ALooper instance that already
* listens to two important things:
*
* - activity lifecycle events (e.g. "pause", "resume"). See APP_CMD_XXX
* declarations below.
*
* - input events coming from the AInputQueue attached to the activity.
*
* Each of these correspond to an ALooper identifier returned by
* ALooper_pollOnce with values of LOOPER_ID_MAIN and LOOPER_ID_INPUT,
* respectively.
*
* Your application can use the same ALooper to listen to additional
* file-descriptors. They can either be callback based, or with return
* identifiers starting with LOOPER_ID_USER.
*
* 4/ Whenever you receive a LOOPER_ID_MAIN or LOOPER_ID_INPUT event,
* the returned data will point to an android_poll_source structure. You
* can call the process() function on it, and fill in android_app->onAppCmd
* and android_app->onInputEvent to be called for your own processing
* of the event.
*
* Alternatively, you can call the low-level functions to read and process
* the data directly... look at the process_cmd() and process_input()
* implementations in the glue to see how to do this.
*
* See the sample named "native-activity" that comes with the NDK with a
* full usage example. Also look at the JavaDoc of NativeActivity.
*/
struct android_app;
/**
* Data associated with an ALooper fd that will be returned as the "outData"
* when that source has data ready.
*/
struct android_poll_source {
// The identifier of this source. May be LOOPER_ID_MAIN or
// LOOPER_ID_INPUT.
int32_t id;
// The android_app this ident is associated with.
struct android_app* app;
// Function to call to perform the standard processing of data from
// this source.
void (*process)(struct android_app* app, struct android_poll_source* source);
};
/**
* This is the interface for the standard glue code of a threaded
* application. In this model, the application's code is running
* in its own thread separate from the main thread of the process.
* It is not required that this thread be associated with the Java
* VM, although it will need to be in order to make JNI calls any
* Java objects.
*/
struct android_app {
// The application can place a pointer to its own state object
// here if it likes.
void* userData;
// Fill this in with the function to process main app commands (APP_CMD_*)
void (*onAppCmd)(struct android_app* app, int32_t cmd);
// Fill this in with the function to process input events. At this point
// the event has already been pre-dispatched, and it will be finished upon
// return. Return 1 if you have handled the event, 0 for any default
// dispatching.
int32_t (*onInputEvent)(struct android_app* app, AInputEvent* event);
// The ANativeActivity object instance that this app is running in.
ANativeActivity* activity;
// The current configuration the app is running in.
AConfiguration* config;
// This is the last instance's saved state, as provided at creation time.
// It is NULL if there was no state. You can use this as you need; the
// memory will remain around until you call android_app_exec_cmd() for
// APP_CMD_RESUME, at which point it will be freed and savedState set to NULL.
// These variables should only be changed when processing a APP_CMD_SAVE_STATE,
// at which point they will be initialized to NULL and you can malloc your
// state and place the information here. In that case the memory will be
// freed for you later.
void* savedState;
size_t savedStateSize;
// The ALooper associated with the app's thread.
ALooper* looper;
// When non-NULL, this is the input queue from which the app will
// receive user input events.
AInputQueue* inputQueue;
// When non-NULL, this is the window surface that the app can draw in.
ANativeWindow* window;
// Current content rectangle of the window; this is the area where the
// window's content should be placed to be seen by the user.
ARect contentRect;
// Current state of the app's activity. May be either APP_CMD_START,
// APP_CMD_RESUME, APP_CMD_PAUSE, or APP_CMD_STOP; see below.
int activityState;
// This is non-zero when the application's NativeActivity is being
// destroyed and waiting for the app thread to complete.
int destroyRequested;
// -------------------------------------------------
// Below are "private" implementation of the glue code.
pthread_mutex_t mutex;
pthread_cond_t cond;
int msgread;
int msgwrite;
pthread_t thread;
struct android_poll_source cmdPollSource;
struct android_poll_source inputPollSource;
int running;
int stateSaved;
int destroyed;
int redrawNeeded;
AInputQueue* pendingInputQueue;
ANativeWindow* pendingWindow;
ARect pendingContentRect;
};
enum {
/**
* Looper data ID of commands coming from the app's main thread, which
* is returned as an identifier from ALooper_pollOnce(). The data for this
* identifier is a pointer to an android_poll_source structure.
* These can be retrieved and processed with android_app_read_cmd()
* and android_app_exec_cmd().
*/
LOOPER_ID_MAIN = 1,
/**
* Looper data ID of events coming from the AInputQueue of the
* application's window, which is returned as an identifier from
* ALooper_pollOnce(). The data for this identifier is a pointer to an
* android_poll_source structure. These can be read via the inputQueue
* object of android_app.
*/
LOOPER_ID_INPUT = 2,
/**
* Start of user-defined ALooper identifiers.
*/
LOOPER_ID_USER = 3,
};
enum {
/**
* Command from main thread: the AInputQueue has changed. Upon processing
* this command, android_app->inputQueue will be updated to the new queue
* (or NULL).
*/
APP_CMD_INPUT_CHANGED,
/**
* Command from main thread: a new ANativeWindow is ready for use. Upon
* receiving this command, android_app->window will contain the new window
* surface.
*/
APP_CMD_INIT_WINDOW,
/**
* Command from main thread: the existing ANativeWindow needs to be
* terminated. Upon receiving this command, android_app->window still
* contains the existing window; after calling android_app_exec_cmd
* it will be set to NULL.
*/
APP_CMD_TERM_WINDOW,
/**
* Command from main thread: the current ANativeWindow has been resized.
* Please redraw with its new size.
*/
APP_CMD_WINDOW_RESIZED,
/**
* Command from main thread: the system needs that the current ANativeWindow
* be redrawn. You should redraw the window before handing this to
* android_app_exec_cmd() in order to avoid transient drawing glitches.
*/
APP_CMD_WINDOW_REDRAW_NEEDED,
/**
* Command from main thread: the content area of the window has changed,
* such as from the soft input window being shown or hidden. You can
* find the new content rect in android_app::contentRect.
*/
APP_CMD_CONTENT_RECT_CHANGED,
/**
* Command from main thread: the app's activity window has gained
* input focus.
*/
APP_CMD_GAINED_FOCUS,
/**
* Command from main thread: the app's activity window has lost
* input focus.
*/
APP_CMD_LOST_FOCUS,
/**
* Command from main thread: the current device configuration has changed.
*/
APP_CMD_CONFIG_CHANGED,
/**
* Command from main thread: the system is running low on memory.
* Try to reduce your memory use.
*/
APP_CMD_LOW_MEMORY,
/**
* Command from main thread: the app's activity has been started.
*/
APP_CMD_START,
/**
* Command from main thread: the app's activity has been resumed.
*/
APP_CMD_RESUME,
/**
* Command from main thread: the app should generate a new saved state
* for itself, to restore from later if needed. If you have saved state,
* allocate it with malloc and place it in android_app.savedState with
* the size in android_app.savedStateSize. The will be freed for you
* later.
*/
APP_CMD_SAVE_STATE,
/**
* Command from main thread: the app's activity has been paused.
*/
APP_CMD_PAUSE,
/**
* Command from main thread: the app's activity has been stopped.
*/
APP_CMD_STOP,
/**
* Command from main thread: the app's activity is being destroyed,
* and waiting for the app thread to clean up and exit before proceeding.
*/
APP_CMD_DESTROY,
};
/**
* Call when ALooper_pollAll() returns LOOPER_ID_MAIN, reading the next
* app command message.
*/
int8_t android_app_read_cmd(struct android_app* android_app);
/**
* Call with the command returned by android_app_read_cmd() to do the
* initial pre-processing of the given command. You can perform your own
* actions for the command after calling this function.
*/
void android_app_pre_exec_cmd(struct android_app* android_app, int8_t cmd);
/**
* Call with the command returned by android_app_read_cmd() to do the
* final post-processing of the given command. You must have done your own
* actions for the command before calling this function.
*/
void android_app_post_exec_cmd(struct android_app* android_app, int8_t cmd);
/**
* Dummy function you can call to ensure glue code isn't stripped.
*/
void app_dummy();
/**
* This is the function that application code must implement, representing
* the main entry to the app.
*/
extern void android_main(struct android_app* app);
#ifdef __cplusplus
}
#endif
#endif /* _ANDROID_NATIVE_APP_GLUE_H */
......@@ -83,6 +83,13 @@
'osx/OSXWindow.h',
'posix/Posix_system_utils.cpp',
],
'util_android_sources':
[
'android/AndroidWindow.cpp',
'android/AndroidWindow.h',
'android/third_party/android_native_app_glue.c',
'android/third_party/android_native_app_glue.h',
],
},
'targets':
[
......
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