GAL: made Begin/EndDrawing calls public to have more control over timing of rendering context creation/destruction

This commit is contained in:
Tomasz Wlostowski 2021-11-28 16:39:10 +01:00
parent 5750e38102
commit b59ee13fcc
5 changed files with 52 additions and 44 deletions

View File

@ -89,13 +89,13 @@ CAIRO_GAL_BASE::~CAIRO_GAL_BASE()
}
void CAIRO_GAL_BASE::beginDrawing()
void CAIRO_GAL_BASE::BeginDrawing()
{
resetContext();
}
void CAIRO_GAL_BASE::endDrawing()
void CAIRO_GAL_BASE::EndDrawing()
{
// Force remaining objects to be drawn
Flush();
@ -1317,11 +1317,11 @@ CAIRO_GAL::~CAIRO_GAL()
}
void CAIRO_GAL::beginDrawing()
void CAIRO_GAL::BeginDrawing()
{
initSurface();
CAIRO_GAL_BASE::beginDrawing();
CAIRO_GAL_BASE::BeginDrawing();
if( !m_validCompositor )
setCompositor();
@ -1331,9 +1331,9 @@ void CAIRO_GAL::beginDrawing()
}
void CAIRO_GAL::endDrawing()
void CAIRO_GAL::EndDrawing()
{
CAIRO_GAL_BASE::endDrawing();
CAIRO_GAL_BASE::EndDrawing();
// Merge buffers on the screen
m_compositor->DrawBuffer( m_mainBuffer );

View File

@ -415,7 +415,7 @@ VECTOR2D OPENGL_GAL::getScreenPixelSize() const
}
void OPENGL_GAL::beginDrawing()
void OPENGL_GAL::BeginDrawing()
{
#ifdef KICAD_GAL_PROFILE
PROF_COUNTER totalRealTime( "OPENGL_GAL::beginDrawing()", true );
@ -573,7 +573,7 @@ void OPENGL_GAL::beginDrawing()
}
void OPENGL_GAL::endDrawing()
void OPENGL_GAL::EndDrawing()
{
wxASSERT_MSG( m_isContextLocked, "What happened to the context lock?" );
@ -614,7 +614,7 @@ void OPENGL_GAL::endDrawing()
}
void OPENGL_GAL::lockContext( int aClientCookie )
void OPENGL_GAL::LockContext( int aClientCookie )
{
wxASSERT_MSG( !m_isContextLocked, "Context already locked." );
m_isContextLocked = true;
@ -624,7 +624,7 @@ void OPENGL_GAL::lockContext( int aClientCookie )
}
void OPENGL_GAL::unlockContext( int aClientCookie )
void OPENGL_GAL::UnlockContext( int aClientCookie )
{
wxASSERT_MSG( m_isContextLocked, "Context not locked. A GAL_CONTEXT_LOCKER RAII object must "
"be stacked rather than making separate lock/unlock calls." );

View File

@ -218,6 +218,12 @@ public:
///< @copydoc GAL::DrawGrid()
void DrawGrid() override;
/// @copydoc GAL::BeginDrawing()
void BeginDrawing() override;
/// @copydoc GAL::EndDrawing()
void EndDrawing() override;
protected:
// Geometric transforms according to the m_currentWorld2Screen transform matrix:
@ -242,12 +248,6 @@ protected:
*/
void arc_angles_xform_and_normalize( double& aStartAngle, double& aEndAngle );
/// @copydoc GAL::BeginDrawing()
void beginDrawing() override;
/// @copydoc GAL::EndDrawing()
void endDrawing() override;
void resetContext();
/**
@ -425,10 +425,10 @@ public:
bool SetNativeCursorStyle( KICURSOR aCursor ) override;
/// @copydoc GAL::BeginDrawing()
void beginDrawing() override;
void BeginDrawing() override;
/// @copydoc GAL::EndDrawing()
void endDrawing() override;
void EndDrawing() override;
/// Prepare Cairo surfaces for drawing
void initSurface();

View File

@ -1086,12 +1086,26 @@ public:
return false;
}
/// Use GAL_CONTEXT_LOCKER RAII object unless you know what you're doing.
virtual void LockContext( int aClientCookie ) {}
virtual void UnlockContext( int aClientCookie ) {}
/// Start/end drawing functions, draw calls can be only made in between the calls
/// to BeginDrawing()/EndDrawing(). Normally you should create a GAL_DRAWING_CONTEXT RAII
/// object, but I'm leaving these functions public for more precise (i.e. timing/profiling)
/// control of the drawing process - Tom
/// Begin the drawing, needs to be called for every new frame.
/// Use GAL_DRAWING_CONTEXT RAII object unless you know what you're doing.
virtual void BeginDrawing() {};
/// End the drawing, needs to be called for every new frame.
/// Use GAL_DRAWING_CONTEXT RAII object unless you know what you're doing.
virtual void EndDrawing() {};
protected:
/// Use GAL_CONTEXT_LOCKER RAII object
virtual void lockContext( int aClientCookie ) {}
virtual void unlockContext( int aClientCookie ) {}
/// Enable item update mode.
/// Private: use GAL_UPDATE_CONTEXT RAII object
virtual void beginUpdate() {}
@ -1099,13 +1113,7 @@ protected:
/// Disable item update mode.
virtual void endUpdate() {}
/// Begin the drawing, needs to be called for every new frame.
/// Private: use GAL_DRAWING_CONTEXT RAII object
virtual void beginDrawing() {};
/// End the drawing, needs to be called for every new frame.
/// Private: use GAL_DRAWING_CONTEXT RAII object
virtual void endDrawing() {};
/// Compute the scaling factor for the world->screen matrix
inline void computeWorldScale()
@ -1228,12 +1236,12 @@ public:
m_gal( aGal )
{
m_cookie = rand();
m_gal->lockContext( m_cookie );
m_gal->LockContext( m_cookie );
}
~GAL_CONTEXT_LOCKER()
{
m_gal->unlockContext( m_cookie );
m_gal->UnlockContext( m_cookie );
}
protected:
@ -1264,12 +1272,12 @@ public:
GAL_DRAWING_CONTEXT( GAL* aGal ) :
GAL_CONTEXT_LOCKER( aGal )
{
m_gal->beginDrawing();
m_gal->BeginDrawing();
}
~GAL_DRAWING_CONTEXT()
{
m_gal->endDrawing();
m_gal->EndDrawing();
}
};

View File

@ -289,6 +289,16 @@ public:
return m_isContextLocked;
}
void LockContext( int aClientCookie ) override;
void UnlockContext( int aClientCookie ) override;
/// @copydoc GAL::BeginDrawing()
void BeginDrawing() override;
/// @copydoc GAL::EndDrawing()
void EndDrawing() override;
///< Parameters passed to the GLU tesselator
struct TessParams
{
@ -354,22 +364,12 @@ private:
GLUtesselator* m_tesselator;
std::deque< boost::shared_array<GLdouble> > m_tessIntersects;
void lockContext( int aClientCookie ) override;
void unlockContext( int aClientCookie ) override;
/// @copydoc GAL::BeginUpdate()
void beginUpdate() override;
/// @copydoc GAL::EndUpdate()
void endUpdate() override;
/// @copydoc GAL::BeginDrawing()
void beginDrawing() override;
/// @copydoc GAL::EndDrawing()
void endDrawing() override;
///< Update handler for OpenGL settings
bool updatedGalDisplayOptions( const GAL_DISPLAY_OPTIONS& aOptions ) override;