forked from blackberry/SDL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
patch-master-emulate.patch
677 lines (632 loc) · 24.5 KB
/
patch-master-emulate.patch
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
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
-int PLAYBOOK_VideoInit(_THIS, SDL_PixelFormat *vformat)
+int PLAYBOOK_VideoInit(SDL_VideoDevice *this, SDL_PixelFormat *vformat)
{
int i;
screen_display_t *displays = 0;
@@ -202,7 +176,7 @@ int PLAYBOOK_VideoInit(_THIS, SDL_PixelFormat *vformat)
return -1;
}
- if (BPS_SUCCESS != navigator_rotation_lock(getenv("AUTO_ORIENTATION") != NULL ? false : true)) {
+ if (BPS_SUCCESS != navigator_rotation_lock(false)) {
SDL_SetError("Cannot set rotation lock: %s", strerror(errno));
bps_shutdown();
screen_destroy_event(this->hidden->screenEvent);
@@ -210,6 +184,14 @@ int PLAYBOOK_VideoInit(_THIS, SDL_PixelFormat *vformat)
return -1;
}
+ if (BPS_SUCCESS != navigator_extend_timeout(120000, 0)) {
+ SDL_SetError("Cannot extend timeout: %s", strerror(errno));
+ bps_shutdown();
+ screen_destroy_event(this->hidden->screenEvent);
+ screen_destroy_context(this->hidden->screenContext);
+ return -1;
+ }
+
if (BPS_SUCCESS != navigator_request_events(0)) {
SDL_SetError("Cannot get navigator events: %s", strerror(errno));
bps_shutdown();
@@ -226,6 +208,14 @@ int PLAYBOOK_VideoInit(_THIS, SDL_PixelFormat *vformat)
return -1;
}
+ if (BPS_SUCCESS != virtualkeyboard_request_events(0)) {
+ SDL_SetError("Cannot get VKB events: %s", strerror(errno));
+ bps_shutdown();
+ screen_destroy_event(this->hidden->screenEvent);
+ screen_destroy_context(this->hidden->screenContext);
+ return -1;
+ }
+
rc = screen_get_context_property_iv(this->hidden->screenContext, SCREEN_PROPERTY_DISPLAY_COUNT, &displayCount);
if (rc || displayCount <= 0) {
SDL_SetError("Cannot get display count: %s", strerror(errno));
@@ -257,11 +247,7 @@ int PLAYBOOK_VideoInit(_THIS, SDL_PixelFormat *vformat)
return -1;
}
- if (getenv("WIDTH") != NULL && getenv("HEIGHT") != NULL) {
- screenResolution[0] = atoi(getenv("WIDTH"));
- screenResolution[1] = atoi(getenv("HEIGHT"));
- } else {
- rc = screen_get_display_property_iv(displays[0], SCREEN_PROPERTY_SIZE, screenResolution);
+ rc = screen_get_display_property_iv(displays[0], SCREEN_PROPERTY_NATIVE_RESOLUTION, screenResolution);
if (rc) {
SDL_SetError("Cannot get native resolution: %s", strerror(errno));
SDL_free(displays);
@@ -271,222 +257,61 @@ int PLAYBOOK_VideoInit(_THIS, SDL_PixelFormat *vformat)
bps_shutdown();
return -1;
}
- }
-
- // FIXME: Bad hack for PlayBook to avoid rotation issues.
- if (screenResolution[0] == 600 && screenResolution[1] == 1024) {
- int angle = 0;
- char *orientation = getenv("ORIENTATION");
- if (orientation) {
- fprintf(stderr, "Received orientation: %s\n", orientation);
- angle = atoi(orientation);
- if (angle == 0) {
- screenResolution[0] = 1024;
- screenResolution[1] = 600;
- }
- }
- }
- rc = screen_create_window(&this->hidden->mainWindow, this->hidden->screenContext);
- if (rc) {
- SDL_SetError("Cannot create main application window: %s", strerror(errno));
SDL_free(displays);
- screen_stop_events(this->hidden->screenContext);
- screen_destroy_event(this->hidden->screenEvent);
- screen_destroy_context(this->hidden->screenContext);
- bps_shutdown();
- return -1;
- }
- char groupName[256];
- snprintf(groupName, 256, "SDL-window-%d", getpid());
- rc = screen_create_window_group(this->hidden->mainWindow, groupName);
- if (rc) {
- SDL_SetError("Cannot create main window group: %s", strerror(errno));
- screen_destroy_window(this->hidden->mainWindow);
- SDL_free(displays);
- screen_stop_events(this->hidden->screenContext);
- screen_destroy_event(this->hidden->screenEvent);
- screen_destroy_context(this->hidden->screenContext);
- bps_shutdown();
- return -1;
- }
+ this->hidden->screenWindow = 0;
+ this->hidden->surface = 0;
+ this->hidden->eglInfo.eglDisplay = 0;
+ this->hidden->eglInfo.eglContext = 0;
+ this->hidden->eglInfo.eglSurface = 0;
- rc = screen_set_window_property_iv(this->hidden->mainWindow, SCREEN_PROPERTY_SIZE, screenResolution);
- if (rc) {
- SDL_SetError("Cannot set application window size: %s", strerror(errno));
- screen_destroy_window(this->hidden->mainWindow);
- SDL_free(displays);
- screen_stop_events(this->hidden->screenContext);
- screen_destroy_event(this->hidden->screenEvent);
- screen_destroy_context(this->hidden->screenContext);
- bps_shutdown();
- return -1;
+ for ( i=0; i<SDL_NUMMODES; ++i ) {
+ this->hidden->SDL_modelist[i] = SDL_malloc(sizeof(SDL_Rect));
+ this->hidden->SDL_modelist[i]->x = this->hidden->SDL_modelist[i]->y = 0;
}
- rc = screen_set_window_property_iv(this->hidden->mainWindow, SCREEN_PROPERTY_BUFFER_SIZE, screenResolution);
- if (rc) {
- SDL_SetError("Cannot set application window buffer size: %s", strerror(errno));
- screen_destroy_window(this->hidden->mainWindow);
- SDL_free(displays);
- screen_stop_events(this->hidden->screenContext);
- screen_destroy_event(this->hidden->screenEvent);
- screen_destroy_context(this->hidden->screenContext);
- bps_shutdown();
- return -1;
- }
+ /* Modes sorted largest to smallest */
+ i = 0;
- int format = SCREEN_FORMAT_RGBX8888;
- rc = screen_set_window_property_iv(this->hidden->mainWindow, SCREEN_PROPERTY_FORMAT, &format);
- if (rc) {
- SDL_SetError("Cannot set application window format: %s", strerror(errno));
- screen_destroy_window(this->hidden->mainWindow);
- SDL_free(displays);
- screen_stop_events(this->hidden->screenContext);
- screen_destroy_event(this->hidden->screenEvent);
- screen_destroy_context(this->hidden->screenContext);
- bps_shutdown();
- return -1;
- }
+ /* 0: Default device screen size */
+ this->hidden->SDL_modelist[i]->w = screenResolution[0];
+ this->hidden->SDL_modelist[i++]->h = screenResolution[1];
- int usage = SCREEN_USAGE_NATIVE | SCREEN_USAGE_READ | SCREEN_USAGE_WRITE;
- if(getenv("AUTO_ORIENTATION") != NULL){
- usage |= SCREEN_USAGE_ROTATION;
- }
- rc = screen_set_window_property_iv(this->hidden->mainWindow, SCREEN_PROPERTY_USAGE, &usage);
- if (rc) {
- SDL_SetError("Cannot set application window usage: %s", strerror(errno));
- screen_destroy_window(this->hidden->mainWindow);
- SDL_free(displays);
- screen_stop_events(this->hidden->screenContext);
- screen_destroy_event(this->hidden->screenEvent);
- screen_destroy_context(this->hidden->screenContext);
- bps_shutdown();
- return -1;
- }
+ /* 1: BlackBerry PlayBook */
+ this->hidden->SDL_modelist[i]->w = 1024;
+ this->hidden->SDL_modelist[i++]->h = 600;
- int sensitivity = SCREEN_SENSITIVITY_NEVER;
- rc = screen_set_window_property_iv(this->hidden->mainWindow, SCREEN_PROPERTY_SENSITIVITY, &sensitivity);
- if (rc) {
- SDL_SetError("Cannot set application window touch sensitivity: %s", strerror(errno));
- screen_destroy_window(this->hidden->mainWindow);
- SDL_free(displays);
- screen_stop_events(this->hidden->screenContext);
- screen_destroy_event(this->hidden->screenEvent);
- screen_destroy_context(this->hidden->screenContext);
- bps_shutdown();
- return -1;
- }
+ /* 2: BlackBerry Z10 */
+ this->hidden->SDL_modelist[i]->w = 1280;
+ this->hidden->SDL_modelist[i++]->h = 768;
- int angle = 0;
- char *orientation = getenv("ORIENTATION");
- if (orientation) {
- angle = atoi(orientation);
- }
- rc = screen_set_window_property_iv(this->hidden->mainWindow, SCREEN_PROPERTY_ROTATION, &angle);
- if (rc) {
- SDL_SetError("Cannot set application window rotation: %s", strerror(errno));
- screen_destroy_window(this->hidden->mainWindow);
- SDL_free(displays);
- screen_stop_events(this->hidden->screenContext);
- screen_destroy_event(this->hidden->screenEvent);
- screen_destroy_context(this->hidden->screenContext);
- bps_shutdown();
- return -1;
- }
+ /* 3: BlackBerry Q10, Q5 */
+ this->hidden->SDL_modelist[i]->w = 720;
+ this->hidden->SDL_modelist[i++]->h = 720;
- rc = screen_create_window_buffers(this->hidden->mainWindow, 1);
- if (rc) {
- SDL_SetError("Cannot create application window buffer: %s", strerror(errno));
- screen_destroy_window(this->hidden->mainWindow);
- SDL_free(displays);
- screen_stop_events(this->hidden->screenContext);
- screen_destroy_event(this->hidden->screenEvent);
- screen_destroy_context(this->hidden->screenContext);
- bps_shutdown();
- return -1;
- }
+ /* 4: SVGA */
+ this->hidden->SDL_modelist[i]->w = 800;
+ this->hidden->SDL_modelist[i++]->h = 600;
- screen_buffer_t windowBuffer[1];
- rc = screen_get_window_property_pv(this->hidden->mainWindow,
- SCREEN_PROPERTY_RENDER_BUFFERS, (void**)&windowBuffer);
- if (rc) {
- SDL_SetError("Cannot retrieve application window buffer: %s", strerror(errno));
- screen_destroy_window_buffers(this->hidden->mainWindow);
- screen_destroy_window(this->hidden->mainWindow);
- SDL_free(displays);
- screen_stop_events(this->hidden->screenContext);
- screen_destroy_event(this->hidden->screenEvent);
- screen_destroy_context(this->hidden->screenContext);
- bps_shutdown();
- return -1;
- }
+ /* 5: VGA */
+ this->hidden->SDL_modelist[i]->w = 640;
+ this->hidden->SDL_modelist[i++]->h = 480;
- int attribs[] = {SCREEN_BLIT_DESTINATION_X, 0,
- SCREEN_BLIT_DESTINATION_Y, 0,
- SCREEN_BLIT_DESTINATION_WIDTH, screenResolution[0],
- SCREEN_BLIT_DESTINATION_HEIGHT, screenResolution[1],
- SCREEN_BLIT_COLOR, 0xff000000,
- SCREEN_BLIT_END};
- rc = screen_fill(this->hidden->screenContext, windowBuffer[0], attribs);
- if (rc) {
- SDL_SetError("Cannot fill application window: %s", strerror(errno));
- screen_destroy_window_buffers(this->hidden->mainWindow);
- screen_destroy_window(this->hidden->mainWindow);
- SDL_free(displays);
- screen_stop_events(this->hidden->screenContext);
- screen_destroy_event(this->hidden->screenEvent);
- screen_destroy_context(this->hidden->screenContext);
- bps_shutdown();
- return -1;
- }
+ /* 6: X-Mode VGA */
+ this->hidden->SDL_modelist[i]->w = 320;
+ this->hidden->SDL_modelist[i++]->h = 400;
- rc = screen_get_window_property_pv(this->hidden->mainWindow,
- SCREEN_PROPERTY_RENDER_BUFFERS, (void**)&windowBuffer);
- if (rc) {
- SDL_SetError("Cannot retrieve application window buffer: %s", strerror(errno));
- screen_destroy_window_buffers(this->hidden->mainWindow);
- screen_destroy_window(this->hidden->mainWindow);
- SDL_free(displays);
- screen_stop_events(this->hidden->screenContext);
- screen_destroy_event(this->hidden->screenEvent);
- screen_destroy_context(this->hidden->screenContext);
- bps_shutdown();
- return -1;
- }
+ /* 7: QVGA */
+ this->hidden->SDL_modelist[i]->w = 320;
+ this->hidden->SDL_modelist[i++]->h = 240;
- int rect[4] = {0, 0, screenResolution[0], screenResolution[1]};
- rc = screen_post_window(this->hidden->mainWindow, windowBuffer[0], 1, rect, 0);
- if (rc) {
- SDL_SetError("Cannot post application window: %s", strerror(errno));
- screen_destroy_window_buffers(this->hidden->mainWindow);
- screen_destroy_window(this->hidden->mainWindow);
- SDL_free(displays);
- screen_stop_events(this->hidden->screenContext);
- screen_destroy_event(this->hidden->screenEvent);
- screen_destroy_context(this->hidden->screenContext);
- bps_shutdown();
- return -1;
- }
+ /* 8: CGA */
+ this->hidden->SDL_modelist[i]->w = 320;
+ this->hidden->SDL_modelist[i++]->h = 200;
- SDL_free(displays);
-
- this->hidden->screenWindow = 0;
- this->hidden->surface = 0;
- this->hidden->eglInfo.eglDisplay = 0;
- this->hidden->eglInfo.eglContext = 0;
- this->hidden->eglInfo.eglSurface = 0;
-
- for ( i=0; i<SDL_NUMMODES; ++i ) {
- this->hidden->SDL_modelist[i] = SDL_malloc(sizeof(SDL_Rect));
- this->hidden->SDL_modelist[i]->x = this->hidden->SDL_modelist[i]->y = 0;
- }
-
- /* Modes sorted largest to smallest */
- this->hidden->SDL_modelist[0]->w = screenResolution[0]; this->hidden->SDL_modelist[0]->h = screenResolution[1];
- this->hidden->SDL_modelist[1]->w = 800; this->hidden->SDL_modelist[1]->h = 576;
- this->hidden->SDL_modelist[2]->w = 640; this->hidden->SDL_modelist[2]->h = 480;
- this->hidden->SDL_modelist[3] = NULL;
+ /* 9: Sentinel (no screen) */
+ this->hidden->SDL_modelist[i] = NULL;
/* Determine the screen depth (use default 32-bit depth) */
vformat->BitsPerPixel = 32;
@@ -502,7 +327,7 @@ int PLAYBOOK_VideoInit(_THIS, SDL_PixelFormat *vformat)
/* There is no window manager to talk to */
this->info.wm_available = 0;
- /* Full screen size is 1024x600 */
+ /* Full screen size is screenResolution */
this->info.current_w = screenResolution[0];
this->info.current_h = screenResolution[1];
@@ -510,59 +335,53 @@ int PLAYBOOK_VideoInit(_THIS, SDL_PixelFormat *vformat)
return 0;
}
-SDL_Rect **PLAYBOOK_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
+SDL_Rect **PLAYBOOK_ListModes(SDL_VideoDevice *this, SDL_PixelFormat *format, Uint32 flags)
{
- return (SDL_Rect**)-1;
+ if (flags & SDL_FULLSCREEN ) {
+ return this->hidden->SDL_modelist;
+ } else {
+ return (SDL_Rect**)-1; // We only support full-screen video modes.
+ }
}
-screen_window_t PLAYBOOK_CreateWindow(_THIS, SDL_Surface *current,
+screen_window_t PLAYBOOK_CreateWindow(SDL_VideoDevice *this, SDL_Surface *current,
int width, int height, int bpp)
{
screen_window_t screenWindow;
int rc = 0;
- int idle_mode = getenv("SCREEN_IDLE_NORMAL") != NULL ? SCREEN_IDLE_MODE_NORMAL : SCREEN_IDLE_MODE_KEEP_AWAKE;
+ int position[2] = {0, 0};
+ int idle_mode = SCREEN_IDLE_MODE_KEEP_AWAKE; // TODO: Handle idle gracefully?
- if (this->hidden->screenWindow) {
- if (current->hwdata)
- SDL_free(current->hwdata);
- if (this->hidden->tcoControlsDir) {
- tco_shutdown(this->hidden->emu_context);
- }
- int zorder = 0, setzorder = -1;
- do {
- /* Before we destroy the active screenWindow, send it to the back.
- * This also allows us to busy wait for the windowing system
- * to finish up whatever it is doing. If we do not busy wait,
- * then the new window we create may not actually work right
- * and may not have the right properties set. Ideally there is a
- * better way than busy wait, but I don't know what it is.
- */
- rc = screen_set_window_property_iv(this->hidden->screenWindow, SCREEN_PROPERTY_ZORDER, &setzorder);
- if (rc) {
- SDL_SetError("Cannot set ZORDER window: %s\n", strerror(errno));
- }
- rc = screen_get_window_property_iv(this->hidden->screenWindow, SCREEN_PROPERTY_ZORDER, &zorder);
- if (rc) {
- SDL_SetError("Cannot get ZORDER window: %s\n", strerror(errno));
- }
- usleep(50);
- } while (rc != 0 && (errno == EAGAIN || errno == EBUSY) && zorder != -1);
+ if (!this->hidden->screenWindow) {
+ char groupName[256];
- rc = screen_destroy_window_buffers(this->hidden->screenWindow);
- rc = screen_destroy_window(this->hidden->screenWindow);
+ rc = screen_create_window(&screenWindow, this->hidden->screenContext);
+ if (rc) {
+ SDL_SetError("Cannot create window: %s", strerror(errno));
+ return NULL;
}
- rc = screen_create_window_type(&screenWindow, this->hidden->screenContext, SCREEN_CHILD_WINDOW);
+ snprintf(groupName, 256, "sdl-%dx%dx%d-%u", width, height, bpp, time(NULL));
+ rc = screen_create_window_group(screenWindow, groupName);
if (rc) {
- SDL_SetError("Cannot create window: %s", strerror(errno));
+ SDL_SetError("Cannot set window group: %s", strerror(errno));
+ screen_destroy_window(screenWindow);
return NULL;
}
+ } else {
+ if (current->hwdata)
+ SDL_free(current->hwdata);
+ if (this->hidden->tco_context) {
+ tco_shutdown(this->hidden->tco_context);
+ this->hidden->tco_context = NULL;
+ }
+ screen_destroy_window_buffers(this->hidden->screenWindow);
+ screenWindow = this->hidden->screenWindow;
+ }
- char groupName[256];
- snprintf(groupName, 256, "SDL-window-%d", getpid());
- rc = screen_join_window_group(screenWindow, groupName);
+ rc = screen_set_window_property_iv(screenWindow, SCREEN_PROPERTY_POSITION, position);
if (rc) {
- SDL_SetError("Cannot join window group: %s", strerror(errno));
+ SDL_SetError("Cannot position window: %s", strerror(errno));
screen_destroy_window(screenWindow);
return NULL;
}
@@ -577,101 +396,78 @@ screen_window_t PLAYBOOK_CreateWindow(_THIS, SDL_Surface *current,
return screenWindow;
}
-int PLAYBOOK_SetupStretch(_THIS, screen_window_t screenWindow, int width, int height)
+SDL_Surface *PLAYBOOK_SetVideoMode(SDL_VideoDevice *this, SDL_Surface *current,
+ int width, int height, int bpp, Uint32 flags)
{
- int hwResolution[2];
- int rc;
- if (getenv("WIDTH") != NULL && getenv("HEIGHT") != NULL) {
- hwResolution[0] = atoi(getenv("WIDTH"));
- hwResolution[1] = atoi(getenv("HEIGHT"));
- } else {
- rc = screen_get_window_property_iv(this->hidden->mainWindow, SCREEN_PROPERTY_SIZE, hwResolution);
- if (rc) {
- SDL_SetError("Cannot get resolution: %s", strerror(errno));
- return -1;
+#ifdef _DEBUG
+ fprintf(stderr, "SetVideoMode: %dx%d %dbpp\n", width, height, bpp);
+#endif
+ if (width == 640 && height == 400) {
+ this->hidden->eventYOffset = 40;
+ height = 480;
}
+ if (flags & SDL_OPENGL) {
+ return PLAYBOOK_SetVideoMode_GL(this, current, width, height, bpp, flags);
}
+ screen_window_t screenWindow = PLAYBOOK_CreateWindow(this, current, width, height, bpp);
+ if (screenWindow == NULL)
+ return NULL;
- char *stretch_mode = getenv("STRETCH_MODE");
- if (stretch_mode == NULL) {
- stretch_mode = "aspect";
- }
+ int rc;
+ int format = 0;
int sizeOfWindow[2];
- if (strcmp(stretch_mode, "fill") == 0) {
- sizeOfWindow[0] = hwResolution[0];
- sizeOfWindow[1] = hwResolution[1];
- } else if (strcmp(stretch_mode, "noscale") == 0) {
- sizeOfWindow[0] = width;
- sizeOfWindow[1] = height;
-
- int position[2] = {ceil((hwResolution[0]-sizeOfWindow[0])/2), ceil((hwResolution[1]-sizeOfWindow[1])/2)};
- rc = screen_set_window_property_iv(screenWindow, SCREEN_PROPERTY_POSITION, position);
+#ifdef __STRETCHED_VIDEO_SCREEN__
+ rc = screen_get_window_property_iv(screenWindow, SCREEN_PROPERTY_SIZE, sizeOfWindow);
if (rc) {
- SDL_SetError("Cannot position window: %s", strerror(errno));
- return -1;
+ SDL_SetError("Cannot get resolution: %s", strerror(errno));
+ screen_destroy_window(screenWindow);
+ return NULL;
}
- } else {
- // Default is to preserve aspect ratio.
+#else
+ int hwResolution[2];
+
+ rc = screen_get_window_property_iv(screenWindow, SCREEN_PROPERTY_SIZE, hwResolution);
+ if (rc) {
+ SDL_SetError("Cannot get resolution: %s", strerror(errno));
+ screen_destroy_window(screenWindow);
+ return NULL;
+ }
+
float hwRatio, appRatio;
hwRatio = (float)hwResolution[0]/(float)hwResolution[1];
appRatio = (float)width/(float)height;
double newResolution[2];
if(hwRatio > appRatio){
- newResolution[0] = ((double)width) * ((double)hwResolution[1]) / ((double)height);
- newResolution[1] = (double)hwResolution[1];
+ newResolution[0] = ((double)height / ((double)hwResolution[1] / (double)hwResolution[0]));
+ newResolution[1] = (double)height;
} else {
- newResolution[0] = (double)hwResolution[0];
- newResolution[1] = ((double)height) * ((double)hwResolution[0]) / ((double)width);
+ newResolution[0] = (double)width;
+ newResolution[1] = (((double)hwResolution[1] / (double)hwResolution[0]) * (double)width);
}
sizeOfWindow[0] = (int)(ceil(newResolution[0]));
sizeOfWindow[1] = (int)(ceil(newResolution[1]));
- int position[2] = {ceil((hwResolution[0]-sizeOfWindow[0])/2), ceil((hwResolution[1]-sizeOfWindow[1])/2)};
- rc = screen_set_window_property_iv(screenWindow, SCREEN_PROPERTY_POSITION, position);
- if (rc) {
- SDL_SetError("Cannot position window: %s", strerror(errno));
- return -1;
- }
- }
-
rc = screen_set_window_property_iv(screenWindow, SCREEN_PROPERTY_SIZE, sizeOfWindow);
if (rc) {
SDL_SetError("Cannot resize window: %s", strerror(errno));
- return -1;
+ screen_destroy_window(screenWindow);
+ return NULL;
}
+#endif
+
+#ifdef __STRETCHED_VIDEO_SCREEN__
int sizeOfBuffer[2] = {width, height};
+#else
+ int sizeOfBuffer[2] = {sizeOfWindow[0], sizeOfWindow[1]};
+#endif
rc = screen_set_window_property_iv(screenWindow, SCREEN_PROPERTY_BUFFER_SIZE, sizeOfBuffer);
if (rc) {
SDL_SetError("Cannot resize window buffer: %s", strerror(errno));
- return -1;
- }
- return 0;
-}
-
-SDL_Surface *PLAYBOOK_SetVideoMode(_THIS, SDL_Surface *current,
- int width, int height, int bpp, Uint32 flags)
-{
- if (width == 640 && height == 400) {
- this->hidden->eventYOffset = 40;
- height = 480;
- }
- if (flags & SDL_OPENGL) {
- return PLAYBOOK_SetVideoMode_GL(this, current, width, height, bpp, flags);
- }
- screen_window_t screenWindow = PLAYBOOK_CreateWindow(this, current, width, height, bpp);
- if (screenWindow == NULL)
- return NULL;
-
- int rc;
- int format = 0;
-
- rc = PLAYBOOK_SetupStretch(this, screenWindow, width, height);
- if (rc) {
screen_destroy_window(screenWindow);
return NULL;
}
@@ -699,9 +495,6 @@ SDL_Surface *PLAYBOOK_SetVideoMode(_THIS, SDL_Surface *current,
}
int usage = SCREEN_USAGE_NATIVE | SCREEN_USAGE_READ | SCREEN_USAGE_WRITE; // FIXME: GL needs other usage
- if(getenv("AUTO_ORIENTATION") != NULL){
- usage |= SCREEN_USAGE_ROTATION;
- }
rc = screen_set_window_property_iv(screenWindow, SCREEN_PROPERTY_USAGE, &usage);
if (rc) {
SDL_SetError("Cannot set window usage: %s", strerror(errno));
@@ -709,6 +502,17 @@ SDL_Surface *PLAYBOOK_SetVideoMode(_THIS, SDL_Surface *current,
return NULL;
}
+ int angle = 0;
+ char *orientation = getenv("ORIENTATION");
+ if (orientation) {
+ angle = atoi(orientation);
+ }
+ rc = screen_set_window_property_iv(screenWindow, SCREEN_PROPERTY_ROTATION, &angle);
+ if (rc) {
+ SDL_SetError("Cannot set window rotation: %s", strerror(errno));
+ return NULL;
+ }
+
int bufferCount = 1; // FIXME: (flags & SDL_DOUBLEBUF)?2:1; - Currently double-buffered surfaces are slow!
rc = screen_create_window_buffers(screenWindow, bufferCount);
if (rc) {
@@ -736,24 +540,10 @@ SDL_Surface *PLAYBOOK_SetVideoMode(_THIS, SDL_Surface *current,
return NULL;
}
- int angle;
- rc = screen_get_window_property_iv(this->hidden->mainWindow,
- SCREEN_PROPERTY_ROTATION, &angle);
- if (rc) {
- SDL_SetError("Cannot get rotation: %s", strerror(errno));
- return NULL;
- }
-
- locateTCOControlFile(this);
- if (this->hidden->tcoControlsDir) {
- initializeOverlay(this, screenWindow);
- }
+ initialize_touch_controls(this, screenWindow);
this->hidden->frontBuffer = windowBuffer[0];
this->hidden->screenWindow = screenWindow;
- this->hidden->w = width;
- this->hidden->h = height;
- this->hidden->angle = angle;
current->hwdata = SDL_malloc(sizeof(struct private_hwdata));
current->hwdata->pixmap = 0;
@@ -768,15 +558,20 @@ SDL_Surface *PLAYBOOK_SetVideoMode(_THIS, SDL_Surface *current,
current->flags &= ~SDL_RESIZABLE; /* no resize for Direct Context */
current->flags |= SDL_FULLSCREEN;
current->flags |= SDL_HWSURFACE;
+#ifdef __STRETCHED_VIDEO_SCREEN__
current->w = width;
current->h = height;
+#else
+ current->w = sizeOfWindow[0];
+ current->h = sizeOfWindow[1];
+#endif
current->pitch = this->hidden->pitch;
current->pixels = this->hidden->pixels;
this->hidden->surface = current;
return current;
}
-void PLAYBOOK_UpdateRects(_THIS, int numrects, SDL_Rect *rects)
+void PLAYBOOK_UpdateRects(SDL_VideoDevice *this, int numrects, SDL_Rect *rects)
{
static int dirtyRects[256*4];
int index = 0, i = 0;
@@ -791,10 +586,8 @@ void PLAYBOOK_UpdateRects(_THIS, int numrects, SDL_Rect *rects)
screen_post_window(this->hidden->screenWindow, this->hidden->frontBuffer, numrects, dirtyRects, 0);
}
-int PLAYBOOK_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
+int PLAYBOOK_SetColors(SDL_VideoDevice *this, int firstcolor, int ncolors, SDL_Color *colors)
{
- /* do nothing of note. */
- // FIXME: Do we need to handle palette?
return(1);
}
@@ -802,7 +595,7 @@ int PLAYBOOK_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
another SDL video routine -- notably UpdateRects.
*/
// FIXME: Fix up cleanup process
-void PLAYBOOK_VideoQuit(_THIS)
+void PLAYBOOK_VideoQuit(SDL_VideoDevice *this)
{
if (this->hidden->screenWindow) {
if (this->hidden->eglInfo.eglDisplay) {
@@ -818,9 +611,11 @@ void PLAYBOOK_VideoQuit(_THIS)
screen_stop_events(this->hidden->screenContext);
screen_destroy_event(this->hidden->screenEvent);
screen_destroy_context(this->hidden->screenContext);
- bps_shutdown();
- if (this->hidden->tcoControlsDir) {
- tco_shutdown(this->hidden->emu_context);
+
+ if (this->hidden->tco_context) {
+ tco_shutdown(this->hidden->tco_context);
+ this->hidden->tco_context = NULL;
}
this->screen = 0;
+ bps_shutdown();
}