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
33struct NineSurface9
34{
35    struct NineResource9 base;
36
37    /* G3D state */
38    struct pipe_transfer *transfer;
39    struct pipe_surface *surface[2]; /* created on-demand (linear, sRGB) */
40    int lock_count;
41    uint8_t texture; /* rtype of container BaseTex or 0 */
42
43    /* resource description */
44    unsigned level;        /* refers to the pipe_resource (SetLOD !) */
45    unsigned level_actual; /* refers to the NineTexture */
46    unsigned layer;
47    D3DSURFACE_DESC desc;
48
49    uint8_t *data; /* system memory backing */
50    uint8_t *data_internal; /* for conversions */
51    enum pipe_format format_internal;
52    unsigned stride; /* for system memory backing */
53    unsigned stride_internal;
54
55    unsigned pending_uploads_counter; /* pending uploads */
56};
57static inline struct NineSurface9 *
58NineSurface9( void *data )
59{
60    return (struct NineSurface9 *)data;
61}
62
63HRESULT
64NineSurface9_new( struct NineDevice9 *pDevice,
65                  struct NineUnknown *pContainer,
66                  struct pipe_resource *pResource,
67                  void *user_buffer,
68                  uint8_t TextureType, /* 0 if pContainer isn't BaseTexure9 */
69                  unsigned Level,
70                  unsigned Layer,
71                  D3DSURFACE_DESC *pDesc,
72                  struct NineSurface9 **ppOut );
73
74HRESULT
75NineSurface9_ctor( struct NineSurface9 *This,
76                   struct NineUnknownParams *pParams,
77                   struct NineUnknown *pContainer,
78                   struct pipe_resource *pResource,
79                   void *user_buffer,
80                   uint8_t TextureType,
81                   unsigned Level,
82                   unsigned Layer,
83                   D3DSURFACE_DESC *pDesc );
84
85void
86NineSurface9_dtor( struct NineSurface9 *This );
87
88/*** Nine private ***/
89
90void
91NineSurface9_MarkContainerDirty( struct NineSurface9 *This );
92
93static inline struct pipe_surface *
94NineSurface9_GetSurface( struct NineSurface9 *This, int sRGB )
95{
96    assert(This->surface[sRGB]);
97    return This->surface[sRGB];
98}
99
100static inline struct pipe_resource *
101NineSurface9_GetResource( struct NineSurface9 *This )
102{
103    return This->base.resource;
104}
105
106void
107NineSurface9_SetResource( struct NineSurface9 *This,
108                          struct pipe_resource *resource, unsigned level );
109
110void
111NineSurface9_SetMultiSampleType( struct NineSurface9 *This,
112                                 D3DMULTISAMPLE_TYPE mst );
113
114void
115NineSurface9_SetResourceResize( struct NineSurface9 *This,
116                                struct pipe_resource *resource );
117
118void
119NineSurface9_AddDirtyRect( struct NineSurface9 *This,
120                           const struct pipe_box *box );
121
122HRESULT
123NineSurface9_UploadSelf( struct NineSurface9 *This,
124                         const struct pipe_box *damaged );
125
126void
127NineSurface9_CopyMemToDefault( struct NineSurface9 *This,
128                               struct NineSurface9 *From,
129                               const POINT *pDestPoint,
130                               const RECT *pSourceRect );
131
132void
133NineSurface9_CopyDefaultToMem( struct NineSurface9 *This,
134                               struct NineSurface9 *From );
135
136static inline boolean
137NineSurface9_IsOffscreenPlain (struct NineSurface9 *This )
138{
139    return This->base.usage == 0 && !This->texture;
140}
141
142#if defined(DEBUG) || !defined(NDEBUG)
143void
144NineSurface9_Dump( struct NineSurface9 *This );
145#else
146static inline void
147NineSurface9_Dump( struct NineSurface9 *This ) { }
148#endif
149
150/*** Direct3D public ***/
151
152HRESULT NINE_WINAPI
153NineSurface9_GetContainer( struct NineSurface9 *This,
154                           REFIID riid,
155                           void **ppContainer );
156
157HRESULT NINE_WINAPI
158NineSurface9_GetDesc( struct NineSurface9 *This,
159                      D3DSURFACE_DESC *pDesc );
160
161HRESULT NINE_WINAPI
162NineSurface9_LockRect( struct NineSurface9 *This,
163                       D3DLOCKED_RECT *pLockedRect,
164                       const RECT *pRect,
165                       DWORD Flags );
166
167HRESULT NINE_WINAPI
168NineSurface9_UnlockRect( struct NineSurface9 *This );
169
170HRESULT NINE_WINAPI
171NineSurface9_GetDC( struct NineSurface9 *This,
172                    HDC *phdc );
173
174HRESULT NINE_WINAPI
175NineSurface9_ReleaseDC( struct NineSurface9 *This,
176                        HDC hdc );
177
178#endif /* _NINE_SURFACE9_H_ */
179