~ubuntu-branches/ubuntu/trusty/vice/trusty

« back to all changes in this revision

Viewing changes to src/arch/win32/fullscrn.c

  • Committer: Package Import Robot
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2013-07-28 20:38:23 UTC
  • mfrom: (1.2.5)
  • mto: This revision was merged to the branch mainline in revision 27.
  • Revision ID: package-import@ubuntu.com-20130728203823-w495rps5wuykespp
Tags: upstream-2.4.dfsg
ImportĀ upstreamĀ versionĀ 2.4.dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
 
33
33
#include "fullscrn.h"
34
34
#include "lib.h"
 
35
#include "log.h"
35
36
#include "res.h"
36
37
#include "resources.h"
37
38
#include "statusbar.h"
38
39
#include "translate.h"
39
40
#include "ui.h"
40
41
#include "uilib.h"
 
42
#include "util.h"
 
43
#include "video.h"
41
44
#include "videoarch.h"
42
45
#include "viewport.h"
43
46
#include "winlong.h"
48
51
static int keep_aspect_ratio, true_aspect_ratio, aspect_ratio;
49
52
static int ui_setup_finished = 0;
50
53
 
 
54
#ifdef HAVE_D3D9_H
 
55
#include <d3d9.h>
 
56
 
 
57
static HMENU old_menu;
 
58
static RECT old_rect;
 
59
static DWORD old_style;
 
60
static float old_refreshrate;
 
61
 
 
62
typedef struct _DDL {
 
63
    struct _DDL *next;
 
64
    int isNullGUID;
 
65
    GUID guid;
 
66
    LPSTR desc;
 
67
} DirectDrawDeviceList;
 
68
 
 
69
typedef struct _ML {
 
70
    struct _ML *next;
 
71
    int devicenumber;
 
72
    int width;
 
73
    int height;
 
74
    int bitdepth;
 
75
    int refreshrate;
 
76
} DirectDrawModeList;
 
77
 
51
78
static DirectDrawDeviceList *devices = NULL;
52
79
static DirectDrawModeList *modes = NULL;
53
 
 
 
80
#endif
54
81
 
55
82
void fullscreen_setup_finished(void)
56
83
{
62
89
    }
63
90
}
64
91
 
65
 
void fullscreen_devices_and_modes_free(void)
66
 
{
67
 
    DirectDrawModeList *m1, *m2;
68
 
    DirectDrawDeviceList *d1, *d2;
69
 
 
70
 
    m1 = modes;
71
 
    while (m1 != NULL) {
72
 
        m2 = m1->next;
73
 
        lib_free(m1);
74
 
        m1 = m2;
75
 
    }
76
 
    modes = NULL;
77
 
 
78
 
    d1 = devices;
79
 
    while (d1 != NULL) {
80
 
        d2 = d1->next;
81
 
        lib_free(d1->desc);
82
 
        lib_free(d1);
83
 
        d1 = d2;
84
 
    }
85
 
    devices = NULL;
86
 
}
87
 
 
88
92
int fullscreen_get_nesting_level(void)
89
93
{
90
94
    return fullscreen_nesting_level;
92
96
 
93
97
static void fullscreen_set_res_from_current_display(void)
94
98
{
 
99
#ifdef HAVE_D3D9_H
95
100
    int bitdepth, width, height, refreshrate;
96
101
 
97
102
    if (video_dx9_enabled()) {
98
 
        fullscreen_get_current_display_dx9(&bitdepth, &width, &height, &refreshrate);
99
 
    } else {
100
 
        fullscreen_get_current_display_ddraw(&bitdepth, &width, &height, &refreshrate);
 
103
        D3DDISPLAYMODE mode;
 
104
 
 
105
        if (S_OK == IDirect3D9_GetAdapterDisplayMode(d3d, D3DADAPTER_DEFAULT , &mode)) {
 
106
            bitdepth = 32;
 
107
            width = mode.Width;
 
108
            height = mode.Height;
 
109
            refreshrate = mode.RefreshRate;
 
110
        } else {
 
111
            /* provide defaults if GetDisplayMode fails for some reason */
 
112
            log_debug("fullscreen_get_current_display_dx9 failed to get mode!");
 
113
            bitdepth = 32;
 
114
            width = 640;
 
115
            height = 480;
 
116
            refreshrate = 0;
 
117
        }
101
118
    }
102
119
 
103
120
    resources_set_int("FullscreenBitdepth", bitdepth);
104
121
    resources_set_int("FullscreenWidth", width);
105
122
    resources_set_int("FullscreenHeight", height);
106
123
    resources_set_int("FullscreenRefreshRate", refreshrate);
 
124
#endif
107
125
}
108
126
 
109
127
/* check if the fullscreen resource values are valid */
121
139
    return 0;
122
140
}
123
141
 
 
142
#ifdef HAVE_D3D9_H
 
143
static void fullscreen_getmodes_dx9(void)
 
144
{
 
145
    int adapter, numAdapter, mode, numAdapterModes;
 
146
    D3DADAPTER_IDENTIFIER9 d3didentifier;
 
147
    D3DDISPLAYMODE displayMode;
 
148
    DirectDrawDeviceList *new_device;
 
149
    DirectDrawDeviceList *search_device;
 
150
    DirectDrawModeList *new_mode;
 
151
    DirectDrawModeList *search_mode;
 
152
 
 
153
    numAdapter = 0;
 
154
    while (D3D_OK == IDirect3D9_GetAdapterIdentifier(d3d, numAdapter, 0, &d3didentifier)) {
 
155
        new_device = lib_malloc(sizeof(DirectDrawDeviceList));
 
156
        new_device->next = NULL;
 
157
        new_device->desc = util_concat(d3didentifier.DeviceName, " - ", d3didentifier.Description, NULL);
 
158
        if (devices == NULL) {
 
159
            devices = new_device;
 
160
        } else {
 
161
            search_device = devices;
 
162
            while (search_device->next != NULL) {
 
163
                search_device = search_device->next;
 
164
            }
 
165
            search_device->next = new_device;
 
166
        }
 
167
        numAdapter++;
 
168
    }
 
169
 
 
170
    for (adapter = 0; adapter < numAdapter; adapter++) {
 
171
        numAdapterModes = IDirect3D9_GetAdapterModeCount(d3d, adapter, D3DFMT_X8R8G8B8);
 
172
 
 
173
        for (mode = 0; mode < numAdapterModes; mode++) {
 
174
            if (S_OK == IDirect3D9_EnumAdapterModes(d3d, adapter, D3DFMT_X8R8G8B8, mode, &displayMode)) {
 
175
                new_mode = lib_malloc(sizeof(DirectDrawModeList));
 
176
                new_mode->next = NULL;
 
177
                new_mode->devicenumber = adapter;
 
178
                new_mode->width = displayMode.Width;
 
179
                new_mode->height = displayMode.Height;
 
180
                new_mode->bitdepth = 32;
 
181
                new_mode->refreshrate = displayMode.RefreshRate;
 
182
 
 
183
                if (modes == NULL) {
 
184
                    modes = new_mode;
 
185
                } else {
 
186
                    search_mode = modes;
 
187
                    while (search_mode->next != NULL) {
 
188
                        search_mode = search_mode->next;
 
189
                    }
 
190
                    search_mode->next = new_mode;
 
191
                }
 
192
            }
 
193
        }
 
194
    }
 
195
}
 
196
#endif
 
197
 
124
198
void fullscreen_getmodes(void)
125
199
{
 
200
#ifdef HAVE_D3D9_H
126
201
    if (video_dx9_enabled()) {
127
 
        fullscreen_use_devices_dx9(&devices, &modes);
128
 
    } else {
129
 
        fullscreen_use_devices_ddraw(&devices, &modes);
 
202
        if (devices == NULL) {
 
203
            fullscreen_getmodes_dx9();
 
204
        }
130
205
    }
 
206
#endif
131
207
    
132
208
    /* Use current display parameters if resources are not valid */
133
209
    if (fullscrn_res_valid() < 0) {
137
213
 
138
214
void ui_fullscreen_init(void)
139
215
{
140
 
    fullscreen_getmodes_ddraw();
 
216
#ifdef HAVE_D3D9_H
141
217
    if (video_dx9_enabled()) {
142
218
        fullscreen_getmodes_dx9();
143
219
    }
 
220
#endif
144
221
}
145
222
 
146
223
void ui_fullscreen_shutdown(void)
147
224
{
 
225
#ifdef HAVE_D3D9_H
148
226
    if (video_dx9_available()) {
149
 
        fullscreen_use_devices_dx9(&devices, &modes);
150
 
        fullscreen_devices_and_modes_free();
 
227
        DirectDrawModeList *m1, *m2;
 
228
        DirectDrawDeviceList *d1, *d2;
 
229
 
 
230
        if (devices == NULL) {
 
231
            fullscreen_getmodes_dx9();
 
232
        }
 
233
 
 
234
        m1 = modes;
 
235
        while (m1 != NULL) {
 
236
            m2 = m1->next;
 
237
            lib_free(m1);
 
238
            m1 = m2;
 
239
        }
 
240
        modes = NULL;
 
241
 
 
242
        d1 = devices;
 
243
        while (d1 != NULL) {
 
244
            d2 = d1->next;
 
245
            lib_free(d1->desc);
 
246
            lib_free(d1);
 
247
            d1 = d2;
 
248
        }
 
249
        devices = NULL;
151
250
    }
152
 
    fullscreen_use_devices_ddraw(&devices, &modes);
153
 
    fullscreen_devices_and_modes_free();
 
251
#endif
154
252
}
155
253
 
156
254
void GetCurrentModeParameters(int *device, int *width, int *height, int *bitdepth, int *refreshrate)
181
279
        fullscreen_set_res_from_current_display();
182
280
    }
183
281
 
 
282
#ifdef HAVE_D3D9_H
184
283
    if (video_dx9_enabled()) {
185
 
        SwitchToFullscreenModeDx9(hwnd);
186
 
    } else {
187
 
        SwitchToFullscreenModeDDraw(hwnd);
 
284
        video_canvas_t *c;
 
285
 
 
286
        c = video_canvas_for_hwnd(hwnd);
 
287
 
 
288
 
 
289
        statusbar_destroy(hwnd);
 
290
 
 
291
        /*  Remove Window stuff that prevents fullscreen display */
 
292
        old_style = GetWindowLong(hwnd, GWL_STYLE);
 
293
        GetWindowRect(hwnd, &old_rect);
 
294
        SetWindowLong(hwnd, GWL_STYLE, old_style & ~WS_SYSMENU & ~WS_CAPTION);
 
295
        old_menu = GetMenu(hwnd);
 
296
        SetMenu(hwnd, NULL);
 
297
        ShowCursor(FALSE);
 
298
 
 
299
        video_device_release_dx9(c);
 
300
        ui_set_render_window(c, 1);
 
301
        video_device_create_dx9(c, 1);
 
302
                video_canvas_reset_dx9(c);
 
303
        video_canvas_refresh_all(c);
188
304
    }
 
305
#endif
189
306
}
190
307
 
191
308
void SwitchToWindowedMode(HWND hwnd)
195
312
    if (!ui_setup_finished)
196
313
        return;
197
314
 
 
315
#ifdef HAVE_D3D9_H
198
316
    if (video_dx9_enabled()) {
199
 
        SwitchToWindowedModeDx9(hwnd);
200
 
    } else {
201
 
        SwitchToWindowedModeDDraw(hwnd);
 
317
        video_canvas_t *c;
 
318
 
 
319
        c = video_canvas_for_hwnd(hwnd);
 
320
 
 
321
        video_device_release_dx9(c);
 
322
 
 
323
        /* Create statusbar here to get correct dimensions for client window */
 
324
        statusbar_create(hwnd);
 
325
        ui_set_render_window(c, 0);
 
326
 
 
327
        LockWindowUpdate(hwnd);
 
328
        SetWindowLong(hwnd, GWL_STYLE, old_style);
 
329
        /* Restore  Menu */
 
330
        SetMenu(hwnd,old_menu);
 
331
        ui_show_menu();
 
332
        SetWindowPos(hwnd, HWND_NOTOPMOST, old_rect.left, old_rect.top, old_rect.right - old_rect.left, old_rect.bottom - old_rect.top, SWP_NOCOPYBITS);
 
333
        ShowCursor(TRUE);
 
334
        LockWindowUpdate(NULL);
 
335
 
 
336
        video_device_create_dx9(c, 0);
 
337
                video_canvas_reset_dx9(c);
 
338
        video_canvas_refresh_all(c);
 
339
 
 
340
        c->refreshrate = old_refreshrate;
202
341
    }
 
342
#endif
203
343
    resources_get_int("AlwaysOnTop", &alwaysontop);
204
344
    ui_set_alwaysontop(alwaysontop);
205
345
}
298
438
int fullscreen_height = 0;
299
439
int fullscreen_refreshrate = 0;
300
440
 
 
441
#ifdef HAVE_D3D9_H
301
442
static void validate_mode(int *device, int *width, int *height, int *bitdepth, int *rate)
302
443
{
303
444
    DirectDrawModeList  *mode;
310
451
        }
311
452
        mode = mode->next;
312
453
    }
313
 
    if (mode == NULL) {
 
454
    if (mode == NULL && modes != NULL) {
314
455
        *device = modes->devicenumber;
315
456
    }
316
457
 
517
658
        mode = mode->next;
518
659
    }
519
660
}
 
661
#endif
520
662
 
521
663
static int vblank_sync;
522
664
 
567
709
 
568
710
static void init_fullscreen_dialog(HWND hwnd)
569
711
{
 
712
#ifdef HAVE_D3D9_H
570
713
    HWND setting_hwnd;
571
714
    DirectDrawDeviceList *dev;
572
715
    ValueList *value;
 
716
#endif
573
717
    int xpos;
574
718
    int xstart;
575
719
    int xend;
617
761
        uilib_set_element_width(hwnd, IDC_FULLSCREEN_DEVICE, size + distance);
618
762
    }
619
763
 
 
764
#ifdef HAVE_D3D9_H
620
765
    validate_mode(&fullscreen_device, &fullscreen_width, &fullscreen_height, &fullscreen_bitdepth, &fullscreen_refreshrate);
621
766
    setting_hwnd = GetDlgItem(hwnd, IDC_FULLSCREEN_DEVICE);
622
767
    SendMessage(setting_hwnd, CB_RESETCONTENT, 0, 0);
656
801
        value = value->next;
657
802
    }
658
803
    SendMessage(setting_hwnd, CB_SETCURSEL, (WPARAM)GetIndexFromList(refresh_rates, fullscreen_refreshrate), 0);
 
804
#endif
659
805
    EnableWindow(GetDlgItem(hwnd, IDC_TOGGLE_VIDEO_VBLANK_SYNC), !video_dx9_enabled());
660
806
    CheckDlgButton(hwnd, IDC_TOGGLE_VIDEO_VBLANK_SYNC, vblank_sync ? BST_CHECKED : BST_UNCHECKED);
661
807
    CheckDlgButton(hwnd, IDC_TOGGLE_VIDEO_DX_PRIMARY, dx_primary ? BST_CHECKED : BST_UNCHECKED);
662
808
    EnableWindow(GetDlgItem(hwnd, IDC_TOGGLE_KEEP_ASPECT_RATIO), video_dx9_enabled());
663
 
    CheckDlgButton(hwnd, IDC_TOGGLE_KEEP_ASPECT_RATIO, keep_aspect_ratio ? BST_CHECKED : BST_UNCHECKED);
664
 
    CheckDlgButton(hwnd, IDC_TOGGLE_TRUE_ASPECT_RATIO, true_aspect_ratio ? BST_CHECKED : BST_UNCHECKED);
665
 
    enable_aspect_ratio(hwnd);
666
 
 
667
 
    fval = ((double)aspect_ratio) / 1000.0;
668
 
    _stprintf(newval, TEXT("%.3f"), (float)fval);
669
 
    SetDlgItemText(hwnd, IDC_ASPECT_RATIO, newval);
670
 
 
671
 
    fval = canvas->geometry->pixel_aspect_ratio;
672
 
    _stprintf(newval, TEXT("%.3f"), (float)fval);
673
 
    SetDlgItemText(hwnd, IDC_GEOMETRY_ASPECT_RATIO, newval);
 
809
    if (video_dx9_enabled()) {
 
810
        CheckDlgButton(hwnd, IDC_TOGGLE_KEEP_ASPECT_RATIO, keep_aspect_ratio ? BST_CHECKED : BST_UNCHECKED);
 
811
        CheckDlgButton(hwnd, IDC_TOGGLE_TRUE_ASPECT_RATIO, true_aspect_ratio ? BST_CHECKED : BST_UNCHECKED);
 
812
        enable_aspect_ratio(hwnd);
 
813
 
 
814
        fval = ((double)aspect_ratio) / 1000.0;
 
815
        _stprintf(newval, TEXT("%.3f"), (float)fval);
 
816
        SetDlgItemText(hwnd, IDC_ASPECT_RATIO, newval);
 
817
 
 
818
        fval = canvas->geometry->pixel_aspect_ratio;
 
819
        _stprintf(newval, TEXT("%.3f"), (float)fval);
 
820
        SetDlgItemText(hwnd, IDC_GEOMETRY_ASPECT_RATIO, newval);
 
821
    }
674
822
}
675
823
 
676
824
static void fullscreen_dialog_end(void)
682
830
    resources_set_int("FullScreenRefreshRate", fullscreen_refreshrate);
683
831
    resources_set_int("VBLANKSync", vblank_sync);
684
832
    resources_set_int("DXPrimarySurfaceRendering", dx_primary);
685
 
    resources_set_int("TrueAspectRatio", true_aspect_ratio);
686
 
    resources_set_int("KeepAspectRatio", keep_aspect_ratio);
687
 
    resources_set_int("AspectRatio", aspect_ratio);
688
 
    fullscrn_invalidate_refreshrate();
 
833
    if (video_dx9_enabled()) {
 
834
        resources_set_int("TrueAspectRatio", true_aspect_ratio);
 
835
        resources_set_int("KeepAspectRatio", keep_aspect_ratio);
 
836
        resources_set_int("AspectRatio", aspect_ratio);
 
837
    }
689
838
}
690
839
 
691
840
static void fullscreen_dialog_init(HWND hwnd)
697
846
    resources_get_int("FullscreenRefreshRate", &fullscreen_refreshrate);
698
847
    resources_get_int("VBLANKSync", &vblank_sync);
699
848
    resources_get_int("DXPrimarySurfaceRendering", &dx_primary);
700
 
    resources_get_int("KeepAspectRatio", &keep_aspect_ratio);
701
 
    resources_get_int("TrueAspectRatio", &true_aspect_ratio);
702
 
    resources_get_int("AspectRatio", &aspect_ratio);
 
849
    if (video_dx9_enabled()) {
 
850
        resources_get_int("KeepAspectRatio", &keep_aspect_ratio);
 
851
        resources_get_int("TrueAspectRatio", &true_aspect_ratio);
 
852
        resources_get_int("AspectRatio", &aspect_ratio);
 
853
    }
703
854
    init_fullscreen_dialog(hwnd);
704
855
}
705
856
 
706
857
INT_PTR CALLBACK dialog_fullscreen_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
707
858
{
 
859
#ifdef HAVE_D3D9_H
 
860
    int value;
 
861
    int index;
 
862
#endif
708
863
    int notifycode;
709
864
    int item;
710
 
    int index;
711
 
    int value;
712
865
    int command;
713
866
    TCHAR s[100];
714
867
    float tf;
716
869
    switch (msg) {
717
870
        case WM_NOTIFY:
718
871
            if (((NMHDR FAR *)lparam)->code == (UINT)PSN_APPLY) {
719
 
                GetDlgItemText(hwnd, IDC_ASPECT_RATIO, s, 100);
720
 
                _stscanf(s, TEXT("%f"), &tf);
721
 
                aspect_ratio = (int)(tf * 1000.0 + 0.5);
722
 
                if (aspect_ratio < 500) {
723
 
                    ui_error(translate_text(IDS_VAL_F_FOR_S_OUT_RANGE_USE_F), tf, translate_text(IDS_TOGGLE_KEEP_ASPECT_RATIO), 0.5f);
724
 
                    aspect_ratio = 500;
725
 
                }
726
 
                if (aspect_ratio > 2000) {
727
 
                    ui_error(translate_text(IDS_VAL_F_FOR_S_OUT_RANGE_USE_F), tf, translate_text(IDS_TOGGLE_KEEP_ASPECT_RATIO), 2.0f);
728
 
                    aspect_ratio = 2000;
 
872
                if (video_dx9_enabled()) {
 
873
                    GetDlgItemText(hwnd, IDC_ASPECT_RATIO, s, 100);
 
874
                    _stscanf(s, TEXT("%f"), &tf);
 
875
                    aspect_ratio = (int)(tf * 1000.0 + 0.5);
 
876
                    if (aspect_ratio < 500) {
 
877
                        ui_error(translate_text(IDS_VAL_F_FOR_S_OUT_RANGE_USE_F), tf, translate_text(IDS_TOGGLE_KEEP_ASPECT_RATIO), 0.5f);
 
878
                        aspect_ratio = 500;
 
879
                    }
 
880
                    if (aspect_ratio > 2000) {
 
881
                        ui_error(translate_text(IDS_VAL_F_FOR_S_OUT_RANGE_USE_F), tf, translate_text(IDS_TOGGLE_KEEP_ASPECT_RATIO), 2.0f);
 
882
                        aspect_ratio = 2000;
 
883
                    }
729
884
                }
730
885
                fullscreen_dialog_end();
731
886
                SetWindowLongPtr(hwnd, DWLP_MSGRESULT, FALSE);
735
890
        case WM_COMMAND:
736
891
            notifycode = HIWORD(wparam);
737
892
            item = LOWORD(wparam);
 
893
#ifdef HAVE_D3D9_H
738
894
            if (notifycode == CBN_SELENDOK) {
739
895
                if (item == IDC_FULLSCREEN_DEVICE) { 
740
896
                    fullscreen_device = (int)SendMessage(GetDlgItem(hwnd, IDC_FULLSCREEN_DEVICE), CB_GETCURSEL, 0, 0);
751
907
                    fullscreen_refreshrate = GetValueFromList(refresh_rates, index);
752
908
                }
753
909
                init_fullscreen_dialog(hwnd);
754
 
            } else {
 
910
            } else
 
911
#endif
 
912
            {
755
913
                command = LOWORD(wparam);
756
914
                switch (command) {
757
915
                    case IDC_TOGGLE_VIDEO_VBLANK_SYNC: