浏览代码

onRenderTexture

/siyaoH-1.17-android
siyao 3 年前
当前提交
d41bceb1
共有 6 个文件被更改,包括 110 次插入85 次删除
  1. 70
      com.unity.uiwidgets/Runtime/engine/UIWidgetsPanelWrapper.cs
  2. 16
      engine/Build.bee.cs
  3. 36
      engine/src/shell/platform/unity/android/uiwidgets_panel.cc
  4. 6
      engine/src/shell/platform/unity/android/uiwidgets_panel.h
  5. 58
      engine/src/shell/platform/unity/android/unity_surface_manager.cc
  6. 9
      engine/src/shell/platform/unity/android/unity_surface_manager.h

70
com.unity.uiwidgets/Runtime/engine/UIWidgetsPanelWrapper.cs


namespace Unity.UIWidgets.engine {
#region Platform: MacOs/iOS/Windows Specific Functionalities
#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_IOS || UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_IOS || UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN || UNITY_ANDROID
public partial class UIWidgetsPanelWrapper {
Texture _renderTexture;

void _enableUIWidgetsPanel(string font_settings) {
D.assert(_renderTexture == null);
#if !UNITY_EDITOR && UNITY_ANDROID
IntPtr native_tex_ptr = UIWidgetsPanel_onEnable(_ptr, _width, _height, devicePixelRatio,
Application.temporaryCachePath, font_settings);
#else
#endif
D.assert(native_tex_ptr != IntPtr.Zero);
_renderTexture =

[DllImport(NativeBindings.dllName)]
static extern IntPtr UIWidgetsPanel_onRenderTexture(
IntPtr ptr, int width, int height, float dpi);
#region Platform: Android Runtime Specific Functionalities
#if (!UNITY_EDITOR && UNITY_ANDROID )
public partial class UIWidgetsPanelWrapper {
RenderTexture _renderTexture;
public RenderTexture renderTexture {
get { return _renderTexture; }
}
void _createRenderTexture(int width, int height, float devicePixelRatio) {
D.assert(_renderTexture == null);
var desc = new RenderTextureDescriptor(
width, height, RenderTextureFormat.ARGB32, 0) {
useMipMap = false,
autoGenerateMips = false,
};
_renderTexture = new RenderTexture(desc) {hideFlags = HideFlags.HideAndDontSave};
_renderTexture.Create();
_width = width;
_height = height;
this.devicePixelRatio = devicePixelRatio;
}
void _destroyRenderTexture() {
D.assert(_renderTexture != null);
ObjectUtils.SafeDestroy(_renderTexture);
_renderTexture = null;
}
void _enableUIWidgetsPanel(string font_settings) {
UIWidgetsPanel_onEnable(_ptr, _renderTexture.GetNativeTexturePtr(),
_width, _height, devicePixelRatio, Application.temporaryCachePath, font_settings);
}
void _resizeUIWidgetsPanel() {
UIWidgetsPanel_onRenderTexture(_ptr,
_renderTexture.GetNativeTexturePtr(),
_width, _height, devicePixelRatio);
}
void _disableUIWidgetsPanel() {
_renderTexture = null;
}
[DllImport(NativeBindings.dllName)]
static extern void UIWidgetsPanel_onEnable(IntPtr ptr,
IntPtr nativeTexturePtr, int width, int height, float dpi, string streamingAssetsPath,
string font_settings);
[DllImport(NativeBindings.dllName)]
static extern void UIWidgetsPanel_onRenderTexture(
IntPtr ptr, IntPtr nativeTexturePtr, int width, int height, float dpi);
}
#endif
#endregion
#region Window Common Properties and Functions
public partial class UIWidgetsPanelWrapper {

16
engine/Build.bee.cs


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

"SK_CODEC_DECODES_WEBP",
"SK_ENCODE_WEBP",
"SK_XML",
"EGL_EGLEXT_PROTOTYPES",
"GL_GLEXT_PROTOTYPES",
//"UIWIDGETS_ENGINE_VERSION=\"0.0\"",
//"SKIA_VERSION=\"0.0\"",

"-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-28/arch-arm",
"-L"+ flutterRoot + "/third_party/android_tools/ndk/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a",
"-Wl,--build-id=sha1",
"-g",

}
else if (platform == UIWidgetsBuildTargetPlatform.android)
{
var androidToolchain = ToolChain.Store.Android().r19().Armv7();
var androidToolchain = new AndroidAppToolchain(new NPath ("/Users/siyao/temp/flutter/engine/src/third_party/android_tools/ndk"));
var validConfigurations = new List<NativeProgramConfiguration>();

36
engine/src/shell/platform/unity/android/uiwidgets_panel.cc


return window_type_ == EditorWindowPanel;
}
void UIWidgetsPanel::OnEnable(void *native_texture_ptr, size_t width,
GLuint UIWidgetsPanel::OnEnable( size_t width,
size_t height, float device_pixel_ratio,
const char *streaming_assets_path,
const char *settings)

FML_DCHECK(fbo_ == 0);
surface_manager_->MakeCurrent(EGL_NO_DISPLAY);
fbo_ = surface_manager_->CreateRenderSurface(native_texture_ptr);
fbo_ = surface_manager_->CreateRenderSurface(width, height);
surface_manager_->ClearCurrent();
fml::AutoResetWaitableEvent latch;

{
std::cerr << "Failed to start UIWidgets engine: error " << result
<< std::endl;
return;
return 0;
}
engine_ = engine;

process_events_ = true;
return surface_manager_->GetTexture();
}
void UIWidgetsPanel::MonoEntrypoint() { entrypoint_callback_(handle_); }

surface_manager_ = nullptr;
}
void UIWidgetsPanel::OnRenderTexture(void *native_texture_ptr, size_t width,
GLuint UIWidgetsPanel::OnRenderTexture(size_t width,
[this, native_texture_ptr]() -> void {
[this, width, height]() -> void {
surface_manager_->MakeCurrent(EGL_NO_DISPLAY);
if (fbo_)

}
fbo_ = surface_manager_->CreateRenderSurface(native_texture_ptr);
fbo_ = surface_manager_->CreateRenderSurface(width, height);
surface_manager_->ClearCurrent();
});

metrics.physical_height = static_cast<float>(height);
metrics.device_pixel_ratio = device_pixel_ratio;
reinterpret_cast<EmbedderEngine *>(engine_)->SetViewportMetrics(metrics);
return surface_manager_->GetTexture();
}
int UIWidgetsPanel::RegisterTexture(void *native_texture_ptr)

}
}
bool UIWidgetsPanel::ReleaseNativeRenderTexture() {
// for android this process is done during OnRenderTexture
//surface_manager_->DestroyRenderSurface();
return true;
}
void UIWidgetsPanel::OnKeyDown(int keyCode, bool isKeyDown)
{
if (process_events_)

panel->Release();
}
UIWIDGETS_API(void)
UIWidgetsPanel_onEnable(UIWidgetsPanel *panel, void *native_texture_ptr,
UIWIDGETS_API(GLuint)
UIWidgetsPanel_onEnable(UIWidgetsPanel *panel,
panel->OnEnable(native_texture_ptr, width, height, device_pixel_ratio,
return panel->OnEnable(width, height, device_pixel_ratio,
streaming_assets_path, settings);
}

panel->OnDisable();
}
UIWIDGETS_API(void)
UIWidgetsPanel_onRenderTexture(UIWidgetsPanel *panel, void *native_texture_ptr,
UIWIDGETS_API(GLuint)
UIWidgetsPanel_onRenderTexture(UIWidgetsPanel *panel,
panel->OnRenderTexture(native_texture_ptr, width, height, dpi);
return panel->OnRenderTexture(width, height, dpi);
}
UIWIDGETS_API(bool) UIWidgetsPanel_releaseNativeTexture(UIWidgetsPanel* panel) {
return panel->ReleaseNativeRenderTexture();
}
UIWIDGETS_API(int)

6
engine/src/shell/platform/unity/android/uiwidgets_panel.h


~UIWidgetsPanel();
void OnEnable(void* native_texture_ptr, size_t width, size_t height,
GLuint OnEnable(size_t width, size_t height,
float device_pixel_ratio, const char* streaming_assets_path,
const char* settings);

void OnRenderTexture(void* native_texture_ptr, size_t width, size_t height,
GLuint OnRenderTexture(size_t width, size_t height,
bool ReleaseNativeRenderTexture();
int RegisterTexture(void* native_texture_ptr);
void UnregisterTexture(int texture_id);

58
engine/src/shell/platform/unity/android/unity_surface_manager.cc


#include <flutter/fml/logging.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <GLES2/gl2ext.h>
#include <android/hardware_buffer.h>
#include "src/shell/common/shell_io_manager.h"
#include "src/shell/gpu/gpu_surface_delegate.h"

UnitySurfaceManager::~UnitySurfaceManager() { CleanUp(); }
GLuint UnitySurfaceManager::CreateRenderSurface(void *native_texture_ptr)
GLuint UnitySurfaceManager::CreateRenderSurface(size_t width, size_t height)
buffer = nullptr;
AHardwareBuffer_Desc usage = {};
// filling in the usage for HardwareBuffer
usage.format = AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM;
usage.height = height; //format.height;
usage.width = width; //format.width;
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;
FML_CHECK(AHardwareBuffer_allocate(&usage, &buffer) == 0);
EGLClientBuffer native_buffer = eglGetNativeClientBufferANDROID(buffer);
assert(native_buffer);
auto success = false;
EGLint attrs[] = {EGL_NONE};
image = eglCreateImageKHR(egl_display_, EGL_NO_CONTEXT,
EGL_NATIVE_BUFFER_ANDROID, native_buffer, attrs);
glBindTexture(GL_TEXTURE_2D, egl_texture_);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image);
GLuint gltex = (GLuint)(size_t)(native_texture_ptr);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, gltex, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, egl_texture_, 0);
// GLuint gltex = (GLuint)(size_t)(native_texture_ptr);
// glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, gltex, 0);
FML_CHECK(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE);
glBindFramebuffer(GL_FRAMEBUFFER, old_framebuffer_binding);

void UnitySurfaceManager::DestroyRenderSurface()
{
if(buffer != nullptr){
AHardwareBuffer_release(buffer);
}
if(image){
eglDestroyImageKHR(egl_display_, image);
}
eglDestroyImageKHR(egl_display_, image);
}
bool UnitySurfaceManager::ClearCurrent()

std::tie(success, egl_context_) = CreateContext(egl_display_, egl_config_, egl_unity_context_);
std::tie(success, egl_resource_context_) = CreateContext(egl_display_, egl_config_, egl_context_);
MakeCurrent(EGL_NO_DISPLAY);
egl_texture_ = 0;
glGenTextures(1, &egl_texture_);
return success;
}

9
engine/src/shell/platform/unity/android/unity_surface_manager.h


UnitySurfaceManager(IUnityInterfaces *unity_interfaces);
~UnitySurfaceManager();
GLuint CreateRenderSurface(void *native_texture_ptr);
GLuint CreateRenderSurface(size_t width, size_t height);
GLuint GetTexture() {return egl_texture_;}
bool ClearCurrent();

EGLContext egl_context_;
EGLContext egl_resource_context_;
EGLConfig egl_config_;
GLuint egl_texture_;
AHardwareBuffer *buffer;
EGLImageKHR image;
bool initialize_succeeded_;
GLuint fbo_ = 0;

正在加载...
取消
保存