2016-05-07 11:07:46 -04:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
|
|
|
/*
|
2016-05-09 07:51:29 -04:00
|
|
|
* Copyright (C) 2011 Intel Corporation.
|
2016-05-07 11:07:46 -04:00
|
|
|
* Copyright (C) 2016 Red Hat
|
2018-11-29 06:34:40 -05:00
|
|
|
* Copyright (c) 2018,2019 DisplayLink (UK) Ltd.
|
2016-05-07 11:07:46 -04:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
* obtaining a copy of this software and associated documentation
|
|
|
|
* files (the "Software"), to deal in the Software without
|
|
|
|
* restriction, including without limitation the rights to use, copy,
|
|
|
|
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
|
|
* of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*
|
2016-05-09 07:51:29 -04:00
|
|
|
* Authors:
|
|
|
|
* Rob Bradford <rob@linux.intel.com> (from cogl-winsys-egl-kms.c)
|
|
|
|
* Kristian Høgsberg (from eglkms.c)
|
|
|
|
* Benjamin Franzke (from eglkms.c)
|
|
|
|
* Robert Bragg <robert@linux.intel.com> (from cogl-winsys-egl-kms.c)
|
|
|
|
* Neil Roberts <neil@linux.intel.com> (from cogl-winsys-egl-kms.c)
|
|
|
|
* Jonas Ådahl <jadahl@redhat.com>
|
|
|
|
*
|
2016-05-07 11:07:46 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2018-07-10 04:36:24 -04:00
|
|
|
#include <drm_fourcc.h>
|
2016-05-09 07:51:29 -04:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <gbm.h>
|
2016-05-09 09:22:01 -04:00
|
|
|
#include <gio/gio.h>
|
|
|
|
#include <glib-object.h>
|
2016-05-09 07:51:29 -04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2016-08-17 23:28:59 -04:00
|
|
|
#include <sys/mman.h>
|
2016-05-09 07:51:29 -04:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <xf86drm.h>
|
2016-05-07 11:07:46 -04:00
|
|
|
|
2016-05-09 07:51:29 -04:00
|
|
|
#include "backends/meta-backend-private.h"
|
2017-03-28 00:35:19 -04:00
|
|
|
#include "backends/meta-crtc.h"
|
2016-08-17 23:28:59 -04:00
|
|
|
#include "backends/meta-egl-ext.h"
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "backends/meta-egl.h"
|
|
|
|
#include "backends/meta-gles3.h"
|
2016-12-12 21:37:11 -05:00
|
|
|
#include "backends/meta-logical-monitor.h"
|
2017-03-24 05:35:51 -04:00
|
|
|
#include "backends/meta-output.h"
|
2016-06-08 05:05:31 -04:00
|
|
|
#include "backends/meta-renderer-view.h"
|
2017-08-03 10:42:50 -04:00
|
|
|
#include "backends/native/meta-crtc-kms.h"
|
2019-05-20 16:08:35 -04:00
|
|
|
#include "backends/native/meta-drm-buffer-dumb.h"
|
|
|
|
#include "backends/native/meta-drm-buffer-gbm.h"
|
2019-05-24 10:07:14 -04:00
|
|
|
#include "backends/native/meta-drm-buffer-import.h"
|
2019-05-20 15:20:17 -04:00
|
|
|
#include "backends/native/meta-drm-buffer.h"
|
2017-07-10 06:19:32 -04:00
|
|
|
#include "backends/native/meta-gpu-kms.h"
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
#include "backends/native/meta-kms-update.h"
|
2019-03-11 06:13:01 -04:00
|
|
|
#include "backends/native/meta-kms-utils.h"
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
#include "backends/native/meta-kms.h"
|
|
|
|
#include "backends/native/meta-output-kms.h"
|
2017-07-24 22:21:04 -04:00
|
|
|
#include "backends/native/meta-renderer-native-gles3.h"
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "backends/native/meta-renderer-native.h"
|
2016-05-07 11:09:59 -04:00
|
|
|
#include "cogl/cogl.h"
|
2018-11-29 06:34:40 -05:00
|
|
|
#include "cogl/cogl-framebuffer.h"
|
2019-06-11 04:16:39 -04:00
|
|
|
#include "cogl/cogl-trace.h"
|
2016-06-08 05:05:31 -04:00
|
|
|
#include "core/boxes-private.h"
|
2016-05-07 11:09:59 -04:00
|
|
|
|
2016-08-17 23:28:59 -04:00
|
|
|
#ifndef EGL_DRM_MASTER_FD_EXT
|
|
|
|
#define EGL_DRM_MASTER_FD_EXT 0x333C
|
|
|
|
#endif
|
|
|
|
|
2018-11-21 08:25:07 -05:00
|
|
|
/* added in libdrm 2.4.95 */
|
|
|
|
#ifndef DRM_FORMAT_INVALID
|
|
|
|
#define DRM_FORMAT_INVALID 0
|
|
|
|
#endif
|
|
|
|
|
2017-07-24 22:21:04 -04:00
|
|
|
typedef enum _MetaSharedFramebufferCopyMode
|
|
|
|
{
|
2019-05-24 10:07:14 -04:00
|
|
|
/* Zero-copy: primary GPU exports, secondary GPU imports as KMS FB */
|
|
|
|
META_SHARED_FRAMEBUFFER_COPY_MODE_ZERO,
|
2018-11-29 06:34:40 -05:00
|
|
|
/* the secondary GPU will make the copy */
|
|
|
|
META_SHARED_FRAMEBUFFER_COPY_MODE_SECONDARY_GPU,
|
|
|
|
/*
|
|
|
|
* The copy is made in the primary GPU rendering context, either
|
|
|
|
* as a CPU copy through Cogl read-pixels or as primary GPU copy
|
|
|
|
* using glBlitFramebuffer.
|
|
|
|
*/
|
|
|
|
META_SHARED_FRAMEBUFFER_COPY_MODE_PRIMARY
|
2017-07-24 22:21:04 -04:00
|
|
|
} MetaSharedFramebufferCopyMode;
|
|
|
|
|
2017-07-10 06:19:32 -04:00
|
|
|
typedef struct _MetaRendererNativeGpuData
|
|
|
|
{
|
|
|
|
MetaRendererNative *renderer_native;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
struct gbm_device *device;
|
|
|
|
} gbm;
|
|
|
|
|
|
|
|
#ifdef HAVE_EGL_DEVICE
|
|
|
|
struct {
|
|
|
|
EGLDeviceEXT device;
|
|
|
|
} egl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
MetaRendererNativeMode mode;
|
|
|
|
|
2017-07-24 22:21:04 -04:00
|
|
|
EGLDisplay egl_display;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fields used for blitting iGPU framebuffer content onto dGPU framebuffers.
|
|
|
|
*/
|
|
|
|
struct {
|
|
|
|
MetaSharedFramebufferCopyMode copy_mode;
|
renderer/native: Prefer hardware rendering for primary GPU
Mutter prefers platform devices over anything else as the primary GPU.
This will not work too well, when a platform device does not actually
have a rendering GPU but is a display-only device. An example of this
are DisplayLink devices with the proprietary driver stack, which exposes
a DRM KMS platform device but without any rendering driver.
Mutter cannot rely on EGL init failing on such devices either, because
nowadays Mesa supports software renderers on GBM, so the initialization
may well succeed.
The hardware rendering capability is recognized by matching the GL
renderer string to the known Mesa software renderers. At this time,
there is no better alternative to detecting this.
The secondary GPU data is abused for the GL renderer, as the Cogl
context may not have been created yet. Also, the Cogl context would
only be created on the primary GPU, but at this point the primary GPU
has not been chosen yet. Hence, GPU copy path GL context is used as a
proxy and predictor of what the Cogl context might be if it was created.
Mind, that even the GL flavour are not the same between Cogl and
secondary contexts, so this is stretch but it should be just enough.
The logic to choose the primary GPU is changed to always prefer hardware
rendering devices while also maintaining the old order of preferring
platform over boot_vga devices.
Co-authored by: Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>
https://gitlab.gnome.org/GNOME/mutter/merge_requests/271
2018-12-10 09:49:58 -05:00
|
|
|
gboolean is_hardware_rendering;
|
2018-11-29 06:34:40 -05:00
|
|
|
gboolean has_EGL_EXT_image_dma_buf_import_modifiers;
|
2017-07-24 22:21:04 -04:00
|
|
|
|
|
|
|
/* For GPU blit mode */
|
|
|
|
EGLContext egl_context;
|
|
|
|
EGLConfig egl_config;
|
|
|
|
} secondary;
|
2017-07-10 06:19:32 -04:00
|
|
|
} MetaRendererNativeGpuData;
|
|
|
|
|
2017-07-24 03:38:46 -04:00
|
|
|
typedef struct _MetaDumbBuffer
|
|
|
|
{
|
|
|
|
uint32_t fb_id;
|
|
|
|
uint32_t handle;
|
|
|
|
void *map;
|
|
|
|
uint64_t map_size;
|
2018-09-05 04:48:08 -04:00
|
|
|
int width;
|
|
|
|
int height;
|
2018-09-05 05:07:59 -04:00
|
|
|
int stride_bytes;
|
2018-11-09 07:22:18 -05:00
|
|
|
uint32_t drm_format;
|
2018-11-29 06:37:16 -05:00
|
|
|
int dmabuf_fd;
|
2017-07-24 03:38:46 -04:00
|
|
|
} MetaDumbBuffer;
|
|
|
|
|
2019-05-24 10:07:14 -04:00
|
|
|
typedef enum _MetaSharedFramebufferImportStatus
|
|
|
|
{
|
|
|
|
/* Not tried importing yet. */
|
|
|
|
META_SHARED_FRAMEBUFFER_IMPORT_STATUS_NONE,
|
|
|
|
/* Tried before and failed. */
|
|
|
|
META_SHARED_FRAMEBUFFER_IMPORT_STATUS_FAILED,
|
|
|
|
/* Tried before and succeeded. */
|
|
|
|
META_SHARED_FRAMEBUFFER_IMPORT_STATUS_OK
|
|
|
|
} MetaSharedFramebufferImportStatus;
|
|
|
|
|
2017-07-24 22:21:04 -04:00
|
|
|
typedef struct _MetaOnscreenNativeSecondaryGpuState
|
2016-05-27 03:07:41 -04:00
|
|
|
{
|
2017-07-10 06:19:32 -04:00
|
|
|
MetaGpuKms *gpu_kms;
|
2017-07-24 22:21:04 -04:00
|
|
|
MetaRendererNativeGpuData *renderer_gpu_data;
|
|
|
|
|
|
|
|
EGLSurface egl_surface;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
struct gbm_surface *surface;
|
2019-05-20 15:20:17 -04:00
|
|
|
MetaDrmBuffer *current_fb;
|
|
|
|
MetaDrmBuffer *next_fb;
|
2017-07-24 22:21:04 -04:00
|
|
|
} gbm;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
MetaDumbBuffer *dumb_fb;
|
|
|
|
MetaDumbBuffer dumb_fbs[2];
|
|
|
|
} cpu;
|
|
|
|
|
|
|
|
int pending_flips;
|
2019-07-05 07:09:31 -04:00
|
|
|
|
|
|
|
gboolean noted_primary_gpu_copy_ok;
|
|
|
|
gboolean noted_primary_gpu_copy_failed;
|
2019-05-24 10:07:14 -04:00
|
|
|
MetaSharedFramebufferImportStatus import_status;
|
2017-07-24 22:21:04 -04:00
|
|
|
} MetaOnscreenNativeSecondaryGpuState;
|
|
|
|
|
|
|
|
typedef struct _MetaOnscreenNative
|
|
|
|
{
|
|
|
|
MetaRendererNative *renderer_native;
|
|
|
|
MetaGpuKms *render_gpu;
|
2020-01-17 15:08:02 -05:00
|
|
|
MetaOutput *output;
|
|
|
|
MetaCrtc *crtc;
|
2017-07-24 22:21:04 -04:00
|
|
|
|
2020-01-17 15:08:02 -05:00
|
|
|
MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state;
|
2017-07-10 06:19:32 -04:00
|
|
|
|
2016-08-17 23:11:30 -04:00
|
|
|
struct {
|
|
|
|
struct gbm_surface *surface;
|
2019-05-20 15:20:17 -04:00
|
|
|
MetaDrmBuffer *current_fb;
|
|
|
|
MetaDrmBuffer *next_fb;
|
2016-08-17 23:11:30 -04:00
|
|
|
} gbm;
|
|
|
|
|
2016-08-17 23:28:59 -04:00
|
|
|
#ifdef HAVE_EGL_DEVICE
|
|
|
|
struct {
|
|
|
|
EGLStreamKHR stream;
|
|
|
|
|
2017-07-24 03:38:46 -04:00
|
|
|
MetaDumbBuffer dumb_fb;
|
2016-08-17 23:28:59 -04:00
|
|
|
} egl;
|
|
|
|
#endif
|
|
|
|
|
2016-05-27 03:07:41 -04:00
|
|
|
gboolean pending_swap_notify;
|
|
|
|
|
2016-06-08 05:05:31 -04:00
|
|
|
gboolean pending_set_crtc;
|
|
|
|
|
2016-12-05 13:18:24 -05:00
|
|
|
int64_t pending_queue_swap_notify_frame_count;
|
|
|
|
int64_t pending_swap_notify_frame_count;
|
|
|
|
|
2016-06-08 05:05:31 -04:00
|
|
|
MetaRendererView *view;
|
2017-07-24 22:21:04 -04:00
|
|
|
int total_pending_flips;
|
2016-05-27 03:07:41 -04:00
|
|
|
} MetaOnscreenNative;
|
|
|
|
|
2016-05-07 11:07:46 -04:00
|
|
|
struct _MetaRendererNative
|
|
|
|
{
|
|
|
|
MetaRenderer parent;
|
2016-05-07 11:09:59 -04:00
|
|
|
|
2018-12-10 07:19:25 -05:00
|
|
|
MetaGpuKms *primary_gpu_kms;
|
2019-01-11 09:35:42 -05:00
|
|
|
|
2017-07-24 22:21:04 -04:00
|
|
|
MetaGles3 *gles3;
|
2016-08-17 22:37:16 -04:00
|
|
|
|
2018-04-11 08:39:15 -04:00
|
|
|
gboolean use_modifiers;
|
|
|
|
|
2017-07-10 06:19:32 -04:00
|
|
|
GHashTable *gpu_datas;
|
2016-08-17 23:28:59 -04:00
|
|
|
|
2016-05-09 09:22:01 -04:00
|
|
|
CoglClosure *swap_notify_idle;
|
2016-05-09 22:16:45 -04:00
|
|
|
|
2016-06-08 05:05:31 -04:00
|
|
|
int64_t frame_counter;
|
2017-09-28 11:59:27 -04:00
|
|
|
gboolean pending_unset_disabled_crtcs;
|
2019-03-25 05:24:46 -04:00
|
|
|
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
GList *power_save_page_flip_onscreens;
|
2019-03-25 05:24:46 -04:00
|
|
|
guint power_save_page_flip_source_id;
|
2016-05-07 11:07:46 -04:00
|
|
|
};
|
|
|
|
|
2016-05-09 09:22:01 -04:00
|
|
|
static void
|
|
|
|
initable_iface_init (GInitableIface *initable_iface);
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (MetaRendererNative,
|
|
|
|
meta_renderer_native,
|
|
|
|
META_TYPE_RENDERER,
|
|
|
|
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
|
|
|
|
initable_iface_init))
|
2016-05-07 11:07:46 -04:00
|
|
|
|
2016-05-09 07:51:29 -04:00
|
|
|
static const CoglWinsysEGLVtable _cogl_winsys_egl_vtable;
|
|
|
|
static const CoglWinsysVtable *parent_vtable;
|
|
|
|
|
2017-07-24 03:38:46 -04:00
|
|
|
static void
|
|
|
|
release_dumb_fb (MetaDumbBuffer *dumb_fb,
|
|
|
|
MetaGpuKms *gpu_kms);
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
init_dumb_fb (MetaDumbBuffer *dumb_fb,
|
|
|
|
MetaGpuKms *gpu_kms,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
uint32_t format,
|
|
|
|
GError **error);
|
|
|
|
|
2018-11-29 06:37:16 -05:00
|
|
|
static int
|
|
|
|
meta_dumb_buffer_ensure_dmabuf_fd (MetaDumbBuffer *dumb_fb,
|
|
|
|
MetaGpuKms *gpu_kms);
|
|
|
|
|
2017-07-24 22:21:04 -04:00
|
|
|
static MetaEgl *
|
|
|
|
meta_renderer_native_get_egl (MetaRendererNative *renderer_native);
|
|
|
|
|
|
|
|
static void
|
2020-01-17 15:08:02 -05:00
|
|
|
free_current_secondary_bo (CoglOnscreen *onscreen);
|
2017-07-24 22:21:04 -04:00
|
|
|
|
2018-11-21 08:25:07 -05:00
|
|
|
static gboolean
|
|
|
|
cogl_pixel_format_from_drm_format (uint32_t drm_format,
|
|
|
|
CoglPixelFormat *out_format,
|
|
|
|
CoglTextureComponents *out_components);
|
|
|
|
|
2019-06-19 14:57:14 -04:00
|
|
|
static void
|
|
|
|
meta_renderer_native_queue_modes_reset (MetaRendererNative *renderer_native);
|
|
|
|
|
2017-07-10 06:19:32 -04:00
|
|
|
static void
|
|
|
|
meta_renderer_native_gpu_data_free (MetaRendererNativeGpuData *renderer_gpu_data)
|
|
|
|
{
|
2017-07-24 22:21:04 -04:00
|
|
|
MetaRendererNative *renderer_native = renderer_gpu_data->renderer_native;
|
|
|
|
MetaEgl *egl = meta_renderer_native_get_egl (renderer_native);
|
|
|
|
|
|
|
|
if (renderer_gpu_data->egl_display != EGL_NO_DISPLAY)
|
|
|
|
meta_egl_terminate (egl, renderer_gpu_data->egl_display, NULL);
|
|
|
|
|
2017-11-06 14:39:56 -05:00
|
|
|
g_clear_pointer (&renderer_gpu_data->gbm.device, gbm_device_destroy);
|
2017-07-10 06:19:32 -04:00
|
|
|
g_free (renderer_gpu_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static MetaRendererNativeGpuData *
|
|
|
|
meta_renderer_native_get_gpu_data (MetaRendererNative *renderer_native,
|
|
|
|
MetaGpuKms *gpu_kms)
|
|
|
|
{
|
|
|
|
return g_hash_table_lookup (renderer_native->gpu_datas, gpu_kms);
|
|
|
|
}
|
|
|
|
|
|
|
|
static MetaRendererNative *
|
|
|
|
meta_renderer_native_from_gpu (MetaGpuKms *gpu_kms)
|
|
|
|
{
|
2019-01-11 09:35:42 -05:00
|
|
|
MetaBackend *backend = meta_gpu_get_backend (META_GPU (gpu_kms));
|
2017-07-10 06:19:32 -04:00
|
|
|
|
|
|
|
return META_RENDERER_NATIVE (meta_backend_get_renderer (backend));
|
|
|
|
}
|
|
|
|
|
|
|
|
struct gbm_device *
|
|
|
|
meta_gbm_device_from_gpu (MetaGpuKms *gpu_kms)
|
|
|
|
{
|
2017-07-24 22:21:04 -04:00
|
|
|
MetaRendererNative *renderer_native = meta_renderer_native_from_gpu (gpu_kms);
|
2017-07-10 06:19:32 -04:00
|
|
|
MetaRendererNativeGpuData *renderer_gpu_data;
|
|
|
|
|
|
|
|
renderer_gpu_data = meta_renderer_native_get_gpu_data (renderer_native,
|
|
|
|
gpu_kms);
|
|
|
|
|
|
|
|
return renderer_gpu_data->gbm.device;
|
|
|
|
}
|
|
|
|
|
|
|
|
static MetaRendererNativeGpuData *
|
|
|
|
meta_create_renderer_native_gpu_data (MetaGpuKms *gpu_kms)
|
|
|
|
{
|
|
|
|
return g_new0 (MetaRendererNativeGpuData, 1);
|
|
|
|
}
|
|
|
|
|
2017-07-24 03:54:29 -04:00
|
|
|
static MetaEgl *
|
|
|
|
meta_renderer_native_get_egl (MetaRendererNative *renderer_native)
|
|
|
|
{
|
2019-10-01 05:51:53 -04:00
|
|
|
MetaRenderer *renderer = META_RENDERER (renderer_native);
|
|
|
|
|
|
|
|
return meta_backend_get_egl (meta_renderer_get_backend (renderer));
|
2017-07-24 03:54:29 -04:00
|
|
|
}
|
|
|
|
|
2017-07-24 22:21:04 -04:00
|
|
|
static MetaEgl *
|
|
|
|
meta_onscreen_native_get_egl (MetaOnscreenNative *onscreen_native)
|
|
|
|
{
|
|
|
|
return meta_renderer_native_get_egl (onscreen_native->renderer_native);
|
|
|
|
}
|
|
|
|
|
2018-02-14 13:27:28 -05:00
|
|
|
static GArray *
|
2020-01-17 15:08:02 -05:00
|
|
|
get_supported_kms_modifiers (MetaCrtc *crtc,
|
|
|
|
uint32_t format)
|
2018-02-14 13:27:28 -05:00
|
|
|
{
|
|
|
|
GArray *modifiers;
|
2020-01-17 15:08:02 -05:00
|
|
|
GArray *crtc_mods;
|
2018-02-14 13:27:28 -05:00
|
|
|
unsigned int i;
|
|
|
|
|
2020-01-17 15:08:02 -05:00
|
|
|
crtc_mods = meta_crtc_kms_get_modifiers (crtc, format);
|
|
|
|
if (!crtc_mods)
|
2018-02-14 13:27:28 -05:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
modifiers = g_array_new (FALSE, FALSE, sizeof (uint64_t));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For each modifier from base_crtc, check if it's available on all other
|
|
|
|
* CRTCs.
|
|
|
|
*/
|
2020-01-17 15:08:02 -05:00
|
|
|
for (i = 0; i < crtc_mods->len; i++)
|
2018-02-14 13:27:28 -05:00
|
|
|
{
|
2020-01-17 15:08:02 -05:00
|
|
|
uint64_t modifier = g_array_index (crtc_mods, uint64_t, i);
|
2018-02-14 13:27:28 -05:00
|
|
|
|
2020-01-17 15:08:02 -05:00
|
|
|
g_array_append_val (modifiers, modifier);
|
2018-02-14 13:27:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (modifiers->len == 0)
|
|
|
|
{
|
|
|
|
g_array_free (modifiers, TRUE);
|
2020-01-17 15:08:02 -05:00
|
|
|
return NULL;
|
2018-02-14 13:27:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return modifiers;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GArray *
|
|
|
|
get_supported_egl_modifiers (CoglOnscreen *onscreen,
|
2020-01-17 15:08:02 -05:00
|
|
|
MetaCrtc *crtc,
|
2018-02-14 13:27:28 -05:00
|
|
|
uint32_t format)
|
|
|
|
{
|
|
|
|
CoglOnscreenEGL *onscreen_egl = onscreen->winsys;
|
|
|
|
MetaOnscreenNative *onscreen_native = onscreen_egl->platform;
|
|
|
|
MetaRendererNative *renderer_native = onscreen_native->renderer_native;
|
|
|
|
MetaEgl *egl = meta_onscreen_native_get_egl (onscreen_native);
|
2020-01-17 15:08:02 -05:00
|
|
|
MetaGpu *gpu;
|
2018-02-14 13:27:28 -05:00
|
|
|
MetaRendererNativeGpuData *renderer_gpu_data;
|
|
|
|
EGLint num_modifiers;
|
|
|
|
GArray *modifiers;
|
|
|
|
GError *error = NULL;
|
|
|
|
gboolean ret;
|
|
|
|
|
2020-01-17 15:08:02 -05:00
|
|
|
gpu = meta_crtc_get_gpu (crtc);
|
2018-02-14 13:27:28 -05:00
|
|
|
renderer_gpu_data = meta_renderer_native_get_gpu_data (renderer_native,
|
|
|
|
META_GPU_KMS (gpu));
|
|
|
|
|
|
|
|
if (!meta_egl_has_extensions (egl, renderer_gpu_data->egl_display, NULL,
|
|
|
|
"EGL_EXT_image_dma_buf_import_modifiers",
|
|
|
|
NULL))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ret = meta_egl_query_dma_buf_modifiers (egl, renderer_gpu_data->egl_display,
|
|
|
|
format, 0, NULL, NULL,
|
|
|
|
&num_modifiers, NULL);
|
|
|
|
if (!ret || num_modifiers == 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
modifiers = g_array_sized_new (FALSE, FALSE, sizeof (uint64_t),
|
|
|
|
num_modifiers);
|
|
|
|
ret = meta_egl_query_dma_buf_modifiers (egl, renderer_gpu_data->egl_display,
|
|
|
|
format, num_modifiers,
|
|
|
|
(EGLuint64KHR *) modifiers->data, NULL,
|
|
|
|
&num_modifiers, &error);
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
g_warning ("Failed to query DMABUF modifiers: %s", error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
g_array_free (modifiers, TRUE);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return modifiers;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GArray *
|
|
|
|
get_supported_modifiers (CoglOnscreen *onscreen,
|
|
|
|
uint32_t format)
|
|
|
|
{
|
|
|
|
CoglOnscreenEGL *onscreen_egl = onscreen->winsys;
|
|
|
|
MetaOnscreenNative *onscreen_native = onscreen_egl->platform;
|
2020-01-17 15:08:02 -05:00
|
|
|
MetaCrtc *crtc = onscreen_native->crtc;
|
2018-11-21 08:25:07 -05:00
|
|
|
MetaGpu *gpu;
|
2020-01-17 15:08:02 -05:00
|
|
|
g_autoptr (GArray) modifiers = NULL;
|
2018-11-21 08:25:07 -05:00
|
|
|
|
2020-01-17 15:08:02 -05:00
|
|
|
gpu = meta_crtc_get_gpu (crtc);
|
|
|
|
if (gpu == META_GPU (onscreen_native->render_gpu))
|
|
|
|
modifiers = get_supported_kms_modifiers (crtc, format);
|
|
|
|
else
|
|
|
|
modifiers = get_supported_egl_modifiers (onscreen, crtc, format);
|
2018-11-21 08:25:07 -05:00
|
|
|
|
2020-01-17 15:08:02 -05:00
|
|
|
return g_steal_pointer (&modifiers);
|
2018-11-21 08:25:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static GArray *
|
2020-01-17 15:08:02 -05:00
|
|
|
get_supported_kms_formats (CoglOnscreen *onscreen)
|
2018-11-21 08:25:07 -05:00
|
|
|
{
|
|
|
|
CoglOnscreenEGL *onscreen_egl = onscreen->winsys;
|
|
|
|
MetaOnscreenNative *onscreen_native = onscreen_egl->platform;
|
2020-01-17 15:08:02 -05:00
|
|
|
MetaCrtc *crtc = onscreen_native->crtc;
|
2018-11-21 08:25:07 -05:00
|
|
|
|
2020-01-17 15:08:02 -05:00
|
|
|
return meta_crtc_kms_copy_drm_format_list (crtc);
|
2018-11-21 08:25:07 -05:00
|
|
|
}
|
|
|
|
|
2017-07-24 22:21:04 -04:00
|
|
|
static gboolean
|
|
|
|
init_secondary_gpu_state_gpu_copy_mode (MetaRendererNative *renderer_native,
|
|
|
|
CoglOnscreen *onscreen,
|
|
|
|
MetaRendererNativeGpuData *renderer_gpu_data,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
|
|
|
|
CoglOnscreenEGL *onscreen_egl = onscreen->winsys;
|
|
|
|
MetaOnscreenNative *onscreen_native = onscreen_egl->platform;
|
|
|
|
MetaEgl *egl = meta_onscreen_native_get_egl (onscreen_native);
|
|
|
|
int width, height;
|
|
|
|
EGLNativeWindowType egl_native_window;
|
|
|
|
struct gbm_surface *gbm_surface;
|
|
|
|
EGLSurface egl_surface;
|
|
|
|
MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state;
|
2020-01-17 15:08:02 -05:00
|
|
|
MetaGpuKms *gpu_kms;
|
2017-07-24 22:21:04 -04:00
|
|
|
|
|
|
|
width = cogl_framebuffer_get_width (framebuffer);
|
|
|
|
height = cogl_framebuffer_get_height (framebuffer);
|
|
|
|
|
|
|
|
gbm_surface = gbm_surface_create (renderer_gpu_data->gbm.device,
|
|
|
|
width, height,
|
|
|
|
GBM_FORMAT_XRGB8888,
|
|
|
|
GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
|
|
|
|
if (!gbm_surface)
|
|
|
|
{
|
|
|
|
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
|
|
|
"Failed to create gbm_surface: %s", strerror (errno));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
egl_native_window = (EGLNativeWindowType) gbm_surface;
|
|
|
|
egl_surface =
|
|
|
|
meta_egl_create_window_surface (egl,
|
|
|
|
renderer_gpu_data->egl_display,
|
|
|
|
renderer_gpu_data->secondary.egl_config,
|
|
|
|
egl_native_window,
|
|
|
|
NULL,
|
|
|
|
error);
|
|
|
|
if (egl_surface == EGL_NO_SURFACE)
|
|
|
|
{
|
|
|
|
gbm_surface_destroy (gbm_surface);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
secondary_gpu_state = g_new0 (MetaOnscreenNativeSecondaryGpuState, 1);
|
|
|
|
|
2020-01-17 15:08:02 -05:00
|
|
|
gpu_kms = META_GPU_KMS (meta_crtc_get_gpu (onscreen_native->crtc));
|
2017-07-24 22:21:04 -04:00
|
|
|
secondary_gpu_state->gpu_kms = gpu_kms;
|
|
|
|
secondary_gpu_state->renderer_gpu_data = renderer_gpu_data;
|
|
|
|
secondary_gpu_state->gbm.surface = gbm_surface;
|
|
|
|
secondary_gpu_state->egl_surface = egl_surface;
|
|
|
|
|
2020-01-17 15:08:02 -05:00
|
|
|
onscreen_native->secondary_gpu_state = secondary_gpu_state;
|
2017-07-24 22:21:04 -04:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-09-17 06:23:22 -04:00
|
|
|
static void
|
|
|
|
secondary_gpu_release_dumb (MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state)
|
|
|
|
{
|
|
|
|
MetaGpuKms *gpu_kms = secondary_gpu_state->gpu_kms;
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (secondary_gpu_state->cpu.dumb_fbs); i++)
|
|
|
|
release_dumb_fb (&secondary_gpu_state->cpu.dumb_fbs[i], gpu_kms);
|
|
|
|
}
|
|
|
|
|
2017-07-24 22:21:04 -04:00
|
|
|
static void
|
|
|
|
secondary_gpu_state_free (MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state)
|
|
|
|
{
|
|
|
|
MetaBackend *backend = meta_get_backend ();
|
|
|
|
MetaEgl *egl = meta_backend_get_egl (backend);
|
|
|
|
|
|
|
|
if (secondary_gpu_state->egl_surface != EGL_NO_SURFACE)
|
|
|
|
{
|
|
|
|
MetaRendererNativeGpuData *renderer_gpu_data;
|
|
|
|
|
|
|
|
renderer_gpu_data = secondary_gpu_state->renderer_gpu_data;
|
|
|
|
meta_egl_destroy_surface (egl,
|
|
|
|
renderer_gpu_data->egl_display,
|
|
|
|
secondary_gpu_state->egl_surface,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2020-01-17 15:08:02 -05:00
|
|
|
g_clear_object (&secondary_gpu_state->gbm.current_fb);
|
2019-09-16 09:47:49 -04:00
|
|
|
g_clear_object (&secondary_gpu_state->gbm.next_fb);
|
2017-07-24 22:21:04 -04:00
|
|
|
g_clear_pointer (&secondary_gpu_state->gbm.surface, gbm_surface_destroy);
|
|
|
|
|
2019-09-17 06:23:22 -04:00
|
|
|
secondary_gpu_release_dumb (secondary_gpu_state);
|
2017-07-24 22:21:04 -04:00
|
|
|
|
|
|
|
g_free (secondary_gpu_state);
|
|
|
|
}
|
|
|
|
|
2018-11-21 08:25:07 -05:00
|
|
|
static uint32_t
|
2020-01-17 15:08:02 -05:00
|
|
|
pick_secondary_gpu_framebuffer_format_for_cpu (CoglOnscreen *onscreen)
|
2018-11-21 08:25:07 -05:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* cogl_framebuffer_read_pixels_into_bitmap () supported formats in
|
|
|
|
* preference order. Ideally these should depend on the render buffer
|
|
|
|
* format copy_shared_framebuffer_cpu () will be reading from but
|
|
|
|
* alpha channel ignored.
|
|
|
|
*/
|
|
|
|
static const uint32_t preferred_formats[] =
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* DRM_FORMAT_XBGR8888 a.k.a GL_RGBA, GL_UNSIGNED_BYTE on
|
|
|
|
* little-endian is possibly the most optimized glReadPixels
|
|
|
|
* output format. glReadPixels cannot avoid manufacturing an alpha
|
|
|
|
* channel if the render buffer does not have one and converting
|
|
|
|
* to ABGR8888 may be more optimized than ARGB8888.
|
|
|
|
*/
|
|
|
|
DRM_FORMAT_XBGR8888,
|
|
|
|
/* The rest are other fairly commonly used formats in OpenGL. */
|
|
|
|
DRM_FORMAT_XRGB8888,
|
|
|
|
};
|
2019-06-20 04:22:32 -04:00
|
|
|
g_autoptr (GArray) formats = NULL;
|
2018-11-21 08:25:07 -05:00
|
|
|
size_t k;
|
|
|
|
unsigned int i;
|
|
|
|
uint32_t drm_format;
|
|
|
|
|
2020-01-17 15:08:02 -05:00
|
|
|
formats = get_supported_kms_formats (onscreen);
|
2018-11-21 08:25:07 -05:00
|
|
|
|
|
|
|
/* Check if any of our preferred formats are supported. */
|
|
|
|
for (k = 0; k < G_N_ELEMENTS (preferred_formats); k++)
|
|
|
|
{
|
|
|
|
g_assert (cogl_pixel_format_from_drm_format (preferred_formats[k],
|
|
|
|
NULL,
|
|
|
|
NULL));
|
|
|
|
|
|
|
|
for (i = 0; i < formats->len; i++)
|
|
|
|
{
|
|
|
|
drm_format = g_array_index (formats, uint32_t, i);
|
|
|
|
|
|
|
|
if (drm_format == preferred_formats[k])
|
|
|
|
return drm_format;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Otherwise just pick an arbitrary format we recognize. The formats
|
|
|
|
* list is not in any specific order and we don't know any better
|
|
|
|
* either.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < formats->len; i++)
|
|
|
|
{
|
|
|
|
drm_format = g_array_index (formats, uint32_t, i);
|
|
|
|
|
|
|
|
if (cogl_pixel_format_from_drm_format (drm_format, NULL, NULL))
|
|
|
|
return drm_format;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DRM_FORMAT_INVALID;
|
|
|
|
}
|
|
|
|
|
2017-07-24 22:21:04 -04:00
|
|
|
static gboolean
|
|
|
|
init_secondary_gpu_state_cpu_copy_mode (MetaRendererNative *renderer_native,
|
|
|
|
CoglOnscreen *onscreen,
|
|
|
|
MetaRendererNativeGpuData *renderer_gpu_data,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
|
|
|
|
CoglOnscreenEGL *onscreen_egl = onscreen->winsys;
|
|
|
|
MetaOnscreenNative *onscreen_native = onscreen_egl->platform;
|
|
|
|
MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state;
|
2020-01-17 15:08:02 -05:00
|
|
|
MetaGpuKms *gpu_kms;
|
2017-07-24 22:21:04 -04:00
|
|
|
int width, height;
|
|
|
|
unsigned int i;
|
2018-11-21 08:25:07 -05:00
|
|
|
uint32_t drm_format;
|
2018-11-22 09:26:01 -05:00
|
|
|
MetaDrmFormatBuf tmp;
|
2018-11-21 08:25:07 -05:00
|
|
|
|
2020-01-17 15:08:02 -05:00
|
|
|
drm_format = pick_secondary_gpu_framebuffer_format_for_cpu (onscreen);
|
2018-11-21 08:25:07 -05:00
|
|
|
if (drm_format == DRM_FORMAT_INVALID)
|
|
|
|
{
|
|
|
|
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
|
|
|
"Could not find a suitable pixel format in CPU copy mode");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2017-07-24 22:21:04 -04:00
|
|
|
|
|
|
|
width = cogl_framebuffer_get_width (framebuffer);
|
|
|
|
height = cogl_framebuffer_get_height (framebuffer);
|
|
|
|
|
2020-01-17 15:08:02 -05:00
|
|
|
gpu_kms = META_GPU_KMS (meta_crtc_get_gpu (onscreen_native->crtc));
|
2018-11-22 09:26:01 -05:00
|
|
|
g_debug ("Secondary GPU %s using DRM format '%s' (0x%x) for a %dx%d output.",
|
|
|
|
meta_gpu_kms_get_file_path (gpu_kms),
|
|
|
|
meta_drm_format_to_string (&tmp, drm_format),
|
|
|
|
drm_format,
|
|
|
|
width, height);
|
|
|
|
|
2017-07-24 22:21:04 -04:00
|
|
|
secondary_gpu_state = g_new0 (MetaOnscreenNativeSecondaryGpuState, 1);
|
|
|
|
secondary_gpu_state->renderer_gpu_data = renderer_gpu_data;
|
|
|
|
secondary_gpu_state->gpu_kms = gpu_kms;
|
|
|
|
secondary_gpu_state->egl_surface = EGL_NO_SURFACE;
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (secondary_gpu_state->cpu.dumb_fbs); i++)
|
|
|
|
{
|
|
|
|
MetaDumbBuffer *dumb_fb = &secondary_gpu_state->cpu.dumb_fbs[i];
|
|
|
|
|
|
|
|
if (!init_dumb_fb (dumb_fb,
|
|
|
|
gpu_kms,
|
|
|
|
width, height,
|
2018-11-21 08:25:07 -05:00
|
|
|
drm_format,
|
2017-07-24 22:21:04 -04:00
|
|
|
error))
|
|
|
|
{
|
|
|
|
secondary_gpu_state_free (secondary_gpu_state);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-24 10:07:14 -04:00
|
|
|
/*
|
|
|
|
* This function initializes everything needed for
|
|
|
|
* META_SHARED_FRAMEBUFFER_COPY_MODE_ZERO as well.
|
|
|
|
*/
|
|
|
|
secondary_gpu_state->import_status =
|
|
|
|
META_SHARED_FRAMEBUFFER_IMPORT_STATUS_NONE;
|
|
|
|
|
2020-01-17 15:08:02 -05:00
|
|
|
onscreen_native->secondary_gpu_state = secondary_gpu_state;
|
2017-07-24 22:21:04 -04:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
init_secondary_gpu_state (MetaRendererNative *renderer_native,
|
|
|
|
CoglOnscreen *onscreen,
|
|
|
|
GError **error)
|
|
|
|
{
|
2020-01-17 15:08:02 -05:00
|
|
|
CoglOnscreenEGL *onscreen_egl = onscreen->winsys;
|
|
|
|
MetaOnscreenNative *onscreen_native = onscreen_egl->platform;
|
|
|
|
MetaGpu *gpu = meta_crtc_get_gpu (onscreen_native->crtc);
|
2017-07-24 22:21:04 -04:00
|
|
|
MetaRendererNativeGpuData *renderer_gpu_data;
|
|
|
|
|
|
|
|
renderer_gpu_data = meta_renderer_native_get_gpu_data (renderer_native,
|
2020-01-17 15:08:02 -05:00
|
|
|
META_GPU_KMS (gpu));
|
2017-07-24 22:21:04 -04:00
|
|
|
|
|
|
|
switch (renderer_gpu_data->secondary.copy_mode)
|
|
|
|
{
|
2018-11-29 06:34:40 -05:00
|
|
|
case META_SHARED_FRAMEBUFFER_COPY_MODE_SECONDARY_GPU:
|
2017-07-24 22:21:04 -04:00
|
|
|
if (!init_secondary_gpu_state_gpu_copy_mode (renderer_native,
|
|
|
|
onscreen,
|
|
|
|
renderer_gpu_data,
|
|
|
|
error))
|
|
|
|
return FALSE;
|
|
|
|
break;
|
2019-05-24 10:07:14 -04:00
|
|
|
case META_SHARED_FRAMEBUFFER_COPY_MODE_ZERO:
|
|
|
|
/*
|
|
|
|
* Initialize also the primary copy mode, so that if zero-copy
|
|
|
|
* path fails, which is quite likely, we can simply continue
|
|
|
|
* with the primary copy path on the very first frame.
|
|
|
|
*/
|
|
|
|
G_GNUC_FALLTHROUGH;
|
2018-11-29 06:34:40 -05:00
|
|
|
case META_SHARED_FRAMEBUFFER_COPY_MODE_PRIMARY:
|
2017-07-24 22:21:04 -04:00
|
|
|
if (!init_secondary_gpu_state_cpu_copy_mode (renderer_native,
|
|
|
|
onscreen,
|
|
|
|
renderer_gpu_data,
|
|
|
|
error))
|
|
|
|
return FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-05-09 07:51:29 -04:00
|
|
|
static void
|
2016-06-01 05:53:07 -04:00
|
|
|
meta_renderer_native_disconnect (CoglRenderer *cogl_renderer)
|
2016-05-09 07:51:29 -04:00
|
|
|
{
|
2017-07-14 03:20:41 -04:00
|
|
|
CoglRendererEGL *cogl_renderer_egl = cogl_renderer->winsys;
|
2016-05-09 07:51:29 -04:00
|
|
|
|
2017-07-14 03:20:41 -04:00
|
|
|
g_slice_free (CoglRendererEGL, cogl_renderer_egl);
|
2016-05-09 07:51:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-06-08 05:05:31 -04:00
|
|
|
flush_pending_swap_notify (CoglFramebuffer *framebuffer)
|
2016-05-09 07:51:29 -04:00
|
|
|
{
|
|
|
|
if (framebuffer->type == COGL_FRAMEBUFFER_TYPE_ONSCREEN)
|
|
|
|
{
|
|
|
|
CoglOnscreen *onscreen = COGL_ONSCREEN (framebuffer);
|
2017-07-14 03:20:41 -04:00
|
|
|
CoglOnscreenEGL *onscreen_egl = onscreen->winsys;
|
|
|
|
MetaOnscreenNative *onscreen_native = onscreen_egl->platform;
|
2016-05-09 07:51:29 -04:00
|
|
|
|
2016-05-27 03:07:41 -04:00
|
|
|
if (onscreen_native->pending_swap_notify)
|
2016-05-09 07:51:29 -04:00
|
|
|
{
|
2016-12-05 13:18:24 -05:00
|
|
|
CoglFrameInfo *info;
|
2016-05-09 07:51:29 -04:00
|
|
|
|
2016-12-05 13:18:24 -05:00
|
|
|
while ((info = g_queue_peek_head (&onscreen->pending_frame_infos)) &&
|
|
|
|
info->global_frame_counter <= onscreen_native->pending_swap_notify_frame_count)
|
|
|
|
{
|
|
|
|
_cogl_onscreen_notify_frame_sync (onscreen, info);
|
|
|
|
_cogl_onscreen_notify_complete (onscreen, info);
|
|
|
|
cogl_object_unref (info);
|
|
|
|
g_queue_pop_head (&onscreen->pending_frame_infos);
|
|
|
|
}
|
2016-06-08 05:05:31 -04:00
|
|
|
|
2016-05-27 03:07:41 -04:00
|
|
|
onscreen_native->pending_swap_notify = FALSE;
|
2016-06-08 05:05:31 -04:00
|
|
|
cogl_object_unref (onscreen);
|
2016-05-09 07:51:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
flush_pending_swap_notify_idle (void *user_data)
|
|
|
|
{
|
2016-06-01 05:53:07 -04:00
|
|
|
CoglContext *cogl_context = user_data;
|
2017-07-14 03:20:41 -04:00
|
|
|
CoglRendererEGL *cogl_renderer_egl = cogl_context->display->renderer->winsys;
|
2017-07-24 22:21:04 -04:00
|
|
|
MetaRendererNativeGpuData *renderer_gpu_data = cogl_renderer_egl->platform;
|
|
|
|
MetaRendererNative *renderer_native = renderer_gpu_data->renderer_native;
|
2016-06-08 05:05:31 -04:00
|
|
|
GList *l;
|
2016-05-09 07:51:29 -04:00
|
|
|
|
|
|
|
/* This needs to be disconnected before invoking the callbacks in
|
|
|
|
* case the callbacks cause it to be queued again */
|
2016-05-09 09:22:01 -04:00
|
|
|
_cogl_closure_disconnect (renderer_native->swap_notify_idle);
|
|
|
|
renderer_native->swap_notify_idle = NULL;
|
2016-05-09 07:51:29 -04:00
|
|
|
|
2016-06-08 05:05:31 -04:00
|
|
|
l = cogl_context->framebuffers;
|
|
|
|
while (l)
|
|
|
|
{
|
|
|
|
GList *next = l->next;
|
|
|
|
CoglFramebuffer *framebuffer = l->data;
|
|
|
|
|
|
|
|
flush_pending_swap_notify (framebuffer);
|
|
|
|
|
|
|
|
l = next;
|
|
|
|
}
|
2016-05-09 07:51:29 -04:00
|
|
|
}
|
|
|
|
|
2017-07-24 22:21:04 -04:00
|
|
|
static void
|
2020-01-17 15:08:02 -05:00
|
|
|
free_current_secondary_bo (CoglOnscreen *onscreen)
|
2017-07-24 22:21:04 -04:00
|
|
|
{
|
2020-01-17 15:08:02 -05:00
|
|
|
CoglOnscreenEGL *onscreen_egl = onscreen->winsys;
|
|
|
|
MetaOnscreenNative *onscreen_native = onscreen_egl->platform;
|
|
|
|
MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state;
|
|
|
|
|
|
|
|
secondary_gpu_state = onscreen_native->secondary_gpu_state;
|
|
|
|
if (!secondary_gpu_state)
|
|
|
|
return;
|
|
|
|
|
2019-09-16 09:39:02 -04:00
|
|
|
g_clear_object (&secondary_gpu_state->gbm.current_fb);
|
2017-07-24 22:21:04 -04:00
|
|
|
}
|
|
|
|
|
2016-05-09 07:51:29 -04:00
|
|
|
static void
|
|
|
|
free_current_bo (CoglOnscreen *onscreen)
|
|
|
|
{
|
2017-07-14 03:20:41 -04:00
|
|
|
CoglOnscreenEGL *onscreen_egl = onscreen->winsys;
|
|
|
|
MetaOnscreenNative *onscreen_native = onscreen_egl->platform;
|
2016-05-09 07:51:29 -04:00
|
|
|
|
2018-01-30 04:47:17 -05:00
|
|
|
g_clear_object (&onscreen_native->gbm.current_fb);
|
2020-01-17 15:08:02 -05:00
|
|
|
free_current_secondary_bo (onscreen);
|
2016-05-09 07:51:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-06-08 05:05:31 -04:00
|
|
|
meta_onscreen_native_queue_swap_notify (CoglOnscreen *onscreen)
|
2016-05-09 07:51:29 -04:00
|
|
|
{
|
2017-07-14 03:20:41 -04:00
|
|
|
CoglOnscreenEGL *onscreen_egl = onscreen->winsys;
|
|
|
|
MetaOnscreenNative *onscreen_native = onscreen_egl->platform;
|
2017-07-24 22:21:04 -04:00
|
|
|
MetaRendererNative *renderer_native = onscreen_native->renderer_native;
|
2016-05-09 07:51:29 -04:00
|
|
|
|
2016-12-05 13:18:24 -05:00
|
|
|
onscreen_native->pending_swap_notify_frame_count =
|
|
|
|
onscreen_native->pending_queue_swap_notify_frame_count;
|
|
|
|
|
2016-11-23 09:46:26 -05:00
|
|
|
if (onscreen_native->pending_swap_notify)
|
|
|
|
return;
|
|
|
|
|
2016-05-09 07:51:29 -04:00
|
|
|
/* We only want to notify that the swap is complete when the
|
|
|
|
* application calls cogl_context_dispatch so instead of
|
|
|
|
* immediately notifying we queue an idle callback */
|
2016-05-09 09:22:01 -04:00
|
|
|
if (!renderer_native->swap_notify_idle)
|
2016-05-09 07:51:29 -04:00
|
|
|
{
|
2017-07-24 22:21:04 -04:00
|
|
|
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
|
|
|
|
CoglContext *cogl_context = framebuffer->context;
|
|
|
|
CoglRenderer *cogl_renderer = cogl_context->display->renderer;
|
|
|
|
|
2016-05-09 09:22:01 -04:00
|
|
|
renderer_native->swap_notify_idle =
|
2016-06-01 05:53:07 -04:00
|
|
|
_cogl_poll_renderer_add_idle (cogl_renderer,
|
2016-05-09 07:51:29 -04:00
|
|
|
flush_pending_swap_notify_idle,
|
2016-06-01 05:53:07 -04:00
|
|
|
cogl_context,
|
2016-05-09 07:51:29 -04:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2016-06-08 05:05:31 -04:00
|
|
|
/*
|
|
|
|
* The framebuffer will have its own referenc while the swap notify is
|
|
|
|
* pending. Otherwise when destroying the view would drop the pending
|
|
|
|
* notification with if the destruction happens before the idle callback
|
|
|
|
* is invoked.
|
|
|
|
*/
|
|
|
|
cogl_object_ref (onscreen);
|
2016-05-27 03:07:41 -04:00
|
|
|
onscreen_native->pending_swap_notify = TRUE;
|
2016-05-09 07:51:29 -04:00
|
|
|
}
|
|
|
|
|
2016-08-17 22:21:12 -04:00
|
|
|
static gboolean
|
2016-05-27 03:13:09 -04:00
|
|
|
meta_renderer_native_connect (CoglRenderer *cogl_renderer,
|
2016-08-17 22:21:12 -04:00
|
|
|
GError **error)
|
2016-05-09 07:51:29 -04:00
|
|
|
{
|
2017-07-14 03:20:41 -04:00
|
|
|
CoglRendererEGL *cogl_renderer_egl;
|
2017-07-24 22:21:04 -04:00
|
|
|
MetaGpuKms *gpu_kms = cogl_renderer->custom_winsys_user_data;
|
|
|
|
MetaRendererNative *renderer_native = meta_renderer_native_from_gpu (gpu_kms);
|
|
|
|
MetaRendererNativeGpuData *renderer_gpu_data;
|
2016-05-09 07:51:29 -04:00
|
|
|
|
|
|
|
cogl_renderer->winsys = g_slice_new0 (CoglRendererEGL);
|
2017-07-14 03:20:41 -04:00
|
|
|
cogl_renderer_egl = cogl_renderer->winsys;
|
2016-05-09 07:51:29 -04:00
|
|
|
|
2017-07-24 22:21:04 -04:00
|
|
|
renderer_gpu_data = meta_renderer_native_get_gpu_data (renderer_native,
|
|
|
|
gpu_kms);
|
|
|
|
|
2017-07-14 03:20:41 -04:00
|
|
|
cogl_renderer_egl->platform_vtable = &_cogl_winsys_egl_vtable;
|
2017-07-24 22:21:04 -04:00
|
|
|
cogl_renderer_egl->platform = renderer_gpu_data;
|
|
|
|
cogl_renderer_egl->edpy = renderer_gpu_data->egl_display;
|
2016-05-09 07:51:29 -04:00
|
|
|
|
|
|
|
if (!_cogl_winsys_egl_renderer_connect_common (cogl_renderer, error))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
fail:
|
2016-05-27 03:13:09 -04:00
|
|
|
meta_renderer_native_disconnect (cogl_renderer);
|
2016-05-09 07:51:29 -04:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-09-26 03:54:27 -04:00
|
|
|
static int
|
|
|
|
meta_renderer_native_add_egl_config_attributes (CoglDisplay *cogl_display,
|
|
|
|
CoglFramebufferConfig *config,
|
|
|
|
EGLint *attributes)
|
|
|
|
{
|
2017-07-14 03:20:41 -04:00
|
|
|
CoglRendererEGL *cogl_renderer_egl = cogl_display->renderer->winsys;
|
2017-07-24 22:21:04 -04:00
|
|
|
MetaRendererNativeGpuData *renderer_gpu_data = cogl_renderer_egl->platform;
|
2016-09-26 03:54:27 -04:00
|
|
|
int i = 0;
|
|
|
|
|
2017-07-24 22:21:04 -04:00
|
|
|
switch (renderer_gpu_data->mode)
|
2016-08-17 23:28:59 -04:00
|
|
|
{
|
|
|
|
case META_RENDERER_NATIVE_MODE_GBM:
|
|
|
|
attributes[i++] = EGL_SURFACE_TYPE;
|
|
|
|
attributes[i++] = EGL_WINDOW_BIT;
|
|
|
|
break;
|
|
|
|
#ifdef HAVE_EGL_DEVICE
|
|
|
|
case META_RENDERER_NATIVE_MODE_EGL_DEVICE:
|
|
|
|
attributes[i++] = EGL_SURFACE_TYPE;
|
|
|
|
attributes[i++] = EGL_STREAM_BIT_KHR;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
}
|
2016-09-26 03:54:27 -04:00
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2018-02-23 09:14:07 -05:00
|
|
|
static gboolean
|
|
|
|
choose_egl_config_from_gbm_format (MetaEgl *egl,
|
|
|
|
EGLDisplay egl_display,
|
|
|
|
const EGLint *attributes,
|
|
|
|
uint32_t gbm_format,
|
|
|
|
EGLConfig *out_config,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
EGLConfig *egl_configs;
|
|
|
|
EGLint n_configs;
|
|
|
|
EGLint i;
|
|
|
|
|
|
|
|
egl_configs = meta_egl_choose_all_configs (egl, egl_display,
|
|
|
|
attributes,
|
|
|
|
&n_configs,
|
|
|
|
error);
|
|
|
|
if (!egl_configs)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
for (i = 0; i < n_configs; i++)
|
|
|
|
{
|
|
|
|
EGLint visual_id;
|
|
|
|
|
|
|
|
if (!meta_egl_get_config_attrib (egl, egl_display,
|
|
|
|
egl_configs[i],
|
|
|
|
EGL_NATIVE_VISUAL_ID,
|
|
|
|
&visual_id,
|
|
|
|
error))
|
|
|
|
{
|
|
|
|
g_free (egl_configs);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((uint32_t) visual_id == gbm_format)
|
|
|
|
{
|
|
|
|
*out_config = egl_configs[i];
|
|
|
|
g_free (egl_configs);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (egl_configs);
|
|
|
|
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
|
|
|
"No EGL config matching supported GBM format found");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
meta_renderer_native_choose_egl_config (CoglDisplay *cogl_display,
|
|
|
|
EGLint *attributes,
|
|
|
|
EGLConfig *out_config,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
CoglRenderer *cogl_renderer = cogl_display->renderer;
|
|
|
|
CoglRendererEGL *cogl_renderer_egl = cogl_renderer->winsys;
|
|
|
|
MetaBackend *backend = meta_get_backend ();
|
|
|
|
MetaEgl *egl = meta_backend_get_egl (backend);
|
2018-06-07 19:29:44 -04:00
|
|
|
MetaRendererNativeGpuData *renderer_gpu_data = cogl_renderer_egl->platform;
|
2018-02-23 09:14:07 -05:00
|
|
|
EGLDisplay egl_display = cogl_renderer_egl->edpy;
|
|
|
|
|
2018-06-07 19:29:44 -04:00
|
|
|
switch (renderer_gpu_data->mode)
|
|
|
|
{
|
|
|
|
case META_RENDERER_NATIVE_MODE_GBM:
|
|
|
|
return choose_egl_config_from_gbm_format (egl,
|
|
|
|
egl_display,
|
|
|
|
attributes,
|
|
|
|
GBM_FORMAT_XRGB8888,
|
|
|
|
out_config,
|
|
|
|
error);
|
|
|
|
#ifdef HAVE_EGL_DEVICE
|
|
|
|
case META_RENDERER_NATIVE_MODE_EGL_DEVICE:
|
|
|
|
return meta_egl_choose_first_config (egl,
|
|
|
|
egl_display,
|
|
|
|
attributes,
|
|
|
|
out_config,
|
|
|
|
error);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
2018-02-23 09:14:07 -05:00
|
|
|
}
|
|
|
|
|
2016-08-17 22:21:12 -04:00
|
|
|
static gboolean
|
2016-06-01 05:53:07 -04:00
|
|
|
meta_renderer_native_setup_egl_display (CoglDisplay *cogl_display,
|
2016-08-17 22:21:12 -04:00
|
|
|
GError **error)
|
2016-05-09 07:51:29 -04:00
|
|
|
{
|
2017-07-14 03:20:41 -04:00
|
|
|
CoglDisplayEGL *cogl_display_egl = cogl_display->winsys;
|
|
|
|
CoglRendererEGL *cogl_renderer_egl = cogl_display->renderer->winsys;
|
2017-07-24 22:21:04 -04:00
|
|
|
MetaRendererNativeGpuData *renderer_gpu_data = cogl_renderer_egl->platform;
|
|
|
|
MetaRendererNative *renderer_native = renderer_gpu_data->renderer_native;
|
2016-05-09 07:51:29 -04:00
|
|
|
|
2017-07-14 03:20:41 -04:00
|
|
|
cogl_display_egl->platform = renderer_native;
|
2016-05-09 07:51:29 -04:00
|
|
|
|
|
|
|
/* Force a full modeset / drmModeSetCrtc on
|
|
|
|
* the first swap buffers call.
|
|
|
|
*/
|
2016-06-08 05:05:31 -04:00
|
|
|
meta_renderer_native_queue_modes_reset (renderer_native);
|
2016-05-09 07:51:29 -04:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-06-01 05:53:07 -04:00
|
|
|
meta_renderer_native_destroy_egl_display (CoglDisplay *cogl_display)
|
2016-05-09 07:51:29 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-08-30 23:25:45 -04:00
|
|
|
static EGLSurface
|
|
|
|
create_dummy_pbuffer_surface (EGLDisplay egl_display,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
MetaBackend *backend = meta_get_backend ();
|
|
|
|
MetaEgl *egl = meta_backend_get_egl (backend);
|
|
|
|
EGLConfig pbuffer_config;
|
|
|
|
static const EGLint pbuffer_config_attribs[] = {
|
|
|
|
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
|
|
|
|
EGL_RED_SIZE, 1,
|
|
|
|
EGL_GREEN_SIZE, 1,
|
|
|
|
EGL_BLUE_SIZE, 1,
|
|
|
|
EGL_ALPHA_SIZE, 0,
|
|
|
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
static const EGLint pbuffer_attribs[] = {
|
|
|
|
EGL_WIDTH, 16,
|
|
|
|
EGL_HEIGHT, 16,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
|
2018-02-23 09:13:11 -05:00
|
|
|
if (!meta_egl_choose_first_config (egl, egl_display, pbuffer_config_attribs,
|
|
|
|
&pbuffer_config, error))
|
2016-08-30 23:25:45 -04:00
|
|
|
return EGL_NO_SURFACE;
|
|
|
|
|
|
|
|
return meta_egl_create_pbuffer_surface (egl, egl_display,
|
|
|
|
pbuffer_config, pbuffer_attribs,
|
|
|
|
error);
|
|
|
|
}
|
|
|
|
|
2016-08-17 22:21:12 -04:00
|
|
|
static gboolean
|
2016-06-01 05:53:07 -04:00
|
|
|
meta_renderer_native_egl_context_created (CoglDisplay *cogl_display,
|
2016-08-17 22:21:12 -04:00
|
|
|
GError **error)
|
2016-05-09 07:51:29 -04:00
|
|
|
{
|
2017-07-14 03:20:41 -04:00
|
|
|
CoglDisplayEGL *cogl_display_egl = cogl_display->winsys;
|
2016-06-01 05:53:07 -04:00
|
|
|
CoglRenderer *cogl_renderer = cogl_display->renderer;
|
2017-07-14 03:20:41 -04:00
|
|
|
CoglRendererEGL *cogl_renderer_egl = cogl_renderer->winsys;
|
2016-05-09 07:51:29 -04:00
|
|
|
|
2017-07-14 03:20:41 -04:00
|
|
|
if ((cogl_renderer_egl->private_features &
|
2016-05-09 07:51:29 -04:00
|
|
|
COGL_EGL_WINSYS_FEATURE_SURFACELESS_CONTEXT) == 0)
|
|
|
|
{
|
2017-07-14 03:20:41 -04:00
|
|
|
cogl_display_egl->dummy_surface =
|
|
|
|
create_dummy_pbuffer_surface (cogl_renderer_egl->edpy, error);
|
|
|
|
if (cogl_display_egl->dummy_surface == EGL_NO_SURFACE)
|
2016-08-30 23:25:45 -04:00
|
|
|
return FALSE;
|
2016-05-09 07:51:29 -04:00
|
|
|
}
|
|
|
|
|
2016-06-01 05:53:07 -04:00
|
|
|
if (!_cogl_winsys_egl_make_current (cogl_display,
|
2017-07-14 03:20:41 -04:00
|
|
|
cogl_display_egl->dummy_surface,
|
|
|
|
cogl_display_egl->dummy_surface,
|
|
|
|
cogl_display_egl->egl_context))
|
2016-05-09 07:51:29 -04:00
|
|
|
{
|
2019-06-17 12:18:12 -04:00
|
|
|
g_set_error (error, COGL_WINSYS_ERROR,
|
2016-05-09 07:51:29 -04:00
|
|
|
COGL_WINSYS_ERROR_CREATE_CONTEXT,
|
|
|
|
"Failed to make context current");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-06-01 05:53:07 -04:00
|
|
|
meta_renderer_native_egl_cleanup_context (CoglDisplay *cogl_display)
|
2016-05-09 07:51:29 -04:00
|
|
|
{
|
2017-07-14 03:20:41 -04:00
|
|
|
CoglDisplayEGL *cogl_display_egl = cogl_display->winsys;
|
2016-06-01 05:53:07 -04:00
|
|
|
CoglRenderer *cogl_renderer = cogl_display->renderer;
|
2017-07-14 03:20:41 -04:00
|
|
|
CoglRendererEGL *cogl_renderer_egl = cogl_renderer->winsys;
|
2017-07-24 22:21:04 -04:00
|
|
|
MetaRendererNativeGpuData *renderer_gpu_data = cogl_renderer_egl->platform;
|
|
|
|
MetaRendererNative *renderer_native = renderer_gpu_data->renderer_native;
|
2017-07-24 04:19:55 -04:00
|
|
|
MetaEgl *egl = meta_renderer_native_get_egl (renderer_native);
|
2016-05-09 07:51:29 -04:00
|
|
|
|
2017-07-14 03:20:41 -04:00
|
|
|
if (cogl_display_egl->dummy_surface != EGL_NO_SURFACE)
|
2016-05-09 07:51:29 -04:00
|
|
|
{
|
2017-07-24 04:19:55 -04:00
|
|
|
meta_egl_destroy_surface (egl,
|
|
|
|
cogl_renderer_egl->edpy,
|
|
|
|
cogl_display_egl->dummy_surface,
|
|
|
|
NULL);
|
2017-07-14 03:20:41 -04:00
|
|
|
cogl_display_egl->dummy_surface = EGL_NO_SURFACE;
|
2016-05-09 07:51:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-24 22:21:04 -04:00
|
|
|
static void
|
2020-01-17 15:08:02 -05:00
|
|
|
swap_secondary_drm_fb (CoglOnscreen *onscreen)
|
2017-07-24 22:21:04 -04:00
|
|
|
{
|
2020-01-17 15:08:02 -05:00
|
|
|
CoglOnscreenEGL *onscreen_egl = onscreen->winsys;
|
|
|
|
MetaOnscreenNative *onscreen_native = onscreen_egl->platform;
|
|
|
|
MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state;
|
|
|
|
|
|
|
|
secondary_gpu_state = onscreen_native->secondary_gpu_state;
|
|
|
|
if (!secondary_gpu_state)
|
|
|
|
return;
|
|
|
|
|
2018-01-30 04:47:17 -05:00
|
|
|
g_set_object (&secondary_gpu_state->gbm.current_fb,
|
|
|
|
secondary_gpu_state->gbm.next_fb);
|
|
|
|
g_clear_object (&secondary_gpu_state->gbm.next_fb);
|
2017-07-24 22:21:04 -04:00
|
|
|
}
|
|
|
|
|
2016-05-12 02:55:06 -04:00
|
|
|
static void
|
2016-06-08 05:05:31 -04:00
|
|
|
meta_onscreen_native_swap_drm_fb (CoglOnscreen *onscreen)
|
2016-05-12 02:55:06 -04:00
|
|
|
{
|
2017-07-14 03:20:41 -04:00
|
|
|
CoglOnscreenEGL *onscreen_egl = onscreen->winsys;
|
|
|
|
MetaOnscreenNative *onscreen_native = onscreen_egl->platform;
|
2016-05-12 02:55:06 -04:00
|
|
|
|
|
|
|
free_current_bo (onscreen);
|
|
|
|
|
2018-01-30 04:47:17 -05:00
|
|
|
g_set_object (&onscreen_native->gbm.current_fb, onscreen_native->gbm.next_fb);
|
|
|
|
g_clear_object (&onscreen_native->gbm.next_fb);
|
2017-07-24 22:21:04 -04:00
|
|
|
|
2020-01-17 15:08:02 -05:00
|
|
|
swap_secondary_drm_fb (onscreen);
|
2016-06-08 05:05:31 -04:00
|
|
|
}
|
2016-05-12 02:55:06 -04:00
|
|
|
|
2016-06-08 05:05:31 -04:00
|
|
|
static void
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
notify_view_crtc_presented (MetaRendererView *view,
|
|
|
|
MetaKmsCrtc *kms_crtc,
|
|
|
|
int64_t time_ns)
|
2016-06-08 05:05:31 -04:00
|
|
|
{
|
|
|
|
ClutterStageView *stage_view = CLUTTER_STAGE_VIEW (view);
|
|
|
|
CoglFramebuffer *framebuffer =
|
2016-07-31 20:44:57 -04:00
|
|
|
clutter_stage_view_get_onscreen (stage_view);
|
2016-06-08 05:05:31 -04:00
|
|
|
CoglOnscreen *onscreen = COGL_ONSCREEN (framebuffer);
|
2017-07-14 03:20:41 -04:00
|
|
|
CoglOnscreenEGL *onscreen_egl = onscreen->winsys;
|
|
|
|
MetaOnscreenNative *onscreen_native = onscreen_egl->platform;
|
2017-07-24 22:21:04 -04:00
|
|
|
MetaRendererNative *renderer_native = onscreen_native->renderer_native;
|
|
|
|
MetaGpuKms *render_gpu = onscreen_native->render_gpu;
|
2018-06-27 05:19:27 -04:00
|
|
|
CoglFrameInfo *frame_info;
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
MetaCrtc *crtc;
|
2018-06-27 05:19:27 -04:00
|
|
|
float refresh_rate;
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
MetaGpuKms *gpu_kms;
|
2018-06-27 05:19:27 -04:00
|
|
|
|
|
|
|
/* Only keep the frame info for the fastest CRTC in use, which may not be
|
|
|
|
* the first one to complete a flip. By only telling the compositor about the
|
|
|
|
* fastest monitor(s) we direct it to produce new frames fast enough to
|
|
|
|
* satisfy all monitors.
|
|
|
|
*/
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
frame_info = g_queue_peek_tail (&onscreen->pending_frame_infos);
|
|
|
|
|
|
|
|
crtc = meta_crtc_kms_from_kms_crtc (kms_crtc);
|
2020-01-14 16:34:44 -05:00
|
|
|
refresh_rate = crtc && crtc->config ?
|
|
|
|
crtc->config->mode->refresh_rate :
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
0.0f;
|
2018-06-27 05:19:27 -04:00
|
|
|
if (refresh_rate >= frame_info->refresh_rate)
|
|
|
|
{
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
frame_info->presentation_time = time_ns;
|
2018-06-27 05:19:27 -04:00
|
|
|
frame_info->refresh_rate = refresh_rate;
|
|
|
|
}
|
2017-07-24 22:21:04 -04:00
|
|
|
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
gpu_kms = META_GPU_KMS (meta_crtc_get_gpu (crtc));
|
2017-07-24 22:21:04 -04:00
|
|
|
if (gpu_kms != render_gpu)
|
|
|
|
{
|
2020-01-17 15:08:02 -05:00
|
|
|
MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state =
|
|
|
|
onscreen_native->secondary_gpu_state;
|
2016-06-08 05:05:31 -04:00
|
|
|
|
2017-07-24 22:21:04 -04:00
|
|
|
secondary_gpu_state->pending_flips--;
|
|
|
|
}
|
|
|
|
|
|
|
|
onscreen_native->total_pending_flips--;
|
|
|
|
if (onscreen_native->total_pending_flips == 0)
|
2016-06-08 05:05:31 -04:00
|
|
|
{
|
2017-07-10 06:19:32 -04:00
|
|
|
MetaRendererNativeGpuData *renderer_gpu_data;
|
|
|
|
|
2016-06-08 05:05:31 -04:00
|
|
|
meta_onscreen_native_queue_swap_notify (onscreen);
|
2016-08-17 23:28:59 -04:00
|
|
|
|
2017-07-10 06:19:32 -04:00
|
|
|
renderer_gpu_data =
|
|
|
|
meta_renderer_native_get_gpu_data (renderer_native,
|
2017-07-24 22:21:04 -04:00
|
|
|
onscreen_native->render_gpu);
|
2017-07-10 06:19:32 -04:00
|
|
|
switch (renderer_gpu_data->mode)
|
2016-08-17 23:28:59 -04:00
|
|
|
{
|
|
|
|
case META_RENDERER_NATIVE_MODE_GBM:
|
|
|
|
meta_onscreen_native_swap_drm_fb (onscreen);
|
|
|
|
break;
|
|
|
|
#ifdef HAVE_EGL_DEVICE
|
|
|
|
case META_RENDERER_NATIVE_MODE_EGL_DEVICE:
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
}
|
2016-06-08 05:05:31 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
static int64_t
|
|
|
|
timeval_to_nanoseconds (const struct timeval *tv)
|
|
|
|
{
|
|
|
|
int64_t usec = ((int64_t) tv->tv_sec) * G_USEC_PER_SEC + tv->tv_usec;
|
|
|
|
int64_t nsec = usec * 1000;
|
|
|
|
|
|
|
|
return nsec;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
page_flip_feedback_flipped (MetaKmsCrtc *kms_crtc,
|
|
|
|
unsigned int sequence,
|
|
|
|
unsigned int tv_sec,
|
|
|
|
unsigned int tv_usec,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
MetaRendererView *view = user_data;
|
|
|
|
struct timeval page_flip_time;
|
|
|
|
|
|
|
|
page_flip_time = (struct timeval) {
|
|
|
|
.tv_sec = tv_sec,
|
|
|
|
.tv_usec = tv_usec,
|
|
|
|
};
|
|
|
|
|
|
|
|
notify_view_crtc_presented (view, kms_crtc,
|
|
|
|
timeval_to_nanoseconds (&page_flip_time));
|
|
|
|
|
|
|
|
g_object_unref (view);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
page_flip_feedback_mode_set_fallback (MetaKmsCrtc *kms_crtc,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
MetaRendererView *view = user_data;
|
|
|
|
MetaCrtc *crtc;
|
|
|
|
MetaGpuKms *gpu_kms;
|
|
|
|
int64_t now_ns;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We ended up not page flipping, thus we don't have a presentation time to
|
|
|
|
* use. Lets use the next best thing: the current time.
|
|
|
|
*/
|
|
|
|
|
|
|
|
crtc = meta_crtc_kms_from_kms_crtc (kms_crtc);
|
|
|
|
gpu_kms = META_GPU_KMS (meta_crtc_get_gpu (crtc));
|
|
|
|
now_ns = meta_gpu_kms_get_current_time_ns (gpu_kms);
|
|
|
|
|
|
|
|
notify_view_crtc_presented (view, kms_crtc, now_ns);
|
|
|
|
|
|
|
|
g_object_unref (view);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
page_flip_feedback_discarded (MetaKmsCrtc *kms_crtc,
|
|
|
|
gpointer user_data,
|
|
|
|
const GError *error)
|
|
|
|
{
|
|
|
|
MetaRendererView *view = user_data;
|
|
|
|
MetaCrtc *crtc;
|
|
|
|
MetaGpuKms *gpu_kms;
|
|
|
|
int64_t now_ns;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Page flipping failed, but we want to fail gracefully, so to avoid freezing
|
|
|
|
* the frame clack, pretend we flipped.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (error)
|
|
|
|
g_warning ("Page flip discarded: %s", error->message);
|
|
|
|
|
|
|
|
crtc = meta_crtc_kms_from_kms_crtc (kms_crtc);
|
|
|
|
gpu_kms = META_GPU_KMS (meta_crtc_get_gpu (crtc));
|
|
|
|
now_ns = meta_gpu_kms_get_current_time_ns (gpu_kms);
|
|
|
|
|
|
|
|
notify_view_crtc_presented (view, kms_crtc, now_ns);
|
|
|
|
|
|
|
|
g_object_unref (view);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const MetaKmsPageFlipFeedback page_flip_feedback = {
|
|
|
|
.flipped = page_flip_feedback_flipped,
|
|
|
|
.mode_set_fallback = page_flip_feedback_mode_set_fallback,
|
|
|
|
.discarded = page_flip_feedback_discarded,
|
|
|
|
};
|
|
|
|
|
2016-08-17 23:28:59 -04:00
|
|
|
#ifdef HAVE_EGL_DEVICE
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
static int
|
|
|
|
custom_egl_stream_page_flip (gpointer custom_page_flip_data,
|
|
|
|
gpointer user_data)
|
2016-08-17 23:28:59 -04:00
|
|
|
{
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
MetaOnscreenNative *onscreen_native = custom_page_flip_data;
|
|
|
|
MetaRendererView *view = user_data;
|
|
|
|
MetaEgl *egl = meta_onscreen_native_get_egl (onscreen_native);
|
2017-07-10 06:19:32 -04:00
|
|
|
MetaRendererNativeGpuData *renderer_gpu_data;
|
2017-07-24 22:21:04 -04:00
|
|
|
EGLDisplay *egl_display;
|
2016-08-17 23:28:59 -04:00
|
|
|
EGLAttrib *acquire_attribs;
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
g_autoptr (GError) error = NULL;
|
2017-11-14 03:08:52 -05:00
|
|
|
|
2016-08-17 23:28:59 -04:00
|
|
|
acquire_attribs = (EGLAttrib[]) {
|
|
|
|
EGL_DRM_FLIP_EVENT_DATA_NV,
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
(EGLAttrib) view,
|
2016-08-17 23:28:59 -04:00
|
|
|
EGL_NONE
|
|
|
|
};
|
2017-02-01 21:15:53 -05:00
|
|
|
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
renderer_gpu_data =
|
|
|
|
meta_renderer_native_get_gpu_data (onscreen_native->renderer_native,
|
|
|
|
onscreen_native->render_gpu);
|
|
|
|
|
2017-07-24 22:21:04 -04:00
|
|
|
egl_display = renderer_gpu_data->egl_display;
|
2016-08-17 23:28:59 -04:00
|
|
|
if (!meta_egl_stream_consumer_acquire_attrib (egl,
|
2017-07-24 22:21:04 -04:00
|
|
|
egl_display,
|
2016-08-17 23:28:59 -04:00
|
|
|
onscreen_native->egl.stream,
|
|
|
|
acquire_attribs,
|
|
|
|
&error))
|
|
|
|
{
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
if (g_error_matches (error, META_EGL_ERROR, EGL_RESOURCE_BUSY_EXT))
|
|
|
|
return -EBUSY;
|
|
|
|
else
|
|
|
|
return -EINVAL;
|
2016-08-17 23:28:59 -04:00
|
|
|
}
|
|
|
|
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
return 0;
|
2016-08-17 23:28:59 -04:00
|
|
|
}
|
|
|
|
#endif /* HAVE_EGL_DEVICE */
|
|
|
|
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
static void
|
|
|
|
dummy_power_save_page_flip (CoglOnscreen *onscreen)
|
2019-02-12 13:10:59 -05:00
|
|
|
{
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
meta_onscreen_native_swap_drm_fb (onscreen);
|
|
|
|
meta_onscreen_native_queue_swap_notify (onscreen);
|
2019-02-12 13:10:59 -05:00
|
|
|
}
|
|
|
|
|
2019-03-25 05:24:46 -04:00
|
|
|
static gboolean
|
|
|
|
dummy_power_save_page_flip_cb (gpointer user_data)
|
|
|
|
{
|
|
|
|
MetaRendererNative *renderer_native = user_data;
|
|
|
|
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
g_list_foreach (renderer_native->power_save_page_flip_onscreens,
|
|
|
|
(GFunc) dummy_power_save_page_flip, NULL);
|
|
|
|
g_list_free_full (renderer_native->power_save_page_flip_onscreens,
|
|
|
|
(GDestroyNotify) cogl_object_unref);
|
|
|
|
renderer_native->power_save_page_flip_onscreens = NULL;
|
2019-03-25 05:24:46 -04:00
|
|
|
renderer_native->power_save_page_flip_source_id = 0;
|
|
|
|
|
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
queue_dummy_power_save_page_flip (CoglOnscreen *onscreen)
|
2019-03-25 05:24:46 -04:00
|
|
|
{
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
CoglOnscreenEGL *onscreen_egl = onscreen->winsys;
|
|
|
|
MetaOnscreenNative *onscreen_native = onscreen_egl->platform;
|
|
|
|
MetaRendererNative *renderer_native = onscreen_native->renderer_native;
|
2019-03-25 05:24:46 -04:00
|
|
|
const unsigned int timeout_ms = 100;
|
|
|
|
|
|
|
|
if (!renderer_native->power_save_page_flip_source_id)
|
|
|
|
{
|
|
|
|
renderer_native->power_save_page_flip_source_id =
|
|
|
|
g_timeout_add (timeout_ms,
|
|
|
|
dummy_power_save_page_flip_cb,
|
|
|
|
renderer_native);
|
|
|
|
}
|
|
|
|
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
renderer_native->power_save_page_flip_onscreens =
|
|
|
|
g_list_prepend (renderer_native->power_save_page_flip_onscreens,
|
|
|
|
cogl_object_ref (onscreen));
|
2019-02-12 13:10:59 -05:00
|
|
|
}
|
|
|
|
|
2016-06-08 05:05:31 -04:00
|
|
|
static void
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
meta_onscreen_native_flip_crtc (CoglOnscreen *onscreen,
|
|
|
|
MetaRendererView *view,
|
|
|
|
MetaCrtc *crtc,
|
|
|
|
MetaKmsUpdate *kms_update)
|
2017-07-24 22:21:04 -04:00
|
|
|
{
|
|
|
|
CoglOnscreenEGL *onscreen_egl = onscreen->winsys;
|
|
|
|
MetaOnscreenNative *onscreen_native = onscreen_egl->platform;
|
|
|
|
MetaRendererNative *renderer_native = onscreen_native->renderer_native;
|
|
|
|
MetaGpuKms *render_gpu = onscreen_native->render_gpu;
|
2017-07-10 06:19:32 -04:00
|
|
|
MetaRendererNativeGpuData *renderer_gpu_data;
|
2017-07-24 22:21:04 -04:00
|
|
|
MetaGpuKms *gpu_kms;
|
|
|
|
MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state = NULL;
|
|
|
|
uint32_t fb_id;
|
2016-06-08 05:05:31 -04:00
|
|
|
|
2017-07-24 22:21:04 -04:00
|
|
|
gpu_kms = META_GPU_KMS (meta_crtc_get_gpu (crtc));
|
2019-03-25 05:24:46 -04:00
|
|
|
|
|
|
|
g_assert (meta_gpu_kms_is_crtc_active (gpu_kms, crtc));
|
2016-06-08 05:05:31 -04:00
|
|
|
|
2017-07-10 06:19:32 -04:00
|
|
|
renderer_gpu_data = meta_renderer_native_get_gpu_data (renderer_native,
|
2017-07-24 22:21:04 -04:00
|
|
|
render_gpu);
|
2017-07-10 06:19:32 -04:00
|
|
|
switch (renderer_gpu_data->mode)
|
2016-08-17 23:28:59 -04:00
|
|
|
{
|
|
|
|
case META_RENDERER_NATIVE_MODE_GBM:
|
2017-07-24 22:21:04 -04:00
|
|
|
if (gpu_kms == render_gpu)
|
|
|
|
{
|
2019-05-20 15:20:17 -04:00
|
|
|
fb_id = meta_drm_buffer_get_fb_id (onscreen_native->gbm.next_fb);
|
2017-07-24 22:21:04 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-17 15:08:02 -05:00
|
|
|
secondary_gpu_state = onscreen_native->secondary_gpu_state;
|
2019-05-20 15:20:17 -04:00
|
|
|
fb_id = meta_drm_buffer_get_fb_id (secondary_gpu_state->gbm.next_fb);
|
2017-07-24 22:21:04 -04:00
|
|
|
}
|
|
|
|
|
2020-01-17 15:08:02 -05:00
|
|
|
meta_crtc_kms_assign_primary_plane (crtc, fb_id, kms_update);
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
meta_crtc_kms_page_flip (crtc,
|
|
|
|
&page_flip_feedback,
|
|
|
|
g_object_ref (view),
|
|
|
|
kms_update);
|
2017-07-24 22:21:04 -04:00
|
|
|
|
|
|
|
onscreen_native->total_pending_flips++;
|
|
|
|
if (secondary_gpu_state)
|
|
|
|
secondary_gpu_state->pending_flips++;
|
|
|
|
|
2016-08-17 23:28:59 -04:00
|
|
|
break;
|
|
|
|
#ifdef HAVE_EGL_DEVICE
|
|
|
|
case META_RENDERER_NATIVE_MODE_EGL_DEVICE:
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
meta_kms_update_custom_page_flip (kms_update,
|
|
|
|
meta_crtc_kms_get_kms_crtc (crtc),
|
|
|
|
&page_flip_feedback,
|
|
|
|
g_object_ref (view),
|
|
|
|
custom_egl_stream_page_flip,
|
|
|
|
onscreen_native);
|
|
|
|
onscreen_native->total_pending_flips++;
|
2016-08-17 23:28:59 -04:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
}
|
2019-02-12 13:10:59 -05:00
|
|
|
}
|
2017-03-28 00:17:38 -04:00
|
|
|
|
2016-06-08 05:05:31 -04:00
|
|
|
static void
|
2020-01-17 15:08:02 -05:00
|
|
|
meta_onscreen_native_set_crtc_mode (CoglOnscreen *onscreen,
|
|
|
|
MetaRendererNativeGpuData *renderer_gpu_data,
|
|
|
|
MetaKmsUpdate *kms_update)
|
2016-06-08 05:05:31 -04:00
|
|
|
{
|
2020-01-17 15:08:02 -05:00
|
|
|
CoglOnscreenEGL *onscreen_egl = onscreen->winsys;
|
|
|
|
MetaOnscreenNative *onscreen_native = onscreen_egl->platform;
|
|
|
|
|
|
|
|
COGL_TRACE_BEGIN_SCOPED (MetaOnscreenNativeSetCrtcModes,
|
|
|
|
"Onscreen (set CRTC modes)");
|
2016-06-08 05:05:31 -04:00
|
|
|
|
2020-01-17 15:08:02 -05:00
|
|
|
switch (renderer_gpu_data->mode)
|
2016-08-17 23:28:59 -04:00
|
|
|
{
|
|
|
|
case META_RENDERER_NATIVE_MODE_GBM:
|
|
|
|
break;
|
|
|
|
#ifdef HAVE_EGL_DEVICE
|
|
|
|
case META_RENDERER_NATIVE_MODE_EGL_DEVICE:
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
{
|
|
|
|
uint32_t fb_id;
|
2017-03-28 00:17:38 -04:00
|
|
|
|
2020-01-17 15:08:02 -05:00
|
|
|
fb_id = onscreen_native->egl.dumb_fb.fb_id;
|
|
|
|
meta_crtc_kms_assign_primary_plane (onscreen_native->crtc,
|
|
|
|
fb_id, kms_update);
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2016-06-08 05:05:31 -04:00
|
|
|
}
|
|
|
|
|
2020-01-17 15:08:02 -05:00
|
|
|
meta_crtc_kms_set_mode (onscreen_native->crtc, kms_update);
|
|
|
|
meta_output_kms_set_underscan (onscreen_native->output, kms_update);
|
2017-03-28 00:17:38 -04:00
|
|
|
}
|
|
|
|
|
2016-06-08 05:05:31 -04:00
|
|
|
static void
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
meta_onscreen_native_flip_crtcs (CoglOnscreen *onscreen,
|
|
|
|
MetaKmsUpdate *kms_update)
|
2016-06-08 05:05:31 -04:00
|
|
|
{
|
2017-07-14 03:20:41 -04:00
|
|
|
CoglOnscreenEGL *onscreen_egl = onscreen->winsys;
|
|
|
|
MetaOnscreenNative *onscreen_native = onscreen_egl->platform;
|
2016-06-08 05:05:31 -04:00
|
|
|
MetaRendererView *view = onscreen_native->view;
|
2019-03-25 05:24:46 -04:00
|
|
|
MetaRendererNative *renderer_native = onscreen_native->renderer_native;
|
2019-10-01 05:51:53 -04:00
|
|
|
MetaRenderer *renderer = META_RENDERER (renderer_native);
|
2019-03-25 05:24:46 -04:00
|
|
|
MetaMonitorManager *monitor_manager =
|
2019-10-01 05:51:53 -04:00
|
|
|
meta_backend_get_monitor_manager (meta_renderer_get_backend (renderer));
|
2019-03-25 05:24:46 -04:00
|
|
|
MetaPowerSave power_save_mode;
|
2016-06-08 05:05:31 -04:00
|
|
|
|
2019-08-27 06:11:07 -04:00
|
|
|
COGL_TRACE_BEGIN_SCOPED (MetaOnscreenNativeFlipCrtcs,
|
|
|
|
"Onscreen (flip CRTCs)");
|
|
|
|
|
2019-03-25 05:24:46 -04:00
|
|
|
power_save_mode = meta_monitor_manager_get_power_save_mode (monitor_manager);
|
|
|
|
if (power_save_mode == META_POWER_SAVE_ON)
|
|
|
|
{
|
2020-01-17 15:08:02 -05:00
|
|
|
meta_onscreen_native_flip_crtc (onscreen, view, onscreen_native->crtc,
|
|
|
|
kms_update);
|
2019-03-25 05:24:46 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
queue_dummy_power_save_page_flip (onscreen);
|
2019-03-25 05:24:46 -04:00
|
|
|
}
|
2017-07-24 22:21:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
wait_for_pending_flips (CoglOnscreen *onscreen)
|
|
|
|
{
|
|
|
|
CoglOnscreenEGL *onscreen_egl = onscreen->winsys;
|
|
|
|
MetaOnscreenNative *onscreen_native = onscreen_egl->platform;
|
|
|
|
MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state;
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
GError *error = NULL;
|
2017-07-24 22:21:04 -04:00
|
|
|
|
2020-01-17 15:08:02 -05:00
|
|
|
secondary_gpu_state = onscreen_native->secondary_gpu_state;
|
|
|
|
if (secondary_gpu_state)
|
2017-07-24 22:21:04 -04:00
|
|
|
{
|
|
|
|
while (secondary_gpu_state->pending_flips)
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
{
|
|
|
|
if (!meta_gpu_kms_wait_for_flip (secondary_gpu_state->gpu_kms, &error))
|
|
|
|
{
|
|
|
|
g_warning ("Failed to wait for flip on secondary GPU: %s",
|
|
|
|
error->message);
|
|
|
|
g_clear_error (&error);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-07-24 22:21:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
while (onscreen_native->total_pending_flips)
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
{
|
|
|
|
if (!meta_gpu_kms_wait_for_flip (onscreen_native->render_gpu, &error))
|
|
|
|
{
|
|
|
|
g_warning ("Failed to wait for flip: %s", error->message);
|
|
|
|
g_clear_error (&error);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-07-24 22:21:04 -04:00
|
|
|
}
|
|
|
|
|
2019-05-24 10:07:14 -04:00
|
|
|
static gboolean
|
|
|
|
import_shared_framebuffer (CoglOnscreen *onscreen,
|
|
|
|
MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state)
|
|
|
|
{
|
|
|
|
CoglOnscreenEGL *onscreen_egl = onscreen->winsys;
|
|
|
|
MetaOnscreenNative *onscreen_native = onscreen_egl->platform;
|
|
|
|
MetaDrmBufferGbm *buffer_gbm;
|
|
|
|
MetaDrmBufferImport *buffer_import;
|
|
|
|
g_autoptr (GError) error = NULL;
|
|
|
|
|
|
|
|
buffer_gbm = META_DRM_BUFFER_GBM (onscreen_native->gbm.next_fb);
|
|
|
|
|
|
|
|
buffer_import = meta_drm_buffer_import_new (secondary_gpu_state->gpu_kms,
|
|
|
|
buffer_gbm,
|
|
|
|
&error);
|
|
|
|
if (!buffer_import)
|
|
|
|
{
|
|
|
|
g_debug ("Zero-copy disabled for %s, meta_drm_buffer_import_new failed: %s",
|
|
|
|
meta_gpu_kms_get_file_path (secondary_gpu_state->gpu_kms),
|
|
|
|
error->message);
|
|
|
|
|
|
|
|
g_warn_if_fail (secondary_gpu_state->import_status ==
|
|
|
|
META_SHARED_FRAMEBUFFER_IMPORT_STATUS_NONE);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fall back. If META_SHARED_FRAMEBUFFER_IMPORT_STATUS_NONE is
|
|
|
|
* in effect, we have COPY_MODE_PRIMARY prepared already, so we
|
|
|
|
* simply retry with that path. Import status cannot be FAILED,
|
|
|
|
* because we should not retry if failed once.
|
|
|
|
*
|
|
|
|
* If import status is OK, that is unexpected and we do not
|
|
|
|
* have the fallback path prepared which means this output cannot
|
|
|
|
* work anymore.
|
|
|
|
*/
|
|
|
|
secondary_gpu_state->renderer_gpu_data->secondary.copy_mode =
|
|
|
|
META_SHARED_FRAMEBUFFER_COPY_MODE_PRIMARY;
|
|
|
|
|
|
|
|
secondary_gpu_state->import_status =
|
|
|
|
META_SHARED_FRAMEBUFFER_IMPORT_STATUS_FAILED;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* next_fb may already contain a fallback buffer, so clear it only
|
|
|
|
* when we are sure to succeed.
|
|
|
|
*/
|
|
|
|
g_clear_object (&secondary_gpu_state->gbm.next_fb);
|
|
|
|
secondary_gpu_state->gbm.next_fb = META_DRM_BUFFER (buffer_import);
|
|
|
|
|
|
|
|
if (secondary_gpu_state->import_status ==
|
|
|
|
META_SHARED_FRAMEBUFFER_IMPORT_STATUS_NONE)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Clean up the cpu-copy part of
|
|
|
|
* init_secondary_gpu_state_cpu_copy_mode ()
|
|
|
|
*/
|
|
|
|
secondary_gpu_release_dumb (secondary_gpu_state);
|
|
|
|
|
|
|
|
g_debug ("Using zero-copy for %s succeeded once.",
|
|
|
|
meta_gpu_kms_get_file_path (secondary_gpu_state->gpu_kms));
|
|
|
|
}
|
|
|
|
|
|
|
|
secondary_gpu_state->import_status =
|
|
|
|
META_SHARED_FRAMEBUFFER_IMPORT_STATUS_OK;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-07-24 22:21:04 -04:00
|
|
|
static void
|
|
|
|
copy_shared_framebuffer_gpu (CoglOnscreen *onscreen,
|
|
|
|
MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state,
|
|
|
|
MetaRendererNativeGpuData *renderer_gpu_data,
|
|
|
|
gboolean *egl_context_changed)
|
|
|
|
{
|
|
|
|
CoglOnscreenEGL *onscreen_egl = onscreen->winsys;
|
|
|
|
MetaOnscreenNative *onscreen_native = onscreen_egl->platform;
|
|
|
|
MetaRendererNative *renderer_native = renderer_gpu_data->renderer_native;
|
|
|
|
MetaEgl *egl = meta_renderer_native_get_egl (renderer_native);
|
|
|
|
GError *error = NULL;
|
2019-05-20 16:08:35 -04:00
|
|
|
MetaDrmBufferGbm *buffer_gbm;
|
|
|
|
struct gbm_bo *bo;
|
2017-07-24 22:21:04 -04:00
|
|
|
|
2019-06-11 04:16:39 -04:00
|
|
|
COGL_TRACE_BEGIN_SCOPED (CopySharedFramebufferSecondaryGpu,
|
|
|
|
"FB Copy (secondary GPU)");
|
|
|
|
|
2019-12-02 07:00:56 -05:00
|
|
|
g_warn_if_fail (secondary_gpu_state->gbm.next_fb == NULL);
|
|
|
|
g_clear_object (&secondary_gpu_state->gbm.next_fb);
|
|
|
|
|
2017-07-24 22:21:04 -04:00
|
|
|
if (!meta_egl_make_current (egl,
|
|
|
|
renderer_gpu_data->egl_display,
|
|
|
|
secondary_gpu_state->egl_surface,
|
|
|
|
secondary_gpu_state->egl_surface,
|
|
|
|
renderer_gpu_data->secondary.egl_context,
|
|
|
|
&error))
|
|
|
|
{
|
|
|
|
g_warning ("Failed to make current: %s", error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
*egl_context_changed = TRUE;
|
|
|
|
|
2019-05-20 16:08:35 -04:00
|
|
|
buffer_gbm = META_DRM_BUFFER_GBM (onscreen_native->gbm.next_fb);
|
|
|
|
bo = meta_drm_buffer_gbm_get_bo (buffer_gbm);
|
2017-07-24 22:21:04 -04:00
|
|
|
if (!meta_renderer_native_gles3_blit_shared_bo (egl,
|
|
|
|
renderer_native->gles3,
|
|
|
|
renderer_gpu_data->egl_display,
|
|
|
|
renderer_gpu_data->secondary.egl_context,
|
|
|
|
secondary_gpu_state->egl_surface,
|
2019-05-20 16:08:35 -04:00
|
|
|
bo,
|
2017-07-24 22:21:04 -04:00
|
|
|
&error))
|
|
|
|
{
|
|
|
|
g_warning ("Failed to blit shared framebuffer: %s", error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!meta_egl_swap_buffers (egl,
|
|
|
|
renderer_gpu_data->egl_display,
|
|
|
|
secondary_gpu_state->egl_surface,
|
|
|
|
&error))
|
|
|
|
{
|
|
|
|
g_warning ("Failed to swap buffers: %s", error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-20 16:08:35 -04:00
|
|
|
buffer_gbm = meta_drm_buffer_gbm_new (secondary_gpu_state->gpu_kms,
|
|
|
|
secondary_gpu_state->gbm.surface,
|
|
|
|
renderer_native->use_modifiers,
|
|
|
|
&error);
|
2019-09-16 08:24:52 -04:00
|
|
|
if (!buffer_gbm)
|
2018-01-30 04:47:17 -05:00
|
|
|
{
|
2019-05-20 16:08:35 -04:00
|
|
|
g_warning ("meta_drm_buffer_gbm_new failed: %s",
|
2018-01-30 04:47:17 -05:00
|
|
|
error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
return;
|
|
|
|
}
|
2019-09-16 08:24:52 -04:00
|
|
|
|
|
|
|
secondary_gpu_state->gbm.next_fb = META_DRM_BUFFER (buffer_gbm);
|
2017-07-24 22:21:04 -04:00
|
|
|
}
|
|
|
|
|
2018-11-29 06:54:31 -05:00
|
|
|
static MetaDumbBuffer *
|
|
|
|
secondary_gpu_get_next_dumb_buffer (MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state)
|
|
|
|
{
|
|
|
|
MetaDumbBuffer *current_dumb_fb;
|
|
|
|
|
|
|
|
current_dumb_fb = secondary_gpu_state->cpu.dumb_fb;
|
|
|
|
if (current_dumb_fb == &secondary_gpu_state->cpu.dumb_fbs[0])
|
|
|
|
return &secondary_gpu_state->cpu.dumb_fbs[1];
|
|
|
|
else
|
|
|
|
return &secondary_gpu_state->cpu.dumb_fbs[0];
|
|
|
|
}
|
|
|
|
|
2019-12-09 08:04:56 -05:00
|
|
|
static CoglContext *
|
|
|
|
cogl_context_from_renderer_native (MetaRendererNative *renderer_native)
|
2018-11-29 06:34:40 -05:00
|
|
|
{
|
2019-12-09 08:04:56 -05:00
|
|
|
MetaRenderer *renderer = META_RENDERER (renderer_native);
|
|
|
|
MetaBackend *backend = meta_renderer_get_backend (renderer);
|
|
|
|
ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
|
|
|
|
|
|
|
|
return clutter_backend_get_cogl_context (clutter_backend);
|
|
|
|
}
|
|
|
|
|
|
|
|
static CoglFramebuffer *
|
|
|
|
create_dma_buf_framebuffer (MetaRendererNative *renderer_native,
|
|
|
|
int dmabuf_fd,
|
|
|
|
uint32_t width,
|
|
|
|
uint32_t height,
|
|
|
|
uint32_t stride,
|
|
|
|
uint32_t offset,
|
|
|
|
uint64_t modifier,
|
|
|
|
uint32_t drm_format,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
CoglContext *cogl_context =
|
|
|
|
cogl_context_from_renderer_native (renderer_native);
|
2018-11-29 06:34:40 -05:00
|
|
|
CoglDisplay *cogl_display = cogl_context->display;
|
|
|
|
CoglRenderer *cogl_renderer = cogl_display->renderer;
|
|
|
|
CoglRendererEGL *cogl_renderer_egl = cogl_renderer->winsys;
|
|
|
|
EGLDisplay egl_display = cogl_renderer_egl->edpy;
|
|
|
|
MetaEgl *egl = meta_renderer_native_get_egl (renderer_native);
|
|
|
|
EGLImageKHR egl_image;
|
|
|
|
uint32_t strides[1];
|
|
|
|
uint32_t offsets[1];
|
|
|
|
uint64_t modifiers[1];
|
|
|
|
CoglPixelFormat cogl_format;
|
2019-07-16 12:29:29 -04:00
|
|
|
CoglEglImageFlags flags;
|
2018-11-29 06:34:40 -05:00
|
|
|
CoglTexture2D *cogl_tex;
|
|
|
|
CoglOffscreen *cogl_fbo;
|
|
|
|
int ret;
|
|
|
|
|
2019-12-09 08:04:56 -05:00
|
|
|
ret = cogl_pixel_format_from_drm_format (drm_format, &cogl_format, NULL);
|
2018-11-29 06:34:40 -05:00
|
|
|
g_assert (ret);
|
|
|
|
|
2019-12-09 08:04:56 -05:00
|
|
|
strides[0] = stride;
|
|
|
|
offsets[0] = offset;
|
|
|
|
modifiers[0] = modifier;
|
2018-11-29 06:34:40 -05:00
|
|
|
egl_image = meta_egl_create_dmabuf_image (egl,
|
|
|
|
egl_display,
|
2019-12-09 08:04:56 -05:00
|
|
|
width,
|
|
|
|
height,
|
|
|
|
drm_format,
|
2018-11-29 06:34:40 -05:00
|
|
|
1 /* n_planes */,
|
|
|
|
&dmabuf_fd,
|
|
|
|
strides,
|
|
|
|
offsets,
|
|
|
|
modifiers,
|
2019-12-09 08:04:56 -05:00
|
|
|
error);
|
2018-11-29 06:34:40 -05:00
|
|
|
if (egl_image == EGL_NO_IMAGE_KHR)
|
2019-12-09 08:04:56 -05:00
|
|
|
return NULL;
|
2018-11-29 06:34:40 -05:00
|
|
|
|
2019-07-16 12:30:12 -04:00
|
|
|
flags = COGL_EGL_IMAGE_FLAG_NO_GET_DATA;
|
2018-11-29 06:34:40 -05:00
|
|
|
cogl_tex = cogl_egl_texture_2d_new_from_image (cogl_context,
|
2019-12-09 08:04:56 -05:00
|
|
|
width,
|
|
|
|
height,
|
2018-11-29 06:34:40 -05:00
|
|
|
cogl_format,
|
|
|
|
egl_image,
|
2019-07-16 12:29:29 -04:00
|
|
|
flags,
|
2019-12-09 08:04:56 -05:00
|
|
|
error);
|
2018-11-29 06:34:40 -05:00
|
|
|
|
|
|
|
meta_egl_destroy_image (egl, egl_display, egl_image, NULL);
|
|
|
|
|
|
|
|
if (!cogl_tex)
|
2019-12-09 08:04:56 -05:00
|
|
|
return NULL;
|
2018-11-29 06:34:40 -05:00
|
|
|
|
|
|
|
cogl_fbo = cogl_offscreen_new_with_texture (COGL_TEXTURE (cogl_tex));
|
|
|
|
cogl_object_unref (cogl_tex);
|
|
|
|
|
2019-12-09 08:04:56 -05:00
|
|
|
if (!cogl_framebuffer_allocate (COGL_FRAMEBUFFER (cogl_fbo), error))
|
2018-11-29 06:34:40 -05:00
|
|
|
{
|
|
|
|
cogl_object_unref (cogl_fbo);
|
2019-12-09 08:04:56 -05:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return COGL_FRAMEBUFFER (cogl_fbo);
|
|
|
|
}
|
2018-11-29 06:34:40 -05:00
|
|
|
|
2019-12-09 08:04:56 -05:00
|
|
|
static gboolean
|
|
|
|
copy_shared_framebuffer_primary_gpu (CoglOnscreen *onscreen,
|
|
|
|
MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state)
|
|
|
|
{
|
|
|
|
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
|
|
|
|
CoglOnscreenEGL *onscreen_egl = onscreen->winsys;
|
|
|
|
MetaOnscreenNative *onscreen_native = onscreen_egl->platform;
|
|
|
|
MetaRendererNative *renderer_native = onscreen_native->renderer_native;
|
|
|
|
MetaRendererNativeGpuData *primary_gpu_data;
|
|
|
|
MetaDrmBufferDumb *buffer_dumb;
|
|
|
|
MetaDumbBuffer *dumb_fb;
|
|
|
|
CoglFramebuffer *dmabuf_fb;
|
|
|
|
int dmabuf_fd;
|
|
|
|
g_autoptr (GError) error = NULL;
|
|
|
|
CoglPixelFormat cogl_format;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
COGL_TRACE_BEGIN_SCOPED (CopySharedFramebufferPrimaryGpu,
|
|
|
|
"FB Copy (primary GPU)");
|
|
|
|
|
|
|
|
primary_gpu_data =
|
|
|
|
meta_renderer_native_get_gpu_data (renderer_native,
|
|
|
|
renderer_native->primary_gpu_kms);
|
|
|
|
if (!primary_gpu_data->secondary.has_EGL_EXT_image_dma_buf_import_modifiers)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
dumb_fb = secondary_gpu_get_next_dumb_buffer (secondary_gpu_state);
|
|
|
|
|
|
|
|
g_assert (cogl_framebuffer_get_width (framebuffer) == dumb_fb->width);
|
|
|
|
g_assert (cogl_framebuffer_get_height (framebuffer) == dumb_fb->height);
|
|
|
|
|
|
|
|
ret = cogl_pixel_format_from_drm_format (dumb_fb->drm_format,
|
|
|
|
&cogl_format,
|
|
|
|
NULL);
|
|
|
|
g_assert (ret);
|
|
|
|
|
|
|
|
dmabuf_fd = meta_dumb_buffer_ensure_dmabuf_fd (dumb_fb,
|
|
|
|
secondary_gpu_state->gpu_kms);
|
|
|
|
if (dmabuf_fd == -1)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
dmabuf_fb = create_dma_buf_framebuffer (renderer_native,
|
|
|
|
dmabuf_fd,
|
|
|
|
dumb_fb->width,
|
|
|
|
dumb_fb->height,
|
|
|
|
dumb_fb->stride_bytes,
|
|
|
|
0, DRM_FORMAT_MOD_LINEAR,
|
|
|
|
dumb_fb->drm_format,
|
|
|
|
&error);
|
|
|
|
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
g_debug ("%s: Failed to blit DMA buffer image: %s",
|
|
|
|
G_STRFUNC, error->message);
|
2018-11-29 06:34:40 -05:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-12-09 08:04:56 -05:00
|
|
|
if (!cogl_blit_framebuffer (framebuffer, COGL_FRAMEBUFFER (dmabuf_fb),
|
2018-11-29 06:34:40 -05:00
|
|
|
0, 0, 0, 0,
|
2019-12-09 08:04:56 -05:00
|
|
|
dumb_fb->width,
|
|
|
|
dumb_fb->height,
|
|
|
|
&error))
|
2018-11-29 06:34:40 -05:00
|
|
|
{
|
2019-12-09 08:04:56 -05:00
|
|
|
cogl_object_unref (dmabuf_fb);
|
2018-11-29 06:34:40 -05:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-12-09 08:04:56 -05:00
|
|
|
cogl_object_unref (dmabuf_fb);
|
2018-11-29 06:34:40 -05:00
|
|
|
|
|
|
|
g_clear_object (&secondary_gpu_state->gbm.next_fb);
|
|
|
|
buffer_dumb = meta_drm_buffer_dumb_new (dumb_fb->fb_id);
|
|
|
|
secondary_gpu_state->gbm.next_fb = META_DRM_BUFFER (buffer_dumb);
|
|
|
|
secondary_gpu_state->cpu.dumb_fb = dumb_fb;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
renderer/native: use cogl for CPU copy path
Use cogl_framebuffer_read_pixels_into_bitmap () instead of
glReadPixels () for the CPU copy path in multi-GPU support.
The cogl function employs several tricks to make the read-pixels as fast
as possible and does the y-flip as necessary. This should make the copy
more performant over all kinds of hardware.
This is expected to be used on virtual outputs (e.g. DisplayLink USB
docks and monitors) foremost, where the dumb buffer memory is just
regular system memory. If the dumb buffer memory is somehow slow, like
residing in discrete VRAM or having an unexpected caching mode, it may
be possible for the cogl function perform worse because it might do the
y-flip in-place in the dumb buffer. Hopefully that does not happen in
any practical scenario.
Calling meta_renderer_native_gles3_read_pixels () here was conceptually
wrong to begin with because it was done with the Cogl GL context of the
primary GPU, not on the GL ES 3 context of a secondary GPU. However,
due eglBindAPI being a no-op in Mesa and the glReadPixels () arguments
being compatible, it worked.
This patch adds a pixel format conversion table between DRM and Cogl
formats. It contains more formats than absolutely necessary and the
texture components field which is currently unused for completeness. See
Mutter issue #323. Making the table more complete documents better how
the pixel formats actually map so that posterity should be less likely
to be confused. This table could be shared with
shm_buffer_get_cogl_pixel_format () as well, but not with
meta_wayland_dma_buf_buffer_attach ().
On HP ProBook 4520s laptop (Mesa DRI Intel(R) Ironlake Mobile, Mesa
18.0.5), without this patch copy_shared_framebuffer_cpu () for a
DisplayLink output takes 5 seconds with a 1080p frame. Obviously that
makes Mutter and gnome-shell completely unusable. With this patch, that
function takes 13-18 ms which makes it usable if not fluent.
On Intel i7-4790 (Mesa DRI Intel(R) Haswell Desktop) machine, this patch
makes no significant difference (the copy takes 4-5 ms).
2018-09-27 09:42:19 -04:00
|
|
|
typedef struct _PixelFormatMap {
|
|
|
|
uint32_t drm_format;
|
|
|
|
CoglPixelFormat cogl_format;
|
|
|
|
CoglTextureComponents cogl_components;
|
|
|
|
} PixelFormatMap;
|
|
|
|
|
|
|
|
static const PixelFormatMap pixel_format_map[] = {
|
|
|
|
/* DRM formats are defined as little-endian, not machine endian. */
|
|
|
|
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
|
|
|
{ DRM_FORMAT_RGB565, COGL_PIXEL_FORMAT_RGB_565, COGL_TEXTURE_COMPONENTS_RGB },
|
|
|
|
{ DRM_FORMAT_ABGR8888, COGL_PIXEL_FORMAT_RGBA_8888_PRE, COGL_TEXTURE_COMPONENTS_RGBA },
|
|
|
|
{ DRM_FORMAT_XBGR8888, COGL_PIXEL_FORMAT_RGBA_8888_PRE, COGL_TEXTURE_COMPONENTS_RGB },
|
|
|
|
{ DRM_FORMAT_ARGB8888, COGL_PIXEL_FORMAT_BGRA_8888_PRE, COGL_TEXTURE_COMPONENTS_RGBA },
|
|
|
|
{ DRM_FORMAT_XRGB8888, COGL_PIXEL_FORMAT_BGRA_8888_PRE, COGL_TEXTURE_COMPONENTS_RGB },
|
|
|
|
{ DRM_FORMAT_BGRA8888, COGL_PIXEL_FORMAT_ARGB_8888_PRE, COGL_TEXTURE_COMPONENTS_RGBA },
|
|
|
|
{ DRM_FORMAT_BGRX8888, COGL_PIXEL_FORMAT_ARGB_8888_PRE, COGL_TEXTURE_COMPONENTS_RGB },
|
|
|
|
{ DRM_FORMAT_RGBA8888, COGL_PIXEL_FORMAT_ABGR_8888_PRE, COGL_TEXTURE_COMPONENTS_RGBA },
|
|
|
|
{ DRM_FORMAT_RGBX8888, COGL_PIXEL_FORMAT_ABGR_8888_PRE, COGL_TEXTURE_COMPONENTS_RGB },
|
|
|
|
#elif G_BYTE_ORDER == G_BIG_ENDIAN
|
|
|
|
/* DRM_FORMAT_RGB565 cannot be expressed. */
|
|
|
|
{ DRM_FORMAT_ABGR8888, COGL_PIXEL_FORMAT_ABGR_8888_PRE, COGL_TEXTURE_COMPONENTS_RGBA },
|
|
|
|
{ DRM_FORMAT_XBGR8888, COGL_PIXEL_FORMAT_ABGR_8888_PRE, COGL_TEXTURE_COMPONENTS_RGB },
|
|
|
|
{ DRM_FORMAT_ARGB8888, COGL_PIXEL_FORMAT_ARGB_8888_PRE, COGL_TEXTURE_COMPONENTS_RGBA },
|
|
|
|
{ DRM_FORMAT_XRGB8888, COGL_PIXEL_FORMAT_ARGB_8888_PRE, COGL_TEXTURE_COMPONENTS_RGB },
|
|
|
|
{ DRM_FORMAT_BGRA8888, COGL_PIXEL_FORMAT_BGRA_8888_PRE, COGL_TEXTURE_COMPONENTS_RGBA },
|
|
|
|
{ DRM_FORMAT_BGRX8888, COGL_PIXEL_FORMAT_BGRA_8888_PRE, COGL_TEXTURE_COMPONENTS_RGB },
|
|
|
|
{ DRM_FORMAT_RGBA8888, COGL_PIXEL_FORMAT_RGBA_8888_PRE, COGL_TEXTURE_COMPONENTS_RGBA },
|
|
|
|
{ DRM_FORMAT_RGBX8888, COGL_PIXEL_FORMAT_RGBA_8888_PRE, COGL_TEXTURE_COMPONENTS_RGB },
|
|
|
|
#else
|
|
|
|
#error "unexpected G_BYTE_ORDER"
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
cogl_pixel_format_from_drm_format (uint32_t drm_format,
|
|
|
|
CoglPixelFormat *out_format,
|
|
|
|
CoglTextureComponents *out_components)
|
|
|
|
{
|
|
|
|
const size_t n = G_N_ELEMENTS (pixel_format_map);
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
{
|
|
|
|
if (pixel_format_map[i].drm_format == drm_format)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == n)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (out_format)
|
|
|
|
*out_format = pixel_format_map[i].cogl_format;
|
|
|
|
|
|
|
|
if (out_components)
|
|
|
|
*out_components = pixel_format_map[i].cogl_components;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-07-24 22:21:04 -04:00
|
|
|
static void
|
|
|
|
copy_shared_framebuffer_cpu (CoglOnscreen *onscreen,
|
|
|
|
MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state,
|
|
|
|
MetaRendererNativeGpuData *renderer_gpu_data)
|
|
|
|
{
|
|
|
|
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
|
renderer/native: use cogl for CPU copy path
Use cogl_framebuffer_read_pixels_into_bitmap () instead of
glReadPixels () for the CPU copy path in multi-GPU support.
The cogl function employs several tricks to make the read-pixels as fast
as possible and does the y-flip as necessary. This should make the copy
more performant over all kinds of hardware.
This is expected to be used on virtual outputs (e.g. DisplayLink USB
docks and monitors) foremost, where the dumb buffer memory is just
regular system memory. If the dumb buffer memory is somehow slow, like
residing in discrete VRAM or having an unexpected caching mode, it may
be possible for the cogl function perform worse because it might do the
y-flip in-place in the dumb buffer. Hopefully that does not happen in
any practical scenario.
Calling meta_renderer_native_gles3_read_pixels () here was conceptually
wrong to begin with because it was done with the Cogl GL context of the
primary GPU, not on the GL ES 3 context of a secondary GPU. However,
due eglBindAPI being a no-op in Mesa and the glReadPixels () arguments
being compatible, it worked.
This patch adds a pixel format conversion table between DRM and Cogl
formats. It contains more formats than absolutely necessary and the
texture components field which is currently unused for completeness. See
Mutter issue #323. Making the table more complete documents better how
the pixel formats actually map so that posterity should be less likely
to be confused. This table could be shared with
shm_buffer_get_cogl_pixel_format () as well, but not with
meta_wayland_dma_buf_buffer_attach ().
On HP ProBook 4520s laptop (Mesa DRI Intel(R) Ironlake Mobile, Mesa
18.0.5), without this patch copy_shared_framebuffer_cpu () for a
DisplayLink output takes 5 seconds with a 1080p frame. Obviously that
makes Mutter and gnome-shell completely unusable. With this patch, that
function takes 13-18 ms which makes it usable if not fluent.
On Intel i7-4790 (Mesa DRI Intel(R) Haswell Desktop) machine, this patch
makes no significant difference (the copy takes 4-5 ms).
2018-09-27 09:42:19 -04:00
|
|
|
CoglContext *cogl_context = framebuffer->context;
|
2018-11-29 06:54:31 -05:00
|
|
|
MetaDumbBuffer *dumb_fb;
|
renderer/native: use cogl for CPU copy path
Use cogl_framebuffer_read_pixels_into_bitmap () instead of
glReadPixels () for the CPU copy path in multi-GPU support.
The cogl function employs several tricks to make the read-pixels as fast
as possible and does the y-flip as necessary. This should make the copy
more performant over all kinds of hardware.
This is expected to be used on virtual outputs (e.g. DisplayLink USB
docks and monitors) foremost, where the dumb buffer memory is just
regular system memory. If the dumb buffer memory is somehow slow, like
residing in discrete VRAM or having an unexpected caching mode, it may
be possible for the cogl function perform worse because it might do the
y-flip in-place in the dumb buffer. Hopefully that does not happen in
any practical scenario.
Calling meta_renderer_native_gles3_read_pixels () here was conceptually
wrong to begin with because it was done with the Cogl GL context of the
primary GPU, not on the GL ES 3 context of a secondary GPU. However,
due eglBindAPI being a no-op in Mesa and the glReadPixels () arguments
being compatible, it worked.
This patch adds a pixel format conversion table between DRM and Cogl
formats. It contains more formats than absolutely necessary and the
texture components field which is currently unused for completeness. See
Mutter issue #323. Making the table more complete documents better how
the pixel formats actually map so that posterity should be less likely
to be confused. This table could be shared with
shm_buffer_get_cogl_pixel_format () as well, but not with
meta_wayland_dma_buf_buffer_attach ().
On HP ProBook 4520s laptop (Mesa DRI Intel(R) Ironlake Mobile, Mesa
18.0.5), without this patch copy_shared_framebuffer_cpu () for a
DisplayLink output takes 5 seconds with a 1080p frame. Obviously that
makes Mutter and gnome-shell completely unusable. With this patch, that
function takes 13-18 ms which makes it usable if not fluent.
On Intel i7-4790 (Mesa DRI Intel(R) Haswell Desktop) machine, this patch
makes no significant difference (the copy takes 4-5 ms).
2018-09-27 09:42:19 -04:00
|
|
|
CoglBitmap *dumb_bitmap;
|
|
|
|
CoglPixelFormat cogl_format;
|
|
|
|
gboolean ret;
|
2019-05-20 16:08:35 -04:00
|
|
|
MetaDrmBufferDumb *buffer_dumb;
|
2017-07-24 22:21:04 -04:00
|
|
|
|
2019-06-11 04:16:39 -04:00
|
|
|
COGL_TRACE_BEGIN_SCOPED (CopySharedFramebufferCpu,
|
|
|
|
"FB Copy (CPU)");
|
|
|
|
|
2018-11-29 06:54:31 -05:00
|
|
|
dumb_fb = secondary_gpu_get_next_dumb_buffer (secondary_gpu_state);
|
2018-09-05 04:48:08 -04:00
|
|
|
|
2018-11-29 06:54:31 -05:00
|
|
|
g_assert (cogl_framebuffer_get_width (framebuffer) == dumb_fb->width);
|
|
|
|
g_assert (cogl_framebuffer_get_height (framebuffer) == dumb_fb->height);
|
renderer/native: use cogl for CPU copy path
Use cogl_framebuffer_read_pixels_into_bitmap () instead of
glReadPixels () for the CPU copy path in multi-GPU support.
The cogl function employs several tricks to make the read-pixels as fast
as possible and does the y-flip as necessary. This should make the copy
more performant over all kinds of hardware.
This is expected to be used on virtual outputs (e.g. DisplayLink USB
docks and monitors) foremost, where the dumb buffer memory is just
regular system memory. If the dumb buffer memory is somehow slow, like
residing in discrete VRAM or having an unexpected caching mode, it may
be possible for the cogl function perform worse because it might do the
y-flip in-place in the dumb buffer. Hopefully that does not happen in
any practical scenario.
Calling meta_renderer_native_gles3_read_pixels () here was conceptually
wrong to begin with because it was done with the Cogl GL context of the
primary GPU, not on the GL ES 3 context of a secondary GPU. However,
due eglBindAPI being a no-op in Mesa and the glReadPixels () arguments
being compatible, it worked.
This patch adds a pixel format conversion table between DRM and Cogl
formats. It contains more formats than absolutely necessary and the
texture components field which is currently unused for completeness. See
Mutter issue #323. Making the table more complete documents better how
the pixel formats actually map so that posterity should be less likely
to be confused. This table could be shared with
shm_buffer_get_cogl_pixel_format () as well, but not with
meta_wayland_dma_buf_buffer_attach ().
On HP ProBook 4520s laptop (Mesa DRI Intel(R) Ironlake Mobile, Mesa
18.0.5), without this patch copy_shared_framebuffer_cpu () for a
DisplayLink output takes 5 seconds with a 1080p frame. Obviously that
makes Mutter and gnome-shell completely unusable. With this patch, that
function takes 13-18 ms which makes it usable if not fluent.
On Intel i7-4790 (Mesa DRI Intel(R) Haswell Desktop) machine, this patch
makes no significant difference (the copy takes 4-5 ms).
2018-09-27 09:42:19 -04:00
|
|
|
|
2018-11-29 06:54:31 -05:00
|
|
|
ret = cogl_pixel_format_from_drm_format (dumb_fb->drm_format,
|
renderer/native: use cogl for CPU copy path
Use cogl_framebuffer_read_pixels_into_bitmap () instead of
glReadPixels () for the CPU copy path in multi-GPU support.
The cogl function employs several tricks to make the read-pixels as fast
as possible and does the y-flip as necessary. This should make the copy
more performant over all kinds of hardware.
This is expected to be used on virtual outputs (e.g. DisplayLink USB
docks and monitors) foremost, where the dumb buffer memory is just
regular system memory. If the dumb buffer memory is somehow slow, like
residing in discrete VRAM or having an unexpected caching mode, it may
be possible for the cogl function perform worse because it might do the
y-flip in-place in the dumb buffer. Hopefully that does not happen in
any practical scenario.
Calling meta_renderer_native_gles3_read_pixels () here was conceptually
wrong to begin with because it was done with the Cogl GL context of the
primary GPU, not on the GL ES 3 context of a secondary GPU. However,
due eglBindAPI being a no-op in Mesa and the glReadPixels () arguments
being compatible, it worked.
This patch adds a pixel format conversion table between DRM and Cogl
formats. It contains more formats than absolutely necessary and the
texture components field which is currently unused for completeness. See
Mutter issue #323. Making the table more complete documents better how
the pixel formats actually map so that posterity should be less likely
to be confused. This table could be shared with
shm_buffer_get_cogl_pixel_format () as well, but not with
meta_wayland_dma_buf_buffer_attach ().
On HP ProBook 4520s laptop (Mesa DRI Intel(R) Ironlake Mobile, Mesa
18.0.5), without this patch copy_shared_framebuffer_cpu () for a
DisplayLink output takes 5 seconds with a 1080p frame. Obviously that
makes Mutter and gnome-shell completely unusable. With this patch, that
function takes 13-18 ms which makes it usable if not fluent.
On Intel i7-4790 (Mesa DRI Intel(R) Haswell Desktop) machine, this patch
makes no significant difference (the copy takes 4-5 ms).
2018-09-27 09:42:19 -04:00
|
|
|
&cogl_format,
|
|
|
|
NULL);
|
|
|
|
g_assert (ret);
|
|
|
|
|
|
|
|
dumb_bitmap = cogl_bitmap_new_for_data (cogl_context,
|
2018-11-29 06:54:31 -05:00
|
|
|
dumb_fb->width,
|
|
|
|
dumb_fb->height,
|
renderer/native: use cogl for CPU copy path
Use cogl_framebuffer_read_pixels_into_bitmap () instead of
glReadPixels () for the CPU copy path in multi-GPU support.
The cogl function employs several tricks to make the read-pixels as fast
as possible and does the y-flip as necessary. This should make the copy
more performant over all kinds of hardware.
This is expected to be used on virtual outputs (e.g. DisplayLink USB
docks and monitors) foremost, where the dumb buffer memory is just
regular system memory. If the dumb buffer memory is somehow slow, like
residing in discrete VRAM or having an unexpected caching mode, it may
be possible for the cogl function perform worse because it might do the
y-flip in-place in the dumb buffer. Hopefully that does not happen in
any practical scenario.
Calling meta_renderer_native_gles3_read_pixels () here was conceptually
wrong to begin with because it was done with the Cogl GL context of the
primary GPU, not on the GL ES 3 context of a secondary GPU. However,
due eglBindAPI being a no-op in Mesa and the glReadPixels () arguments
being compatible, it worked.
This patch adds a pixel format conversion table between DRM and Cogl
formats. It contains more formats than absolutely necessary and the
texture components field which is currently unused for completeness. See
Mutter issue #323. Making the table more complete documents better how
the pixel formats actually map so that posterity should be less likely
to be confused. This table could be shared with
shm_buffer_get_cogl_pixel_format () as well, but not with
meta_wayland_dma_buf_buffer_attach ().
On HP ProBook 4520s laptop (Mesa DRI Intel(R) Ironlake Mobile, Mesa
18.0.5), without this patch copy_shared_framebuffer_cpu () for a
DisplayLink output takes 5 seconds with a 1080p frame. Obviously that
makes Mutter and gnome-shell completely unusable. With this patch, that
function takes 13-18 ms which makes it usable if not fluent.
On Intel i7-4790 (Mesa DRI Intel(R) Haswell Desktop) machine, this patch
makes no significant difference (the copy takes 4-5 ms).
2018-09-27 09:42:19 -04:00
|
|
|
cogl_format,
|
2018-11-29 06:54:31 -05:00
|
|
|
dumb_fb->stride_bytes,
|
|
|
|
dumb_fb->map);
|
renderer/native: use cogl for CPU copy path
Use cogl_framebuffer_read_pixels_into_bitmap () instead of
glReadPixels () for the CPU copy path in multi-GPU support.
The cogl function employs several tricks to make the read-pixels as fast
as possible and does the y-flip as necessary. This should make the copy
more performant over all kinds of hardware.
This is expected to be used on virtual outputs (e.g. DisplayLink USB
docks and monitors) foremost, where the dumb buffer memory is just
regular system memory. If the dumb buffer memory is somehow slow, like
residing in discrete VRAM or having an unexpected caching mode, it may
be possible for the cogl function perform worse because it might do the
y-flip in-place in the dumb buffer. Hopefully that does not happen in
any practical scenario.
Calling meta_renderer_native_gles3_read_pixels () here was conceptually
wrong to begin with because it was done with the Cogl GL context of the
primary GPU, not on the GL ES 3 context of a secondary GPU. However,
due eglBindAPI being a no-op in Mesa and the glReadPixels () arguments
being compatible, it worked.
This patch adds a pixel format conversion table between DRM and Cogl
formats. It contains more formats than absolutely necessary and the
texture components field which is currently unused for completeness. See
Mutter issue #323. Making the table more complete documents better how
the pixel formats actually map so that posterity should be less likely
to be confused. This table could be shared with
shm_buffer_get_cogl_pixel_format () as well, but not with
meta_wayland_dma_buf_buffer_attach ().
On HP ProBook 4520s laptop (Mesa DRI Intel(R) Ironlake Mobile, Mesa
18.0.5), without this patch copy_shared_framebuffer_cpu () for a
DisplayLink output takes 5 seconds with a 1080p frame. Obviously that
makes Mutter and gnome-shell completely unusable. With this patch, that
function takes 13-18 ms which makes it usable if not fluent.
On Intel i7-4790 (Mesa DRI Intel(R) Haswell Desktop) machine, this patch
makes no significant difference (the copy takes 4-5 ms).
2018-09-27 09:42:19 -04:00
|
|
|
|
|
|
|
if (!cogl_framebuffer_read_pixels_into_bitmap (framebuffer,
|
|
|
|
0 /* x */,
|
|
|
|
0 /* y */,
|
|
|
|
COGL_READ_PIXELS_COLOR_BUFFER,
|
|
|
|
dumb_bitmap))
|
|
|
|
g_warning ("Failed to CPU-copy to a secondary GPU output");
|
|
|
|
|
|
|
|
cogl_object_unref (dumb_bitmap);
|
2016-06-08 05:05:31 -04:00
|
|
|
|
2018-01-30 04:47:17 -05:00
|
|
|
g_clear_object (&secondary_gpu_state->gbm.next_fb);
|
2018-11-29 06:54:31 -05:00
|
|
|
buffer_dumb = meta_drm_buffer_dumb_new (dumb_fb->fb_id);
|
2019-05-20 16:08:35 -04:00
|
|
|
secondary_gpu_state->gbm.next_fb = META_DRM_BUFFER (buffer_dumb);
|
2018-11-29 06:54:31 -05:00
|
|
|
secondary_gpu_state->cpu.dumb_fb = dumb_fb;
|
2017-07-24 22:21:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
update_secondary_gpu_state_pre_swap_buffers (CoglOnscreen *onscreen)
|
|
|
|
{
|
|
|
|
CoglOnscreenEGL *onscreen_egl = onscreen->winsys;
|
|
|
|
MetaOnscreenNative *onscreen_native = onscreen_egl->platform;
|
|
|
|
MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state;
|
|
|
|
|
2019-08-27 06:11:07 -04:00
|
|
|
COGL_TRACE_BEGIN_SCOPED (MetaRendererNativeGpuStatePreSwapBuffers,
|
|
|
|
"Onscreen (secondary gpu pre-swap-buffers)");
|
|
|
|
|
2020-01-17 15:08:02 -05:00
|
|
|
secondary_gpu_state = onscreen_native->secondary_gpu_state;
|
|
|
|
if (secondary_gpu_state)
|
2016-06-08 05:05:31 -04:00
|
|
|
{
|
2017-07-10 06:19:32 -04:00
|
|
|
MetaRendererNativeGpuData *renderer_gpu_data;
|
|
|
|
|
2017-07-24 22:21:04 -04:00
|
|
|
renderer_gpu_data = secondary_gpu_state->renderer_gpu_data;
|
|
|
|
switch (renderer_gpu_data->secondary.copy_mode)
|
2016-08-17 23:28:59 -04:00
|
|
|
{
|
2018-11-29 06:34:40 -05:00
|
|
|
case META_SHARED_FRAMEBUFFER_COPY_MODE_SECONDARY_GPU:
|
2017-07-24 22:21:04 -04:00
|
|
|
/* Done after eglSwapBuffers. */
|
2016-08-17 23:28:59 -04:00
|
|
|
break;
|
2019-05-24 10:07:14 -04:00
|
|
|
case META_SHARED_FRAMEBUFFER_COPY_MODE_ZERO:
|
|
|
|
/* Done after eglSwapBuffers. */
|
|
|
|
if (secondary_gpu_state->import_status ==
|
|
|
|
META_SHARED_FRAMEBUFFER_IMPORT_STATUS_OK)
|
|
|
|
break;
|
|
|
|
/* prepare fallback */
|
|
|
|
G_GNUC_FALLTHROUGH;
|
2018-11-29 06:34:40 -05:00
|
|
|
case META_SHARED_FRAMEBUFFER_COPY_MODE_PRIMARY:
|
|
|
|
if (!copy_shared_framebuffer_primary_gpu (onscreen,
|
|
|
|
secondary_gpu_state))
|
|
|
|
{
|
2019-07-05 07:09:31 -04:00
|
|
|
if (!secondary_gpu_state->noted_primary_gpu_copy_failed)
|
|
|
|
{
|
|
|
|
g_debug ("Using primary GPU to copy for %s failed once.",
|
|
|
|
meta_gpu_kms_get_file_path (secondary_gpu_state->gpu_kms));
|
|
|
|
secondary_gpu_state->noted_primary_gpu_copy_failed = TRUE;
|
|
|
|
}
|
|
|
|
|
2018-11-29 06:34:40 -05:00
|
|
|
copy_shared_framebuffer_cpu (onscreen,
|
|
|
|
secondary_gpu_state,
|
|
|
|
renderer_gpu_data);
|
|
|
|
}
|
2019-07-05 07:09:31 -04:00
|
|
|
else if (!secondary_gpu_state->noted_primary_gpu_copy_ok)
|
|
|
|
{
|
|
|
|
g_debug ("Using primary GPU to copy for %s succeeded once.",
|
|
|
|
meta_gpu_kms_get_file_path (secondary_gpu_state->gpu_kms));
|
|
|
|
secondary_gpu_state->noted_primary_gpu_copy_ok = TRUE;
|
|
|
|
}
|
2016-08-17 23:28:59 -04:00
|
|
|
break;
|
|
|
|
}
|
2016-06-08 05:05:31 -04:00
|
|
|
}
|
2016-05-12 02:55:06 -04:00
|
|
|
}
|
|
|
|
|
2017-07-24 22:21:04 -04:00
|
|
|
static void
|
|
|
|
update_secondary_gpu_state_post_swap_buffers (CoglOnscreen *onscreen,
|
|
|
|
gboolean *egl_context_changed)
|
2016-05-09 07:51:29 -04:00
|
|
|
{
|
2017-07-14 03:20:41 -04:00
|
|
|
CoglOnscreenEGL *onscreen_egl = onscreen->winsys;
|
|
|
|
MetaOnscreenNative *onscreen_native = onscreen_egl->platform;
|
2017-07-24 22:21:04 -04:00
|
|
|
MetaRendererNative *renderer_native = onscreen_native->renderer_native;
|
|
|
|
MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state;
|
|
|
|
|
2019-08-27 06:11:07 -04:00
|
|
|
COGL_TRACE_BEGIN_SCOPED (MetaRendererNativeGpuStatePostSwapBuffers,
|
|
|
|
"Onscreen (secondary gpu post-swap-buffers)");
|
|
|
|
|
2020-01-17 15:08:02 -05:00
|
|
|
secondary_gpu_state = onscreen_native->secondary_gpu_state;
|
|
|
|
if (secondary_gpu_state)
|
2016-05-09 07:51:29 -04:00
|
|
|
{
|
2017-07-24 22:21:04 -04:00
|
|
|
MetaRendererNativeGpuData *renderer_gpu_data;
|
2016-05-09 07:51:29 -04:00
|
|
|
|
2017-07-24 22:21:04 -04:00
|
|
|
renderer_gpu_data =
|
|
|
|
meta_renderer_native_get_gpu_data (renderer_native,
|
|
|
|
secondary_gpu_state->gpu_kms);
|
2019-05-24 10:07:14 -04:00
|
|
|
retry:
|
2017-07-24 22:21:04 -04:00
|
|
|
switch (renderer_gpu_data->secondary.copy_mode)
|
|
|
|
{
|
2019-05-24 10:07:14 -04:00
|
|
|
case META_SHARED_FRAMEBUFFER_COPY_MODE_ZERO:
|
|
|
|
if (!import_shared_framebuffer (onscreen,
|
|
|
|
secondary_gpu_state))
|
|
|
|
goto retry;
|
|
|
|
break;
|
2018-11-29 06:34:40 -05:00
|
|
|
case META_SHARED_FRAMEBUFFER_COPY_MODE_SECONDARY_GPU:
|
2017-07-24 22:21:04 -04:00
|
|
|
copy_shared_framebuffer_gpu (onscreen,
|
|
|
|
secondary_gpu_state,
|
|
|
|
renderer_gpu_data,
|
|
|
|
egl_context_changed);
|
|
|
|
break;
|
2018-11-29 06:34:40 -05:00
|
|
|
case META_SHARED_FRAMEBUFFER_COPY_MODE_PRIMARY:
|
2017-07-24 22:21:04 -04:00
|
|
|
/* Done before eglSwapBuffers. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-09-29 10:33:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_onscreen_native_swap_buffers_with_damage (CoglOnscreen *onscreen,
|
|
|
|
const int *rectangles,
|
|
|
|
int n_rectangles)
|
|
|
|
{
|
|
|
|
CoglContext *cogl_context = COGL_FRAMEBUFFER (onscreen)->context;
|
2017-07-24 22:21:04 -04:00
|
|
|
CoglDisplay *cogl_display = cogl_context_get_display (cogl_context);
|
2016-09-29 10:33:02 -04:00
|
|
|
CoglRenderer *cogl_renderer = cogl_context->display->renderer;
|
2017-07-14 03:20:41 -04:00
|
|
|
CoglRendererEGL *cogl_renderer_egl = cogl_renderer->winsys;
|
2017-07-24 22:21:04 -04:00
|
|
|
MetaRendererNativeGpuData *renderer_gpu_data = cogl_renderer_egl->platform;
|
|
|
|
MetaRendererNative *renderer_native = renderer_gpu_data->renderer_native;
|
2019-10-01 05:51:53 -04:00
|
|
|
MetaRenderer *renderer = META_RENDERER (renderer_native);
|
|
|
|
MetaBackend *backend = meta_renderer_get_backend (renderer);
|
2019-03-25 05:24:46 -04:00
|
|
|
MetaMonitorManager *monitor_manager =
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
meta_backend_get_monitor_manager (backend);
|
|
|
|
MetaBackendNative *backend_native = META_BACKEND_NATIVE (backend);
|
|
|
|
MetaKms *kms = meta_backend_native_get_kms (backend_native);
|
2017-07-14 03:20:41 -04:00
|
|
|
CoglOnscreenEGL *onscreen_egl = onscreen->winsys;
|
|
|
|
MetaOnscreenNative *onscreen_native = onscreen_egl->platform;
|
2017-07-24 22:21:04 -04:00
|
|
|
MetaGpuKms *render_gpu = onscreen_native->render_gpu;
|
2016-09-29 10:33:02 -04:00
|
|
|
CoglFrameInfo *frame_info;
|
2017-07-24 22:21:04 -04:00
|
|
|
gboolean egl_context_changed = FALSE;
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
MetaKmsUpdate *kms_update;
|
2019-03-25 05:24:46 -04:00
|
|
|
MetaPowerSave power_save_mode;
|
2018-01-30 04:47:17 -05:00
|
|
|
g_autoptr (GError) error = NULL;
|
2019-05-20 16:08:35 -04:00
|
|
|
MetaDrmBufferGbm *buffer_gbm;
|
2019-11-08 18:14:36 -05:00
|
|
|
g_autoptr (MetaKmsFeedback) kms_feedback = NULL;
|
2016-09-29 10:33:02 -04:00
|
|
|
|
2019-08-27 06:11:07 -04:00
|
|
|
COGL_TRACE_BEGIN_SCOPED (MetaRendererNativeSwapBuffers,
|
|
|
|
"Onscreen (swap-buffers)");
|
|
|
|
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
kms_update = meta_kms_ensure_pending_update (kms);
|
|
|
|
|
2018-10-04 06:53:17 -04:00
|
|
|
/*
|
|
|
|
* Wait for the flip callback before continuing, as we might have started the
|
|
|
|
* animation earlier due to the animation being driven by some other monitor.
|
|
|
|
*/
|
2019-08-27 06:11:07 -04:00
|
|
|
COGL_TRACE_BEGIN (MetaRendererNativeSwapBuffersWait,
|
2019-09-12 13:30:44 -04:00
|
|
|
"Onscreen (waiting for page flips)");
|
2018-10-04 06:53:17 -04:00
|
|
|
wait_for_pending_flips (onscreen);
|
2019-08-27 06:11:07 -04:00
|
|
|
COGL_TRACE_END (MetaRendererNativeSwapBuffersWait);
|
2018-10-04 06:53:17 -04:00
|
|
|
|
2016-09-29 10:33:02 -04:00
|
|
|
frame_info = g_queue_peek_tail (&onscreen->pending_frame_infos);
|
|
|
|
frame_info->global_frame_counter = renderer_native->frame_counter;
|
|
|
|
|
2017-07-24 22:21:04 -04:00
|
|
|
update_secondary_gpu_state_pre_swap_buffers (onscreen);
|
2016-09-29 10:33:02 -04:00
|
|
|
|
|
|
|
parent_vtable->onscreen_swap_buffers_with_damage (onscreen,
|
|
|
|
rectangles,
|
|
|
|
n_rectangles);
|
|
|
|
|
2017-07-10 06:19:32 -04:00
|
|
|
renderer_gpu_data = meta_renderer_native_get_gpu_data (renderer_native,
|
2017-07-24 22:21:04 -04:00
|
|
|
render_gpu);
|
2017-07-10 06:19:32 -04:00
|
|
|
switch (renderer_gpu_data->mode)
|
2016-08-17 23:28:59 -04:00
|
|
|
{
|
|
|
|
case META_RENDERER_NATIVE_MODE_GBM:
|
2018-01-30 04:47:17 -05:00
|
|
|
g_warn_if_fail (onscreen_native->gbm.next_fb == NULL);
|
|
|
|
g_clear_object (&onscreen_native->gbm.next_fb);
|
2019-05-20 16:08:35 -04:00
|
|
|
|
|
|
|
buffer_gbm = meta_drm_buffer_gbm_new (render_gpu,
|
|
|
|
onscreen_native->gbm.surface,
|
|
|
|
renderer_native->use_modifiers,
|
|
|
|
&error);
|
2019-09-16 08:24:52 -04:00
|
|
|
if (!buffer_gbm)
|
2018-01-30 04:47:17 -05:00
|
|
|
{
|
2019-05-20 16:08:35 -04:00
|
|
|
g_warning ("meta_drm_buffer_gbm_new failed: %s",
|
2018-01-30 04:47:17 -05:00
|
|
|
error->message);
|
|
|
|
return;
|
|
|
|
}
|
2016-08-17 23:28:59 -04:00
|
|
|
|
2019-09-16 08:24:52 -04:00
|
|
|
onscreen_native->gbm.next_fb = META_DRM_BUFFER (buffer_gbm);
|
|
|
|
|
2016-08-17 23:28:59 -04:00
|
|
|
break;
|
|
|
|
#ifdef HAVE_EGL_DEVICE
|
|
|
|
case META_RENDERER_NATIVE_MODE_EGL_DEVICE:
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
}
|
2016-09-29 10:33:02 -04:00
|
|
|
|
2017-07-24 22:21:04 -04:00
|
|
|
update_secondary_gpu_state_post_swap_buffers (onscreen, &egl_context_changed);
|
|
|
|
|
2016-05-09 07:51:29 -04:00
|
|
|
/* If this is the first framebuffer to be presented then we now setup the
|
|
|
|
* crtc modes, else we flip from the previous buffer */
|
2019-03-25 05:24:46 -04:00
|
|
|
|
|
|
|
power_save_mode = meta_monitor_manager_get_power_save_mode (monitor_manager);
|
|
|
|
if (onscreen_native->pending_set_crtc &&
|
|
|
|
power_save_mode == META_POWER_SAVE_ON)
|
2016-05-09 07:51:29 -04:00
|
|
|
{
|
2020-01-17 15:08:02 -05:00
|
|
|
meta_onscreen_native_set_crtc_mode (onscreen,
|
|
|
|
renderer_gpu_data,
|
|
|
|
kms_update);
|
2016-06-08 05:05:31 -04:00
|
|
|
onscreen_native->pending_set_crtc = FALSE;
|
2016-05-09 07:51:29 -04:00
|
|
|
}
|
|
|
|
|
2016-12-05 13:18:24 -05:00
|
|
|
onscreen_native->pending_queue_swap_notify_frame_count = renderer_native->frame_counter;
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
meta_onscreen_native_flip_crtcs (onscreen, kms_update);
|
2017-07-24 22:21:04 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we changed EGL context, cogl will have the wrong idea about what is
|
|
|
|
* current, making it fail to set it when it needs to. Avoid that by making
|
|
|
|
* EGL_NO_CONTEXT current now, making cogl eventually set the correct
|
|
|
|
* context.
|
|
|
|
*/
|
|
|
|
if (egl_context_changed)
|
2018-04-19 11:28:07 -04:00
|
|
|
_cogl_winsys_egl_ensure_current (cogl_display);
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
|
2019-08-27 06:11:07 -04:00
|
|
|
COGL_TRACE_BEGIN (MetaRendererNativePostKmsUpdate,
|
2019-09-12 13:30:44 -04:00
|
|
|
"Onscreen (post pending update)");
|
2019-11-08 18:14:36 -05:00
|
|
|
kms_feedback = meta_kms_post_pending_update_sync (kms);
|
|
|
|
if (meta_kms_feedback_get_result (kms_feedback) != META_KMS_FEEDBACK_PASSED)
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
{
|
2019-11-08 18:14:36 -05:00
|
|
|
const GError *error = meta_kms_feedback_get_error (kms_feedback);
|
|
|
|
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED))
|
|
|
|
g_warning ("Failed to post KMS update: %s", error->message);
|
|
|
|
}
|
2019-08-27 06:11:07 -04:00
|
|
|
COGL_TRACE_END (MetaRendererNativePostKmsUpdate);
|
2016-05-09 07:51:29 -04:00
|
|
|
}
|
|
|
|
|
2016-08-17 22:21:12 -04:00
|
|
|
static gboolean
|
2016-06-01 05:53:07 -04:00
|
|
|
meta_renderer_native_init_egl_context (CoglContext *cogl_context,
|
2016-08-17 22:21:12 -04:00
|
|
|
GError **error)
|
2016-05-09 07:51:29 -04:00
|
|
|
{
|
2016-10-20 03:59:09 -04:00
|
|
|
#ifdef HAVE_EGL_DEVICE
|
|
|
|
CoglRenderer *cogl_renderer = cogl_context->display->renderer;
|
2017-07-14 03:20:41 -04:00
|
|
|
CoglRendererEGL *cogl_renderer_egl = cogl_renderer->winsys;
|
2017-07-24 22:21:04 -04:00
|
|
|
MetaRendererNativeGpuData *renderer_gpu_data = cogl_renderer_egl->platform;
|
2016-10-20 03:59:09 -04:00
|
|
|
#endif
|
|
|
|
|
2018-11-30 02:22:00 -05:00
|
|
|
COGL_FLAGS_SET (cogl_context->features,
|
|
|
|
COGL_FEATURE_ID_PRESENTATION_TIME, TRUE);
|
2016-06-01 05:53:07 -04:00
|
|
|
COGL_FLAGS_SET (cogl_context->features,
|
2016-05-09 07:51:29 -04:00
|
|
|
COGL_FEATURE_ID_SWAP_BUFFERS_EVENT, TRUE);
|
|
|
|
/* TODO: remove this deprecated feature */
|
2016-06-01 05:53:07 -04:00
|
|
|
COGL_FLAGS_SET (cogl_context->winsys_features,
|
2016-05-09 07:51:29 -04:00
|
|
|
COGL_WINSYS_FEATURE_SWAP_BUFFERS_EVENT,
|
|
|
|
TRUE);
|
2016-06-01 05:53:07 -04:00
|
|
|
COGL_FLAGS_SET (cogl_context->winsys_features,
|
2016-05-09 07:51:29 -04:00
|
|
|
COGL_WINSYS_FEATURE_SYNC_AND_COMPLETE_EVENT,
|
|
|
|
TRUE);
|
2016-06-08 05:05:31 -04:00
|
|
|
COGL_FLAGS_SET (cogl_context->winsys_features,
|
|
|
|
COGL_WINSYS_FEATURE_MULTIPLE_ONSCREEN,
|
|
|
|
TRUE);
|
|
|
|
|
2018-07-10 05:46:02 -04:00
|
|
|
/* COGL_WINSYS_FEATURE_SWAP_THROTTLE is always true for this renderer
|
|
|
|
* because we have the call to wait_for_pending_flips on every frame.
|
|
|
|
*/
|
|
|
|
COGL_FLAGS_SET (cogl_context->winsys_features,
|
|
|
|
COGL_WINSYS_FEATURE_SWAP_THROTTLE,
|
|
|
|
TRUE);
|
|
|
|
|
2016-10-20 03:59:09 -04:00
|
|
|
#ifdef HAVE_EGL_DEVICE
|
2017-07-24 22:21:04 -04:00
|
|
|
if (renderer_gpu_data->mode == META_RENDERER_NATIVE_MODE_EGL_DEVICE)
|
2016-10-20 03:59:09 -04:00
|
|
|
COGL_FLAGS_SET (cogl_context->features,
|
|
|
|
COGL_FEATURE_ID_TEXTURE_EGL_IMAGE_EXTERNAL, TRUE);
|
|
|
|
#endif
|
|
|
|
|
2016-06-08 05:05:31 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2017-07-24 22:21:04 -04:00
|
|
|
should_surface_be_sharable (CoglOnscreen *onscreen)
|
|
|
|
{
|
|
|
|
CoglOnscreenEGL *onscreen_egl = onscreen->winsys;
|
|
|
|
MetaOnscreenNative *onscreen_native = onscreen_egl->platform;
|
|
|
|
|
2020-01-17 15:08:02 -05:00
|
|
|
if (META_GPU_KMS (meta_crtc_get_gpu (onscreen_native->crtc)) ==
|
|
|
|
onscreen_native->render_gpu)
|
2017-07-24 22:21:04 -04:00
|
|
|
return FALSE;
|
2020-01-17 15:08:02 -05:00
|
|
|
else
|
|
|
|
return TRUE;
|
2017-07-24 22:21:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
meta_renderer_native_create_surface_gbm (CoglOnscreen *onscreen,
|
2016-08-17 23:11:30 -04:00
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
struct gbm_surface **gbm_surface,
|
|
|
|
EGLSurface *egl_surface,
|
|
|
|
GError **error)
|
2016-06-08 05:05:31 -04:00
|
|
|
{
|
2017-07-24 22:21:04 -04:00
|
|
|
CoglOnscreenEGL *onscreen_egl = onscreen->winsys;
|
|
|
|
MetaOnscreenNative *onscreen_native = onscreen_egl->platform;
|
|
|
|
MetaRendererNative *renderer_native = onscreen_native->renderer_native;
|
|
|
|
MetaEgl *egl = meta_onscreen_native_get_egl (onscreen_native);
|
|
|
|
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
|
|
|
|
CoglContext *cogl_context = framebuffer->context;
|
2016-06-08 05:05:31 -04:00
|
|
|
CoglDisplay *cogl_display = cogl_context->display;
|
2017-07-14 03:20:41 -04:00
|
|
|
CoglDisplayEGL *cogl_display_egl = cogl_display->winsys;
|
2017-07-24 22:21:04 -04:00
|
|
|
CoglRenderer *cogl_renderer = cogl_display->renderer;
|
|
|
|
CoglRendererEGL *cogl_renderer_egl = cogl_renderer->winsys;
|
|
|
|
MetaRendererNativeGpuData *renderer_gpu_data = cogl_renderer_egl->platform;
|
2018-04-02 12:14:53 -04:00
|
|
|
struct gbm_surface *new_gbm_surface = NULL;
|
2016-06-08 05:05:31 -04:00
|
|
|
EGLNativeWindowType egl_native_window;
|
|
|
|
EGLSurface new_egl_surface;
|
2017-08-03 10:42:50 -04:00
|
|
|
uint32_t format = GBM_FORMAT_XRGB8888;
|
|
|
|
GArray *modifiers;
|
2016-06-08 05:05:31 -04:00
|
|
|
|
2017-07-10 06:19:32 -04:00
|
|
|
renderer_gpu_data =
|
|
|
|
meta_renderer_native_get_gpu_data (renderer_native,
|
2017-07-24 22:21:04 -04:00
|
|
|
onscreen_native->render_gpu);
|
2017-08-03 10:42:50 -04:00
|
|
|
|
2018-04-11 08:39:15 -04:00
|
|
|
if (renderer_native->use_modifiers)
|
|
|
|
modifiers = get_supported_modifiers (onscreen, format);
|
|
|
|
else
|
|
|
|
modifiers = NULL;
|
2017-08-03 10:42:50 -04:00
|
|
|
|
|
|
|
if (modifiers)
|
|
|
|
{
|
|
|
|
new_gbm_surface =
|
|
|
|
gbm_surface_create_with_modifiers (renderer_gpu_data->gbm.device,
|
|
|
|
width, height, format,
|
|
|
|
(uint64_t *) modifiers->data,
|
|
|
|
modifiers->len);
|
|
|
|
g_array_free (modifiers, TRUE);
|
|
|
|
}
|
2018-04-02 12:14:53 -04:00
|
|
|
|
|
|
|
if (!new_gbm_surface)
|
2017-08-03 10:42:50 -04:00
|
|
|
{
|
|
|
|
uint32_t flags = GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING;
|
|
|
|
|
|
|
|
if (should_surface_be_sharable (onscreen))
|
|
|
|
flags |= GBM_BO_USE_LINEAR;
|
|
|
|
|
|
|
|
new_gbm_surface = gbm_surface_create (renderer_gpu_data->gbm.device,
|
|
|
|
width, height,
|
|
|
|
format,
|
|
|
|
flags);
|
|
|
|
}
|
2016-06-08 05:05:31 -04:00
|
|
|
|
|
|
|
if (!new_gbm_surface)
|
|
|
|
{
|
|
|
|
g_set_error (error, COGL_WINSYS_ERROR,
|
|
|
|
COGL_WINSYS_ERROR_CREATE_ONSCREEN,
|
|
|
|
"Failed to allocate surface");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
egl_native_window = (EGLNativeWindowType) new_gbm_surface;
|
2017-07-24 04:19:55 -04:00
|
|
|
new_egl_surface =
|
|
|
|
meta_egl_create_window_surface (egl,
|
|
|
|
cogl_renderer_egl->edpy,
|
|
|
|
cogl_display_egl->egl_config,
|
|
|
|
egl_native_window,
|
|
|
|
NULL,
|
|
|
|
error);
|
2016-06-08 05:05:31 -04:00
|
|
|
if (new_egl_surface == EGL_NO_SURFACE)
|
|
|
|
{
|
|
|
|
gbm_surface_destroy (new_gbm_surface);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*gbm_surface = new_gbm_surface;
|
|
|
|
*egl_surface = new_egl_surface;
|
2016-05-09 07:51:29 -04:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-08-17 23:28:59 -04:00
|
|
|
#ifdef HAVE_EGL_DEVICE
|
|
|
|
static gboolean
|
2020-01-17 15:08:02 -05:00
|
|
|
meta_renderer_native_create_surface_egl_device (CoglOnscreen *onscreen,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
EGLStreamKHR *out_egl_stream,
|
|
|
|
EGLSurface *out_egl_surface,
|
|
|
|
GError **error)
|
2016-08-17 23:28:59 -04:00
|
|
|
{
|
2017-07-24 22:21:04 -04:00
|
|
|
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
|
2020-01-17 15:08:02 -05:00
|
|
|
CoglOnscreenEGL *onscreen_egl = onscreen->winsys;
|
|
|
|
MetaOnscreenNative *onscreen_native = onscreen_egl->platform;
|
2017-07-24 22:21:04 -04:00
|
|
|
CoglContext *cogl_context = framebuffer->context;
|
|
|
|
CoglDisplay *cogl_display = cogl_context->display;
|
2017-07-14 03:20:41 -04:00
|
|
|
CoglDisplayEGL *cogl_display_egl = cogl_display->winsys;
|
2016-08-17 23:28:59 -04:00
|
|
|
CoglRenderer *cogl_renderer = cogl_display->renderer;
|
2017-07-14 03:20:41 -04:00
|
|
|
CoglRendererEGL *cogl_renderer_egl = cogl_renderer->winsys;
|
2017-07-24 22:21:04 -04:00
|
|
|
MetaRendererNativeGpuData *renderer_gpu_data = cogl_renderer_egl->platform;
|
|
|
|
MetaEgl *egl =
|
|
|
|
meta_renderer_native_get_egl (renderer_gpu_data->renderer_native);
|
|
|
|
EGLDisplay egl_display = renderer_gpu_data->egl_display;
|
2016-08-17 23:28:59 -04:00
|
|
|
EGLConfig egl_config;
|
|
|
|
EGLStreamKHR egl_stream;
|
|
|
|
EGLSurface egl_surface;
|
|
|
|
EGLint num_layers;
|
|
|
|
EGLOutputLayerEXT output_layer;
|
2016-12-13 08:44:16 -05:00
|
|
|
EGLAttrib output_attribs[3];
|
2016-08-17 23:28:59 -04:00
|
|
|
EGLint stream_attribs[] = {
|
2019-01-11 10:03:37 -05:00
|
|
|
EGL_STREAM_FIFO_LENGTH_KHR, 0,
|
2016-08-17 23:28:59 -04:00
|
|
|
EGL_CONSUMER_AUTO_ACQUIRE_EXT, EGL_FALSE,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
EGLint stream_producer_attribs[] = {
|
|
|
|
EGL_WIDTH, width,
|
|
|
|
EGL_HEIGHT, height,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
|
|
|
|
egl_stream = meta_egl_create_stream (egl, egl_display, stream_attribs, error);
|
|
|
|
if (egl_stream == EGL_NO_STREAM_KHR)
|
|
|
|
return FALSE;
|
|
|
|
|
2016-12-13 08:44:16 -05:00
|
|
|
output_attribs[0] = EGL_DRM_CRTC_EXT;
|
2020-01-17 15:08:02 -05:00
|
|
|
output_attribs[1] = onscreen_native->crtc->crtc_id;
|
2016-12-13 08:44:16 -05:00
|
|
|
output_attribs[2] = EGL_NONE;
|
|
|
|
|
2016-08-17 23:28:59 -04:00
|
|
|
if (!meta_egl_get_output_layers (egl, egl_display,
|
|
|
|
output_attribs,
|
|
|
|
&output_layer, 1, &num_layers,
|
|
|
|
error))
|
|
|
|
{
|
|
|
|
meta_egl_destroy_stream (egl, egl_display, egl_stream, NULL);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num_layers < 1)
|
|
|
|
{
|
|
|
|
meta_egl_destroy_stream (egl, egl_display, egl_stream, NULL);
|
|
|
|
g_set_error (error, G_IO_ERROR,
|
|
|
|
G_IO_ERROR_FAILED,
|
|
|
|
"Unable to find output layers.");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!meta_egl_stream_consumer_output (egl, egl_display,
|
|
|
|
egl_stream, output_layer,
|
|
|
|
error))
|
|
|
|
{
|
|
|
|
meta_egl_destroy_stream (egl, egl_display, egl_stream, NULL);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2017-07-14 03:20:41 -04:00
|
|
|
egl_config = cogl_display_egl->egl_config;
|
2016-08-17 23:28:59 -04:00
|
|
|
egl_surface = meta_egl_create_stream_producer_surface (egl,
|
|
|
|
egl_display,
|
|
|
|
egl_config,
|
|
|
|
egl_stream,
|
|
|
|
stream_producer_attribs,
|
|
|
|
error);
|
|
|
|
if (egl_surface == EGL_NO_SURFACE)
|
|
|
|
{
|
|
|
|
meta_egl_destroy_stream (egl, egl_display, egl_stream, NULL);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*out_egl_stream = egl_stream;
|
|
|
|
*out_egl_surface = egl_surface;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2017-10-09 07:39:50 -04:00
|
|
|
#endif /* HAVE_EGL_DEVICE */
|
2016-08-17 23:28:59 -04:00
|
|
|
|
|
|
|
static gboolean
|
2017-07-24 03:38:46 -04:00
|
|
|
init_dumb_fb (MetaDumbBuffer *dumb_fb,
|
|
|
|
MetaGpuKms *gpu_kms,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
uint32_t format,
|
|
|
|
GError **error)
|
2016-08-17 23:28:59 -04:00
|
|
|
{
|
|
|
|
struct drm_mode_create_dumb create_arg;
|
|
|
|
struct drm_mode_destroy_dumb destroy_arg;
|
|
|
|
struct drm_mode_map_dumb map_arg;
|
|
|
|
uint32_t fb_id = 0;
|
|
|
|
void *map;
|
2017-07-06 04:00:56 -04:00
|
|
|
int kms_fd;
|
2019-09-25 10:03:59 -04:00
|
|
|
MetaGpuKmsFBArgs fb_args = {
|
|
|
|
.width = width,
|
|
|
|
.height = height,
|
|
|
|
.format = format,
|
|
|
|
};
|
2017-07-06 04:00:56 -04:00
|
|
|
|
2017-07-10 06:19:32 -04:00
|
|
|
kms_fd = meta_gpu_kms_get_fd (gpu_kms);
|
2016-08-17 23:28:59 -04:00
|
|
|
|
|
|
|
create_arg = (struct drm_mode_create_dumb) {
|
|
|
|
.bpp = 32, /* RGBX8888 */
|
|
|
|
.width = width,
|
|
|
|
.height = height
|
|
|
|
};
|
2017-07-06 04:00:56 -04:00
|
|
|
if (drmIoctl (kms_fd, DRM_IOCTL_MODE_CREATE_DUMB, &create_arg) != 0)
|
2016-08-17 23:28:59 -04:00
|
|
|
{
|
|
|
|
g_set_error (error, G_IO_ERROR,
|
|
|
|
G_IO_ERROR_FAILED,
|
|
|
|
"Failed to create dumb drm buffer: %s",
|
|
|
|
g_strerror (errno));
|
|
|
|
goto err_ioctl;
|
|
|
|
}
|
|
|
|
|
2019-09-25 10:03:59 -04:00
|
|
|
fb_args.handles[0] = create_arg.handle;
|
|
|
|
fb_args.strides[0] = create_arg.pitch;
|
2018-09-05 03:38:09 -04:00
|
|
|
|
2019-09-25 10:03:59 -04:00
|
|
|
if (!meta_gpu_kms_add_fb (gpu_kms, FALSE, &fb_args, &fb_id, error))
|
|
|
|
goto err_add_fb;
|
2016-08-17 23:28:59 -04:00
|
|
|
|
|
|
|
map_arg = (struct drm_mode_map_dumb) {
|
|
|
|
.handle = create_arg.handle
|
|
|
|
};
|
2017-07-06 04:00:56 -04:00
|
|
|
if (drmIoctl (kms_fd, DRM_IOCTL_MODE_MAP_DUMB,
|
2016-08-17 23:28:59 -04:00
|
|
|
&map_arg) != 0)
|
|
|
|
{
|
|
|
|
g_set_error (error, G_IO_ERROR,
|
|
|
|
G_IO_ERROR_FAILED,
|
|
|
|
"Failed to map dumb drm buffer: %s",
|
|
|
|
g_strerror (errno));
|
|
|
|
goto err_map_dumb;
|
|
|
|
}
|
|
|
|
|
|
|
|
map = mmap (NULL, create_arg.size, PROT_WRITE, MAP_SHARED,
|
2017-07-06 04:00:56 -04:00
|
|
|
kms_fd, map_arg.offset);
|
2016-08-17 23:28:59 -04:00
|
|
|
if (map == MAP_FAILED)
|
|
|
|
{
|
|
|
|
g_set_error (error, G_IO_ERROR,
|
|
|
|
G_IO_ERROR_FAILED,
|
|
|
|
"Failed to mmap dumb drm buffer memory: %s",
|
|
|
|
g_strerror (errno));
|
|
|
|
goto err_mmap;
|
|
|
|
}
|
|
|
|
|
2017-07-24 03:38:46 -04:00
|
|
|
dumb_fb->fb_id = fb_id;
|
|
|
|
dumb_fb->handle = create_arg.handle;
|
|
|
|
dumb_fb->map = map;
|
|
|
|
dumb_fb->map_size = create_arg.size;
|
2018-09-05 04:48:08 -04:00
|
|
|
dumb_fb->width = width;
|
|
|
|
dumb_fb->height = height;
|
2018-09-05 05:07:59 -04:00
|
|
|
dumb_fb->stride_bytes = create_arg.pitch;
|
2018-11-09 07:22:18 -05:00
|
|
|
dumb_fb->drm_format = format;
|
2018-11-29 06:37:16 -05:00
|
|
|
dumb_fb->dmabuf_fd = -1;
|
2016-08-17 23:28:59 -04:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
err_mmap:
|
|
|
|
err_map_dumb:
|
2017-07-06 04:00:56 -04:00
|
|
|
drmModeRmFB (kms_fd, fb_id);
|
2016-08-17 23:28:59 -04:00
|
|
|
|
|
|
|
err_add_fb:
|
|
|
|
destroy_arg = (struct drm_mode_destroy_dumb) {
|
|
|
|
.handle = create_arg.handle
|
|
|
|
};
|
2017-07-06 04:00:56 -04:00
|
|
|
drmIoctl (kms_fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_arg);
|
2016-08-17 23:28:59 -04:00
|
|
|
|
|
|
|
err_ioctl:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-11-29 06:37:16 -05:00
|
|
|
static int
|
|
|
|
meta_dumb_buffer_ensure_dmabuf_fd (MetaDumbBuffer *dumb_fb,
|
|
|
|
MetaGpuKms *gpu_kms)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
int kms_fd;
|
|
|
|
int dmabuf_fd;
|
|
|
|
|
|
|
|
if (dumb_fb->dmabuf_fd != -1)
|
|
|
|
return dumb_fb->dmabuf_fd;
|
|
|
|
|
|
|
|
kms_fd = meta_gpu_kms_get_fd (gpu_kms);
|
|
|
|
|
|
|
|
ret = drmPrimeHandleToFD (kms_fd, dumb_fb->handle, DRM_CLOEXEC,
|
|
|
|
&dmabuf_fd);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
g_debug ("Failed to export dumb drm buffer: %s",
|
|
|
|
g_strerror (errno));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
dumb_fb->dmabuf_fd = dmabuf_fd;
|
|
|
|
|
|
|
|
return dumb_fb->dmabuf_fd;
|
|
|
|
}
|
|
|
|
|
2016-08-17 23:28:59 -04:00
|
|
|
static void
|
2017-07-24 03:38:46 -04:00
|
|
|
release_dumb_fb (MetaDumbBuffer *dumb_fb,
|
|
|
|
MetaGpuKms *gpu_kms)
|
2016-08-17 23:28:59 -04:00
|
|
|
{
|
|
|
|
struct drm_mode_destroy_dumb destroy_arg;
|
2017-07-06 04:00:56 -04:00
|
|
|
int kms_fd;
|
2016-08-17 23:28:59 -04:00
|
|
|
|
2017-07-24 03:38:46 -04:00
|
|
|
if (!dumb_fb->map)
|
2016-08-17 23:28:59 -04:00
|
|
|
return;
|
|
|
|
|
2018-11-29 06:37:16 -05:00
|
|
|
if (dumb_fb->dmabuf_fd != -1)
|
|
|
|
close (dumb_fb->dmabuf_fd);
|
|
|
|
|
2017-07-24 03:38:46 -04:00
|
|
|
munmap (dumb_fb->map, dumb_fb->map_size);
|
2016-08-17 23:28:59 -04:00
|
|
|
|
2017-07-10 06:19:32 -04:00
|
|
|
kms_fd = meta_gpu_kms_get_fd (gpu_kms);
|
2017-07-06 04:00:56 -04:00
|
|
|
|
2017-07-24 03:38:46 -04:00
|
|
|
drmModeRmFB (kms_fd, dumb_fb->fb_id);
|
2016-08-17 23:28:59 -04:00
|
|
|
|
|
|
|
destroy_arg = (struct drm_mode_destroy_dumb) {
|
2017-07-24 03:38:46 -04:00
|
|
|
.handle = dumb_fb->handle
|
2016-08-17 23:28:59 -04:00
|
|
|
};
|
2017-07-06 04:00:56 -04:00
|
|
|
drmIoctl (kms_fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_arg);
|
2019-09-17 06:20:36 -04:00
|
|
|
|
|
|
|
*dumb_fb = (MetaDumbBuffer) {
|
|
|
|
.dmabuf_fd = -1,
|
|
|
|
};
|
2016-08-17 23:28:59 -04:00
|
|
|
}
|
|
|
|
|
2016-08-17 22:21:12 -04:00
|
|
|
static gboolean
|
2016-05-27 03:13:09 -04:00
|
|
|
meta_renderer_native_init_onscreen (CoglOnscreen *onscreen,
|
2016-08-17 22:21:12 -04:00
|
|
|
GError **error)
|
2016-05-09 07:51:29 -04:00
|
|
|
{
|
|
|
|
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
|
2016-06-01 05:53:07 -04:00
|
|
|
CoglContext *cogl_context = framebuffer->context;
|
|
|
|
CoglDisplay *cogl_display = cogl_context->display;
|
2017-07-14 03:20:41 -04:00
|
|
|
CoglDisplayEGL *cogl_display_egl = cogl_display->winsys;
|
|
|
|
CoglOnscreenEGL *onscreen_egl;
|
2016-05-27 03:07:41 -04:00
|
|
|
MetaOnscreenNative *onscreen_native;
|
2016-05-09 07:51:29 -04:00
|
|
|
|
2019-06-17 17:42:01 -04:00
|
|
|
g_return_val_if_fail (cogl_display_egl->egl_context, FALSE);
|
2016-05-09 07:51:29 -04:00
|
|
|
|
|
|
|
onscreen->winsys = g_slice_new0 (CoglOnscreenEGL);
|
2017-07-14 03:20:41 -04:00
|
|
|
onscreen_egl = onscreen->winsys;
|
2016-05-09 07:51:29 -04:00
|
|
|
|
2016-05-27 03:07:41 -04:00
|
|
|
onscreen_native = g_slice_new0 (MetaOnscreenNative);
|
2017-07-14 03:20:41 -04:00
|
|
|
onscreen_egl->platform = onscreen_native;
|
2016-05-09 07:51:29 -04:00
|
|
|
|
2016-09-29 10:46:34 -04:00
|
|
|
/*
|
|
|
|
* Don't actually initialize anything here, since we may not have the
|
|
|
|
* information available yet, and there is no way to pass it at this stage.
|
|
|
|
* To properly allocate a MetaOnscreenNative, the caller must call
|
|
|
|
* meta_onscreen_native_allocate() after cogl_framebuffer_allocate().
|
|
|
|
*
|
|
|
|
* TODO: Turn CoglFramebuffer/CoglOnscreen into GObjects, so it's possible
|
|
|
|
* to add backend specific properties.
|
|
|
|
*/
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
meta_onscreen_native_allocate (CoglOnscreen *onscreen,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
|
2017-07-14 03:20:41 -04:00
|
|
|
CoglOnscreenEGL *onscreen_egl = onscreen->winsys;
|
|
|
|
MetaOnscreenNative *onscreen_native = onscreen_egl->platform;
|
2017-07-10 06:19:32 -04:00
|
|
|
MetaRendererNativeGpuData *renderer_gpu_data;
|
2016-09-29 10:46:34 -04:00
|
|
|
struct gbm_surface *gbm_surface;
|
|
|
|
EGLSurface egl_surface;
|
|
|
|
int width;
|
|
|
|
int height;
|
2016-08-17 23:28:59 -04:00
|
|
|
#ifdef HAVE_EGL_DEVICE
|
|
|
|
EGLStreamKHR egl_stream;
|
|
|
|
#endif
|
2016-09-29 10:46:34 -04:00
|
|
|
|
2016-06-08 05:05:31 -04:00
|
|
|
onscreen_native->pending_set_crtc = TRUE;
|
|
|
|
|
2016-05-09 07:51:29 -04:00
|
|
|
/* If a kms_fd is set then the display width and height
|
|
|
|
* won't be available until meta_renderer_native_set_layout
|
|
|
|
* is called. In that case, defer creating the surface
|
|
|
|
* until then.
|
|
|
|
*/
|
2016-06-08 05:05:31 -04:00
|
|
|
width = cogl_framebuffer_get_width (framebuffer);
|
|
|
|
height = cogl_framebuffer_get_height (framebuffer);
|
|
|
|
if (width == 0 || height == 0)
|
2016-05-09 07:51:29 -04:00
|
|
|
return TRUE;
|
|
|
|
|
2017-07-10 06:19:32 -04:00
|
|
|
renderer_gpu_data =
|
2017-07-24 22:21:04 -04:00
|
|
|
meta_renderer_native_get_gpu_data (onscreen_native->renderer_native,
|
|
|
|
onscreen_native->render_gpu);
|
2017-07-10 06:19:32 -04:00
|
|
|
switch (renderer_gpu_data->mode)
|
2016-08-17 23:28:59 -04:00
|
|
|
{
|
|
|
|
case META_RENDERER_NATIVE_MODE_GBM:
|
2017-07-24 22:21:04 -04:00
|
|
|
if (!meta_renderer_native_create_surface_gbm (onscreen,
|
2016-08-17 23:28:59 -04:00
|
|
|
width, height,
|
|
|
|
&gbm_surface,
|
|
|
|
&egl_surface,
|
|
|
|
error))
|
|
|
|
return FALSE;
|
2016-08-17 23:11:30 -04:00
|
|
|
|
2016-08-17 23:28:59 -04:00
|
|
|
onscreen_native->gbm.surface = gbm_surface;
|
2017-07-14 03:20:41 -04:00
|
|
|
onscreen_egl->egl_surface = egl_surface;
|
2016-08-17 23:28:59 -04:00
|
|
|
break;
|
|
|
|
#ifdef HAVE_EGL_DEVICE
|
|
|
|
case META_RENDERER_NATIVE_MODE_EGL_DEVICE:
|
2017-07-24 03:38:46 -04:00
|
|
|
if (!init_dumb_fb (&onscreen_native->egl.dumb_fb,
|
2017-07-24 22:21:04 -04:00
|
|
|
onscreen_native->render_gpu,
|
2017-07-24 03:38:46 -04:00
|
|
|
width, height,
|
2018-11-09 07:17:12 -05:00
|
|
|
DRM_FORMAT_XRGB8888,
|
2017-07-24 03:38:46 -04:00
|
|
|
error))
|
2016-08-17 23:28:59 -04:00
|
|
|
return FALSE;
|
|
|
|
|
2017-07-24 22:21:04 -04:00
|
|
|
if (!meta_renderer_native_create_surface_egl_device (onscreen,
|
2016-08-17 23:28:59 -04:00
|
|
|
width, height,
|
|
|
|
&egl_stream,
|
|
|
|
&egl_surface,
|
|
|
|
error))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
onscreen_native->egl.stream = egl_stream;
|
2017-07-14 03:20:41 -04:00
|
|
|
onscreen_egl->egl_surface = egl_surface;
|
2016-08-17 23:28:59 -04:00
|
|
|
break;
|
|
|
|
#endif /* HAVE_EGL_DEVICE */
|
|
|
|
}
|
2016-08-17 23:11:30 -04:00
|
|
|
|
|
|
|
return TRUE;
|
2016-05-09 07:51:29 -04:00
|
|
|
}
|
|
|
|
|
2019-06-17 13:16:12 -04:00
|
|
|
static void
|
|
|
|
destroy_egl_surface (CoglOnscreen *onscreen)
|
|
|
|
{
|
|
|
|
CoglOnscreenEGL *onscreen_egl = onscreen->winsys;
|
|
|
|
|
|
|
|
if (onscreen_egl->egl_surface != EGL_NO_SURFACE)
|
|
|
|
{
|
|
|
|
MetaOnscreenNative *onscreen_native = onscreen_egl->platform;
|
|
|
|
MetaEgl *egl = meta_onscreen_native_get_egl (onscreen_native);
|
|
|
|
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
|
|
|
|
CoglContext *cogl_context = framebuffer->context;
|
|
|
|
CoglRenderer *cogl_renderer = cogl_context->display->renderer;
|
|
|
|
CoglRendererEGL *cogl_renderer_egl = cogl_renderer->winsys;
|
|
|
|
|
|
|
|
meta_egl_destroy_surface (egl,
|
|
|
|
cogl_renderer_egl->edpy,
|
|
|
|
onscreen_egl->egl_surface,
|
|
|
|
NULL);
|
|
|
|
onscreen_egl->egl_surface = EGL_NO_SURFACE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-09 07:51:29 -04:00
|
|
|
static void
|
2016-05-27 03:13:09 -04:00
|
|
|
meta_renderer_native_release_onscreen (CoglOnscreen *onscreen)
|
2016-05-09 07:51:29 -04:00
|
|
|
{
|
|
|
|
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
|
2016-06-01 05:53:07 -04:00
|
|
|
CoglContext *cogl_context = framebuffer->context;
|
2019-06-17 12:18:42 -04:00
|
|
|
CoglDisplay *cogl_display = cogl_context_get_display (cogl_context);
|
|
|
|
CoglDisplayEGL *cogl_display_egl = cogl_display->winsys;
|
2017-07-24 04:19:55 -04:00
|
|
|
CoglOnscreenEGL *onscreen_egl = onscreen->winsys;
|
2016-05-27 03:07:41 -04:00
|
|
|
MetaOnscreenNative *onscreen_native;
|
2019-01-11 09:35:42 -05:00
|
|
|
MetaRendererNative *renderer_native;
|
2017-07-10 06:19:32 -04:00
|
|
|
MetaRendererNativeGpuData *renderer_gpu_data;
|
2016-05-09 07:51:29 -04:00
|
|
|
|
|
|
|
/* If we never successfully allocated then there's nothing to do */
|
2017-07-14 03:20:41 -04:00
|
|
|
if (onscreen_egl == NULL)
|
2016-05-09 07:51:29 -04:00
|
|
|
return;
|
|
|
|
|
2017-07-14 03:20:41 -04:00
|
|
|
onscreen_native = onscreen_egl->platform;
|
2019-01-11 09:35:42 -05:00
|
|
|
renderer_native = onscreen_native->renderer_native;
|
2016-05-09 07:51:29 -04:00
|
|
|
|
2019-06-17 12:18:42 -04:00
|
|
|
if (onscreen_egl->egl_surface != EGL_NO_SURFACE &&
|
|
|
|
(cogl_display_egl->current_draw_surface == onscreen_egl->egl_surface ||
|
|
|
|
cogl_display_egl->current_read_surface == onscreen_egl->egl_surface))
|
|
|
|
{
|
|
|
|
if (!_cogl_winsys_egl_make_current (cogl_display,
|
|
|
|
cogl_display_egl->dummy_surface,
|
|
|
|
cogl_display_egl->dummy_surface,
|
|
|
|
cogl_display_egl->egl_context))
|
|
|
|
g_warning ("Failed to clear current context");
|
|
|
|
}
|
|
|
|
|
2017-07-10 06:19:32 -04:00
|
|
|
renderer_gpu_data =
|
2019-01-11 09:35:42 -05:00
|
|
|
meta_renderer_native_get_gpu_data (renderer_native,
|
2017-07-24 22:21:04 -04:00
|
|
|
onscreen_native->render_gpu);
|
2017-07-10 06:19:32 -04:00
|
|
|
switch (renderer_gpu_data->mode)
|
2016-05-09 07:51:29 -04:00
|
|
|
{
|
2016-08-17 23:28:59 -04:00
|
|
|
case META_RENDERER_NATIVE_MODE_GBM:
|
|
|
|
/* flip state takes a reference on the onscreen so there should
|
|
|
|
* never be outstanding flips when we reach here. */
|
2018-01-30 04:47:17 -05:00
|
|
|
g_return_if_fail (onscreen_native->gbm.next_fb == NULL);
|
2016-08-17 23:28:59 -04:00
|
|
|
|
|
|
|
free_current_bo (onscreen);
|
|
|
|
|
2019-06-17 13:16:12 -04:00
|
|
|
destroy_egl_surface (onscreen);
|
|
|
|
|
2016-08-17 23:28:59 -04:00
|
|
|
if (onscreen_native->gbm.surface)
|
|
|
|
{
|
|
|
|
gbm_surface_destroy (onscreen_native->gbm.surface);
|
|
|
|
onscreen_native->gbm.surface = NULL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#ifdef HAVE_EGL_DEVICE
|
|
|
|
case META_RENDERER_NATIVE_MODE_EGL_DEVICE:
|
2017-07-24 03:38:46 -04:00
|
|
|
release_dumb_fb (&onscreen_native->egl.dumb_fb,
|
2017-07-24 22:21:04 -04:00
|
|
|
onscreen_native->render_gpu);
|
2019-06-17 13:16:12 -04:00
|
|
|
|
|
|
|
destroy_egl_surface (onscreen);
|
|
|
|
|
2016-08-17 23:28:59 -04:00
|
|
|
if (onscreen_native->egl.stream != EGL_NO_STREAM_KHR)
|
|
|
|
{
|
2017-07-24 22:21:04 -04:00
|
|
|
MetaEgl *egl = meta_onscreen_native_get_egl (onscreen_native);
|
2019-06-27 03:24:19 -04:00
|
|
|
CoglRenderer *cogl_renderer = cogl_context->display->renderer;
|
|
|
|
CoglRendererEGL *cogl_renderer_egl = cogl_renderer->winsys;
|
2016-08-17 23:28:59 -04:00
|
|
|
|
|
|
|
meta_egl_destroy_stream (egl,
|
2017-07-14 03:20:41 -04:00
|
|
|
cogl_renderer_egl->edpy,
|
2016-08-17 23:28:59 -04:00
|
|
|
onscreen_native->egl.stream,
|
|
|
|
NULL);
|
|
|
|
onscreen_native->egl.stream = EGL_NO_STREAM_KHR;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif /* HAVE_EGL_DEVICE */
|
2016-05-09 07:51:29 -04:00
|
|
|
}
|
|
|
|
|
2020-01-17 15:08:02 -05:00
|
|
|
g_clear_pointer (&onscreen_native->secondary_gpu_state,
|
|
|
|
secondary_gpu_state_free);
|
2017-07-24 22:21:04 -04:00
|
|
|
|
2016-05-27 03:07:41 -04:00
|
|
|
g_slice_free (MetaOnscreenNative, onscreen_native);
|
2016-05-09 07:51:29 -04:00
|
|
|
g_slice_free (CoglOnscreenEGL, onscreen->winsys);
|
|
|
|
onscreen->winsys = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const CoglWinsysEGLVtable
|
|
|
|
_cogl_winsys_egl_vtable = {
|
2016-09-26 03:54:27 -04:00
|
|
|
.add_config_attributes = meta_renderer_native_add_egl_config_attributes,
|
2018-02-23 09:14:07 -05:00
|
|
|
.choose_config = meta_renderer_native_choose_egl_config,
|
2016-05-27 03:13:09 -04:00
|
|
|
.display_setup = meta_renderer_native_setup_egl_display,
|
|
|
|
.display_destroy = meta_renderer_native_destroy_egl_display,
|
|
|
|
.context_created = meta_renderer_native_egl_context_created,
|
|
|
|
.cleanup_context = meta_renderer_native_egl_cleanup_context,
|
|
|
|
.context_init = meta_renderer_native_init_egl_context
|
2016-05-09 07:51:29 -04:00
|
|
|
};
|
|
|
|
|
2017-07-10 06:19:32 -04:00
|
|
|
gboolean
|
|
|
|
meta_renderer_native_supports_mirroring (MetaRendererNative *renderer_native)
|
2016-08-17 23:28:59 -04:00
|
|
|
{
|
2019-10-01 05:51:53 -04:00
|
|
|
MetaRenderer *renderer = META_RENDERER (renderer_native);
|
|
|
|
MetaBackend *backend = meta_renderer_get_backend (renderer);
|
2017-07-10 06:19:32 -04:00
|
|
|
GList *l;
|
2016-08-17 23:28:59 -04:00
|
|
|
|
2019-10-01 05:51:53 -04:00
|
|
|
for (l = meta_backend_get_gpus (backend); l; l = l->next)
|
2017-07-10 06:19:32 -04:00
|
|
|
{
|
|
|
|
MetaGpuKms *gpu_kms = META_GPU_KMS (l->data);
|
|
|
|
MetaRendererNativeGpuData *renderer_gpu_data;
|
|
|
|
|
|
|
|
renderer_gpu_data = meta_renderer_native_get_gpu_data (renderer_native,
|
|
|
|
gpu_kms);
|
|
|
|
switch (renderer_gpu_data->mode)
|
|
|
|
{
|
|
|
|
case META_RENDERER_NATIVE_MODE_GBM:
|
|
|
|
break;
|
|
|
|
#ifdef HAVE_EGL_DEVICE
|
|
|
|
case META_RENDERER_NATIVE_MODE_EGL_DEVICE:
|
|
|
|
return FALSE;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2016-05-09 07:51:29 -04:00
|
|
|
}
|
|
|
|
|
2019-06-19 14:57:14 -04:00
|
|
|
static void
|
2016-05-09 07:51:29 -04:00
|
|
|
meta_renderer_native_queue_modes_reset (MetaRendererNative *renderer_native)
|
|
|
|
{
|
2016-06-08 05:05:31 -04:00
|
|
|
MetaRenderer *renderer = META_RENDERER (renderer_native);
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
for (l = meta_renderer_get_views (renderer); l; l = l->next)
|
|
|
|
{
|
|
|
|
ClutterStageView *stage_view = l->data;
|
|
|
|
CoglFramebuffer *framebuffer =
|
2016-07-31 20:44:57 -04:00
|
|
|
clutter_stage_view_get_onscreen (stage_view);
|
2016-06-08 05:05:31 -04:00
|
|
|
CoglOnscreen *onscreen = COGL_ONSCREEN (framebuffer);
|
2017-07-14 03:20:41 -04:00
|
|
|
CoglOnscreenEGL *onscreen_egl = onscreen->winsys;
|
|
|
|
MetaOnscreenNative *onscreen_native = onscreen_egl->platform;
|
2016-06-08 05:05:31 -04:00
|
|
|
|
|
|
|
onscreen_native->pending_set_crtc = TRUE;
|
|
|
|
}
|
2017-09-28 11:59:27 -04:00
|
|
|
|
|
|
|
renderer_native->pending_unset_disabled_crtcs = TRUE;
|
2016-05-09 07:51:29 -04:00
|
|
|
}
|
|
|
|
|
2016-07-31 21:47:11 -04:00
|
|
|
static CoglOnscreen *
|
2017-07-24 22:21:04 -04:00
|
|
|
meta_renderer_native_create_onscreen (MetaRendererNative *renderer_native,
|
|
|
|
MetaGpuKms *render_gpu,
|
2020-01-17 15:08:02 -05:00
|
|
|
MetaOutput *output,
|
|
|
|
MetaCrtc *crtc,
|
2017-07-10 06:19:32 -04:00
|
|
|
CoglContext *context,
|
2020-01-17 15:08:02 -05:00
|
|
|
int width,
|
|
|
|
int height,
|
2017-07-24 05:35:55 -04:00
|
|
|
GError **error)
|
2016-07-31 21:47:11 -04:00
|
|
|
{
|
|
|
|
CoglOnscreen *onscreen;
|
2017-07-14 03:20:41 -04:00
|
|
|
CoglOnscreenEGL *onscreen_egl;
|
2017-07-10 06:19:32 -04:00
|
|
|
MetaOnscreenNative *onscreen_native;
|
2016-07-31 21:47:11 -04:00
|
|
|
|
|
|
|
onscreen = cogl_onscreen_new (context, width, height);
|
2018-07-10 05:46:02 -04:00
|
|
|
|
2017-07-24 05:35:55 -04:00
|
|
|
if (!cogl_framebuffer_allocate (COGL_FRAMEBUFFER (onscreen), error))
|
2016-07-31 21:47:11 -04:00
|
|
|
{
|
|
|
|
cogl_object_unref (onscreen);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-07-14 03:20:41 -04:00
|
|
|
onscreen_egl = onscreen->winsys;
|
|
|
|
onscreen_native = onscreen_egl->platform;
|
2017-07-24 22:21:04 -04:00
|
|
|
onscreen_native->renderer_native = renderer_native;
|
|
|
|
onscreen_native->render_gpu = render_gpu;
|
2020-01-17 15:08:02 -05:00
|
|
|
onscreen_native->output = output;
|
|
|
|
onscreen_native->crtc = crtc;
|
2017-07-24 22:21:04 -04:00
|
|
|
|
2020-01-17 15:08:02 -05:00
|
|
|
if (META_GPU_KMS (meta_crtc_get_gpu (crtc)) != render_gpu)
|
2017-07-24 22:21:04 -04:00
|
|
|
{
|
2020-01-17 15:08:02 -05:00
|
|
|
if (!init_secondary_gpu_state (renderer_native, onscreen, error))
|
2017-07-24 22:21:04 -04:00
|
|
|
{
|
|
|
|
cogl_object_unref (onscreen);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2017-07-10 06:19:32 -04:00
|
|
|
|
2016-07-31 21:47:11 -04:00
|
|
|
return onscreen;
|
|
|
|
}
|
|
|
|
|
2016-07-31 21:48:30 -04:00
|
|
|
static CoglOffscreen *
|
|
|
|
meta_renderer_native_create_offscreen (MetaRendererNative *renderer,
|
|
|
|
CoglContext *context,
|
|
|
|
gint view_width,
|
2017-07-24 05:35:55 -04:00
|
|
|
gint view_height,
|
|
|
|
GError **error)
|
2016-07-31 21:48:30 -04:00
|
|
|
{
|
|
|
|
CoglOffscreen *fb;
|
|
|
|
CoglTexture2D *tex;
|
|
|
|
|
|
|
|
tex = cogl_texture_2d_new_with_size (context, view_width, view_height);
|
|
|
|
cogl_primitive_texture_set_auto_mipmap (COGL_PRIMITIVE_TEXTURE (tex), FALSE);
|
|
|
|
|
2017-07-24 05:35:55 -04:00
|
|
|
if (!cogl_texture_allocate (COGL_TEXTURE (tex), error))
|
2016-07-31 21:48:30 -04:00
|
|
|
{
|
|
|
|
cogl_object_unref (tex);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
fb = cogl_offscreen_new_with_texture (COGL_TEXTURE (tex));
|
|
|
|
cogl_object_unref (tex);
|
2017-07-24 05:35:55 -04:00
|
|
|
if (!cogl_framebuffer_allocate (COGL_FRAMEBUFFER (fb), error))
|
2016-07-31 21:48:30 -04:00
|
|
|
{
|
|
|
|
cogl_object_unref (fb);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return fb;
|
|
|
|
}
|
|
|
|
|
2018-06-27 05:19:27 -04:00
|
|
|
static int64_t
|
|
|
|
meta_renderer_native_get_clock_time (CoglContext *context)
|
|
|
|
{
|
|
|
|
CoglRenderer *cogl_renderer = cogl_context_get_renderer (context);
|
|
|
|
MetaGpuKms *gpu_kms = cogl_renderer->custom_winsys_user_data;
|
|
|
|
|
|
|
|
return meta_gpu_kms_get_current_time_ns (gpu_kms);
|
|
|
|
}
|
|
|
|
|
2016-05-09 07:51:29 -04:00
|
|
|
static const CoglWinsysVtable *
|
2016-09-22 23:49:10 -04:00
|
|
|
get_native_cogl_winsys_vtable (CoglRenderer *cogl_renderer)
|
2016-05-09 07:51:29 -04:00
|
|
|
{
|
2016-08-17 22:21:12 -04:00
|
|
|
static gboolean vtable_inited = FALSE;
|
2016-05-09 07:51:29 -04:00
|
|
|
static CoglWinsysVtable vtable;
|
|
|
|
|
|
|
|
if (!vtable_inited)
|
|
|
|
{
|
|
|
|
/* The this winsys is a subclass of the EGL winsys so we
|
|
|
|
start by copying its vtable */
|
|
|
|
|
|
|
|
parent_vtable = _cogl_winsys_egl_get_vtable ();
|
|
|
|
vtable = *parent_vtable;
|
|
|
|
|
|
|
|
vtable.id = COGL_WINSYS_ID_CUSTOM;
|
|
|
|
vtable.name = "EGL_KMS";
|
|
|
|
|
2016-05-27 03:13:09 -04:00
|
|
|
vtable.renderer_connect = meta_renderer_native_connect;
|
|
|
|
vtable.renderer_disconnect = meta_renderer_native_disconnect;
|
2016-05-09 07:51:29 -04:00
|
|
|
|
2016-05-27 03:13:09 -04:00
|
|
|
vtable.onscreen_init = meta_renderer_native_init_onscreen;
|
|
|
|
vtable.onscreen_deinit = meta_renderer_native_release_onscreen;
|
2016-05-09 07:51:29 -04:00
|
|
|
|
|
|
|
/* The KMS winsys doesn't support swap region */
|
|
|
|
vtable.onscreen_swap_region = NULL;
|
|
|
|
vtable.onscreen_swap_buffers_with_damage =
|
2016-05-27 03:13:09 -04:00
|
|
|
meta_onscreen_native_swap_buffers_with_damage;
|
2016-05-09 07:51:29 -04:00
|
|
|
|
2018-06-27 05:19:27 -04:00
|
|
|
vtable.context_get_clock_time = meta_renderer_native_get_clock_time;
|
|
|
|
|
2016-05-09 07:51:29 -04:00
|
|
|
vtable_inited = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return &vtable;
|
|
|
|
}
|
|
|
|
|
2016-05-08 21:59:54 -04:00
|
|
|
static CoglRenderer *
|
2017-07-24 22:21:04 -04:00
|
|
|
create_cogl_renderer_for_gpu (MetaGpuKms *gpu_kms)
|
2016-05-08 21:59:54 -04:00
|
|
|
{
|
|
|
|
CoglRenderer *cogl_renderer;
|
|
|
|
|
|
|
|
cogl_renderer = cogl_renderer_new ();
|
|
|
|
cogl_renderer_set_custom_winsys (cogl_renderer,
|
2017-07-24 04:03:02 -04:00
|
|
|
get_native_cogl_winsys_vtable,
|
2017-07-24 22:21:04 -04:00
|
|
|
gpu_kms);
|
2016-05-08 21:59:54 -04:00
|
|
|
|
|
|
|
return cogl_renderer;
|
|
|
|
}
|
|
|
|
|
2017-07-24 22:21:04 -04:00
|
|
|
static CoglRenderer *
|
|
|
|
meta_renderer_native_create_cogl_renderer (MetaRenderer *renderer)
|
|
|
|
{
|
|
|
|
MetaRendererNative *renderer_native = META_RENDERER_NATIVE (renderer);
|
|
|
|
|
2018-12-10 07:19:25 -05:00
|
|
|
return create_cogl_renderer_for_gpu (renderer_native->primary_gpu_kms);
|
2017-07-24 22:21:04 -04:00
|
|
|
}
|
|
|
|
|
2016-06-08 05:05:31 -04:00
|
|
|
static void
|
|
|
|
meta_onscreen_native_set_view (CoglOnscreen *onscreen,
|
|
|
|
MetaRendererView *view)
|
|
|
|
{
|
2017-07-14 03:20:41 -04:00
|
|
|
CoglOnscreenEGL *onscreen_egl;
|
2016-06-08 05:05:31 -04:00
|
|
|
MetaOnscreenNative *onscreen_native;
|
|
|
|
|
2017-07-14 03:20:41 -04:00
|
|
|
onscreen_egl = onscreen->winsys;
|
|
|
|
onscreen_native = onscreen_egl->platform;
|
2016-06-08 05:05:31 -04:00
|
|
|
onscreen_native->view = view;
|
|
|
|
}
|
|
|
|
|
2017-03-08 03:05:00 -05:00
|
|
|
static MetaMonitorTransform
|
|
|
|
calculate_view_transform (MetaMonitorManager *monitor_manager,
|
2020-01-17 15:08:02 -05:00
|
|
|
MetaLogicalMonitor *logical_monitor,
|
|
|
|
MetaOutput *output,
|
|
|
|
MetaCrtc *crtc)
|
2017-03-08 03:05:00 -05:00
|
|
|
{
|
2018-07-23 15:36:57 -04:00
|
|
|
MetaMonitorTransform crtc_transform;
|
|
|
|
|
2020-01-17 15:08:02 -05:00
|
|
|
crtc = meta_output_get_assigned_crtc (output);
|
2018-07-23 15:36:57 -04:00
|
|
|
crtc_transform =
|
2020-01-17 15:08:02 -05:00
|
|
|
meta_output_logical_to_crtc_transform (output, logical_monitor->transform);
|
2017-03-08 03:05:00 -05:00
|
|
|
|
|
|
|
if (meta_monitor_manager_is_transform_handled (monitor_manager,
|
2017-11-03 06:25:30 -04:00
|
|
|
crtc,
|
2018-07-23 15:36:57 -04:00
|
|
|
crtc_transform))
|
2017-03-08 03:05:00 -05:00
|
|
|
return META_MONITOR_TRANSFORM_NORMAL;
|
|
|
|
else
|
2018-07-23 15:36:57 -04:00
|
|
|
return crtc_transform;
|
2017-03-08 03:05:00 -05:00
|
|
|
}
|
|
|
|
|
2018-10-09 09:55:23 -04:00
|
|
|
static gboolean
|
|
|
|
should_force_shadow_fb (MetaRendererNative *renderer_native,
|
|
|
|
MetaGpuKms *primary_gpu)
|
|
|
|
{
|
2019-10-01 05:54:32 -04:00
|
|
|
MetaRenderer *renderer = META_RENDERER (renderer_native);
|
2018-10-09 09:55:23 -04:00
|
|
|
int kms_fd;
|
|
|
|
uint64_t prefer_shadow = 0;
|
|
|
|
|
2019-10-01 05:54:32 -04:00
|
|
|
if (meta_renderer_is_hardware_accelerated (renderer))
|
|
|
|
return FALSE;
|
2018-10-09 09:55:23 -04:00
|
|
|
|
|
|
|
kms_fd = meta_gpu_kms_get_fd (primary_gpu);
|
|
|
|
if (drmGetCap (kms_fd, DRM_CAP_DUMB_PREFER_SHADOW, &prefer_shadow) == 0)
|
|
|
|
{
|
|
|
|
if (prefer_shadow)
|
|
|
|
{
|
|
|
|
static gboolean logged_once = FALSE;
|
|
|
|
|
|
|
|
if (!logged_once)
|
|
|
|
{
|
|
|
|
g_message ("Forcing shadow framebuffer");
|
|
|
|
logged_once = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-06-08 05:05:31 -04:00
|
|
|
static MetaRendererView *
|
2016-11-25 01:31:38 -05:00
|
|
|
meta_renderer_native_create_view (MetaRenderer *renderer,
|
2020-01-17 15:08:02 -05:00
|
|
|
MetaLogicalMonitor *logical_monitor,
|
|
|
|
MetaOutput *output,
|
|
|
|
MetaCrtc *crtc)
|
2016-06-08 05:05:31 -04:00
|
|
|
{
|
2017-07-06 04:00:56 -04:00
|
|
|
MetaRendererNative *renderer_native = META_RENDERER_NATIVE (renderer);
|
2019-10-01 05:51:53 -04:00
|
|
|
MetaBackend *backend = meta_renderer_get_backend (renderer);
|
2017-03-08 03:05:00 -05:00
|
|
|
MetaMonitorManager *monitor_manager =
|
2019-01-11 09:35:42 -05:00
|
|
|
meta_backend_get_monitor_manager (backend);
|
2017-07-10 06:19:32 -04:00
|
|
|
CoglContext *cogl_context =
|
2018-10-09 09:55:23 -04:00
|
|
|
cogl_context_from_renderer_native (renderer_native);
|
2016-07-31 21:48:30 -04:00
|
|
|
CoglDisplay *cogl_display = cogl_context_get_display (cogl_context);
|
2017-07-24 22:21:04 -04:00
|
|
|
CoglDisplayEGL *cogl_display_egl;
|
2017-07-14 03:20:41 -04:00
|
|
|
CoglOnscreenEGL *onscreen_egl;
|
2020-01-17 15:08:02 -05:00
|
|
|
MetaCrtcConfig *crtc_config;
|
2017-03-08 03:05:00 -05:00
|
|
|
MetaMonitorTransform view_transform;
|
2016-07-31 21:47:11 -04:00
|
|
|
CoglOnscreen *onscreen = NULL;
|
2016-07-31 21:48:30 -04:00
|
|
|
CoglOffscreen *offscreen = NULL;
|
2019-10-22 11:05:46 -04:00
|
|
|
CoglOffscreen *shadowfb = NULL;
|
2017-05-25 04:12:51 -04:00
|
|
|
float scale;
|
2020-01-17 15:08:02 -05:00
|
|
|
int onscreen_width;
|
|
|
|
int onscreen_height;
|
2016-06-08 05:05:31 -04:00
|
|
|
MetaRendererView *view;
|
2016-09-29 10:46:34 -04:00
|
|
|
GError *error = NULL;
|
2016-06-08 05:05:31 -04:00
|
|
|
|
2020-01-17 15:08:02 -05:00
|
|
|
crtc_config = crtc->config;
|
|
|
|
onscreen_width = crtc_config->mode->width;
|
|
|
|
onscreen_height = crtc_config->mode->height;
|
2017-02-24 05:10:52 -05:00
|
|
|
|
2017-07-24 22:21:04 -04:00
|
|
|
onscreen = meta_renderer_native_create_onscreen (renderer_native,
|
2018-12-10 07:19:25 -05:00
|
|
|
renderer_native->primary_gpu_kms,
|
2020-01-17 15:08:02 -05:00
|
|
|
output,
|
|
|
|
crtc,
|
2016-07-31 21:47:11 -04:00
|
|
|
cogl_context,
|
2020-01-17 15:08:02 -05:00
|
|
|
onscreen_width,
|
|
|
|
onscreen_height,
|
2017-07-24 05:35:55 -04:00
|
|
|
&error);
|
2016-07-31 21:47:11 -04:00
|
|
|
if (!onscreen)
|
2017-07-24 05:35:55 -04:00
|
|
|
g_error ("Failed to allocate onscreen framebuffer: %s", error->message);
|
2016-06-08 05:05:31 -04:00
|
|
|
|
2020-01-17 15:08:02 -05:00
|
|
|
view_transform = calculate_view_transform (monitor_manager,
|
|
|
|
logical_monitor,
|
|
|
|
output,
|
|
|
|
crtc);
|
2020-01-17 13:35:19 -05:00
|
|
|
if (view_transform != META_MONITOR_TRANSFORM_NORMAL)
|
2016-07-31 21:48:30 -04:00
|
|
|
{
|
2020-01-17 15:08:02 -05:00
|
|
|
int offscreen_width;
|
|
|
|
int offscreen_height;
|
|
|
|
|
|
|
|
if (meta_monitor_transform_is_rotated (view_transform))
|
|
|
|
{
|
|
|
|
offscreen_width = onscreen_height;
|
|
|
|
offscreen_height = onscreen_width;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
offscreen_width = onscreen_width;
|
|
|
|
offscreen_height = onscreen_height;
|
|
|
|
}
|
|
|
|
|
2017-07-10 06:19:32 -04:00
|
|
|
offscreen = meta_renderer_native_create_offscreen (renderer_native,
|
2016-07-31 21:48:30 -04:00
|
|
|
cogl_context,
|
2020-01-17 15:08:02 -05:00
|
|
|
offscreen_width,
|
|
|
|
offscreen_height,
|
2017-07-24 05:35:55 -04:00
|
|
|
&error);
|
2016-07-31 21:48:30 -04:00
|
|
|
if (!offscreen)
|
2017-07-24 05:35:55 -04:00
|
|
|
g_error ("Failed to allocate back buffer texture: %s", error->message);
|
2019-10-22 11:05:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (should_force_shadow_fb (renderer_native,
|
|
|
|
renderer_native->primary_gpu_kms))
|
|
|
|
{
|
|
|
|
int shadow_width;
|
|
|
|
int shadow_height;
|
|
|
|
|
|
|
|
/* The shadowfb must be the same size as the on-screen framebuffer */
|
|
|
|
shadow_width = cogl_framebuffer_get_width (COGL_FRAMEBUFFER (onscreen));
|
|
|
|
shadow_height = cogl_framebuffer_get_height (COGL_FRAMEBUFFER (onscreen));
|
|
|
|
|
|
|
|
shadowfb = meta_renderer_native_create_offscreen (renderer_native,
|
|
|
|
cogl_context,
|
|
|
|
shadow_width,
|
|
|
|
shadow_height,
|
|
|
|
&error);
|
|
|
|
if (!shadowfb)
|
|
|
|
g_error ("Failed to allocate shadow buffer texture: %s", error->message);
|
2016-07-31 21:48:30 -04:00
|
|
|
}
|
|
|
|
|
2020-01-17 15:08:02 -05:00
|
|
|
if (meta_is_stage_views_scaled ())
|
|
|
|
scale = meta_logical_monitor_get_scale (logical_monitor);
|
|
|
|
else
|
|
|
|
scale = 1.0;
|
|
|
|
|
2016-06-08 05:05:31 -04:00
|
|
|
view = g_object_new (META_TYPE_RENDERER_VIEW,
|
2016-11-25 01:31:38 -05:00
|
|
|
"layout", &logical_monitor->rect,
|
2017-05-25 04:12:51 -04:00
|
|
|
"scale", scale,
|
2016-07-31 21:47:11 -04:00
|
|
|
"framebuffer", onscreen,
|
2016-07-31 21:48:30 -04:00
|
|
|
"offscreen", offscreen,
|
2019-10-22 11:05:46 -04:00
|
|
|
"shadowfb", shadowfb,
|
2017-03-08 03:05:00 -05:00
|
|
|
"transform", view_transform,
|
2016-06-08 05:05:31 -04:00
|
|
|
NULL);
|
2016-07-31 21:48:30 -04:00
|
|
|
g_clear_pointer (&offscreen, cogl_object_unref);
|
2019-10-22 11:05:46 -04:00
|
|
|
g_clear_pointer (&shadowfb, cogl_object_unref);
|
2016-06-08 05:05:31 -04:00
|
|
|
|
|
|
|
meta_onscreen_native_set_view (onscreen, view);
|
|
|
|
|
2016-09-29 10:46:34 -04:00
|
|
|
if (!meta_onscreen_native_allocate (onscreen, &error))
|
|
|
|
{
|
|
|
|
g_warning ("Could not create onscreen: %s", error->message);
|
|
|
|
cogl_object_unref (onscreen);
|
|
|
|
g_object_unref (view);
|
|
|
|
g_error_free (error);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
cogl_object_unref (onscreen);
|
|
|
|
|
|
|
|
/* Ensure we don't point to stale surfaces when creating the offscreen */
|
2017-07-14 03:20:41 -04:00
|
|
|
onscreen_egl = onscreen->winsys;
|
2017-07-24 22:21:04 -04:00
|
|
|
cogl_display_egl = cogl_display->winsys;
|
2016-09-29 10:46:34 -04:00
|
|
|
_cogl_winsys_egl_make_current (cogl_display,
|
2017-07-14 03:20:41 -04:00
|
|
|
onscreen_egl->egl_surface,
|
|
|
|
onscreen_egl->egl_surface,
|
|
|
|
cogl_display_egl->egl_context);
|
2016-09-29 10:46:34 -04:00
|
|
|
|
2016-06-08 05:05:31 -04:00
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
2019-06-19 14:57:14 -04:00
|
|
|
static void
|
|
|
|
meta_renderer_native_rebuild_views (MetaRenderer *renderer)
|
|
|
|
{
|
2019-10-01 05:51:53 -04:00
|
|
|
MetaBackend *backend = meta_renderer_get_backend (renderer);
|
|
|
|
MetaBackendNative *backend_native = META_BACKEND_NATIVE (backend);
|
2019-06-19 15:14:05 -04:00
|
|
|
MetaKms *kms = meta_backend_native_get_kms (backend_native);
|
2019-06-19 14:57:14 -04:00
|
|
|
MetaRendererClass *parent_renderer_class =
|
|
|
|
META_RENDERER_CLASS (meta_renderer_native_parent_class);
|
|
|
|
|
2019-06-19 15:14:05 -04:00
|
|
|
meta_kms_discard_pending_page_flips (kms);
|
|
|
|
|
2019-06-19 14:57:14 -04:00
|
|
|
parent_renderer_class->rebuild_views (renderer);
|
|
|
|
|
|
|
|
meta_renderer_native_queue_modes_reset (META_RENDERER_NATIVE (renderer));
|
|
|
|
}
|
|
|
|
|
2016-06-08 05:05:31 -04:00
|
|
|
void
|
|
|
|
meta_renderer_native_finish_frame (MetaRendererNative *renderer_native)
|
|
|
|
{
|
2019-10-01 05:51:53 -04:00
|
|
|
MetaRenderer *renderer = META_RENDERER (renderer_native);
|
|
|
|
MetaBackend *backend = meta_renderer_get_backend (renderer);
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
MetaBackendNative *backend_native = META_BACKEND_NATIVE (backend);
|
|
|
|
MetaKms *kms = meta_backend_native_get_kms (backend_native);
|
|
|
|
MetaKmsUpdate *kms_update = NULL;
|
|
|
|
|
2016-06-08 05:05:31 -04:00
|
|
|
renderer_native->frame_counter++;
|
2017-09-28 11:59:27 -04:00
|
|
|
|
|
|
|
if (renderer_native->pending_unset_disabled_crtcs)
|
|
|
|
{
|
2017-03-28 00:35:19 -04:00
|
|
|
GList *l;
|
2017-09-28 11:59:27 -04:00
|
|
|
|
2019-10-01 05:51:53 -04:00
|
|
|
for (l = meta_backend_get_gpus (backend); l; l = l->next)
|
2017-09-28 11:59:27 -04:00
|
|
|
{
|
2017-07-10 06:19:32 -04:00
|
|
|
MetaGpu *gpu = l->data;
|
|
|
|
GList *k;
|
2017-09-28 11:59:27 -04:00
|
|
|
|
2017-07-10 06:19:32 -04:00
|
|
|
for (k = meta_gpu_get_crtcs (gpu); k; k = k->next)
|
|
|
|
{
|
|
|
|
MetaCrtc *crtc = k->data;
|
|
|
|
|
2020-01-14 16:34:44 -05:00
|
|
|
if (crtc->config)
|
2017-07-10 06:19:32 -04:00
|
|
|
continue;
|
2017-09-28 11:59:27 -04:00
|
|
|
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
kms_update = meta_kms_ensure_pending_update (kms);
|
|
|
|
meta_crtc_kms_set_mode (crtc, kms_update);
|
2017-07-10 06:19:32 -04:00
|
|
|
}
|
2017-09-28 11:59:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
renderer_native->pending_unset_disabled_crtcs = FALSE;
|
|
|
|
}
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
|
|
|
|
if (kms_update)
|
|
|
|
{
|
2019-11-08 18:14:36 -05:00
|
|
|
g_autoptr (MetaKmsFeedback) kms_feedback = NULL;
|
|
|
|
|
|
|
|
kms_feedback = meta_kms_post_pending_update_sync (kms);
|
|
|
|
if (meta_kms_feedback_get_result (kms_feedback) != META_KMS_FEEDBACK_PASSED)
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
{
|
2019-11-08 18:14:36 -05:00
|
|
|
const GError *error = meta_kms_feedback_get_error (kms_feedback);
|
|
|
|
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED))
|
|
|
|
g_warning ("Failed to post KMS update: %s", error->message);
|
|
|
|
}
|
|
|
|
}
|
2016-06-08 05:05:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int64_t
|
|
|
|
meta_renderer_native_get_frame_counter (MetaRendererNative *renderer_native)
|
|
|
|
{
|
|
|
|
return renderer_native->frame_counter;
|
|
|
|
}
|
|
|
|
|
2017-07-24 22:21:04 -04:00
|
|
|
static gboolean
|
2018-06-07 19:29:44 -04:00
|
|
|
create_secondary_egl_config (MetaEgl *egl,
|
|
|
|
MetaRendererNativeMode mode,
|
|
|
|
EGLDisplay egl_display,
|
|
|
|
EGLConfig *egl_config,
|
|
|
|
GError **error)
|
2017-07-24 22:21:04 -04:00
|
|
|
{
|
|
|
|
EGLint attributes[] = {
|
|
|
|
EGL_RED_SIZE, 1,
|
|
|
|
EGL_GREEN_SIZE, 1,
|
|
|
|
EGL_BLUE_SIZE, 1,
|
|
|
|
EGL_ALPHA_SIZE, EGL_DONT_CARE,
|
|
|
|
EGL_BUFFER_SIZE, EGL_DONT_CARE,
|
|
|
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT,
|
|
|
|
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
|
2018-06-07 19:29:44 -04:00
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case META_RENDERER_NATIVE_MODE_GBM:
|
|
|
|
return choose_egl_config_from_gbm_format (egl,
|
|
|
|
egl_display,
|
|
|
|
attributes,
|
|
|
|
GBM_FORMAT_XRGB8888,
|
|
|
|
egl_config,
|
|
|
|
error);
|
|
|
|
#ifdef HAVE_EGL_DEVICE
|
|
|
|
case META_RENDERER_NATIVE_MODE_EGL_DEVICE:
|
|
|
|
return meta_egl_choose_first_config (egl,
|
|
|
|
egl_display,
|
|
|
|
attributes,
|
|
|
|
egl_config,
|
|
|
|
error);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
2017-07-24 22:21:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static EGLContext
|
|
|
|
create_secondary_egl_context (MetaEgl *egl,
|
|
|
|
EGLDisplay egl_display,
|
|
|
|
EGLConfig egl_config,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
EGLint attributes[] = {
|
|
|
|
EGL_CONTEXT_CLIENT_VERSION, 3,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
|
|
|
|
return meta_egl_create_context (egl,
|
|
|
|
egl_display,
|
|
|
|
egl_config,
|
|
|
|
EGL_NO_CONTEXT,
|
|
|
|
attributes,
|
|
|
|
error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_renderer_native_ensure_gles3 (MetaRendererNative *renderer_native)
|
|
|
|
{
|
|
|
|
MetaEgl *egl = meta_renderer_native_get_egl (renderer_native);
|
|
|
|
|
|
|
|
if (renderer_native->gles3)
|
|
|
|
return;
|
|
|
|
|
|
|
|
renderer_native->gles3 = meta_gles3_new (egl);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
init_secondary_gpu_data_gpu (MetaRendererNativeGpuData *renderer_gpu_data,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
MetaRendererNative *renderer_native = renderer_gpu_data->renderer_native;
|
|
|
|
MetaEgl *egl = meta_renderer_native_get_egl (renderer_native);
|
|
|
|
EGLDisplay egl_display = renderer_gpu_data->egl_display;
|
|
|
|
EGLConfig egl_config;
|
|
|
|
EGLContext egl_context;
|
2019-01-20 05:46:46 -05:00
|
|
|
const char **missing_gl_extensions;
|
renderer/native: Prefer hardware rendering for primary GPU
Mutter prefers platform devices over anything else as the primary GPU.
This will not work too well, when a platform device does not actually
have a rendering GPU but is a display-only device. An example of this
are DisplayLink devices with the proprietary driver stack, which exposes
a DRM KMS platform device but without any rendering driver.
Mutter cannot rely on EGL init failing on such devices either, because
nowadays Mesa supports software renderers on GBM, so the initialization
may well succeed.
The hardware rendering capability is recognized by matching the GL
renderer string to the known Mesa software renderers. At this time,
there is no better alternative to detecting this.
The secondary GPU data is abused for the GL renderer, as the Cogl
context may not have been created yet. Also, the Cogl context would
only be created on the primary GPU, but at this point the primary GPU
has not been chosen yet. Hence, GPU copy path GL context is used as a
proxy and predictor of what the Cogl context might be if it was created.
Mind, that even the GL flavour are not the same between Cogl and
secondary contexts, so this is stretch but it should be just enough.
The logic to choose the primary GPU is changed to always prefer hardware
rendering devices while also maintaining the old order of preferring
platform over boot_vga devices.
Co-authored by: Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>
https://gitlab.gnome.org/GNOME/mutter/merge_requests/271
2018-12-10 09:49:58 -05:00
|
|
|
const char *renderer_str;
|
2017-07-24 22:21:04 -04:00
|
|
|
|
2018-06-07 19:29:44 -04:00
|
|
|
if (!create_secondary_egl_config (egl, renderer_gpu_data->mode, egl_display,
|
|
|
|
&egl_config, error))
|
2017-07-24 22:21:04 -04:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
egl_context = create_secondary_egl_context (egl, egl_display, egl_config, error);
|
|
|
|
if (egl_context == EGL_NO_CONTEXT)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
meta_renderer_native_ensure_gles3 (renderer_native);
|
|
|
|
|
|
|
|
if (!meta_egl_make_current (egl,
|
|
|
|
egl_display,
|
|
|
|
EGL_NO_SURFACE,
|
|
|
|
EGL_NO_SURFACE,
|
|
|
|
egl_context,
|
|
|
|
error))
|
|
|
|
{
|
|
|
|
meta_egl_destroy_context (egl, egl_display, egl_context, NULL);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
renderer/native: Prefer hardware rendering for primary GPU
Mutter prefers platform devices over anything else as the primary GPU.
This will not work too well, when a platform device does not actually
have a rendering GPU but is a display-only device. An example of this
are DisplayLink devices with the proprietary driver stack, which exposes
a DRM KMS platform device but without any rendering driver.
Mutter cannot rely on EGL init failing on such devices either, because
nowadays Mesa supports software renderers on GBM, so the initialization
may well succeed.
The hardware rendering capability is recognized by matching the GL
renderer string to the known Mesa software renderers. At this time,
there is no better alternative to detecting this.
The secondary GPU data is abused for the GL renderer, as the Cogl
context may not have been created yet. Also, the Cogl context would
only be created on the primary GPU, but at this point the primary GPU
has not been chosen yet. Hence, GPU copy path GL context is used as a
proxy and predictor of what the Cogl context might be if it was created.
Mind, that even the GL flavour are not the same between Cogl and
secondary contexts, so this is stretch but it should be just enough.
The logic to choose the primary GPU is changed to always prefer hardware
rendering devices while also maintaining the old order of preferring
platform over boot_vga devices.
Co-authored by: Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>
https://gitlab.gnome.org/GNOME/mutter/merge_requests/271
2018-12-10 09:49:58 -05:00
|
|
|
renderer_str = (const char *) glGetString (GL_RENDERER);
|
|
|
|
if (g_str_has_prefix (renderer_str, "llvmpipe") ||
|
|
|
|
g_str_has_prefix (renderer_str, "softpipe") ||
|
|
|
|
g_str_has_prefix (renderer_str, "swrast"))
|
2018-10-23 04:09:22 -04:00
|
|
|
{
|
|
|
|
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
|
|
|
"Do not want to use software renderer (%s), falling back to CPU copy path",
|
|
|
|
renderer_str);
|
2019-01-28 06:02:07 -05:00
|
|
|
goto out_fail_with_context;
|
2018-10-23 04:09:22 -04:00
|
|
|
}
|
renderer/native: Prefer hardware rendering for primary GPU
Mutter prefers platform devices over anything else as the primary GPU.
This will not work too well, when a platform device does not actually
have a rendering GPU but is a display-only device. An example of this
are DisplayLink devices with the proprietary driver stack, which exposes
a DRM KMS platform device but without any rendering driver.
Mutter cannot rely on EGL init failing on such devices either, because
nowadays Mesa supports software renderers on GBM, so the initialization
may well succeed.
The hardware rendering capability is recognized by matching the GL
renderer string to the known Mesa software renderers. At this time,
there is no better alternative to detecting this.
The secondary GPU data is abused for the GL renderer, as the Cogl
context may not have been created yet. Also, the Cogl context would
only be created on the primary GPU, but at this point the primary GPU
has not been chosen yet. Hence, GPU copy path GL context is used as a
proxy and predictor of what the Cogl context might be if it was created.
Mind, that even the GL flavour are not the same between Cogl and
secondary contexts, so this is stretch but it should be just enough.
The logic to choose the primary GPU is changed to always prefer hardware
rendering devices while also maintaining the old order of preferring
platform over boot_vga devices.
Co-authored by: Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>
https://gitlab.gnome.org/GNOME/mutter/merge_requests/271
2018-12-10 09:49:58 -05:00
|
|
|
|
2017-07-24 22:21:04 -04:00
|
|
|
if (!meta_gles3_has_extensions (renderer_native->gles3,
|
|
|
|
&missing_gl_extensions,
|
|
|
|
"GL_OES_EGL_image_external",
|
|
|
|
NULL))
|
|
|
|
{
|
|
|
|
char *missing_gl_extensions_str;
|
|
|
|
|
2019-01-20 05:46:46 -05:00
|
|
|
missing_gl_extensions_str = g_strjoinv (", ",
|
|
|
|
(char **) missing_gl_extensions);
|
2017-07-24 22:21:04 -04:00
|
|
|
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
|
|
|
"Missing OpenGL ES extensions: %s",
|
|
|
|
missing_gl_extensions_str);
|
|
|
|
g_free (missing_gl_extensions_str);
|
|
|
|
g_free (missing_gl_extensions);
|
2019-01-28 06:02:07 -05:00
|
|
|
|
|
|
|
goto out_fail_with_context;
|
2017-07-24 22:21:04 -04:00
|
|
|
}
|
|
|
|
|
2018-10-23 04:09:22 -04:00
|
|
|
renderer_gpu_data->secondary.is_hardware_rendering = TRUE;
|
2017-07-24 22:21:04 -04:00
|
|
|
renderer_gpu_data->secondary.egl_context = egl_context;
|
|
|
|
renderer_gpu_data->secondary.egl_config = egl_config;
|
2018-11-29 06:34:40 -05:00
|
|
|
renderer_gpu_data->secondary.copy_mode = META_SHARED_FRAMEBUFFER_COPY_MODE_SECONDARY_GPU;
|
|
|
|
|
|
|
|
renderer_gpu_data->secondary.has_EGL_EXT_image_dma_buf_import_modifiers =
|
|
|
|
meta_egl_has_extensions (egl, egl_display, NULL,
|
|
|
|
"EGL_EXT_image_dma_buf_import_modifiers",
|
|
|
|
NULL);
|
2017-07-24 22:21:04 -04:00
|
|
|
|
|
|
|
return TRUE;
|
2019-01-28 06:02:07 -05:00
|
|
|
|
|
|
|
out_fail_with_context:
|
|
|
|
meta_egl_make_current (egl,
|
|
|
|
egl_display,
|
|
|
|
EGL_NO_SURFACE,
|
|
|
|
EGL_NO_SURFACE,
|
|
|
|
EGL_NO_CONTEXT,
|
|
|
|
NULL);
|
|
|
|
meta_egl_destroy_context (egl, egl_display, egl_context, NULL);
|
|
|
|
|
|
|
|
return FALSE;
|
2017-07-24 22:21:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_secondary_gpu_data_cpu (MetaRendererNativeGpuData *renderer_gpu_data)
|
|
|
|
{
|
renderer/native: Prefer hardware rendering for primary GPU
Mutter prefers platform devices over anything else as the primary GPU.
This will not work too well, when a platform device does not actually
have a rendering GPU but is a display-only device. An example of this
are DisplayLink devices with the proprietary driver stack, which exposes
a DRM KMS platform device but without any rendering driver.
Mutter cannot rely on EGL init failing on such devices either, because
nowadays Mesa supports software renderers on GBM, so the initialization
may well succeed.
The hardware rendering capability is recognized by matching the GL
renderer string to the known Mesa software renderers. At this time,
there is no better alternative to detecting this.
The secondary GPU data is abused for the GL renderer, as the Cogl
context may not have been created yet. Also, the Cogl context would
only be created on the primary GPU, but at this point the primary GPU
has not been chosen yet. Hence, GPU copy path GL context is used as a
proxy and predictor of what the Cogl context might be if it was created.
Mind, that even the GL flavour are not the same between Cogl and
secondary contexts, so this is stretch but it should be just enough.
The logic to choose the primary GPU is changed to always prefer hardware
rendering devices while also maintaining the old order of preferring
platform over boot_vga devices.
Co-authored by: Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>
https://gitlab.gnome.org/GNOME/mutter/merge_requests/271
2018-12-10 09:49:58 -05:00
|
|
|
renderer_gpu_data->secondary.is_hardware_rendering = FALSE;
|
2019-05-24 10:07:14 -04:00
|
|
|
|
|
|
|
/* First try ZERO, it automatically falls back to PRIMARY as needed */
|
|
|
|
renderer_gpu_data->secondary.copy_mode =
|
|
|
|
META_SHARED_FRAMEBUFFER_COPY_MODE_ZERO;
|
2017-07-24 22:21:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_secondary_gpu_data (MetaRendererNativeGpuData *renderer_gpu_data)
|
|
|
|
{
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
if (init_secondary_gpu_data_gpu (renderer_gpu_data, &error))
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_warning ("Failed to initialize accelerated iGPU/dGPU framebuffer sharing: %s",
|
|
|
|
error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
|
|
|
|
init_secondary_gpu_data_cpu (renderer_gpu_data);
|
|
|
|
}
|
|
|
|
|
renderer/native: Prefer hardware rendering for primary GPU
Mutter prefers platform devices over anything else as the primary GPU.
This will not work too well, when a platform device does not actually
have a rendering GPU but is a display-only device. An example of this
are DisplayLink devices with the proprietary driver stack, which exposes
a DRM KMS platform device but without any rendering driver.
Mutter cannot rely on EGL init failing on such devices either, because
nowadays Mesa supports software renderers on GBM, so the initialization
may well succeed.
The hardware rendering capability is recognized by matching the GL
renderer string to the known Mesa software renderers. At this time,
there is no better alternative to detecting this.
The secondary GPU data is abused for the GL renderer, as the Cogl
context may not have been created yet. Also, the Cogl context would
only be created on the primary GPU, but at this point the primary GPU
has not been chosen yet. Hence, GPU copy path GL context is used as a
proxy and predictor of what the Cogl context might be if it was created.
Mind, that even the GL flavour are not the same between Cogl and
secondary contexts, so this is stretch but it should be just enough.
The logic to choose the primary GPU is changed to always prefer hardware
rendering devices while also maintaining the old order of preferring
platform over boot_vga devices.
Co-authored by: Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>
https://gitlab.gnome.org/GNOME/mutter/merge_requests/271
2018-12-10 09:49:58 -05:00
|
|
|
static gboolean
|
|
|
|
gpu_kms_is_hardware_rendering (MetaRendererNative *renderer_native,
|
|
|
|
MetaGpuKms *gpu_kms)
|
|
|
|
{
|
|
|
|
MetaRendererNativeGpuData *data;
|
|
|
|
|
|
|
|
data = meta_renderer_native_get_gpu_data (renderer_native, gpu_kms);
|
|
|
|
return data->secondary.is_hardware_rendering;
|
|
|
|
}
|
|
|
|
|
2019-04-03 06:11:45 -04:00
|
|
|
static EGLDisplay
|
|
|
|
init_gbm_egl_display (MetaRendererNative *renderer_native,
|
|
|
|
struct gbm_device *gbm_device,
|
|
|
|
GError **error)
|
2016-05-09 09:22:01 -04:00
|
|
|
{
|
2017-07-24 22:21:04 -04:00
|
|
|
MetaEgl *egl = meta_renderer_native_get_egl (renderer_native);
|
2016-08-17 22:37:16 -04:00
|
|
|
EGLDisplay egl_display;
|
2016-05-09 09:22:01 -04:00
|
|
|
|
2016-08-31 23:04:22 -04:00
|
|
|
if (!meta_egl_has_extensions (egl, EGL_NO_DISPLAY, NULL,
|
|
|
|
"EGL_MESA_platform_gbm",
|
2017-11-02 23:59:00 -04:00
|
|
|
NULL) &&
|
|
|
|
!meta_egl_has_extensions (egl, EGL_NO_DISPLAY, NULL,
|
|
|
|
"EGL_KHR_platform_gbm",
|
2016-08-31 23:04:22 -04:00
|
|
|
NULL))
|
|
|
|
{
|
|
|
|
g_set_error (error, G_IO_ERROR,
|
|
|
|
G_IO_ERROR_FAILED,
|
|
|
|
"Missing extension for GBM renderer: EGL_KHR_platform_gbm");
|
2019-04-03 06:11:45 -04:00
|
|
|
return EGL_NO_DISPLAY;
|
2016-08-31 23:04:22 -04:00
|
|
|
}
|
|
|
|
|
2019-04-03 06:11:45 -04:00
|
|
|
egl_display = meta_egl_get_platform_display (egl,
|
|
|
|
EGL_PLATFORM_GBM_KHR,
|
|
|
|
gbm_device, NULL, error);
|
|
|
|
if (egl_display == EGL_NO_DISPLAY)
|
|
|
|
return EGL_NO_DISPLAY;
|
|
|
|
|
|
|
|
if (!meta_egl_initialize (egl, egl_display, error))
|
|
|
|
return EGL_NO_DISPLAY;
|
|
|
|
|
|
|
|
return egl_display;
|
|
|
|
}
|
|
|
|
|
|
|
|
static MetaRendererNativeGpuData *
|
|
|
|
create_renderer_gpu_data_gbm (MetaRendererNative *renderer_native,
|
|
|
|
MetaGpuKms *gpu_kms,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
struct gbm_device *gbm_device;
|
|
|
|
int kms_fd;
|
|
|
|
MetaRendererNativeGpuData *renderer_gpu_data;
|
|
|
|
g_autoptr (GError) local_error = NULL;
|
|
|
|
|
2017-07-10 06:19:32 -04:00
|
|
|
kms_fd = meta_gpu_kms_get_fd (gpu_kms);
|
2017-07-06 04:00:56 -04:00
|
|
|
|
|
|
|
gbm_device = gbm_create_device (kms_fd);
|
2016-08-17 22:37:16 -04:00
|
|
|
if (!gbm_device)
|
2016-05-09 09:22:01 -04:00
|
|
|
{
|
2016-05-09 22:16:45 -04:00
|
|
|
g_set_error (error, G_IO_ERROR,
|
2016-05-09 09:22:01 -04:00
|
|
|
G_IO_ERROR_FAILED,
|
2016-10-28 03:35:31 -04:00
|
|
|
"Failed to create gbm device: %s", g_strerror (errno));
|
2017-07-10 06:19:32 -04:00
|
|
|
return NULL;
|
2016-05-09 09:22:01 -04:00
|
|
|
}
|
|
|
|
|
2017-07-10 06:19:32 -04:00
|
|
|
renderer_gpu_data = meta_create_renderer_native_gpu_data (gpu_kms);
|
|
|
|
renderer_gpu_data->renderer_native = renderer_native;
|
|
|
|
renderer_gpu_data->gbm.device = gbm_device;
|
|
|
|
renderer_gpu_data->mode = META_RENDERER_NATIVE_MODE_GBM;
|
|
|
|
|
2019-04-03 06:11:45 -04:00
|
|
|
renderer_gpu_data->egl_display = init_gbm_egl_display (renderer_native,
|
|
|
|
gbm_device,
|
|
|
|
&local_error);
|
|
|
|
if (renderer_gpu_data->egl_display == EGL_NO_DISPLAY)
|
|
|
|
{
|
|
|
|
g_debug ("GBM EGL init for %s failed: %s",
|
|
|
|
meta_gpu_kms_get_file_path (gpu_kms),
|
|
|
|
local_error->message);
|
2016-08-17 22:37:16 -04:00
|
|
|
|
2019-04-03 06:11:45 -04:00
|
|
|
init_secondary_gpu_data_cpu (renderer_gpu_data);
|
|
|
|
return renderer_gpu_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
init_secondary_gpu_data (renderer_gpu_data);
|
2017-07-10 06:19:32 -04:00
|
|
|
return renderer_gpu_data;
|
2016-05-09 09:22:01 -04:00
|
|
|
}
|
|
|
|
|
2016-08-17 23:28:59 -04:00
|
|
|
#ifdef HAVE_EGL_DEVICE
|
|
|
|
static const char *
|
|
|
|
get_drm_device_file (MetaEgl *egl,
|
|
|
|
EGLDeviceEXT device,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
if (!meta_egl_egl_device_has_extensions (egl, device,
|
|
|
|
NULL,
|
|
|
|
"EGL_EXT_device_drm",
|
|
|
|
NULL))
|
|
|
|
{
|
|
|
|
g_set_error (error, G_IO_ERROR,
|
|
|
|
G_IO_ERROR_FAILED,
|
|
|
|
"Missing required EGLDevice extension EGL_EXT_device_drm");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return meta_egl_query_device_string (egl, device,
|
|
|
|
EGL_DRM_DEVICE_FILE_EXT,
|
|
|
|
error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static EGLDeviceEXT
|
2017-07-10 06:19:32 -04:00
|
|
|
find_egl_device (MetaRendererNative *renderer_native,
|
|
|
|
MetaGpuKms *gpu_kms,
|
|
|
|
GError **error)
|
2016-08-17 23:28:59 -04:00
|
|
|
{
|
2017-07-24 03:54:29 -04:00
|
|
|
MetaEgl *egl = meta_renderer_native_get_egl (renderer_native);
|
2019-01-20 05:46:46 -05:00
|
|
|
const char **missing_extensions;
|
2016-08-17 23:28:59 -04:00
|
|
|
EGLint num_devices;
|
|
|
|
EGLDeviceEXT *devices;
|
2017-07-06 04:00:56 -04:00
|
|
|
const char *kms_file_path;
|
2016-08-17 23:28:59 -04:00
|
|
|
EGLDeviceEXT device;
|
|
|
|
EGLint i;
|
|
|
|
|
|
|
|
if (!meta_egl_has_extensions (egl,
|
|
|
|
EGL_NO_DISPLAY,
|
|
|
|
&missing_extensions,
|
|
|
|
"EGL_EXT_device_base",
|
|
|
|
NULL))
|
|
|
|
{
|
|
|
|
char *missing_extensions_str;
|
|
|
|
|
2019-01-20 05:46:46 -05:00
|
|
|
missing_extensions_str = g_strjoinv (", ", (char **) missing_extensions);
|
2016-08-17 23:28:59 -04:00
|
|
|
g_set_error (error, G_IO_ERROR,
|
|
|
|
G_IO_ERROR_FAILED,
|
|
|
|
"Missing EGL extensions required for EGLDevice renderer: %s",
|
|
|
|
missing_extensions_str);
|
|
|
|
g_free (missing_extensions_str);
|
|
|
|
g_free (missing_extensions);
|
|
|
|
return EGL_NO_DEVICE_EXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!meta_egl_query_devices (egl, 0, NULL, &num_devices, error))
|
|
|
|
return EGL_NO_DEVICE_EXT;
|
|
|
|
|
|
|
|
devices = g_new0 (EGLDeviceEXT, num_devices);
|
|
|
|
if (!meta_egl_query_devices (egl, num_devices, devices, &num_devices,
|
|
|
|
error))
|
|
|
|
{
|
|
|
|
g_free (devices);
|
|
|
|
return EGL_NO_DEVICE_EXT;
|
|
|
|
}
|
|
|
|
|
2017-07-10 06:19:32 -04:00
|
|
|
kms_file_path = meta_gpu_kms_get_file_path (gpu_kms);
|
2017-07-06 04:00:56 -04:00
|
|
|
|
2016-08-17 23:28:59 -04:00
|
|
|
device = EGL_NO_DEVICE_EXT;
|
|
|
|
for (i = 0; i < num_devices; i++)
|
|
|
|
{
|
|
|
|
const char *egl_device_drm_path;
|
|
|
|
|
|
|
|
g_clear_error (error);
|
|
|
|
|
|
|
|
egl_device_drm_path = get_drm_device_file (egl, devices[i], error);
|
|
|
|
if (!egl_device_drm_path)
|
|
|
|
continue;
|
|
|
|
|
2017-07-06 04:00:56 -04:00
|
|
|
if (g_str_equal (egl_device_drm_path, kms_file_path))
|
2016-08-17 23:28:59 -04:00
|
|
|
{
|
|
|
|
device = devices[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_free (devices);
|
|
|
|
|
|
|
|
if (device == EGL_NO_DEVICE_EXT)
|
|
|
|
{
|
|
|
|
if (!*error)
|
|
|
|
g_set_error (error, G_IO_ERROR,
|
|
|
|
G_IO_ERROR_FAILED,
|
|
|
|
"Failed to find matching EGLDeviceEXT");
|
|
|
|
return EGL_NO_DEVICE_EXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return device;
|
|
|
|
}
|
|
|
|
|
|
|
|
static EGLDisplay
|
2017-07-10 06:19:32 -04:00
|
|
|
get_egl_device_display (MetaRendererNative *renderer_native,
|
|
|
|
MetaGpuKms *gpu_kms,
|
|
|
|
EGLDeviceEXT egl_device,
|
|
|
|
GError **error)
|
2016-08-17 23:28:59 -04:00
|
|
|
{
|
2017-07-24 03:54:29 -04:00
|
|
|
MetaEgl *egl = meta_renderer_native_get_egl (renderer_native);
|
2017-07-10 06:19:32 -04:00
|
|
|
int kms_fd = meta_gpu_kms_get_fd (gpu_kms);
|
2016-08-17 23:28:59 -04:00
|
|
|
EGLint platform_attribs[] = {
|
2017-07-06 04:00:56 -04:00
|
|
|
EGL_DRM_MASTER_FD_EXT, kms_fd,
|
2016-08-17 23:28:59 -04:00
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
|
|
|
|
return meta_egl_get_platform_display (egl, EGL_PLATFORM_DEVICE_EXT,
|
|
|
|
(void *) egl_device,
|
|
|
|
platform_attribs,
|
|
|
|
error);
|
|
|
|
}
|
|
|
|
|
2018-12-10 08:46:56 -05:00
|
|
|
static int
|
|
|
|
count_drm_devices (MetaRendererNative *renderer_native)
|
|
|
|
{
|
2019-10-01 05:51:53 -04:00
|
|
|
MetaRenderer *renderer = META_RENDERER (renderer_native);
|
|
|
|
MetaBackend *backend = meta_renderer_get_backend (renderer);
|
|
|
|
|
|
|
|
return g_list_length (meta_backend_get_gpus (backend));
|
2018-12-10 08:46:56 -05:00
|
|
|
}
|
|
|
|
|
2017-07-10 06:19:32 -04:00
|
|
|
static MetaRendererNativeGpuData *
|
|
|
|
create_renderer_gpu_data_egl_device (MetaRendererNative *renderer_native,
|
|
|
|
MetaGpuKms *gpu_kms,
|
|
|
|
GError **error)
|
2016-08-17 23:28:59 -04:00
|
|
|
{
|
2017-07-24 03:54:29 -04:00
|
|
|
MetaEgl *egl = meta_renderer_native_get_egl (renderer_native);
|
2019-01-20 05:46:46 -05:00
|
|
|
const char **missing_extensions;
|
2016-08-17 23:28:59 -04:00
|
|
|
EGLDeviceEXT egl_device;
|
|
|
|
EGLDisplay egl_display;
|
2017-07-10 06:19:32 -04:00
|
|
|
MetaRendererNativeGpuData *renderer_gpu_data;
|
2016-08-17 23:28:59 -04:00
|
|
|
|
2018-12-10 08:46:56 -05:00
|
|
|
if (count_drm_devices (renderer_native) != 1)
|
2017-07-24 22:21:04 -04:00
|
|
|
{
|
|
|
|
g_set_error (error, G_IO_ERROR,
|
|
|
|
G_IO_ERROR_FAILED,
|
|
|
|
"EGLDevice currently only works with single GPU systems");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-07-10 06:19:32 -04:00
|
|
|
egl_device = find_egl_device (renderer_native, gpu_kms, error);
|
2016-08-17 23:28:59 -04:00
|
|
|
if (egl_device == EGL_NO_DEVICE_EXT)
|
2017-07-10 06:19:32 -04:00
|
|
|
return NULL;
|
2016-08-17 23:28:59 -04:00
|
|
|
|
2017-07-10 06:19:32 -04:00
|
|
|
egl_display = get_egl_device_display (renderer_native, gpu_kms,
|
|
|
|
egl_device, error);
|
2016-08-17 23:28:59 -04:00
|
|
|
if (egl_display == EGL_NO_DISPLAY)
|
2017-07-10 06:19:32 -04:00
|
|
|
return NULL;
|
2016-08-17 23:28:59 -04:00
|
|
|
|
|
|
|
if (!meta_egl_initialize (egl, egl_display, error))
|
2017-07-10 06:19:32 -04:00
|
|
|
return NULL;
|
2016-08-17 23:28:59 -04:00
|
|
|
|
|
|
|
if (!meta_egl_has_extensions (egl,
|
|
|
|
egl_display,
|
|
|
|
&missing_extensions,
|
|
|
|
"EGL_NV_output_drm_flip_event",
|
|
|
|
"EGL_EXT_output_base",
|
|
|
|
"EGL_EXT_output_drm",
|
|
|
|
"EGL_KHR_stream",
|
|
|
|
"EGL_KHR_stream_producer_eglsurface",
|
|
|
|
"EGL_EXT_stream_consumer_egloutput",
|
|
|
|
"EGL_EXT_stream_acquire_mode",
|
|
|
|
NULL))
|
|
|
|
{
|
|
|
|
char *missing_extensions_str;
|
|
|
|
|
2019-01-20 05:46:46 -05:00
|
|
|
missing_extensions_str = g_strjoinv (", ", (char **) missing_extensions);
|
2016-08-17 23:28:59 -04:00
|
|
|
g_set_error (error, G_IO_ERROR,
|
|
|
|
G_IO_ERROR_FAILED,
|
|
|
|
"Missing EGL extensions required for EGLDevice renderer: %s",
|
|
|
|
missing_extensions_str);
|
2019-06-12 12:58:54 -04:00
|
|
|
meta_egl_terminate (egl, egl_display, NULL);
|
2016-08-17 23:28:59 -04:00
|
|
|
g_free (missing_extensions_str);
|
|
|
|
g_free (missing_extensions);
|
2017-07-10 06:19:32 -04:00
|
|
|
return NULL;
|
2016-08-17 23:28:59 -04:00
|
|
|
}
|
|
|
|
|
2017-07-10 06:19:32 -04:00
|
|
|
renderer_gpu_data = meta_create_renderer_native_gpu_data (gpu_kms);
|
|
|
|
renderer_gpu_data->renderer_native = renderer_native;
|
|
|
|
renderer_gpu_data->egl.device = egl_device;
|
|
|
|
renderer_gpu_data->mode = META_RENDERER_NATIVE_MODE_EGL_DEVICE;
|
2017-07-24 22:21:04 -04:00
|
|
|
renderer_gpu_data->egl_display = egl_display;
|
2016-08-17 23:28:59 -04:00
|
|
|
|
2017-07-10 06:19:32 -04:00
|
|
|
return renderer_gpu_data;
|
2016-08-17 23:28:59 -04:00
|
|
|
}
|
|
|
|
#endif /* HAVE_EGL_DEVICE */
|
|
|
|
|
2017-07-10 06:19:32 -04:00
|
|
|
static MetaRendererNativeGpuData *
|
|
|
|
meta_renderer_native_create_renderer_gpu_data (MetaRendererNative *renderer_native,
|
|
|
|
MetaGpuKms *gpu_kms,
|
|
|
|
GError **error)
|
2016-08-17 23:14:03 -04:00
|
|
|
{
|
2017-07-10 06:19:32 -04:00
|
|
|
MetaRendererNativeGpuData *renderer_gpu_data;
|
2016-08-17 23:28:59 -04:00
|
|
|
GError *gbm_error = NULL;
|
|
|
|
#ifdef HAVE_EGL_DEVICE
|
|
|
|
GError *egl_device_error = NULL;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_EGL_DEVICE
|
2017-06-27 21:31:48 -04:00
|
|
|
/* Try to initialize the EGLDevice backend first. Whenever we use a
|
|
|
|
* non-NVIDIA GPU, the EGLDevice enumeration function won't find a match, and
|
|
|
|
* we'll fall back to GBM (which will always succeed as it has a software
|
|
|
|
* rendering fallback)
|
|
|
|
*/
|
2017-07-10 06:19:32 -04:00
|
|
|
renderer_gpu_data = create_renderer_gpu_data_egl_device (renderer_native,
|
|
|
|
gpu_kms,
|
|
|
|
&egl_device_error);
|
|
|
|
if (renderer_gpu_data)
|
|
|
|
return renderer_gpu_data;
|
2017-06-27 21:31:48 -04:00
|
|
|
#endif
|
|
|
|
|
2017-07-10 06:19:32 -04:00
|
|
|
renderer_gpu_data = create_renderer_gpu_data_gbm (renderer_native,
|
|
|
|
gpu_kms,
|
|
|
|
&gbm_error);
|
|
|
|
if (renderer_gpu_data)
|
2016-08-17 23:28:59 -04:00
|
|
|
{
|
2017-07-07 05:59:20 -04:00
|
|
|
#ifdef HAVE_EGL_DEVICE
|
2017-06-27 21:31:48 -04:00
|
|
|
g_error_free (egl_device_error);
|
2017-07-07 05:59:20 -04:00
|
|
|
#endif
|
2017-07-10 06:19:32 -04:00
|
|
|
return renderer_gpu_data;
|
2016-08-17 23:28:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
g_set_error (error, G_IO_ERROR,
|
|
|
|
G_IO_ERROR_FAILED,
|
|
|
|
"Failed to initialize renderer: "
|
|
|
|
"%s"
|
|
|
|
#ifdef HAVE_EGL_DEVICE
|
|
|
|
", %s"
|
|
|
|
#endif
|
|
|
|
, gbm_error->message
|
|
|
|
#ifdef HAVE_EGL_DEVICE
|
|
|
|
, egl_device_error->message
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
|
|
|
|
g_error_free (gbm_error);
|
|
|
|
#ifdef HAVE_EGL_DEVICE
|
|
|
|
g_error_free (egl_device_error);
|
|
|
|
#endif
|
|
|
|
|
2017-07-10 06:19:32 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-09-17 07:03:18 -04:00
|
|
|
static gboolean
|
|
|
|
create_renderer_gpu_data (MetaRendererNative *renderer_native,
|
|
|
|
MetaGpuKms *gpu_kms,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
MetaRendererNativeGpuData *renderer_gpu_data;
|
|
|
|
|
|
|
|
renderer_gpu_data =
|
|
|
|
meta_renderer_native_create_renderer_gpu_data (renderer_native,
|
|
|
|
gpu_kms,
|
|
|
|
error);
|
|
|
|
if (!renderer_gpu_data)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
g_hash_table_insert (renderer_native->gpu_datas,
|
|
|
|
gpu_kms,
|
|
|
|
renderer_gpu_data);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-01-11 09:35:42 -05:00
|
|
|
on_gpu_added (MetaBackendNative *backend_native,
|
2018-09-17 07:03:18 -04:00
|
|
|
MetaGpuKms *gpu_kms,
|
|
|
|
MetaRendererNative *renderer_native)
|
|
|
|
{
|
2019-01-11 09:35:42 -05:00
|
|
|
MetaBackend *backend = META_BACKEND (backend_native);
|
2018-09-17 07:03:18 -04:00
|
|
|
ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
|
|
|
|
CoglContext *cogl_context = clutter_backend_get_cogl_context (clutter_backend);
|
|
|
|
CoglDisplay *cogl_display = cogl_context_get_display (cogl_context);
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
if (!create_renderer_gpu_data (renderer_native, gpu_kms, &error))
|
|
|
|
{
|
|
|
|
g_warning ("on_gpu_added: could not create gpu_data for gpu %s: %s",
|
|
|
|
meta_gpu_kms_get_file_path (gpu_kms), error->message);
|
|
|
|
g_clear_error (&error);
|
|
|
|
}
|
|
|
|
|
|
|
|
_cogl_winsys_egl_ensure_current (cogl_display);
|
|
|
|
}
|
|
|
|
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
static void
|
|
|
|
on_power_save_mode_changed (MetaMonitorManager *monitor_manager,
|
|
|
|
MetaRendererNative *renderer_native)
|
|
|
|
{
|
2019-10-01 05:51:53 -04:00
|
|
|
MetaRenderer *renderer = META_RENDERER (renderer_native);
|
|
|
|
MetaBackend *backend = meta_renderer_get_backend (renderer);
|
|
|
|
MetaBackendNative *backend_native = META_BACKEND_NATIVE (backend);
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
MetaKms *kms = meta_backend_native_get_kms (backend_native);
|
|
|
|
MetaPowerSave power_save_mode;
|
|
|
|
|
|
|
|
power_save_mode = meta_monitor_manager_get_power_save_mode (monitor_manager);
|
|
|
|
if (power_save_mode == META_POWER_SAVE_ON)
|
|
|
|
meta_renderer_native_queue_modes_reset (renderer_native);
|
|
|
|
else
|
|
|
|
meta_kms_discard_pending_page_flips (kms);
|
|
|
|
}
|
|
|
|
|
2018-12-10 07:19:25 -05:00
|
|
|
static MetaGpuKms *
|
2019-01-11 09:35:42 -05:00
|
|
|
choose_primary_gpu_unchecked (MetaBackend *backend,
|
2019-04-03 06:34:09 -04:00
|
|
|
MetaRendererNative *renderer_native)
|
2018-12-10 07:19:25 -05:00
|
|
|
{
|
2019-01-11 09:35:42 -05:00
|
|
|
GList *gpus = meta_backend_get_gpus (backend);
|
2018-12-10 07:19:25 -05:00
|
|
|
GList *l;
|
renderer/native: Prefer hardware rendering for primary GPU
Mutter prefers platform devices over anything else as the primary GPU.
This will not work too well, when a platform device does not actually
have a rendering GPU but is a display-only device. An example of this
are DisplayLink devices with the proprietary driver stack, which exposes
a DRM KMS platform device but without any rendering driver.
Mutter cannot rely on EGL init failing on such devices either, because
nowadays Mesa supports software renderers on GBM, so the initialization
may well succeed.
The hardware rendering capability is recognized by matching the GL
renderer string to the known Mesa software renderers. At this time,
there is no better alternative to detecting this.
The secondary GPU data is abused for the GL renderer, as the Cogl
context may not have been created yet. Also, the Cogl context would
only be created on the primary GPU, but at this point the primary GPU
has not been chosen yet. Hence, GPU copy path GL context is used as a
proxy and predictor of what the Cogl context might be if it was created.
Mind, that even the GL flavour are not the same between Cogl and
secondary contexts, so this is stretch but it should be just enough.
The logic to choose the primary GPU is changed to always prefer hardware
rendering devices while also maintaining the old order of preferring
platform over boot_vga devices.
Co-authored by: Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>
https://gitlab.gnome.org/GNOME/mutter/merge_requests/271
2018-12-10 09:49:58 -05:00
|
|
|
int allow_sw;
|
2018-12-10 07:19:25 -05:00
|
|
|
|
renderer/native: Prefer hardware rendering for primary GPU
Mutter prefers platform devices over anything else as the primary GPU.
This will not work too well, when a platform device does not actually
have a rendering GPU but is a display-only device. An example of this
are DisplayLink devices with the proprietary driver stack, which exposes
a DRM KMS platform device but without any rendering driver.
Mutter cannot rely on EGL init failing on such devices either, because
nowadays Mesa supports software renderers on GBM, so the initialization
may well succeed.
The hardware rendering capability is recognized by matching the GL
renderer string to the known Mesa software renderers. At this time,
there is no better alternative to detecting this.
The secondary GPU data is abused for the GL renderer, as the Cogl
context may not have been created yet. Also, the Cogl context would
only be created on the primary GPU, but at this point the primary GPU
has not been chosen yet. Hence, GPU copy path GL context is used as a
proxy and predictor of what the Cogl context might be if it was created.
Mind, that even the GL flavour are not the same between Cogl and
secondary contexts, so this is stretch but it should be just enough.
The logic to choose the primary GPU is changed to always prefer hardware
rendering devices while also maintaining the old order of preferring
platform over boot_vga devices.
Co-authored by: Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>
https://gitlab.gnome.org/GNOME/mutter/merge_requests/271
2018-12-10 09:49:58 -05:00
|
|
|
/*
|
|
|
|
* Check first hardware rendering devices, and if none found,
|
|
|
|
* then software rendering devices.
|
|
|
|
*/
|
|
|
|
for (allow_sw = 0; allow_sw < 2; allow_sw++)
|
|
|
|
{
|
|
|
|
/* Prefer a platform device */
|
|
|
|
for (l = gpus; l; l = l->next)
|
|
|
|
{
|
|
|
|
MetaGpuKms *gpu_kms = META_GPU_KMS (l->data);
|
|
|
|
|
|
|
|
if (meta_gpu_kms_is_platform_device (gpu_kms) &&
|
|
|
|
(allow_sw == 1 ||
|
|
|
|
gpu_kms_is_hardware_rendering (renderer_native, gpu_kms)))
|
|
|
|
return gpu_kms;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Otherwise a device we booted with */
|
|
|
|
for (l = gpus; l; l = l->next)
|
|
|
|
{
|
|
|
|
MetaGpuKms *gpu_kms = META_GPU_KMS (l->data);
|
|
|
|
|
|
|
|
if (meta_gpu_kms_is_boot_vga (gpu_kms) &&
|
|
|
|
(allow_sw == 1 ||
|
|
|
|
gpu_kms_is_hardware_rendering (renderer_native, gpu_kms)))
|
|
|
|
return gpu_kms;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fall back to any device */
|
|
|
|
for (l = gpus; l; l = l->next)
|
|
|
|
{
|
|
|
|
MetaGpuKms *gpu_kms = META_GPU_KMS (l->data);
|
|
|
|
|
|
|
|
if (allow_sw == 1 ||
|
|
|
|
gpu_kms_is_hardware_rendering (renderer_native, gpu_kms))
|
|
|
|
return gpu_kms;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
return NULL;
|
2018-12-10 07:19:25 -05:00
|
|
|
}
|
|
|
|
|
2019-04-03 06:34:09 -04:00
|
|
|
static MetaGpuKms *
|
2019-01-11 09:35:42 -05:00
|
|
|
choose_primary_gpu (MetaBackend *backend,
|
2019-04-03 06:34:09 -04:00
|
|
|
MetaRendererNative *renderer_native,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
MetaGpuKms *gpu_kms;
|
|
|
|
MetaRendererNativeGpuData *renderer_gpu_data;
|
|
|
|
|
2019-01-11 09:35:42 -05:00
|
|
|
gpu_kms = choose_primary_gpu_unchecked (backend, renderer_native);
|
2019-04-03 06:34:09 -04:00
|
|
|
renderer_gpu_data = meta_renderer_native_get_gpu_data (renderer_native,
|
|
|
|
gpu_kms);
|
|
|
|
if (renderer_gpu_data->egl_display == EGL_NO_DISPLAY)
|
|
|
|
{
|
|
|
|
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
|
|
|
"The GPU %s chosen as primary is not supported by EGL.",
|
|
|
|
meta_gpu_kms_get_file_path (gpu_kms));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return gpu_kms;
|
|
|
|
}
|
|
|
|
|
2017-07-10 06:19:32 -04:00
|
|
|
static gboolean
|
|
|
|
meta_renderer_native_initable_init (GInitable *initable,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
MetaRendererNative *renderer_native = META_RENDERER_NATIVE (initable);
|
2019-10-01 05:51:53 -04:00
|
|
|
MetaRenderer *renderer = META_RENDERER (renderer_native);
|
|
|
|
MetaBackend *backend = meta_renderer_get_backend (renderer);
|
2017-07-10 06:19:32 -04:00
|
|
|
GList *gpus;
|
2017-07-24 22:21:04 -04:00
|
|
|
GList *l;
|
2017-07-10 06:19:32 -04:00
|
|
|
|
2019-01-11 09:35:42 -05:00
|
|
|
gpus = meta_backend_get_gpus (backend);
|
2017-07-24 22:21:04 -04:00
|
|
|
for (l = gpus; l; l = l->next)
|
2017-07-10 06:19:32 -04:00
|
|
|
{
|
2017-07-24 22:21:04 -04:00
|
|
|
MetaGpuKms *gpu_kms = META_GPU_KMS (l->data);
|
2017-07-10 06:19:32 -04:00
|
|
|
|
2018-09-17 07:03:18 -04:00
|
|
|
if (!create_renderer_gpu_data (renderer_native, gpu_kms, error))
|
2017-07-24 22:21:04 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
2017-07-10 06:19:32 -04:00
|
|
|
|
2019-01-11 09:35:42 -05:00
|
|
|
renderer_native->primary_gpu_kms = choose_primary_gpu (backend,
|
2019-04-03 06:34:09 -04:00
|
|
|
renderer_native,
|
|
|
|
error);
|
|
|
|
if (!renderer_native->primary_gpu_kms)
|
|
|
|
return FALSE;
|
2018-10-12 08:19:24 -04:00
|
|
|
|
2017-07-10 06:19:32 -04:00
|
|
|
return TRUE;
|
2016-08-17 23:14:03 -04:00
|
|
|
}
|
|
|
|
|
2016-05-09 09:22:01 -04:00
|
|
|
static void
|
|
|
|
initable_iface_init (GInitableIface *initable_iface)
|
|
|
|
{
|
|
|
|
initable_iface->init = meta_renderer_native_initable_init;
|
|
|
|
}
|
|
|
|
|
2017-07-10 06:19:32 -04:00
|
|
|
static void
|
|
|
|
meta_renderer_native_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
MetaRendererNative *renderer_native = META_RENDERER_NATIVE (object);
|
|
|
|
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
if (renderer_native->power_save_page_flip_onscreens)
|
2019-03-25 05:24:46 -04:00
|
|
|
{
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
g_list_free_full (renderer_native->power_save_page_flip_onscreens,
|
|
|
|
(GDestroyNotify) cogl_object_unref);
|
2019-11-21 18:25:30 -05:00
|
|
|
g_clear_handle_id (&renderer_native->power_save_page_flip_source_id,
|
|
|
|
g_source_remove);
|
2019-03-25 05:24:46 -04:00
|
|
|
}
|
|
|
|
|
2017-07-10 06:19:32 -04:00
|
|
|
g_hash_table_destroy (renderer_native->gpu_datas);
|
2017-07-24 22:21:04 -04:00
|
|
|
g_clear_object (&renderer_native->gles3);
|
2017-07-10 06:19:32 -04:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (meta_renderer_native_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2018-04-11 08:39:15 -04:00
|
|
|
static void
|
|
|
|
meta_renderer_native_constructed (GObject *object)
|
|
|
|
{
|
|
|
|
MetaRendererNative *renderer_native = META_RENDERER_NATIVE (object);
|
2019-10-01 05:51:53 -04:00
|
|
|
MetaRenderer *renderer = META_RENDERER (renderer_native);
|
|
|
|
MetaBackend *backend = meta_renderer_get_backend (renderer);
|
2018-04-11 08:39:15 -04:00
|
|
|
MetaSettings *settings = meta_backend_get_settings (backend);
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
MetaMonitorManager *monitor_manager =
|
|
|
|
meta_backend_get_monitor_manager (backend);
|
2018-04-11 08:39:15 -04:00
|
|
|
|
|
|
|
if (meta_settings_is_experimental_feature_enabled (
|
|
|
|
settings, META_EXPERIMENTAL_FEATURE_KMS_MODIFIERS))
|
|
|
|
renderer_native->use_modifiers = TRUE;
|
|
|
|
|
2019-01-11 09:35:42 -05:00
|
|
|
g_signal_connect (backend, "gpu-added",
|
2018-09-17 07:03:18 -04:00
|
|
|
G_CALLBACK (on_gpu_added), renderer_native);
|
backend/native: Add and use transactional KMS API
This commit introduces, and makes use of, a transactional API used for
setting up KMS state, later to be applied, potentially atomically. From
an API point of view, so is always the case, but in the current
implementation, it still uses legacy drmMode* API to apply the state
non-atomically.
The API consists of various buliding blocks:
* MetaKmsUpdate - a set of configuration changes, the higher level
handle for handing over configuration to the impl backend. It's used to
set mode, assign framebuffers to planes, queue page flips and set
connector properties.
* MetaKmsPlaneAssignment - the assignment of a framebuffer to a plane.
Currently used to map a framebuffer to the primary plane of a CRTC. In
the legacy KMS implementation, the plane assignment is used to derive
the framebuffer used for mode setting and page flipping.
This also means various high level changes:
State, excluding configuring the cursor plane and creating/destroying
DRM framebuffer handles, are applied in the end of a clutter frame, in
one go. From an API point of view, this is done atomically, but as
mentioned, only the non-atomic implementation exists so far.
From MetaRendererNative's point of view, a page flip now initially
always succeeds; the handling of EBUSY errors are done asynchronously in
the MetaKmsImpl backend (still by retrying at refresh rate, but
postponing flip callbacks instead of manipulating the frame clock).
Handling of falling back to mode setting instead of page flipping is
notified after the fact by a more precise page flip feedback API.
EGLStream based page flipping relies on the impl backend not being
atomic, as the page flipping is done in the EGLStream backend (e.g.
nvidia driver). It uses a 'custom' page flip queueing method, keeping
the EGLStream logic inside meta-renderer-native.c.
Page flip handling is moved to meta-kms-impl-device.c from
meta-gpu-kms.c. It goes via an extra idle callback before reaching
meta-renderer-native.c to make sure callbacks are invoked outside of the
impl context.
While dummy power save page flipping is kept in meta-renderer-native.c, the
EBUSY handling is moved to meta-kms-impl-simple.c. Instead of freezing the
frame clock, actual page flip callbacks are postponed until all EBUSY retries
have either succeeded or failed due to some other error than EBUSY. This
effectively inhibits new frames to be drawn, meaning we won't stall waiting on
the file descriptor for pending page flips.
https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
2019-04-04 16:36:41 -04:00
|
|
|
g_signal_connect (monitor_manager, "power-save-mode-changed",
|
|
|
|
G_CALLBACK (on_power_save_mode_changed), renderer_native);
|
2018-09-17 07:03:18 -04:00
|
|
|
|
2018-04-11 08:39:15 -04:00
|
|
|
G_OBJECT_CLASS (meta_renderer_native_parent_class)->constructed (object);
|
|
|
|
}
|
|
|
|
|
2016-05-07 11:07:46 -04:00
|
|
|
static void
|
|
|
|
meta_renderer_native_init (MetaRendererNative *renderer_native)
|
|
|
|
{
|
2017-07-10 06:19:32 -04:00
|
|
|
renderer_native->gpu_datas =
|
|
|
|
g_hash_table_new_full (NULL, NULL,
|
|
|
|
NULL,
|
|
|
|
(GDestroyNotify) meta_renderer_native_gpu_data_free);
|
2016-05-07 11:07:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_renderer_native_class_init (MetaRendererNativeClass *klass)
|
|
|
|
{
|
2016-05-07 11:09:59 -04:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2016-05-08 21:59:54 -04:00
|
|
|
MetaRendererClass *renderer_class = META_RENDERER_CLASS (klass);
|
2016-05-07 11:09:59 -04:00
|
|
|
|
2016-05-09 09:22:01 -04:00
|
|
|
object_class->finalize = meta_renderer_native_finalize;
|
2018-04-11 08:39:15 -04:00
|
|
|
object_class->constructed = meta_renderer_native_constructed;
|
2016-05-07 11:09:59 -04:00
|
|
|
|
2016-05-08 21:59:54 -04:00
|
|
|
renderer_class->create_cogl_renderer = meta_renderer_native_create_cogl_renderer;
|
2016-06-08 05:05:31 -04:00
|
|
|
renderer_class->create_view = meta_renderer_native_create_view;
|
2019-06-19 14:57:14 -04:00
|
|
|
renderer_class->rebuild_views = meta_renderer_native_rebuild_views;
|
2016-05-07 11:07:46 -04:00
|
|
|
}
|
2016-05-09 09:22:01 -04:00
|
|
|
|
|
|
|
MetaRendererNative *
|
2019-01-11 09:35:42 -05:00
|
|
|
meta_renderer_native_new (MetaBackendNative *backend_native,
|
|
|
|
GError **error)
|
2016-05-09 09:22:01 -04:00
|
|
|
{
|
2017-10-05 10:47:25 -04:00
|
|
|
return g_initable_new (META_TYPE_RENDERER_NATIVE,
|
|
|
|
NULL,
|
|
|
|
error,
|
2019-01-11 09:35:42 -05:00
|
|
|
"backend", backend_native,
|
2017-10-05 10:47:25 -04:00
|
|
|
NULL);
|
2016-05-09 09:22:01 -04:00
|
|
|
}
|