浏览代码

stash changes

/siyaoH-1.17-PlatformMessage
xingweizhu 4 年前
当前提交
58acea59
共有 5 个文件被更改,包括 118 次插入54 次删除
  1. 67
      com.unity.uiwidgets/Runtime/engine/UIWidgetsPanelWrapper.cs
  2. 41
      engine/src/shell/platform/unity/windows/uiwidgets_panel.cc
  3. 4
      engine/src/shell/platform/unity/windows/uiwidgets_panel.h
  4. 53
      engine/src/shell/platform/unity/windows/unity_surface_manager.cc
  5. 7
      engine/src/shell/platform/unity/windows/unity_surface_manager.h

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


#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
public partial class UIWidgetsPanelWrapper {
public RenderTexture renderTexture { get; private set; }
Texture _renderTexture;
public Texture renderTexture {
get { return _renderTexture; }
}
D.assert(renderTexture == null);
var desc = new RenderTextureDescriptor(
width: width, height: height, colorFormat: RenderTextureFormat.ARGB32, 0) {
useMipMap = false,
autoGenerateMips = false
};
renderTexture = new RenderTexture(desc: desc) {hideFlags = HideFlags.HideAndDontSave};
renderTexture.Create();
D.assert(_renderTexture == null);
_width = width;
_height = height;

void _destroyRenderTexture() {
D.assert(renderTexture != null);
ObjectUtils.SafeDestroy(obj: renderTexture);
renderTexture = null;
D.assert(_renderTexture != null);
var releaseOK = UIWidgetsPanel_releaseNativeTexture(_ptr);
D.assert(releaseOK);
_renderTexture = null;
UIWidgetsPanel_onEnable(ptr: _ptr, renderTexture.GetNativeTexturePtr(),
width: _width, height: _height, dpi: devicePixelRatio,
streamingAssetsPath: Application.streamingAssetsPath, font_settings: font_settings);
D.assert(_renderTexture == null);
IntPtr native_tex_ptr = UIWidgetsPanel_onEnable(_ptr, _width, _height, devicePixelRatio,
Application.streamingAssetsPath, font_settings);
D.assert(native_tex_ptr != IntPtr.Zero);
_renderTexture =
Texture2D.CreateExternalTexture(_width, _height, TextureFormat.BGRA32, false, true, native_tex_ptr);
}
void _disableUIWidgetsPanel() {
_renderTexture = null;
UIWidgetsPanel_onRenderTexture(ptr: _ptr,
renderTexture.GetNativeTexturePtr(),
width: _width, height: _height, dpi: devicePixelRatio);
D.assert(_renderTexture == null);
IntPtr native_tex_ptr = UIWidgetsPanel_onRenderTexture(_ptr, _width, _height, devicePixelRatio);
D.assert(native_tex_ptr != IntPtr.Zero);
_renderTexture =
Texture2D.CreateExternalTexture(_width, _height, TextureFormat.BGRA32, false, true, native_tex_ptr);
void _disableUIWidgetsPanel() {
renderTexture = null;
}
[DllImport(NativeBindings.dllName)]
static extern IntPtr UIWidgetsPanel_onEnable(IntPtr ptr,
int width, int height, float dpi, string streamingAssetsPath, string font_settings);
[DllImport(dllName: 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 bool UIWidgetsPanel_releaseNativeTexture(IntPtr ptr);
[DllImport(dllName: NativeBindings.dllName)]
static extern void UIWidgetsPanel_onRenderTexture(
IntPtr ptr, IntPtr nativeTexturePtr, int width, int height, float dpi);
[DllImport(NativeBindings.dllName)]
static extern IntPtr UIWidgetsPanel_onRenderTexture(
IntPtr ptr, int width, int height, float dpi);
}
#endif

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


return window_type_ == EditorWindowPanel;
}
void UIWidgetsPanel::OnEnable(void* native_texture_ptr, size_t width,
void* 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);
//return surface_manager_->CreateRenderTexture(width, height);
fbo_ = surface_manager_->CreateRenderSurface(width, height);
void* d3dtexture = surface_manager_->GetD3DInnerTexture();
surface_manager_->ClearCurrent();
fml::AutoResetWaitableEvent latch;

if (result != kSuccess || engine == nullptr) {
std::cerr << "Failed to start UIWidgets engine: error " << result
<< std::endl;
return;
return nullptr;
}
engine_ = engine;

process_events_ = true;
return static_cast<void*>(d3dtexture);
}
void UIWidgetsPanel::MonoEntrypoint() { entrypoint_callback_(handle_); }

surface_manager_ = nullptr;
}
void UIWidgetsPanel::OnRenderTexture(void* native_texture_ptr, size_t width,
void* UIWidgetsPanel::OnRenderTexture(size_t width,
fml::AutoResetWaitableEvent latch;
/*fml::AutoResetWaitableEvent latch;
reinterpret_cast<EmbedderEngine*>(engine_)->PostRenderThreadTask(
[&latch, this, native_texture_ptr]() -> void {
surface_manager_->MakeCurrent(EGL_NO_DISPLAY);

fbo_ = 0;
}
fbo_ = surface_manager_->CreateRenderSurface(native_texture_ptr);
fbo_ = surface_manager_->CreateRenderSurface(width, height);
latch.Wait();
latch.Wait();*/
ViewportMetrics metrics;
metrics.physical_width = static_cast<float>(width);

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

panel->Release();
}
UIWIDGETS_API(void)
UIWidgetsPanel_onEnable(UIWidgetsPanel* panel, void* native_texture_ptr,
UIWIDGETS_API(void*)
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);
}

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

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


~UIWidgetsPanel();
void OnEnable(void* native_texture_ptr, size_t width, size_t height,
void* 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,
void* OnRenderTexture(size_t width, size_t height,
float dpi);
int RegisterTexture(void* native_texture_ptr);

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


UnitySurfaceManager::~UnitySurfaceManager() { CleanUp(); }
GLuint UnitySurfaceManager::CreateRenderSurface(void* native_texture_ptr) {
ID3D11Texture2D* d3d11_texture =
static_cast<ID3D11Texture2D*>(native_texture_ptr);
void* UnitySurfaceManager::CreateRenderTexture(size_t width, size_t height) {
D3D11_TEXTURE2D_DESC desc = {0};
desc.Width = width;
desc.Height = height;
desc.MipLevels = 0;
desc.ArraySize = 1;
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
desc.CPUAccessFlags = 0;
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);
}
GLuint UnitySurfaceManager::CreateRenderSurface(size_t width, size_t height) {
CreateRenderTexture(width, height);
//ID3D11Texture2D* d3d11_texture =
// static_cast<ID3D11Texture2D*>(native_texture_ptr);
IDXGIResource* image_resource;
HRESULT hr = d3d11_texture->QueryInterface(
__uuidof(IDXGIResource), reinterpret_cast<void**>(&image_resource));

hr = image_resource->GetSharedHandle(&shared_image_handle);
hr = image_resource->GetSharedHandle(&shared_image_handle);
FML_CHECK(SUCCEEDED(hr)) << "UnitySurfaceManager: GetSharedHandle() failed";
image_resource->Release();

dxgi_resource->Release();
MakeCurrent(EGL_NO_DISPLAY);
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);
FML_CHECK(glCheckFramebufferStatus(GL_FRAMEBUFFER) ==
auto flag = glCheckFramebufferStatus(GL_FRAMEBUFFER);
FML_CHECK(flag ==
GL_FRAMEBUFFER_COMPLETE);
glBindFramebuffer(GL_FRAMEBUFFER, old_framebuffer_binding);

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


UnitySurfaceManager(IUnityInterfaces* unity_interfaces);
~UnitySurfaceManager();
GLuint CreateRenderSurface(void* native_texture_ptr);
GLuint CreateRenderSurface(size_t width, size_t height);
void*CreateRenderTexture(size_t width, size_t height);
void DestroyRenderSurface();
bool ClearCurrent();

ID3D11Device* GetD3D11Device() const { return d3d11_device_; }
void* GetD3DInnerTexture() const { return static_cast<void*>(d3d11_resource_view); }
FML_DISALLOW_COPY_AND_ASSIGN(UnitySurfaceManager);
private:

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

正在加载...
取消
保存