summaryrefslogtreecommitdiff
path: root/vcl/unx/gtk3
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2016-01-14 20:49:06 +0000
committerCaolán McNamara <caolanm@redhat.com>2016-01-18 11:34:09 +0000
commit4bf6f5581c9938504b841eb94f6121068b2eb752 (patch)
tree572ef155cd3307fcca30e6388bd3f685f781a3cf /vcl/unx/gtk3
parent7d8e94aaaddff0708dd8a5a6fde4d9922cd4e1ea (diff)
svp: replace basebmp surfaces with native cairo surfaces
so we can then a) drop all of our own clipping code in favour of cairos clipping code b) just pass cairo surfaces around the place instead of constantly creating and tearing down surfaces based on basebmp data c) we can additionally drop various flushing of the surfaces as it doesn't matter anymore d) use a lot less of our own code and far more of some one elses hopefully more drawing optimized code e) seeing as the graphics context are always cairo now, then they are always cairo compatible, so those checks can go also still need to figure out drawMask Change-Id: I320cd14cdc714ea59d00e90233f1171f821cf953
Diffstat (limited to 'vcl/unx/gtk3')
-rw-r--r--vcl/unx/gtk3/gtk3gtkframe.cxx107
-rw-r--r--vcl/unx/gtk3/gtk3salnativewidgets-gtk.cxx3
2 files changed, 41 insertions, 69 deletions
diff --git a/vcl/unx/gtk3/gtk3gtkframe.cxx b/vcl/unx/gtk3/gtk3gtkframe.cxx
index c2551314ba28..6012f58f2650 100644
--- a/vcl/unx/gtk3/gtk3gtkframe.cxx
+++ b/vcl/unx/gtk3/gtk3gtkframe.cxx
@@ -335,24 +335,6 @@ GetAlternateKeyCode( const sal_uInt16 nKeyCode )
return aAlternate;
}
-namespace {
-/// Decouple SalFrame lifetime from damagetracker lifetime
-struct DamageTracker : public basebmp::IBitmapDeviceDamageTracker
-{
- explicit DamageTracker(GtkSalFrame& rFrame) : m_rFrame(rFrame)
- {}
-
- virtual ~DamageTracker() {}
-
- virtual void damaged(const basegfx::B2IBox& rDamageRect) const override
- {
- m_rFrame.damaged(rDamageRect);
- }
-
- GtkSalFrame& m_rFrame;
-};
-}
-
static bool dumpframes = false;
void GtkSalFrame::doKeyCallback( guint state,
@@ -857,6 +839,9 @@ GtkSalFrame::~GtkSalFrame()
delete m_pGraphics;
m_pGraphics = nullptr;
+
+ if (m_pSurface)
+ cairo_surface_destroy(m_pSurface);
}
void GtkSalFrame::moveWindow( long nX, long nY )
@@ -956,8 +941,22 @@ GtkWidget *GtkSalFrame::getMouseEventWidget() const
return GTK_WIDGET(m_pEventBox);
}
+static void damaged(void *handle,
+ sal_Int32 nExtentsLeft, sal_Int32 nExtentsTop,
+ sal_Int32 nExtentsRight, sal_Int32 nExtentsBottom)
+{
+ GtkSalFrame* pThis = static_cast<GtkSalFrame*>(handle);
+ pThis->damaged(nExtentsLeft, nExtentsTop,
+ nExtentsRight, nExtentsBottom);
+}
+
void GtkSalFrame::InitCommon()
{
+ m_pSurface = nullptr;
+
+ m_aDamageHandler.handle = this;
+ m_aDamageHandler.damaged = ::damaged;
+
m_pEventBox = GTK_EVENT_BOX(gtk_event_box_new());
gtk_widget_add_events( GTK_WIDGET(m_pEventBox),
GDK_ALL_EVENTS_MASK );
@@ -1271,12 +1270,12 @@ SalGraphics* GtkSalFrame::AcquireGraphics()
if( !m_pGraphics )
{
m_pGraphics = new GtkSalGraphics( this, m_pWindow );
- if( !m_aFrame.get() )
+ if (!m_pSurface)
{
AllocateFrame();
TriggerPaintEvent();
}
- m_pGraphics->setDevice( m_aFrame );
+ m_pGraphics->setSurface(m_pSurface);
}
m_bGraphics = true;
return m_pGraphics;
@@ -1525,25 +1524,24 @@ void GtkSalFrame::SetMinClientSize( long nWidth, long nHeight )
void GtkSalFrame::AllocateFrame()
{
basegfx::B2IVector aFrameSize( maGeometry.nWidth, maGeometry.nHeight );
- if( ! m_aFrame.get() || m_aFrame->getSize() != aFrameSize )
+ if (!m_pSurface || cairo_image_surface_get_width(m_pSurface) != aFrameSize.getX() ||
+ cairo_image_surface_get_height(m_pSurface) != aFrameSize.getY() )
{
if( aFrameSize.getX() == 0 )
aFrameSize.setX( 1 );
if( aFrameSize.getY() == 0 )
aFrameSize.setY( 1 );
- m_aFrame = basebmp::createBitmapDevice(aFrameSize, true, SVP_CAIRO_FORMAT);
- assert(cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, aFrameSize.getX()) ==
- m_aFrame->getScanlineStride());
- m_aFrame->setDamageTracker(
- basebmp::IBitmapDeviceDamageTrackerSharedPtr(new DamageTracker(*this)) );
- SAL_INFO("vcl.gtk3", "allocated m_aFrame size of " << maGeometry.nWidth << " x " << maGeometry.nHeight);
-
-#if OSL_DEBUG_LEVEL > 0 // set background to orange
- m_aFrame->clear( basebmp::Color( 255, 127, 0 ) );
-#endif
- if( m_pGraphics )
- m_pGraphics->setDevice( m_aFrame );
+ if (m_pSurface)
+ cairo_surface_destroy(m_pSurface);
+ m_pSurface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
+ aFrameSize.getX(),
+ aFrameSize.getY());
+ cairo_surface_set_user_data(m_pSurface, SvpSalGraphics::getDamageKey(), &m_aDamageHandler, nullptr);
+ SAL_INFO("vcl.gtk3", "allocated Frame size of " << maGeometry.nWidth << " x " << maGeometry.nHeight);
+
+ if (m_pGraphics)
+ m_pGraphics->setSurface(m_pSurface);
}
}
@@ -2654,26 +2652,14 @@ gboolean GtkSalFrame::signalCrossing( GtkWidget*, GdkEventCrossing* pEvent, gpoi
cairo_t* GtkSalFrame::getCairoContext() const
{
- cairo_t* cr = SvpSalGraphics::createCairoContext(m_aFrame);
+ cairo_t* cr = cairo_create(m_pSurface);
assert(cr);
return cr;
}
-void GtkSalFrame::damaged (const basegfx::B2IBox& rDamageRect)
+void GtkSalFrame::damaged(sal_Int32 nExtentsLeft, sal_Int32 nExtentsTop,
+ sal_Int32 nExtentsRight, sal_Int32 nExtentsBottom) const
{
-#if OSL_DEBUG_LEVEL > 1
- long long area = rDamageRect.getWidth() * rDamageRect.getHeight();
- if( area > 32 * 1024 )
- {
- fprintf( stderr, "bitmap damaged %d %d (%dx%d) area %lld widget\n",
- (int) rDamageRect.getMinX(),
- (int) rDamageRect.getMinY(),
- (int) rDamageRect.getWidth(),
- (int) rDamageRect.getHeight(),
- area );
- }
-#endif
-
if (dumpframes)
{
static int frame;
@@ -2684,32 +2670,19 @@ void GtkSalFrame::damaged (const basegfx::B2IBox& rDamageRect)
}
gtk_widget_queue_draw_area(GTK_WIDGET(m_pFixedContainer),
- rDamageRect.getMinX(),
- rDamageRect.getMinY(),
- rDamageRect.getWidth(),
- rDamageRect.getHeight());
+ nExtentsLeft, nExtentsTop,
+ nExtentsRight - nExtentsLeft,
+ nExtentsBottom - nExtentsTop);
}
-// blit our backing basebmp buffer to the target cairo context cr
-gboolean GtkSalFrame::signalDraw( GtkWidget*, cairo_t *cr, gpointer frame )
+// blit our backing cairo surface to the target cairo context
+gboolean GtkSalFrame::signalDraw(GtkWidget*, cairo_t *cr, gpointer frame)
{
GtkSalFrame* pThis = static_cast<GtkSalFrame*>(frame);
- cairo_save(cr);
-
- cairo_t* source = pThis->getCairoContext();
- cairo_surface_t *pSurface = cairo_get_target(source);
-
- cairo_set_operator( cr, CAIRO_OPERATOR_OVER );
- cairo_set_source_surface(cr, pSurface, 0, 0);
+ cairo_set_source_surface(cr, pThis->m_pSurface, 0, 0);
cairo_paint(cr);
- cairo_destroy(source);
-
- cairo_restore(cr);
-
- cairo_surface_flush(cairo_get_target(cr));
-
return false;
}
diff --git a/vcl/unx/gtk3/gtk3salnativewidgets-gtk.cxx b/vcl/unx/gtk3/gtk3salnativewidgets-gtk.cxx
index ead9d7fb3474..65f3d7c6ad1a 100644
--- a/vcl/unx/gtk3/gtk3salnativewidgets-gtk.cxx
+++ b/vcl/unx/gtk3/gtk3salnativewidgets-gtk.cxx
@@ -1214,9 +1214,8 @@ bool GtkSalGraphics::drawNativeControl( ControlType nType, ControlPart nPart, co
}
gtk_style_context_restore(context);
- cairo_surface_flush(cairo_get_target(cr));
cairo_destroy(cr); // unref
- mpFrame->damaged(basegfx::B2IBox(rControlRegion.Left(), rControlRegion.Top(), rControlRegion.Right(), rControlRegion.Bottom()));
+ mpFrame->damaged(rControlRegion.Left(), rControlRegion.Top(), rControlRegion.Right(), rControlRegion.Bottom());
return true;
}