aboutsummaryrefslogtreecommitdiffhomepage
path: root/gtk/PlatGTK.cxx
diff options
context:
space:
mode:
authorColomban Wendling <ban@herbesfolles.org>2014-06-23 17:57:07 +0200
committerColomban Wendling <ban@herbesfolles.org>2014-06-23 17:57:07 +0200
commitdd7b3437a932eca46d401f932cc7ca25e210dcf5 (patch)
treed05f28f4822763549b3c38368a5eac7b7937ed69 /gtk/PlatGTK.cxx
parent99fe65d3efef3442a0766e2b21fd3726a1169c50 (diff)
downloadscintilla-mirror-dd7b3437a932eca46d401f932cc7ca25e210dcf5.tar.gz
GTK: Don't create unnecessary drawing contexts
When surfaces are created without an explicit target surface they are only used for measurement purposes, so don't create a unnecessary drawing context out of the widget's surface. This avoid calling gdk_cairo_create() outside a draw handler, which GTK 3.14 stops allowing [1]. [1] https://mail.gnome.org/archives/gtk-devel-list/2014-June/msg00010.html
Diffstat (limited to 'gtk/PlatGTK.cxx')
-rw-r--r--gtk/PlatGTK.cxx23
1 files changed, 9 insertions, 14 deletions
diff --git a/gtk/PlatGTK.cxx b/gtk/PlatGTK.cxx
index d4572a912..0b8eeaf92 100644
--- a/gtk/PlatGTK.cxx
+++ b/gtk/PlatGTK.cxx
@@ -549,20 +549,9 @@ bool SurfaceImpl::Initialised() {
void SurfaceImpl::Init(WindowID wid) {
Release();
PLATFORM_ASSERT(wid);
-#if GTK_CHECK_VERSION(3,0,0)
- GdkWindow *drawable_ = gtk_widget_get_window(PWidget(wid));
-#else
- GdkDrawable *drawable_ = GDK_DRAWABLE(PWidget(wid)->window);
-#endif
- if (drawable_) {
- context = gdk_cairo_create(drawable_);
- PLATFORM_ASSERT(context);
- } else {
- // Shouldn't happen with valid window but may when calls made before
- // window completely allocated and mapped.
- psurf = cairo_image_surface_create(CAIRO_FORMAT_RGB24, 1, 1);
- context = cairo_create(psurf);
- }
+ // if we are only created from a window ID, we can't perform drawing
+ psurf = 0;
+ context = 0;
createdGC = true;
pcontext = gtk_widget_create_pango_context(PWidget(wid));
PLATFORM_ASSERT(pcontext);
@@ -681,6 +670,7 @@ void SurfaceImpl::LineTo(int x_, int y_) {
void SurfaceImpl::Polygon(Point *pts, int npts, ColourDesired fore,
ColourDesired back) {
+ PLATFORM_ASSERT(context);
PenColour(back);
cairo_move_to(context, pts[0].x + 0.5, pts[0].y + 0.5);
for (int i = 1; i < npts; i++) {
@@ -718,6 +708,7 @@ void SurfaceImpl::FillRectangle(PRectangle rc, Surface &surfacePattern) {
SurfaceImpl &surfi = static_cast<SurfaceImpl &>(surfacePattern);
bool canDraw = surfi.psurf;
if (canDraw) {
+ PLATFORM_ASSERT(context);
// Tile pattern over rectangle
// Currently assumes 8x8 pattern
int widthPat = 8;
@@ -803,6 +794,7 @@ void SurfaceImpl::AlphaRectangle(PRectangle rc, int cornerSize, ColourDesired fi
}
void SurfaceImpl::DrawRGBAImage(PRectangle rc, int width, int height, const unsigned char *pixelsImage) {
+ PLATFORM_ASSERT(context);
if (rc.Width() > width)
rc.left += (rc.Width() - width) / 2;
rc.right = rc.left + width;
@@ -837,6 +829,7 @@ void SurfaceImpl::DrawRGBAImage(PRectangle rc, int width, int height, const unsi
}
void SurfaceImpl::Ellipse(PRectangle rc, ColourDesired fore, ColourDesired back) {
+ PLATFORM_ASSERT(context);
PenColour(back);
cairo_arc(context, (rc.left + rc.right) / 2, (rc.top + rc.bottom) / 2,
Platform::Minimum(rc.Width(), rc.Height()) / 2, 0, 2*kPi);
@@ -849,6 +842,7 @@ void SurfaceImpl::Copy(PRectangle rc, Point from, Surface &surfaceSource) {
SurfaceImpl &surfi = static_cast<SurfaceImpl &>(surfaceSource);
bool canDraw = surfi.psurf;
if (canDraw) {
+ PLATFORM_ASSERT(context);
cairo_set_source_surface(context, surfi.psurf,
rc.left - from.x, rc.top - from.y);
cairo_rectangle(context, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top);
@@ -1201,6 +1195,7 @@ XYPOSITION SurfaceImpl::AverageCharWidth(Font &font_) {
}
void SurfaceImpl::SetClip(PRectangle rc) {
+ PLATFORM_ASSERT(context);
cairo_rectangle(context, rc.left, rc.top, rc.right, rc.bottom);
cairo_clip(context);
}