SDL  2.0
SDL_winrtapp_direct3d.cpp File Reference
#include "../../SDL_internal.h"
#include <functional>
#include <string>
#include <sstream>
#include "ppltasks.h"
#include "SDL_assert.h"
#include "SDL_events.h"
#include "SDL_hints.h"
#include "SDL_log.h"
#include "SDL_main.h"
#include "SDL_stdinc.h"
#include "SDL_render.h"
#include "../../video/SDL_sysvideo.h"
#include "../../events/SDL_events_c.h"
#include "../../events/SDL_keyboard_c.h"
#include "../../events/SDL_mouse_c.h"
#include "../../events/SDL_windowevents_c.h"
#include "../../render/SDL_sysrender.h"
#include "../windows/SDL_windows.h"
#include "../../video/winrt/SDL_winrtevents_c.h"
#include "../../video/winrt/SDL_winrtvideo_cpp.h"
#include "SDL_winrtapp_common.h"
#include "SDL_winrtapp_direct3d.h"
+ Include dependency graph for SDL_winrtapp_direct3d.cpp:

Go to the source code of this file.

Data Structures

class  sealed
 

Functions

int SDL_WinRTInitNonXAMLApp (int(*mainFunction)(int, char **))
 
static void WINRT_SetDisplayOrientationsPreference (void *userdata, const char *name, const char *oldValue, const char *newValue)
 
static void WINRT_ProcessWindowSizeChange ()
 
static bool IsSDLWindowEventPending (SDL_WindowEventID windowEventID)
 
static void WINRT_LogPointerEvent (const char *header, Windows::UI::Core::PointerEventArgs ^ args, Windows::Foundation::Point transformedPoint)
 
template<typename BackButtonEventArgs >
static void WINRT_OnBackButtonPressed (BackButtonEventArgs ^ args)
 

Variables

SDL_WinRTApp SDL_WinRTGlobalApp = nullptr
 

Function Documentation

◆ IsSDLWindowEventPending()

static bool IsSDLWindowEventPending ( SDL_WindowEventID  windowEventID)
static

Definition at line 434 of file SDL_winrtapp_direct3d.cpp.

References events, i, SDL_Renderer::info, SDL_RendererInfo::name, NULL, renderer, SDL_APP_DIDENTERBACKGROUND, SDL_APP_DIDENTERFOREGROUND, SDL_APP_TERMINATING, SDL_APP_WILLENTERBACKGROUND, SDL_APP_WILLENTERFOREGROUND, SDL_free, SDL_GetHint, SDL_GetKeyboardFocus, SDL_GetRenderer, SDL_HINT_WINRT_PRIVACY_POLICY_LABEL, SDL_HINT_WINRT_PRIVACY_POLICY_URL, SDL_Log, SDL_PEEKEVENT, SDL_PeepEvents, SDL_SendAppEvent(), SDL_SendMouseMotion(), SDL_SendWindowEvent(), SDL_SetCursor, SDL_SetKeyboardFocus(), SDL_strcmp, SDL_WINDOW_MAXIMIZED, SDL_WINDOWEVENT, SDL_WINDOWEVENT_FOCUS_GAINED, SDL_WINDOWEVENT_FOCUS_LOST, SDL_WINDOWEVENT_HIDDEN, SDL_WINDOWEVENT_MAXIMIZED, SDL_WINDOWEVENT_MINIMIZED, SDL_WINDOWEVENT_RESTORED, SDL_WINDOWEVENT_SHOWN, SDL_Window::surface_valid, WIN_UTF8ToString, WINRT_DetectWindowFlags(), WINRT_GlobalSDLWindow, and WINRT_ProcessWindowSizeChange().

435 {
436  SDL_Event events[128];
437  const int count = SDL_PeepEvents(events, sizeof(events)/sizeof(SDL_Event), SDL_PEEKEVENT, SDL_WINDOWEVENT, SDL_WINDOWEVENT);
438  for (int i = 0; i < count; ++i) {
439  if (events[i].window.event == windowEventID) {
440  return true;
441  }
442  }
443  return false;
444 }
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
static SDL_Event events[EVENT_BUF_SIZE]
Definition: testgesture.c:35
#define SDL_PeepEvents
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
General event structure.
Definition: SDL_events.h:525

◆ SDL_WinRTInitNonXAMLApp()

int SDL_WinRTInitNonXAMLApp ( int(*)(int, char **)  mainFunction)

Definition at line 116 of file SDL_winrtapp_direct3d.cpp.

References Run(), SDLCALL, and WINRT_SDLAppEntryPoint.

Referenced by SDL_WinRTRunApp().

117 {
118  WINRT_SDLAppEntryPoint = mainFunction;
119  auto direct3DApplicationSource = ref new SDLApplicationSource();
120  CoreApplication::Run(direct3DApplicationSource);
121  return 0;
122 }
GLenum GLint ref
int Run(void *data)
Definition: testlock.c:65
int(* WINRT_SDLAppEntryPoint)(int, char **)

◆ WINRT_LogPointerEvent()

static void WINRT_LogPointerEvent ( const char *  header,
Windows::UI::Core::PointerEventArgs ^  args,
Windows::Foundation::Point  transformedPoint 
)
static

Definition at line 732 of file SDL_winrtapp_direct3d.cpp.

References SDL_Log, and WINRT_GlobalSDLWindow.

733 {
734  Windows::UI::Input::PointerPoint ^ pt = args->CurrentPoint;
735  SDL_Log("%s: Position={%f,%f}, Transformed Pos={%f, %f}, MouseWheelDelta=%d, FrameId=%d, PointerId=%d, SDL button=%d\n",
736  header,
737  pt->Position.X, pt->Position.Y,
738  transformedPoint.X, transformedPoint.Y,
739  pt->Properties->MouseWheelDelta,
740  pt->FrameId,
741  pt->PointerId,
742  WINRT_GetSDLButtonForPointerPoint(pt));
743 }
#define SDL_Log

◆ WINRT_OnBackButtonPressed()

template<typename BackButtonEventArgs >
static void WINRT_OnBackButtonPressed ( BackButtonEventArgs ^  args)
static

Definition at line 820 of file SDL_winrtapp_direct3d.cpp.

References SDL_FALSE, SDL_GetHintBoolean, SDL_HINT_WINRT_HANDLE_BACK_BUTTON, SDL_PRESSED, SDL_RELEASED, SDL_SCANCODE_AC_BACK, and SDL_SendKeyboardKey().

821 {
824 
826  args->Handled = true;
827  }
828 }
int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
Definition: SDL_keyboard.c:679
#define SDL_GetHintBoolean
#define SDL_PRESSED
Definition: SDL_events.h:50
#define SDL_HINT_WINRT_HANDLE_BACK_BUTTON
Allows back-button-press events on Windows Phone to be marked as handled.
Definition: SDL_hints.h:678
#define SDL_RELEASED
Definition: SDL_events.h:49

◆ WINRT_ProcessWindowSizeChange()

static void WINRT_ProcessWindowSizeChange ( )
static

Definition at line 187 of file SDL_winrtapp_direct3d.cpp.

References SDL_Window::driverdata, NULL, Run(), SDL_AddHintCallback, SDL_HINT_ORIENTATIONS, SDL_Log, SDL_SendWindowEvent(), SDL_SetMainReady, SDL_WINDOW_FULLSCREEN_DESKTOP, SDL_WINDOW_MAXIMIZED, SDL_WINDOWEVENT_MAXIMIZED, SDL_WINDOWEVENT_MOVED, SDL_WINDOWEVENT_RESIZED, SDL_WINDOWEVENT_RESTORED, SDL_WINDOWEVENT_SIZE_CHANGED, WINRT_DetectWindowFlags(), WINRT_GlobalSDLWindow, WINRT_SDLAppEntryPoint, WINRT_SetDisplayOrientationsPreference(), and WINRT_UpdateWindowFlags().

Referenced by IsSDLWindowEventPending().

188 {
189  CoreWindow ^ coreWindow = CoreWindow::GetForCurrentThread();
190  if (coreWindow) {
191  if (WINRT_GlobalSDLWindow) {
194 
195  int x = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Left);
196  int y = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Top);
197  int w = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Width);
198  int h = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Height);
199 
200 #if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) && (NTDDI_VERSION == NTDDI_WIN8)
201  /* WinPhone 8.0 always keeps its native window size in portrait,
202  regardless of orientation. This changes in WinPhone 8.1,
203  in which the native window's size changes along with
204  orientation.
205 
206  Attempt to emulate WinPhone 8.1's behavior on WinPhone 8.0, with
207  regards to window size. This fixes a rendering bug that occurs
208  when a WinPhone 8.0 app is rotated to either 90 or 270 degrees.
209  */
210  const DisplayOrientations currentOrientation = WINRT_DISPLAY_PROPERTY(CurrentOrientation);
211  switch (currentOrientation) {
212  case DisplayOrientations::Landscape:
213  case DisplayOrientations::LandscapeFlipped: {
214  int tmp = w;
215  w = h;
216  h = tmp;
217  } break;
218  }
219 #endif
220 
221  const Uint32 latestFlags = WINRT_DetectWindowFlags(window);
222  if (latestFlags & SDL_WINDOW_MAXIMIZED) {
224  } else {
226  }
227 
229 
230  /* The window can move during a resize event, such as when maximizing
231  or resizing from a corner */
234  }
235  }
236 }
void WINRT_UpdateWindowFlags(SDL_Window *window, Uint32 mask)
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
GLfloat GLfloat GLfloat GLfloat h
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
uint32_t Uint32
Definition: SDL_stdinc.h:181
GLubyte GLubyte GLubyte GLubyte w
Uint32 WINRT_DetectWindowFlags(SDL_Window *window)
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
SDL_Window * WINRT_GlobalSDLWindow
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
The type used to identify a window.
Definition: SDL_sysvideo.h:73
void * driverdata
Definition: SDL_sysvideo.h:111

◆ WINRT_SetDisplayOrientationsPreference()

static void WINRT_SetDisplayOrientationsPreference ( void userdata,
const char *  name,
const char *  oldValue,
const char *  newValue 
)
static

Definition at line 125 of file SDL_winrtapp_direct3d.cpp.

References NULL, SDL_assert, SDL_HINT_ORIENTATIONS, and SDL_strcmp.

Referenced by WINRT_ProcessWindowSizeChange().

126 {
128 
129  /* HACK: prevent SDL from altering an app's .appxmanifest-set orientation
130  * from being changed on startup, by detecting when SDL_HINT_ORIENTATIONS
131  * is getting registered.
132  *
133  * TODO, WinRT: consider reading in an app's .appxmanifest file, and apply its orientation when 'newValue == NULL'.
134  */
135  if ((oldValue == NULL) && (newValue == NULL)) {
136  return;
137  }
138 
139  // Start with no orientation flags, then add each in as they're parsed
140  // from newValue.
141  unsigned int orientationFlags = 0;
142  if (newValue) {
143  std::istringstream tokenizer(newValue);
144  while (!tokenizer.eof()) {
145  std::string orientationName;
146  std::getline(tokenizer, orientationName, ' ');
147  if (orientationName == "LandscapeLeft") {
148  orientationFlags |= (unsigned int) DisplayOrientations::LandscapeFlipped;
149  } else if (orientationName == "LandscapeRight") {
150  orientationFlags |= (unsigned int) DisplayOrientations::Landscape;
151  } else if (orientationName == "Portrait") {
152  orientationFlags |= (unsigned int) DisplayOrientations::Portrait;
153  } else if (orientationName == "PortraitUpsideDown") {
154  orientationFlags |= (unsigned int) DisplayOrientations::PortraitFlipped;
155  }
156  }
157  }
158 
159  // If no valid orientation flags were specified, use a reasonable set of defaults:
160  if (!orientationFlags) {
161  // TODO, WinRT: consider seeing if an app's default orientation flags can be found out via some API call(s).
162  orientationFlags = (unsigned int) ( \
163  DisplayOrientations::Landscape |
164  DisplayOrientations::LandscapeFlipped |
165  DisplayOrientations::Portrait |
166  DisplayOrientations::PortraitFlipped);
167  }
168 
169  // Set the orientation/rotation preferences. Please note that this does
170  // not constitute a 100%-certain lock of a given set of possible
171  // orientations. According to Microsoft's documentation on WinRT [1]
172  // when a device is not capable of being rotated, Windows may ignore
173  // the orientation preferences, and stick to what the device is capable of
174  // displaying.
175  //
176  // [1] Documentation on the 'InitialRotationPreference' setting for a
177  // Windows app's manifest file describes how some orientation/rotation
178  // preferences may be ignored. See
179  // http://msdn.microsoft.com/en-us/library/windows/apps/hh700343.aspx
180  // for details. Microsoft's "Display orientation sample" also gives an
181  // outline of how Windows treats device rotation
182  // (http://code.msdn.microsoft.com/Display-Orientation-Sample-19a58e93).
183  WINRT_DISPLAY_PROPERTY(AutoRotationPreferences) = (DisplayOrientations) orientationFlags;
184 }
GLsizei const GLchar *const * string
GLuint const GLchar * name
#define SDL_assert(condition)
Definition: SDL_assert.h:169
#define SDL_HINT_ORIENTATIONS
A variable controlling which orientations are allowed on iOS.
Definition: SDL_hints.h:340
#define NULL
Definition: begin_code.h:164
#define SDL_strcmp

Variable Documentation

◆ SDL_WinRTGlobalApp

SDL_WinRTApp SDL_WinRTGlobalApp = nullptr

Definition at line 94 of file SDL_winrtapp_direct3d.cpp.