2014-03-31 14:08:14 -04:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2013 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Author: Giovanni Campagna <gcampagn@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2015-03-10 02:41:12 -04:00
|
|
|
#include "meta-cursor.h"
|
2014-03-31 14:08:14 -04:00
|
|
|
|
2014-03-31 15:21:19 -04:00
|
|
|
#include <meta/errors.h>
|
|
|
|
|
|
|
|
#include "display-private.h"
|
|
|
|
#include "screen-private.h"
|
2014-08-05 08:11:59 -04:00
|
|
|
#include "meta-backend-private.h"
|
2014-05-29 12:11:26 -04:00
|
|
|
|
|
|
|
#ifdef HAVE_NATIVE_BACKEND
|
2015-03-10 02:41:12 -04:00
|
|
|
#include <gbm.h>
|
2014-04-22 15:15:11 -04:00
|
|
|
#include "backends/native/meta-cursor-renderer-native.h"
|
2014-05-29 12:11:26 -04:00
|
|
|
#endif
|
2014-03-31 15:21:19 -04:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <X11/cursorfont.h>
|
|
|
|
#include <X11/extensions/Xfixes.h>
|
|
|
|
#include <X11/Xcursor/Xcursor.h>
|
|
|
|
|
2014-08-13 20:19:35 -04:00
|
|
|
#ifdef HAVE_WAYLAND
|
2014-03-31 15:21:19 -04:00
|
|
|
#include <cogl/cogl-wayland-server.h>
|
2014-08-13 20:19:35 -04:00
|
|
|
#endif
|
2014-03-31 15:21:19 -04:00
|
|
|
|
2015-03-10 02:41:12 -04:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
CoglTexture2D *texture;
|
|
|
|
int hot_x, hot_y;
|
|
|
|
|
|
|
|
#ifdef HAVE_NATIVE_BACKEND
|
|
|
|
struct gbm_bo *bo;
|
|
|
|
#endif
|
|
|
|
} MetaCursorImage;
|
|
|
|
|
|
|
|
struct _MetaCursorSprite
|
|
|
|
{
|
|
|
|
GObject parent;
|
|
|
|
|
|
|
|
MetaCursor cursor;
|
|
|
|
MetaCursorImage image;
|
|
|
|
|
|
|
|
int current_frame;
|
|
|
|
XcursorImages *xcursor_images;
|
|
|
|
};
|
|
|
|
|
2015-03-10 02:35:49 -04:00
|
|
|
GType meta_cursor_sprite_get_type (void) G_GNUC_CONST;
|
2014-03-31 14:08:14 -04:00
|
|
|
|
2015-03-10 02:35:49 -04:00
|
|
|
G_DEFINE_TYPE (MetaCursorSprite, meta_cursor_sprite, G_TYPE_OBJECT)
|
2014-03-31 14:08:14 -04:00
|
|
|
|
2014-03-31 16:56:03 -04:00
|
|
|
static void
|
2014-03-31 17:01:14 -04:00
|
|
|
meta_cursor_image_free (MetaCursorImage *image)
|
2014-03-31 16:56:03 -04:00
|
|
|
{
|
2014-12-04 12:45:38 -05:00
|
|
|
if (image->texture)
|
|
|
|
cogl_object_unref (image->texture);
|
2014-10-15 13:35:53 -04:00
|
|
|
|
|
|
|
#ifdef HAVE_NATIVE_BACKEND
|
2014-03-31 17:01:14 -04:00
|
|
|
if (image->bo)
|
|
|
|
gbm_bo_destroy (image->bo);
|
2014-10-15 13:35:53 -04:00
|
|
|
#endif
|
2014-03-31 17:01:14 -04:00
|
|
|
}
|
2014-03-31 16:56:03 -04:00
|
|
|
|
2014-04-22 11:53:31 -04:00
|
|
|
static const char *
|
|
|
|
translate_meta_cursor (MetaCursor cursor)
|
2014-03-31 15:21:19 -04:00
|
|
|
{
|
|
|
|
switch (cursor)
|
|
|
|
{
|
|
|
|
case META_CURSOR_DEFAULT:
|
2014-04-22 11:53:31 -04:00
|
|
|
return "left_ptr";
|
2014-03-31 15:21:19 -04:00
|
|
|
case META_CURSOR_NORTH_RESIZE:
|
2014-04-22 11:53:31 -04:00
|
|
|
return "top_side";
|
2014-03-31 15:21:19 -04:00
|
|
|
case META_CURSOR_SOUTH_RESIZE:
|
2014-04-22 11:53:31 -04:00
|
|
|
return "bottom_side";
|
2014-03-31 15:21:19 -04:00
|
|
|
case META_CURSOR_WEST_RESIZE:
|
2014-04-22 11:53:31 -04:00
|
|
|
return "left_side";
|
2014-03-31 15:21:19 -04:00
|
|
|
case META_CURSOR_EAST_RESIZE:
|
2014-04-22 11:53:31 -04:00
|
|
|
return "right_side";
|
2014-03-31 15:21:19 -04:00
|
|
|
case META_CURSOR_SE_RESIZE:
|
2014-04-22 11:53:31 -04:00
|
|
|
return "bottom_right_corner";
|
2014-03-31 15:21:19 -04:00
|
|
|
case META_CURSOR_SW_RESIZE:
|
2014-04-22 11:53:31 -04:00
|
|
|
return "bottom_left_corner";
|
2014-03-31 15:21:19 -04:00
|
|
|
case META_CURSOR_NE_RESIZE:
|
2014-04-22 11:53:31 -04:00
|
|
|
return "top_right_corner";
|
2014-03-31 15:21:19 -04:00
|
|
|
case META_CURSOR_NW_RESIZE:
|
2014-04-22 11:53:31 -04:00
|
|
|
return "top_left_corner";
|
2014-03-31 15:21:19 -04:00
|
|
|
case META_CURSOR_MOVE_OR_RESIZE_WINDOW:
|
2014-04-22 11:53:31 -04:00
|
|
|
return "fleur";
|
2014-03-31 15:21:19 -04:00
|
|
|
case META_CURSOR_BUSY:
|
2014-04-22 11:53:31 -04:00
|
|
|
return "watch";
|
2014-03-31 15:21:19 -04:00
|
|
|
case META_CURSOR_DND_IN_DRAG:
|
2014-04-22 11:53:31 -04:00
|
|
|
return "dnd-none";
|
2014-03-31 15:21:19 -04:00
|
|
|
case META_CURSOR_DND_MOVE:
|
2014-04-22 11:53:31 -04:00
|
|
|
return "dnd-move";
|
2014-03-31 15:21:19 -04:00
|
|
|
case META_CURSOR_DND_COPY:
|
2014-04-22 11:53:31 -04:00
|
|
|
return "dnd-copy";
|
2014-03-31 15:21:19 -04:00
|
|
|
case META_CURSOR_DND_UNSUPPORTED_TARGET:
|
2014-04-22 11:53:31 -04:00
|
|
|
return "dnd-none";
|
2014-03-31 15:21:19 -04:00
|
|
|
case META_CURSOR_POINTING_HAND:
|
2014-04-22 11:53:31 -04:00
|
|
|
return "hand2";
|
2014-03-31 15:21:19 -04:00
|
|
|
case META_CURSOR_CROSSHAIR:
|
2014-04-22 11:53:31 -04:00
|
|
|
return "crosshair";
|
2014-03-31 15:21:19 -04:00
|
|
|
case META_CURSOR_IBEAM:
|
2014-04-22 11:53:31 -04:00
|
|
|
return "xterm";
|
2014-03-31 15:21:19 -04:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-04-22 11:53:31 -04:00
|
|
|
g_assert_not_reached ();
|
2014-03-31 15:21:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Cursor
|
2014-04-23 10:41:09 -04:00
|
|
|
meta_cursor_create_x_cursor (Display *xdisplay,
|
|
|
|
MetaCursor cursor)
|
2014-03-31 15:21:19 -04:00
|
|
|
{
|
2014-04-23 10:41:09 -04:00
|
|
|
return XcursorLibraryLoadCursor (xdisplay, translate_meta_cursor (cursor));
|
2014-03-31 15:21:19 -04:00
|
|
|
}
|
|
|
|
|
2015-07-13 14:32:42 -04:00
|
|
|
static XcursorImages *
|
2014-04-23 10:38:30 -04:00
|
|
|
load_cursor_on_client (MetaCursor cursor)
|
2014-03-31 15:21:19 -04:00
|
|
|
{
|
2015-07-13 14:32:42 -04:00
|
|
|
return XcursorLibraryLoadImages (translate_meta_cursor (cursor),
|
|
|
|
meta_prefs_get_cursor_theme (),
|
|
|
|
meta_prefs_get_cursor_size ());
|
2014-03-31 15:21:19 -04:00
|
|
|
}
|
|
|
|
|
2014-10-15 13:35:53 -04:00
|
|
|
#ifdef HAVE_NATIVE_BACKEND
|
2014-09-24 17:40:09 -04:00
|
|
|
static void
|
|
|
|
get_hardware_cursor_size (uint64_t *cursor_width, uint64_t *cursor_height)
|
|
|
|
{
|
|
|
|
MetaBackend *meta_backend = meta_get_backend ();
|
|
|
|
MetaCursorRenderer *renderer = meta_backend_get_cursor_renderer (meta_backend);
|
|
|
|
|
|
|
|
if (META_IS_CURSOR_RENDERER_NATIVE (renderer))
|
|
|
|
{
|
|
|
|
meta_cursor_renderer_native_get_cursor_size (META_CURSOR_RENDERER_NATIVE (renderer), cursor_width, cursor_height);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
2014-10-15 13:35:53 -04:00
|
|
|
#endif
|
2014-09-24 17:40:09 -04:00
|
|
|
|
2014-10-15 13:35:53 -04:00
|
|
|
#ifdef HAVE_NATIVE_BACKEND
|
2014-03-31 17:50:15 -04:00
|
|
|
static void
|
|
|
|
meta_cursor_image_load_gbm_buffer (struct gbm_device *gbm,
|
|
|
|
MetaCursorImage *image,
|
|
|
|
uint8_t *pixels,
|
2014-09-24 17:40:09 -04:00
|
|
|
uint width,
|
|
|
|
uint height,
|
2014-03-31 17:50:15 -04:00
|
|
|
int rowstride,
|
|
|
|
uint32_t gbm_format)
|
|
|
|
{
|
2014-09-24 17:40:09 -04:00
|
|
|
uint64_t cursor_width, cursor_height;
|
|
|
|
get_hardware_cursor_size (&cursor_width, &cursor_height);
|
|
|
|
|
|
|
|
if (width > cursor_width || height > cursor_height)
|
2014-03-31 17:50:15 -04:00
|
|
|
{
|
2014-09-24 17:40:09 -04:00
|
|
|
meta_warning ("Invalid theme cursor size (must be at most %ux%u)\n",
|
|
|
|
(unsigned int)cursor_width, (unsigned int)cursor_height);
|
2014-03-31 17:50:15 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gbm_device_is_format_supported (gbm, gbm_format,
|
2014-09-24 17:40:09 -04:00
|
|
|
GBM_BO_USE_CURSOR | GBM_BO_USE_WRITE))
|
2014-03-31 17:50:15 -04:00
|
|
|
{
|
2014-09-24 17:40:09 -04:00
|
|
|
uint8_t buf[4 * cursor_width * cursor_height];
|
|
|
|
uint i;
|
2014-03-31 17:50:15 -04:00
|
|
|
|
2014-09-24 17:40:09 -04:00
|
|
|
image->bo = gbm_bo_create (gbm, cursor_width, cursor_height,
|
|
|
|
gbm_format, GBM_BO_USE_CURSOR | GBM_BO_USE_WRITE);
|
2014-03-31 17:50:15 -04:00
|
|
|
|
|
|
|
memset (buf, 0, sizeof(buf));
|
|
|
|
for (i = 0; i < height; i++)
|
2014-09-24 17:40:09 -04:00
|
|
|
memcpy (buf + i * 4 * cursor_width, pixels + i * rowstride, width * 4);
|
2014-03-31 17:50:15 -04:00
|
|
|
|
2014-09-24 17:40:09 -04:00
|
|
|
gbm_bo_write (image->bo, buf, cursor_width * cursor_height * 4);
|
2014-03-31 17:50:15 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
meta_warning ("HW cursor for format %d not supported\n", gbm_format);
|
|
|
|
}
|
2014-10-15 13:35:53 -04:00
|
|
|
#endif
|
2014-03-31 17:50:15 -04:00
|
|
|
|
2014-10-15 13:35:53 -04:00
|
|
|
#ifdef HAVE_NATIVE_BACKEND
|
2014-04-22 15:23:45 -04:00
|
|
|
static struct gbm_device *
|
|
|
|
get_gbm_device (void)
|
|
|
|
{
|
|
|
|
MetaBackend *meta_backend = meta_get_backend ();
|
|
|
|
MetaCursorRenderer *renderer = meta_backend_get_cursor_renderer (meta_backend);
|
2014-04-22 15:15:11 -04:00
|
|
|
|
|
|
|
if (META_IS_CURSOR_RENDERER_NATIVE (renderer))
|
|
|
|
return meta_cursor_renderer_native_get_gbm_device (META_CURSOR_RENDERER_NATIVE (renderer));
|
2014-10-15 13:35:53 -04:00
|
|
|
else
|
|
|
|
return NULL;
|
2014-04-22 15:23:45 -04:00
|
|
|
}
|
2014-10-15 13:35:53 -04:00
|
|
|
#endif
|
2014-04-22 15:23:45 -04:00
|
|
|
|
2014-03-31 17:13:03 -04:00
|
|
|
static void
|
2014-04-23 10:38:30 -04:00
|
|
|
meta_cursor_image_load_from_xcursor_image (MetaCursorImage *image,
|
2014-03-31 17:13:03 -04:00
|
|
|
XcursorImage *xc_image)
|
2014-03-31 15:21:19 -04:00
|
|
|
{
|
2014-09-24 17:40:09 -04:00
|
|
|
uint width, height, rowstride;
|
2014-03-31 15:21:19 -04:00
|
|
|
CoglPixelFormat cogl_format;
|
|
|
|
ClutterBackend *clutter_backend;
|
|
|
|
CoglContext *cogl_context;
|
|
|
|
|
2014-03-31 17:13:03 -04:00
|
|
|
width = xc_image->width;
|
|
|
|
height = xc_image->height;
|
2014-03-31 15:21:19 -04:00
|
|
|
rowstride = width * 4;
|
|
|
|
|
|
|
|
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
|
|
|
cogl_format = COGL_PIXEL_FORMAT_BGRA_8888;
|
|
|
|
#else
|
|
|
|
cogl_format = COGL_PIXEL_FORMAT_ARGB_8888;
|
|
|
|
#endif
|
|
|
|
|
2014-03-31 17:13:03 -04:00
|
|
|
image->hot_x = xc_image->xhot;
|
|
|
|
image->hot_y = xc_image->yhot;
|
2014-03-31 15:21:19 -04:00
|
|
|
|
|
|
|
clutter_backend = clutter_get_default_backend ();
|
|
|
|
cogl_context = clutter_backend_get_cogl_context (clutter_backend);
|
2014-03-31 17:13:03 -04:00
|
|
|
image->texture = cogl_texture_2d_new_from_data (cogl_context,
|
|
|
|
width, height,
|
|
|
|
cogl_format,
|
|
|
|
rowstride,
|
2014-03-31 17:50:15 -04:00
|
|
|
(uint8_t *) xc_image->pixels,
|
2014-03-31 17:13:03 -04:00
|
|
|
NULL);
|
2014-03-31 15:21:19 -04:00
|
|
|
|
2014-10-15 13:35:53 -04:00
|
|
|
#ifdef HAVE_NATIVE_BACKEND
|
|
|
|
struct gbm_device *gbm = get_gbm_device ();
|
2014-04-21 18:23:15 -04:00
|
|
|
if (gbm)
|
|
|
|
meta_cursor_image_load_gbm_buffer (gbm,
|
2014-03-31 17:50:15 -04:00
|
|
|
image,
|
|
|
|
(uint8_t *) xc_image->pixels,
|
|
|
|
width, height, rowstride,
|
2014-10-15 13:35:53 -04:00
|
|
|
GBM_FORMAT_ARGB8888);
|
|
|
|
#endif
|
2014-03-31 16:09:32 -04:00
|
|
|
}
|
|
|
|
|
2015-07-13 14:32:42 -04:00
|
|
|
static XcursorImage *
|
2015-03-09 23:23:00 -04:00
|
|
|
meta_cursor_sprite_get_current_frame_image (MetaCursorSprite *self)
|
2015-07-13 14:32:42 -04:00
|
|
|
{
|
|
|
|
return self->xcursor_images->images[self->current_frame];
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-03-09 23:23:00 -04:00
|
|
|
meta_cursor_sprite_tick_frame (MetaCursorSprite *self)
|
2015-07-13 14:32:42 -04:00
|
|
|
{
|
|
|
|
XcursorImage *image;
|
|
|
|
|
2015-03-09 23:23:00 -04:00
|
|
|
if (!meta_cursor_sprite_is_animated (self))
|
2015-07-13 14:32:42 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
self->current_frame++;
|
|
|
|
|
|
|
|
if (self->current_frame >= self->xcursor_images->nimage)
|
|
|
|
self->current_frame = 0;
|
|
|
|
|
|
|
|
meta_cursor_image_free (&self->image);
|
2015-03-09 23:23:00 -04:00
|
|
|
image = meta_cursor_sprite_get_current_frame_image (self);
|
2015-07-13 14:32:42 -04:00
|
|
|
meta_cursor_image_load_from_xcursor_image (&self->image, image);
|
|
|
|
}
|
|
|
|
|
|
|
|
guint
|
2015-03-09 23:23:00 -04:00
|
|
|
meta_cursor_sprite_get_current_frame_time (MetaCursorSprite *self)
|
2015-07-13 14:32:42 -04:00
|
|
|
{
|
2015-03-09 23:23:00 -04:00
|
|
|
if (!meta_cursor_sprite_is_animated (self))
|
2015-07-13 14:32:42 -04:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
return self->xcursor_images->images[self->current_frame]->delay;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2015-03-09 23:23:00 -04:00
|
|
|
meta_cursor_sprite_is_animated (MetaCursorSprite *self)
|
2015-07-13 14:32:42 -04:00
|
|
|
{
|
|
|
|
return (self->xcursor_images &&
|
|
|
|
self->xcursor_images->nimage > 1);
|
|
|
|
}
|
|
|
|
|
2014-11-27 17:34:25 -05:00
|
|
|
static void
|
2015-03-09 23:23:00 -04:00
|
|
|
load_cursor_image (MetaCursorSprite *self)
|
2014-03-31 16:09:32 -04:00
|
|
|
{
|
|
|
|
XcursorImage *image;
|
2014-03-31 15:21:19 -04:00
|
|
|
|
2014-11-27 17:34:25 -05:00
|
|
|
/* Either cursors are loaded from X cursors or buffers. Since
|
|
|
|
* buffers are converted over immediately, we can make sure to
|
|
|
|
* load this directly. */
|
2015-03-09 23:23:00 -04:00
|
|
|
g_assert (self->cursor != META_CURSOR_NONE);
|
2014-11-27 17:34:25 -05:00
|
|
|
|
2015-03-09 23:23:00 -04:00
|
|
|
if (!self->xcursor_images)
|
2015-07-13 14:32:42 -04:00
|
|
|
{
|
2015-03-09 23:23:00 -04:00
|
|
|
self->current_frame = 0;
|
|
|
|
self->xcursor_images = load_cursor_on_client (self->cursor);
|
|
|
|
if (!self->xcursor_images)
|
2015-08-18 16:58:58 -04:00
|
|
|
meta_fatal ("Could not find cursor. Perhaps set XCURSOR_PATH?");
|
2015-07-13 14:32:42 -04:00
|
|
|
}
|
2014-03-31 16:09:32 -04:00
|
|
|
|
2015-03-09 23:23:00 -04:00
|
|
|
image = meta_cursor_sprite_get_current_frame_image (self);
|
|
|
|
meta_cursor_image_load_from_xcursor_image (&self->image, image);
|
2014-11-27 17:34:25 -05:00
|
|
|
}
|
|
|
|
|
2015-03-09 23:23:00 -04:00
|
|
|
MetaCursorSprite *
|
|
|
|
meta_cursor_sprite_from_theme (MetaCursor cursor)
|
2014-11-27 17:34:25 -05:00
|
|
|
{
|
2015-03-10 02:35:49 -04:00
|
|
|
MetaCursorSprite *self;
|
|
|
|
|
|
|
|
self = g_object_new (META_TYPE_CURSOR_SPRITE, NULL);
|
|
|
|
|
2014-04-23 11:04:08 -04:00
|
|
|
self->cursor = cursor;
|
2015-03-10 02:35:49 -04:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
MetaCursorSprite *
|
|
|
|
meta_cursor_sprite_from_texture (CoglTexture2D *texture,
|
|
|
|
int hot_x,
|
|
|
|
int hot_y)
|
|
|
|
{
|
|
|
|
MetaCursorSprite *self;
|
|
|
|
|
|
|
|
self = g_object_new (META_TYPE_CURSOR_SPRITE, NULL);
|
|
|
|
|
|
|
|
cogl_object_ref (texture);
|
|
|
|
|
|
|
|
self->image.texture = texture;
|
|
|
|
self->image.hot_x = hot_x;
|
|
|
|
self->image.hot_y = hot_y;
|
|
|
|
|
2014-03-31 15:21:19 -04:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2014-08-13 20:19:35 -04:00
|
|
|
#ifdef HAVE_WAYLAND
|
2014-03-31 17:13:03 -04:00
|
|
|
static void
|
2014-04-22 15:23:45 -04:00
|
|
|
meta_cursor_image_load_from_buffer (MetaCursorImage *image,
|
2014-03-31 17:13:03 -04:00
|
|
|
struct wl_resource *buffer,
|
|
|
|
int hot_x,
|
|
|
|
int hot_y)
|
2014-03-31 15:21:19 -04:00
|
|
|
{
|
|
|
|
ClutterBackend *backend;
|
|
|
|
CoglContext *cogl_context;
|
|
|
|
|
2014-03-31 17:13:03 -04:00
|
|
|
image->hot_x = hot_x;
|
|
|
|
image->hot_y = hot_y;
|
2014-03-31 15:21:19 -04:00
|
|
|
|
|
|
|
backend = clutter_get_default_backend ();
|
|
|
|
cogl_context = clutter_backend_get_cogl_context (backend);
|
|
|
|
|
2014-03-31 17:48:51 -04:00
|
|
|
image->texture = cogl_wayland_texture_2d_new_from_buffer (cogl_context, buffer, NULL);
|
|
|
|
|
2014-10-15 13:35:53 -04:00
|
|
|
#ifdef HAVE_NATIVE_BACKEND
|
|
|
|
struct gbm_device *gbm = get_gbm_device ();
|
2014-10-15 13:36:42 -04:00
|
|
|
if (gbm)
|
2014-03-31 15:21:19 -04:00
|
|
|
{
|
2014-10-15 13:35:53 -04:00
|
|
|
uint32_t gbm_format;
|
|
|
|
uint64_t cursor_width, cursor_height;
|
|
|
|
uint width, height;
|
|
|
|
|
|
|
|
width = cogl_texture_get_width (COGL_TEXTURE (image->texture));
|
|
|
|
height = cogl_texture_get_height (COGL_TEXTURE (image->texture));
|
|
|
|
|
2014-10-15 13:36:42 -04:00
|
|
|
struct wl_shm_buffer *shm_buffer = wl_shm_buffer_get (buffer);
|
|
|
|
if (shm_buffer)
|
2014-03-31 15:21:19 -04:00
|
|
|
{
|
2014-03-31 17:59:14 -04:00
|
|
|
int rowstride = wl_shm_buffer_get_stride (shm_buffer);
|
|
|
|
|
2015-01-09 10:09:23 -05:00
|
|
|
wl_shm_buffer_begin_access (shm_buffer);
|
|
|
|
|
2014-03-31 17:59:14 -04:00
|
|
|
switch (wl_shm_buffer_get_format (shm_buffer))
|
|
|
|
{
|
2014-03-31 15:21:19 -04:00
|
|
|
#if G_BYTE_ORDER == G_BIG_ENDIAN
|
2014-03-31 17:59:14 -04:00
|
|
|
case WL_SHM_FORMAT_ARGB8888:
|
|
|
|
gbm_format = GBM_FORMAT_ARGB8888;
|
|
|
|
break;
|
|
|
|
case WL_SHM_FORMAT_XRGB8888:
|
|
|
|
gbm_format = GBM_FORMAT_XRGB8888;
|
|
|
|
break;
|
2014-03-31 15:21:19 -04:00
|
|
|
#else
|
2014-03-31 17:59:14 -04:00
|
|
|
case WL_SHM_FORMAT_ARGB8888:
|
|
|
|
gbm_format = GBM_FORMAT_ARGB8888;
|
|
|
|
break;
|
|
|
|
case WL_SHM_FORMAT_XRGB8888:
|
|
|
|
gbm_format = GBM_FORMAT_XRGB8888;
|
|
|
|
break;
|
2014-03-31 15:21:19 -04:00
|
|
|
#endif
|
2014-03-31 17:59:14 -04:00
|
|
|
default:
|
|
|
|
g_warn_if_reached ();
|
|
|
|
gbm_format = GBM_FORMAT_ARGB8888;
|
|
|
|
}
|
|
|
|
|
2014-04-21 18:23:15 -04:00
|
|
|
meta_cursor_image_load_gbm_buffer (gbm,
|
2014-03-31 17:59:14 -04:00
|
|
|
image,
|
|
|
|
(uint8_t *) wl_shm_buffer_get_data (shm_buffer),
|
|
|
|
width, height, rowstride,
|
|
|
|
gbm_format);
|
2015-01-09 10:09:23 -05:00
|
|
|
|
|
|
|
wl_shm_buffer_end_access (shm_buffer);
|
2014-03-31 15:21:19 -04:00
|
|
|
}
|
2014-10-15 13:36:42 -04:00
|
|
|
else
|
2014-03-31 15:21:19 -04:00
|
|
|
{
|
2014-09-24 17:40:09 -04:00
|
|
|
/* HW cursors have a predefined size (at least 64x64), which usually is bigger than cursor theme
|
|
|
|
size, so themed cursors must be padded with transparent pixels to fill the
|
|
|
|
overlay. This is trivial if we have CPU access to the data, but it's not
|
|
|
|
possible if the buffer is in GPU memory (and possibly tiled too), so if we
|
|
|
|
don't get the right size, we fallback to GL.
|
|
|
|
*/
|
|
|
|
get_hardware_cursor_size (&cursor_width, &cursor_height);
|
|
|
|
|
|
|
|
if (width != cursor_width || height != cursor_height)
|
|
|
|
{
|
|
|
|
meta_warning ("Invalid cursor size (must be 64x64), falling back to software (GL) cursors\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
image->bo = gbm_bo_import (gbm, GBM_BO_IMPORT_WL_BUFFER, buffer, GBM_BO_USE_CURSOR);
|
2014-03-31 17:13:03 -04:00
|
|
|
if (!image->bo)
|
2014-03-31 15:21:19 -04:00
|
|
|
meta_warning ("Importing HW cursor from wl_buffer failed\n");
|
|
|
|
}
|
2014-03-31 17:13:38 -04:00
|
|
|
}
|
2014-10-15 13:35:53 -04:00
|
|
|
#endif
|
2014-03-31 17:13:03 -04:00
|
|
|
}
|
|
|
|
|
2015-03-09 23:23:00 -04:00
|
|
|
MetaCursorSprite *
|
|
|
|
meta_cursor_sprite_from_buffer (struct wl_resource *buffer,
|
|
|
|
int hot_x,
|
|
|
|
int hot_y)
|
2014-03-31 17:13:03 -04:00
|
|
|
{
|
2015-03-09 23:23:00 -04:00
|
|
|
MetaCursorSprite *self;
|
2014-03-31 17:13:03 -04:00
|
|
|
|
2015-03-10 02:35:49 -04:00
|
|
|
self = g_object_new (META_TYPE_CURSOR_SPRITE, NULL);
|
|
|
|
|
2014-04-22 15:23:45 -04:00
|
|
|
meta_cursor_image_load_from_buffer (&self->image, buffer, hot_x, hot_y);
|
2014-03-31 15:21:19 -04:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
2014-08-13 20:19:35 -04:00
|
|
|
#endif
|
2014-03-31 15:31:15 -04:00
|
|
|
|
|
|
|
CoglTexture *
|
2015-03-09 23:23:00 -04:00
|
|
|
meta_cursor_sprite_get_cogl_texture (MetaCursorSprite *self,
|
|
|
|
int *hot_x,
|
|
|
|
int *hot_y)
|
2014-03-31 15:31:15 -04:00
|
|
|
{
|
2015-03-09 23:23:00 -04:00
|
|
|
if (!self->image.texture)
|
|
|
|
load_cursor_image (self);
|
2014-11-27 17:34:25 -05:00
|
|
|
|
2014-03-31 15:31:15 -04:00
|
|
|
if (hot_x)
|
2015-03-09 23:23:00 -04:00
|
|
|
*hot_x = self->image.hot_x;
|
2014-03-31 15:31:15 -04:00
|
|
|
if (hot_y)
|
2015-03-09 23:23:00 -04:00
|
|
|
*hot_y = self->image.hot_y;
|
2014-11-27 17:34:25 -05:00
|
|
|
|
2015-03-09 23:23:00 -04:00
|
|
|
return COGL_TEXTURE (self->image.texture);
|
2014-03-31 15:31:15 -04:00
|
|
|
}
|
|
|
|
|
2014-10-15 13:35:53 -04:00
|
|
|
#ifdef HAVE_NATIVE_BACKEND
|
2014-03-31 15:31:15 -04:00
|
|
|
struct gbm_bo *
|
2015-03-09 23:23:00 -04:00
|
|
|
meta_cursor_sprite_get_gbm_bo (MetaCursorSprite *self,
|
|
|
|
int *hot_x,
|
|
|
|
int *hot_y)
|
2014-03-31 15:31:15 -04:00
|
|
|
{
|
2015-03-09 23:23:00 -04:00
|
|
|
if (!self->image.bo)
|
|
|
|
load_cursor_image (self);
|
2014-11-27 17:34:25 -05:00
|
|
|
|
2014-03-31 15:31:15 -04:00
|
|
|
if (hot_x)
|
2015-03-09 23:23:00 -04:00
|
|
|
*hot_x = self->image.hot_x;
|
2014-03-31 15:31:15 -04:00
|
|
|
if (hot_y)
|
2015-03-09 23:23:00 -04:00
|
|
|
*hot_y = self->image.hot_y;
|
|
|
|
return self->image.bo;
|
2014-03-31 15:31:15 -04:00
|
|
|
}
|
2014-10-15 13:35:53 -04:00
|
|
|
#endif
|
2014-04-23 11:04:08 -04:00
|
|
|
|
|
|
|
MetaCursor
|
2015-03-09 23:23:00 -04:00
|
|
|
meta_cursor_sprite_get_meta_cursor (MetaCursorSprite *self)
|
2014-04-23 11:04:08 -04:00
|
|
|
{
|
2015-03-09 23:23:00 -04:00
|
|
|
return self->cursor;
|
2014-04-23 11:04:08 -04:00
|
|
|
}
|
2015-03-10 02:35:49 -04:00
|
|
|
|
|
|
|
static void
|
|
|
|
meta_cursor_sprite_init (MetaCursorSprite *self)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_cursor_sprite_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
MetaCursorSprite *self = META_CURSOR_SPRITE (object);
|
|
|
|
|
|
|
|
if (self->xcursor_images)
|
|
|
|
XcursorImagesDestroy (self->xcursor_images);
|
|
|
|
meta_cursor_image_free (&self->image);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (meta_cursor_sprite_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_cursor_sprite_class_init (MetaCursorSpriteClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->finalize = meta_cursor_sprite_finalize;
|
|
|
|
}
|