1/**************************************************************************
2 *
3 * Copyright 2008-2009 VMware, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28#ifndef STW_WINSYS_H
29#define STW_WINSYS_H
30
31#include <windows.h> /* for HDC */
32
33#include "pipe/p_compiler.h"
34#include "frontend/api.h"
35
36struct pipe_screen;
37struct pipe_context;
38struct pipe_resource;
39
40struct stw_shared_surface;
41
42typedef enum
43{
44   stw_pfd_gdi_support   = 1 << 0,
45   stw_pfd_double_buffer = 1 << 1,
46} stw_pfd_flag;
47
48struct stw_winsys_framebuffer
49{
50   void
51   (*destroy)(struct stw_winsys_framebuffer *fb,
52              struct pipe_context *context);
53
54   boolean
55   (*present)(struct stw_winsys_framebuffer *fb);
56
57   void
58   (*resize)(struct stw_winsys_framebuffer *fb,
59             struct pipe_context *context,
60             struct pipe_resource *templ);
61
62   struct pipe_resource *
63   (*get_resource)(struct stw_winsys_framebuffer *fb,
64                   enum st_attachment_type statt);
65};
66
67struct stw_winsys
68{
69   struct pipe_screen *
70   (*create_screen)( HDC hDC );
71
72   /* XXX is it actually possible to have non-zero level/layer ??? */
73   /**
74    * Present the color buffer to the window associated with the device context.
75    */
76   void
77   (*present)( struct pipe_screen *screen,
78               struct pipe_context *context,
79               struct pipe_resource *res,
80               HDC hDC );
81
82   /**
83    * Locally unique identifier (LUID) of the graphics adapter.
84    *
85    * @sa GLCBPRESENTBUFFERSDATA::AdapterLuid;
86    */
87   boolean
88   (*get_adapter_luid)( struct pipe_screen *screen,
89                        HDC hDC,
90                        LUID *pAdapterLuid );
91
92   /**
93    * Open a shared surface (optional).
94    *
95    * @sa GLCBPRESENTBUFFERSDATA::hSharedSurface;
96    */
97   struct stw_shared_surface *
98   (*shared_surface_open)(struct pipe_screen *screen,
99                          HANDLE hSharedSurface);
100
101   /**
102    * Close a shared surface (optional).
103    */
104   void
105   (*shared_surface_close)(struct pipe_screen *screen,
106                           struct stw_shared_surface *surface);
107
108   /**
109    * Compose into a shared surface (optional).
110    *
111    * Blit the color buffer into a shared surface.
112    *
113    * @sa GLPRESENTBUFFERSDATA::PresentHistoryToken.
114    */
115   void
116   (*compose)( struct pipe_screen *screen,
117               struct pipe_resource *res,
118               struct stw_shared_surface *dest,
119               LPCRECT pRect,
120               ULONGLONG PresentHistoryToken );
121
122   /**
123    * Query whether the driver can support GDI and/or double-buffering in its
124    * pixel formats (optional).
125    */
126   unsigned
127   (*get_pfd_flags)( struct pipe_screen *screen );
128
129   /**
130    * Create a winsys-specific object for a given DC's framebuffer
131    */
132   struct stw_winsys_framebuffer *
133   (*create_framebuffer)( struct pipe_screen *screen,
134                          HWND hWnd,
135                          int iPixelFormat );
136
137   /**
138    * Get the name of the screen that was created
139    */
140   const char *
141   (*get_name)(void);
142};
143
144boolean
145stw_init(const struct stw_winsys *stw_winsys);
146
147boolean
148stw_init_thread(void);
149
150void
151stw_cleanup_thread(void);
152
153void
154stw_cleanup(void);
155
156#endif /* STW_WINSYS_H */
157