native service, EGL, native test client
This commit is contained in:
1
.idea/gradle.xml
generated
1
.idea/gradle.xml
generated
@@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
|
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||||
<component name="GradleSettings">
|
<component name="GradleSettings">
|
||||||
<option name="linkedExternalProjectsSettings">
|
<option name="linkedExternalProjectsSettings">
|
||||||
<GradleProjectSettings>
|
<GradleProjectSettings>
|
||||||
|
|||||||
1
.idea/misc.xml
generated
1
.idea/misc.xml
generated
@@ -1,4 +1,3 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="jbr-21" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="jbr-21" project-jdk-type="JavaSDK">
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
plugins {
|
plugins {
|
||||||
alias(libs.plugins.android.application)
|
alias(libs.plugins.android.application)
|
||||||
alias(libs.plugins.kotlin.android)
|
alias(libs.plugins.kotlin.android)
|
||||||
|
alias(libs.plugins.kotlin.compose)
|
||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
@@ -47,6 +48,12 @@ android {
|
|||||||
dependencies {
|
dependencies {
|
||||||
implementation(libs.androidx.core.ktx)
|
implementation(libs.androidx.core.ktx)
|
||||||
implementation(libs.androidx.appcompat)
|
implementation(libs.androidx.appcompat)
|
||||||
|
implementation(libs.androidx.activity.compose)
|
||||||
|
implementation(libs.androidx.compose.ui)
|
||||||
|
implementation(libs.androidx.compose.material3)
|
||||||
implementation(libs.material)
|
implementation(libs.material)
|
||||||
implementation(libs.androidx.constraintlayout)
|
implementation(libs.androidx.constraintlayout)
|
||||||
|
implementation(libs.androidx.activity)
|
||||||
|
implementation(libs.androidx.compose.foundation)
|
||||||
|
implementation(libs.androidx.material3)
|
||||||
}
|
}
|
||||||
@@ -5,13 +5,24 @@ coreKtx = "1.17.0"
|
|||||||
appcompat = "1.7.1"
|
appcompat = "1.7.1"
|
||||||
material = "1.13.0"
|
material = "1.13.0"
|
||||||
constraintlayout = "2.2.1"
|
constraintlayout = "2.2.1"
|
||||||
|
activity = "1.12.2"
|
||||||
|
activityCompose = "1.12.2"
|
||||||
|
foundation = "1.10.0"
|
||||||
|
material3 = "1.4.0"
|
||||||
|
|
||||||
[libraries]
|
[libraries]
|
||||||
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
|
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
|
||||||
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
|
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
|
||||||
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
|
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
|
||||||
androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }
|
androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }
|
||||||
|
androidx-activity = { group = "androidx.activity", name = "activity", version.ref = "activity" }
|
||||||
|
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" }
|
||||||
|
androidx-compose-ui = { group = "androidx.compose.ui", name = "ui" }
|
||||||
|
androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3" }
|
||||||
|
androidx-compose-foundation = { group = "androidx.compose.foundation", name = "foundation", version.ref = "foundation" }
|
||||||
|
androidx-material3 = { group = "androidx.compose.material3", name = "material3", version.ref = "material3" }
|
||||||
|
|
||||||
[plugins]
|
[plugins]
|
||||||
android-application = { id = "com.android.application", version.ref = "agp" }
|
android-application = { id = "com.android.application", version.ref = "agp" }
|
||||||
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
|
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
|
||||||
|
kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
|
||||||
@@ -7,14 +7,23 @@
|
|||||||
|
|
||||||
<application
|
<application
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
android:label="MosisOS Service"
|
android:theme="@style/Theme.AppCompat.Light" >
|
||||||
android:theme="@style/Theme.AppCompat.Light">
|
<activity
|
||||||
|
android:name=".MainActivity"
|
||||||
|
android:label="MosisOS Test"
|
||||||
|
android:exported="true" >
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
<service
|
<service
|
||||||
android:name=".NativeService"
|
android:name=".NativeService"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:process=":service"
|
android:foregroundServiceType="dataSync"
|
||||||
android:foregroundServiceType="dataSync">
|
android:label="MosisOS Service"
|
||||||
|
android:process=":service" >
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="com.omixlab.mosis.SERVICE" />
|
<action android:name="com.omixlab.mosis.SERVICE" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.omixlab.mosis;
|
package com.omixlab.mosis;
|
||||||
|
|
||||||
interface IMosisService {
|
interface IMosisService {
|
||||||
|
boolean initOS();
|
||||||
int getNumber();
|
int getNumber();
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,30 @@
|
|||||||
cmake_minimum_required(VERSION 3.22.1)
|
cmake_minimum_required(VERSION 3.22.1)
|
||||||
project("mosis-service")
|
project("mosis")
|
||||||
|
|
||||||
set(ANDROID_SDK "/Users/omar/Library/Android/sdk")
|
set(ANDROID_SDK "/Users/omar/Library/Android/sdk")
|
||||||
set(BINDER_DIR "${ANDROID_SDK}/platforms/android-36/optional/libbinder_ndk_cpp")
|
set(BINDER_DIR "${ANDROID_SDK}/platforms/android-36/optional/libbinder_ndk_cpp")
|
||||||
|
|
||||||
add_library(${CMAKE_PROJECT_NAME} SHARED
|
add_library(mosis-service SHARED
|
||||||
mosis-service.cpp
|
mosis-service.cpp
|
||||||
com/omixlab/mosis/IMosisService.cpp)
|
com/omixlab/mosis/IMosisService.cpp
|
||||||
target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC
|
egl_context.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR} ${BINDER_DIR})
|
logger.cpp
|
||||||
target_link_libraries(${CMAKE_PROJECT_NAME}
|
glad/src/egl.c
|
||||||
|
glad/src/gles2.c)
|
||||||
|
target_include_directories(mosis-service PUBLIC
|
||||||
|
${CMAKE_CURRENT_LIST_DIR} ${BINDER_DIR} glad/include)
|
||||||
|
target_link_libraries(mosis-service
|
||||||
|
android log binder_ndk)
|
||||||
|
|
||||||
|
add_library(mosis-test SHARED
|
||||||
|
com/omixlab/mosis/IMosisService.cpp
|
||||||
|
mosis-test.cpp
|
||||||
|
egl_context.cpp
|
||||||
|
logger.cpp
|
||||||
|
glad/src/egl.c
|
||||||
|
glad/src/gles2.c)
|
||||||
|
|
||||||
|
target_include_directories(mosis-test PUBLIC
|
||||||
|
${CMAKE_CURRENT_LIST_DIR} ${BINDER_DIR} glad/include)
|
||||||
|
target_link_libraries(mosis-test
|
||||||
android log binder_ndk)
|
android log binder_ndk)
|
||||||
|
|||||||
@@ -36,6 +36,9 @@ public:
|
|||||||
explicit IMosisServiceDelegator(const std::shared_ptr<IMosisService> &impl) : _impl(impl) {
|
explicit IMosisServiceDelegator(const std::shared_ptr<IMosisService> &impl) : _impl(impl) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
::ndk::ScopedAStatus initOS(bool* _aidl_return) override {
|
||||||
|
return _impl->initOS(_aidl_return);
|
||||||
|
}
|
||||||
::ndk::ScopedAStatus getNumber(int32_t* _aidl_return) override {
|
::ndk::ScopedAStatus getNumber(int32_t* _aidl_return) override {
|
||||||
return _impl->getNumber(_aidl_return);
|
return _impl->getNumber(_aidl_return);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ public:
|
|||||||
explicit BpMosisService(const ::ndk::SpAIBinder& binder);
|
explicit BpMosisService(const ::ndk::SpAIBinder& binder);
|
||||||
virtual ~BpMosisService();
|
virtual ~BpMosisService();
|
||||||
|
|
||||||
|
::ndk::ScopedAStatus initOS(bool* _aidl_return) override;
|
||||||
::ndk::ScopedAStatus getNumber(int32_t* _aidl_return) override;
|
::ndk::ScopedAStatus getNumber(int32_t* _aidl_return) override;
|
||||||
};
|
};
|
||||||
} // namespace mosis
|
} // namespace mosis
|
||||||
|
|||||||
@@ -31,19 +31,22 @@ public:
|
|||||||
IMosisService();
|
IMosisService();
|
||||||
virtual ~IMosisService();
|
virtual ~IMosisService();
|
||||||
|
|
||||||
static constexpr uint32_t TRANSACTION_getNumber = FIRST_CALL_TRANSACTION + 0;
|
static constexpr uint32_t TRANSACTION_initOS = FIRST_CALL_TRANSACTION + 0;
|
||||||
|
static constexpr uint32_t TRANSACTION_getNumber = FIRST_CALL_TRANSACTION + 1;
|
||||||
|
|
||||||
static std::shared_ptr<IMosisService> fromBinder(const ::ndk::SpAIBinder& binder);
|
static std::shared_ptr<IMosisService> fromBinder(const ::ndk::SpAIBinder& binder);
|
||||||
static binder_status_t writeToParcel(AParcel* parcel, const std::shared_ptr<IMosisService>& instance);
|
static binder_status_t writeToParcel(AParcel* parcel, const std::shared_ptr<IMosisService>& instance);
|
||||||
static binder_status_t readFromParcel(const AParcel* parcel, std::shared_ptr<IMosisService>* instance);
|
static binder_status_t readFromParcel(const AParcel* parcel, std::shared_ptr<IMosisService>* instance);
|
||||||
static bool setDefaultImpl(const std::shared_ptr<IMosisService>& impl);
|
static bool setDefaultImpl(const std::shared_ptr<IMosisService>& impl);
|
||||||
static const std::shared_ptr<IMosisService>& getDefaultImpl();
|
static const std::shared_ptr<IMosisService>& getDefaultImpl();
|
||||||
|
virtual ::ndk::ScopedAStatus initOS(bool* _aidl_return) = 0;
|
||||||
virtual ::ndk::ScopedAStatus getNumber(int32_t* _aidl_return) = 0;
|
virtual ::ndk::ScopedAStatus getNumber(int32_t* _aidl_return) = 0;
|
||||||
private:
|
private:
|
||||||
static std::shared_ptr<IMosisService> default_impl;
|
static std::shared_ptr<IMosisService> default_impl;
|
||||||
};
|
};
|
||||||
class IMosisServiceDefault : public IMosisService {
|
class IMosisServiceDefault : public IMosisService {
|
||||||
public:
|
public:
|
||||||
|
::ndk::ScopedAStatus initOS(bool* _aidl_return) override;
|
||||||
::ndk::ScopedAStatus getNumber(int32_t* _aidl_return) override;
|
::ndk::ScopedAStatus getNumber(int32_t* _aidl_return) override;
|
||||||
::ndk::SpAIBinder asBinder() override;
|
::ndk::SpAIBinder asBinder() override;
|
||||||
bool isRemote() override;
|
bool isRemote() override;
|
||||||
|
|||||||
@@ -25,7 +25,21 @@ static binder_status_t _aidl_com_omixlab_mosis_IMosisService_onTransact(AIBinder
|
|||||||
binder_status_t _aidl_ret_status = STATUS_UNKNOWN_TRANSACTION;
|
binder_status_t _aidl_ret_status = STATUS_UNKNOWN_TRANSACTION;
|
||||||
std::shared_ptr<BnMosisService> _aidl_impl = std::static_pointer_cast<BnMosisService>(::ndk::ICInterface::asInterface(_aidl_binder));
|
std::shared_ptr<BnMosisService> _aidl_impl = std::static_pointer_cast<BnMosisService>(::ndk::ICInterface::asInterface(_aidl_binder));
|
||||||
switch (_aidl_code) {
|
switch (_aidl_code) {
|
||||||
case (FIRST_CALL_TRANSACTION + 0 /*getNumber*/): {
|
case (FIRST_CALL_TRANSACTION + 0 /*initOS*/): {
|
||||||
|
bool _aidl_return;
|
||||||
|
|
||||||
|
::ndk::ScopedAStatus _aidl_status = _aidl_impl->initOS(&_aidl_return);
|
||||||
|
_aidl_ret_status = AParcel_writeStatusHeader(_aidl_out, _aidl_status.get());
|
||||||
|
if (_aidl_ret_status != STATUS_OK) break;
|
||||||
|
|
||||||
|
if (!AStatus_isOk(_aidl_status.get())) break;
|
||||||
|
|
||||||
|
_aidl_ret_status = ::ndk::AParcel_writeData(_aidl_out, _aidl_return);
|
||||||
|
if (_aidl_ret_status != STATUS_OK) break;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case (FIRST_CALL_TRANSACTION + 1 /*getNumber*/): {
|
||||||
int32_t _aidl_return;
|
int32_t _aidl_return;
|
||||||
|
|
||||||
::ndk::ScopedAStatus _aidl_status = _aidl_impl->getNumber(&_aidl_return);
|
::ndk::ScopedAStatus _aidl_status = _aidl_impl->getNumber(&_aidl_return);
|
||||||
@@ -48,6 +62,43 @@ static AIBinder_Class* _g_aidl_com_omixlab_mosis_IMosisService_clazz = ::ndk::IC
|
|||||||
BpMosisService::BpMosisService(const ::ndk::SpAIBinder& binder) : BpCInterface(binder) {}
|
BpMosisService::BpMosisService(const ::ndk::SpAIBinder& binder) : BpCInterface(binder) {}
|
||||||
BpMosisService::~BpMosisService() {}
|
BpMosisService::~BpMosisService() {}
|
||||||
|
|
||||||
|
::ndk::ScopedAStatus BpMosisService::initOS(bool* _aidl_return) {
|
||||||
|
binder_status_t _aidl_ret_status = STATUS_OK;
|
||||||
|
::ndk::ScopedAStatus _aidl_status;
|
||||||
|
::ndk::ScopedAParcel _aidl_in;
|
||||||
|
::ndk::ScopedAParcel _aidl_out;
|
||||||
|
|
||||||
|
_aidl_ret_status = AIBinder_prepareTransaction(asBinderReference().get(), _aidl_in.getR());
|
||||||
|
if (_aidl_ret_status != STATUS_OK) goto _aidl_error;
|
||||||
|
|
||||||
|
_aidl_ret_status = AIBinder_transact(
|
||||||
|
asBinderReference().get(),
|
||||||
|
(FIRST_CALL_TRANSACTION + 0 /*initOS*/),
|
||||||
|
_aidl_in.getR(),
|
||||||
|
_aidl_out.getR(),
|
||||||
|
0
|
||||||
|
#ifdef BINDER_STABILITY_SUPPORT
|
||||||
|
| static_cast<int>(FLAG_PRIVATE_LOCAL)
|
||||||
|
#endif // BINDER_STABILITY_SUPPORT
|
||||||
|
);
|
||||||
|
if (_aidl_ret_status == STATUS_UNKNOWN_TRANSACTION && IMosisService::getDefaultImpl()) {
|
||||||
|
_aidl_status = IMosisService::getDefaultImpl()->initOS(_aidl_return);
|
||||||
|
goto _aidl_status_return;
|
||||||
|
}
|
||||||
|
if (_aidl_ret_status != STATUS_OK) goto _aidl_error;
|
||||||
|
|
||||||
|
_aidl_ret_status = AParcel_readStatusHeader(_aidl_out.get(), _aidl_status.getR());
|
||||||
|
if (_aidl_ret_status != STATUS_OK) goto _aidl_error;
|
||||||
|
|
||||||
|
if (!AStatus_isOk(_aidl_status.get())) goto _aidl_status_return;
|
||||||
|
_aidl_ret_status = ::ndk::AParcel_readData(_aidl_out.get(), _aidl_return);
|
||||||
|
if (_aidl_ret_status != STATUS_OK) goto _aidl_error;
|
||||||
|
|
||||||
|
_aidl_error:
|
||||||
|
_aidl_status.set(AStatus_fromStatus(_aidl_ret_status));
|
||||||
|
_aidl_status_return:
|
||||||
|
return _aidl_status;
|
||||||
|
}
|
||||||
::ndk::ScopedAStatus BpMosisService::getNumber(int32_t* _aidl_return) {
|
::ndk::ScopedAStatus BpMosisService::getNumber(int32_t* _aidl_return) {
|
||||||
binder_status_t _aidl_ret_status = STATUS_OK;
|
binder_status_t _aidl_ret_status = STATUS_OK;
|
||||||
::ndk::ScopedAStatus _aidl_status;
|
::ndk::ScopedAStatus _aidl_status;
|
||||||
@@ -59,7 +110,7 @@ BpMosisService::~BpMosisService() {}
|
|||||||
|
|
||||||
_aidl_ret_status = AIBinder_transact(
|
_aidl_ret_status = AIBinder_transact(
|
||||||
asBinderReference().get(),
|
asBinderReference().get(),
|
||||||
(FIRST_CALL_TRANSACTION + 0 /*getNumber*/),
|
(FIRST_CALL_TRANSACTION + 1 /*getNumber*/),
|
||||||
_aidl_in.getR(),
|
_aidl_in.getR(),
|
||||||
_aidl_out.getR(),
|
_aidl_out.getR(),
|
||||||
0
|
0
|
||||||
@@ -144,6 +195,11 @@ const std::shared_ptr<IMosisService>& IMosisService::getDefaultImpl() {
|
|||||||
return IMosisService::default_impl;
|
return IMosisService::default_impl;
|
||||||
}
|
}
|
||||||
std::shared_ptr<IMosisService> IMosisService::default_impl = nullptr;
|
std::shared_ptr<IMosisService> IMosisService::default_impl = nullptr;
|
||||||
|
::ndk::ScopedAStatus IMosisServiceDefault::initOS(bool* /*_aidl_return*/) {
|
||||||
|
::ndk::ScopedAStatus _aidl_status;
|
||||||
|
_aidl_status.set(AStatus_fromStatus(STATUS_UNKNOWN_TRANSACTION));
|
||||||
|
return _aidl_status;
|
||||||
|
}
|
||||||
::ndk::ScopedAStatus IMosisServiceDefault::getNumber(int32_t* /*_aidl_return*/) {
|
::ndk::ScopedAStatus IMosisServiceDefault::getNumber(int32_t* /*_aidl_return*/) {
|
||||||
::ndk::ScopedAStatus _aidl_status;
|
::ndk::ScopedAStatus _aidl_status;
|
||||||
_aidl_status.set(AStatus_fromStatus(STATUS_UNKNOWN_TRANSACTION));
|
_aidl_status.set(AStatus_fromStatus(STATUS_UNKNOWN_TRANSACTION));
|
||||||
|
|||||||
78
src/main/cpp/egl_context.cpp
Normal file
78
src/main/cpp/egl_context.cpp
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
#include "egl_context.h"
|
||||||
|
#include "logger.h"
|
||||||
|
#include <glad/gles2.h>
|
||||||
|
#include <glad/egl.h>
|
||||||
|
|
||||||
|
bool egl::Context::create()
|
||||||
|
{
|
||||||
|
int version = gladLoaderLoadEGL(EGL_NO_DISPLAY);
|
||||||
|
if (version == 0)
|
||||||
|
{
|
||||||
|
Logger::Log("glad failed to load EGL");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (m_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
||||||
|
m_display == EGL_NO_DISPLAY)
|
||||||
|
{
|
||||||
|
Logger::Log("eglGetDisplay failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
EGLint major, minor;
|
||||||
|
if (!eglInitialize(m_display, &major, &minor))
|
||||||
|
{
|
||||||
|
Logger::Log("eglInitialize failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
version = gladLoaderLoadEGL(EGL_DEFAULT_DISPLAY);
|
||||||
|
const EGLint config_attribs[] =
|
||||||
|
{
|
||||||
|
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
|
||||||
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT,
|
||||||
|
EGL_NONE,
|
||||||
|
};
|
||||||
|
EGLint num_configs;
|
||||||
|
if (!eglChooseConfig(m_display, config_attribs, &m_config, 1, &num_configs) || num_configs == 0)
|
||||||
|
{
|
||||||
|
Logger::Log("eglChooseConfig failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const EGLint context_attribs[] =
|
||||||
|
{
|
||||||
|
EGL_CONTEXT_MAJOR_VERSION, 3,
|
||||||
|
EGL_CONTEXT_MINOR_VERSION, 2,
|
||||||
|
EGL_NONE,
|
||||||
|
};
|
||||||
|
if (m_context = eglCreateContext(m_display, m_config, EGL_NO_CONTEXT, context_attribs);
|
||||||
|
m_context == EGL_NO_CONTEXT)
|
||||||
|
{
|
||||||
|
Logger::Log("eglCreateContext failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!eglMakeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, m_context))
|
||||||
|
{
|
||||||
|
Logger::Log("eglMakeCurrent failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void egl::Context::destroy()
|
||||||
|
{
|
||||||
|
if (m_display != EGL_NO_DISPLAY)
|
||||||
|
{
|
||||||
|
eglMakeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
||||||
|
if (m_context != EGL_NO_CONTEXT)
|
||||||
|
{
|
||||||
|
eglDestroyContext(m_display, m_context);
|
||||||
|
}
|
||||||
|
eglTerminate(m_display);
|
||||||
|
}
|
||||||
|
m_display = EGL_NO_DISPLAY;
|
||||||
|
m_context = EGL_NO_CONTEXT;
|
||||||
|
}
|
||||||
|
|
||||||
|
egl::Context::Context()
|
||||||
|
: m_display(EGL_NO_DISPLAY), m_config(EGL_NO_CONFIG_KHR), m_context(EGL_NO_CONTEXT)
|
||||||
|
{
|
||||||
|
Logger::Log("egl::Context::Context");
|
||||||
|
}
|
||||||
19
src/main/cpp/egl_context.h
Normal file
19
src/main/cpp/egl_context.h
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
typedef void* EGLContext;
|
||||||
|
typedef void* EGLDisplay;
|
||||||
|
typedef void* EGLConfig;
|
||||||
|
|
||||||
|
namespace egl
|
||||||
|
{
|
||||||
|
class Context
|
||||||
|
{
|
||||||
|
EGLContext m_context;
|
||||||
|
EGLDisplay m_display;
|
||||||
|
EGLConfig m_config = nullptr;
|
||||||
|
public:
|
||||||
|
Context();
|
||||||
|
bool create();
|
||||||
|
void destroy();
|
||||||
|
};
|
||||||
|
}
|
||||||
175
src/main/cpp/glad/include/EGL/eglplatform.h
Normal file
175
src/main/cpp/glad/include/EGL/eglplatform.h
Normal file
@@ -0,0 +1,175 @@
|
|||||||
|
#ifndef __eglplatform_h_
|
||||||
|
#define __eglplatform_h_
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Copyright 2007-2020 The Khronos Group Inc.
|
||||||
|
** SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Platform-specific types and definitions for egl.h
|
||||||
|
*
|
||||||
|
* Adopters may modify khrplatform.h and this file to suit their platform.
|
||||||
|
* You are encouraged to submit all modifications to the Khronos group so that
|
||||||
|
* they can be included in future versions of this file. Please submit changes
|
||||||
|
* by filing an issue or pull request on the public Khronos EGL Registry, at
|
||||||
|
* https://www.github.com/KhronosGroup/EGL-Registry/
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <KHR/khrplatform.h>
|
||||||
|
|
||||||
|
/* Macros used in EGL function prototype declarations.
|
||||||
|
*
|
||||||
|
* EGL functions should be prototyped as:
|
||||||
|
*
|
||||||
|
* EGLAPI return-type EGLAPIENTRY eglFunction(arguments);
|
||||||
|
* typedef return-type (EXPAPIENTRYP PFNEGLFUNCTIONPROC) (arguments);
|
||||||
|
*
|
||||||
|
* KHRONOS_APICALL and KHRONOS_APIENTRY are defined in KHR/khrplatform.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef EGLAPI
|
||||||
|
#define EGLAPI KHRONOS_APICALL
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef EGLAPIENTRY
|
||||||
|
#define EGLAPIENTRY KHRONOS_APIENTRY
|
||||||
|
#endif
|
||||||
|
#define EGLAPIENTRYP EGLAPIENTRY*
|
||||||
|
|
||||||
|
/* The types NativeDisplayType, NativeWindowType, and NativePixmapType
|
||||||
|
* are aliases of window-system-dependent types, such as X Display * or
|
||||||
|
* Windows Device Context. They must be defined in platform-specific
|
||||||
|
* code below. The EGL-prefixed versions of Native*Type are the same
|
||||||
|
* types, renamed in EGL 1.3 so all types in the API start with "EGL".
|
||||||
|
*
|
||||||
|
* Khronos STRONGLY RECOMMENDS that you use the default definitions
|
||||||
|
* provided below, since these changes affect both binary and source
|
||||||
|
* portability of applications using EGL running on different EGL
|
||||||
|
* implementations.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(EGL_NO_PLATFORM_SPECIFIC_TYPES)
|
||||||
|
|
||||||
|
typedef void *EGLNativeDisplayType;
|
||||||
|
typedef void *EGLNativePixmapType;
|
||||||
|
typedef void *EGLNativeWindowType;
|
||||||
|
|
||||||
|
#elif defined(_WIN32) || defined(__VC32__) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) /* Win32 and WinCE */
|
||||||
|
#ifndef WIN32_LEAN_AND_MEAN
|
||||||
|
#define WIN32_LEAN_AND_MEAN 1
|
||||||
|
#endif
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
typedef HDC EGLNativeDisplayType;
|
||||||
|
typedef HBITMAP EGLNativePixmapType;
|
||||||
|
typedef HWND EGLNativeWindowType;
|
||||||
|
|
||||||
|
#elif defined(__QNX__)
|
||||||
|
|
||||||
|
typedef khronos_uintptr_t EGLNativeDisplayType;
|
||||||
|
typedef struct _screen_pixmap* EGLNativePixmapType; /* screen_pixmap_t */
|
||||||
|
typedef struct _screen_window* EGLNativeWindowType; /* screen_window_t */
|
||||||
|
|
||||||
|
#elif defined(__EMSCRIPTEN__)
|
||||||
|
|
||||||
|
typedef int EGLNativeDisplayType;
|
||||||
|
typedef int EGLNativePixmapType;
|
||||||
|
typedef int EGLNativeWindowType;
|
||||||
|
|
||||||
|
#elif defined(__WINSCW__) || defined(__SYMBIAN32__) /* Symbian */
|
||||||
|
|
||||||
|
typedef int EGLNativeDisplayType;
|
||||||
|
typedef void *EGLNativePixmapType;
|
||||||
|
typedef void *EGLNativeWindowType;
|
||||||
|
|
||||||
|
#elif defined(WL_EGL_PLATFORM)
|
||||||
|
|
||||||
|
typedef struct wl_display *EGLNativeDisplayType;
|
||||||
|
typedef struct wl_egl_pixmap *EGLNativePixmapType;
|
||||||
|
typedef struct wl_egl_window *EGLNativeWindowType;
|
||||||
|
|
||||||
|
#elif defined(__GBM__)
|
||||||
|
|
||||||
|
typedef struct gbm_device *EGLNativeDisplayType;
|
||||||
|
typedef struct gbm_bo *EGLNativePixmapType;
|
||||||
|
typedef void *EGLNativeWindowType;
|
||||||
|
|
||||||
|
#elif defined(__ANDROID__) || defined(ANDROID)
|
||||||
|
|
||||||
|
struct ANativeWindow;
|
||||||
|
struct egl_native_pixmap_t;
|
||||||
|
|
||||||
|
typedef void* EGLNativeDisplayType;
|
||||||
|
typedef struct egl_native_pixmap_t* EGLNativePixmapType;
|
||||||
|
typedef struct ANativeWindow* EGLNativeWindowType;
|
||||||
|
|
||||||
|
#elif defined(USE_OZONE)
|
||||||
|
|
||||||
|
typedef intptr_t EGLNativeDisplayType;
|
||||||
|
typedef intptr_t EGLNativePixmapType;
|
||||||
|
typedef intptr_t EGLNativeWindowType;
|
||||||
|
|
||||||
|
#elif defined(USE_X11)
|
||||||
|
|
||||||
|
/* X11 (tentative) */
|
||||||
|
#include <X11/Xlib.h>
|
||||||
|
#include <X11/Xutil.h>
|
||||||
|
|
||||||
|
typedef Display *EGLNativeDisplayType;
|
||||||
|
typedef Pixmap EGLNativePixmapType;
|
||||||
|
typedef Window EGLNativeWindowType;
|
||||||
|
|
||||||
|
#elif defined(__unix__)
|
||||||
|
|
||||||
|
typedef void *EGLNativeDisplayType;
|
||||||
|
typedef khronos_uintptr_t EGLNativePixmapType;
|
||||||
|
typedef khronos_uintptr_t EGLNativeWindowType;
|
||||||
|
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
|
||||||
|
typedef int EGLNativeDisplayType;
|
||||||
|
typedef void *EGLNativePixmapType;
|
||||||
|
typedef void *EGLNativeWindowType;
|
||||||
|
|
||||||
|
#elif defined(__HAIKU__)
|
||||||
|
|
||||||
|
#include <kernel/image.h>
|
||||||
|
|
||||||
|
typedef void *EGLNativeDisplayType;
|
||||||
|
typedef khronos_uintptr_t EGLNativePixmapType;
|
||||||
|
typedef khronos_uintptr_t EGLNativeWindowType;
|
||||||
|
|
||||||
|
#elif defined(__Fuchsia__)
|
||||||
|
|
||||||
|
typedef void *EGLNativeDisplayType;
|
||||||
|
typedef khronos_uintptr_t EGLNativePixmapType;
|
||||||
|
typedef khronos_uintptr_t EGLNativeWindowType;
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error "Platform not recognized"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* EGL 1.2 types, renamed for consistency in EGL 1.3 */
|
||||||
|
typedef EGLNativeDisplayType NativeDisplayType;
|
||||||
|
typedef EGLNativePixmapType NativePixmapType;
|
||||||
|
typedef EGLNativeWindowType NativeWindowType;
|
||||||
|
|
||||||
|
|
||||||
|
/* Define EGLint. This must be a signed integral type large enough to contain
|
||||||
|
* all legal attribute names and values passed into and out of EGL, whether
|
||||||
|
* their type is boolean, bitmask, enumerant (symbolic constant), integer,
|
||||||
|
* handle, or other. While in general a 32-bit integer will suffice, if
|
||||||
|
* handles are 64 bit types, then EGLint should be defined as a signed 64-bit
|
||||||
|
* integer type.
|
||||||
|
*/
|
||||||
|
typedef khronos_int32_t EGLint;
|
||||||
|
|
||||||
|
|
||||||
|
/* C++ / C typecast macros for special EGL handle values */
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
#define EGL_CAST(type, value) (static_cast<type>(value))
|
||||||
|
#else
|
||||||
|
#define EGL_CAST(type, value) ((type) (value))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __eglplatform_h */
|
||||||
311
src/main/cpp/glad/include/KHR/khrplatform.h
Normal file
311
src/main/cpp/glad/include/KHR/khrplatform.h
Normal file
@@ -0,0 +1,311 @@
|
|||||||
|
#ifndef __khrplatform_h_
|
||||||
|
#define __khrplatform_h_
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Copyright (c) 2008-2018 The Khronos Group Inc.
|
||||||
|
**
|
||||||
|
** Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
** copy of this software and/or associated documentation files (the
|
||||||
|
** "Materials"), to deal in the Materials without restriction, including
|
||||||
|
** without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
** distribute, sublicense, and/or sell copies of the Materials, and to
|
||||||
|
** permit persons to whom the Materials are furnished to do so, subject to
|
||||||
|
** the following conditions:
|
||||||
|
**
|
||||||
|
** The above copyright notice and this permission notice shall be included
|
||||||
|
** in all copies or substantial portions of the Materials.
|
||||||
|
**
|
||||||
|
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||||
|
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||||
|
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||||
|
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Khronos platform-specific types and definitions.
|
||||||
|
*
|
||||||
|
* The master copy of khrplatform.h is maintained in the Khronos EGL
|
||||||
|
* Registry repository at https://github.com/KhronosGroup/EGL-Registry
|
||||||
|
* The last semantic modification to khrplatform.h was at commit ID:
|
||||||
|
* 67a3e0864c2d75ea5287b9f3d2eb74a745936692
|
||||||
|
*
|
||||||
|
* Adopters may modify this file to suit their platform. Adopters are
|
||||||
|
* encouraged to submit platform specific modifications to the Khronos
|
||||||
|
* group so that they can be included in future versions of this file.
|
||||||
|
* Please submit changes by filing pull requests or issues on
|
||||||
|
* the EGL Registry repository linked above.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* See the Implementer's Guidelines for information about where this file
|
||||||
|
* should be located on your system and for more details of its use:
|
||||||
|
* http://www.khronos.org/registry/implementers_guide.pdf
|
||||||
|
*
|
||||||
|
* This file should be included as
|
||||||
|
* #include <KHR/khrplatform.h>
|
||||||
|
* by Khronos client API header files that use its types and defines.
|
||||||
|
*
|
||||||
|
* The types in khrplatform.h should only be used to define API-specific types.
|
||||||
|
*
|
||||||
|
* Types defined in khrplatform.h:
|
||||||
|
* khronos_int8_t signed 8 bit
|
||||||
|
* khronos_uint8_t unsigned 8 bit
|
||||||
|
* khronos_int16_t signed 16 bit
|
||||||
|
* khronos_uint16_t unsigned 16 bit
|
||||||
|
* khronos_int32_t signed 32 bit
|
||||||
|
* khronos_uint32_t unsigned 32 bit
|
||||||
|
* khronos_int64_t signed 64 bit
|
||||||
|
* khronos_uint64_t unsigned 64 bit
|
||||||
|
* khronos_intptr_t signed same number of bits as a pointer
|
||||||
|
* khronos_uintptr_t unsigned same number of bits as a pointer
|
||||||
|
* khronos_ssize_t signed size
|
||||||
|
* khronos_usize_t unsigned size
|
||||||
|
* khronos_float_t signed 32 bit floating point
|
||||||
|
* khronos_time_ns_t unsigned 64 bit time in nanoseconds
|
||||||
|
* khronos_utime_nanoseconds_t unsigned time interval or absolute time in
|
||||||
|
* nanoseconds
|
||||||
|
* khronos_stime_nanoseconds_t signed time interval in nanoseconds
|
||||||
|
* khronos_boolean_enum_t enumerated boolean type. This should
|
||||||
|
* only be used as a base type when a client API's boolean type is
|
||||||
|
* an enum. Client APIs which use an integer or other type for
|
||||||
|
* booleans cannot use this as the base type for their boolean.
|
||||||
|
*
|
||||||
|
* Tokens defined in khrplatform.h:
|
||||||
|
*
|
||||||
|
* KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values.
|
||||||
|
*
|
||||||
|
* KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0.
|
||||||
|
* KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0.
|
||||||
|
*
|
||||||
|
* Calling convention macros defined in this file:
|
||||||
|
* KHRONOS_APICALL
|
||||||
|
* KHRONOS_APIENTRY
|
||||||
|
* KHRONOS_APIATTRIBUTES
|
||||||
|
*
|
||||||
|
* These may be used in function prototypes as:
|
||||||
|
*
|
||||||
|
* KHRONOS_APICALL void KHRONOS_APIENTRY funcname(
|
||||||
|
* int arg1,
|
||||||
|
* int arg2) KHRONOS_APIATTRIBUTES;
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(__SCITECH_SNAP__) && !defined(KHRONOS_STATIC)
|
||||||
|
# define KHRONOS_STATIC 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------------------
|
||||||
|
* Definition of KHRONOS_APICALL
|
||||||
|
*-------------------------------------------------------------------------
|
||||||
|
* This precedes the return type of the function in the function prototype.
|
||||||
|
*/
|
||||||
|
#if defined(KHRONOS_STATIC)
|
||||||
|
/* If the preprocessor constant KHRONOS_STATIC is defined, make the
|
||||||
|
* header compatible with static linking. */
|
||||||
|
# define KHRONOS_APICALL
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
# define KHRONOS_APICALL __declspec(dllimport)
|
||||||
|
#elif defined (__SYMBIAN32__)
|
||||||
|
# define KHRONOS_APICALL IMPORT_C
|
||||||
|
#elif defined(__ANDROID__)
|
||||||
|
# define KHRONOS_APICALL __attribute__((visibility("default")))
|
||||||
|
#else
|
||||||
|
# define KHRONOS_APICALL
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------------------
|
||||||
|
* Definition of KHRONOS_APIENTRY
|
||||||
|
*-------------------------------------------------------------------------
|
||||||
|
* This follows the return type of the function and precedes the function
|
||||||
|
* name in the function prototype.
|
||||||
|
*/
|
||||||
|
#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__)
|
||||||
|
/* Win32 but not WinCE */
|
||||||
|
# define KHRONOS_APIENTRY __stdcall
|
||||||
|
#else
|
||||||
|
# define KHRONOS_APIENTRY
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------------------
|
||||||
|
* Definition of KHRONOS_APIATTRIBUTES
|
||||||
|
*-------------------------------------------------------------------------
|
||||||
|
* This follows the closing parenthesis of the function prototype arguments.
|
||||||
|
*/
|
||||||
|
#if defined (__ARMCC_2__)
|
||||||
|
#define KHRONOS_APIATTRIBUTES __softfp
|
||||||
|
#else
|
||||||
|
#define KHRONOS_APIATTRIBUTES
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------------------
|
||||||
|
* basic type definitions
|
||||||
|
*-----------------------------------------------------------------------*/
|
||||||
|
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__)
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Using <stdint.h>
|
||||||
|
*/
|
||||||
|
#include <stdint.h>
|
||||||
|
typedef int32_t khronos_int32_t;
|
||||||
|
typedef uint32_t khronos_uint32_t;
|
||||||
|
typedef int64_t khronos_int64_t;
|
||||||
|
typedef uint64_t khronos_uint64_t;
|
||||||
|
#define KHRONOS_SUPPORT_INT64 1
|
||||||
|
#define KHRONOS_SUPPORT_FLOAT 1
|
||||||
|
/*
|
||||||
|
* To support platform where unsigned long cannot be used interchangeably with
|
||||||
|
* inptr_t (e.g. CHERI-extended ISAs), we can use the stdint.h intptr_t.
|
||||||
|
* Ideally, we could just use (u)intptr_t everywhere, but this could result in
|
||||||
|
* ABI breakage if khronos_uintptr_t is changed from unsigned long to
|
||||||
|
* unsigned long long or similar (this results in different C++ name mangling).
|
||||||
|
* To avoid changes for existing platforms, we restrict usage of intptr_t to
|
||||||
|
* platforms where the size of a pointer is larger than the size of long.
|
||||||
|
*/
|
||||||
|
#if defined(__SIZEOF_LONG__) && defined(__SIZEOF_POINTER__)
|
||||||
|
#if __SIZEOF_POINTER__ > __SIZEOF_LONG__
|
||||||
|
#define KHRONOS_USE_INTPTR_T
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#elif defined(__VMS ) || defined(__sgi)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Using <inttypes.h>
|
||||||
|
*/
|
||||||
|
#include <inttypes.h>
|
||||||
|
typedef int32_t khronos_int32_t;
|
||||||
|
typedef uint32_t khronos_uint32_t;
|
||||||
|
typedef int64_t khronos_int64_t;
|
||||||
|
typedef uint64_t khronos_uint64_t;
|
||||||
|
#define KHRONOS_SUPPORT_INT64 1
|
||||||
|
#define KHRONOS_SUPPORT_FLOAT 1
|
||||||
|
|
||||||
|
#elif defined(_WIN32) && !defined(__SCITECH_SNAP__)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Win32
|
||||||
|
*/
|
||||||
|
typedef __int32 khronos_int32_t;
|
||||||
|
typedef unsigned __int32 khronos_uint32_t;
|
||||||
|
typedef __int64 khronos_int64_t;
|
||||||
|
typedef unsigned __int64 khronos_uint64_t;
|
||||||
|
#define KHRONOS_SUPPORT_INT64 1
|
||||||
|
#define KHRONOS_SUPPORT_FLOAT 1
|
||||||
|
|
||||||
|
#elif defined(__sun__) || defined(__digital__)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Sun or Digital
|
||||||
|
*/
|
||||||
|
typedef int khronos_int32_t;
|
||||||
|
typedef unsigned int khronos_uint32_t;
|
||||||
|
#if defined(__arch64__) || defined(_LP64)
|
||||||
|
typedef long int khronos_int64_t;
|
||||||
|
typedef unsigned long int khronos_uint64_t;
|
||||||
|
#else
|
||||||
|
typedef long long int khronos_int64_t;
|
||||||
|
typedef unsigned long long int khronos_uint64_t;
|
||||||
|
#endif /* __arch64__ */
|
||||||
|
#define KHRONOS_SUPPORT_INT64 1
|
||||||
|
#define KHRONOS_SUPPORT_FLOAT 1
|
||||||
|
|
||||||
|
#elif 0
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Hypothetical platform with no float or int64 support
|
||||||
|
*/
|
||||||
|
typedef int khronos_int32_t;
|
||||||
|
typedef unsigned int khronos_uint32_t;
|
||||||
|
#define KHRONOS_SUPPORT_INT64 0
|
||||||
|
#define KHRONOS_SUPPORT_FLOAT 0
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Generic fallback
|
||||||
|
*/
|
||||||
|
#include <stdint.h>
|
||||||
|
typedef int32_t khronos_int32_t;
|
||||||
|
typedef uint32_t khronos_uint32_t;
|
||||||
|
typedef int64_t khronos_int64_t;
|
||||||
|
typedef uint64_t khronos_uint64_t;
|
||||||
|
#define KHRONOS_SUPPORT_INT64 1
|
||||||
|
#define KHRONOS_SUPPORT_FLOAT 1
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Types that are (so far) the same on all platforms
|
||||||
|
*/
|
||||||
|
typedef signed char khronos_int8_t;
|
||||||
|
typedef unsigned char khronos_uint8_t;
|
||||||
|
typedef signed short int khronos_int16_t;
|
||||||
|
typedef unsigned short int khronos_uint16_t;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Types that differ between LLP64 and LP64 architectures - in LLP64,
|
||||||
|
* pointers are 64 bits, but 'long' is still 32 bits. Win64 appears
|
||||||
|
* to be the only LLP64 architecture in current use.
|
||||||
|
*/
|
||||||
|
#ifdef KHRONOS_USE_INTPTR_T
|
||||||
|
typedef intptr_t khronos_intptr_t;
|
||||||
|
typedef uintptr_t khronos_uintptr_t;
|
||||||
|
#elif defined(_WIN64)
|
||||||
|
typedef signed long long int khronos_intptr_t;
|
||||||
|
typedef unsigned long long int khronos_uintptr_t;
|
||||||
|
#else
|
||||||
|
typedef signed long int khronos_intptr_t;
|
||||||
|
typedef unsigned long int khronos_uintptr_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_WIN64)
|
||||||
|
typedef signed long long int khronos_ssize_t;
|
||||||
|
typedef unsigned long long int khronos_usize_t;
|
||||||
|
#else
|
||||||
|
typedef signed long int khronos_ssize_t;
|
||||||
|
typedef unsigned long int khronos_usize_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if KHRONOS_SUPPORT_FLOAT
|
||||||
|
/*
|
||||||
|
* Float type
|
||||||
|
*/
|
||||||
|
typedef float khronos_float_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if KHRONOS_SUPPORT_INT64
|
||||||
|
/* Time types
|
||||||
|
*
|
||||||
|
* These types can be used to represent a time interval in nanoseconds or
|
||||||
|
* an absolute Unadjusted System Time. Unadjusted System Time is the number
|
||||||
|
* of nanoseconds since some arbitrary system event (e.g. since the last
|
||||||
|
* time the system booted). The Unadjusted System Time is an unsigned
|
||||||
|
* 64 bit value that wraps back to 0 every 584 years. Time intervals
|
||||||
|
* may be either signed or unsigned.
|
||||||
|
*/
|
||||||
|
typedef khronos_uint64_t khronos_utime_nanoseconds_t;
|
||||||
|
typedef khronos_int64_t khronos_stime_nanoseconds_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Dummy value used to pad enum types to 32 bits.
|
||||||
|
*/
|
||||||
|
#ifndef KHRONOS_MAX_ENUM
|
||||||
|
#define KHRONOS_MAX_ENUM 0x7FFFFFFF
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Enumerated boolean type
|
||||||
|
*
|
||||||
|
* Values other than zero should be considered to be true. Therefore
|
||||||
|
* comparisons should not be made against KHRONOS_TRUE.
|
||||||
|
*/
|
||||||
|
typedef enum {
|
||||||
|
KHRONOS_FALSE = 0,
|
||||||
|
KHRONOS_TRUE = 1,
|
||||||
|
KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM
|
||||||
|
} khronos_boolean_enum_t;
|
||||||
|
|
||||||
|
#endif /* __khrplatform_h_ */
|
||||||
1651
src/main/cpp/glad/include/glad/egl.h
Normal file
1651
src/main/cpp/glad/include/glad/egl.h
Normal file
File diff suppressed because it is too large
Load Diff
6145
src/main/cpp/glad/include/glad/gles2.h
Normal file
6145
src/main/cpp/glad/include/glad/gles2.h
Normal file
File diff suppressed because one or more lines are too long
1217
src/main/cpp/glad/src/egl.c
Normal file
1217
src/main/cpp/glad/src/egl.c
Normal file
File diff suppressed because it is too large
Load Diff
3819
src/main/cpp/glad/src/gles2.c
Normal file
3819
src/main/cpp/glad/src/gles2.c
Normal file
File diff suppressed because it is too large
Load Diff
9
src/main/cpp/logger.cpp
Normal file
9
src/main/cpp/logger.cpp
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#include "logger.h"
|
||||||
|
#include <android/log.h>
|
||||||
|
#define LOG_TAG "MosisOS"
|
||||||
|
#include <android/log_macros.h>
|
||||||
|
|
||||||
|
void Logger::Log(const std::string &message)
|
||||||
|
{
|
||||||
|
ALOGI("%s", message.c_str());
|
||||||
|
}
|
||||||
8
src/main/cpp/logger.h
Normal file
8
src/main/cpp/logger.h
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class Logger
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static void Log(const std::string& message);
|
||||||
|
};
|
||||||
@@ -1,26 +1,38 @@
|
|||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
#include <android/binder_ibinder_jni.h>
|
#include <android/binder_ibinder_jni.h>
|
||||||
#include <aidl/com/omixlab/mosis/BnMosisService.h>
|
#include <aidl/com/omixlab/mosis/BnMosisService.h>
|
||||||
|
#include "egl_context.h"
|
||||||
|
#include "logger.h"
|
||||||
|
|
||||||
using namespace aidl::com::omixlab::mosis;
|
using namespace aidl::com::omixlab::mosis;
|
||||||
|
|
||||||
class NativeService : public BnMosisService {
|
class NativeService : public BnMosisService {
|
||||||
|
std::unique_ptr<egl::Context> m_egl_context;
|
||||||
public:
|
public:
|
||||||
ndk::ScopedAStatus getNumber(int32_t *_aidl_return) override {
|
NativeService() = default;
|
||||||
|
ndk::ScopedAStatus getNumber(int32_t *_aidl_return) override
|
||||||
|
{
|
||||||
*_aidl_return = 100;
|
*_aidl_return = 100;
|
||||||
return ndk::ScopedAStatus::ok();
|
return ndk::ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
|
ndk::ScopedAStatus initOS(bool *_aidl_return) override {
|
||||||
|
if (!m_egl_context)
|
||||||
|
{
|
||||||
|
m_egl_context = std::make_unique<egl::Context>();
|
||||||
|
*_aidl_return = m_egl_context->create();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Logger::Log("OS already initialized");
|
||||||
|
*_aidl_return = true;
|
||||||
|
}
|
||||||
|
return ndk::ScopedAStatus::ok();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static std::shared_ptr<NativeService> g_service;
|
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
JNIEXPORT jobject JNICALL
|
JNIEXPORT jobject JNICALL
|
||||||
Java_com_omixlab_mosis_NativeService_getBinderNative(JNIEnv *env, jobject thiz) {
|
Java_com_omixlab_mosis_NativeService_getBinderNative(JNIEnv *env, jobject thiz) {
|
||||||
if (!g_service)
|
static std::shared_ptr<NativeService> g_service = ndk::SharedRefBase::make<NativeService>();
|
||||||
{
|
|
||||||
g_service = ndk::SharedRefBase::make<NativeService>();
|
|
||||||
|
|
||||||
}
|
|
||||||
return AIBinder_toJavaBinder(env, g_service->asBinder().get());
|
return AIBinder_toJavaBinder(env, g_service->asBinder().get());
|
||||||
}
|
}
|
||||||
|
|||||||
16
src/main/cpp/mosis-test.cpp
Normal file
16
src/main/cpp/mosis-test.cpp
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#include <jni.h>
|
||||||
|
#include <android/binder_ibinder_jni.h>
|
||||||
|
#include <aidl/com/omixlab/mosis/IMosisService.h>
|
||||||
|
#include "logger.h"
|
||||||
|
|
||||||
|
using namespace aidl::com::omixlab::mosis;
|
||||||
|
|
||||||
|
std::shared_ptr<IMosisService> g_service;
|
||||||
|
extern "C"
|
||||||
|
JNIEXPORT void JNICALL
|
||||||
|
Java_com_omixlab_mosis_MainActivity_serviceConnected(JNIEnv *env, jobject thiz, jobject binder) {
|
||||||
|
AIBinder* pBinder = AIBinder_fromJavaBinder(env, binder);
|
||||||
|
const ndk::SpAIBinder spBinder(pBinder);
|
||||||
|
g_service = IMosisService::fromBinder(spBinder);
|
||||||
|
Logger::Log("Service Connected");
|
||||||
|
}
|
||||||
80
src/main/java/com/omixlab/mosis/MainActivity.kt
Normal file
80
src/main/java/com/omixlab/mosis/MainActivity.kt
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
package com.omixlab.mosis
|
||||||
|
|
||||||
|
import android.content.ComponentName
|
||||||
|
import android.content.Intent
|
||||||
|
import android.content.ServiceConnection
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.os.IBinder
|
||||||
|
import android.util.Log
|
||||||
|
import androidx.activity.ComponentActivity
|
||||||
|
import androidx.activity.enableEdgeToEdge
|
||||||
|
import androidx.activity.compose.setContent
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.material3.Button
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
|
||||||
|
class MainActivity : ComponentActivity() {
|
||||||
|
init {
|
||||||
|
System.loadLibrary("mosis-test")
|
||||||
|
}
|
||||||
|
var remote_service: IMosisService? = null
|
||||||
|
var statusText = mutableStateOf("Status: idle")
|
||||||
|
var buttonText = mutableStateOf("Init OS")
|
||||||
|
private val connection = object : ServiceConnection {
|
||||||
|
override fun onServiceConnected(className: ComponentName, service: IBinder) {
|
||||||
|
Log.d("MosisTest", "Service Connected")
|
||||||
|
statusText.value = "Service Connected"
|
||||||
|
remote_service = IMosisService.Stub.asInterface(service)
|
||||||
|
Log.d("MosisTest", "Number: ${remote_service?.number}")
|
||||||
|
serviceConnected(service)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onServiceDisconnected(arg0: ComponentName) {
|
||||||
|
Log.d("MosisTest", "Service Disconnected")
|
||||||
|
statusText.value = "Service Disconnected"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fun initOS()
|
||||||
|
{
|
||||||
|
remote_service?.let { service ->
|
||||||
|
val result = service.initOS()
|
||||||
|
Log.d("MosisTest", "InitOS returned: $result")
|
||||||
|
buttonText.value = if (result) "OS Initialized" else "OS Not Initialized"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private fun startRemoteService() {
|
||||||
|
val intent = Intent("com.omixlab.mosis.SERVICE")
|
||||||
|
intent.setPackage("com.omixlab.mosis")
|
||||||
|
try {
|
||||||
|
startForegroundService(intent)
|
||||||
|
val result = bindService(intent, connection, BIND_AUTO_CREATE)
|
||||||
|
Log.d("ServiceTester", "Bind result: $result")
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e("ServiceTester", "Bind failed", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
startRemoteService()
|
||||||
|
enableEdgeToEdge()
|
||||||
|
setContent {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.fillMaxSize(),
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
|
verticalArrangement = Arrangement.Center
|
||||||
|
) {
|
||||||
|
Text("Welcome to Mosis OS")
|
||||||
|
Button(onClick = { initOS() }) {
|
||||||
|
Text(buttonText.value)
|
||||||
|
}
|
||||||
|
Text(statusText.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
external fun serviceConnected(binder: IBinder)
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import android.app.NotificationManager
|
|||||||
import android.app.Service
|
import android.app.Service
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
import android.os.Debug
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
|
|
||||||
|
|||||||
10
src/main/res/layout/activity_main.xml
Normal file
10
src/main/res/layout/activity_main.xml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/main"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:context=".MainActivity">
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
1
src/main/res/values/strings.xml
Normal file
1
src/main/res/values/strings.xml
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<resources></resources>
|
||||||
Reference in New Issue
Block a user