1 | /* $Id$ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | * Blitter API
|
---|
5 | */
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2013 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 | #ifndef ___cr_blitter_h__
|
---|
18 | #define ___cr_blitter_h__
|
---|
19 |
|
---|
20 | #include <iprt/cdefs.h>
|
---|
21 | #include <iprt/asm.h>
|
---|
22 | #include "cr_spu.h"
|
---|
23 | #include "cr_vreg.h"
|
---|
24 |
|
---|
25 | #ifndef IN_RING0
|
---|
26 | # define VBOXBLITTERDECL(_type) DECLEXPORT(_type)
|
---|
27 | #else
|
---|
28 | # define VBOXBLITTERDECL(_type) RTDECL(_type)
|
---|
29 | #endif
|
---|
30 |
|
---|
31 | RT_C_DECLS_BEGIN
|
---|
32 | /* GLSL Cache */
|
---|
33 | typedef struct CR_GLSL_CACHE
|
---|
34 | {
|
---|
35 | int iGlVersion;
|
---|
36 | GLuint uNoAlpha2DProg;
|
---|
37 | GLuint uNoAlpha2DRectProg;
|
---|
38 | SPUDispatchTable *pDispatch;
|
---|
39 | } CR_GLSL_CACHE;
|
---|
40 |
|
---|
41 | DECLINLINE(void) CrGlslInit(CR_GLSL_CACHE *pCache, SPUDispatchTable *pDispatch)
|
---|
42 | {
|
---|
43 | memset(pCache, 0, sizeof (*pCache));
|
---|
44 | pCache->pDispatch = pDispatch;
|
---|
45 | }
|
---|
46 |
|
---|
47 | DECLINLINE(bool) CrGlslIsInited(const CR_GLSL_CACHE *pCache)
|
---|
48 | {
|
---|
49 | return !!pCache->pDispatch;
|
---|
50 | }
|
---|
51 |
|
---|
52 | /* clients should set proper context before calling these funcs */
|
---|
53 | VBOXBLITTERDECL(bool) CrGlslIsSupported(CR_GLSL_CACHE *pCache);
|
---|
54 | VBOXBLITTERDECL(int) CrGlslProgGenAllNoAlpha(CR_GLSL_CACHE *pCache);
|
---|
55 | VBOXBLITTERDECL(int) CrGlslProgGenNoAlpha(CR_GLSL_CACHE *pCache, GLenum enmTexTarget);
|
---|
56 | VBOXBLITTERDECL(int) CrGlslProgUseGenNoAlpha(CR_GLSL_CACHE *pCache, GLenum enmTexTarget);
|
---|
57 | VBOXBLITTERDECL(int) CrGlslProgUseNoAlpha(const CR_GLSL_CACHE *pCache, GLenum enmTexTarget);
|
---|
58 | VBOXBLITTERDECL(void) CrGlslProgClear(const CR_GLSL_CACHE *pCache);
|
---|
59 | VBOXBLITTERDECL(bool) CrGlslNeedsCleanup(const CR_GLSL_CACHE *pCache);
|
---|
60 | VBOXBLITTERDECL(void) CrGlslCleanup(CR_GLSL_CACHE *pCache);
|
---|
61 | VBOXBLITTERDECL(void) CrGlslTerm(CR_GLSL_CACHE *pCache);
|
---|
62 |
|
---|
63 | /* BLITTER */
|
---|
64 | typedef struct CR_BLITTER_BUFFER
|
---|
65 | {
|
---|
66 | GLuint cbBuffer;
|
---|
67 | GLvoid * pvBuffer;
|
---|
68 | } CR_BLITTER_BUFFER, *PCR_BLITTER_BUFFER;
|
---|
69 |
|
---|
70 | typedef union CR_BLITTER_FLAGS
|
---|
71 | {
|
---|
72 | struct
|
---|
73 | {
|
---|
74 | uint32_t Initialized : 1;
|
---|
75 | uint32_t CtxCreated : 1;
|
---|
76 | uint32_t SupportsFBO : 1;
|
---|
77 | uint32_t SupportsPBO : 1;
|
---|
78 | uint32_t CurrentMuralChanged : 1;
|
---|
79 | uint32_t LastWasFBODraw : 1;
|
---|
80 | uint32_t ForceDrawBlit : 1;
|
---|
81 | uint32_t ShadersGloal : 1;
|
---|
82 | uint32_t Reserved : 24;
|
---|
83 | };
|
---|
84 | uint32_t Value;
|
---|
85 | } CR_BLITTER_FLAGS, *PCR_BLITTER_FLAGS;
|
---|
86 |
|
---|
87 | struct CR_BLITTER;
|
---|
88 |
|
---|
89 | typedef DECLCALLBACK(int) FNCRBLT_BLITTER(struct CR_BLITTER *pBlitter, const VBOXVR_TEXTURE *pSrc, const RTRECT *paSrcRect, const RTRECTSIZE *pDstSize, const RTRECT *paDstRect, uint32_t cRects, uint32_t fFlags);
|
---|
90 | typedef FNCRBLT_BLITTER *PFNCRBLT_BLITTER;
|
---|
91 |
|
---|
92 | typedef struct CR_BLITTER_SPUITEM
|
---|
93 | {
|
---|
94 | int id;
|
---|
95 | GLint visualBits;
|
---|
96 | } CR_BLITTER_SPUITEM, *PCR_BLITTER_SPUITEM;
|
---|
97 |
|
---|
98 | typedef struct CR_BLITTER_CONTEXT
|
---|
99 | {
|
---|
100 | CR_BLITTER_SPUITEM Base;
|
---|
101 | } CR_BLITTER_CONTEXT, *PCR_BLITTER_CONTEXT;
|
---|
102 |
|
---|
103 | typedef struct CR_BLITTER_WINDOW
|
---|
104 | {
|
---|
105 | CR_BLITTER_SPUITEM Base;
|
---|
106 | GLuint width, height;
|
---|
107 | } CR_BLITTER_WINDOW, *PCR_BLITTER_WINDOW;
|
---|
108 |
|
---|
109 | typedef struct CR_BLITTER_IMG
|
---|
110 | {
|
---|
111 | void *pvData;
|
---|
112 | GLuint cbData;
|
---|
113 | GLenum enmFormat;
|
---|
114 | GLuint width, height;
|
---|
115 | GLuint bpp;
|
---|
116 | GLuint pitch;
|
---|
117 | } CR_BLITTER_IMG, *PCR_BLITTER_IMG;
|
---|
118 |
|
---|
119 | typedef struct CR_BLITTER
|
---|
120 | {
|
---|
121 | GLuint idFBO;
|
---|
122 | CR_BLITTER_FLAGS Flags;
|
---|
123 | uint32_t cEnters;
|
---|
124 | PFNCRBLT_BLITTER pfnBlt;
|
---|
125 | CR_BLITTER_BUFFER Verticies;
|
---|
126 | CR_BLITTER_BUFFER Indicies;
|
---|
127 | RTRECTSIZE CurrentSetSize;
|
---|
128 | CR_BLITTER_WINDOW CurrentMural;
|
---|
129 | CR_BLITTER_CONTEXT CtxInfo;
|
---|
130 | int32_t i32MakeCurrentUserData;
|
---|
131 | SPUDispatchTable *pDispatch;
|
---|
132 | const CR_GLSL_CACHE *pGlslCache;
|
---|
133 | CR_GLSL_CACHE LocalGlslCache;
|
---|
134 | } CR_BLITTER, *PCR_BLITTER;
|
---|
135 |
|
---|
136 | DECLINLINE(GLboolean) CrBltIsInitialized(PCR_BLITTER pBlitter)
|
---|
137 | {
|
---|
138 | return !!pBlitter->pDispatch;
|
---|
139 | }
|
---|
140 |
|
---|
141 | VBOXBLITTERDECL(int) CrBltInit(PCR_BLITTER pBlitter, const CR_BLITTER_CONTEXT *pCtxBase, bool fCreateNewCtx, bool fForceDrawBlt, const CR_GLSL_CACHE *pShaders, SPUDispatchTable *pDispatch);
|
---|
142 |
|
---|
143 | VBOXBLITTERDECL(void) CrBltTerm(PCR_BLITTER pBlitter);
|
---|
144 |
|
---|
145 | VBOXBLITTERDECL(int) CrBltCleanup(PCR_BLITTER pBlitter);
|
---|
146 |
|
---|
147 | DECLINLINE(GLboolean) CrBltSupportsTexTex(PCR_BLITTER pBlitter)
|
---|
148 | {
|
---|
149 | return pBlitter->Flags.SupportsFBO;
|
---|
150 | }
|
---|
151 |
|
---|
152 | DECLINLINE(GLboolean) CrBltIsEntered(PCR_BLITTER pBlitter)
|
---|
153 | {
|
---|
154 | return !!pBlitter->cEnters;
|
---|
155 | }
|
---|
156 |
|
---|
157 | DECLINLINE(GLint) CrBltGetVisBits(PCR_BLITTER pBlitter)
|
---|
158 | {
|
---|
159 | return pBlitter->CtxInfo.Base.visualBits;
|
---|
160 | }
|
---|
161 |
|
---|
162 |
|
---|
163 | DECLINLINE(GLboolean) CrBltIsEverEntered(PCR_BLITTER pBlitter)
|
---|
164 | {
|
---|
165 | return !!pBlitter->Flags.Initialized;
|
---|
166 | }
|
---|
167 |
|
---|
168 | DECLINLINE(void) CrBltSetMakeCurrentUserData(PCR_BLITTER pBlitter, int32_t i32MakeCurrentUserData)
|
---|
169 | {
|
---|
170 | pBlitter->i32MakeCurrentUserData = i32MakeCurrentUserData;
|
---|
171 | }
|
---|
172 |
|
---|
173 | VBOXBLITTERDECL(int) CrBltMuralSetCurrentInfo(PCR_BLITTER pBlitter, const CR_BLITTER_WINDOW *pMural);
|
---|
174 | DECLINLINE(const CR_BLITTER_WINDOW *) CrBltMuralGetCurrentInfo(PCR_BLITTER pBlitter)
|
---|
175 | {
|
---|
176 | return &pBlitter->CurrentMural;
|
---|
177 | }
|
---|
178 |
|
---|
179 | VBOXBLITTERDECL(void) CrBltCheckUpdateViewport(PCR_BLITTER pBlitter);
|
---|
180 |
|
---|
181 | VBOXBLITTERDECL(void) CrBltLeave(PCR_BLITTER pBlitter);
|
---|
182 | VBOXBLITTERDECL(int) CrBltEnter(PCR_BLITTER pBlitter);
|
---|
183 | VBOXBLITTERDECL(void) CrBltBlitTexMural(PCR_BLITTER pBlitter, bool fBb, const VBOXVR_TEXTURE *pSrc, const RTRECT *paSrcRects, const RTRECT *paDstRects, uint32_t cRects, uint32_t fFlags);
|
---|
184 | VBOXBLITTERDECL(void) CrBltBlitTexTex(PCR_BLITTER pBlitter, const VBOXVR_TEXTURE *pSrc, const RTRECT *pSrcRect, const VBOXVR_TEXTURE *pDst, const RTRECT *pDstRect, uint32_t cRects, uint32_t fFlags);
|
---|
185 | VBOXBLITTERDECL(int) CrBltImgGetTex(PCR_BLITTER pBlitter, const VBOXVR_TEXTURE *pSrc, GLenum enmFormat, CR_BLITTER_IMG *pDst);
|
---|
186 |
|
---|
187 | VBOXBLITTERDECL(int) CrBltImgGetMural(PCR_BLITTER pBlitter, bool fBb, CR_BLITTER_IMG *pDst);
|
---|
188 | VBOXBLITTERDECL(void) CrBltImgFree(PCR_BLITTER pBlitter, CR_BLITTER_IMG *pDst);
|
---|
189 | VBOXBLITTERDECL(void) CrBltPresent(PCR_BLITTER pBlitter);
|
---|
190 | /* */
|
---|
191 | struct CR_TEXDATA;
|
---|
192 |
|
---|
193 | typedef DECLCALLBACK(void) FNCRTEXDATA_RELEASED(struct CR_TEXDATA *pTexture);
|
---|
194 | typedef FNCRTEXDATA_RELEASED *PFNCRTEXDATA_RELEASED;
|
---|
195 |
|
---|
196 | typedef union CR_TEXDATA_FLAGS
|
---|
197 | {
|
---|
198 | struct
|
---|
199 | {
|
---|
200 | uint32_t DataValid : 1;
|
---|
201 | uint32_t DataAcquired : 1;
|
---|
202 | uint32_t DataInverted : 1;
|
---|
203 | uint32_t Entered : 1;
|
---|
204 | uint32_t Reserved : 28;
|
---|
205 | };
|
---|
206 | uint32_t Value;
|
---|
207 | } CR_TEXDATA_FLAGS, *PCR_TEXDATA_FLAGS;
|
---|
208 |
|
---|
209 |
|
---|
210 | typedef struct CR_TEXDATA
|
---|
211 | {
|
---|
212 | VBOXVR_TEXTURE Tex;
|
---|
213 | volatile uint32_t cRefs;
|
---|
214 | /* fields specific to texture data download */
|
---|
215 | uint32_t idInvertTex;
|
---|
216 | uint32_t idPBO;
|
---|
217 | CR_TEXDATA_FLAGS Flags;
|
---|
218 | PCR_BLITTER pBlitter;
|
---|
219 | CR_BLITTER_IMG Img;
|
---|
220 | /*dtor*/
|
---|
221 | PFNCRTEXDATA_RELEASED pfnTextureReleased;
|
---|
222 | struct CR_TEXDATA *pScaledCache;
|
---|
223 | } CR_TEXDATA, *PCR_TEXDATA;
|
---|
224 |
|
---|
225 | DECLINLINE(void) CrTdInit(PCR_TEXDATA pTex, const VBOXVR_TEXTURE *pVrTex, PCR_BLITTER pBlitter, PFNCRTEXDATA_RELEASED pfnTextureReleased)
|
---|
226 | {
|
---|
227 | memset(pTex, 0, sizeof (*pTex));
|
---|
228 | pTex->Tex = *pVrTex;
|
---|
229 | pTex->cRefs = 1;
|
---|
230 | pTex->pBlitter = pBlitter;
|
---|
231 | pTex->pfnTextureReleased = pfnTextureReleased;
|
---|
232 | }
|
---|
233 |
|
---|
234 | DECLINLINE(const VBOXVR_TEXTURE*) CrTdTexGet(const CR_TEXDATA *pTex)
|
---|
235 | {
|
---|
236 | return &pTex->Tex;
|
---|
237 | }
|
---|
238 |
|
---|
239 | DECLINLINE(PCR_BLITTER) CrTdBlitterGet(CR_TEXDATA *pTex)
|
---|
240 | {
|
---|
241 | return pTex->pBlitter;
|
---|
242 | }
|
---|
243 |
|
---|
244 | DECLINLINE(int) CrTdBltEnter(PCR_TEXDATA pTex)
|
---|
245 | {
|
---|
246 | int rc;
|
---|
247 | if (pTex->Flags.Entered)
|
---|
248 | return VERR_INVALID_STATE;
|
---|
249 | rc = CrBltEnter(pTex->pBlitter);
|
---|
250 | if (!RT_SUCCESS(rc))
|
---|
251 | {
|
---|
252 | WARN(("CrBltEnter failed rc %d", rc));
|
---|
253 | return rc;
|
---|
254 | }
|
---|
255 | pTex->Flags.Entered = 1;
|
---|
256 | return VINF_SUCCESS;
|
---|
257 | }
|
---|
258 |
|
---|
259 | DECLINLINE(bool) CrTdBltIsEntered(PCR_TEXDATA pTex)
|
---|
260 | {
|
---|
261 | return pTex->Flags.Entered;
|
---|
262 | }
|
---|
263 |
|
---|
264 | DECLINLINE(void) CrTdBltLeave(PCR_TEXDATA pTex)
|
---|
265 | {
|
---|
266 | if (!pTex->Flags.Entered)
|
---|
267 | {
|
---|
268 | WARN(("invalid Blt Leave"));
|
---|
269 | return;
|
---|
270 | }
|
---|
271 |
|
---|
272 | CrBltLeave(pTex->pBlitter);
|
---|
273 |
|
---|
274 | pTex->Flags.Entered = 0;
|
---|
275 | }
|
---|
276 |
|
---|
277 | /* the CrTdBltXxx calls are done with the entered blitter */
|
---|
278 | /* acquire the texture data, returns the cached data in case it is cached.
|
---|
279 | * the data remains cached in the CR_TEXDATA object until it is discarded with CrTdBltDataFree or CrTdBltDataCleanup.
|
---|
280 | * */
|
---|
281 | VBOXBLITTERDECL(int) CrTdBltDataAcquire(PCR_TEXDATA pTex, GLenum enmFormat, bool fInverted, const CR_BLITTER_IMG**ppImg);
|
---|
282 |
|
---|
283 | VBOXBLITTERDECL(int) CrTdBltDataAcquireScaled(PCR_TEXDATA pTex, GLenum enmFormat, bool fInverted, uint32_t width, uint32_t height, const CR_BLITTER_IMG**ppImg);
|
---|
284 |
|
---|
285 | VBOXBLITTERDECL(int) CrTdBltDataReleaseScaled(PCR_TEXDATA pTex, const CR_BLITTER_IMG *pImg);
|
---|
286 |
|
---|
287 | VBOXBLITTERDECL(void) CrTdBltScaleCacheMoveTo(PCR_TEXDATA pTex, PCR_TEXDATA pDstTex);
|
---|
288 |
|
---|
289 | /* release the texture data, the data remains cached in the CR_TEXDATA object until it is discarded with CrTdBltDataFree or CrTdBltDataCleanup */
|
---|
290 | VBOXBLITTERDECL(int) CrTdBltDataRelease(PCR_TEXDATA pTex);
|
---|
291 | /* discard the texture data cached with previous CrTdBltDataAcquire.
|
---|
292 | * Must be called wit data released (CrTdBltDataRelease) */
|
---|
293 | VBOXBLITTERDECL(int) CrTdBltDataFree(PCR_TEXDATA pTex);
|
---|
294 | VBOXBLITTERDECL(int) CrTdBltDataFreeNe(PCR_TEXDATA pTex);
|
---|
295 | VBOXBLITTERDECL(void) CrTdBltDataInvalidateNe(PCR_TEXDATA pTex);
|
---|
296 | /* does same as CrTdBltDataFree, and in addition cleans up.
|
---|
297 | * this is kind of a texture destructor, which clients should call on texture object destruction, e.g. from the PFNCRTEXDATA_RELEASED callback */
|
---|
298 | VBOXBLITTERDECL(int) CrTdBltDataCleanup(PCR_TEXDATA pTex);
|
---|
299 |
|
---|
300 | VBOXBLITTERDECL(int) CrTdBltDataCleanupNe(PCR_TEXDATA pTex);
|
---|
301 |
|
---|
302 | DECLINLINE(uint32_t) CrTdAddRef(PCR_TEXDATA pTex)
|
---|
303 | {
|
---|
304 | return ASMAtomicIncU32(&pTex->cRefs);
|
---|
305 | }
|
---|
306 |
|
---|
307 | DECLINLINE(uint32_t) CrTdRelease(PCR_TEXDATA pTex)
|
---|
308 | {
|
---|
309 | uint32_t cRefs = ASMAtomicDecU32(&pTex->cRefs);
|
---|
310 | if (!cRefs)
|
---|
311 | {
|
---|
312 | if (pTex->pfnTextureReleased)
|
---|
313 | pTex->pfnTextureReleased(pTex);
|
---|
314 | else
|
---|
315 | CrTdBltDataCleanupNe(pTex);
|
---|
316 | }
|
---|
317 |
|
---|
318 | return cRefs;
|
---|
319 | }
|
---|
320 |
|
---|
321 | RT_C_DECLS_END
|
---|
322 |
|
---|
323 | #endif /* #ifndef ___cr_blitter_h__ */
|
---|