Loading common/drawpanel_gal.cpp +5 −8 Original line number Original line Diff line number Diff line Loading @@ -127,6 +127,8 @@ void EDA_DRAW_PANEL_GAL::onPaint( wxPaintEvent& WXUNUSED( aEvent ) ) void EDA_DRAW_PANEL_GAL::onSize( wxSizeEvent& aEvent ) void EDA_DRAW_PANEL_GAL::onSize( wxSizeEvent& aEvent ) { { m_gal->ResizeScreen( aEvent.GetSize().x, aEvent.GetSize().y ); m_gal->ResizeScreen( aEvent.GetSize().x, aEvent.GetSize().y ); m_view->SetTargetDirty( KiGfx::TARGET_CACHED ); m_view->SetTargetDirty( KiGfx::TARGET_NONCACHED ); } } Loading @@ -134,24 +136,19 @@ void EDA_DRAW_PANEL_GAL::Refresh( bool eraseBackground, const wxRect* rect ) { { #ifdef __WXDEBUG__ #ifdef __WXDEBUG__ prof_counter time; prof_counter time; prof_start( &time, false ); prof_start( &time, false ); #endif /* __WXDEBUG__ */ #endif /* __WXDEBUG__ */ printf("Refresh!\n"); m_gal->BeginDrawing(); m_gal->BeginDrawing(); m_gal->SetBackgroundColor( KiGfx::COLOR4D( 0.0, 0.0, 0.0, 1.0 ) ); m_gal->SetBackgroundColor( KiGfx::COLOR4D( 0.0, 0.0, 0.0, 1.0 ) ); m_gal->ClearScreen(); m_gal->ClearScreen(); m_gal->DrawGrid(); m_view->Redraw(); m_view->Redraw(); m_gal->EndDrawing(); m_gal->EndDrawing(); #ifdef __WXDEBUG__ #ifdef __WXDEBUG__ prof_end( &time ); prof_end( &time ); wxLogDebug( wxT( "EDA_DRAW_PANEL_GAL::Refresh: %.0f ms (%.0f fps)" ), wxLogDebug( wxT( "EDA_DRAW_PANEL_GAL::Refresh: %.0f ms (%.0f fps)" ), static_cast<double>( time.value ) / 1000.0, 1000000.0 / static_cast<double>( time.value ) ); static_cast<double>( time.value ) / 1000.0, 1000000.0 / static_cast<double>( time.value ) ); #endif /* __WXDEBUG__ */ #endif /* __WXDEBUG__ */ Loading Loading @@ -184,6 +181,9 @@ void EDA_DRAW_PANEL_GAL::SwitchBackend( GalType aGalType ) m_gal->SetScreenDPI( 106 ); // Display resolution setting m_gal->SetScreenDPI( 106 ); // Display resolution setting m_gal->ComputeWorldScreenMatrix(); m_gal->ComputeWorldScreenMatrix(); wxSize size = GetClientSize(); m_gal->ResizeScreen( size.GetX(), size.GetY() ); if( m_painter ) if( m_painter ) m_painter->SetGAL( m_gal ); m_painter->SetGAL( m_gal ); Loading @@ -193,9 +193,6 @@ void EDA_DRAW_PANEL_GAL::SwitchBackend( GalType aGalType ) m_view->RecacheAllItems( true ); m_view->RecacheAllItems( true ); } } wxSize size = GetClientSize(); m_gal->ResizeScreen( size.GetX(), size.GetY() ); m_currentGal = aGalType; m_currentGal = aGalType; } } Loading common/gal/cairo/cairo_compositor.cpp +27 −41 Original line number Original line Diff line number Diff line Loading @@ -36,8 +36,6 @@ using namespace KiGfx; CAIRO_COMPOSITOR::CAIRO_COMPOSITOR( cairo_t** aMainContext ) : CAIRO_COMPOSITOR::CAIRO_COMPOSITOR( cairo_t** aMainContext ) : m_current( 0 ), m_currentContext( aMainContext ), m_mainContext( *aMainContext ) m_current( 0 ), m_currentContext( aMainContext ), m_mainContext( *aMainContext ) { { // Obtain the transformation matrix used in the main context cairo_get_matrix( m_mainContext, &m_matrix ); } } Loading Loading @@ -65,11 +63,10 @@ void CAIRO_COMPOSITOR::Resize( unsigned int aWidth, unsigned int aHeight ) } } unsigned int CAIRO_COMPOSITOR::GetBuffer() unsigned int CAIRO_COMPOSITOR::CreateBuffer() { { // Pixel storage // Pixel storage BitmapPtr bitmap( new unsigned int[m_bufferSize] ); BitmapPtr bitmap( new unsigned int[m_bufferSize] ); memset( bitmap.get(), 0x00, m_bufferSize * sizeof(int) ); memset( bitmap.get(), 0x00, m_bufferSize * sizeof(int) ); // Create the Cairo surface // Create the Cairo surface Loading @@ -89,6 +86,7 @@ unsigned int CAIRO_COMPOSITOR::GetBuffer() cairo_set_line_cap( context, CAIRO_LINE_CAP_ROUND ); cairo_set_line_cap( context, CAIRO_LINE_CAP_ROUND ); // Use the same transformation matrix as the main context // Use the same transformation matrix as the main context cairo_get_matrix( m_mainContext, &m_matrix ); cairo_set_matrix( context, &m_matrix ); cairo_set_matrix( context, &m_matrix ); // Store the new buffer // Store the new buffer Loading @@ -101,42 +99,36 @@ unsigned int CAIRO_COMPOSITOR::GetBuffer() void CAIRO_COMPOSITOR::SetBuffer( unsigned int aBufferHandle ) void CAIRO_COMPOSITOR::SetBuffer( unsigned int aBufferHandle ) { { if( aBufferHandle <= usedBuffers() ) wxASSERT_MSG( aBufferHandle <= usedBuffers(), wxT( "Tried to use a not existing buffer" ) ); { // Get currently used transformation matrix, so it can be applied to the new buffer cairo_get_matrix( *m_currentContext, &m_matrix ); m_current = aBufferHandle - 1; m_current = aBufferHandle - 1; *m_currentContext = m_buffers[m_current].context; *m_currentContext = m_buffers[m_current].context; } #ifdef __WXDEBUG__ // Apply the current transformation matrix else cairo_set_matrix( *m_currentContext, &m_matrix ); wxLogDebug( wxT( "Tried to use a not existing buffer" ) ); #endif } } void CAIRO_COMPOSITOR::ClearBuffer() void CAIRO_COMPOSITOR::ClearBuffer() { { // Reset the transformation matrix, so it is possible to composite images using // Clear the pixel storage // screen coordinates instead of world coordinates memset( m_buffers[m_current].bitmap.get(), 0x00, m_bufferSize * sizeof(int) ); cairo_identity_matrix( m_buffers[m_current].context ); cairo_set_source_rgba( m_buffers[m_current].context, 0.0, 0.0, 0.0, 0.0 ); cairo_rectangle( m_buffers[m_current].context, 0.0, 0.0, m_width, m_height ); cairo_fill( m_buffers[m_current].context ); // Restore the transformation matrix cairo_set_matrix( m_buffers[m_current].context, &m_matrix ); } } void CAIRO_COMPOSITOR::DrawBuffer( unsigned int aBufferHandle ) void CAIRO_COMPOSITOR::DrawBuffer( unsigned int aBufferHandle ) { { if( aBufferHandle <= usedBuffers() ) wxASSERT_MSG( aBufferHandle <= usedBuffers(), wxT( "Tried to use a not existing buffer" ) ); { // Reset the transformation matrix, so it is possible to composite images using // Reset the transformation matrix, so it is possible to composite images using // screen coordinates instead of world coordinates // screen coordinates instead of world coordinates cairo_get_matrix( m_mainContext, &m_matrix ); cairo_identity_matrix( m_mainContext ); cairo_identity_matrix( m_mainContext ); // Draw the selected buffer contents cairo_set_source_surface( m_mainContext, m_buffers[aBufferHandle - 1].surface, 0.0, 0.0 ); cairo_set_source_surface( m_mainContext, m_buffers[aBufferHandle - 1].surface, 0.0, 0.0 ); cairo_paint( m_mainContext ); cairo_paint( m_mainContext ); Loading @@ -144,12 +136,6 @@ void CAIRO_COMPOSITOR::DrawBuffer( unsigned int aBufferHandle ) cairo_set_matrix( m_mainContext, &m_matrix ); cairo_set_matrix( m_mainContext, &m_matrix ); } } #ifdef __WXDEBUG__ else wxLogDebug( wxT( "Tried to use a not existing buffer" ) ); #endif } void CAIRO_COMPOSITOR::clean() void CAIRO_COMPOSITOR::clean() { { Loading common/gal/cairo/cairo_gal.cpp +43 −7 Original line number Original line Diff line number Diff line Loading @@ -48,6 +48,7 @@ CAIRO_GAL::CAIRO_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener, isGrouping = false; isGrouping = false; isInitialized = false; isInitialized = false; isDeleteSavedPixels = false; isDeleteSavedPixels = false; validCompositor = false; groupCounter = 0; groupCounter = 0; // Connecting the event handlers // Connecting the event handlers Loading Loading @@ -90,8 +91,12 @@ CAIRO_GAL::~CAIRO_GAL() void CAIRO_GAL::BeginDrawing() void CAIRO_GAL::BeginDrawing() { { initSurface(); initSurface(); if( !validCompositor ) setCompositor(); setCompositor(); compositor->SetMainContext( context ); compositor->SetBuffer( mainBuffer ); // Cairo grouping prevents display of overlapping items on the same layer in the lighter color // Cairo grouping prevents display of overlapping items on the same layer in the lighter color cairo_push_group( currentContext ); cairo_push_group( currentContext ); } } Loading Loading @@ -273,6 +278,10 @@ void CAIRO_GAL::ResizeScreen( int aWidth, int aHeight ) deleteBitmaps(); deleteBitmaps(); allocateBitmaps(); allocateBitmaps(); if( validCompositor ) compositor->Resize( aWidth, aHeight ); validCompositor = false; SetSize( wxSize( aWidth, aHeight ) ); SetSize( wxSize( aWidth, aHeight ) ); } } Loading Loading @@ -719,7 +728,7 @@ void CAIRO_GAL::SetTarget( RenderTarget aTarget ) { { // If the compositor is not set, that means that there is a recaching process going on // If the compositor is not set, that means that there is a recaching process going on // and we do not need the compositor now // and we do not need the compositor now if( !compositor ) if( !validCompositor ) return; return; // Cairo grouping prevents display of overlapping items on the same layer in the lighter color // Cairo grouping prevents display of overlapping items on the same layer in the lighter color Loading Loading @@ -751,6 +760,31 @@ RenderTarget CAIRO_GAL::GetTarget() const } } void CAIRO_GAL::ClearTarget( RenderTarget aTarget ) { // Save the current state unsigned int currentBuffer = compositor->GetBuffer(); switch( aTarget ) { // Cached and noncached items are rendered to the same buffer default: case TARGET_CACHED: case TARGET_NONCACHED: compositor->SetBuffer( mainBuffer ); break; case TARGET_OVERLAY: compositor->SetBuffer( overlayBuffer ); break; } compositor->ClearBuffer(); // Restore the previous state compositor->SetBuffer( currentBuffer ); } VECTOR2D CAIRO_GAL::ComputeCursorToWorld( const VECTOR2D& aCursorPosition ) VECTOR2D CAIRO_GAL::ComputeCursorToWorld( const VECTOR2D& aCursorPosition ) { { MATRIX3x3D inverseMatrix = worldScreenMatrix.Inverse(); MATRIX3x3D inverseMatrix = worldScreenMatrix.Inverse(); Loading Loading @@ -972,8 +1006,10 @@ void CAIRO_GAL::setCompositor() compositor->Resize( screenSize.x, screenSize.y ); compositor->Resize( screenSize.x, screenSize.y ); // Prepare buffers // Prepare buffers mainBuffer = compositor->GetBuffer(); mainBuffer = compositor->CreateBuffer(); overlayBuffer = compositor->GetBuffer(); overlayBuffer = compositor->CreateBuffer(); validCompositor = true; } } Loading common/gal/opengl/opengl_compositor.cpp +11 −11 Original line number Original line Diff line number Diff line Loading @@ -74,7 +74,7 @@ void OPENGL_COMPOSITOR::Initialize() GL_RENDERBUFFER, m_depthBuffer ); GL_RENDERBUFFER, m_depthBuffer ); // Unbind the framebuffer, so by default all the rendering goes directly to the display // Unbind the framebuffer, so by default all the rendering goes directly to the display glBindFramebuffer( GL_FRAMEBUFFER, 0 ); glBindFramebuffer( GL_FRAMEBUFFER, DIRECT_RENDERING ); m_currentFbo = 0; m_currentFbo = 0; m_initialized = true; m_initialized = true; Loading @@ -91,7 +91,7 @@ void OPENGL_COMPOSITOR::Resize( unsigned int aWidth, unsigned int aHeight ) } } unsigned int OPENGL_COMPOSITOR::GetBuffer() unsigned int OPENGL_COMPOSITOR::CreateBuffer() { { wxASSERT( m_initialized ); wxASSERT( m_initialized ); Loading Loading @@ -169,8 +169,8 @@ unsigned int OPENGL_COMPOSITOR::GetBuffer() ClearBuffer(); ClearBuffer(); glBindFramebuffer( GL_FRAMEBUFFER, 0 ); glBindFramebuffer( GL_FRAMEBUFFER, DIRECT_RENDERING ); m_currentFbo = 0; m_currentFbo = DIRECT_RENDERING; // Store the new buffer // Store the new buffer OPENGL_BUFFER buffer = { textureTarget, attachmentPoint }; OPENGL_BUFFER buffer = { textureTarget, attachmentPoint }; Loading @@ -186,10 +186,10 @@ void OPENGL_COMPOSITOR::SetBuffer( unsigned int aBufferHandle ) return; return; // Change the rendering destination to the selected attachment point // Change the rendering destination to the selected attachment point if( aBufferHandle == 0 ) if( aBufferHandle == DIRECT_RENDERING ) { { glBindFramebuffer( GL_FRAMEBUFFER, 0 ); glBindFramebuffer( GL_FRAMEBUFFER, DIRECT_RENDERING ); m_currentFbo = 0; m_currentFbo = DIRECT_RENDERING; } } else if( m_currentFbo != m_framebuffer ) else if( m_currentFbo != m_framebuffer ) { { Loading @@ -197,7 +197,7 @@ void OPENGL_COMPOSITOR::SetBuffer( unsigned int aBufferHandle ) m_currentFbo = m_framebuffer; m_currentFbo = m_framebuffer; } } if( m_currentFbo != 0 && m_current != aBufferHandle - 1 ) if( m_currentFbo != DIRECT_RENDERING ) { { m_current = aBufferHandle - 1; m_current = aBufferHandle - 1; glDrawBuffer( m_buffers[m_current].attachmentPoint ); glDrawBuffer( m_buffers[m_current].attachmentPoint ); Loading @@ -219,8 +219,8 @@ void OPENGL_COMPOSITOR::DrawBuffer( unsigned int aBufferHandle ) wxASSERT( m_initialized ); wxASSERT( m_initialized ); // Switch to the main framebuffer and blit the scene // Switch to the main framebuffer and blit the scene glBindFramebuffer( GL_FRAMEBUFFER, 0 ); glBindFramebuffer( GL_FRAMEBUFFER, DIRECT_RENDERING ); m_currentFbo = 0; m_currentFbo = DIRECT_RENDERING; // Depth test has to be disabled to make transparency working // Depth test has to be disabled to make transparency working glDisable( GL_DEPTH_TEST ); glDisable( GL_DEPTH_TEST ); Loading Loading @@ -279,4 +279,4 @@ void OPENGL_COMPOSITOR::clean() } } GLuint OPENGL_COMPOSITOR::m_currentFbo = 0; GLuint OPENGL_COMPOSITOR::m_currentFbo = DIRECT_RENDERING; common/gal/opengl/opengl_gal.cpp +30 −8 Original line number Original line Diff line number Diff line Loading @@ -130,8 +130,8 @@ void OPENGL_GAL::BeginDrawing() // Prepare rendering target buffers // Prepare rendering target buffers compositor.Initialize(); compositor.Initialize(); mainBuffer = compositor.GetBuffer(); mainBuffer = compositor.CreateBuffer(); overlayBuffer = compositor.GetBuffer(); overlayBuffer = compositor.CreateBuffer(); isFramebufferInitialized = true; isFramebufferInitialized = true; } } Loading Loading @@ -187,13 +187,10 @@ void OPENGL_GAL::BeginDrawing() SetFillColor( fillColor ); SetFillColor( fillColor ); SetStrokeColor( strokeColor ); SetStrokeColor( strokeColor ); // Prepare buffers for drawing // Unbind buffers - set compositor for direct drawing compositor.SetBuffer( mainBuffer ); compositor.SetBuffer( OPENGL_COMPOSITOR::DIRECT_RENDERING ); compositor.ClearBuffer(); compositor.SetBuffer( overlayBuffer ); compositor.ClearBuffer(); compositor.SetBuffer( 0 ); // Unbind buffers // Remove all previously stored items nonCachedManager.Clear(); nonCachedManager.Clear(); overlayManager.Clear(); overlayManager.Clear(); Loading Loading @@ -711,6 +708,31 @@ RenderTarget OPENGL_GAL::GetTarget() const } } void OPENGL_GAL::ClearTarget( RenderTarget aTarget ) { // Save the current state unsigned int oldTarget = compositor.GetBuffer(); switch( aTarget ) { // Cached and noncached items are rendered to the same buffer default: case TARGET_CACHED: case TARGET_NONCACHED: compositor.SetBuffer( mainBuffer ); break; case TARGET_OVERLAY: compositor.SetBuffer( overlayBuffer ); break; } compositor.ClearBuffer(); // Restore the previous state compositor.SetBuffer( oldTarget ); } VECTOR2D OPENGL_GAL::ComputeCursorToWorld( const VECTOR2D& aCursorPosition ) VECTOR2D OPENGL_GAL::ComputeCursorToWorld( const VECTOR2D& aCursorPosition ) { { VECTOR2D cursorPosition = aCursorPosition; VECTOR2D cursorPosition = aCursorPosition; Loading Loading
common/drawpanel_gal.cpp +5 −8 Original line number Original line Diff line number Diff line Loading @@ -127,6 +127,8 @@ void EDA_DRAW_PANEL_GAL::onPaint( wxPaintEvent& WXUNUSED( aEvent ) ) void EDA_DRAW_PANEL_GAL::onSize( wxSizeEvent& aEvent ) void EDA_DRAW_PANEL_GAL::onSize( wxSizeEvent& aEvent ) { { m_gal->ResizeScreen( aEvent.GetSize().x, aEvent.GetSize().y ); m_gal->ResizeScreen( aEvent.GetSize().x, aEvent.GetSize().y ); m_view->SetTargetDirty( KiGfx::TARGET_CACHED ); m_view->SetTargetDirty( KiGfx::TARGET_NONCACHED ); } } Loading @@ -134,24 +136,19 @@ void EDA_DRAW_PANEL_GAL::Refresh( bool eraseBackground, const wxRect* rect ) { { #ifdef __WXDEBUG__ #ifdef __WXDEBUG__ prof_counter time; prof_counter time; prof_start( &time, false ); prof_start( &time, false ); #endif /* __WXDEBUG__ */ #endif /* __WXDEBUG__ */ printf("Refresh!\n"); m_gal->BeginDrawing(); m_gal->BeginDrawing(); m_gal->SetBackgroundColor( KiGfx::COLOR4D( 0.0, 0.0, 0.0, 1.0 ) ); m_gal->SetBackgroundColor( KiGfx::COLOR4D( 0.0, 0.0, 0.0, 1.0 ) ); m_gal->ClearScreen(); m_gal->ClearScreen(); m_gal->DrawGrid(); m_view->Redraw(); m_view->Redraw(); m_gal->EndDrawing(); m_gal->EndDrawing(); #ifdef __WXDEBUG__ #ifdef __WXDEBUG__ prof_end( &time ); prof_end( &time ); wxLogDebug( wxT( "EDA_DRAW_PANEL_GAL::Refresh: %.0f ms (%.0f fps)" ), wxLogDebug( wxT( "EDA_DRAW_PANEL_GAL::Refresh: %.0f ms (%.0f fps)" ), static_cast<double>( time.value ) / 1000.0, 1000000.0 / static_cast<double>( time.value ) ); static_cast<double>( time.value ) / 1000.0, 1000000.0 / static_cast<double>( time.value ) ); #endif /* __WXDEBUG__ */ #endif /* __WXDEBUG__ */ Loading Loading @@ -184,6 +181,9 @@ void EDA_DRAW_PANEL_GAL::SwitchBackend( GalType aGalType ) m_gal->SetScreenDPI( 106 ); // Display resolution setting m_gal->SetScreenDPI( 106 ); // Display resolution setting m_gal->ComputeWorldScreenMatrix(); m_gal->ComputeWorldScreenMatrix(); wxSize size = GetClientSize(); m_gal->ResizeScreen( size.GetX(), size.GetY() ); if( m_painter ) if( m_painter ) m_painter->SetGAL( m_gal ); m_painter->SetGAL( m_gal ); Loading @@ -193,9 +193,6 @@ void EDA_DRAW_PANEL_GAL::SwitchBackend( GalType aGalType ) m_view->RecacheAllItems( true ); m_view->RecacheAllItems( true ); } } wxSize size = GetClientSize(); m_gal->ResizeScreen( size.GetX(), size.GetY() ); m_currentGal = aGalType; m_currentGal = aGalType; } } Loading
common/gal/cairo/cairo_compositor.cpp +27 −41 Original line number Original line Diff line number Diff line Loading @@ -36,8 +36,6 @@ using namespace KiGfx; CAIRO_COMPOSITOR::CAIRO_COMPOSITOR( cairo_t** aMainContext ) : CAIRO_COMPOSITOR::CAIRO_COMPOSITOR( cairo_t** aMainContext ) : m_current( 0 ), m_currentContext( aMainContext ), m_mainContext( *aMainContext ) m_current( 0 ), m_currentContext( aMainContext ), m_mainContext( *aMainContext ) { { // Obtain the transformation matrix used in the main context cairo_get_matrix( m_mainContext, &m_matrix ); } } Loading Loading @@ -65,11 +63,10 @@ void CAIRO_COMPOSITOR::Resize( unsigned int aWidth, unsigned int aHeight ) } } unsigned int CAIRO_COMPOSITOR::GetBuffer() unsigned int CAIRO_COMPOSITOR::CreateBuffer() { { // Pixel storage // Pixel storage BitmapPtr bitmap( new unsigned int[m_bufferSize] ); BitmapPtr bitmap( new unsigned int[m_bufferSize] ); memset( bitmap.get(), 0x00, m_bufferSize * sizeof(int) ); memset( bitmap.get(), 0x00, m_bufferSize * sizeof(int) ); // Create the Cairo surface // Create the Cairo surface Loading @@ -89,6 +86,7 @@ unsigned int CAIRO_COMPOSITOR::GetBuffer() cairo_set_line_cap( context, CAIRO_LINE_CAP_ROUND ); cairo_set_line_cap( context, CAIRO_LINE_CAP_ROUND ); // Use the same transformation matrix as the main context // Use the same transformation matrix as the main context cairo_get_matrix( m_mainContext, &m_matrix ); cairo_set_matrix( context, &m_matrix ); cairo_set_matrix( context, &m_matrix ); // Store the new buffer // Store the new buffer Loading @@ -101,42 +99,36 @@ unsigned int CAIRO_COMPOSITOR::GetBuffer() void CAIRO_COMPOSITOR::SetBuffer( unsigned int aBufferHandle ) void CAIRO_COMPOSITOR::SetBuffer( unsigned int aBufferHandle ) { { if( aBufferHandle <= usedBuffers() ) wxASSERT_MSG( aBufferHandle <= usedBuffers(), wxT( "Tried to use a not existing buffer" ) ); { // Get currently used transformation matrix, so it can be applied to the new buffer cairo_get_matrix( *m_currentContext, &m_matrix ); m_current = aBufferHandle - 1; m_current = aBufferHandle - 1; *m_currentContext = m_buffers[m_current].context; *m_currentContext = m_buffers[m_current].context; } #ifdef __WXDEBUG__ // Apply the current transformation matrix else cairo_set_matrix( *m_currentContext, &m_matrix ); wxLogDebug( wxT( "Tried to use a not existing buffer" ) ); #endif } } void CAIRO_COMPOSITOR::ClearBuffer() void CAIRO_COMPOSITOR::ClearBuffer() { { // Reset the transformation matrix, so it is possible to composite images using // Clear the pixel storage // screen coordinates instead of world coordinates memset( m_buffers[m_current].bitmap.get(), 0x00, m_bufferSize * sizeof(int) ); cairo_identity_matrix( m_buffers[m_current].context ); cairo_set_source_rgba( m_buffers[m_current].context, 0.0, 0.0, 0.0, 0.0 ); cairo_rectangle( m_buffers[m_current].context, 0.0, 0.0, m_width, m_height ); cairo_fill( m_buffers[m_current].context ); // Restore the transformation matrix cairo_set_matrix( m_buffers[m_current].context, &m_matrix ); } } void CAIRO_COMPOSITOR::DrawBuffer( unsigned int aBufferHandle ) void CAIRO_COMPOSITOR::DrawBuffer( unsigned int aBufferHandle ) { { if( aBufferHandle <= usedBuffers() ) wxASSERT_MSG( aBufferHandle <= usedBuffers(), wxT( "Tried to use a not existing buffer" ) ); { // Reset the transformation matrix, so it is possible to composite images using // Reset the transformation matrix, so it is possible to composite images using // screen coordinates instead of world coordinates // screen coordinates instead of world coordinates cairo_get_matrix( m_mainContext, &m_matrix ); cairo_identity_matrix( m_mainContext ); cairo_identity_matrix( m_mainContext ); // Draw the selected buffer contents cairo_set_source_surface( m_mainContext, m_buffers[aBufferHandle - 1].surface, 0.0, 0.0 ); cairo_set_source_surface( m_mainContext, m_buffers[aBufferHandle - 1].surface, 0.0, 0.0 ); cairo_paint( m_mainContext ); cairo_paint( m_mainContext ); Loading @@ -144,12 +136,6 @@ void CAIRO_COMPOSITOR::DrawBuffer( unsigned int aBufferHandle ) cairo_set_matrix( m_mainContext, &m_matrix ); cairo_set_matrix( m_mainContext, &m_matrix ); } } #ifdef __WXDEBUG__ else wxLogDebug( wxT( "Tried to use a not existing buffer" ) ); #endif } void CAIRO_COMPOSITOR::clean() void CAIRO_COMPOSITOR::clean() { { Loading
common/gal/cairo/cairo_gal.cpp +43 −7 Original line number Original line Diff line number Diff line Loading @@ -48,6 +48,7 @@ CAIRO_GAL::CAIRO_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener, isGrouping = false; isGrouping = false; isInitialized = false; isInitialized = false; isDeleteSavedPixels = false; isDeleteSavedPixels = false; validCompositor = false; groupCounter = 0; groupCounter = 0; // Connecting the event handlers // Connecting the event handlers Loading Loading @@ -90,8 +91,12 @@ CAIRO_GAL::~CAIRO_GAL() void CAIRO_GAL::BeginDrawing() void CAIRO_GAL::BeginDrawing() { { initSurface(); initSurface(); if( !validCompositor ) setCompositor(); setCompositor(); compositor->SetMainContext( context ); compositor->SetBuffer( mainBuffer ); // Cairo grouping prevents display of overlapping items on the same layer in the lighter color // Cairo grouping prevents display of overlapping items on the same layer in the lighter color cairo_push_group( currentContext ); cairo_push_group( currentContext ); } } Loading Loading @@ -273,6 +278,10 @@ void CAIRO_GAL::ResizeScreen( int aWidth, int aHeight ) deleteBitmaps(); deleteBitmaps(); allocateBitmaps(); allocateBitmaps(); if( validCompositor ) compositor->Resize( aWidth, aHeight ); validCompositor = false; SetSize( wxSize( aWidth, aHeight ) ); SetSize( wxSize( aWidth, aHeight ) ); } } Loading Loading @@ -719,7 +728,7 @@ void CAIRO_GAL::SetTarget( RenderTarget aTarget ) { { // If the compositor is not set, that means that there is a recaching process going on // If the compositor is not set, that means that there is a recaching process going on // and we do not need the compositor now // and we do not need the compositor now if( !compositor ) if( !validCompositor ) return; return; // Cairo grouping prevents display of overlapping items on the same layer in the lighter color // Cairo grouping prevents display of overlapping items on the same layer in the lighter color Loading Loading @@ -751,6 +760,31 @@ RenderTarget CAIRO_GAL::GetTarget() const } } void CAIRO_GAL::ClearTarget( RenderTarget aTarget ) { // Save the current state unsigned int currentBuffer = compositor->GetBuffer(); switch( aTarget ) { // Cached and noncached items are rendered to the same buffer default: case TARGET_CACHED: case TARGET_NONCACHED: compositor->SetBuffer( mainBuffer ); break; case TARGET_OVERLAY: compositor->SetBuffer( overlayBuffer ); break; } compositor->ClearBuffer(); // Restore the previous state compositor->SetBuffer( currentBuffer ); } VECTOR2D CAIRO_GAL::ComputeCursorToWorld( const VECTOR2D& aCursorPosition ) VECTOR2D CAIRO_GAL::ComputeCursorToWorld( const VECTOR2D& aCursorPosition ) { { MATRIX3x3D inverseMatrix = worldScreenMatrix.Inverse(); MATRIX3x3D inverseMatrix = worldScreenMatrix.Inverse(); Loading Loading @@ -972,8 +1006,10 @@ void CAIRO_GAL::setCompositor() compositor->Resize( screenSize.x, screenSize.y ); compositor->Resize( screenSize.x, screenSize.y ); // Prepare buffers // Prepare buffers mainBuffer = compositor->GetBuffer(); mainBuffer = compositor->CreateBuffer(); overlayBuffer = compositor->GetBuffer(); overlayBuffer = compositor->CreateBuffer(); validCompositor = true; } } Loading
common/gal/opengl/opengl_compositor.cpp +11 −11 Original line number Original line Diff line number Diff line Loading @@ -74,7 +74,7 @@ void OPENGL_COMPOSITOR::Initialize() GL_RENDERBUFFER, m_depthBuffer ); GL_RENDERBUFFER, m_depthBuffer ); // Unbind the framebuffer, so by default all the rendering goes directly to the display // Unbind the framebuffer, so by default all the rendering goes directly to the display glBindFramebuffer( GL_FRAMEBUFFER, 0 ); glBindFramebuffer( GL_FRAMEBUFFER, DIRECT_RENDERING ); m_currentFbo = 0; m_currentFbo = 0; m_initialized = true; m_initialized = true; Loading @@ -91,7 +91,7 @@ void OPENGL_COMPOSITOR::Resize( unsigned int aWidth, unsigned int aHeight ) } } unsigned int OPENGL_COMPOSITOR::GetBuffer() unsigned int OPENGL_COMPOSITOR::CreateBuffer() { { wxASSERT( m_initialized ); wxASSERT( m_initialized ); Loading Loading @@ -169,8 +169,8 @@ unsigned int OPENGL_COMPOSITOR::GetBuffer() ClearBuffer(); ClearBuffer(); glBindFramebuffer( GL_FRAMEBUFFER, 0 ); glBindFramebuffer( GL_FRAMEBUFFER, DIRECT_RENDERING ); m_currentFbo = 0; m_currentFbo = DIRECT_RENDERING; // Store the new buffer // Store the new buffer OPENGL_BUFFER buffer = { textureTarget, attachmentPoint }; OPENGL_BUFFER buffer = { textureTarget, attachmentPoint }; Loading @@ -186,10 +186,10 @@ void OPENGL_COMPOSITOR::SetBuffer( unsigned int aBufferHandle ) return; return; // Change the rendering destination to the selected attachment point // Change the rendering destination to the selected attachment point if( aBufferHandle == 0 ) if( aBufferHandle == DIRECT_RENDERING ) { { glBindFramebuffer( GL_FRAMEBUFFER, 0 ); glBindFramebuffer( GL_FRAMEBUFFER, DIRECT_RENDERING ); m_currentFbo = 0; m_currentFbo = DIRECT_RENDERING; } } else if( m_currentFbo != m_framebuffer ) else if( m_currentFbo != m_framebuffer ) { { Loading @@ -197,7 +197,7 @@ void OPENGL_COMPOSITOR::SetBuffer( unsigned int aBufferHandle ) m_currentFbo = m_framebuffer; m_currentFbo = m_framebuffer; } } if( m_currentFbo != 0 && m_current != aBufferHandle - 1 ) if( m_currentFbo != DIRECT_RENDERING ) { { m_current = aBufferHandle - 1; m_current = aBufferHandle - 1; glDrawBuffer( m_buffers[m_current].attachmentPoint ); glDrawBuffer( m_buffers[m_current].attachmentPoint ); Loading @@ -219,8 +219,8 @@ void OPENGL_COMPOSITOR::DrawBuffer( unsigned int aBufferHandle ) wxASSERT( m_initialized ); wxASSERT( m_initialized ); // Switch to the main framebuffer and blit the scene // Switch to the main framebuffer and blit the scene glBindFramebuffer( GL_FRAMEBUFFER, 0 ); glBindFramebuffer( GL_FRAMEBUFFER, DIRECT_RENDERING ); m_currentFbo = 0; m_currentFbo = DIRECT_RENDERING; // Depth test has to be disabled to make transparency working // Depth test has to be disabled to make transparency working glDisable( GL_DEPTH_TEST ); glDisable( GL_DEPTH_TEST ); Loading Loading @@ -279,4 +279,4 @@ void OPENGL_COMPOSITOR::clean() } } GLuint OPENGL_COMPOSITOR::m_currentFbo = 0; GLuint OPENGL_COMPOSITOR::m_currentFbo = DIRECT_RENDERING;
common/gal/opengl/opengl_gal.cpp +30 −8 Original line number Original line Diff line number Diff line Loading @@ -130,8 +130,8 @@ void OPENGL_GAL::BeginDrawing() // Prepare rendering target buffers // Prepare rendering target buffers compositor.Initialize(); compositor.Initialize(); mainBuffer = compositor.GetBuffer(); mainBuffer = compositor.CreateBuffer(); overlayBuffer = compositor.GetBuffer(); overlayBuffer = compositor.CreateBuffer(); isFramebufferInitialized = true; isFramebufferInitialized = true; } } Loading Loading @@ -187,13 +187,10 @@ void OPENGL_GAL::BeginDrawing() SetFillColor( fillColor ); SetFillColor( fillColor ); SetStrokeColor( strokeColor ); SetStrokeColor( strokeColor ); // Prepare buffers for drawing // Unbind buffers - set compositor for direct drawing compositor.SetBuffer( mainBuffer ); compositor.SetBuffer( OPENGL_COMPOSITOR::DIRECT_RENDERING ); compositor.ClearBuffer(); compositor.SetBuffer( overlayBuffer ); compositor.ClearBuffer(); compositor.SetBuffer( 0 ); // Unbind buffers // Remove all previously stored items nonCachedManager.Clear(); nonCachedManager.Clear(); overlayManager.Clear(); overlayManager.Clear(); Loading Loading @@ -711,6 +708,31 @@ RenderTarget OPENGL_GAL::GetTarget() const } } void OPENGL_GAL::ClearTarget( RenderTarget aTarget ) { // Save the current state unsigned int oldTarget = compositor.GetBuffer(); switch( aTarget ) { // Cached and noncached items are rendered to the same buffer default: case TARGET_CACHED: case TARGET_NONCACHED: compositor.SetBuffer( mainBuffer ); break; case TARGET_OVERLAY: compositor.SetBuffer( overlayBuffer ); break; } compositor.ClearBuffer(); // Restore the previous state compositor.SetBuffer( oldTarget ); } VECTOR2D OPENGL_GAL::ComputeCursorToWorld( const VECTOR2D& aCursorPosition ) VECTOR2D OPENGL_GAL::ComputeCursorToWorld( const VECTOR2D& aCursorPosition ) { { VECTOR2D cursorPosition = aCursorPosition; VECTOR2D cursorPosition = aCursorPosition; Loading