浏览代码

bug fixes

/siyaoH-1.17-PlatformMessage
xingweizhu 3 年前
当前提交
7ef3ff70
共有 5 个文件被更改,包括 49 次插入61 次删除
  1. 4
      com.unity.uiwidgets/Runtime/engine/UIWidgetsPanelWrapper.cs
  2. 27
      engine/src/shell/platform/unity/windows/uiwidgets_panel.cc
  3. 2
      engine/src/shell/platform/unity/windows/uiwidgets_panel.h
  4. 68
      engine/src/shell/platform/unity/windows/unity_surface_manager.cc
  5. 9
      engine/src/shell/platform/unity/windows/unity_surface_manager.h

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


D.assert(native_tex_ptr != IntPtr.Zero);
_renderTexture =
Texture2D.CreateExternalTexture(_width, _height, TextureFormat.BGRA32, false, true, native_tex_ptr);
Texture2D.CreateExternalTexture(_width, _height, TextureFormat.RGBAFloat, false, true, native_tex_ptr);
}
void _disableUIWidgetsPanel() {

D.assert(native_tex_ptr != IntPtr.Zero);
_renderTexture =
Texture2D.CreateExternalTexture(_width, _height, TextureFormat.BGRA32, false, true, native_tex_ptr);
Texture2D.CreateExternalTexture(_width, _height, TextureFormat.RGBAFloat, false, true, native_tex_ptr);
}
[DllImport(NativeBindings.dllName)]

27
engine/src/shell/platform/unity/windows/uiwidgets_panel.cc


//return surface_manager_->CreateRenderTexture(width, height);
surface_manager_->ClearCurrent();
fml::AutoResetWaitableEvent latch;

void UIWidgetsPanel::MonoEntrypoint() { entrypoint_callback_(handle_); }
void UIWidgetsPanel::OnDisable() {
process_events_ = false;
UIWidgetsSystem::GetInstancePtr()->UnregisterPanel(this);

if (fbo_) {
surface_manager_->MakeCurrent(EGL_NO_DISPLAY);
surface_manager_->DestroyRenderSurface();
surface_manager_->ReleaseNativeRenderTexture();
fbo_ = 0;
surface_manager_->ClearCurrent();

void* UIWidgetsPanel::OnRenderTexture(size_t width,
size_t height, float device_pixel_ratio) {
/*fml::AutoResetWaitableEvent latch;
reinterpret_cast<EmbedderEngine*>(engine_)->PostRenderThreadTask(
[&latch, this, native_texture_ptr]() -> void {
surface_manager_->MakeCurrent(EGL_NO_DISPLAY);
if (fbo_) {
surface_manager_->DestroyRenderSurface();
fbo_ = 0;
}
fbo_ = surface_manager_->CreateRenderSurface(width, height);
surface_manager_->ClearCurrent();
latch.Signal();
});
latch.Wait();*/
ViewportMetrics metrics;
metrics.physical_width = static_cast<float>(width);
metrics.physical_height = static_cast<float>(height);

fbo_ = surface_manager_->CreateRenderSurface(width, height);
return static_cast<void*>(surface_manager_->GetD3DInnerTexture());
}
bool UIWidgetsPanel::ReleaseNativeRenderTexture() { return surface_manager_->ReleaseNativeRenderTexture(); }
int UIWidgetsPanel::RegisterTexture(void* native_texture_ptr) {
int texture_identifier = 0;

}
UIWIDGETS_API(bool) UIWidgetsPanel_releaseNativeTexture(UIWidgetsPanel* panel) {
return true;
return panel->ReleaseNativeRenderTexture();
}
UIWIDGETS_API(void*)

2
engine/src/shell/platform/unity/windows/uiwidgets_panel.h


void* OnRenderTexture(size_t width, size_t height,
float dpi);
bool ReleaseNativeRenderTexture();
int RegisterTexture(void* native_texture_ptr);

68
engine/src/shell/platform/unity/windows/unity_surface_manager.cc


#include <d3d11.h>
#include <dxgi.h>
#include <flutter/fml/logging.h>
#include "uiwidgets_system.h"
#include "Unity/IUnityGraphics.h"
#include "Unity/IUnityGraphicsD3D11.h"

D3D11_TEXTURE2D_DESC desc = {0};
desc.Width = width;
desc.Height = height;
desc.MipLevels = 0;
desc.MipLevels = 1;
desc.ArraySize = 1;
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
desc.SampleDesc.Count = 1;

desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED;
HRESULT hr = d3d11_device_->CreateTexture2D(&desc, nullptr, &d3d11_texture);
FML_CHECK(SUCCEEDED(hr)) << "UnitySurfaceManager: Create texture failed";
D3D11_SHADER_RESOURCE_VIEW_DESC viewDesc;
viewDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
viewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
viewDesc.Texture2D.MostDetailedMip = 0;
viewDesc.Texture2D.MipLevels = 1;
hr = d3d11_device_->CreateShaderResourceView(d3d11_texture, &viewDesc, &d3d11_resource_view);
FML_CHECK(SUCCEEDED(hr)) << "UnitySurfaceManager: Create resource view failed";
return static_cast<void*>(d3d11_texture);
}

//ID3D11Texture2D* d3d11_texture =
// static_cast<ID3D11Texture2D*>(native_texture_ptr);
IDXGIResource* image_resource;
HRESULT hr = d3d11_texture->QueryInterface(
__uuidof(IDXGIResource), reinterpret_cast<void**>(&image_resource));

"D3D11_RESOURCE_MISC_SHARED is needed";
IDXGIResource* dxgi_resource;
hr = d3d11_device_->OpenSharedResource(
hr = d3d11_angle_device_->OpenSharedResource(
shared_image_handle, __uuidof(ID3D11Resource),
reinterpret_cast<void**>(&dxgi_resource));
FML_CHECK(SUCCEEDED(hr))

MakeCurrent(EGL_NO_DISPLAY);
const EGLint attribs[] = {EGL_NONE};
//FML_DCHECK(fbo_egl_image_ == nullptr);
FML_DCHECK(fbo_egl_image_ == nullptr);
fbo_egl_image_ =
eglCreateImageKHR(egl_display_, EGL_NO_CONTEXT, EGL_D3D11_TEXTURE_ANGLE,
static_cast<EGLClientBuffer>(image_texture), attribs);

GLint old_texture_binding_2d;
glGetIntegerv(GL_TEXTURE_BINDING_2D, &old_texture_binding_2d);
//FML_DCHECK(fbo_texture_ == 0);
FML_DCHECK(fbo_texture_ == 0);
glGenTextures(1, &fbo_texture_);
glBindTexture(GL_TEXTURE_2D, fbo_texture_);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

GLint old_framebuffer_binding;
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &old_framebuffer_binding);
//FML_DCHECK(fbo_ == 0);
FML_DCHECK(fbo_ == 0);
glGenFramebuffers(1, &fbo_);
glBindFramebuffer(GL_FRAMEBUFFER, fbo_);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,

return fbo_;
}
void UnitySurfaceManager::DestroyRenderSurface() {
FML_DCHECK(fbo_ != 0);
glDeleteFramebuffers(1, &fbo_);
fbo_ = 0;
FML_DCHECK(fbo_texture_ != 0);
glDeleteTextures(1, &fbo_texture_);
fbo_texture_ = 0;
FML_DCHECK(fbo_egl_image_ != nullptr);
eglDestroyImageKHR(egl_display_, fbo_egl_image_);
fbo_egl_image_ = nullptr;
}
bool UnitySurfaceManager::ClearCurrent() {
return eglMakeCurrent(egl_display_, EGL_NO_SURFACE, EGL_NO_SURFACE,
EGL_NO_CONTEXT) == EGL_TRUE;

IUnityGraphicsD3D11* d3d11 = unity_interfaces->Get<IUnityGraphicsD3D11>();
ID3D11Device* d3d11_device = d3d11->GetDevice();
d3d11_device_ = d3d11_device;
IDXGIDevice* dxgi_device;
HRESULT hr = d3d11_device->QueryInterface(

EGLAttrib angle_device = 0;
eglQueryDeviceAttribEXT(reinterpret_cast<EGLDeviceEXT>(egl_device),
EGL_D3D11_DEVICE_ANGLE, &angle_device);
d3d11_device_ = reinterpret_cast<ID3D11Device*>(angle_device);
d3d11_angle_device_ = reinterpret_cast<ID3D11Device*>(angle_device);
const EGLint configAttributes[] = {EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 8,

}
d3d11_device_ = nullptr;
d3d11_angle_device_ = nullptr;
}
bool UnitySurfaceManager::ReleaseNativeRenderTexture() {
if (d3d11_texture == nullptr) {
return true;
}
FML_DCHECK(fbo_ != 0);
glDeleteFramebuffers(1, &fbo_);
fbo_ = 0;
FML_DCHECK(fbo_texture_ != 0);
glDeleteTextures(1, &fbo_texture_);
fbo_texture_ = 0;
FML_DCHECK(fbo_egl_image_ != nullptr);
eglDestroyImageKHR(egl_display_, fbo_egl_image_);
fbo_egl_image_ = nullptr;
d3d11_texture->Release();
d3d11_texture = nullptr;
return true;

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


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

EGLDisplay GetEGLDisplay() const { return egl_display_; }
ID3D11Device* GetD3D11Device() const { return d3d11_device_; }
ID3D11Device* GetD3D11Device() const { return d3d11_angle_device_; }
void* GetD3DInnerTexture() const { return static_cast<void*>(d3d11_resource_view); }
void* GetD3DInnerTexture() const { return static_cast<void*>(d3d11_texture); }
FML_DISALLOW_COPY_AND_ASSIGN(UnitySurfaceManager);

EGLConfig egl_config_;
bool initialize_succeeded_;
ID3D11Device* d3d11_device_;
ID3D11Device* d3d11_angle_device_;
ID3D11ShaderResourceView* d3d11_resource_view;
EGLImage fbo_egl_image_ = nullptr;
GLuint fbo_texture_ = 0;

正在加载...
取消
保存