Skip to content

Commit

Permalink
Stage #3 - first cut at flushing the whole buffer across ...
Browse files Browse the repository at this point in the history
  • Loading branch information
mmeeks committed Nov 14, 2015
1 parent 6d78666 commit 619981f
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 6 deletions.
4 changes: 4 additions & 0 deletions vcl/inc/openglgdiimpl.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ protected:
/// retrieve the default context for offscreen rendering
static rtl::Reference<OpenGLContext> GetDefaultContext();

/// flush contents of the back-buffer to the screen & swap.
void FlushAndSwap();

/// create a new context for rendering to the underlying window
virtual rtl::Reference<OpenGLContext> CreateWinContext() = 0;

Expand Down Expand Up @@ -346,6 +349,7 @@ public:
virtual bool drawGradient(const tools::PolyPolygon& rPolygon, const Gradient& rGradient) override;

virtual OpenGLContext *beginPaint() override;
virtual void endPaint() override;
private:
};

Expand Down
1 change: 1 addition & 0 deletions vcl/inc/salgdi.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ public:
const OutputDevice *pOutDev );

virtual OpenGLContext *BeginPaint() { return nullptr; }
virtual void EndPaint() { }

virtual SystemGraphicsData GetGraphicsData() const = 0;

Expand Down
1 change: 1 addition & 0 deletions vcl/inc/salgdiimpl.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ public:
virtual bool drawGradient(const tools::PolyPolygon& rPolygon, const Gradient& rGradient) = 0;

virtual OpenGLContext *beginPaint() { return nullptr; }
virtual OpenGLContext *endPaint() { }
};

#endif
Expand Down
85 changes: 79 additions & 6 deletions vcl/opengl/gdiimpl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ void OpenGLSalGraphicsImpl::Init()
}
maOffscreenTex = OpenGLTexture();
}

if( mpWindowContext.is() )
mpWindowContext.reset();
mpWindowContext = CreateWinContext();
}

// Currently only used to get windows ordering right.
Expand Down Expand Up @@ -172,12 +176,6 @@ void OpenGLSalGraphicsImpl::PreDraw()

void OpenGLSalGraphicsImpl::PostDraw()
{
if( mpContext->mnPainting == 0 )
{
if (!IsOffscreen()) ...
#warning "Trigger re-rendering of the window if we have one"
glFlush();
}
if( mbUseScissor )
glDisable( GL_SCISSOR_TEST );
if( mbUseStencil )
Expand All @@ -191,6 +189,15 @@ void OpenGLSalGraphicsImpl::PostDraw()
#endif
}

if( mpContext->mnPainting == 0 )
{
if (!IsOffscreen())
{
SAL_DEBUG("PostDraw flush ?");
FlushAndSwap();
}
}

CHECK_GL_ERROR();
OpenGLZone::leave();
}
Expand Down Expand Up @@ -1848,10 +1855,76 @@ bool OpenGLSalGraphicsImpl::drawGradient(const tools::PolyPolygon& rPolyPoly,

OpenGLContext *OpenGLSalGraphicsImpl::beginPaint()
{
SAL_DEBUG( "want to rid ourselves of this method" );
AcquireContext();
return mpContext.get();
}

void OpenGLSalGraphicsImpl::FlushAndSwap()
{
assert( !IsOffscreen() );
assert( mpContext.is() );

OpenGLZone aZone;

// glFlush(); - not needed
mpWindowContext->makeCurrent();
CHECK_GL_ERROR();

mpWindowContext->AcquireDefaultFramebuffer();
CHECK_GL_ERROR();

glViewport( 0, 0, GetWidth(), GetHeight() );
ImplInitClipRegion();
CHECK_GL_ERROR();

SalTwoRect aPosAry(0, 0, maOffscreenTex.GetWidth(), maOffscreenTex.GetHeight(),
0, 0, maOffscreenTex.GetWidth(), maOffscreenTex.GetHeight());

OpenGLProgram *pProgram =
mpContext->UseProgram( "textureVertexShader", "textureFragmentShader", "" );

pProgram->SetTexture( "sampler", maOffscreenTex );

GLfloat aTexCoord[8];
maOffscreenTex.GetCoord( aTexCoord, rPosAry, false );
pProgram->SetTextureCoord( aTexCoord );

long nX1( rPosAry.mnDestX );
long nY1( rPosAry.mnDestY );
long nX2( nX1 + rPosAry.mnDestWidth );
long nY2( nY1 + rPosAry.mnDestHeight );
const SalPoint aPoints[] = { { nX1, nY2 }, { nX1, nY1 },
{ nX2, nY1 }, { nX2, nY2 }};

std::vector<GLfloat> aVertices(nPoints * 2);
sal_uInt32 i, j;

for( i = 0, j = 0; i < 4; i++, j += 2 )
{
aVertices[j] = GLfloat(aPoints[i].mnX);
aVertices[j+1] = GLfloat(aPoints[i].mnY);
}

pProgram->ApplyMatrix(GetWidth(), GetHeight(), 0.0);
pProgram->SetVertices( &aVertices[0] );
glDrawArrays( GL_TRIANGLE_FAN, 0, nPoints );

pProgram->Clean();

mpContext->swapBuffers();
}

void OpenGLSalGraphicsImpl::endPaint()
{
assert( !IsOffscreen() );

AcquireContext();
if( mpContext.is() &&
mpContext->mnPainting == 0 )
FlushAndSwap();
}

bool OpenGLSalGraphicsImpl::IsForeignContext(const rtl::Reference<OpenGLContext> &xContext)
{
// so far a blunt heuristic: vcl uses shiny new contexts.
Expand Down
7 changes: 7 additions & 0 deletions vcl/source/opengl/OpenGLHelper.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1086,13 +1086,15 @@ OutputDevice::PaintScope::PaintScope(OutputDevice *pDev)
if( pDev->mpGraphics || pDev->AcquireGraphics() )
{
OpenGLContext *pContext = pDev->mpGraphics->BeginPaint();
/*
if( pContext )
{
assert( pContext->mnPainting >= 0 );
pContext->mnPainting++;
pContext->acquire();
pHandle = static_cast<void *>( pContext );
}
*/
}
}

Expand All @@ -1101,6 +1103,10 @@ OutputDevice::PaintScope::PaintScope(OutputDevice *pDev)
*/
void OutputDevice::PaintScope::flush()
{
if( pDev->mpGraphics || pDev->AcquireGraphics() )
pDev->mpGraphics->EndPaint();

#if 0
if( pHandle )
{
OpenGLContext *pContext = static_cast<OpenGLContext *>( pHandle );
Expand All @@ -1117,6 +1123,7 @@ void OutputDevice::PaintScope::flush()
}
pContext->release();
}
#endif
}

OutputDevice::PaintScope::~PaintScope()
Expand Down

0 comments on commit 619981f

Please sign in to comment.