commit ed77b1a8cdee42203ff785409e2de60ca5f472bc Author: hecomi Date: Thu Oct 27 15:36:29 2016 +0900 initial commit. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e08563d --- /dev/null +++ b/.gitignore @@ -0,0 +1,25 @@ +# Unity3D temporary directories +/[Ll]ibrary/ +/[Tt]emp/ +/[Oo]bj/ +/[Bb]uild/ + +# Autogenerated VS/MD solution and project files +*.csproj +*.unityproj +*.sln +*.suo +*.tmp +*.user +*.userprefs +*.pidb +*.booproj + +# Unity3D generated meta files +*.pidb.meta + +# Unity3D Generated File On Crash Reports +sysinfo.txt + +# Others +.DS_Store diff --git a/Assets/uDesktopDuplication.meta b/Assets/uDesktopDuplication.meta new file mode 100644 index 0000000..6f4f7b1 --- /dev/null +++ b/Assets/uDesktopDuplication.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 6cafb37e09eca694285c387022c33179 +folderAsset: yes +timeCreated: 1477544983 +licenseType: Pro +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/uDesktopDuplication/Materials.meta b/Assets/uDesktopDuplication/Materials.meta new file mode 100644 index 0000000..afd68c2 --- /dev/null +++ b/Assets/uDesktopDuplication/Materials.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 168bfc51ae38cb945b9cbb64e3c15a3a +folderAsset: yes +timeCreated: 1452486970 +licenseType: Pro +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/uDesktopDuplication/Materials/NativeTexture.mat b/Assets/uDesktopDuplication/Materials/NativeTexture.mat new file mode 100644 index 0000000..1570aa2 Binary files /dev/null and b/Assets/uDesktopDuplication/Materials/NativeTexture.mat differ diff --git a/Assets/uDesktopDuplication/Materials/NativeTexture.mat.meta b/Assets/uDesktopDuplication/Materials/NativeTexture.mat.meta new file mode 100644 index 0000000..1c26222 --- /dev/null +++ b/Assets/uDesktopDuplication/Materials/NativeTexture.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c181d333a7bee7a44b94c0f4e02c4bd4 +timeCreated: 1452176604 +licenseType: Pro +NativeFormatImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/uDesktopDuplication/Plugins.meta b/Assets/uDesktopDuplication/Plugins.meta new file mode 100644 index 0000000..e47593b --- /dev/null +++ b/Assets/uDesktopDuplication/Plugins.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 82fa7e3d8c4d04f429e44f2a44f7c94a +folderAsset: yes +timeCreated: 1452530215 +licenseType: Pro +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/uDesktopDuplication/Plugins/uDesktopDuplication.dll b/Assets/uDesktopDuplication/Plugins/uDesktopDuplication.dll new file mode 100644 index 0000000..5687770 Binary files /dev/null and b/Assets/uDesktopDuplication/Plugins/uDesktopDuplication.dll differ diff --git a/Assets/uDesktopDuplication/Plugins/uDesktopDuplication.dll.meta b/Assets/uDesktopDuplication/Plugins/uDesktopDuplication.dll.meta new file mode 100644 index 0000000..e1c5b83 --- /dev/null +++ b/Assets/uDesktopDuplication/Plugins/uDesktopDuplication.dll.meta @@ -0,0 +1,20 @@ +fileFormatVersion: 2 +guid: 02fc121822cf2ea4e82e16c4a28bf711 +timeCreated: 1477546714 +licenseType: Pro +PluginImporter: + serializedVersion: 1 + iconMap: {} + executionOrder: {} + isPreloaded: 0 + platformData: + Any: + enabled: 1 + settings: {} + Editor: + enabled: 0 + settings: + DefaultValueInitialized: true + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/uDesktopDuplication/Scenes.meta b/Assets/uDesktopDuplication/Scenes.meta new file mode 100644 index 0000000..d556f18 --- /dev/null +++ b/Assets/uDesktopDuplication/Scenes.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 4916b05f682614c478174c4863f32ca2 +folderAsset: yes +timeCreated: 1452486965 +licenseType: Pro +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/uDesktopDuplication/Scenes/Example.unity b/Assets/uDesktopDuplication/Scenes/Example.unity new file mode 100644 index 0000000..5b01201 Binary files /dev/null and b/Assets/uDesktopDuplication/Scenes/Example.unity differ diff --git a/Assets/uDesktopDuplication/Scenes/Example.unity.meta b/Assets/uDesktopDuplication/Scenes/Example.unity.meta new file mode 100644 index 0000000..2d9a488 --- /dev/null +++ b/Assets/uDesktopDuplication/Scenes/Example.unity.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f9bfdaaf005950544860a1f6efad2925 +timeCreated: 1452176573 +licenseType: Pro +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/uDesktopDuplication/Scripts.meta b/Assets/uDesktopDuplication/Scripts.meta new file mode 100644 index 0000000..15e3772 --- /dev/null +++ b/Assets/uDesktopDuplication/Scripts.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 1d35b933a9534f04991d5fd4d32b59fc +folderAsset: yes +timeCreated: 1452486935 +licenseType: Pro +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/uDesktopDuplication/Scripts/uDesktopDuplication.cs b/Assets/uDesktopDuplication/Scripts/uDesktopDuplication.cs new file mode 100644 index 0000000..9479d8d --- /dev/null +++ b/Assets/uDesktopDuplication/Scripts/uDesktopDuplication.cs @@ -0,0 +1,62 @@ +using UnityEngine; +using System; +using System.Collections; +using System.Runtime.InteropServices; + +public class uDesktopDuplication : MonoBehaviour +{ + [DllImport("uDesktopDuplication")] + private static extern void Initialize(); + [DllImport("uDesktopDuplication")] + private static extern int GetWidth(); + [DllImport("uDesktopDuplication")] + private static extern int GetHeight(); + [DllImport("uDesktopDuplication")] + private static extern bool IsPointerVisible(); + [DllImport("uDesktopDuplication")] + private static extern int GetPointerX(); + [DllImport("uDesktopDuplication")] + private static extern int GetPointerY(); + [DllImport("uDesktopDuplication")] + private static extern int SetTexturePtr(IntPtr ptr); + [DllImport("uDesktopDuplication")] + private static extern IntPtr GetRenderEventFunc(); + + public bool isPointerVisible = false; + public int pointerX = 0; + public int pointerY = 0; + + Coroutine renderCoroutine_ = null; + + void OnEnable() + { + var tex = new Texture2D(GetWidth(), GetHeight(), TextureFormat.BGRA32, false); + GetComponent().sharedMaterial.mainTexture = tex; + + SetTexturePtr(tex.GetNativeTexturePtr()); + renderCoroutine_ = StartCoroutine(OnRender()); + } + + void OnDisable() + { + if (renderCoroutine_ != null) { + StopCoroutine(renderCoroutine_); + renderCoroutine_ = null; + } + } + + void Update() + { + isPointerVisible = IsPointerVisible(); + pointerX = GetPointerX(); + pointerY = GetPointerY(); + } + + IEnumerator OnRender() + { + for (;;) { + yield return new WaitForEndOfFrame(); + GL.IssuePluginEvent(GetRenderEventFunc(), 0); + } + } +} \ No newline at end of file diff --git a/Assets/uDesktopDuplication/Scripts/uDesktopDuplication.cs.meta b/Assets/uDesktopDuplication/Scripts/uDesktopDuplication.cs.meta new file mode 100644 index 0000000..4b7ab66 --- /dev/null +++ b/Assets/uDesktopDuplication/Scripts/uDesktopDuplication.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: bb54a34570e4747429b1c5b66c69d356 +timeCreated: 1452445649 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Plugins/uDesktopDuplication/.gitignore b/Plugins/uDesktopDuplication/.gitignore new file mode 100644 index 0000000..62dd6c9 --- /dev/null +++ b/Plugins/uDesktopDuplication/.gitignore @@ -0,0 +1,272 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +project.fragment.lock.json +artifacts/ +Properties/launchSettings.json + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/ diff --git a/Plugins/uDesktopDuplication/uDesktopDuplication/IUnityGraphics.h b/Plugins/uDesktopDuplication/uDesktopDuplication/IUnityGraphics.h new file mode 100644 index 0000000..edf4a6b --- /dev/null +++ b/Plugins/uDesktopDuplication/uDesktopDuplication/IUnityGraphics.h @@ -0,0 +1,49 @@ +#pragma once +#include "IUnityInterface.h" + +typedef enum UnityGfxRenderer +{ + kUnityGfxRendererOpenGL = 0, // Desktop OpenGL 2 (deprecated) + kUnityGfxRendererD3D9 = 1, // Direct3D 9 + kUnityGfxRendererD3D11 = 2, // Direct3D 11 + kUnityGfxRendererGCM = 3, // PlayStation 3 + kUnityGfxRendererNull = 4, // "null" device (used in batch mode) + kUnityGfxRendererXenon = 6, // Xbox 360 + kUnityGfxRendererOpenGLES20 = 8, // OpenGL ES 2.0 + kUnityGfxRendererOpenGLES30 = 11, // OpenGL ES 3.x + kUnityGfxRendererGXM = 12, // PlayStation Vita + kUnityGfxRendererPS4 = 13, // PlayStation 4 + kUnityGfxRendererXboxOne = 14, // Xbox One + kUnityGfxRendererMetal = 16, // iOS Metal + kUnityGfxRendererOpenGLCore = 17, // Desktop OpenGL core + kUnityGfxRendererD3D12 = 18, // Direct3D 12 +} UnityGfxRenderer; + +typedef enum UnityGfxDeviceEventType +{ + kUnityGfxDeviceEventInitialize = 0, + kUnityGfxDeviceEventShutdown = 1, + kUnityGfxDeviceEventBeforeReset = 2, + kUnityGfxDeviceEventAfterReset = 3, +} UnityGfxDeviceEventType; + +typedef void (UNITY_INTERFACE_API * IUnityGraphicsDeviceEventCallback)(UnityGfxDeviceEventType eventType); + +// Should only be used on the rendering thread unless noted otherwise. +UNITY_DECLARE_INTERFACE(IUnityGraphics) +{ + UnityGfxRenderer (UNITY_INTERFACE_API * GetRenderer)(); // Thread safe + + // This callback will be called when graphics device is created, destroyed, reset, etc. + // It is possible to miss the kUnityGfxDeviceEventInitialize event in case plugin is loaded at a later time, + // when the graphics device is already created. + void (UNITY_INTERFACE_API * RegisterDeviceEventCallback)(IUnityGraphicsDeviceEventCallback callback); + void (UNITY_INTERFACE_API * UnregisterDeviceEventCallback)(IUnityGraphicsDeviceEventCallback callback); +}; +UNITY_REGISTER_INTERFACE_GUID(0x7CBA0A9CA4DDB544ULL,0x8C5AD4926EB17B11ULL,IUnityGraphics) + + + +// Certain Unity APIs (GL.IssuePluginEvent, CommandBuffer.IssuePluginEvent) can callback into native plugins. +// Provide them with an address to a function of this signature. +typedef void (UNITY_INTERFACE_API * UnityRenderingEvent)(int eventId); diff --git a/Plugins/uDesktopDuplication/uDesktopDuplication/IUnityGraphicsD3D11.h b/Plugins/uDesktopDuplication/uDesktopDuplication/IUnityGraphicsD3D11.h new file mode 100644 index 0000000..a3f4c8b --- /dev/null +++ b/Plugins/uDesktopDuplication/uDesktopDuplication/IUnityGraphicsD3D11.h @@ -0,0 +1,9 @@ +#pragma once +#include "IUnityInterface.h" + +// Should only be used on the rendering thread unless noted otherwise. +UNITY_DECLARE_INTERFACE(IUnityGraphicsD3D11) +{ + ID3D11Device* (UNITY_INTERFACE_API * GetDevice)(); +}; +UNITY_REGISTER_INTERFACE_GUID(0xAAB37EF87A87D748ULL,0xBF76967F07EFB177ULL,IUnityGraphicsD3D11) diff --git a/Plugins/uDesktopDuplication/uDesktopDuplication/IUnityInterface.h b/Plugins/uDesktopDuplication/uDesktopDuplication/IUnityInterface.h new file mode 100644 index 0000000..25073e0 --- /dev/null +++ b/Plugins/uDesktopDuplication/uDesktopDuplication/IUnityInterface.h @@ -0,0 +1,148 @@ +#pragma once + +// Unity native plugin API +// Compatible with C99 + +#if defined(__CYGWIN32__) + #define UNITY_INTERFACE_API __stdcall + #define UNITY_INTERFACE_EXPORT __declspec(dllexport) +#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) || defined(WINAPI_FAMILY) + #define UNITY_INTERFACE_API __stdcall + #define UNITY_INTERFACE_EXPORT __declspec(dllexport) +#elif defined(__MACH__) || defined(__ANDROID__) || defined(__linux__) || defined(__QNX__) + #define UNITY_INTERFACE_API + #define UNITY_INTERFACE_EXPORT +#else + #define UNITY_INTERFACE_API + #define UNITY_INTERFACE_EXPORT +#endif + + + +// Unity Interface GUID +// Ensures cross plugin uniqueness. +// +// Template specialization is used to produce a means of looking up a GUID from it's payload type at compile time. +// The net result should compile down to passing around the GUID. +// +// UNITY_REGISTER_INTERFACE_GUID should be placed in the header file of any payload definition outside of all namespaces. +// The payload structure and the registration GUID are all that is required to expose the interface to other systems. +struct UnityInterfaceGUID +{ +#ifdef __cplusplus + UnityInterfaceGUID(unsigned long long high, unsigned long long low) + : m_GUIDHigh(high) + , m_GUIDLow(low) + { + } + + UnityInterfaceGUID(const UnityInterfaceGUID& other) + { + m_GUIDHigh = other.m_GUIDHigh; + m_GUIDLow = other.m_GUIDLow; + } + + UnityInterfaceGUID& operator=(const UnityInterfaceGUID& other) + { + m_GUIDHigh = other.m_GUIDHigh; + m_GUIDLow = other.m_GUIDLow; + return *this; + } + + bool Equals(const UnityInterfaceGUID& other) const { return m_GUIDHigh == other.m_GUIDHigh && m_GUIDLow == other.m_GUIDLow; } + bool LessThan(const UnityInterfaceGUID& other) const { return m_GUIDHigh < other.m_GUIDHigh || (m_GUIDHigh == other.m_GUIDHigh && m_GUIDLow < other.m_GUIDLow); } +#endif + unsigned long long m_GUIDHigh; + unsigned long long m_GUIDLow; +}; +#ifdef __cplusplus +inline bool operator==(const UnityInterfaceGUID& left, const UnityInterfaceGUID& right) { return left.Equals(right); } +inline bool operator!=(const UnityInterfaceGUID& left, const UnityInterfaceGUID& right) { return !left.Equals(right); } +inline bool operator< (const UnityInterfaceGUID& left, const UnityInterfaceGUID& right) { return left.LessThan(right); } +inline bool operator> (const UnityInterfaceGUID& left, const UnityInterfaceGUID& right) { return right.LessThan(left); } +inline bool operator>=(const UnityInterfaceGUID& left, const UnityInterfaceGUID& right) { return !operator< (left,right); } +inline bool operator<=(const UnityInterfaceGUID& left, const UnityInterfaceGUID& right) { return !operator> (left,right); } +#else +typedef struct UnityInterfaceGUID UnityInterfaceGUID; +#endif + + + +#define UNITY_GET_INTERFACE_GUID(TYPE) TYPE##_GUID +#define UNITY_GET_INTERFACE(INTERFACES, TYPE) (TYPE*)INTERFACES->GetInterface(UNITY_GET_INTERFACE_GUID(TYPE)); + +#ifdef __cplusplus + #define UNITY_DECLARE_INTERFACE(NAME) \ + struct NAME : IUnityInterface + + template \ + inline const UnityInterfaceGUID GetUnityInterfaceGUID(); \ + + #define UNITY_REGISTER_INTERFACE_GUID(HASHH, HASHL, TYPE) \ + const UnityInterfaceGUID TYPE##_GUID(HASHH, HASHL); \ + template<> \ + inline const UnityInterfaceGUID GetUnityInterfaceGUID() \ + { \ + return UNITY_GET_INTERFACE_GUID(TYPE); \ + } +#else + #define UNITY_DECLARE_INTERFACE(NAME) \ + typedef struct NAME NAME; \ + struct NAME + + #define UNITY_REGISTER_INTERFACE_GUID(HASHH, HASHL, TYPE) \ + const UnityInterfaceGUID TYPE##_GUID = {HASHH, HASHL}; +#endif + + + +#ifdef __cplusplus +struct IUnityInterface +{ +}; +#else +typedef void IUnityInterface; +#endif + + + +typedef struct IUnityInterfaces +{ + // Returns an interface matching the guid. + // Returns nullptr if the given interface is unavailable in the active Unity runtime. + IUnityInterface* (UNITY_INTERFACE_API * GetInterface)(UnityInterfaceGUID guid); + + // Registers a new interface. + void (UNITY_INTERFACE_API * RegisterInterface)(UnityInterfaceGUID guid, IUnityInterface* ptr); + +#ifdef __cplusplus + // Helper for GetInterface. + template + INTERFACE* Get() + { + return static_cast(GetInterface(GetUnityInterfaceGUID())); + } + + // Helper for RegisterInterface. + template + void Register(IUnityInterface* ptr) + { + RegisterInterface(GetUnityInterfaceGUID(), ptr); + } +#endif +} IUnityInterfaces; + + + +#ifdef __cplusplus +extern "C" { +#endif + +// If exported by a plugin, this function will be called when the plugin is loaded. +void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityPluginLoad(IUnityInterfaces* unityInterfaces); +// If exported by a plugin, this function will be called when the plugin is about to be unloaded. +void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityPluginUnload(); + +#ifdef __cplusplus +} +#endif diff --git a/Plugins/uDesktopDuplication/uDesktopDuplication/main.cpp b/Plugins/uDesktopDuplication/uDesktopDuplication/main.cpp new file mode 100644 index 0000000..166829a --- /dev/null +++ b/Plugins/uDesktopDuplication/uDesktopDuplication/main.cpp @@ -0,0 +1,179 @@ +#include +#include + +#include "IUnityInterface.h" +#include "IUnityGraphics.h" +#include "IUnityGraphicsD3D11.h" + +#pragma comment(lib, "dxgi.lib") + + +namespace +{ + IUnityInterfaces* g_unity = nullptr; + IDXGIOutputDuplication* g_deskDupl = nullptr; + ID3D11Texture2D* g_texture = nullptr; + bool g_isPointerVisible = -1; + int g_pointerX = -1; + int g_pointerY = -1; + int g_width = -1; + int g_height = -1; +} + + +extern "C" +{ + void InitializeDuplication() + { + IDXGIFactory1* factory; + CreateDXGIFactory1(__uuidof(IDXGIFactory1), reinterpret_cast(&factory)); + + // Check all display adapters. + IDXGIAdapter1* adapter; + for (int i = 0; (factory->EnumAdapters1(i, &adapter) != DXGI_ERROR_NOT_FOUND); ++i) + { + // Search the main monitor from all outputs. + IDXGIOutput* output; + for (int j = 0; (adapter->EnumOutputs(j, &output) != DXGI_ERROR_NOT_FOUND); j++) + { + DXGI_OUTPUT_DESC outputDesc; + output->GetDesc(&outputDesc); + + MONITORINFOEX monitorInfo; + monitorInfo.cbSize = sizeof(MONITORINFOEX); + GetMonitorInfo(outputDesc.Monitor, &monitorInfo); + + if (monitorInfo.dwFlags == MONITORINFOF_PRIMARY) + { + g_width = monitorInfo.rcMonitor.right - monitorInfo.rcMonitor.left; + g_height = monitorInfo.rcMonitor.bottom - monitorInfo.rcMonitor.top; + + auto device = g_unity->Get()->GetDevice(); + IDXGIOutput1* output1; + output1 = reinterpret_cast(output); + output1->DuplicateOutput(device, &g_deskDupl); + + output->Release(); + adapter->Release(); + factory->Release(); + + return; + } + + output->Release(); + } + + adapter->Release(); + } + + factory->Release(); + } + + void FinalizeDuplication() + { + g_deskDupl->Release(); + g_deskDupl = nullptr; + } + + UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API UnityPluginLoad(IUnityInterfaces* unityInterfaces) + { + g_unity = unityInterfaces; + InitializeDuplication(); + } + + UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API UnityPluginUnload() + { + g_unity = nullptr; + g_texture = nullptr; + g_width = -1; + g_height = -1; + g_pointerX = -1; + g_pointerY = -1; + FinalizeDuplication(); + } + + void UNITY_INTERFACE_API OnRenderEvent(int eventId) + { + if (g_deskDupl == nullptr || g_texture == nullptr) return; + + HRESULT hr; + IDXGIResource* resource = nullptr; + DXGI_OUTDUPL_FRAME_INFO frameInfo; + + const UINT timeout = 100; // ms + hr = g_deskDupl->AcquireNextFrame(timeout, &frameInfo, &resource); + switch (hr) + { + case S_OK: + { + break; + } + case DXGI_ERROR_ACCESS_LOST: + { + FinalizeDuplication(); + InitializeDuplication(); + return; + } + default: + { + return; + } + } + + g_isPointerVisible = frameInfo.PointerPosition.Visible; + g_pointerX = frameInfo.PointerPosition.Position.x; + g_pointerY = frameInfo.PointerPosition.Position.y; + + ID3D11Texture2D* texture; + hr = resource->QueryInterface(__uuidof(ID3D11Texture2D), reinterpret_cast(&texture)); + if (hr != S_OK) + { + resource->Release(); + return; + } + + resource->Release(); + + ID3D11DeviceContext* context; + auto device = g_unity->Get()->GetDevice(); + device->GetImmediateContext(&context); + context->CopyResource(g_texture, texture); + + g_deskDupl->ReleaseFrame(); + } + + UNITY_INTERFACE_EXPORT UnityRenderingEvent UNITY_INTERFACE_API GetRenderEventFunc() + { + return OnRenderEvent; + } + + UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetWidth() + { + return g_width; + } + + UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetHeight() + { + return g_height; + } + + UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API IsPointerVisible() + { + return g_isPointerVisible; + } + + UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetPointerX() + { + return g_pointerX; + } + + UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetPointerY() + { + return g_pointerY; + } + + UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API SetTexturePtr(void* texture) + { + g_texture = reinterpret_cast(texture); + } +} \ No newline at end of file diff --git a/Plugins/uDesktopDuplication/uDesktopDuplication/uDesktopDuplication.filters b/Plugins/uDesktopDuplication/uDesktopDuplication/uDesktopDuplication.filters new file mode 100644 index 0000000..79635bf --- /dev/null +++ b/Plugins/uDesktopDuplication/uDesktopDuplication/uDesktopDuplication.filters @@ -0,0 +1,33 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + \ No newline at end of file diff --git a/Plugins/uDesktopDuplication/uDesktopDuplication/uDesktopDuplication.vcxproj b/Plugins/uDesktopDuplication/uDesktopDuplication/uDesktopDuplication.vcxproj new file mode 100644 index 0000000..af212d0 --- /dev/null +++ b/Plugins/uDesktopDuplication/uDesktopDuplication/uDesktopDuplication.vcxproj @@ -0,0 +1,135 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {BC5DE2F9-BDCC-4449-A017-E5642E04BB56} + uDesktopDuplication + 8.1 + uDesktopDuplication + + + + DynamicLibrary + true + v140 + MultiByte + + + DynamicLibrary + false + v140 + true + MultiByte + + + DynamicLibrary + true + v140 + MultiByte + + + DynamicLibrary + false + v140 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + + + + Level3 + Disabled + true + + + + + Level3 + Disabled + true + + + copy /Y "$(SolutionDir)$(Platform)\$(Configuration)\$(TargetFileName)" "$(SolutionDir)..\..\Assets\$(ProjectName)\Plugins" + + + + + Level3 + MaxSpeed + true + true + true + + + true + true + + + + + + + + + Level3 + MaxSpeed + true + true + true + + + true + true + + + copy /Y "$(SolutionDir)$(Platform)\$(Configuration)\$(TargetFileName)" "$(SolutionDir)..\..\Assets\$(ProjectName)\Plugins" + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ProjectSettings/AudioManager.asset b/ProjectSettings/AudioManager.asset new file mode 100644 index 0000000..fe6cc1d Binary files /dev/null and b/ProjectSettings/AudioManager.asset differ diff --git a/ProjectSettings/ClusterInputManager.asset b/ProjectSettings/ClusterInputManager.asset new file mode 100644 index 0000000..60e3abb Binary files /dev/null and b/ProjectSettings/ClusterInputManager.asset differ diff --git a/ProjectSettings/DynamicsManager.asset b/ProjectSettings/DynamicsManager.asset new file mode 100644 index 0000000..4fed4b8 Binary files /dev/null and b/ProjectSettings/DynamicsManager.asset differ diff --git a/ProjectSettings/EditorBuildSettings.asset b/ProjectSettings/EditorBuildSettings.asset new file mode 100644 index 0000000..5d88f5a Binary files /dev/null and b/ProjectSettings/EditorBuildSettings.asset differ diff --git a/ProjectSettings/EditorSettings.asset b/ProjectSettings/EditorSettings.asset new file mode 100644 index 0000000..b1beb2a Binary files /dev/null and b/ProjectSettings/EditorSettings.asset differ diff --git a/ProjectSettings/GraphicsSettings.asset b/ProjectSettings/GraphicsSettings.asset new file mode 100644 index 0000000..8c694b0 Binary files /dev/null and b/ProjectSettings/GraphicsSettings.asset differ diff --git a/ProjectSettings/InputManager.asset b/ProjectSettings/InputManager.asset new file mode 100644 index 0000000..3789778 Binary files /dev/null and b/ProjectSettings/InputManager.asset differ diff --git a/ProjectSettings/NavMeshAreas.asset b/ProjectSettings/NavMeshAreas.asset new file mode 100644 index 0000000..6f16283 Binary files /dev/null and b/ProjectSettings/NavMeshAreas.asset differ diff --git a/ProjectSettings/NetworkManager.asset b/ProjectSettings/NetworkManager.asset new file mode 100644 index 0000000..6b7e77f Binary files /dev/null and b/ProjectSettings/NetworkManager.asset differ diff --git a/ProjectSettings/Physics2DSettings.asset b/ProjectSettings/Physics2DSettings.asset new file mode 100644 index 0000000..9d64e14 Binary files /dev/null and b/ProjectSettings/Physics2DSettings.asset differ diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset new file mode 100644 index 0000000..c1b79d0 Binary files /dev/null and b/ProjectSettings/ProjectSettings.asset differ diff --git a/ProjectSettings/ProjectVersion.txt b/ProjectSettings/ProjectVersion.txt new file mode 100644 index 0000000..96b25e7 --- /dev/null +++ b/ProjectSettings/ProjectVersion.txt @@ -0,0 +1,2 @@ +m_EditorVersion: 5.4.1f1 +m_StandardAssetsVersion: 0 diff --git a/ProjectSettings/QualitySettings.asset b/ProjectSettings/QualitySettings.asset new file mode 100644 index 0000000..cc79ef5 Binary files /dev/null and b/ProjectSettings/QualitySettings.asset differ diff --git a/ProjectSettings/TagManager.asset b/ProjectSettings/TagManager.asset new file mode 100644 index 0000000..315f235 Binary files /dev/null and b/ProjectSettings/TagManager.asset differ diff --git a/ProjectSettings/TimeManager.asset b/ProjectSettings/TimeManager.asset new file mode 100644 index 0000000..b7b21cb Binary files /dev/null and b/ProjectSettings/TimeManager.asset differ diff --git a/ProjectSettings/UnityAdsSettings.asset b/ProjectSettings/UnityAdsSettings.asset new file mode 100644 index 0000000..d9a4f06 Binary files /dev/null and b/ProjectSettings/UnityAdsSettings.asset differ diff --git a/ProjectSettings/UnityConnectSettings.asset b/ProjectSettings/UnityConnectSettings.asset new file mode 100644 index 0000000..bd9e618 Binary files /dev/null and b/ProjectSettings/UnityConnectSettings.asset differ