浏览代码

android task

/siyaoH-1.17-PlatformMessage
siyao 4 年前
当前提交
eceaaea0
共有 8 个文件被更改,包括 271 次插入220 次删除
  1. 19
      Samples/UIWidgetsSamples_2019_4/Assets/CountDemo.unity
  2. 19
      com.unity.uiwidgets/Runtime/engine2/UIWidgetsPanel.cs
  3. 11
      engine/src/shell/platform/unity/android/cocoa_task_runner.cc
  4. 5
      engine/src/shell/platform/unity/android/cocoa_task_runner.h
  5. 303
      engine/src/shell/platform/unity/android/uiwidgets_panel.cc
  6. 87
      engine/src/shell/platform/unity/android/unity_surface_manager.cc
  7. 15
      engine/src/shell/platform/unity/android/unity_surface_manager.h
  8. 32
      Samples/UIWidgetsSamples_2019_4/Assets/WorkAround.cs

19
Samples/UIWidgetsSamples_2019_4/Assets/CountDemo.unity


- component: {fileID: 1777874941}
- component: {fileID: 1777874942}
- component: {fileID: 1777874943}
- component: {fileID: 1777874944}
m_Layer: 5
m_Name: RawImage
m_TagString: Untagged

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1777874940}
m_Enabled: 1
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0817e3443c80cb943a03dcf7b120bd2e, type: 3}
m_Name:

y: 0
width: 1
height: 1
fonts: []
fonts: []
m_ShowDebugLog: 0
--- !u!114 &1777874944
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1777874940}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: bcb4984097885463dbe58d12837993ce, type: 3}
m_Name:
m_EditorClassIdentifier:
demo: {fileID: 1777874943}

19
com.unity.uiwidgets/Runtime/engine2/UIWidgetsPanel.cs


using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using Color = UnityEngine.Color;
namespace Unity.UIWidgets.engine2 {

}
static bool _ShowDebugLog = false;
Texture2D targetTexture = null;
protected void OnEnable() {
base.OnEnable();

D.assert(_wrapper == null);
_wrapper = new UIWidgetsPanelWrapper();
_wrapper.Initiate(this, _currentWidth, _currentHeight, _currentDevicePixelRatio, settings);
if (targetTexture == null) {
targetTexture = new Texture2D(_currentWidth, _currentHeight, TextureFormat.BGRA32, 1, true);
// GetComponent<Renderer>().material.mainTexture = targetTexture;
Debug.Log($"{_currentWidth}, {_currentHeight}");
for (int y = 0; y < _currentHeight; y++) {
for (int x = 0; x < _currentWidth; x++) {
targetTexture.SetPixel(x, y, Color.green);
}
}
targetTexture.Apply();
}
texture = targetTexture;
texture = _wrapper.renderTexture;
Input_OnEnable();

}
protected virtual void Update() {
Graphics.CopyTexture(_wrapper.renderTexture,0,0, 100, 100, 400, 400, targetTexture, 0, 0, 100, 100);
Input_Update();
}

11
engine/src/shell/platform/unity/android/cocoa_task_runner.cc


namespace uiwidgets {
CocoaTaskRunner::CocoaTaskRunner(const TaskExpiredCallback& on_task_expired)
: on_task_expired_(std::move(on_task_expired)) {}
CocoaTaskRunner::CocoaTaskRunner(pid_t threadId, const TaskExpiredCallback& on_task_expired)
: on_task_expired_(std::move(on_task_expired)),
threadId(threadId)
{}
CocoaTaskRunner::~CocoaTaskRunner() = default;

std::lock_guard<std::mutex> lock(task_queue_mutex_);
task_queue_.push(task);
}
}
bool CocoaTaskRunner::RunsTasksOnCurrentThread(){
pid_t id = gettid();
return threadId == id;
}
void CocoaTaskRunner::AddTaskObserver(intptr_t key,

5
engine/src/shell/platform/unity/android/cocoa_task_runner.h


public:
using TaskExpiredCallback = std::function<void(const UIWidgetsTask*)>;
CocoaTaskRunner(const TaskExpiredCallback& on_task_expired);
CocoaTaskRunner(pid_t threadId, const TaskExpiredCallback& on_task_expired);
~CocoaTaskRunner();

void AddTaskObserver(intptr_t key, const fml::closure& callback);
void RemoveTaskObserver(intptr_t key);
bool RunsTasksOnCurrentThread();
FML_DISALLOW_COPY_AND_ASSIGN(CocoaTaskRunner);

TaskExpiredCallback on_task_expired_;
std::mutex task_queue_mutex_;
std::priority_queue<Task, std::deque<Task>, Task::Comparer> task_queue_;
pid_t threadId;
using TaskObservers = std::map<intptr_t, fml::closure>;
TaskObservers task_observers_;

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


FML_DCHECK(fbo_ == 0);
surface_manager_->MakeCurrent(EGL_NO_DISPLAY);
fbo_ = surface_manager_->CreateRenderSurface(native_texture_ptr, width, height);
fbo_ = surface_manager_->CreateRenderSurface(native_texture_ptr);
// fml::AutoResetWaitableEvent latch;
// std::thread::id gfx_worker_thread_id;
// UIWidgetsSystem::GetInstancePtr()->PostTaskToGfxWorker(
// [&latch, &gfx_worker_thread_id]() -> void {
// gfx_worker_thread_id = std::this_thread::get_id();
// latch.Signal();
// });
// latch.Wait();
fml::AutoResetWaitableEvent latch;
std::thread::id gfx_worker_thread_id;
UIWidgetsSystem::GetInstancePtr()->PostTaskToGfxWorker(
[&latch, &gfx_worker_thread_id]() -> void {
gfx_worker_thread_id = std::this_thread::get_id();
latch.Signal();
});
latch.Wait();
// gfx_worker_task_runner_ = std::make_unique<GfxWorkerTaskRunner>(
// gfx_worker_thread_id, [this](const auto* task) {
// if (UIWidgetsEngineRunTask(engine_, task) != kSuccess) {
// std::cerr << "Could not post an gfx worker task." << std::endl;
// }
// });
gfx_worker_task_runner_ = std::make_unique<GfxWorkerTaskRunner>(
gfx_worker_thread_id, [this](const auto* task) {
if (UIWidgetsEngineRunTask(engine_, task) != kSuccess) {
std::cerr << "Could not post an gfx worker task." << std::endl;
}
});
// UIWidgetsTaskRunnerDescription render_task_runner = {};
// render_task_runner.struct_size = sizeof(UIWidgetsTaskRunnerDescription);
// render_task_runner.identifier = 1;
// render_task_runner.user_data = gfx_worker_task_runner_.get();
// render_task_runner.runs_task_on_current_thread_callback =
// [](void* user_data) -> bool {
// return static_cast<GfxWorkerTaskRunner*>(user_data)
// ->RunsTasksOnCurrentThread();
// };
// render_task_runner.post_task_callback = [](UIWidgetsTask task,
// uint64_t target_time_nanos,
// void* user_data) -> void {
// static_cast<GfxWorkerTaskRunner*>(user_data)->PostTask(task,
// target_time_nanos);
// };
UIWidgetsTaskRunnerDescription render_task_runner = {};
render_task_runner.struct_size = sizeof(UIWidgetsTaskRunnerDescription);
render_task_runner.identifier = 1;
render_task_runner.user_data = gfx_worker_task_runner_.get();
render_task_runner.runs_task_on_current_thread_callback =
[](void* user_data) -> bool {
return static_cast<GfxWorkerTaskRunner*>(user_data)
->RunsTasksOnCurrentThread();
};
render_task_runner.post_task_callback = [](UIWidgetsTask task,
uint64_t target_time_nanos,
void* user_data) -> void {
static_cast<GfxWorkerTaskRunner*>(user_data)->PostTask(task,
target_time_nanos);
};
// UIWidgetsRendererConfig config = {};
// config.type = kOpenGL;
// config.open_gl.struct_size = sizeof(config.open_gl);
// config.open_gl.clear_current = [](void* user_data) -> bool {
// auto* panel = static_cast<UIWidgetsPanel*>(user_data);
// return panel->surface_manager_->ClearCurrent();
// };
// config.open_gl.make_current = [](void* user_data) -> bool {
// auto* panel = static_cast<UIWidgetsPanel*>(user_data);
// return panel->surface_manager_->MakeCurrent(EGL_NO_DISPLAY);
// };
// config.open_gl.make_resource_current = [](void* user_data) -> bool {
// auto* panel = static_cast<UIWidgetsPanel*>(user_data);
// return panel->surface_manager_->MakeResourceCurrent();
// };
// config.open_gl.fbo_callback = [](void* user_data) -> uint32_t {
// auto* panel = static_cast<UIWidgetsPanel*>(user_data);
// return panel->fbo_;
// };
// config.open_gl.present = [](void* user_data) -> bool { return true; };
// config.open_gl.gl_proc_resolver = [](void* user_data,
// const char* what) -> void* {
// return reinterpret_cast<void*>(eglGetProcAddress(what));
// };
// config.open_gl.fbo_reset_after_present = true;
UIWidgetsRendererConfig config = {};
config.type = kOpenGL;
config.open_gl.struct_size = sizeof(config.open_gl);
config.open_gl.clear_current = [](void* user_data) -> bool {
auto* panel = static_cast<UIWidgetsPanel*>(user_data);
return panel->surface_manager_->ClearCurrent();
};
config.open_gl.make_current = [](void* user_data) -> bool {
auto* panel = static_cast<UIWidgetsPanel*>(user_data);
return panel->surface_manager_->MakeCurrent(EGL_NO_DISPLAY);
};
config.open_gl.make_resource_current = [](void* user_data) -> bool {
auto* panel = static_cast<UIWidgetsPanel*>(user_data);
return panel->surface_manager_->MakeResourceCurrent();
};
config.open_gl.fbo_callback = [](void* user_data) -> uint32_t {
auto* panel = static_cast<UIWidgetsPanel*>(user_data);
return panel->fbo_;
};
config.open_gl.present = [](void* user_data) -> bool { return true; };
config.open_gl.gl_proc_resolver = [](void* user_data,
const char* what) -> void* {
return reinterpret_cast<void*>(eglGetProcAddress(what));
};
config.open_gl.fbo_reset_after_present = true;
// task_runner_ = std::make_unique<Win32TaskRunner>(
// GetCurrentThreadId(), [this](const auto* task) {
// if (UIWidgetsEngineRunTask(engine_, task) != kSuccess) {
// std::cerr << "Could not post an engine task." << std::endl;
// }
// });
task_runner_ = std::make_unique<CocoaTaskRunner>(
gettid(), [this](const auto* task) {
if (UIWidgetsEngineRunTask(engine_, task) != kSuccess) {
std::cerr << "Could not post an engine task." << std::endl;
}
});
// UIWidgetsTaskRunnerDescription ui_task_runner = {};
// ui_task_runner.struct_size = sizeof(UIWidgetsTaskRunnerDescription);
// ui_task_runner.identifier = 2;
// ui_task_runner.user_data = task_runner_.get();
// ui_task_runner.runs_task_on_current_thread_callback =
// [](void* user_data) -> bool {
// return static_cast<Win32TaskRunner*>(user_data)->RunsTasksOnCurrentThread();
// };
// ui_task_runner.post_task_callback = [](UIWidgetsTask task,
// uint64_t target_time_nanos,
// void* user_data) -> void {
// static_cast<Win32TaskRunner*>(user_data)->PostTask(task, target_time_nanos);
// };
UIWidgetsTaskRunnerDescription ui_task_runner = {};
ui_task_runner.struct_size = sizeof(UIWidgetsTaskRunnerDescription);
ui_task_runner.identifier = 2;
ui_task_runner.user_data = task_runner_.get();
// UIWidgetsCustomTaskRunners custom_task_runners = {};
// custom_task_runners.struct_size = sizeof(UIWidgetsCustomTaskRunners);
// custom_task_runners.platform_task_runner = &ui_task_runner;
// custom_task_runners.ui_task_runner = &ui_task_runner;
// custom_task_runners.render_task_runner = &render_task_runner;
// TODO: waht is this
ui_task_runner.runs_task_on_current_thread_callback =
[](void* user_data) -> bool {
return static_cast<CocoaTaskRunner*>(user_data)->RunsTasksOnCurrentThread();
};
ui_task_runner.post_task_callback = [](UIWidgetsTask task,
uint64_t target_time_nanos,
void* user_data) -> void {
static_cast<CocoaTaskRunner*>(user_data)->PostTask(task, target_time_nanos);
};
// UIWidgetsProjectArgs args = {};
// args.struct_size = sizeof(UIWidgetsProjectArgs);
UIWidgetsCustomTaskRunners custom_task_runners = {};
custom_task_runners.struct_size = sizeof(UIWidgetsCustomTaskRunners);
custom_task_runners.platform_task_runner = &ui_task_runner;
custom_task_runners.ui_task_runner = &ui_task_runner;
custom_task_runners.render_task_runner = &render_task_runner;
UIWidgetsProjectArgs args = {};
args.struct_size = sizeof(UIWidgetsProjectArgs);
// args.assets_path = streaming_assets_path;
// args.font_asset = settings;
args.assets_path = streaming_assets_path;
args.font_asset = settings;
// args.icu_mapper = GetICUStaticMapping;
args.icu_mapper = GetICUStaticMapping;
// // Used for IOS build
// // std::string icu_symbol_prefix = "_binary_icudtl_dat_start";

// // return GetSymbolMapping(icu_symbol_prefix, native_lib_path);
// // };
// args.command_line_argc = 0;
// args.command_line_argv = nullptr;
args.command_line_argc = 0;
args.command_line_argv = nullptr;
// args.platform_message_callback =
// [](const UIWidgetsPlatformMessage* engine_message,
// void* user_data) -> void {};
args.platform_message_callback =
[](const UIWidgetsPlatformMessage* engine_message,
void* user_data) -> void {};
// args.custom_task_runners = &custom_task_runners;
// args.task_observer_add = [](intptr_t key, void* callback,
// void* user_data) -> void {
// auto* panel = static_cast<UIWidgetsPanel*>(user_data);
// panel->task_runner_->AddTaskObserver(key,
// *static_cast<fml::closure*>(callback));
// };
// args.task_observer_remove = [](intptr_t key, void* user_data) -> void {
// auto* panel = static_cast<UIWidgetsPanel*>(user_data);
// panel->task_runner_->RemoveTaskObserver(key);
// };
args.custom_task_runners = &custom_task_runners;
args.task_observer_add = [](intptr_t key, void* callback,
void* user_data) -> void {
auto* panel = static_cast<UIWidgetsPanel*>(user_data);
panel->task_runner_->AddTaskObserver(key,
*static_cast<fml::closure*>(callback));
};
args.task_observer_remove = [](intptr_t key, void* user_data) -> void {
auto* panel = static_cast<UIWidgetsPanel*>(user_data);
panel->task_runner_->RemoveTaskObserver(key);
};
// args.custom_mono_entrypoint = [](void* user_data) -> void {
// auto* panel = static_cast<UIWidgetsPanel*>(user_data);
// panel->MonoEntrypoint();
// };
args.custom_mono_entrypoint = [](void* user_data) -> void {
auto* panel = static_cast<UIWidgetsPanel*>(user_data);
panel->MonoEntrypoint();
};
// args.vsync_callback = [](void* user_data, intptr_t baton) -> void {
// auto* panel = static_cast<UIWidgetsPanel*>(user_data);
// panel->VSyncCallback(baton);
// };
args.vsync_callback = [](void* user_data, intptr_t baton) -> void {
auto* panel = static_cast<UIWidgetsPanel*>(user_data);
panel->VSyncCallback(baton);
};
// args.initial_window_metrics.width = width;
// args.initial_window_metrics.height = height;
// args.initial_window_metrics.pixel_ratio = device_pixel_ratio;
args.initial_window_metrics.width = width;
args.initial_window_metrics.height = height;
args.initial_window_metrics.pixel_ratio = device_pixel_ratio;
// UIWidgetsEngine engine = nullptr;
// auto result = UIWidgetsEngineInitialize(&config, &args, this, &engine);
UIWidgetsEngine engine = nullptr;
auto result = UIWidgetsEngineInitialize(&config, &args, this, &engine);
// if (result != kSuccess || engine == nullptr) {
// std::cerr << "Failed to start UIWidgets engine: error " << result
// << std::endl;
// return;
// }
if (result != kSuccess || engine == nullptr) {
std::cerr << "Failed to start UIWidgets engine: error " << result
<< std::endl;
return;
}
// engine_ = engine;
// UIWidgetsEngineRunInitialized(engine);
engine_ = engine;
UIWidgetsEngineRunInitialized(engine);
// UIWidgetsSystem::GetInstancePtr()->RegisterPanel(this);
UIWidgetsSystem::GetInstancePtr()->RegisterPanel(this);
// process_events_ = true;
process_events_ = true;
}
void UIWidgetsPanel::MonoEntrypoint() { entrypoint_callback_(handle_); }

gfx_worker_task_runner_ = nullptr;
task_runner_ = nullptr;
// if (fbo_) {
// surface_manager_->MakeCurrent(EGL_NO_DISPLAY);
if (fbo_) {
surface_manager_->MakeCurrent(EGL_NO_DISPLAY);
// surface_manager_->DestroyRenderSurface();
// fbo_ = 0;
surface_manager_->DestroyRenderSurface();
fbo_ = 0;
// surface_manager_->ClearCurrent();
// }
surface_manager_->ClearCurrent();
}
// surface_manager_ = nullptr;
surface_manager_ = nullptr;
// reinterpret_cast<EmbedderEngine*>(engine_)->PostRenderThreadTask(
// [this, native_texture_ptr]() -> void {
// surface_manager_->MakeCurrent(EGL_NO_DISPLAY);
reinterpret_cast<EmbedderEngine*>(engine_)->PostRenderThreadTask(
[this, native_texture_ptr]() -> void {
surface_manager_->MakeCurrent(EGL_NO_DISPLAY);
// if (fbo_) {
// surface_manager_->DestroyRenderSurface();
// fbo_ = 0;
// }
// fbo_ = surface_manager_->CreateRenderSurface(native_texture_ptr);
if (fbo_) {
surface_manager_->DestroyRenderSurface();
fbo_ = 0;
}
fbo_ = surface_manager_->CreateRenderSurface(native_texture_ptr);
// surface_manager_->ClearCurrent();
// });
surface_manager_->ClearCurrent();
});
// ViewportMetrics metrics;
// metrics.physical_width = static_cast<float>(width);
// metrics.physical_height = static_cast<float>(height);
// metrics.device_pixel_ratio = device_pixel_ratio;
// reinterpret_cast<EmbedderEngine*>(engine_)->SetViewportMetrics(metrics);
ViewportMetrics metrics;
metrics.physical_width = static_cast<float>(width);
metrics.physical_height = static_cast<float>(height);
metrics.device_pixel_ratio = device_pixel_ratio;
reinterpret_cast<EmbedderEngine*>(engine_)->SetViewportMetrics(metrics);
}
int UIWidgetsPanel::RegisterTexture(void* native_texture_ptr) {

UIWIDGETS_API(void*)
SetTextureFromUnity2(void* tex, int w, int h) { return UnitySurfaceManager::SetTextureFromUnity(tex, w, h); }
static void UNITY_INTERFACE_API OnGetUnityContextEvent(int eventID)
{
UnitySurfaceManager::GetUnityContext();
}
// --------------------------------------------------------------------------
// GetRenderEventFunc, an example function we export which is used to get a rendering event callback function.
UIWIDGETS_API(UnityRenderingEvent) GetUnityContextEventFunc()
{
return OnGetUnityContextEvent;
}
static void UNITY_INTERFACE_API OnRenderEvent(int eventID)
{

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


namespace uiwidgets
{
static EGLDisplay egl_display_;
static EGLContext egl_unity_context_;
:
egl_display_(EGL_NO_DISPLAY),
: // egl_display_(EGL_NO_DISPLAY),
egl_resource_context_(EGL_NO_CONTEXT),
surface(EGL_NO_SURFACE)
egl_resource_context_(EGL_NO_CONTEXT)
{
initialize_succeeded_ = Initialize(unity_interfaces);
}

GLuint UnitySurfaceManager::CreateRenderSurface(void *native_texture_ptr, size_t width, size_t height)
GLuint UnitySurfaceManager::CreateRenderSurface(void *native_texture_ptr)
// unsigned int texture;
// glGenTextures(1, &texture);
int rowPitch = width * 4;
unsigned char *data = new unsigned char[rowPitch * height];
auto read = eglGetCurrentSurface(EGL_READ);
auto draw = eglGetCurrentSurface(EGL_DRAW);
// auto state = eglMakeCurrent(egl_display_, EGL_NO_SURFACE, EGL_NO_SURFACE, egl_context_) == GL_TRUE;
unsigned char *dst = (unsigned char *)data;
for (size_t y = 0; y < height; ++y)
{
unsigned char *ptr = dst;
for (size_t x = 0; x < width; ++x)
{
// Simple "plasma effect": several combined sine waves
int vv = 255;
GLint old_framebuffer_binding;
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &old_framebuffer_binding);
// Write the texture pixel
ptr[0] = vv;
// ptr[1] = vv;
// ptr[2] = vv;
ptr[3] = vv;
glGenFramebuffers(1, &fbo_);
glBindFramebuffer(GL_FRAMEBUFFER, fbo_);
// To next pixel (our pixels are 4 bpp)
ptr += 4;
}
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);
// To next image row
dst += rowPitch;
}
GLuint gltex = (GLuint)(size_t)(native_texture_ptr);
glBindTexture(GL_TEXTURE_2D, gltex);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data);
delete[](unsigned char *) data;
glBindFramebuffer(GL_FRAMEBUFFER, old_framebuffer_binding);
// eglMakeCurrent(egl_display_, draw, read, egl_unity_context_);
return fbo_;
}

// FML_DCHECK(fbo_ != 0);
// glDeleteFramebuffers(1, &fbo_);
// fbo_ = 0;
FML_DCHECK(fbo_ != 0);
glDeleteFramebuffers(1, &fbo_);
fbo_ = 0;
// FML_DCHECK(fbo_texture_ != 0);
// glDeleteTextures(1, &fbo_texture_);

return {success, success ? egl_config : nullptr};
}
static EGLResult<EGLSurface> CreateContext(EGLDisplay display,
EGLConfig config,
EGLContext share = EGL_NO_CONTEXT)
{
EGLint attributes[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
EGLContext context = eglCreateContext(display, config, share, attributes);
return {context != EGL_NO_CONTEXT, context};
}
void UnitySurfaceManager::GetUnityContext(){
egl_display_ = eglGetCurrentDisplay();
egl_unity_context_ = eglGetCurrentContext();
FML_CHECK(egl_display_ != EGL_NO_DISPLAY)
<< "Renderer type is invalid";
}
egl_display_ = eglGetDisplay(EGL_DEFAULT_DISPLAY);
// egl_display_ = eglGetCurrentDisplay();
// egl_resource_context_ = eglGetCurrentContext();
FML_CHECK(egl_display_ != EGL_NO_DISPLAY)
<< "Renderer type is invalid";

std::tie(success, egl_config_) = ChooseEGLConfiguration(egl_display_);
FML_CHECK(success) << "Could not choose an EGL configuration.";
const EGLint attribs[] = {EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE};
std::tie(success, egl_context_) = CreateContext(egl_display_, egl_config_, egl_unity_context_);
surface = eglCreatePbufferSurface(egl_display_, egl_config_, attribs);
success = surface != EGL_NO_SURFACE;
std::tie(success, egl_resource_context_) = CreateContext(egl_display_, egl_config_, egl_context_);
EGLint attributes[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
egl_context_ = eglCreateContext(egl_display_, egl_config_, EGL_NO_CONTEXT, attributes);
return true;
return success;
}
void UnitySurfaceManager::CleanUp()

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


{
public:
static UnitySurfaceManager instance;
static void* SetTextureFromUnity(void* tex, int w, int h);
static void GetUnityContext();
static void *SetTextureFromUnity(void *tex, int w, int h);
static void SetUp();
static void drawxxx();

GLuint CreateRenderSurface(void *native_texture_ptr, size_t width, size_t height);
GLuint CreateRenderSurface(void *native_texture_ptr);
void DestroyRenderSurface();
bool ClearCurrent();

bool Initialize(IUnityInterfaces *unity_interfaces);
void CleanUp();
#ifdef VulkanX
IUnityGraphicsVulkan *m_UnityVulkan;
UnityVulkanInstance m_Instance;
#endif
// GrBackendTexture m_backendTex;
// GrGLTextureInfo textureInfo;
// sk_sp<SkSurface> m_SkSurface;

EGLDisplay egl_display_;
#ifndef VulkanX
EGLSurface surface;
#endif
// EGLConfig egl_config_;
bool initialize_succeeded_;

32
Samples/UIWidgetsSamples_2019_4/Assets/WorkAround.cs


using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UIWidgetsSample;
using Unity.UIWidgets.ui;
using UnityEngine;
public class WorkAround : MonoBehaviour
{
[DllImport(NativeBindings.dllName)]
static extern System.IntPtr GetUnityContextEventFunc();
public CountDemo demo;
// Start is called before the first frame update
void Start()
{
GL.IssuePluginEvent(GetUnityContextEventFunc(), 1);
// demo = GetComponent<CountDemo>();
}
// Update is called once per frame
void Update()
{
if (!demo.enabled)
{
demo.enabled = true;
this.enabled = false;
}
}
}
正在加载...
取消
保存