Skip to content

Commit

Permalink
xvba: add cropping for shared surfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
FernetMenta committed Mar 6, 2012
1 parent 628f490 commit 77fdd44
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
22 changes: 15 additions & 7 deletions xbmc/cores/VideoRenderers/LinuxRendererGL.cpp
Expand Up @@ -1681,10 +1681,10 @@ void CLinuxRendererGL::RenderXVBA(int index, int field)
glBegin(GL_QUADS);
if (m_textureTarget==GL_TEXTURE_2D)
{
glTexCoord2f(0.0, 0.0); glVertex2f(m_destRect.x1, m_destRect.y1);
glTexCoord2f(1.0, 0.0); glVertex2f(m_destRect.x2, m_destRect.y1);
glTexCoord2f(1.0, 1.0); glVertex2f(m_destRect.x2, m_destRect.y2);
glTexCoord2f(0.0, 1.0); glVertex2f(m_destRect.x1, m_destRect.y2);
glTexCoord2f(plane.rect.x1, plane.rect.y1); glVertex2f(m_destRect.x1, m_destRect.y1);
glTexCoord2f(plane.rect.x2, plane.rect.y1); glVertex2f(m_destRect.x2, m_destRect.y1);
glTexCoord2f(plane.rect.x2, plane.rect.y2); glVertex2f(m_destRect.x2, m_destRect.y2);
glTexCoord2f(plane.rect.x1, plane.rect.y2); glVertex2f(m_destRect.x1, m_destRect.y2);
}
else
{
Expand Down Expand Up @@ -2483,7 +2483,8 @@ bool CLinuxRendererGL::CreateXVBATexture(int index)
#ifdef HAVE_LIBXVBA
YV12Image &im = m_buffers[index].image;
YUVFIELDS &fields = m_buffers[index].fields;
YUVPLANE &plane = fields[0][1];
YUVPLANE &plane = fields[0][0];
YUVPLANE &planeFallback = fields[0][1];

DeleteXVBATexture(index);

Expand All @@ -2498,8 +2499,8 @@ bool CLinuxRendererGL::CreateXVBATexture(int index)
plane.pixpertex_x = 1;
plane.pixpertex_y = 1;

glGenTextures(1, &plane.id);
fields[0][0].id = plane.id;
glGenTextures(1, &planeFallback.id);
plane.id = planeFallback.id;

m_eventTexturesDone[index]->Set();
#endif
Expand Down Expand Up @@ -2535,6 +2536,13 @@ void CLinuxRendererGL::UploadXVBATexture(int index)
if (xvba->UploadTexture(index, field, m_textureTarget) == 1)
fields[m_currentField][0].id = xvba->GetTexture(index, field);

CRect crop = xvba->GetCropRect();
m_sourceRect.x1 += crop.x1;
m_sourceRect.x2 -= m_sourceWidth - crop.x2;
m_sourceRect.y1 += crop.y1;
m_sourceRect.y2 -= m_sourceHeight - crop.y2;
CalculateTextureSourceRects(index, 1);

glDisable(m_textureTarget);

m_eventTexturesDone[index]->Set();
Expand Down
13 changes: 13 additions & 0 deletions xbmc/cores/dvdplayer/DVDCodecs/Video/XVBA.cpp
Expand Up @@ -551,6 +551,9 @@ bool CDecoder::CreateSession(AVCodecContext* avctx)
m_surfaceWidth = (avctx->coded_width+15) & ~15;
m_surfaceHeight = (avctx->coded_height+15) & ~15;

m_vidWidth = avctx->width;
m_vidHeight = avctx->height;

XVBA_Create_Decode_Session_Input sessionInput;
XVBA_Create_Decode_Session_Output sessionOutput;

Expand Down Expand Up @@ -1287,6 +1290,16 @@ GLuint CDecoder::GetTexture(int index, XVBA_SURFACE_FLAG field)
return m_flipBuffer[index].glTexture[field];
}

CRect CDecoder::GetCropRect()
{
CRect crop;
crop.x1 = 0;
crop.y1 = 0;
crop.x2 = m_vidWidth;
crop.y2 = m_vidHeight;
return crop;
}

void CDecoder::FinishGL()
{
CLog::Log(LOGNOTICE, "XVBA::FinishGL - clearing down gl resources");
Expand Down
3 changes: 3 additions & 0 deletions xbmc/cores/dvdplayer/DVDCodecs/Video/XVBA.h
Expand Up @@ -28,6 +28,7 @@
#include "threads/SharedSection.h"
#include "threads/Event.h"
#include "guilib/DispResource.h"
#include "guilib/Geometry.h"
#include "libavcodec/xvba.h"
#include <vector>
#include <deque>
Expand Down Expand Up @@ -91,6 +92,7 @@ class CDecoder : public CDVDVideoCodecFFmpeg::IHardwareDecoder,
void CopyYV12(uint8_t *dest);
int UploadTexture(int index, XVBA_SURFACE_FLAG field, GLenum textureTarget);
GLuint GetTexture(int index, XVBA_SURFACE_FLAG field);
CRect GetCropRect();
void FinishGL();

protected:
Expand All @@ -115,6 +117,7 @@ class CDecoder : public CDVDVideoCodecFFmpeg::IHardwareDecoder,
EDisplayState m_displayState;

unsigned int m_surfaceWidth, m_surfaceHeight;
unsigned int m_vidWidth, m_vidHeight;
unsigned int m_numRenderBuffers;

XVBADecodeCap m_decoderCap;
Expand Down

0 comments on commit 77fdd44

Please sign in to comment.