fix indent.

This commit is contained in:
hecomi
2016-11-06 03:33:21 +09:00
parent 9e42fb0abf
commit 217e63d40c
8 changed files with 161 additions and 161 deletions
@@ -9,7 +9,7 @@ const std::unique_ptr<MonitorManager>& GetMonitorManager();
enum class Message
{
None = -1,
Reinitialized = 0,
None = -1,
Reinitialized = 0,
};
void SendMessageToUnity(Message message);
@@ -28,46 +28,46 @@ Cursor::~Cursor()
void Cursor::UpdateBuffer(const DXGI_OUTDUPL_FRAME_INFO& frameInfo)
{
if (frameInfo.LastMouseUpdateTime.QuadPart == 0)
{
return;
}
if (frameInfo.LastMouseUpdateTime.QuadPart == 0)
{
return;
}
x_ = frameInfo.PointerPosition.Position.x;
y_ = frameInfo.PointerPosition.Position.y;
if (frameInfo.PointerPosition.Visible != 0) {
GetMonitorManager()->SetCursorMonitorId(monitor_->GetId());
timestamp_ = frameInfo.LastMouseUpdateTime;
isVisible_ = frameInfo.PointerPosition.Visible != 0;
}
x_ = frameInfo.PointerPosition.Position.x;
y_ = frameInfo.PointerPosition.Position.y;
if (frameInfo.PointerPosition.Visible != 0) {
GetMonitorManager()->SetCursorMonitorId(monitor_->GetId());
timestamp_ = frameInfo.LastMouseUpdateTime;
isVisible_ = frameInfo.PointerPosition.Visible != 0;
}
if (frameInfo.PointerShapeBufferSize == 0)
{
return;
}
if (frameInfo.PointerShapeBufferSize == 0)
{
return;
}
// Increase the buffer size if needed
if (frameInfo.PointerShapeBufferSize > apiBufferSize_)
{
if (apiBuffer_) delete[] apiBuffer_;
apiBuffer_ = new BYTE[frameInfo.PointerShapeBufferSize];
apiBufferSize_ = frameInfo.PointerShapeBufferSize;
}
if (apiBuffer_ == nullptr) return;
// Increase the buffer size if needed
if (frameInfo.PointerShapeBufferSize > apiBufferSize_)
{
if (apiBuffer_) delete[] apiBuffer_;
apiBuffer_ = new BYTE[frameInfo.PointerShapeBufferSize];
apiBufferSize_ = frameInfo.PointerShapeBufferSize;
}
if (apiBuffer_ == nullptr) return;
// Get mouse pointer information
UINT bufferSize;
const auto hr = monitor_->GetDeskDupl()->GetFramePointerShape(
frameInfo.PointerShapeBufferSize,
reinterpret_cast<void*>(apiBuffer_),
&bufferSize,
&shapeInfo_);
if (FAILED(hr))
{
delete[] apiBuffer_;
apiBuffer_ = nullptr;
apiBufferSize_ = 0;
}
// Get mouse pointer information
UINT bufferSize;
const auto hr = monitor_->GetDeskDupl()->GetFramePointerShape(
frameInfo.PointerShapeBufferSize,
reinterpret_cast<void*>(apiBuffer_),
&bufferSize,
&shapeInfo_);
if (FAILED(hr))
{
delete[] apiBuffer_;
apiBuffer_ = nullptr;
apiBufferSize_ = 0;
}
}
@@ -78,9 +78,9 @@ void Cursor::UpdateTexture()
const bool isColorMask = GetType() == DXGI_OUTDUPL_POINTER_SHAPE_TYPE_MASKED_COLOR;
// Size
const auto w = GetWidth();
const auto h = GetHeight();
const auto p = GetPitch();
const auto w = GetWidth();
const auto h = GetHeight();
const auto p = GetPitch();
// Convert the buffer given by API into BGRA32
const UINT bgraBufferSize = w * h * 4;
@@ -10,7 +10,7 @@ public:
explicit Cursor(Monitor* monitor);
~Cursor();
void UpdateBuffer(const DXGI_OUTDUPL_FRAME_INFO& frameInfo);
void UpdateTexture();
void UpdateTexture();
void GetTexture(ID3D11Texture2D* texture);
bool IsVisible() const;
@@ -31,5 +31,5 @@ private:
BYTE* bgra32Buffer_ = nullptr;
UINT bgra32BufferSize_ = 0;
DXGI_OUTDUPL_POINTER_SHAPE_INFO shapeInfo_;
LARGE_INTEGER timestamp_;
LARGE_INTEGER timestamp_;
};
@@ -21,32 +21,32 @@ HRESULT Monitor::Initialize(IDXGIOutput* output)
auto output1 = reinterpret_cast<IDXGIOutput1*>(output);
const auto hr = output1->DuplicateOutput(GetDevice(), &deskDupl_);
// TODO: error check
// TODO: error check
switch (hr)
{
case S_OK:
state_ = State::Available;
state_ = State::Available;
break;
case E_INVALIDARG:
state_ = State::InvalidArg;
state_ = State::InvalidArg;
break;
case E_ACCESSDENIED:
// For example, when the user presses Ctrl + Alt + Delete and the screen
// switches to admin screen, this error occurs.
state_ = State::AccessDenied;
// For example, when the user presses Ctrl + Alt + Delete and the screen
// switches to admin screen, this error occurs.
state_ = State::AccessDenied;
break;
case DXGI_ERROR_UNSUPPORTED:
// If the display adapter on the computer is running under the Microsoft Hybrid system,
// this error occurs.
state_ = State::Unsupported;
state_ = State::Unsupported;
break;
case DXGI_ERROR_NOT_CURRENTLY_AVAILABLE:
// When other application use Desktop Duplication API, this error occurs.
state_ = State::CurrentlyNotAvailable;
case DXGI_ERROR_NOT_CURRENTLY_AVAILABLE:
// When other application use Desktop Duplication API, this error occurs.
state_ = State::CurrentlyNotAvailable;
break;
case DXGI_ERROR_SESSION_DISCONNECTED:
state_ = State::SessionDisconnected;
break;
state_ = State::SessionDisconnected;
break;
}
return hr;
@@ -55,21 +55,21 @@ HRESULT Monitor::Initialize(IDXGIOutput* output)
Monitor::~Monitor()
{
if (deskDupl_ != nullptr)
{
deskDupl_->Release();
}
if (deskDupl_ != nullptr)
{
deskDupl_->Release();
}
}
HRESULT Monitor::Render(UINT timeout)
{
if (deskDupl_ == nullptr)
{
return S_OK;
}
if (deskDupl_ == nullptr)
{
return S_OK;
}
if (unityTexture_ == nullptr) return 0;
if (unityTexture_ == nullptr) return 0;
IDXGIResource* resource = nullptr;
DXGI_OUTDUPL_FRAME_INFO frameInfo;
@@ -77,21 +77,21 @@ HRESULT Monitor::Render(UINT timeout)
const auto hr = deskDupl_->AcquireNextFrame(timeout, &frameInfo, &resource);
if (FAILED(hr))
{
switch (hr)
{
case DXGI_ERROR_ACCESS_LOST:
// If any monitor setting has changed (e.g. monitor size has changed),
// it is necessary to re-initialize monitors.
state_ = State::AccessLost;
break;
case DXGI_ERROR_WAIT_TIMEOUT:
break;
case DXGI_ERROR_INVALID_CALL:
break;
case E_INVALIDARG:
break;
}
return hr;
switch (hr)
{
case DXGI_ERROR_ACCESS_LOST:
// If any monitor setting has changed (e.g. monitor size has changed),
// it is necessary to re-initialize monitors.
state_ = State::AccessLost;
break;
case DXGI_ERROR_WAIT_TIMEOUT:
break;
case DXGI_ERROR_INVALID_CALL:
break;
case E_INVALIDARG:
break;
}
return hr;
}
ID3D11Texture2D* texture;
@@ -103,7 +103,7 @@ HRESULT Monitor::Render(UINT timeout)
context->Release();
cursor_->UpdateBuffer(frameInfo);
cursor_->UpdateTexture();
cursor_->UpdateTexture();
resource->Release();
deskDupl_->ReleaseFrame();
@@ -120,7 +120,7 @@ int Monitor::GetId() const
MonitorState Monitor::GetState() const
{
return state_;
return state_;
}
@@ -168,31 +168,31 @@ bool Monitor::IsPrimary() const
int Monitor::GetLeft() const
{
return outputDesc_.DesktopCoordinates.left;
return outputDesc_.DesktopCoordinates.left;
}
int Monitor::GetRight() const
{
return outputDesc_.DesktopCoordinates.right;
return outputDesc_.DesktopCoordinates.right;
}
int Monitor::GetTop() const
{
return outputDesc_.DesktopCoordinates.top;
return outputDesc_.DesktopCoordinates.top;
}
int Monitor::GetBottom() const
{
return outputDesc_.DesktopCoordinates.bottom;
return outputDesc_.DesktopCoordinates.bottom;
}
int Monitor::GetRotation() const
{
return static_cast<int>(outputDesc_.Rotation);
return static_cast<int>(outputDesc_.Rotation);
}
@@ -6,20 +6,20 @@ class Cursor;
enum class MonitorState
{
NotSet = -1,
Available = 0,
InvalidArg = 1,
AccessDenied = 2,
Unsupported = 3,
CurrentlyNotAvailable = 4,
SessionDisconnected = 5,
AccessLost = 6,
NotSet = -1,
Available = 0,
InvalidArg = 1,
AccessDenied = 2,
Unsupported = 3,
CurrentlyNotAvailable = 4,
SessionDisconnected = 5,
AccessLost = 6,
};
class Monitor
{
public:
using State = MonitorState;
using State = MonitorState;
explicit Monitor(int id);
~Monitor();
@@ -29,24 +29,24 @@ public:
public:
int GetId() const;
State GetState() const;
State GetState() const;
void SetUnityTexture(ID3D11Texture2D* texture);
ID3D11Texture2D* GetUnityTexture() const;
void GetName(char* buf, int len) const;
bool IsPrimary() const;
int GetLeft() const;
int GetRight() const;
int GetTop() const;
int GetBottom() const;
int GetLeft() const;
int GetRight() const;
int GetTop() const;
int GetBottom() const;
int GetWidth() const;
int GetHeight() const;
int GetRotation() const;
int GetRotation() const;
IDXGIOutputDuplication* GetDeskDupl();
const std::unique_ptr<Cursor>& GetCursor();
private:
int id_ = -1;
State state_ = State::NotSet;
State state_ = State::NotSet;
std::unique_ptr<Cursor> cursor_;
IDXGIOutputDuplication* deskDupl_ = nullptr;
ID3D11Texture2D* unityTexture_ = nullptr;
@@ -61,14 +61,14 @@ void MonitorManager::Finalize()
void MonitorManager::RequireReinitilization()
{
isReinitializationRequired_ = true;
isReinitializationRequired_ = true;
}
void MonitorManager::Reinitialize()
{
Initialize();
SendMessageToUnity(Message::Reinitialized);
Initialize();
SendMessageToUnity(Message::Reinitialized);
}
@@ -84,11 +84,11 @@ std::shared_ptr<Monitor> MonitorManager::GetMonitor(int id) const
void MonitorManager::Update()
{
if (isReinitializationRequired_)
{
Reinitialize();
isReinitializationRequired_ = false;
}
if (isReinitializationRequired_)
{
Reinitialize();
isReinitializationRequired_ = false;
}
}
@@ -111,26 +111,26 @@ int MonitorManager::GetMonitorCount() const
int MonitorManager::GetTotalWidth() const
{
std::vector<int> lefts, rights;
for (const auto& monitor : monitors_)
{
lefts.push_back(monitor->GetLeft());
rights.push_back(monitor->GetRight());
}
const auto minLeft = *std::min_element(lefts.begin(), lefts.end());
const auto maxRight = *std::max_element(rights.begin(), rights.end());
return maxRight - minLeft;
std::vector<int> lefts, rights;
for (const auto& monitor : monitors_)
{
lefts.push_back(monitor->GetLeft());
rights.push_back(monitor->GetRight());
}
const auto minLeft = *std::min_element(lefts.begin(), lefts.end());
const auto maxRight = *std::max_element(rights.begin(), rights.end());
return maxRight - minLeft;
}
int MonitorManager::GetTotalHeight() const
{
std::vector<int> tops, bottoms;
for (const auto& monitor : monitors_)
{
tops.push_back(monitor->GetTop());
bottoms.push_back(monitor->GetBottom());
}
const auto minTop = *std::min_element(tops.begin(), tops.end());
const auto maxBottom = *std::max_element(bottoms.begin(), bottoms.end());
return maxBottom - minTop;
std::vector<int> tops, bottoms;
for (const auto& monitor : monitors_)
{
tops.push_back(monitor->GetTop());
bottoms.push_back(monitor->GetBottom());
}
const auto minTop = *std::min_element(tops.begin(), tops.end());
const auto maxBottom = *std::max_element(bottoms.begin(), bottoms.end());
return maxBottom - minTop;
}
@@ -13,8 +13,8 @@ class MonitorManager
public:
explicit MonitorManager();
~MonitorManager();
void Reinitialize();
void RequireReinitilization();
void Reinitialize();
void RequireReinitilization();
void SetCursorMonitorId(int id) { cursorMonitorId_ = id; }
int GetCursorMonitorId() const { return cursorMonitorId_; }
std::shared_ptr<Monitor> GetMonitor(int id) const;
@@ -25,7 +25,7 @@ private:
// Setters from Unity
public:
void Update();
void Update();
void SetTimeout(int timeout);
int GetTimeout() const;
@@ -40,5 +40,5 @@ private:
std::vector<std::shared_ptr<Monitor>> monitors_;
std::shared_ptr<Cursor> cursor_;
int cursorMonitorId_ = -1;
bool isReinitializationRequired_ = false;
bool isReinitializationRequired_ = false;
};
@@ -21,7 +21,7 @@ namespace
{
IUnityInterfaces* g_unity = nullptr;
std::unique_ptr<MonitorManager> g_manager;
std::queue<Message> g_messages;
std::queue<Message> g_messages;
}
@@ -45,7 +45,7 @@ const std::unique_ptr<MonitorManager>& GetMonitorManager()
void SendMessageToUnity(Message message)
{
g_messages.push(message);
g_messages.push(message);
}
@@ -53,32 +53,32 @@ extern "C"
{
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API InitializeUDD()
{
if (g_unity && !g_manager)
{
g_manager = std::make_unique<MonitorManager>();
}
if (g_unity && !g_manager)
{
g_manager = std::make_unique<MonitorManager>();
}
}
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API FinalizeUDD()
{
g_manager.reset();
g_manager.reset();
}
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API UnityPluginLoad(IUnityInterfaces* unityInterfaces)
{
g_unity = unityInterfaces;
InitializeUDD();
InitializeUDD();
}
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API UnityPluginUnload()
{
g_unity = nullptr;
FinalizeUDD();
g_unity = nullptr;
FinalizeUDD();
}
void UNITY_INTERFACE_API OnRenderEvent(int id)
{
if (!g_manager) return;
if (!g_manager) return;
if (auto monitor = g_manager->GetMonitor(id))
{
monitor->Render(g_manager->GetTimeout());
@@ -92,52 +92,52 @@ extern "C"
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API Reinitialize()
{
if (!g_manager) return;
return g_manager->Reinitialize();
if (!g_manager) return;
return g_manager->Reinitialize();
}
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API Update()
{
if (!g_manager) return;
g_manager->Update();
if (!g_manager) return;
g_manager->Update();
}
UNITY_INTERFACE_EXPORT Message PopMessage()
{
if (g_messages.empty()) return Message::None;
UNITY_INTERFACE_EXPORT Message PopMessage()
{
if (g_messages.empty()) return Message::None;
const auto message = g_messages.front();
g_messages.pop();
return message;
}
const auto message = g_messages.front();
g_messages.pop();
return message;
}
UNITY_INTERFACE_EXPORT size_t UNITY_INTERFACE_API GetMonitorCount()
{
if (!g_manager) return 0;
if (!g_manager) return 0;
return g_manager->GetMonitorCount();
}
UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetTotalWidth()
{
if (!g_manager) return 0;
if (!g_manager) return 0;
return g_manager->GetTotalWidth();
}
UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetTotalHeight()
{
if (!g_manager) return 0;
if (!g_manager) return 0;
return g_manager->GetTotalHeight();
}
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API SetTimeout(int timeout)
{
if (!g_manager) return;
if (!g_manager) return;
g_manager->SetTimeout(timeout);
}
UNITY_INTERFACE_EXPORT MonitorState UNITY_INTERFACE_API GetState(int id)
{
if (!g_manager) return MonitorState::NotSet;
if (!g_manager) return MonitorState::NotSet;
if (auto monitor = g_manager->GetMonitor(id))
{
return monitor->GetState();
@@ -147,7 +147,7 @@ extern "C"
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API GetName(int id, char* buf, int len)
{
if (!g_manager) return;
if (!g_manager) return;
if (auto monitor = g_manager->GetMonitor(id))
{
monitor->GetName(buf, len);
@@ -156,7 +156,7 @@ extern "C"
UNITY_INTERFACE_EXPORT bool UNITY_INTERFACE_API IsPrimary(int id)
{
if (!g_manager) return false;
if (!g_manager) return false;
if (auto monitor = g_manager->GetMonitor(id))
{
return monitor->IsPrimary();