1 /**
2  * \file directx_renderer.h
3  * \brief   DirectX-based renderer for the GTK3 backend.
4  *
5  * \author David Hogan <david.q.hogan@gmail.com>
6  */
7 
8 /* This file is part of VICE, the Versatile Commodore Emulator.
9  * See README for copyright notice.
10  *
11  *  This program is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This program is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
24  *  02111-1307  USA.
25  *
26  */
27 #ifndef VICE_DIRECTX_RENDERER_IMPL_H
28 #define VICE_DIRECTX_RENDERER_IMPL_H
29 
30 #ifdef WIN32_COMPILE
31 
32 #include <windows.h>
33 
34 #include <d2d1.h>
35 #include <glib.h>
36 #include <pthread.h>
37 #include <stdbool.h>
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 #include "render_thread.h"
44 
45 /** \brief Rendering context for the DirectX backend.
46  *  \sa video_canvas_s::renderer_context */
47 typedef struct vice_directx_renderer_context_s {
48     /** \brief needed to coordinate access to the context between vice and main threads */
49     pthread_mutex_t canvas_lock;
50 
51     /** \brief used to coordinate access to native rendering resources */
52     pthread_mutex_t render_lock;
53 
54     /** \brief A 'pool' of one thread used to render backbuffers via directx */
55     render_thread_t render_thread;
56 
57     /** \brief A queue of backbuffers ready for painting to the widget */
58     void *render_queue;
59 
60     /** \brief native child window for DirectX to draw on */
61     HWND window;
62 
63     /** \brief minimum size for the drawing area, based on emu and aspect ratio settings */
64     unsigned int window_min_width;
65 
66     /** \brief minimum size for the drawing area, based on emu and aspect ratio settings */
67     unsigned int window_min_height;
68 
69     /** \brief Direct2D factory. x128 is weird if shared between VDC and VICII. */
70     ID2D1Factory* factory;
71 
72     /** \brief Direct2D render target that renders on window */
73     ID2D1HwndRenderTarget *render_target;
74 
75     /** \brief Direct2D bitmap used to get emu bitmap into the GPU */
76     ID2D1Bitmap *render_bitmap;
77 
78     /** \brief Where emu bitmap gets placed on the target surface */
79     D2D1_RECT_F render_dest_rect;
80 
81     /** \brief Background colour */
82     D2D1_COLOR_F render_bg_colour;
83 
84     /** \brief location of the directx viewport in window pixels */
85     unsigned int viewport_x;
86 
87     /** \brief size of the directx viewport in window pixels */
88     unsigned int viewport_y;
89 
90     /** \brief size of the directx viewport in window pixels */
91     unsigned int viewport_width;
92 
93     /** \brief size of the directx viewport in window pixels */
94     unsigned int viewport_height;
95 
96     /** \brief size of the current gpu bitmap in pixels */
97     unsigned int bitmap_width;
98 
99     /** \brief size of the current gpu bitmap in pixels */
100     unsigned int bitmap_height;
101 
102     /** \brief aspect ratio of each pixel in the current gpu bitmap */
103     float bitmap_pixel_aspect_ratio;
104 
105     /** \brief size of the next emulated frame */
106     unsigned int emulated_width_next;
107 
108     /** \brief size of the NEXT emulated frame */
109     unsigned int emulated_height_next;
110 
111     /** \brief pixel aspect ratio of the next emulated frame */
112     float pixel_aspect_ratio_next;
113 
114 } vice_directx_renderer_context_t;
115 
116 void vice_directx_impl_log_windows_error(const char *prefix);
117 
118 void vice_directx_impl_on_window_resize(vice_directx_renderer_context_t *context);
119 void vice_directx_destroy_context_impl(vice_directx_renderer_context_t *context);
120 
121 void vice_directx_impl_async_render(void *pool_data, void *job_data);
122 
123 #ifdef __cplusplus
124 } /* extern "C" { */
125 #endif
126 
127 #endif /* #ifdef WIN32_COMPILE */
128 
129 #endif /* #ifndef VICE_DIRECTX_RENDERER_IMPL_H */