1 #include "Common/System/Display.h"
2 #include "Common/Math/math_util.h"
3 
4 int dp_xres;
5 int dp_yres;
6 
7 int pixel_xres;
8 int pixel_yres;
9 
10 float g_dpi = 1.0f;  // will be overwritten with a value that makes sense.
11 float g_dpi_scale_x = 1.0f;
12 float g_dpi_scale_y = 1.0f;
13 float g_dpi_scale_real_x = 1.0f;
14 float g_dpi_scale_real_y = 1.0f;
15 float pixel_in_dps_x = 1.0f;
16 float pixel_in_dps_y = 1.0f;
17 float display_hz = 60.0f;
18 
19 DisplayRotation g_display_rotation;
20 Lin::Matrix4x4 g_display_rot_matrix = Lin::Matrix4x4::identity();
21 
22 template<class T>
RotateRectToDisplayImpl(DisplayRect<T> & rect,T curRTWidth,T curRTHeight)23 void RotateRectToDisplayImpl(DisplayRect<T> &rect, T curRTWidth, T curRTHeight) {
24 	switch (g_display_rotation) {
25 	case DisplayRotation::ROTATE_180:
26 		rect.x = curRTWidth - rect.w - rect.x;
27 		rect.y = curRTHeight - rect.h - rect.y;
28 		break;
29 	case DisplayRotation::ROTATE_90: {
30 		// Note that curRTWidth_ and curRTHeight_ are "swapped"!
31 		T origX = rect.x;
32 		T origY = rect.y;
33 		T rth = curRTWidth;
34 		rect.x = clamp_value(rth - rect.h - origY, T{}, curRTHeight);
35 		rect.y = origX;
36 		T temp = rect.w;
37 		rect.w = rect.h;
38 		rect.h = temp;
39 		break;
40 	}
41 	case DisplayRotation::ROTATE_270: {
42 		T origX = rect.x;
43 		T origY = rect.y;
44 		T rtw = curRTHeight;
45 		rect.x = origY;
46 		rect.y = clamp_value(rtw - rect.w - origX, T{}, curRTWidth);
47 		T temp = rect.w;
48 		rect.w = rect.h;
49 		rect.h = temp;
50 		break;
51 	}
52 	case DisplayRotation::ROTATE_0:
53 	default:
54 		break;
55 	}
56 }
57 
RotateRectToDisplay(DisplayRect<int> & rect,int curRTWidth,int curRTHeight)58 void RotateRectToDisplay(DisplayRect<int> &rect, int curRTWidth, int curRTHeight) {
59 	RotateRectToDisplayImpl<int>(rect, curRTWidth, curRTHeight);
60 }
61 
RotateRectToDisplay(DisplayRect<float> & rect,float curRTWidth,float curRTHeight)62 void RotateRectToDisplay(DisplayRect<float> &rect, float curRTWidth, float curRTHeight) {
63 	RotateRectToDisplayImpl<float>(rect, curRTWidth, curRTHeight);
64 }
65