diff options
author | Caolán McNamara <caolanm@redhat.com> | 2021-06-17 10:27:12 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2021-06-17 14:58:26 +0200 |
commit | 5383f219253eb5d7c0eeee2570187e4369987d23 (patch) | |
tree | f972829bb048760cbe55dd31bd5587023fc00ff9 /vcl | |
parent | 2a38a064dfcb56cd887dc672b4d3bd260570ef13 (diff) |
split SurfacePaintable out
Change-Id: I07d2109080f19fb7cf95bc439e5d99ba3247c2bc
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117371
Tested-by: Caolán McNamara <caolanm@redhat.com>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/Library_vclplug_gtk4.mk | 1 | ||||
-rw-r--r-- | vcl/unx/gtk3/gtkinst.cxx | 83 | ||||
-rw-r--r-- | vcl/unx/gtk4/gtkinst.cxx | 1 | ||||
-rw-r--r-- | vcl/unx/gtk4/surfacepaintable.cxx | 93 | ||||
-rw-r--r-- | vcl/unx/gtk4/surfacepaintable.hxx | 32 |
5 files changed, 128 insertions, 82 deletions
diff --git a/vcl/Library_vclplug_gtk4.mk b/vcl/Library_vclplug_gtk4.mk index 93f8d8c90673..98349413a1d3 100644 --- a/vcl/Library_vclplug_gtk4.mk +++ b/vcl/Library_vclplug_gtk4.mk @@ -97,6 +97,7 @@ $(eval $(call gb_Library_add_exception_objects,vclplug_gtk4,\ vcl/unx/gtk4/gloactiongroup \ vcl/unx/gtk4/hudawareness \ vcl/unx/gtk4/notifyinglayout \ + vcl/unx/gtk4/surfacepaintable \ )) ifeq ($(OS),LINUX) diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx index 3aec591a6a7a..b7c315e84abd 100644 --- a/vcl/unx/gtk3/gtkinst.cxx +++ b/vcl/unx/gtk3/gtkinst.cxx @@ -4468,85 +4468,6 @@ namespace } } -#if GTK_CHECK_VERSION(4, 0, 0) - -G_BEGIN_DECLS - -G_DECLARE_FINAL_TYPE(SurfacePaintable, surface_paintable, SURFACE, PAINTABLE, GObject) - -struct _SurfacePaintable -{ - GObject parent_instance; - int width; - int height; - cairo_surface_t* surface; -}; - -struct _SurfacePaintableClass -{ - GObjectClass parent_class; -}; - -static void surface_paintable_snapshot(GdkPaintable *paintable, GdkSnapshot *snapshot, - double width, double height) -{ - graphene_rect_t rect = GRAPHENE_RECT_INIT(0.0f, 0.0f, - static_cast<float>(width), - static_cast<float>(height)); - SurfacePaintable *self = SURFACE_PAINTABLE(paintable); - cairo_t* cr = gtk_snapshot_append_cairo(GTK_SNAPSHOT(snapshot), &rect); - cairo_set_source_surface(cr, self->surface, 0, 0); - cairo_paint(cr); - cairo_destroy(cr); -} - -static int surface_paintable_get_intrinsic_width(GdkPaintable *paintable) -{ - SurfacePaintable *self = SURFACE_PAINTABLE(paintable); - return self->width; -} - -static int surface_paintable_get_intrinsic_height(GdkPaintable *paintable) -{ - SurfacePaintable *self = SURFACE_PAINTABLE(paintable); - return self->height; -} - -static void surface_paintable_init_interface(GdkPaintableInterface *iface) -{ - iface->snapshot = surface_paintable_snapshot; - iface->get_intrinsic_width = surface_paintable_get_intrinsic_width; - iface->get_intrinsic_height = surface_paintable_get_intrinsic_height; -} - -G_DEFINE_TYPE_WITH_CODE(SurfacePaintable, surface_paintable, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE(GDK_TYPE_PAINTABLE, - surface_paintable_init_interface)); - -static void surface_paintable_init(SurfacePaintable *self) -{ - self->width = 0; - self->height = 0; - self->surface = nullptr; -} - -static void surface_paintable_dispose(GObject *object) -{ - SurfacePaintable* self = SURFACE_PAINTABLE(object); - cairo_surface_destroy(self->surface); - G_OBJECT_CLASS(surface_paintable_parent_class)->dispose(object); -} - -static void surface_paintable_class_init(SurfacePaintableClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS(klass); - object_class->dispose = surface_paintable_dispose; -} - -G_END_DECLS - -#endif - namespace { #if GTK_CHECK_VERSION(4, 0, 0) @@ -4565,9 +4486,7 @@ namespace cairo_destroy(cr); SurfacePaintable* pPaintable = SURFACE_PAINTABLE(g_object_new(surface_paintable_get_type(), nullptr)); - pPaintable->surface = target; - pPaintable->width = aSize.Width(); - pPaintable->height = aSize.Height(); + surface_paintable_set_source(pPaintable, target, aSize.Width(), aSize.Height()); return pPaintable; } diff --git a/vcl/unx/gtk4/gtkinst.cxx b/vcl/unx/gtk4/gtkinst.cxx index 4dc435a2bbf4..2bc0bc1c5e0a 100644 --- a/vcl/unx/gtk4/gtkinst.cxx +++ b/vcl/unx/gtk4/gtkinst.cxx @@ -12,6 +12,7 @@ #include "convert3to4.hxx" #include "notifyinglayout.hxx" +#include "surfacepaintable.hxx" #include "../gtk3/gtkinst.cxx" diff --git a/vcl/unx/gtk4/surfacepaintable.cxx b/vcl/unx/gtk4/surfacepaintable.cxx new file mode 100644 index 000000000000..052b2fbacdef --- /dev/null +++ b/vcl/unx/gtk4/surfacepaintable.cxx @@ -0,0 +1,93 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "surfacepaintable.hxx" + +struct _SurfacePaintable +{ + GObject parent_instance; + int width; + int height; + cairo_surface_t* surface; +}; + +namespace +{ +struct _SurfacePaintableClass : public GObjectClass +{ +}; +} + +static void surface_paintable_snapshot(GdkPaintable* paintable, GdkSnapshot* snapshot, double width, + double height) +{ + graphene_rect_t rect + = GRAPHENE_RECT_INIT(0.0f, 0.0f, static_cast<float>(width), static_cast<float>(height)); + SurfacePaintable* self = SURFACE_PAINTABLE(paintable); + cairo_t* cr = gtk_snapshot_append_cairo(GTK_SNAPSHOT(snapshot), &rect); + cairo_set_source_surface(cr, self->surface, 0, 0); + cairo_paint(cr); + cairo_destroy(cr); +} + +static int surface_paintable_get_intrinsic_width(GdkPaintable* paintable) +{ + SurfacePaintable* self = SURFACE_PAINTABLE(paintable); + return self->width; +} + +static int surface_paintable_get_intrinsic_height(GdkPaintable* paintable) +{ + SurfacePaintable* self = SURFACE_PAINTABLE(paintable); + return self->height; +} + +static void surface_paintable_init_interface(GdkPaintableInterface* iface) +{ + iface->snapshot = surface_paintable_snapshot; + iface->get_intrinsic_width = surface_paintable_get_intrinsic_width; + iface->get_intrinsic_height = surface_paintable_get_intrinsic_height; +} + +G_DEFINE_TYPE_WITH_CODE(SurfacePaintable, surface_paintable, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE(GDK_TYPE_PAINTABLE, + surface_paintable_init_interface)); + +static void surface_paintable_init(SurfacePaintable* self) +{ + self->width = 0; + self->height = 0; + self->surface = nullptr; + + // prevent loplugin:unreffun firing on macro generated function + (void)surface_paintable_get_instance_private(self); +} + +static void surface_paintable_dispose(GObject* object) +{ + SurfacePaintable* self = SURFACE_PAINTABLE(object); + cairo_surface_destroy(self->surface); + G_OBJECT_CLASS(surface_paintable_parent_class)->dispose(object); +} + +static void surface_paintable_class_init(SurfacePaintableClass* klass) +{ + GObjectClass* object_class = G_OBJECT_CLASS(klass); + object_class->dispose = surface_paintable_dispose; +} + +void surface_paintable_set_source(SurfacePaintable* pPaintable, cairo_surface_t* pSource, + int nWidth, int nHeight) +{ + pPaintable->surface = pSource; + pPaintable->width = nWidth; + pPaintable->height = nHeight; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/unx/gtk4/surfacepaintable.hxx b/vcl/unx/gtk4/surfacepaintable.hxx new file mode 100644 index 000000000000..3e8c79f8ac1a --- /dev/null +++ b/vcl/unx/gtk4/surfacepaintable.hxx @@ -0,0 +1,32 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include <gtk/gtk.h> +#include <cairo.h> + +G_BEGIN_DECLS + +/* + Provide a mechanism to allow continuing to use cairo surface where a GdkPaintable + is required +*/ + +G_DECLARE_FINAL_TYPE(SurfacePaintable, surface_paintable, SURFACE, PAINTABLE, GObject) + +/* + Set the surface to paint, takes ownership of pSource +*/ +void surface_paintable_set_source(SurfacePaintable* pPaintable, cairo_surface_t* pSource, + int nWidth, int nHeight); + +G_END_DECLS + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |