blitter.cpp revision 68da78527731dc05ee33b1083d8322adbef6aa5a
/* $Id$ */
/** @file
* Blitter API implementation
*/
/*
* Copyright (C) 2013 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#include "cr_blitter.h"
#include "cr_spu.h"
#include "chromium.h"
#include "cr_error.h"
#include "cr_net.h"
#include "cr_rand.h"
#include "cr_mem.h"
#include "cr_string.h"
int CrBltInit(PCR_BLITTER pBlitter, CR_BLITTER_CONTEXT *pCtxBase, bool fCreateNewCtx, SPUDispatchTable *pDispatch)
{
{
crWarning("Default share context not initialized!");
return VERR_INVALID_PARAMETER;
}
if (fCreateNewCtx)
{
pBlitter->CtxInfo.Base.id = pDispatch->CreateContext("", pCtxBase->Base.visualBits, pCtxBase->Base.id);
{
crWarning("CreateContext failed!");
return VERR_GENERAL_FAILURE;
}
}
return VINF_SUCCESS;
}
{
}
{
return;
if (!CrBltIsEntered(pBlitter))
return;
if (pMural)
pBlitter->pDispatch->MakeCurrent(pMural->Base.id, pBlitter->i32MakeCurrentUserData, pBlitter->CtxInfo.Base.id);
else
}
static DECLCALLBACK(int) crBltBlitTexBufImplFbo(PCR_BLITTER pBlitter, VBOXVR_TEXTURE *pSrc, const RTRECT *paSrcRect, const PRTRECTSIZE pDstSize, const RTRECT *paDstRect, uint32_t cRects, uint32_t fFlags)
{
pBlitter->pDispatch->FramebufferTexture2DEXT(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, pSrc->target, pSrc->hwid, 0);
{
if (CRBLT_F_OFFSCREEN & fFlags)
{
}
else
{
}
}
return VINF_SUCCESS;
}
/* GL_TRIANGLE_FAN */
DECLINLINE(GLfloat*) crBltVtRectTFNormalized(const RTRECT *pRect, uint32_t normalX, uint32_t normalY, GLfloat* pBuff, uint32_t height)
{
/* going ccw:
* 1. (left;top) 4. (right;top)
* | ^
* > |
* 2. (left;bottom) -> 3. (right;bottom) */
/* xLeft yTop */
/* xLeft yBottom */
/* xRight yBottom */
/* xRight yTop */
return &pBuff[8];
}
DECLINLINE(GLint*) crBltVtRectTF(const RTRECT *pRect, uint32_t normalX, uint32_t normalY, GLint* pBuff, uint32_t height)
{
/* xLeft yTop */
/* xLeft yBottom */
/* xRight yBottom */
/* xRight yTop */
return &pBuff[8];
}
{
/* triangle 1 */
/* triangle 2 */
return pIndex + 6;
}
/* Indexed GL_TRIANGLES */
DECLINLINE(GLfloat*) crBltVtRectITNormalized(const RTRECT *pRect, uint32_t normalX, uint32_t normalY, GLfloat* pBuff, uint32_t height)
{
return ret;
}
DECLINLINE(GLint*) crBltVtRectIT(RTRECT *pRect, uint32_t normalX, uint32_t normalY, GLint* pBuff, GLubyte **ppIndex, GLubyte *piBase, uint32_t height)
{
if (ppIndex)
return ret;
}
{
return cRects * 4;
}
{
return 6 * cRects;
}
static GLfloat* crBltVtRectsITNormalized(const RTRECT *paRects, uint32_t cRects, uint32_t normalX, uint32_t normalY, GLfloat* pBuff, GLubyte **ppIndex, GLubyte *piBase, uint32_t height)
{
uint32_t i;
for (i = 0; i < cRects; ++i)
{
}
if (ppIndex)
{
for (i = 0; i < cRects; ++i)
{
}
}
return pBuff;
}
{
{
{
}
#ifndef DEBUG_misha
/* debugging: ensure we calculate proper buffer size */
cbBuffer += 16;
#endif
else
{
}
}
}
static void crBltCheckSetupViewport(PCR_BLITTER pBlitter, const PRTRECTSIZE pDstSize, bool fFBODraw)
{
{
#if 0
const GLdouble aProjection[] =
{
0.0, 0.0, 2.0, 0.0,
-1.0, -1.0, -1.0, 1.0
};
#else
/* Clear background to transparent */
#endif
if (!fFBODraw)
}
}
static DECLCALLBACK(int) crBltBlitTexBufImplDraw2D(PCR_BLITTER pBlitter, VBOXVR_TEXTURE *pSrc, const RTRECT *paSrcRect, const PRTRECTSIZE pDstSize, const RTRECT *paDstRect, uint32_t cRects, uint32_t fFlags)
{
{
case GL_TEXTURE_2D:
{
break;
}
case GL_TEXTURE_RECTANGLE_ARB:
{
normalX = 1;
normalY = 1;
break;
}
default:
{
return VERR_INVALID_PARAMETER;
}
}
if (cRects == 1)
{
/* just optimizatino to draw a single rect with GL_TRIANGLE_FAN */
if (bUseSameVerticies)
{
}
else
{
}
}
else
{
if (bUseSameVerticies)
{
pVerticies = (GLfloat*)crBltBufGet(&pBlitter->Verticies, cElements * 2 * sizeof (*pVerticies) + cIndicies * sizeof (*pIndicies));
crBltVtRectsITNormalized(paDstRect, cRects, normalX, normalY, pVerticies, &pIndicies, &iIdxBase, height);
}
else
{
pVerticies = (GLfloat*)crBltBufGet(&pBlitter->Verticies, cElements * 2 * 2 * sizeof (*pVerticies) + cIndicies * sizeof (*pIndicies));
pTexCoords = crBltVtRectsITNormalized(paDstRect, cRects, 1, 1, pVerticies, &pIndicies, &iIdxBase, height);
}
}
return VINF_SUCCESS;
}
{
{
}
else
crWarning("GL_EXT_framebuffer_object not supported, blitter can only blit to window");
{
}
else
{
crWarning("GL_EXT_framebuffer_blit not supported, will use Draw functions for blitting, which might be less efficient");
}
return VINF_SUCCESS;
}
{
{
}
{
}
else
{
}
}
int CrBltEnter(PCR_BLITTER pBlitter, CR_BLITTER_CONTEXT *pRestoreCtxInfo, CR_BLITTER_WINDOW *pRestoreMural)
{
if (!pBlitter->pCurrentMural)
{
crWarning("current mural not initialized!");
return VERR_INVALID_STATE;
}
if (CrBltIsEntered(pBlitter))
{
crWarning("blitter is entered already!");
return VERR_INVALID_STATE;
}
if (pRestoreCtxInfo)
{
}
else
{
}
pBlitter->pDispatch->MakeCurrent(pBlitter->pCurrentMural->Base.id, pBlitter->i32MakeCurrentUserData, pBlitter->CtxInfo.Base.id);
return VINF_SUCCESS;
if (RT_SUCCESS(rc))
{
return VINF_SUCCESS;
}
return rc;
}
static void crBltBlitTexBuf(PCR_BLITTER pBlitter, VBOXVR_TEXTURE *pSrc, const RTRECT *paSrcRects, GLenum enmDstBuff, const PRTRECTSIZE pDstSize, const RTRECT *paDstRects, uint32_t cRects, uint32_t fFlags)
{
pBlitter->pfnBlt(pBlitter, pSrc, paSrcRects, pDstSize, paDstRects, cRects, fFlags & CRBLT_F_OFFSCREEN);
}
void CrBltBlitTexMural(PCR_BLITTER pBlitter, VBOXVR_TEXTURE *pSrc, const RTRECT *paSrcRects, const RTRECT *paDstRects, uint32_t cRects, uint32_t fFlags)
{
crBltBlitTexBuf(pBlitter, pSrc, paSrcRects, GL_BACK, &DstSize, paDstRects, cRects, fFlags & (~CRBLT_F_OFFSCREEN));
}
void CrBltBlitTexTex(PCR_BLITTER pBlitter, VBOXVR_TEXTURE *pSrc, const RTRECT *pSrcRect, VBOXVR_TEXTURE *pDst, const RTRECT *pDstRect, uint32_t cRects, uint32_t fFlags)
{
pBlitter->pDispatch->FramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, pDst->target, pDst->hwid, 0);
// pBlitter->pDispatch->FramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
// pBlitter->pDispatch->FramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
}
{
else
}