Permalink
Browse files

[libass] don't re-uploading glyphs to GPU if not changed

This uses the changed flag from libass to avoid uploading
the texture containing glyphs and the vertex buffer with
positions on every renderered frame.

This will not avoid upload in the case of only position
change which should be possible too.
  • Loading branch information...
1 parent 62b017e commit 88abe763202873665d50f8d0ce878c8bad4fdddc @elupus elupus committed May 6, 2012
@@ -31,6 +31,7 @@
#include "windowing/WindowingFactory.h"
#include "settings/Settings.h"
#include "threads/SingleLock.h"
+#include "utils/MathUtils.h"
#if defined(HAS_GL) || defined(HAS_GLES)
#include "OverlayRendererGL.h"
#elif defined(HAS_DX)
@@ -282,29 +283,62 @@ void CRenderer::Render(COverlay* o)
o->Render(state);
}
+COverlay* CRenderer::Convert(CDVDOverlaySSA* o, double pts)
+{
+ CRect src, dst;
+ g_renderManager.GetVideoRect(src, dst);
+
+ int width = MathUtils::round_int(dst.Width());
+ int height = MathUtils::round_int(dst.Height());
+
+ int changes = 0;
+ ASS_Image* images = o->m_libass->RenderImage(width, height, pts, &changes);
+
+ if(o->m_overlay)
+ {
+ if(changes == 0)
+ return o->m_overlay->Acquire();
+ }
+
+#if defined(HAS_GL) || defined(HAS_GLES)
+ return new COverlayGlyphGL(images, width, height);
+#elif defined(HAS_DX)
+ return new COverlayQuadsDX(images, width, height);
+#endif
+ return NULL;
+}
+
+
COverlay* CRenderer::Convert(CDVDOverlay* o, double pts)
{
- COverlay* r = o->m_overlay;
+ COverlay* r = NULL;
+
+ if(o->IsOverlayType(DVDOVERLAY_TYPE_SSA))
+ r = Convert((CDVDOverlaySSA*)o, pts);
+ else if(o->m_overlay)
+ r = o->m_overlay->Acquire();
+
if(r)
- return r->Acquire();
+ {
+ if(o->m_overlay)
+ o->m_overlay->Release();
+ o->m_overlay = r->Acquire();
+ return r;
+ }
#if defined(HAS_GL) || defined(HAS_GLES)
if (o->IsOverlayType(DVDOVERLAY_TYPE_IMAGE))
r = new COverlayTextureGL((CDVDOverlayImage*)o);
else if(o->IsOverlayType(DVDOVERLAY_TYPE_SPU))
r = new COverlayTextureGL((CDVDOverlaySpu*)o);
- else if(o->IsOverlayType(DVDOVERLAY_TYPE_SSA))
- r = new COverlayGlyphGL((CDVDOverlaySSA*)o, pts);
#elif defined(HAS_DX)
if (o->IsOverlayType(DVDOVERLAY_TYPE_IMAGE))
r = new COverlayImageDX((CDVDOverlayImage*)o);
else if(o->IsOverlayType(DVDOVERLAY_TYPE_SPU))
r = new COverlayImageDX((CDVDOverlaySpu*)o);
- else if(o->IsOverlayType(DVDOVERLAY_TYPE_SSA))
- r = new COverlayQuadsDX((CDVDOverlaySSA*)o, pts);
#endif
- if(r && !o->IsOverlayType(DVDOVERLAY_TYPE_SSA))
+ if(r)
o->m_overlay = r->Acquire();
return r;
}
@@ -119,6 +119,7 @@ namespace OVERLAY {
void Render(COverlay* o);
COverlay* Convert(CDVDOverlay* o, double pts);
+ COverlay* Convert(CDVDOverlaySSA* o, double pts);
void Release(COverlayV& list);
void Release(SElementV& list);
@@ -160,26 +160,19 @@ static bool LoadTexture(int width, int height, int stride
return true;
}
-COverlayQuadsDX::COverlayQuadsDX(CDVDOverlaySSA* o, double pts)
+COverlayQuadsDX::COverlayQuadsDX(ASS_Image* images, int width, int height)
{
- CRect src, dst;
- g_renderManager.GetVideoRect(src, dst);
-
m_width = 1.0;
m_height = 1.0;
m_align = ALIGN_VIDEO;
m_pos = POSITION_RELATIVE;
m_x = 0.0f;
m_y = 0.0f;
m_count = 0;
-
- int width = MathUtils::round_int(dst.Width());
- int height = MathUtils::round_int(dst.Height());
-
m_fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1;
SQuads quads;
- if(!convert_quad(o, pts, width, height, quads))
+ if(!convert_quad(images, quads))
return;
float u, v;
@@ -31,14 +31,15 @@ class CDVDOverlay;
class CDVDOverlayImage;
class CDVDOverlaySpu;
class CDVDOverlaySSA;
+typedef struct ass_image ASS_Image;
namespace OVERLAY {
class COverlayQuadsDX
: public COverlayMainThread
{
public:
- COverlayQuadsDX(CDVDOverlaySSA* o, double pts);
+ COverlayQuadsDX(ASS_Image* images, int width, int height);
virtual ~COverlayQuadsDX();
void Render(SRenderState& state);
@@ -246,26 +246,19 @@ COverlayTextureGL::COverlayTextureGL(CDVDOverlaySpu* o)
m_height = (float)(max_y - min_y);
}
-COverlayGlyphGL::COverlayGlyphGL(CDVDOverlaySSA* o, double pts)
+COverlayGlyphGL::COverlayGlyphGL(ASS_Image* images, int width, int height)
{
- CRect src, dst;
- g_renderManager.GetVideoRect(src, dst);
-
m_vertex = NULL;
m_width = 1.0;
m_height = 1.0;
m_align = ALIGN_VIDEO;
m_pos = POSITION_RELATIVE;
m_x = 0.0f;
m_y = 0.0f;
-
- int width = MathUtils::round_int(dst.Width());
- int height = MathUtils::round_int(dst.Height());
-
m_texture = 0;
SQuads quads;
- if(!convert_quad(o, pts, width, height, quads))
+ if(!convert_quad(images, quads))
return;
glGenTextures(1, &m_texture);
@@ -29,6 +29,7 @@ class CDVDOverlay;
class CDVDOverlayImage;
class CDVDOverlaySpu;
class CDVDOverlaySSA;
+typedef struct ass_image ASS_Image;
#if defined(HAS_GL) || HAS_GLES == 2
@@ -53,7 +54,8 @@ namespace OVERLAY {
: public COverlayMainThread
{
public:
- COverlayGlyphGL(CDVDOverlaySSA* o, double pts);
+ COverlayGlyphGL(ASS_Image* images, int width, int height);
+
virtual ~COverlayGlyphGL();
void Render(SRenderState& state);
@@ -182,9 +182,8 @@ uint32_t* convert_rgba(CDVDOverlaySpu* o, bool mergealpha
return rgba;
}
-bool convert_quad(CDVDOverlaySSA* o, double pts, int width, int height, SQuads& quads)
+bool convert_quad(ASS_Image* images, SQuads& quads)
{
- ASS_Image* images = o->m_libass->RenderImage(width, height, pts);
ASS_Image* img;
if (!images)
@@ -25,6 +25,7 @@
class CDVDOverlayImage;
class CDVDOverlaySpu;
class CDVDOverlaySSA;
+typedef struct ass_image ASS_Image;
namespace OVERLAY {
@@ -62,8 +63,6 @@ namespace OVERLAY {
uint32_t* convert_rgba(CDVDOverlaySpu* o, bool mergealpha
, int& min_x, int& max_x
, int& min_y, int& max_y);
- bool convert_quad(CDVDOverlaySSA* o, double pts
- , int width, int height
- , SQuads& quads);
+ bool convert_quad(ASS_Image* images, SQuads& quads);
}

0 comments on commit 88abe76

Please sign in to comment.