summaryrefslogtreecommitdiff
path: root/vcl/unx
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2015-02-25 14:31:26 +0000
committerCaolán McNamara <caolanm@redhat.com>2015-02-25 17:06:15 +0000
commita785df6a5f9ad327210f51163129ef8b59c3af29 (patch)
tree364f6db15d4ddb4f31ec2cd9b4a6c66482271a74 /vcl/unx
parent940914489c7679dc660dd671c93a7f1ec0d49ead (diff)
Use the cairo-compatible basebmp surface for headless
That way the conversion from basebmp to cairo becomes unnecessary on blitting the thing onto a cairo surface for gtk3 and opens a route to using cairo, e.g. especially for text, to render to basebmp surfaces. Change-Id: I1d11f503410af9c92a97018e9ee20045412b157e
Diffstat (limited to 'vcl/unx')
-rw-r--r--vcl/unx/gtk/window/gtksalframe.cxx46
-rw-r--r--vcl/unx/gtk3/gdi/gtk3salnativewidgets-gtk.cxx52
2 files changed, 37 insertions, 61 deletions
diff --git a/vcl/unx/gtk/window/gtksalframe.cxx b/vcl/unx/gtk/window/gtksalframe.cxx
index ebc038ccb123..997b9482a879 100644
--- a/vcl/unx/gtk/window/gtksalframe.cxx
+++ b/vcl/unx/gtk/window/gtksalframe.cxx
@@ -1966,8 +1966,11 @@ void GtkSalFrame::AllocateFrame()
if( aFrameSize.getY() == 0 )
aFrameSize.setY( 1 );
sal_Int32 nStride(basebmp::getBitmapDeviceStrideForWidth(basebmp::FORMAT_TWENTYFOUR_BIT_TC_MASK, aFrameSize.getX()));
+ int cairo_stride = cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, aFrameSize.getX());
+ assert(cairo_stride >= basebmp::getBitmapDeviceStrideForWidth(basebmp::FORMAT_THIRTYTWO_BIT_TC_MASK_BGRX,
+ aFrameSize.getX()));
m_aFrame = basebmp::createBitmapDevice(aFrameSize, true,
- basebmp::FORMAT_TWENTYFOUR_BIT_TC_MASK, nStride);
+ basebmp::FORMAT_THIRTYTWO_BIT_TC_MASK_BGRX, cairo_stride);
m_aFrame->setDamageTracker(
basebmp::IBitmapDeviceDamageTrackerSharedPtr(new DamageTracker(*this)) );
fprintf( stderr, "allocated m_aFrame size of %dx%d \n",
@@ -3423,41 +3426,28 @@ void GtkSalFrame::renderArea( cairo_t *cr, cairo_rectangle_t *area )
cairo_save( cr );
- int cairo_stride = cairo_format_stride_for_width (CAIRO_FORMAT_ARGB32, area->width);
- unsigned char *p, *src, *mem = (unsigned char *)malloc (cairo_stride * area->height);
- p = mem;
- src = data.get();
- src += (int)ay * nStride + (int)ax * 3;
-
- for (int y = 0; y < aheight; ++y)
- {
- for (int x = 0; x < awidth; ++x)
- {
- p[x*4 + 0] = src[x*3 + 0]; // B
- p[x*4 + 1] = src[x*3 + 1]; // G
- p[x*4 + 2] = src[x*3 + 2]; // R
- p[x*4 + 3] = 255; // A
- }
- src += nStride;
- p += cairo_stride;
- }
+ unsigned char *src = data.get();
+ assert(cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, size.getX()) == nStride);
cairo_surface_t *pSurface =
- cairo_image_surface_create_for_data( mem,
- CAIRO_FORMAT_ARGB32,
- awidth, aheight,
- cairo_stride );
- /* g_warning( "Fixed cairo status %d %d strides: %d vs %d, mask %d\n",
+ cairo_image_surface_create_for_data(src,
+ CAIRO_FORMAT_RGB24,
+ size.getX(), size.getY(),
+ nStride);
+ /*
+ int cairo_stride = cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, size.getX());
+ g_warning( "Fixed cairo status %d %d strides: %d vs %d, mask %d\n",
(int) cairo_status( cr ),
(int) cairo_surface_status( pSurface ),
(int) nStride,
(int) cairo_stride,
- (int) (cairo_stride & (sizeof (uint32_t)-1)) ); */
+ (int) (cairo_stride & (sizeof (uint32_t)-1)) );
+ */
cairo_set_operator( cr, CAIRO_OPERATOR_OVER );
- cairo_set_source_surface( cr, pSurface, ax, ay );
- cairo_paint( cr );
+ cairo_set_source_surface( cr, pSurface, 0, 0 );
+ cairo_rectangle( cr, ax, ay, awidth, aheight );
+ cairo_fill( cr );
cairo_surface_destroy( pSurface );
- free (mem);
cairo_restore( cr );
// Render red rectangles to show what was re-rendered ...
diff --git a/vcl/unx/gtk3/gdi/gtk3salnativewidgets-gtk.cxx b/vcl/unx/gtk3/gdi/gtk3salnativewidgets-gtk.cxx
index ac708fc5e1b7..3e67f0d48405 100644
--- a/vcl/unx/gtk3/gdi/gtk3salnativewidgets-gtk.cxx
+++ b/vcl/unx/gtk3/gdi/gtk3salnativewidgets-gtk.cxx
@@ -912,7 +912,6 @@ bool GtkSalGraphics::drawNativeControl( ControlType nType, ControlPart nPart, co
cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
translatedRegion.width, translatedRegion.height);
cairo_t *cr = cairo_create(surface);
- cairo_surface_destroy(surface); // unref
gtk_style_context_save(context);
gtk_style_context_set_state(context, flags);
@@ -960,18 +959,15 @@ bool GtkSalGraphics::drawNativeControl( ControlType nType, ControlPart nPart, co
break;
}
- gtk_style_context_restore(context);
-
- renderAreaToPix(cr, &translatedRegion);
+ cairo_surface_flush(surface); //remove in a bit
cairo_destroy(cr); // unref
+ renderAreaToPix(surface, &translatedRegion);
+ cairo_surface_destroy(surface); // unref
return true;
}
-// FIXME: This is incredibly lame... but so is cairo's insistence on - exactly -
-// its own stride - neither more nor less - particularly not more aligned
-// we like 8byte aligned, it likes 4 - most odd.
-void GtkSalGraphics::renderAreaToPix( cairo_t *cr,
+void GtkSalGraphics::renderAreaToPix( cairo_surface_t *source,
cairo_rectangle_int_t *region)
{
if( !mpFrame->m_aFrame.get() )
@@ -982,33 +978,23 @@ void GtkSalGraphics::renderAreaToPix( cairo_t *cr,
sal_Int32 nStride = mpFrame->m_aFrame->getScanlineStride();
long ax = region->x;
long ay = region->y;
- long awidth = region->width;
-
- /* Get the cairo surface and the data */
- cairo_surface_t* surface = cairo_get_target(cr);
- g_assert(surface != NULL);
- cairo_surface_flush(surface);
- unsigned char* cairo_data = cairo_image_surface_get_data(surface);
- g_assert(cairo_data != NULL);
- int cairo_stride = cairo_format_stride_for_width (CAIRO_FORMAT_ARGB32, awidth);
-
- unsigned char *src = data.get();
- src += (int)ay * nStride + (int)ax * 3;
- awidth = MIN (region->width, size.getX() - ax);
+ long awidth = MIN (region->width, size.getX() - ax);
long aheight = MIN (region->height, size.getY() - ay);
- for (int y = 0; y < aheight; ++y)
- {
- for (int x = 0; x < awidth && y < aheight; ++x)
- {
- double alpha = ((float)cairo_data[x*4 + 3])/255.0;
- src[x*3 + 0] = src[x*3 + 0] * (1.0 - alpha) + cairo_data[x*4+0];
- src[x*3 + 1] = src[x*3 + 1] * (1.0 - alpha) + cairo_data[x*4+1];
- src[x*3 + 2] = src[x*3 + 2] * (1.0 - alpha) + cairo_data[x*4+2];
- }
- src += nStride;
- cairo_data += cairo_stride;
- }
+ cairo_surface_t *target =
+ cairo_image_surface_create_for_data(data.get(),
+ CAIRO_FORMAT_RGB24,
+ size.getX(), size.getY(),
+ nStride);
+ cairo_t *cr = cairo_create(target);
+
+ cairo_set_source_surface( cr, source, ax, ay );
+ cairo_rectangle( cr, ax, ay, awidth, aheight );
+ cairo_fill( cr );
+ cairo_destroy(cr);
+ cairo_surface_flush(target);
+ cairo_surface_destroy(target);
+
if ( !mpFrame->isDuringRender() )
gtk_widget_queue_draw_area( mpFrame->getWindow(), ax, ay, awidth, aheight );
}