Add WinrtWindow.cpp and WinRT version of angle_util

Change-Id: If4ff4b966f5bd388d32c72a2d1bcf9cf29e6032d
Reviewed-on: https://chromium-review.googlesource.com/297308
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Tested-by: Austin Kinross <aukinros@microsoft.com>
This commit is contained in:
Austin Kinross 2015-09-02 12:29:07 -07:00 коммит произвёл Jamie Madill
Родитель c5b2ba5359
Коммит 9f2fd2b40d
13 изменённых файлов: 757 добавлений и 255 удалений

Просмотреть файл

@ -27,13 +27,24 @@
],
'util_win32_sources':
[
'win32/Win32_system_utils.cpp',
'win32/Win32Pixmap.cpp',
'win32/Win32Pixmap.h',
'win32/Win32Timer.cpp',
'win32/Win32Timer.h',
'win32/Win32Window.cpp',
'win32/Win32Window.h',
'windows/win32/Win32_system_utils.cpp',
'windows/win32/Win32Pixmap.cpp',
'windows/win32/Win32Pixmap.h',
'windows/win32/Win32Window.cpp',
'windows/win32/Win32Window.h',
'windows/Windows_system_utils.cpp',
'windows/WindowsTimer.cpp',
'windows/WindowsTimer.h',
],
'util_winrt_sources':
[
'windows/winrt/WinRT_system_utils.cpp',
'windows/winrt/WinRTPixmap.cpp',
'windows/winrt/WinRTWindow.cpp',
'windows/winrt/WinRTWindow.h',
'windows/Windows_system_utils.cpp',
'windows/WindowsTimer.cpp',
'windows/WindowsTimer.h',
],
'util_linux_sources':
[
@ -106,14 +117,20 @@
},
'conditions':
[
['OS=="win"',
['OS=="win" and angle_build_winrt==0',
{
'msvs_disabled_warnings': [ 4201 ],
'sources':
[
'<@(util_win32_sources)',
],
}],
['OS=="win" and angle_build_winrt==1',
{
'sources':
[
'<@(util_winrt_sources)',
],
}],
['OS=="linux"',
{
'sources':

Просмотреть файл

@ -4,18 +4,15 @@
// found in the LICENSE file.
//
// Win32Timer.cpp: Implementation of a high precision timer class on Windows
// WindowsTimer.cpp: Implementation of a high precision timer class on Windows
#include "win32/Win32Timer.h"
#include "windows/WindowsTimer.h"
Win32Timer::Win32Timer()
: mRunning(false),
mStartTime(0),
mStopTime(0)
WindowsTimer::WindowsTimer() : mRunning(false), mStartTime(0), mStopTime(0)
{
}
void Win32Timer::start()
void WindowsTimer::start()
{
LARGE_INTEGER frequency;
QueryPerformanceFrequency(&frequency);
@ -28,7 +25,7 @@ void Win32Timer::start()
mRunning = true;
}
void Win32Timer::stop()
void WindowsTimer::stop()
{
LARGE_INTEGER curTime;
QueryPerformanceCounter(&curTime);
@ -37,7 +34,7 @@ void Win32Timer::stop()
mRunning = false;
}
double Win32Timer::getElapsedTime() const
double WindowsTimer::getElapsedTime() const
{
LONGLONG endTime;
if (mRunning)
@ -56,5 +53,5 @@ double Win32Timer::getElapsedTime() const
Timer *CreateTimer()
{
return new Win32Timer();
return new WindowsTimer();
}

Просмотреть файл

@ -4,19 +4,19 @@
// found in the LICENSE file.
//
// Win32Timer.h: Definition of a high precision timer class on Windows
// WindowsTimer.h: Definition of a high precision timer class on Windows
#ifndef UTIL_WIN32_TIMER_H
#define UTIL_WIN32_TIMER_H
#ifndef UTIL_WINDOWS_TIMER_H
#define UTIL_WINDOWS_TIMER_H
#include <windows.h>
#include "Timer.h"
class Win32Timer : public Timer
class WindowsTimer : public Timer
{
public:
Win32Timer();
WindowsTimer();
void start() override;
void stop() override;
@ -30,4 +30,4 @@ class Win32Timer : public Timer
LONGLONG mFrequency;
};
#endif // UTIL_WIN32_TIMER_H
#endif // UTIL_WINDOWS_TIMER_H

Просмотреть файл

@ -4,7 +4,7 @@
// found in the LICENSE file.
//
// Win32_system_utils.cpp: Implementation of OS-specific functions for Windows
// Windows_system_utils.cpp: Implementation of OS-specific functions for Windows
#include "system_utils.h"
@ -34,9 +34,4 @@ void Sleep(unsigned int milliseconds)
::Sleep(static_cast<DWORD>(milliseconds));
}
void SetLowPriorityProcess()
{
SetPriorityClass(GetCurrentProcess(), BELOW_NORMAL_PRIORITY_CLASS);
}
} // namespace angle
} // namespace angle

Просмотреть файл

@ -4,12 +4,11 @@
// found in the LICENSE file.
//
// Win32Pixmap.cpp: Implementation of OSPixmap for Windows
// Win32Pixmap.cpp: Implementation of OSPixmap for Win32 (Windows)
#include "win32/Win32Pixmap.h"
#include "windows/win32/Win32Pixmap.h"
Win32Pixmap::Win32Pixmap()
: mBitmap(nullptr)
Win32Pixmap::Win32Pixmap() : mBitmap(nullptr)
{
}
@ -31,20 +30,20 @@ bool Win32Pixmap::initialize(EGLNativeDisplayType display, size_t width, size_t
return false;
}
bitmapInfo.bmiHeader.biSize = sizeof(bitmapInfo);
bitmapInfo.bmiHeader.biSize = sizeof(bitmapInfo);
bitmapInfo.bmiHeader.biWidth = static_cast<LONG>(width);
bitmapInfo.bmiHeader.biHeight = static_cast<LONG>(height);
bitmapInfo.bmiHeader.biPlanes = 1;
bitmapInfo.bmiHeader.biBitCount = static_cast<WORD>(depth);
bitmapInfo.bmiHeader.biCompression = BI_RGB;
bitmapInfo.bmiHeader.biSizeImage = 0;
bitmapInfo.bmiHeader.biPlanes = 1;
bitmapInfo.bmiHeader.biBitCount = static_cast<WORD>(depth);
bitmapInfo.bmiHeader.biCompression = BI_RGB;
bitmapInfo.bmiHeader.biSizeImage = 0;
bitmapInfo.bmiHeader.biXPelsPerMeter = 1;
bitmapInfo.bmiHeader.biYPelsPerMeter = 1;
bitmapInfo.bmiHeader.biClrUsed = 0;
bitmapInfo.bmiHeader.biClrImportant = 0;
bitmapInfo.bmiHeader.biClrUsed = 0;
bitmapInfo.bmiHeader.biClrImportant = 0;
void *bitmapPtr = nullptr;
mBitmap = CreateDIBSection(display, &bitmapInfo, DIB_RGB_COLORS, &bitmapPtr, nullptr, 0);
mBitmap = CreateDIBSection(display, &bitmapInfo, DIB_RGB_COLORS, &bitmapPtr, nullptr, 0);
return mBitmap != nullptr;
}

Просмотреть файл

@ -4,7 +4,7 @@
// found in the LICENSE file.
//
// Win32Pixmap.h: Definition of the implementation of OSPixmap for Windows
// Win32Pixmap.h: Definition of the implementation of OSPixmap for Win32 (Windows)
#ifndef UTIL_WIN32_PIXMAP_H_
#define UTIL_WIN32_PIXMAP_H_
@ -27,4 +27,4 @@ class Win32Pixmap : public OSPixmap
HBITMAP mBitmap;
};
#endif // UTIL_WIN32_PIXMAP_H_
#endif // UTIL_WIN32_PIXMAP_H_

Просмотреть файл

@ -4,9 +4,9 @@
// found in the LICENSE file.
//
// Win32Window.cpp: Implementation of OSWindow for Windows
// Win32Window.cpp: Implementation of OSWindow for Win32 (Windows)
#include "win32/Win32Window.h"
#include "windows/win32/Win32Window.h"
#include <sstream>
@ -17,115 +17,212 @@ Key VirtualKeyCodeToKey(WPARAM key, LPARAM flags)
switch (key)
{
// Check the scancode to distinguish between left and right shift
case VK_SHIFT:
case VK_SHIFT:
{
static unsigned int lShift = MapVirtualKey(VK_LSHIFT, MAPVK_VK_TO_VSC);
unsigned int scancode = static_cast<unsigned int>((flags & (0xFF << 16)) >> 16);
unsigned int scancode = static_cast<unsigned int>((flags & (0xFF << 16)) >> 16);
return scancode == lShift ? KEY_LSHIFT : KEY_RSHIFT;
}
// Check the "extended" flag to distinguish between left and right alt
case VK_MENU: return (HIWORD(flags) & KF_EXTENDED) ? KEY_RALT : KEY_LALT;
case VK_MENU:
return (HIWORD(flags) & KF_EXTENDED) ? KEY_RALT : KEY_LALT;
// Check the "extended" flag to distinguish between left and right control
case VK_CONTROL: return (HIWORD(flags) & KF_EXTENDED) ? KEY_RCONTROL : KEY_LCONTROL;
case VK_CONTROL:
return (HIWORD(flags) & KF_EXTENDED) ? KEY_RCONTROL : KEY_LCONTROL;
// Other keys are reported properly
case VK_LWIN: return KEY_LSYSTEM;
case VK_RWIN: return KEY_RSYSTEM;
case VK_APPS: return KEY_MENU;
case VK_OEM_1: return KEY_SEMICOLON;
case VK_OEM_2: return KEY_SLASH;
case VK_OEM_PLUS: return KEY_EQUAL;
case VK_OEM_MINUS: return KEY_DASH;
case VK_OEM_4: return KEY_LBRACKET;
case VK_OEM_6: return KEY_RBRACKET;
case VK_OEM_COMMA: return KEY_COMMA;
case VK_OEM_PERIOD: return KEY_PERIOD;
case VK_OEM_7: return KEY_QUOTE;
case VK_OEM_5: return KEY_BACKSLASH;
case VK_OEM_3: return KEY_TILDE;
case VK_ESCAPE: return KEY_ESCAPE;
case VK_SPACE: return KEY_SPACE;
case VK_RETURN: return KEY_RETURN;
case VK_BACK: return KEY_BACK;
case VK_TAB: return KEY_TAB;
case VK_PRIOR: return KEY_PAGEUP;
case VK_NEXT: return KEY_PAGEDOWN;
case VK_END: return KEY_END;
case VK_HOME: return KEY_HOME;
case VK_INSERT: return KEY_INSERT;
case VK_DELETE: return KEY_DELETE;
case VK_ADD: return KEY_ADD;
case VK_SUBTRACT: return KEY_SUBTRACT;
case VK_MULTIPLY: return KEY_MULTIPLY;
case VK_DIVIDE: return KEY_DIVIDE;
case VK_PAUSE: return KEY_PAUSE;
case VK_F1: return KEY_F1;
case VK_F2: return KEY_F2;
case VK_F3: return KEY_F3;
case VK_F4: return KEY_F4;
case VK_F5: return KEY_F5;
case VK_F6: return KEY_F6;
case VK_F7: return KEY_F7;
case VK_F8: return KEY_F8;
case VK_F9: return KEY_F9;
case VK_F10: return KEY_F10;
case VK_F11: return KEY_F11;
case VK_F12: return KEY_F12;
case VK_F13: return KEY_F13;
case VK_F14: return KEY_F14;
case VK_F15: return KEY_F15;
case VK_LEFT: return KEY_LEFT;
case VK_RIGHT: return KEY_RIGHT;
case VK_UP: return KEY_UP;
case VK_DOWN: return KEY_DOWN;
case VK_NUMPAD0: return KEY_NUMPAD0;
case VK_NUMPAD1: return KEY_NUMPAD1;
case VK_NUMPAD2: return KEY_NUMPAD2;
case VK_NUMPAD3: return KEY_NUMPAD3;
case VK_NUMPAD4: return KEY_NUMPAD4;
case VK_NUMPAD5: return KEY_NUMPAD5;
case VK_NUMPAD6: return KEY_NUMPAD6;
case VK_NUMPAD7: return KEY_NUMPAD7;
case VK_NUMPAD8: return KEY_NUMPAD8;
case VK_NUMPAD9: return KEY_NUMPAD9;
case 'A': return KEY_A;
case 'Z': return KEY_Z;
case 'E': return KEY_E;
case 'R': return KEY_R;
case 'T': return KEY_T;
case 'Y': return KEY_Y;
case 'U': return KEY_U;
case 'I': return KEY_I;
case 'O': return KEY_O;
case 'P': return KEY_P;
case 'Q': return KEY_Q;
case 'S': return KEY_S;
case 'D': return KEY_D;
case 'F': return KEY_F;
case 'G': return KEY_G;
case 'H': return KEY_H;
case 'J': return KEY_J;
case 'K': return KEY_K;
case 'L': return KEY_L;
case 'M': return KEY_M;
case 'W': return KEY_W;
case 'X': return KEY_X;
case 'C': return KEY_C;
case 'V': return KEY_V;
case 'B': return KEY_B;
case 'N': return KEY_N;
case '0': return KEY_NUM0;
case '1': return KEY_NUM1;
case '2': return KEY_NUM2;
case '3': return KEY_NUM3;
case '4': return KEY_NUM4;
case '5': return KEY_NUM5;
case '6': return KEY_NUM6;
case '7': return KEY_NUM7;
case '8': return KEY_NUM8;
case '9': return KEY_NUM9;
case VK_LWIN:
return KEY_LSYSTEM;
case VK_RWIN:
return KEY_RSYSTEM;
case VK_APPS:
return KEY_MENU;
case VK_OEM_1:
return KEY_SEMICOLON;
case VK_OEM_2:
return KEY_SLASH;
case VK_OEM_PLUS:
return KEY_EQUAL;
case VK_OEM_MINUS:
return KEY_DASH;
case VK_OEM_4:
return KEY_LBRACKET;
case VK_OEM_6:
return KEY_RBRACKET;
case VK_OEM_COMMA:
return KEY_COMMA;
case VK_OEM_PERIOD:
return KEY_PERIOD;
case VK_OEM_7:
return KEY_QUOTE;
case VK_OEM_5:
return KEY_BACKSLASH;
case VK_OEM_3:
return KEY_TILDE;
case VK_ESCAPE:
return KEY_ESCAPE;
case VK_SPACE:
return KEY_SPACE;
case VK_RETURN:
return KEY_RETURN;
case VK_BACK:
return KEY_BACK;
case VK_TAB:
return KEY_TAB;
case VK_PRIOR:
return KEY_PAGEUP;
case VK_NEXT:
return KEY_PAGEDOWN;
case VK_END:
return KEY_END;
case VK_HOME:
return KEY_HOME;
case VK_INSERT:
return KEY_INSERT;
case VK_DELETE:
return KEY_DELETE;
case VK_ADD:
return KEY_ADD;
case VK_SUBTRACT:
return KEY_SUBTRACT;
case VK_MULTIPLY:
return KEY_MULTIPLY;
case VK_DIVIDE:
return KEY_DIVIDE;
case VK_PAUSE:
return KEY_PAUSE;
case VK_F1:
return KEY_F1;
case VK_F2:
return KEY_F2;
case VK_F3:
return KEY_F3;
case VK_F4:
return KEY_F4;
case VK_F5:
return KEY_F5;
case VK_F6:
return KEY_F6;
case VK_F7:
return KEY_F7;
case VK_F8:
return KEY_F8;
case VK_F9:
return KEY_F9;
case VK_F10:
return KEY_F10;
case VK_F11:
return KEY_F11;
case VK_F12:
return KEY_F12;
case VK_F13:
return KEY_F13;
case VK_F14:
return KEY_F14;
case VK_F15:
return KEY_F15;
case VK_LEFT:
return KEY_LEFT;
case VK_RIGHT:
return KEY_RIGHT;
case VK_UP:
return KEY_UP;
case VK_DOWN:
return KEY_DOWN;
case VK_NUMPAD0:
return KEY_NUMPAD0;
case VK_NUMPAD1:
return KEY_NUMPAD1;
case VK_NUMPAD2:
return KEY_NUMPAD2;
case VK_NUMPAD3:
return KEY_NUMPAD3;
case VK_NUMPAD4:
return KEY_NUMPAD4;
case VK_NUMPAD5:
return KEY_NUMPAD5;
case VK_NUMPAD6:
return KEY_NUMPAD6;
case VK_NUMPAD7:
return KEY_NUMPAD7;
case VK_NUMPAD8:
return KEY_NUMPAD8;
case VK_NUMPAD9:
return KEY_NUMPAD9;
case 'A':
return KEY_A;
case 'Z':
return KEY_Z;
case 'E':
return KEY_E;
case 'R':
return KEY_R;
case 'T':
return KEY_T;
case 'Y':
return KEY_Y;
case 'U':
return KEY_U;
case 'I':
return KEY_I;
case 'O':
return KEY_O;
case 'P':
return KEY_P;
case 'Q':
return KEY_Q;
case 'S':
return KEY_S;
case 'D':
return KEY_D;
case 'F':
return KEY_F;
case 'G':
return KEY_G;
case 'H':
return KEY_H;
case 'J':
return KEY_J;
case 'K':
return KEY_K;
case 'L':
return KEY_L;
case 'M':
return KEY_M;
case 'W':
return KEY_W;
case 'X':
return KEY_X;
case 'C':
return KEY_C;
case 'V':
return KEY_V;
case 'B':
return KEY_B;
case 'N':
return KEY_N;
case '0':
return KEY_NUM0;
case '1':
return KEY_NUM1;
case '2':
return KEY_NUM2;
case '3':
return KEY_NUM3;
case '4':
return KEY_NUM4;
case '5':
return KEY_NUM5;
case '6':
return KEY_NUM6;
case '7':
return KEY_NUM7;
case '8':
return KEY_NUM8;
case '9':
return KEY_NUM9;
}
return Key(0);
@ -133,23 +230,24 @@ Key VirtualKeyCodeToKey(WPARAM key, LPARAM flags)
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
switch (message)
{
case WM_NCCREATE:
case WM_NCCREATE:
{
LPCREATESTRUCT pCreateStruct = reinterpret_cast<LPCREATESTRUCT>(lParam);
SetWindowLongPtr(hWnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(pCreateStruct->lpCreateParams));
SetWindowLongPtr(hWnd, GWLP_USERDATA,
reinterpret_cast<LONG_PTR>(pCreateStruct->lpCreateParams));
return DefWindowProcA(hWnd, message, wParam, lParam);
}
}
Win32Window *window = reinterpret_cast<Win32Window*>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
Win32Window *window = reinterpret_cast<Win32Window *>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
if (window)
{
switch (message)
{
case WM_DESTROY:
case WM_CLOSE:
case WM_DESTROY:
case WM_CLOSE:
{
Event event;
event.Type = Event::EVENT_CLOSED;
@ -157,7 +255,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
break;
}
case WM_MOVE:
case WM_MOVE:
{
RECT winRect;
GetClientRect(hWnd, &winRect);
@ -168,15 +266,15 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
ClientToScreen(hWnd, &topLeft);
Event event;
event.Type = Event::EVENT_MOVED;
event.Move.X = topLeft.x;
event.Move.Y = topLeft.y;
event.Type = Event::EVENT_MOVED;
event.Move.X = topLeft.x;
event.Move.Y = topLeft.y;
window->pushEvent(event);
break;
}
case WM_SIZE:
case WM_SIZE:
{
RECT winRect;
GetClientRect(hWnd, &winRect);
@ -200,7 +298,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
break;
}
case WM_SETFOCUS:
case WM_SETFOCUS:
{
Event event;
event.Type = Event::EVENT_GAINED_FOCUS;
@ -208,7 +306,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
break;
}
case WM_KILLFOCUS:
case WM_KILLFOCUS:
{
Event event;
event.Type = Event::EVENT_LOST_FOCUS;
@ -216,132 +314,135 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
break;
}
case WM_KEYDOWN:
case WM_SYSKEYDOWN:
case WM_KEYUP:
case WM_SYSKEYUP:
case WM_KEYDOWN:
case WM_SYSKEYDOWN:
case WM_KEYUP:
case WM_SYSKEYUP:
{
bool down = (message == WM_KEYDOWN || message == WM_SYSKEYDOWN);
Event event;
event.Type = down ? Event::EVENT_KEY_PRESSED : Event::EVENT_KEY_RELEASED;
event.Key.Alt = HIWORD(GetAsyncKeyState(VK_MENU)) != 0;
event.Key.Alt = HIWORD(GetAsyncKeyState(VK_MENU)) != 0;
event.Key.Control = HIWORD(GetAsyncKeyState(VK_CONTROL)) != 0;
event.Key.Shift = HIWORD(GetAsyncKeyState(VK_SHIFT)) != 0;
event.Key.System = HIWORD(GetAsyncKeyState(VK_LWIN)) || HIWORD(GetAsyncKeyState(VK_RWIN));
event.Key.Code = VirtualKeyCodeToKey(wParam, lParam);
event.Key.Shift = HIWORD(GetAsyncKeyState(VK_SHIFT)) != 0;
event.Key.System =
HIWORD(GetAsyncKeyState(VK_LWIN)) || HIWORD(GetAsyncKeyState(VK_RWIN));
event.Key.Code = VirtualKeyCodeToKey(wParam, lParam);
window->pushEvent(event);
break;
}
case WM_MOUSEWHEEL:
case WM_MOUSEWHEEL:
{
Event event;
event.Type = Event::EVENT_MOUSE_WHEEL_MOVED;
event.Type = Event::EVENT_MOUSE_WHEEL_MOVED;
event.MouseWheel.Delta = static_cast<short>(HIWORD(wParam)) / 120;
window->pushEvent(event);
break;
}
case WM_LBUTTONDOWN:
case WM_LBUTTONDBLCLK:
case WM_LBUTTONDOWN:
case WM_LBUTTONDBLCLK:
{
Event event;
event.Type = Event::EVENT_MOUSE_BUTTON_PRESSED;
event.MouseButton.Button = MOUSEBUTTON_LEFT;
event.MouseButton.X = static_cast<short>(LOWORD(lParam));
event.MouseButton.Y = static_cast<short>(HIWORD(lParam));
event.MouseButton.Y = static_cast<short>(HIWORD(lParam));
window->pushEvent(event);
break;
}
case WM_LBUTTONUP:
case WM_LBUTTONUP:
{
Event event;
event.Type = Event::EVENT_MOUSE_BUTTON_RELEASED;
event.MouseButton.Button = MOUSEBUTTON_LEFT;
event.MouseButton.X = static_cast<short>(LOWORD(lParam));
event.MouseButton.Y = static_cast<short>(HIWORD(lParam));
event.MouseButton.Y = static_cast<short>(HIWORD(lParam));
window->pushEvent(event);
break;
}
case WM_RBUTTONDOWN:
case WM_RBUTTONDBLCLK:
case WM_RBUTTONDOWN:
case WM_RBUTTONDBLCLK:
{
Event event;
event.Type = Event::EVENT_MOUSE_BUTTON_PRESSED;
event.MouseButton.Button = MOUSEBUTTON_RIGHT;
event.MouseButton.X = static_cast<short>(LOWORD(lParam));
event.MouseButton.Y = static_cast<short>(HIWORD(lParam));
event.MouseButton.Y = static_cast<short>(HIWORD(lParam));
window->pushEvent(event);
break;
}
// Mouse right button up event
case WM_RBUTTONUP:
case WM_RBUTTONUP:
{
Event event;
event.Type = Event::EVENT_MOUSE_BUTTON_RELEASED;
event.MouseButton.Button = MOUSEBUTTON_RIGHT;
event.MouseButton.X = static_cast<short>(LOWORD(lParam));
event.MouseButton.Y = static_cast<short>(HIWORD(lParam));
event.MouseButton.Y = static_cast<short>(HIWORD(lParam));
window->pushEvent(event);
break;
}
// Mouse wheel button down event
case WM_MBUTTONDOWN:
case WM_MBUTTONDBLCLK:
case WM_MBUTTONDOWN:
case WM_MBUTTONDBLCLK:
{
Event event;
event.Type = Event::EVENT_MOUSE_BUTTON_PRESSED;
event.MouseButton.Button = MOUSEBUTTON_MIDDLE;
event.MouseButton.X = static_cast<short>(LOWORD(lParam));
event.MouseButton.Y = static_cast<short>(HIWORD(lParam));
event.MouseButton.Y = static_cast<short>(HIWORD(lParam));
window->pushEvent(event);
break;
}
// Mouse wheel button up event
case WM_MBUTTONUP:
case WM_MBUTTONUP:
{
Event event;
event.Type = Event::EVENT_MOUSE_BUTTON_RELEASED;
event.MouseButton.Button = MOUSEBUTTON_MIDDLE;
event.MouseButton.X = static_cast<short>(LOWORD(lParam));
event.MouseButton.Y = static_cast<short>(HIWORD(lParam));
event.MouseButton.Y = static_cast<short>(HIWORD(lParam));
window->pushEvent(event);
break;
}
// Mouse X button down event
case WM_XBUTTONDOWN:
case WM_XBUTTONDBLCLK:
case WM_XBUTTONDOWN:
case WM_XBUTTONDBLCLK:
{
Event event;
event.Type = Event::EVENT_MOUSE_BUTTON_PRESSED;
event.MouseButton.Button = (HIWORD(wParam) == XBUTTON1) ? MOUSEBUTTON_BUTTON4 : MOUSEBUTTON_BUTTON5;
event.MouseButton.X = static_cast<short>(LOWORD(lParam));
event.MouseButton.Y = static_cast<short>(HIWORD(lParam));
event.Type = Event::EVENT_MOUSE_BUTTON_PRESSED;
event.MouseButton.Button =
(HIWORD(wParam) == XBUTTON1) ? MOUSEBUTTON_BUTTON4 : MOUSEBUTTON_BUTTON5;
event.MouseButton.X = static_cast<short>(LOWORD(lParam));
event.MouseButton.Y = static_cast<short>(HIWORD(lParam));
window->pushEvent(event);
break;
}
// Mouse X button up event
case WM_XBUTTONUP:
case WM_XBUTTONUP:
{
Event event;
event.Type = Event::EVENT_MOUSE_BUTTON_RELEASED;
event.MouseButton.Button = (HIWORD(wParam) == XBUTTON1) ? MOUSEBUTTON_BUTTON4 : MOUSEBUTTON_BUTTON5;
event.MouseButton.X = static_cast<short>(LOWORD(lParam));
event.MouseButton.Y = static_cast<short>(HIWORD(lParam));
event.Type = Event::EVENT_MOUSE_BUTTON_RELEASED;
event.MouseButton.Button =
(HIWORD(wParam) == XBUTTON1) ? MOUSEBUTTON_BUTTON4 : MOUSEBUTTON_BUTTON5;
event.MouseButton.X = static_cast<short>(LOWORD(lParam));
event.MouseButton.Y = static_cast<short>(HIWORD(lParam));
window->pushEvent(event);
break;
}
case WM_MOUSEMOVE:
case WM_MOUSEMOVE:
{
int mouseX = static_cast<short>(LOWORD(lParam));
int mouseY = static_cast<short>(HIWORD(lParam));
@ -354,7 +455,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
break;
}
case WM_MOUSELEAVE:
case WM_MOUSELEAVE:
{
Event event;
event.Type = Event::EVENT_MOUSE_LEFT;
@ -362,7 +463,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
break;
}
case WM_USER:
case WM_USER:
{
Event testEvent;
testEvent.Type = Event::EVENT_TEST;
@ -370,7 +471,6 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
break;
}
}
}
return DefWindowProcA(hWnd, message, wParam, lParam);
}
@ -401,54 +501,55 @@ bool Win32Window::initialize(const std::string &name, size_t width, size_t heigh
nameStream << name << "_" << windowIdx++;
mParentClassName = nameStream.str();
mChildClassName = mParentClassName + "_Child";
mChildClassName = mParentClassName + "_Child";
// Work around compile error from not defining "UNICODE" while Chromium does
const LPSTR idcArrow = MAKEINTRESOURCEA(32512);
WNDCLASSEXA parentWindowClass = { 0 };
parentWindowClass.cbSize = sizeof(WNDCLASSEXA);
parentWindowClass.style = 0;
parentWindowClass.lpfnWndProc = WndProc;
parentWindowClass.cbClsExtra = 0;
parentWindowClass.cbWndExtra = 0;
parentWindowClass.hInstance = GetModuleHandle(NULL);
parentWindowClass.hIcon = NULL;
parentWindowClass.hCursor = LoadCursorA(NULL, idcArrow);
WNDCLASSEXA parentWindowClass = {0};
parentWindowClass.cbSize = sizeof(WNDCLASSEXA);
parentWindowClass.style = 0;
parentWindowClass.lpfnWndProc = WndProc;
parentWindowClass.cbClsExtra = 0;
parentWindowClass.cbWndExtra = 0;
parentWindowClass.hInstance = GetModuleHandle(NULL);
parentWindowClass.hIcon = NULL;
parentWindowClass.hCursor = LoadCursorA(NULL, idcArrow);
parentWindowClass.hbrBackground = 0;
parentWindowClass.lpszMenuName = NULL;
parentWindowClass.lpszMenuName = NULL;
parentWindowClass.lpszClassName = mParentClassName.c_str();
if (!RegisterClassExA(&parentWindowClass))
{
return false;
}
WNDCLASSEXA childWindowClass = { 0 };
childWindowClass.cbSize = sizeof(WNDCLASSEXA);
childWindowClass.style = CS_OWNDC;
childWindowClass.lpfnWndProc = WndProc;
childWindowClass.cbClsExtra = 0;
childWindowClass.cbWndExtra = 0;
childWindowClass.hInstance = GetModuleHandle(NULL);
childWindowClass.hIcon = NULL;
childWindowClass.hCursor = LoadCursorA(NULL, idcArrow);
WNDCLASSEXA childWindowClass = {0};
childWindowClass.cbSize = sizeof(WNDCLASSEXA);
childWindowClass.style = CS_OWNDC;
childWindowClass.lpfnWndProc = WndProc;
childWindowClass.cbClsExtra = 0;
childWindowClass.cbWndExtra = 0;
childWindowClass.hInstance = GetModuleHandle(NULL);
childWindowClass.hIcon = NULL;
childWindowClass.hCursor = LoadCursorA(NULL, idcArrow);
childWindowClass.hbrBackground = 0;
childWindowClass.lpszMenuName = NULL;
childWindowClass.lpszMenuName = NULL;
childWindowClass.lpszClassName = mChildClassName.c_str();
if (!RegisterClassExA(&childWindowClass))
{
return false;
}
DWORD parentStyle = WS_CAPTION | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SYSMENU;
DWORD parentStyle = WS_CAPTION | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SYSMENU;
DWORD parentExtendedStyle = WS_EX_APPWINDOW;
RECT sizeRect = { 0, 0, static_cast<LONG>(width), static_cast<LONG>(height) };
RECT sizeRect = {0, 0, static_cast<LONG>(width), static_cast<LONG>(height)};
AdjustWindowRectEx(&sizeRect, parentStyle, FALSE, parentExtendedStyle);
mParentWindow = CreateWindowExA(parentExtendedStyle, mParentClassName.c_str(), name.c_str(), parentStyle, CW_USEDEFAULT, CW_USEDEFAULT,
sizeRect.right - sizeRect.left, sizeRect.bottom - sizeRect.top, NULL, NULL,
GetModuleHandle(NULL), this);
mParentWindow =
CreateWindowExA(parentExtendedStyle, mParentClassName.c_str(), name.c_str(), parentStyle,
CW_USEDEFAULT, CW_USEDEFAULT, sizeRect.right - sizeRect.left,
sizeRect.bottom - sizeRect.top, NULL, NULL, GetModuleHandle(NULL), this);
mNativeWindow = CreateWindowExA(0, mChildClassName.c_str(), name.c_str(), WS_CHILD, 0, 0,
static_cast<int>(width), static_cast<int>(height),
@ -500,8 +601,8 @@ bool Win32Window::takeScreenshot(uint8_t *pixelData)
// Hack for DWM: There is no way to wait for DWM animations to finish, so we just have to wait
// for a while before issuing screenshot if window was just made visible.
{
static const double WAIT_WINDOW_VISIBLE_MS = 0.5; // Half a second for the animation
double timeSinceVisible = mSetVisibleTimer->getElapsedTime();
static const double WAIT_WINDOW_VISIBLE_MS = 0.5; // Half a second for the animation
double timeSinceVisible = mSetVisibleTimer->getElapsedTime();
if (timeSinceVisible < WAIT_WINDOW_VISIBLE_MS)
{
@ -509,21 +610,21 @@ bool Win32Window::takeScreenshot(uint8_t *pixelData)
}
}
HDC screenDC = nullptr;
HDC windowDC = nullptr;
HDC tmpDC = nullptr;
HDC screenDC = nullptr;
HDC windowDC = nullptr;
HDC tmpDC = nullptr;
HBITMAP tmpBitmap = nullptr;
if (!error)
{
screenDC = GetDC(nullptr);
error = screenDC == nullptr;
error = screenDC == nullptr;
}
if (!error)
{
windowDC = GetDC(mNativeWindow);
error = windowDC == nullptr;
error = windowDC == nullptr;
}
if (!error)
@ -535,7 +636,7 @@ bool Win32Window::takeScreenshot(uint8_t *pixelData)
if (!error)
{
tmpBitmap = CreateCompatibleBitmap(screenDC, mWidth, mHeight);
error = tmpBitmap == nullptr;
error = tmpBitmap == nullptr;
}
RECT rect = {0, 0, 0, 0};
@ -548,25 +649,26 @@ bool Win32Window::takeScreenshot(uint8_t *pixelData)
if (!error)
{
error = BitBlt(tmpDC, 0, 0, mWidth, mHeight, screenDC, rect.left, rect.top, SRCCOPY) == TRUE;
error =
BitBlt(tmpDC, 0, 0, mWidth, mHeight, screenDC, rect.left, rect.top, SRCCOPY) == TRUE;
}
if (!error)
{
BITMAPINFOHEADER bitmapInfo;
bitmapInfo.biSize = sizeof(BITMAPINFOHEADER);
bitmapInfo.biWidth = mWidth;
bitmapInfo.biHeight = -mHeight;
bitmapInfo.biPlanes = 1;
bitmapInfo.biBitCount = 32;
bitmapInfo.biCompression = BI_RGB;
bitmapInfo.biSizeImage = 0;
bitmapInfo.biSize = sizeof(BITMAPINFOHEADER);
bitmapInfo.biWidth = mWidth;
bitmapInfo.biHeight = -mHeight;
bitmapInfo.biPlanes = 1;
bitmapInfo.biBitCount = 32;
bitmapInfo.biCompression = BI_RGB;
bitmapInfo.biSizeImage = 0;
bitmapInfo.biXPelsPerMeter = 0;
bitmapInfo.biYPelsPerMeter = 0;
bitmapInfo.biClrUsed = 0;
bitmapInfo.biClrImportant = 0;
bitmapInfo.biClrUsed = 0;
bitmapInfo.biClrImportant = 0;
int getBitsResult = GetDIBits(screenDC, tmpBitmap, 0, mHeight, pixelData,
reinterpret_cast<BITMAPINFO*>(&bitmapInfo), DIB_RGB_COLORS);
reinterpret_cast<BITMAPINFO *>(&bitmapInfo), DIB_RGB_COLORS);
error = getBitsResult != 0;
}
@ -641,7 +743,8 @@ bool Win32Window::setPosition(int x, int y)
return false;
}
if (!MoveWindow(mParentWindow, x, y, windowRect.right - windowRect.left, windowRect.bottom - windowRect.top, TRUE))
if (!MoveWindow(mParentWindow, x, y, windowRect.right - windowRect.left,
windowRect.bottom - windowRect.top, TRUE))
{
return false;
}
@ -670,7 +773,8 @@ bool Win32Window::resize(int width, int height)
LONG diffX = (windowRect.right - windowRect.left) - clientRect.right;
LONG diffY = (windowRect.bottom - windowRect.top) - clientRect.bottom;
if (!MoveWindow(mParentWindow, windowRect.left, windowRect.top, width + diffX, height + diffY, TRUE))
if (!MoveWindow(mParentWindow, windowRect.left, windowRect.top, width + diffX, height + diffY,
TRUE))
{
return false;
}
@ -703,11 +807,11 @@ void Win32Window::pushEvent(Event event)
switch (event.Type)
{
case Event::EVENT_RESIZED:
MoveWindow(mNativeWindow, 0, 0, mWidth, mHeight, FALSE);
break;
default:
break;
case Event::EVENT_RESIZED:
MoveWindow(mNativeWindow, 0, 0, mWidth, mHeight, FALSE);
break;
default:
break;
}
}

Просмотреть файл

@ -4,7 +4,7 @@
// found in the LICENSE file.
//
// Win32Window.h: Definition of the implementation of OSWindow for Windows
// Win32Window.h: Definition of the implementation of OSWindow for Win32 (Windows)
#ifndef UTIL_WIN32_WINDOW_H
#define UTIL_WIN32_WINDOW_H
@ -19,7 +19,7 @@ class Win32Window : public OSWindow
{
public:
Win32Window();
~Win32Window();
~Win32Window() override;
bool initialize(const std::string &name, size_t width, size_t height) override;
void destroy() override;
@ -52,4 +52,4 @@ class Win32Window : public OSWindow
EGLNativeDisplayType mNativeDisplay;
};
#endif // UTIL_WIN32_WINDOW_H
#endif // UTIL_WIN32_WINDOW_H

Просмотреть файл

@ -0,0 +1,22 @@
//
// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Win32_system_utils.cpp: Implementation of OS-specific functions for Win32 (Windows)
#include "system_utils.h"
#include <windows.h>
#include <array>
namespace angle
{
void SetLowPriorityProcess()
{
SetPriorityClass(GetCurrentProcess(), BELOW_NORMAL_PRIORITY_CLASS);
}
} // namespace angle

Просмотреть файл

@ -0,0 +1,17 @@
//
// Copyright (c) 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// WinRTPixmap.cpp: Stub implementation of OSPixmap functions for WinRT (Windows)
#include "OSPixmap.h"
#include "common/debug.h"
OSPixmap *CreateOSPixmap()
{
UNIMPLEMENTED();
return nullptr;
}

Просмотреть файл

@ -0,0 +1,284 @@
//
// Copyright (c) 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// WinRTWindow.cpp: Implementation of OSWindow for WinRT (Windows)
#include "windows/winrt/WinRTWindow.h"
#include <wrl.h>
#include <windows.applicationmodel.core.h>
#include <windows.ui.xaml.h>
#include "angle_windowsstore.h"
#include "common/debug.h"
using namespace ABI::Windows::ApplicationModel::Core;
using namespace ABI::Windows::Foundation;
using namespace ABI::Windows::Foundation::Collections;
using namespace ABI::Windows::UI::Core;
using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers;
WinRTWindow::WinRTWindow() : mNativeWindow(nullptr)
{
}
WinRTWindow::~WinRTWindow()
{
destroy();
}
bool WinRTWindow::initialize(const std::string &name, size_t width, size_t height)
{
ComPtr<ICoreWindowStatic> coreWindowStatic;
ComPtr<IActivationFactory> propertySetFactory;
ComPtr<IPropertyValueStatics> propertyValueStatics;
ComPtr<ICoreApplication> coreApplication;
ComPtr<IPropertySet> coreApplicationProperties;
ComPtr<IMap<HSTRING, IInspectable *>> coreApplicationPropertiesAsMap;
ComPtr<IMap<HSTRING, IInspectable *>> nativeWindowAsMap;
ComPtr<IInspectable> sizeValue;
HRESULT result = S_OK;
boolean propertyReplaced = false;
destroy();
// Get all the relevant activation factories
result = GetActivationFactory(
HStringReference(RuntimeClass_Windows_UI_Core_CoreWindow).Get(), &coreWindowStatic);
if (FAILED(result))
{
return false;
}
result = GetActivationFactory(
HStringReference(RuntimeClass_Windows_Foundation_Collections_PropertySet).Get(),
&propertySetFactory);
if (FAILED(result))
{
return false;
}
result =
GetActivationFactory(HStringReference(RuntimeClass_Windows_Foundation_PropertyValue).Get(),
&propertyValueStatics);
if (FAILED(result))
{
return false;
}
result = GetActivationFactory(
HStringReference(RuntimeClass_Windows_ApplicationModel_Core_CoreApplication).Get(),
&coreApplication);
if (FAILED(result))
{
return false;
}
// Create a PropertySet to be used as the native window
result = propertySetFactory->ActivateInstance(&mNativeWindow);
if (FAILED(result))
{
return false;
}
// Get the PropertySet as a map, so we can Insert things into it later
ComPtr<IInspectable> tempNativeWindow = mNativeWindow;
result = tempNativeWindow.As(&nativeWindowAsMap);
if (FAILED(result))
{
return false;
}
// Get the CoreApplication properties
result = coreApplication->get_Properties(coreApplicationProperties.GetAddressOf());
if (FAILED(result))
{
return false;
}
// Get the CoreApplication properties as a map
result = coreApplicationProperties.As(&coreApplicationPropertiesAsMap);
if (FAILED(result))
{
return false;
}
// See if the application properties contain an EGLNativeWindowTypeProperty
boolean hasEGLNativeWindowTypeProperty;
result = coreApplicationPropertiesAsMap->HasKey(
HStringReference(EGLNativeWindowTypeProperty).Get(), &hasEGLNativeWindowTypeProperty);
if (FAILED(result))
{
return false;
}
// If an EGLNativeWindowTypeProperty is inputted then use it
if (hasEGLNativeWindowTypeProperty)
{
ComPtr<IInspectable> coreApplicationPropertyNativeWindow;
result = coreApplicationPropertiesAsMap->Lookup(
HStringReference(EGLNativeWindowTypeProperty).Get(),
&coreApplicationPropertyNativeWindow);
if (FAILED(result))
{
return false;
}
// See if the inputted window was a CoreWindow
ComPtr<ICoreWindow> applicationPropertyCoreWindow;
if (SUCCEEDED(coreApplicationPropertyNativeWindow.As(&applicationPropertyCoreWindow)))
{
// Store away the CoreWindow's dispatcher, to be used later to process messages
result = applicationPropertyCoreWindow->get_Dispatcher(&mCoreDispatcher);
if (FAILED(result))
{
return false;
}
}
else
{
ComPtr<IPropertySet> propSet;
// Disallow Property Sets here, since we want to wrap this window in
// a property set with the size property below
if (SUCCEEDED(coreApplicationPropertyNativeWindow.As(&propSet)))
{
return false;
}
}
// Add the window to the map
result =
nativeWindowAsMap->Insert(HStringReference(EGLNativeWindowTypeProperty).Get(),
coreApplicationPropertyNativeWindow.Get(), &propertyReplaced);
if (FAILED(result))
{
return false;
}
}
else
{
ComPtr<ICoreWindow> currentThreadCoreWindow;
// Get the CoreWindow for the current thread
result = coreWindowStatic->GetForCurrentThread(&currentThreadCoreWindow);
if (FAILED(result))
{
return false;
}
// By default, just add this thread's CoreWindow to the PropertySet
result = nativeWindowAsMap->Insert(HStringReference(EGLNativeWindowTypeProperty).Get(),
currentThreadCoreWindow.Get(), &propertyReplaced);
if (FAILED(result))
{
return false;
}
// Store away the CoreWindow's dispatcher, to be used later to process messages
result = currentThreadCoreWindow->get_Dispatcher(&mCoreDispatcher);
if (FAILED(result))
{
return false;
}
}
// Create a Size to represent the Native Window's size
Size renderSize;
renderSize.Width = static_cast<float>(width);
renderSize.Height = static_cast<float>(height);
result = propertyValueStatics->CreateSize(renderSize, sizeValue.GetAddressOf());
if (FAILED(result))
{
return false;
}
// Add the Size to the PropertySet
result = nativeWindowAsMap->Insert(HStringReference(EGLRenderSurfaceSizeProperty).Get(),
sizeValue.Get(), &propertyReplaced);
if (FAILED(result))
{
return false;
}
return true;
};
void WinRTWindow::destroy()
{
SafeRelease(mNativeWindow);
mCoreDispatcher.Reset();
}
EGLNativeWindowType WinRTWindow::getNativeWindow() const
{
return mNativeWindow;
}
EGLNativeDisplayType WinRTWindow::getNativeDisplay() const
{
UNIMPLEMENTED();
return static_cast<EGLNativeDisplayType>(0);
}
void WinRTWindow::messageLoop()
{
// If we have a CoreDispatcher then use it to process events
if (mCoreDispatcher)
{
HRESULT result =
mCoreDispatcher->ProcessEvents(CoreProcessEventsOption_ProcessAllIfPresent);
UNUSED_ASSERTION_VARIABLE(result);
ASSERT(SUCCEEDED(result));
}
}
void WinRTWindow::setMousePosition(int /* x */, int /* y */)
{
UNIMPLEMENTED();
}
bool WinRTWindow::setPosition(int /* x */, int /* y */)
{
UNIMPLEMENTED();
return false;
}
bool WinRTWindow::resize(int /* width */, int /* height */)
{
UNIMPLEMENTED();
return false;
}
void WinRTWindow::setVisible(bool isVisible)
{
if (isVisible)
{
// Already visible by default
return;
}
else
{
// Not implemented in WinRT
UNIMPLEMENTED();
}
}
void WinRTWindow::signalTestEvent()
{
UNIMPLEMENTED();
}
OSWindow *CreateOSWindow()
{
return new WinRTWindow();
}

Просмотреть файл

@ -0,0 +1,45 @@
//
// Copyright (c) 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// WinRTWindow.h: Definition of the implementation of OSWindow for WinRT (Windows)
#ifndef UTIL_WINRT_WINDOW_H
#define UTIL_WINRT_WINDOW_H
#include <string>
#include <windows.h>
#include <windows.applicationmodel.core.h>
#include <wrl.h>
#include "OSWindow.h"
class WinRTWindow : public OSWindow
{
public:
WinRTWindow();
~WinRTWindow() override;
bool initialize(const std::string &name, size_t width, size_t height) override;
void destroy() override;
EGLNativeWindowType getNativeWindow() const override;
EGLNativeDisplayType getNativeDisplay() const override;
void messageLoop() override;
void setMousePosition(int x, int y) override;
bool setPosition(int x, int y) override;
bool resize(int width, int height) override;
void setVisible(bool isVisible) override;
void signalTestEvent() override;
private:
EGLNativeWindowType mNativeWindow;
Microsoft::WRL::ComPtr<ABI::Windows::UI::Core::ICoreDispatcher> mCoreDispatcher;
};
#endif // UTIL_WINRT_WINDOW_H

Просмотреть файл

@ -0,0 +1,22 @@
//
// Copyright (c) 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// WinRT_system_utils.cpp: Implementation of OS-specific functions for WinRT (Windows)
#include "system_utils.h"
#include <windows.h>
#include <array>
namespace angle
{
void SetLowPriorityProcess()
{
// No equivalent to this in WinRT
}
} // namespace angle