-
Notifications
You must be signed in to change notification settings - Fork 539
/
ClientDisplayView.h
429 lines (351 loc) · 13.1 KB
/
ClientDisplayView.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
/*
Copyright (C) 2017 DeSmuME team
This file is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This file is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the this software. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _CLIENT_DISPLAY_VIEW_H_
#define _CLIENT_DISPLAY_VIEW_H_
#include <pthread.h>
#include <map>
#include <string>
#include "../../filter/videofilter.h"
#include "../../GPU.h"
#include "ClientExecutionControl.h"
#include <ft2build.h>
#include FT_FREETYPE_H
#define HUD_TOTAL_ELEMENTS 1024
#define HUD_INPUT_ELEMENT_LENGTH 26
#define HUD_INPUT_TOUCH_LINE_ELEMENTS 4
#define HUD_TEXT_MAX_CHARACTERS (HUD_TOTAL_ELEMENTS - HUD_INPUT_ELEMENT_LENGTH - HUD_INPUT_TOUCH_LINE_ELEMENTS)
#define HUD_VERTEX_ATTRIBUTE_BUFFER_SIZE (sizeof(float) * HUD_TOTAL_ELEMENTS * (2 * 4))
#define HUD_VERTEX_COLOR_ATTRIBUTE_BUFFER_SIZE (sizeof(uint32_t) * HUD_TOTAL_ELEMENTS * 4)
#define HUD_TEXTBOX_BASEGLYPHSIZE 64.0
#define HUD_TEXTBOX_BASE_SCALE (1.0/3.0)
#define HUD_TEXTBOX_MIN_SCALE 0.70
#define DS_DISPLAY_VERTICAL_GAP_TO_HEIGHT_RATIO (21.0/46.0) // Based on the official DS specification: 21mm/46mm
#define DS_DISPLAY_UNSCALED_GAP (GPU_FRAMEBUFFER_NATIVE_HEIGHT * DS_DISPLAY_VERTICAL_GAP_TO_HEIGHT_RATIO)
enum ClientDisplayMode
{
ClientDisplayMode_Main = 0,
ClientDisplayMode_Touch,
ClientDisplayMode_Dual
};
enum ClientDisplayLayout
{
ClientDisplayLayout_Vertical = 0,
ClientDisplayLayout_Horizontal = 1,
ClientDisplayLayout_Hybrid_2_1 = 1000,
ClientDisplayLayout_Hybrid_16_9 = 1001,
ClientDisplayLayout_Hybrid_16_10 = 1002
};
enum ClientDisplayOrder
{
ClientDisplayOrder_MainFirst = 0,
ClientDisplayOrder_TouchFirst
};
enum ClientDisplaySource
{
ClientDisplaySource_None = 0,
ClientDisplaySource_DeterminedByNDS = 1,
ClientDisplaySource_EngineMain = 2,
ClientDisplaySource_EngineSub = 3
};
enum OutputFilterTypeID
{
OutputFilterTypeID_NearestNeighbor = 0,
OutputFilterTypeID_Bilinear = 1,
OutputFilterTypeID_BicubicBSpline = 2,
OutputFilterTypeID_BicubicMitchell = 3,
OutputFilterTypeID_Lanczos2 = 4,
OutputFilterTypeID_Lanczos3 = 5
};
typedef std::map<int, bool> InitialTouchPressMap; // Key = An ID number of the host input, Value = Flag that indicates if the initial touch press was in the major display
struct GlyphInfo
{
float width;
float texCoord[8];
};
typedef struct GlyphInfo GlyphInfo;
struct LUTValues
{
uint8_t p0;
uint8_t p1;
uint8_t p2;
uint8_t pad0;
uint8_t w0;
uint8_t w1;
uint8_t w2;
uint8_t pad1;
};
typedef struct LUTValues LUTValues;
struct ClientFrameInfo
{
uint32_t videoFPS;
};
typedef struct ClientFrameInfo ClientFrameInfo;
struct ClientDisplayPresenterProperties
{
ClientDisplayMode mode;
ClientDisplayLayout layout;
ClientDisplayOrder order;
double gapScale;
double rotation;
double clientWidth;
double clientHeight;
double normalWidth;
double normalHeight;
double viewScale;
double gapDistance;
};
typedef struct ClientDisplayPresenterProperties ClientDisplayPresenterProperties;
extern LUTValues *_LQ2xLUT;
extern LUTValues *_HQ2xLUT;
extern LUTValues *_HQ3xLUT;
extern LUTValues *_HQ4xLUT;
void InitHQnxLUTs();
class ClientDisplayPresenter
{
private:
void __InstanceInit(const ClientDisplayPresenterProperties &props);
protected:
ClientDisplayPresenterProperties _renderProperty;
ClientDisplayPresenterProperties _stagedProperty;
GPUClientFetchObject *_fetchObject;
bool _useDeposterize;
VideoFilterTypeID _pixelScaler;
OutputFilterTypeID _outputFilter;
ClientDisplaySource _displaySourceSelect[2];
bool _isSelectedDisplayEnabled[2];
NDSDisplayID _selectedSourceForDisplay[2];
double _scaleFactor;
double _hudObjectScale;
bool _isHUDVisible;
bool _showVideoFPS;
bool _showRender3DFPS;
bool _showFrameIndex;
bool _showLagFrameCount;
bool _showCPULoadAverage;
bool _showRTC;
bool _showInputs;
uint32_t _hudColorVideoFPS;
uint32_t _hudColorRender3DFPS;
uint32_t _hudColorFrameIndex;
uint32_t _hudColorLagFrameCount;
uint32_t _hudColorCPULoadAverage;
uint32_t _hudColorRTC;
uint32_t _hudColorInputAppliedAndPending;
uint32_t _hudColorInputAppliedOnly;
uint32_t _hudColorInputPendingOnly;
ClientFrameInfo _clientFrameInfo;
NDSFrameInfo _ndsFrameInfo;
NDSDisplayInfo _emuDisplayInfo;
std::string _hudString;
std::string _hudInputString;
std::string _outHudString;
bool _hudNeedsUpdate;
FT_Library _ftLibrary;
const char *_lastFontFilePath;
GlyphInfo _glyphInfo[256];
size_t _glyphSize;
size_t _glyphTileSize;
uint32_t *_vfMasterDstBuffer;
size_t _vfMasterDstBufferSize;
VideoFilter *_vf[2];
pthread_mutex_t _mutexHUDString;
void _UpdateHUDString();
void _SetHUDShowInfoItem(bool &infoItemFlag, const bool visibleState);
virtual void _UpdateNormalSize() = 0;
virtual void _UpdateOrder() = 0;
virtual void _UpdateRotation() = 0;
virtual void _UpdateClientSize();
virtual void _UpdateViewScale();
virtual void _LoadNativeDisplayByID(const NDSDisplayID displayID);
virtual void _LoadCustomDisplayByID(const NDSDisplayID displayID);
virtual void _ResizeCPUPixelScaler(const VideoFilterTypeID filterID);
public:
ClientDisplayPresenter();
ClientDisplayPresenter(const ClientDisplayPresenterProperties &props);
virtual ~ClientDisplayPresenter();
virtual void Init();
double GetScaleFactor() const;
virtual void SetScaleFactor(const double scaleFactor);
// NDS screen layout
const ClientDisplayPresenterProperties& GetPresenterProperties() const;
void CommitPresenterProperties(const ClientDisplayPresenterProperties &props);
virtual void SetupPresenterProperties();
double GetRotation() const;
double GetViewScale() const;
ClientDisplayMode GetMode() const;
ClientDisplayLayout GetLayout() const;
ClientDisplayOrder GetOrder() const;
double GetGapScale() const;
double GetGapDistance() const;
ClientDisplaySource GetDisplayVideoSource(const NDSDisplayID displayID) const;
virtual void SetDisplayVideoSource(const NDSDisplayID displayID, ClientDisplaySource displaySrc);
NDSDisplayID GetSelectedDisplaySourceForDisplay(const NDSDisplayID displayID) const;
bool IsSelectedDisplayEnabled(const NDSDisplayID displayID) const;
// NDS screen filters
bool GetSourceDeposterize();
virtual void SetSourceDeposterize(const bool useDeposterize);
OutputFilterTypeID GetOutputFilter() const;
virtual void SetOutputFilter(const OutputFilterTypeID filterID);
VideoFilterTypeID GetPixelScaler() const;
virtual void SetPixelScaler(const VideoFilterTypeID filterID);
VideoFilter* GetPixelScalerObject(const NDSDisplayID displayID);
// HUD appearance
const char* GetHUDFontPath() const;
void SetHUDFontPath(const char *filePath);
virtual void LoadHUDFont();
virtual void CopyHUDFont(const FT_Face &fontFace, const size_t glyphSize, const size_t glyphTileSize, GlyphInfo *glyphInfo);
virtual void SetHUDInfo(const ClientFrameInfo &clientFrameInfo, const NDSFrameInfo &ndsFrameInfo);
const std::string& GetHUDString();
float GetHUDObjectScale() const;
virtual void SetHUDObjectScale(float objectScale);
bool GetHUDVisibility() const;
virtual void SetHUDVisibility(const bool visibleState);
bool GetHUDShowVideoFPS() const;
virtual void SetHUDShowVideoFPS(const bool visibleState);
bool GetHUDShowRender3DFPS() const;
virtual void SetHUDShowRender3DFPS(const bool visibleState);
bool GetHUDShowFrameIndex() const;
virtual void SetHUDShowFrameIndex(const bool visibleState);
bool GetHUDShowLagFrameCount() const;
virtual void SetHUDShowLagFrameCount(const bool visibleState);
bool GetHUDShowCPULoadAverage() const;
virtual void SetHUDShowCPULoadAverage(const bool visibleState);
bool GetHUDShowRTC() const;
virtual void SetHUDShowRTC(const bool visibleState);
bool GetHUDShowInput() const;
virtual void SetHUDShowInput(const bool visibleState);
uint32_t GetHUDColorVideoFPS() const;
virtual void SetHUDColorVideoFPS(uint32_t color32);
uint32_t GetHUDColorRender3DFPS() const;
virtual void SetHUDColorRender3DFPS(uint32_t color32);
uint32_t GetHUDColorFrameIndex() const;
virtual void SetHUDColorFrameIndex(uint32_t color32);
uint32_t GetHUDColorLagFrameCount() const;
virtual void SetHUDColorLagFrameCount(uint32_t color32);
uint32_t GetHUDColorCPULoadAverage() const;
virtual void SetHUDColorCPULoadAverage(uint32_t color32);
uint32_t GetHUDColorRTC() const;
virtual void SetHUDColorRTC(uint32_t color32);
uint32_t GetHUDColorInputPendingAndApplied() const;
virtual void SetHUDColorInputPendingAndApplied(uint32_t color32);
uint32_t GetHUDColorInputAppliedOnly() const;
virtual void SetHUDColorInputAppliedOnly(uint32_t color32);
uint32_t GetHUDColorInputPendingOnly() const;
virtual void SetHUDColorInputPendingOnly(uint32_t color32);
uint32_t GetInputColorUsingStates(bool pendingState, bool appliedState);
bool HUDNeedsUpdate();
void ClearHUDNeedsUpdate();
// Client view interface
const GPUClientFetchObject& GetFetchObject() const;
void SetFetchObject(GPUClientFetchObject *fetchObject);
virtual void LoadDisplays();
virtual void ProcessDisplays();
virtual void UpdateLayout();
virtual void FinishFrameAtIndex(const uint8_t bufferIndex);
virtual void CopyFrameToBuffer(uint32_t *dstBuffer);
// Emulator interface
const NDSDisplayInfo& GetEmuDisplayInfo() const;
void SetEmuDisplayInfo(const NDSDisplayInfo &ndsDisplayInfo);
// Utility methods
static void ConvertNormalToTransformedBounds(const double scalar,
const double angleDegrees,
double &inoutWidth, double &inoutHeight);
static double GetMaxScalarWithinBounds(const double normalBoundsWidth, const double normalBoundsHeight,
const double keepInBoundsWidth, const double keepInBoundsHeight);
static void CalculateNormalSize(const ClientDisplayMode mode, const ClientDisplayLayout layout, const double gapScale,
double &outWidth, double &outHeight);
};
class ClientDisplayViewInterface
{
protected:
InitialTouchPressMap *_initialTouchInMajorDisplay;
int64_t _displayViewID;
bool _useVerticalSync;
bool _viewNeedsFlush;
bool _allowViewUpdates;
bool _allowViewFlushes;
public:
ClientDisplayViewInterface();
virtual ~ClientDisplayViewInterface();
int64_t GetDisplayViewID();
virtual void SetDisplayViewID(int64_t displayViewID);
virtual bool GetViewNeedsFlush();
virtual void SetViewNeedsFlush();
bool GetUseVerticalSync() const;
virtual void SetUseVerticalSync(const bool useVerticalSync);
// Client view interface
bool GetAllowViewUpdates() const;
virtual void SetAllowViewUpdates(bool allowUpdates);
bool GetAllowViewFlushes() const;
virtual void SetAllowViewFlushes(bool allowFlushes);
virtual void FlushView();
// Touch screen input handling
void GetNDSPoint(const ClientDisplayPresenterProperties &props,
const double logicalClientWidth, const double logicalClientHeight,
const int inputID, const bool isInitialTouchPress,
const double clientX, const double clientY,
uint8_t &outX, uint8_t &outY) const;
// Utility methods
static void ConvertClientToNormalPoint(const double normalBoundsWidth, const double normalBoundsHeight,
const double transformBoundsWidth, const double transformBoundsHeight,
const double scalar,
const double angleDegrees,
double &inoutX, double &inoutY);
};
class ClientDisplay3DPresenter : public ClientDisplayPresenter
{
private:
void __InstanceInit();
protected:
bool _canFilterOnGPU;
bool _willFilterOnGPU;
bool _filtersPreferGPU;
public:
ClientDisplay3DPresenter();
ClientDisplay3DPresenter(const ClientDisplayPresenterProperties &props);
bool CanFilterOnGPU() const;
bool GetFiltersPreferGPU() const;
virtual void SetFiltersPreferGPU(const bool preferGPU);
bool WillFilterOnGPU() const;
virtual void SetSourceDeposterize(const bool useDeposterize);
void SetHUDPositionVertices(float viewportWidth, float viewportHeight, float *vtxPositionBufferPtr);
void SetHUDTouchLinePositionVertices(float *vtxBufferPtr);
void SetHUDColorVertices(uint32_t *vtxColorBufferPtr);
void SetHUDTextureCoordinates(float *texCoordBufferPtr);
void SetScreenVertices(float *vtxBufferPtr);
void SetScreenTextureCoordinates(float w0, float h0, float w1, float h1, float *texCoordBufferPtr);
};
class ClientDisplayView : public ClientDisplayViewInterface
{
protected:
ClientDisplayPresenter *_presenter;
public:
ClientDisplayView();
ClientDisplayView(ClientDisplayPresenter *thePresenter);
virtual void Init();
ClientDisplayPresenter* GetPresenter();
void SetPresenter(ClientDisplayPresenter *thePresenter);
};
class ClientDisplay3DView : public ClientDisplayViewInterface
{
protected:
ClientDisplay3DPresenter *_presenter;
public:
ClientDisplay3DView();
ClientDisplay3DView(ClientDisplay3DPresenter *thePresenter);
virtual void Init();
ClientDisplay3DPresenter* Get3DPresenter();
void Set3DPresenter(ClientDisplay3DPresenter *thePresenter);
};
#endif // _CLIENT_DISPLAY_VIEW_H_