using Bee.Toolchain.GNU;
using Bee.Toolchain.IOS;
using System.Diagnostics;
using Bee.Toolchain.Android;
enum UIWidgetsBuildTargetPlatform
{
return RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
}
class AndroidAppToolchain : AndroidNdkToolchain
public AndroidAppToolchain(NPath path) : base(new AndroidNdkLocator(Architecture.Armv7).UseSpecific(path).WithForcedApiLevel(28))
//ios build helpers
"-isystem"+ flutterRoot+"/third_party/android_tools/ndk/sources/android/support/include",
"-isystem"+ flutterRoot +
"/third_party/android_tools/ndk/sysroot/usr/include/arm-linux-androideabi",
//"-D__ANDROID_API__=16",
"-D__ANDROID_API__=28",
// "-fvisibility=hidden",
"--sysroot="+ flutterRoot+"/third_party/android_tools/ndk/sysroot",
"-Wstring-conversion",
"-nostdlib++",
"-Wl,--warn-shared-textrel",
"-nostdlib",
"--sysroot="+ flutterRoot+"/third_party/android_tools/ndk/platforms/android-16/arch-arm",
// "--sysroot="+ flutterRoot+"/third_party/android_tools/ndk/platforms/android-16/arch-arm",
"--sysroot="+ flutterRoot+"/third_party/android_tools/ndk/platforms/android-28/arch-arm",
"-L"+ flutterRoot + "/third_party/android_tools/ndk/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a",
"-Wl,--build-id=sha1",
else if (platform == UIWidgetsBuildTargetPlatform.android)
var androidToolchain = ToolChain.Store.Android().r19().Armv7();
// var androidToolchain = new AndroidAppToolchain(new NPath ("/Applications/Unity/Hub/Editor/2019.4.17f1c1/PlaybackEngines/AndroidPlayer/NDK"));
var androidToolchain = new AndroidAppToolchain(new NPath ("/Users/siyao/temp/flutter/engine/src/third_party/android_tools/ndk"));
//var androidToolchain = ToolChain.Store.Android().r19().Armv7();
var validConfigurations = new List<NativeProgramConfiguration>();
buildNP.DeployTo("/Users/siyao/temp/androidBuild/Vulkan28/unityLibrary/src/main/jniLibs/armeabi-v7a");
np.ValidConfigurations = validConfigurations;
return;
egl_display_ = eglGetCurrentDisplay();
egl_unity_context_ = eglGetCurrentContext();
FML_CHECK(egl_display_ != EGL_NO_DISPLAY)
<< "Renderer type is invalid";
// EGLint major, minor;
// egl_display_ = eglGetDisplay(EGL_DEFAULT_DISPLAY);
// eglInitialize(egl_display_, &major, &minor);
// egl_unity_context_ = eglGetCurrentContext();
// FML_CHECK(egl_display_ != EGL_NO_DISPLAY)
// << "Renderer type is invalid";
static const int DEV_W = 16, DEV_H = 16;
auto device = m_Instance.device;
auto physicalDevice = m_Instance.physicalDevice;
VkImage image = 0;
VkImageCreateInfo imageInfo{};
imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
imageInfo.imageType = VK_IMAGE_TYPE_2D;
imageInfo.extent.width = 100;
imageInfo.extent.height = 100;
imageInfo.extent.depth = 1;
imageInfo.mipLevels = 1;
imageInfo.arrayLayers = 1;
imageInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
imageInfo.tiling = VK_IMAGE_TILING_LINEAR;
imageInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
imageInfo.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
imageInfo.samples = VK_SAMPLE_COUNT_1_BIT;
imageInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
vkCreateImage(device, &imageInfo, nullptr, &image);
// ... // create the image as normal
VkMemoryRequirements memReqs; // = device->getImageMemoryRequirements(image);
vkGetImageMemoryRequirements(device, image, &memReqs);
// memory = device->allocateMemory(memAllocInfo);
vkBindImageMemory(device, image, memory, 0);
AHardwareBuffer *buffer = nullptr;
AHardwareBuffer *buffer;
VkMemoryGetAndroidHardwareBufferInfoANDROID meminfo;
meminfo.sType = VK_STRUCTURE_TYPE_MEMORY_GET_ANDROID_HARDWARE_BUFFER_INFO_ANDROID;
// HANDLE sharedMemoryHandle = device->getMemoryWin32HandleKHR({
// texture.memory, VkExternalMemoryHandleTypeFlags::VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID
// });
EGLDisplay display = eglGetCurrentDisplay();
EGLClientBuffer clientBuffer = eglGetNativeClientBufferANDROID(buffer);
bool isProtectedContent = true;
EGLint attribs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE,
isProtectedContent ? EGL_PROTECTED_CONTENT_EXT : EGL_NONE,
isProtectedContent ? EGL_TRUE : EGL_NONE,
EGL_NONE};
// EGLDisplay display = eglGetCurrentDisplay();
bool success = false;
EGLint major, minor;
EGLImageKHR imagekhr = eglCreateImageKHR(display, EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_ANDROID, clientBuffer, attribs);
egl_display_ = eglGetDisplay(EGL_DEFAULT_DISPLAY);
auto error = eglGetError();
eglInitialize(egl_display_, &major, &minor);
error = eglGetError();
std::tie(success, egl_config_) = ChooseEGLConfiguration(egl_display_);
FML_CHECK(success) << "Could not choose an EGL configuration.";
eglBindAPI(EGL_OPENGL_ES_API);
GLint old_framebuffer_binding;
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &old_framebuffer_binding);
std::tie(success, egl_context_) = CreateContext(egl_display_, egl_config_, EGL_NO_CONTEXT);
std::tie(success, egl_resource_context_) = CreateContext(egl_display_, egl_config_, egl_context_);
eglMakeCurrent(egl_display_, EGL_NO_SURFACE, EGL_NO_SURFACE, egl_context_);
GLuint mTexture = 0;
glGenTextures(1, &mTexture);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTexture, 0);
EGLint ver0 = -1;
EGLint ver1 = -1;
EGLint ver2 = -1;
EGLint ver3 = -1;
eglQueryContext(egl_display_, egl_context_, EGL_CONTEXT_CLIENT_VERSION, &ver0);
eglQueryContext(egl_display_, egl_context_, EGL_CONFIG_ID, &ver1);
eglQueryContext(egl_display_, egl_context_, EGL_CONTEXT_CLIENT_TYPE, &ver2);
eglQueryContext(egl_display_, egl_context_, EGL_RENDER_BUFFER, &ver3);
AHardwareBuffer_Desc usage;
// filling in the usage for HardwareBuffer
usage.format = AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM;
usage.height = 100; //outputHeight;
usage.width = 100; // outputWidth;
usage.layers = 1;
usage.rfu0 = 0;
usage.rfu1 = 0;
usage.stride = 10;
usage.usage = AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN | AHARDWAREBUFFER_USAGE_CPU_WRITE_NEVER | AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT;
AHardwareBuffer *graphicBuf;
AHardwareBuffer_allocate(&usage, &graphicBuf); // it's worth to check the return code
// ACTUAL parameters of the AHardwareBuffer which it reports
AHardwareBuffer_Desc usage1;
// for stride, see below
AHardwareBuffer_describe(graphicBuf, &usage1);
// get the native buffer
EGLClientBuffer clientBuf = eglGetNativeClientBufferANDROID(graphicBuf);
// obtaining the EGL display
// specifying the image attributes
// EGLint eglImageAttributes[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE};
EGLint eglImageAttributes[] = { EGL_NONE};
// creating an EGL image
// EGLImageKHR imageEGL = eglCreateImageKHR(egl_display_, egl_context_, EGL_NATIVE_BUFFER_ANDROID, clientBuf, eglImageAttributes);
EGLImageKHR imageEGL = eglCreateImageKHR(egl_display_, EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_ANDROID, clientBuf, eglImageAttributes);
/**
* @note this part should be earlies than any draw or framebuffer options.
* @note refer to answer of @solidpixel at https://stackoverflow.com/questions/64447069/use-gleglimagetargettexture2does-to-replace-glreadpixels-on-android
* @{
*/
// binding the OUTPUT texture
glBindTexture(GL_TEXTURE_2D, mTexture);
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, imageEGL);
glBindTexture(bindType, 0);
auto x = glCheckFramebufferStatus(GL_FRAMEBUFFER);
// glewInit();
EGLint attribs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE};
auto xegl = eglGetCurrentContext();
// EGLImageKHR imagekhr = eglCreateImageKHR(egl_display_, egl_context_, EGL_NATIVE_BUFFER_ANDROID, clientBuffer, attribs);
EGLImageKHR imagekhr = eglCreateImageKHR(egl_display_, EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_ANDROID, clientBuffer, attribs);
//-------------------
auto valid_ = true;
return success;
else