st/nine: Implement MSAA quality levels
[mesa.git] / src / gallium / state_trackers / nine / surface9.h
1 /*
2 * Copyright 2011 Joakim Sindholt <opensource@zhasha.com>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
22
23 #ifndef _NINE_SURFACE9_H_
24 #define _NINE_SURFACE9_H_
25
26 #include "resource9.h"
27
28 #include "pipe/p_state.h"
29 #include "util/list.h"
30 #include "util/u_rect.h"
31 #include "util/u_inlines.h"
32
33 struct NineSurface9
34 {
35 struct NineResource9 base;
36
37 /* G3D state */
38 struct pipe_context *pipe;
39 struct pipe_transfer *transfer;
40 struct pipe_surface *surface[2]; /* created on-demand (linear, sRGB) */
41 int lock_count;
42 uint8_t texture; /* rtype of container BaseTex or 0 */
43
44 /* resource description */
45 unsigned level; /* refers to the pipe_resource (SetLOD !) */
46 unsigned level_actual; /* refers to the NineTexture */
47 unsigned layer;
48 D3DSURFACE_DESC desc;
49
50 uint8_t *data; /* system memory backing */
51 uint8_t *data_conversion; /* for conversions */
52 enum pipe_format format_conversion;
53 unsigned stride; /* for system memory backing */
54 unsigned stride_conversion;
55 };
56 static inline struct NineSurface9 *
57 NineSurface9( void *data )
58 {
59 return (struct NineSurface9 *)data;
60 }
61
62 HRESULT
63 NineSurface9_new( struct NineDevice9 *pDevice,
64 struct NineUnknown *pContainer,
65 struct pipe_resource *pResource,
66 void *user_buffer,
67 uint8_t TextureType, /* 0 if pContainer isn't BaseTexure9 */
68 unsigned Level,
69 unsigned Layer,
70 D3DSURFACE_DESC *pDesc,
71 struct NineSurface9 **ppOut );
72
73 HRESULT
74 NineSurface9_ctor( struct NineSurface9 *This,
75 struct NineUnknownParams *pParams,
76 struct NineUnknown *pContainer,
77 struct pipe_resource *pResource,
78 void *user_buffer,
79 uint8_t TextureType,
80 unsigned Level,
81 unsigned Layer,
82 D3DSURFACE_DESC *pDesc );
83
84 void
85 NineSurface9_dtor( struct NineSurface9 *This );
86
87 /*** Nine private ***/
88
89 void
90 NineSurface9_MarkContainerDirty( struct NineSurface9 *This );
91
92 struct pipe_surface *
93 NineSurface9_CreatePipeSurface( struct NineSurface9 *This, const int sRGB );
94
95 static inline struct pipe_surface *
96 NineSurface9_GetSurface( struct NineSurface9 *This, int sRGB )
97 {
98 if (This->surface[sRGB])
99 return This->surface[sRGB];
100 return NineSurface9_CreatePipeSurface(This, sRGB);
101 }
102
103 static inline struct pipe_resource *
104 NineSurface9_GetResource( struct NineSurface9 *This )
105 {
106 return This->base.resource;
107 }
108
109 static inline void
110 NineSurface9_SetResource( struct NineSurface9 *This,
111 struct pipe_resource *resource, unsigned level )
112 {
113 This->level = level;
114 pipe_resource_reference(&This->base.resource, resource);
115 pipe_surface_reference(&This->surface[0], NULL);
116 pipe_surface_reference(&This->surface[1], NULL);
117 }
118
119 static inline void
120 NineSurface9_SetMultiSampleType( struct NineSurface9 *This,
121 D3DMULTISAMPLE_TYPE mst )
122 {
123 This->desc.MultiSampleType = mst;
124 }
125
126 void
127 NineSurface9_SetResourceResize( struct NineSurface9 *This,
128 struct pipe_resource *resource );
129
130 void
131 NineSurface9_AddDirtyRect( struct NineSurface9 *This,
132 const struct pipe_box *box );
133
134 HRESULT
135 NineSurface9_UploadSelf( struct NineSurface9 *This,
136 const struct pipe_box *damaged );
137
138 void
139 NineSurface9_CopyMemToDefault( struct NineSurface9 *This,
140 struct NineSurface9 *From,
141 const POINT *pDestPoint,
142 const RECT *pSourceRect );
143
144 void
145 NineSurface9_CopyDefaultToMem( struct NineSurface9 *This,
146 struct NineSurface9 *From );
147
148 static inline boolean
149 NineSurface9_IsOffscreenPlain (struct NineSurface9 *This )
150 {
151 return This->base.usage == 0 && !This->texture;
152 }
153
154 #ifdef DEBUG
155 void
156 NineSurface9_Dump( struct NineSurface9 *This );
157 #else
158 static inline void
159 NineSurface9_Dump( struct NineSurface9 *This ) { }
160 #endif
161
162 /*** Direct3D public ***/
163
164 HRESULT NINE_WINAPI
165 NineSurface9_GetContainer( struct NineSurface9 *This,
166 REFIID riid,
167 void **ppContainer );
168
169 HRESULT NINE_WINAPI
170 NineSurface9_GetDesc( struct NineSurface9 *This,
171 D3DSURFACE_DESC *pDesc );
172
173 HRESULT NINE_WINAPI
174 NineSurface9_LockRect( struct NineSurface9 *This,
175 D3DLOCKED_RECT *pLockedRect,
176 const RECT *pRect,
177 DWORD Flags );
178
179 HRESULT NINE_WINAPI
180 NineSurface9_UnlockRect( struct NineSurface9 *This );
181
182 HRESULT NINE_WINAPI
183 NineSurface9_GetDC( struct NineSurface9 *This,
184 HDC *phdc );
185
186 HRESULT NINE_WINAPI
187 NineSurface9_ReleaseDC( struct NineSurface9 *This,
188 HDC hdc );
189
190 #endif /* _NINE_SURFACE9_H_ */