diff --git a/thermion_flutter/thermion_flutter/windows/CMakeLists.txt b/thermion_flutter/thermion_flutter/windows/CMakeLists.txt index 7d15ad3b..cfebf200 100644 --- a/thermion_flutter/thermion_flutter/windows/CMakeLists.txt +++ b/thermion_flutter/thermion_flutter/windows/CMakeLists.txt @@ -14,11 +14,11 @@ list(APPEND PLUGIN_SOURCES "thermion_flutter_plugin.h" ) -set(USE_ANGLE FALSE) +set(THERMION_EGL FALSE) set(WGL_USE_BACKING_WINDOW FALSE) -if(USE_ANGLE) - add_compile_definitions(USE_ANGLE) +if(THERMION_EGL) + add_compile_definitions(THERMION_EGL) list(APPEND PLUGIN_SOURCES "flutter_angle_texture.cpp" "egl_context.cpp" ) else() if(WGL_USE_BACKING_WINDOW) @@ -52,7 +52,7 @@ include_directories( "${CMAKE_SOURCE_DIR}/../../../../thermion_dart/native/include" ) -if(USE_ANGLE) +if(THERMION_EGL) list(APPEND GL_LIBS EGL GLESv2 @@ -87,7 +87,7 @@ target_link_libraries(${PLUGIN_NAME} PRIVATE ) # List of absolute paths to libraries that should be bundled with the plugin -if(USE_ANGLE) +if(THERMION_EGL) set(thermion_flutter_bundled_libraries ${CMAKE_CURRENT_SOURCE_DIR}/lib/Debug/angle/libEGL.dll ${CMAKE_CURRENT_SOURCE_DIR}/lib/Debug/angle/libGLESv2.dll diff --git a/thermion_flutter/thermion_flutter/windows/egl_context.h b/thermion_flutter/thermion_flutter/windows/egl_context.h deleted file mode 100644 index b6b056bc..00000000 --- a/thermion_flutter/thermion_flutter/windows/egl_context.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef _EGL_CONTEXT_H -#define _EGL_CONTEXT_H - -#include - -#include -#include -#include -#include - -#include "flutter_angle_texture.h" -#include "backend/platforms/PlatformEGL.h" -#include "flutter_render_context.h" - -namespace thermion_flutter { - -class FlutterEGLContext : public FlutterRenderContext { -public: - FlutterEGLContext(flutter::PluginRegistrarWindows* pluginRegistrar, flutter::TextureRegistrar* textureRegistrar); - void* GetSharedContext(); - void RenderCallback(); - void* GetPlatform(); - void CreateRenderingSurface(uint32_t width, uint32_t height, std::unique_ptr> result, uint32_t left, uint32_t top ); - -private: - void* _context = nullptr; - EGLConfig _eglConfig = NULL; - EGLDisplay _eglDisplay = NULL; - ID3D11Device* _D3D11Device = nullptr; - ID3D11DeviceContext* _D3D11DeviceContext = nullptr; - filament::backend::Platform* _platform = nullptr; -}; - -} - -#endif \ No newline at end of file diff --git a/thermion_flutter/thermion_flutter/windows/flutter_render_context.h b/thermion_flutter/thermion_flutter/windows/flutter_render_context.h deleted file mode 100644 index 1e86cbf5..00000000 --- a/thermion_flutter/thermion_flutter/windows/flutter_render_context.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef _FLUTTER_RENDER_CONTEXT_H -#define _FLUTTER_RENDER_CONTEXT_H - -#include -#include -#include -#include - -#include "flutter_texture_buffer.h" - -namespace thermion_flutter { - - class FlutterRenderContext { - public: - - void CreateRenderingSurface(uint32_t width, uint32_t height, std::unique_ptr> result, uint32_t left, uint32_t top); - - void DestroyRenderingSurface(std::unique_ptr> result); - - int64_t GetFlutterTextureId() { - if(!_active) { - return -1; - } - return _active->flutterTextureId; - } - - void *GetSharedContext(); - - protected: - FlutterRenderContext( flutter::PluginRegistrarWindows* pluginRegistrar, flutter::TextureRegistrar* textureRegistrar) : _pluginRegistrar(pluginRegistrar), _textureRegistrar(textureRegistrar) {}; - - flutter::PluginRegistrarWindows* _pluginRegistrar; - flutter::TextureRegistrar* _textureRegistrar; - std::unique_ptr _active = nullptr; - std::unique_ptr _inactive = nullptr; - }; -} - -#endif \ No newline at end of file diff --git a/thermion_flutter/thermion_flutter/windows/flutter_texture_buffer.h b/thermion_flutter/thermion_flutter/windows/flutter_texture_buffer.h deleted file mode 100644 index 40ee244f..00000000 --- a/thermion_flutter/thermion_flutter/windows/flutter_texture_buffer.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef _FLUTTER_TEXTURE_BUFFER_H -#define _FLUTTER_TEXTURE_BUFFER_H - -#include -#include -#include -#include - - -namespace thermion_flutter { - - class FlutterTextureBuffer { - public: - int64_t flutterTextureId = -1; - }; -} - -#endif \ No newline at end of file diff --git a/thermion_flutter/thermion_flutter/windows/rendering/egl/CMakeLists.txt b/thermion_flutter/thermion_flutter/windows/rendering/egl/CMakeLists.txt new file mode 100644 index 00000000..e0d6820f --- /dev/null +++ b/thermion_flutter/thermion_flutter/windows/rendering/egl/CMakeLists.txt @@ -0,0 +1,62 @@ +cmake_minimum_required(VERSION 3.14) +set(PROJECT_NAME "thermion_egl") +project(${PROJECT_NAME} LANGUAGES C CXX) + +cmake_policy(VERSION 3.14...3.25) + +add_compile_definitions(THERMION_EGL) + +set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) +set(BUILD_SHARED_LIBS TRUE) +set(CMAKE_ENABLE_EXPORTS TRUE) + +add_library(${PROJECT_NAME} SHARED + "egl_context.cpp" + "egl_texture.cpp" +) + +target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20) +include_directories(${PROJECT_NAME} INTERFACE + "${CMAKE_CURRENT_SOURCE_DIR}/../../include" +) + +add_library(EGL SHARED IMPORTED) +set_property(TARGET EGL PROPERTY IMPORTED_IMPLIB_DEBUG "E:\\angle\\libEGL.dll.lib") +set_property(TARGET EGL PROPERTY IMPORTED_IMPLIB_PROFILE "E:\\angle\\libEGL.dll.lib") +set_property(TARGET EGL PROPERTY IMPORTED_IMPLIB_RELEASE "E:\\angle\\libEGL.dll.lib") +set_property(TARGET EGL PROPERTY IMPORTED_IMPLIB_MINSIZEREL "E:\\angle\\libEGL.dll.lib") +set_property(TARGET EGL PROPERTY IMPORTED_IMPLIB_RELWITHDEBINFO "E:\\angle\\libEGL.dll.lib") +add_library(GLESv2 SHARED IMPORTED) +set_property(TARGET GLESv2 PROPERTY IMPORTED_IMPLIB_DEBUG "E:\\angle\\libGLESv2.dll.lib") +set_property(TARGET GLESv2 PROPERTY IMPORTED_IMPLIB_PROFILE "E:\\angle\\libGLESv2.dll.lib") +set_property(TARGET GLESv2 PROPERTY IMPORTED_IMPLIB_RELEASE "E:\\angle\\libGLESv2.dll") +set_property(TARGET GLESv2 PROPERTY IMPORTED_IMPLIB_MINSIZEREL "E:\\angle\\libGLESv2.dll") +set_property(TARGET GLESv2 PROPERTY IMPORTED_IMPLIB_RELWITHDEBINFO "E:\\angle\\libGLESv2.dll") + +target_link_libraries(${PROJECT_NAME} PRIVATE + Shlwapi + EGL + GLESv2 + dxgi + d3d11 +) + +# Test executable +add_executable(${PROJECT_NAME}_test + "main.cpp" +) + +# Make sure the test depends on the library +add_dependencies(${PROJECT_NAME}_test ${PROJECT_NAME}) + +target_link_libraries(${PROJECT_NAME}_test PRIVATE + ${PROJECT_NAME} +) + +# Copy ANGLE DLLs to the output directory +add_custom_command(TARGET ${PROJECT_NAME}_test POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + "E:/angle/libEGL.dll" + "E:/angle/libGLESv2.dll" + "$" +) \ No newline at end of file diff --git a/thermion_flutter/thermion_flutter/windows/egl_context.cpp b/thermion_flutter/thermion_flutter/windows/rendering/egl/egl_context.cpp similarity index 78% rename from thermion_flutter/thermion_flutter/windows/egl_context.cpp rename to thermion_flutter/thermion_flutter/windows/rendering/egl/egl_context.cpp index a766fa36..808d8c2f 100644 --- a/thermion_flutter/thermion_flutter/windows/egl_context.cpp +++ b/thermion_flutter/thermion_flutter/windows/rendering/egl/egl_context.cpp @@ -1,20 +1,13 @@ +#include +#include +#include #include "egl_context.h" -#define FILAMENT_USE_EXTERNAL_GLES3 -#include +namespace thermion::windows::egl { -#pragma comment(lib, "dwmapi.lib") -#pragma comment(lib, "comctl32.lib") - -namespace thermion_flutter { - -FlutterEGLContext::FlutterEGLContext( - flutter::PluginRegistrarWindows* pluginRegistrar, - flutter::TextureRegistrar* textureRegistrar) : FlutterRenderContext(pluginRegistrar, textureRegistrar) { +FlutterEGLContext::FlutterEGLContext() { - _platform = new filament::backend::PlatformEGL(); - // D3D starts here IDXGIAdapter *adapter_ = nullptr; @@ -81,13 +74,17 @@ FlutterEGLContext::FlutterEGLContext( // * * // ******************* EGLBoolean bindAPI = eglBindAPI(EGL_OPENGL_ES_API); - if (UTILS_UNLIKELY(!bindAPI)) { + if (!bindAPI) { std::cout << "eglBindAPI EGL_OPENGL_ES_API failed" << std::endl; return; } _eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); - assert_invariant(_eglDisplay != EGL_NO_DISPLAY); + if (_eglDisplay == EGL_NO_DISPLAY) { + std::cout << "eglBindAPI EGL_OPENGL_ES_API failed" << std::endl; + return; + } + EGLint major, minor; EGLBoolean initialized = false; @@ -113,12 +110,12 @@ FlutterEGLContext::FlutterEGLContext( std::cout << "Got major " << major << " and minor " << minor << std::endl; - if (UTILS_UNLIKELY(!initialized)) { + if (!initialized) { std::cout << "eglInitialize failed" << std::endl; return; } - glext::importGLESExtensionsEntryPoints(); + // glext::importGLESExtensionsEntryPoints(); EGLint configsCount; @@ -142,34 +139,33 @@ FlutterEGLContext::FlutterEGLContext( auto ctx = eglCreateContext(_eglDisplay, _eglConfig, EGL_NO_CONTEXT,contextAttribs); _context = (void*)ctx; - if (UTILS_UNLIKELY(_context == EGL_NO_CONTEXT)) { + if (_context == EGL_NO_CONTEXT) { return; } } void FlutterEGLContext::CreateRenderingSurface( uint32_t width, uint32_t height, - std::unique_ptr> result, uint32_t left, uint32_t top ) { - glext::importGLESExtensionsEntryPoints(); + // glext::importGLESExtensionsEntryPoints(); if(left != 0 || top != 0) { - result->Error("ERROR", - "Rendering with EGL uses a Texture render target/Flutter widget and does not need a window offset."); + // result->Error("ERROR", + // "Rendering with EGL uses a Texture render target/Flutter widget and does not need a window offset."); return; } if (_active.get()) { - result->Error("ERROR", - "Texture already exists. You must call destroyTexture before " - "attempting to create a new one."); + // result->Error("ERROR", + // "Texture already exists. You must call destroyTexture before " + // "attempting to create a new one."); return; } - std::unique_ptr active = std::make_unique( - _pluginRegistrar, _textureRegistrar, std::move(result), width, height, + _active = std::make_unique( + width, height, _D3D11Device, _D3D11DeviceContext, _eglConfig, _eglDisplay, _context, [=](size_t width, size_t height) { std::cout << "RESIZE" << std::endl; @@ -179,13 +175,12 @@ void FlutterEGLContext::CreateRenderingSurface( // auto val = std::make_unique(list); // this->_channel->InvokeMethod("resize", std::move(val), nullptr); }); - _active = std::move(active); } void FlutterEGLContext::RenderCallback() { if(_active.get()) { - ((FlutterAngleTexture*)_active.get())->RenderCallback(); + ((EGLTexture*)_active.get())->RenderCallback(); } } @@ -193,8 +188,5 @@ void* FlutterEGLContext::GetSharedContext() { return (void*)_context; } -void* FlutterEGLContext::GetPlatform() { - return (void*)_platform; } -} \ No newline at end of file diff --git a/thermion_flutter/thermion_flutter/windows/rendering/egl/egl_context.h b/thermion_flutter/thermion_flutter/windows/rendering/egl/egl_context.h new file mode 100644 index 00000000..186bb081 --- /dev/null +++ b/thermion_flutter/thermion_flutter/windows/rendering/egl/egl_context.h @@ -0,0 +1,26 @@ +#pragma once + +#include +#include + +#include "egl_texture.h" + +namespace thermion::windows::egl { + +class FlutterEGLContext { +public: + FlutterEGLContext(); + void* GetSharedContext(); + void RenderCallback(); + void CreateRenderingSurface(uint32_t width, uint32_t height, uint32_t left, uint32_t top); + +private: + void* _context = nullptr; + EGLConfig _eglConfig = NULL; + EGLDisplay _eglDisplay = NULL; + ID3D11Device* _D3D11Device = nullptr; + ID3D11DeviceContext* _D3D11DeviceContext = nullptr; + std::unique_ptr _active; +}; + +} diff --git a/thermion_flutter/thermion_flutter/windows/flutter_angle_texture.cpp b/thermion_flutter/thermion_flutter/windows/rendering/egl/egl_texture.cpp similarity index 66% rename from thermion_flutter/thermion_flutter/windows/flutter_angle_texture.cpp rename to thermion_flutter/thermion_flutter/windows/rendering/egl/egl_texture.cpp index 75465f55..8b5a068e 100644 --- a/thermion_flutter/thermion_flutter/windows/flutter_angle_texture.cpp +++ b/thermion_flutter/thermion_flutter/windows/rendering/egl/egl_texture.cpp @@ -1,13 +1,11 @@ -#include "flutter_angle_texture.h" - -#include -#include -#include -#include +#include "egl_texture.h" +#include +#include +#include #include -namespace thermion_flutter { +namespace thermion::windows::egl { static void logEglError(const char *name) noexcept { const char *err; @@ -61,14 +59,14 @@ static void logEglError(const char *name) noexcept { std::cout << name << " failed with " << err << std::endl; } -void FlutterAngleTexture::RenderCallback() { +void EGLTexture::RenderCallback() { glFinish(); _D3D11DeviceContext->CopyResource(_externalD3DTexture2D.Get(), _internalD3DTexture2D.Get()); _D3D11DeviceContext->Flush(); } -FlutterAngleTexture::~FlutterAngleTexture() { +EGLTexture::~EGLTexture() { if (_eglDisplay != EGL_NO_DISPLAY && _eglSurface != EGL_NO_SURFACE) { eglReleaseTexImage(_eglDisplay, _eglSurface, EGL_BACK_BUFFER); } @@ -81,17 +79,13 @@ FlutterAngleTexture::~FlutterAngleTexture() { glDeleteTextures(1, &this->glTextureId); } -FlutterAngleTexture::FlutterAngleTexture( - flutter::PluginRegistrarWindows *pluginRegistrar, - flutter::TextureRegistrar *textureRegistrar, - std::unique_ptr> result, +EGLTexture::EGLTexture( uint32_t width, uint32_t height, ID3D11Device *D3D11Device, ID3D11DeviceContext *D3D11DeviceContext, EGLConfig eglConfig, EGLDisplay eglDisplay, EGLContext eglContext, std::function onResizeRequested ) - : _pluginRegistrar(pluginRegistrar), _textureRegistrar(textureRegistrar), - _width(width), _height(height), _D3D11Device(D3D11Device), + : _width(width), _height(height), _D3D11Device(D3D11Device), _D3D11DeviceContext(D3D11DeviceContext), _eglConfig(eglConfig), _eglDisplay(eglDisplay), _eglContext(eglContext), _onResizeRequested(onResizeRequested) { @@ -113,7 +107,7 @@ FlutterAngleTexture::FlutterAngleTexture( auto hr = _D3D11Device->CreateTexture2D(&d3d11_texture2D_desc, nullptr, &_internalD3DTexture2D); if FAILED (hr) { - result->Error("ERROR", "Failed to create D3D texture", nullptr); + // result->Error("ERROR", "Failed to create D3D texture", nullptr); return; ; } @@ -121,14 +115,14 @@ FlutterAngleTexture::FlutterAngleTexture( hr = _internalD3DTexture2D.As(&resource); if FAILED (hr) { - result->Error("ERROR", "Failed to create D3D texture", nullptr); + // result->Error("ERROR", "Failed to create D3D texture", nullptr); return; ; } hr = resource->GetSharedHandle(&_internalD3DTextureHandle); if FAILED (hr) { - result->Error("ERROR", "Failed to get shared handle to D3D texture", - nullptr); + // result->Error("ERROR", "Failed to get shared handle to D3D texture", + // nullptr); return; ; } @@ -140,22 +134,22 @@ FlutterAngleTexture::FlutterAngleTexture( hr = _D3D11Device->CreateTexture2D(&d3d11_texture2D_desc, nullptr, &_externalD3DTexture2D); if FAILED (hr) { - result->Error("ERROR", "Failed to create D3D texture", nullptr); + // result->Error("ERROR", "Failed to create D3D texture", nullptr); return; ; } hr = _externalD3DTexture2D.As(&resource); if FAILED (hr) { - result->Error("ERROR", "Failed to create D3D texture", nullptr); + // result->Error("ERROR", "Failed to create D3D texture", nullptr); return; ; } hr = resource->GetSharedHandle(&_externalD3DTextureHandle); if FAILED (hr) { - result->Error("ERROR", - "Failed to get shared handle to external D3D texture", - nullptr); + // result->Error("ERROR", + // "Failed to get shared handle to external D3D texture", + // nullptr); return; ; } @@ -207,37 +201,27 @@ FlutterAngleTexture::FlutterAngleTexture( glGetIntegerv(GL_MAJOR_VERSION, &major); glGetIntegerv(GL_MINOR_VERSION, &minor); - _textureDescriptor = std::make_unique(); - _textureDescriptor->struct_size = sizeof(FlutterDesktopGpuSurfaceDescriptor); - _textureDescriptor->handle = _externalD3DTextureHandle; - _textureDescriptor->width = _textureDescriptor->visible_width = width; - _textureDescriptor->height = _textureDescriptor->visible_height = height; - _textureDescriptor->release_context = nullptr; - _textureDescriptor->release_callback = [](void *release_context) { + // _textureDescriptor = std::make_unique(); + // _textureDescriptor->struct_size = sizeof(FlutterDesktopGpuSurfaceDescriptor); + // _textureDescriptor->handle = _externalD3DTextureHandle; + // _textureDescriptor->width = _textureDescriptor->visible_width = width; + // _textureDescriptor->height = _textureDescriptor->visible_height = height; + // _textureDescriptor->release_context = nullptr; + // _textureDescriptor->release_callback = [](void *release_context) { - }; - _textureDescriptor->format = kFlutterDesktopPixelFormatBGRA8888; + // }; + // _textureDescriptor->format = kFlutterDesktopPixelFormatBGRA8888; - texture = - std::make_unique(flutter::GpuSurfaceTexture( - kFlutterDesktopGpuSurfaceTypeDxgiSharedHandle, - [&](size_t width, size_t height) { - if(width != this->_width || height != this->_height) { - this->_onResizeRequested(width, height); - } - return _textureDescriptor.get(); - })); + // texture = + // std::make_unique(flutter::GpuSurfaceTexture( + // kFlutterDesktopGpuSurfaceTypeDxgiSharedHandle, + // [&](size_t width, size_t height) { + // if(width != this->_width || height != this->_height) { + // this->_onResizeRequested(width, height); + // } + // return _textureDescriptor.get(); + // })); - flutterTextureId = _textureRegistrar->RegisterTexture(texture.get()); - std::cout << "Registered Flutter texture ID " << flutterTextureId - << std::endl; - - std::vector resultList; - resultList.push_back(flutter::EncodableValue(flutterTextureId)); - resultList.push_back(flutter::EncodableValue((int64_t) nullptr)); - resultList.push_back(flutter::EncodableValue(glTextureId)); - resultList.push_back(flutter::EncodableValue((int64_t) eglContext)); - result->Success(resultList); } } // namespace thermion_flutter \ No newline at end of file diff --git a/thermion_flutter/thermion_flutter/windows/flutter_angle_texture.h b/thermion_flutter/thermion_flutter/windows/rendering/egl/egl_texture.h similarity index 62% rename from thermion_flutter/thermion_flutter/windows/flutter_angle_texture.h rename to thermion_flutter/thermion_flutter/windows/rendering/egl/egl_texture.h index 0612c516..1b8709c4 100644 --- a/thermion_flutter/thermion_flutter/windows/flutter_angle_texture.h +++ b/thermion_flutter/thermion_flutter/windows/rendering/egl/egl_texture.h @@ -1,14 +1,8 @@ #pragma once -#ifndef _FLUTTER_ANGLE_TEXTURE_H -#define _FLUTTER_ANGLE_TEXTURE_H - +#include #include -#include -#include -#include - #include #include @@ -22,18 +16,13 @@ #include #include -#include "flutter_texture_buffer.h" - typedef uint32_t GLuint; -namespace thermion_flutter { +namespace thermion::windows::egl { -class FlutterAngleTexture : public FlutterTextureBuffer { +class EGLTexture { public: - FlutterAngleTexture( - flutter::PluginRegistrarWindows* pluginRegistrar, - flutter::TextureRegistrar* textureRegistrar, - std::unique_ptr> result, + EGLTexture( uint32_t width, uint32_t height, ID3D11Device* D3D11Device, @@ -43,16 +32,14 @@ class FlutterAngleTexture : public FlutterTextureBuffer { EGLContext eglContext, std::function onResizeRequested ); - ~FlutterAngleTexture(); + ~EGLTexture(); void RenderCallback(); - + GLuint glTextureId = 0; - std::unique_ptr texture; private: - flutter::PluginRegistrarWindows* _pluginRegistrar; - flutter::TextureRegistrar* _textureRegistrar; + bool _error = false; uint32_t _width = 0; uint32_t _height = 0; bool logged = false; @@ -72,9 +59,8 @@ class FlutterAngleTexture : public FlutterTextureBuffer { EGLConfig _eglConfig = EGL_NO_CONFIG_KHR; EGLSurface _eglSurface = EGL_NO_SURFACE; - std::unique_ptr _textureDescriptor = nullptr; + // std::unique_ptr _textureDescriptor = nullptr; }; } -#endif // _FLUTTER_ANGLE_TEXTURE \ No newline at end of file diff --git a/thermion_flutter/thermion_flutter/windows/rendering/egl/main.cpp b/thermion_flutter/thermion_flutter/windows/rendering/egl/main.cpp new file mode 100644 index 00000000..848bdaa2 --- /dev/null +++ b/thermion_flutter/thermion_flutter/windows/rendering/egl/main.cpp @@ -0,0 +1,36 @@ +#include "egl_context.h" +#include +#include +#include + +int main() { + std::cout << "Initializing EGL Context..." << std::endl; + + thermion::windows::egl::FlutterEGLContext context; + + // Create a rendering surface + const uint32_t width = 800; + const uint32_t height = 600; + + std::cout << "Creating rendering surface " << width << "x" << height << std::endl; + context.CreateRenderingSurface(width, height, 0, 0); + + void* sharedContext = context.GetSharedContext(); + if (sharedContext) { + std::cout << "Successfully created shared context" << std::endl; + } else { + std::cout << "Failed to create shared context" << std::endl; + return 1; + } + + // Run a simple render loop + std::cout << "Starting render loop..." << std::endl; + for (int i = 0; i < 10; i++) { + context.RenderCallback(); + std::cout << "Rendered frame " << i + 1 << std::endl; + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } + + std::cout << "EGL Context demo completed" << std::endl; + return 0; +} \ No newline at end of file diff --git a/thermion_flutter/thermion_flutter/windows/rendering/flutter_render_context.h b/thermion_flutter/thermion_flutter/windows/rendering/flutter_render_context.h new file mode 100644 index 00000000..b7446cff --- /dev/null +++ b/thermion_flutter/thermion_flutter/windows/rendering/flutter_render_context.h @@ -0,0 +1,23 @@ +#pragma once + +#include "flutter_texture_buffer.h" + +namespace thermion_flutter { + + class FlutterRenderContext { + public: + void CreateRenderingSurface(uint32_t width, uint32_t height, uint32_t left, uint32_t top); + void DestroyRenderingSurface(); + void *GetSharedContext(); + FlutterTextureBuffer GetActiveTexture() { + return _active->get(); + } + + protected: + FlutterRenderContext(); + std::unique_ptr _active = nullptr; + std::unique_ptr _inactive = nullptr; + }; +} + +#endif \ No newline at end of file diff --git a/thermion_flutter/thermion_flutter/windows/rendering/flutter_texture_buffer.h b/thermion_flutter/thermion_flutter/windows/rendering/flutter_texture_buffer.h new file mode 100644 index 00000000..62d2f9e0 --- /dev/null +++ b/thermion_flutter/thermion_flutter/windows/rendering/flutter_texture_buffer.h @@ -0,0 +1,25 @@ +#ifndef _FLUTTER_TEXTURE_BUFFER_H +#define _FLUTTER_TEXTURE_BUFFER_H + +#include +#include +#include +#include + +namespace thermion_flutter { + + class FlutterTextureBuffer { + public: + flutter::TextureVariant GetTexture() { + return texture->get(); + } + void RegisterFlutterTextureId(int64_t flutterTextureId); + int64_t GetFlutterTextureId(); + private: + int64_t flutterTextureId = -1; + std::unique_ptr texture; + + }; +} + +#endif \ No newline at end of file diff --git a/thermion_flutter/thermion_flutter/windows/backing_window.cpp b/thermion_flutter/thermion_flutter/windows/rendering/wgl/backing_window.cpp similarity index 100% rename from thermion_flutter/thermion_flutter/windows/backing_window.cpp rename to thermion_flutter/thermion_flutter/windows/rendering/wgl/backing_window.cpp diff --git a/thermion_flutter/thermion_flutter/windows/backing_window.h b/thermion_flutter/thermion_flutter/windows/rendering/wgl/backing_window.h similarity index 100% rename from thermion_flutter/thermion_flutter/windows/backing_window.h rename to thermion_flutter/thermion_flutter/windows/rendering/wgl/backing_window.h diff --git a/thermion_flutter/thermion_flutter/windows/opengl_texture_buffer.cpp b/thermion_flutter/thermion_flutter/windows/rendering/wgl/opengl_texture_buffer.cpp similarity index 100% rename from thermion_flutter/thermion_flutter/windows/opengl_texture_buffer.cpp rename to thermion_flutter/thermion_flutter/windows/rendering/wgl/opengl_texture_buffer.cpp diff --git a/thermion_flutter/thermion_flutter/windows/opengl_texture_buffer.h b/thermion_flutter/thermion_flutter/windows/rendering/wgl/opengl_texture_buffer.h similarity index 100% rename from thermion_flutter/thermion_flutter/windows/opengl_texture_buffer.h rename to thermion_flutter/thermion_flutter/windows/rendering/wgl/opengl_texture_buffer.h diff --git a/thermion_flutter/thermion_flutter/windows/wgl_context.cpp b/thermion_flutter/thermion_flutter/windows/rendering/wgl/wgl_context.cpp similarity index 100% rename from thermion_flutter/thermion_flutter/windows/wgl_context.cpp rename to thermion_flutter/thermion_flutter/windows/rendering/wgl/wgl_context.cpp diff --git a/thermion_flutter/thermion_flutter/windows/wgl_context.h b/thermion_flutter/thermion_flutter/windows/rendering/wgl/wgl_context.h similarity index 100% rename from thermion_flutter/thermion_flutter/windows/wgl_context.h rename to thermion_flutter/thermion_flutter/windows/rendering/wgl/wgl_context.h diff --git a/thermion_flutter/thermion_flutter/windows/thermion_flutter_plugin.cpp b/thermion_flutter/thermion_flutter/windows/thermion_flutter_plugin.cpp index f4b326f3..2feac132 100644 --- a/thermion_flutter/thermion_flutter/windows/thermion_flutter_plugin.cpp +++ b/thermion_flutter/thermion_flutter/windows/thermion_flutter_plugin.cpp @@ -29,7 +29,7 @@ #include "flutter_render_context.h" -#if USE_ANGLE +#if THERMION_EGL #include "egl_context.h" #else #include "wgl_context.h" @@ -150,6 +150,18 @@ void ThermionFlutterPlugin::CreateTexture( auto top = (uint32_t)round(dTop ); _context->CreateRenderingSurface(width, height, std::move(result), left, top); + auto texture = _context->GetActiveTexture(); + + auto flutterTextureId = _textureRegistrar->RegisterTexture(texture.GetFlutterTextureId()); + texture.RegisterFlutterTextureId(flutterTextureId); + std::cout << "Registered Flutter texture ID " << flutterTextureId + << std::endl; + + std::vector resultList; + resultList.push_back(flutter::EncodableValue(flutterTextureId)); + resultList.push_back(flutter::EncodableValue(glTextureId)); + resultList.push_back(flutter::EncodableValue((int64_t) nullptr)); + result->Success(resultList); } void ThermionFlutterPlugin::DestroyTexture( @@ -180,7 +192,7 @@ void ThermionFlutterPlugin::HandleMethodCall( result->Success(flutter::EncodableValue((int64_t)wrapper)); } else if(methodCall.method_name() == "getSharedContext") { if (!_context) { - #ifdef USE_ANGLE + #ifdef THERMION_EGL _context = std::make_unique(_pluginRegistrar, _textureRegistrar); #else _context = std::make_unique(_pluginRegistrar, _textureRegistrar); @@ -214,12 +226,13 @@ void ThermionFlutterPlugin::HandleMethodCall( DestroyTexture(methodCall, std::move(result)); } else if (methodCall.method_name() == "markTextureFrameAvailable") { if (_context) { - auto flutterTextureId = _context->GetFlutterTextureId(); + auto texture = context->GetActiveTexture(); + auto flutterTextureId = texture.GetFlutterTextureId(); if(flutterTextureId == -1) { std::cout << "Bad texture" << std::endl; return; } - #ifdef USE_ANGLE + #ifdef THERMION_EGL _context->RenderCallback(); #endif #if !WGL_USE_BACKING_WINDOW @@ -228,11 +241,7 @@ void ThermionFlutterPlugin::HandleMethodCall( } result->Success(flutter::EncodableValue((int64_t)nullptr)); } else if (methodCall.method_name() == "getDriverPlatform") { -#ifdef USE_ANGLE - result->Success(flutter::EncodableValue((int64_t)_context->GetPlatform())); -#else result->Success(flutter::EncodableValue((int64_t) nullptr)); -#endif } else { result->Error("NOT_IMPLEMENTED", "Method is not implemented %s", methodCall.method_name()); diff --git a/thermion_flutter/thermion_flutter/windows/thermion_flutter_plugin.h b/thermion_flutter/thermion_flutter/windows/thermion_flutter_plugin.h index 4cb0a645..2e220d48 100644 --- a/thermion_flutter/thermion_flutter/windows/thermion_flutter_plugin.h +++ b/thermion_flutter/thermion_flutter/windows/thermion_flutter_plugin.h @@ -16,7 +16,7 @@ #include "ResourceBuffer.h" -#if USE_ANGLE +#if THERMION_EGL #include "egl_context.h" #else #include "wgl_context.h" @@ -59,7 +59,7 @@ public: void freeResource(ResourceBuffer rbuf); private: - #ifdef USE_ANGLE + #ifdef THERMION_EGL std::unique_ptr _context = nullptr; #else std::unique_ptr _context = nullptr;