Permalink
Browse files

xvba: add cropping for shared surfaces

  • Loading branch information...
1 parent b9df3aa commit 818b4b5802dd3392b570e6ebe0809665ada6f92d @FernetMenta committed Dec 15, 2011
@@ -1680,10 +1680,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
{
@@ -2482,7 +2482,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);
@@ -2497,8 +2498,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
@@ -2534,6 +2535,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();
@@ -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;
@@ -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");
@@ -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>
@@ -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:
@@ -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;

0 comments on commit 818b4b5

Please sign in to comment.