2017-07-04 00:11:44 -04:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2013-2017 Red Hat
|
2018-10-11 10:15:37 -04:00
|
|
|
* Copyright (C) 2018 DisplayLink (UK) Ltd.
|
2017-07-04 00:11:44 -04:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
* 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "backends/native/meta-output-kms.h"
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "backends/meta-crtc.h"
|
2019-03-08 10:23:15 -05:00
|
|
|
#include "backends/native/meta-kms-connector.h"
|
2020-07-02 05:54:56 -04:00
|
|
|
#include "backends/native/meta-kms-device.h"
|
2020-06-04 11:12:34 -04:00
|
|
|
#include "backends/native/meta-kms-mode.h"
|
2020-07-14 10:48:47 -04:00
|
|
|
#include "backends/native/meta-kms-update.h"
|
2019-03-11 06:13:01 -04:00
|
|
|
#include "backends/native/meta-kms-utils.h"
|
2017-07-04 04:04:39 -04:00
|
|
|
#include "backends/native/meta-crtc-kms.h"
|
2020-02-27 17:19:38 -05:00
|
|
|
#include "backends/native/meta-crtc-mode-kms.h"
|
2018-07-07 09:28:41 -04:00
|
|
|
|
2017-07-04 00:11:44 -04:00
|
|
|
#define SYNC_TOLERANCE 0.01 /* 1 percent */
|
|
|
|
|
|
|
|
typedef struct _MetaOutputKms
|
|
|
|
{
|
|
|
|
MetaOutput parent;
|
|
|
|
|
2019-03-08 10:23:15 -05:00
|
|
|
MetaKmsConnector *kms_connector;
|
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
|
|
|
} MetaOutputKms;
|
2019-03-08 10:23:15 -05:00
|
|
|
|
2020-02-26 10:47:03 -05:00
|
|
|
G_DEFINE_TYPE (MetaOutputKms, meta_output_kms, META_TYPE_OUTPUT)
|
|
|
|
|
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
|
|
|
MetaKmsConnector *
|
2020-02-26 10:47:03 -05:00
|
|
|
meta_output_kms_get_kms_connector (MetaOutputKms *output_kms)
|
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 output_kms->kms_connector;
|
|
|
|
}
|
2017-07-04 00:11:44 -04:00
|
|
|
|
2017-07-04 04:04:39 -04:00
|
|
|
void
|
2020-02-26 10:47:03 -05:00
|
|
|
meta_output_kms_set_underscan (MetaOutputKms *output_kms,
|
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)
|
2017-07-04 04:04:39 -04:00
|
|
|
{
|
2020-02-26 10:47:03 -05:00
|
|
|
MetaOutput *output = META_OUTPUT (output_kms);
|
2020-02-26 03:45:07 -05:00
|
|
|
const MetaOutputInfo *output_info = meta_output_get_info (output);
|
2017-11-03 06:25:30 -04:00
|
|
|
|
2020-02-26 03:45:07 -05:00
|
|
|
if (!output_info->supports_underscanning)
|
2017-07-04 04:04:39 -04:00
|
|
|
return;
|
|
|
|
|
2020-02-25 12:37:21 -05:00
|
|
|
if (meta_output_is_underscanning (output))
|
2019-03-26 05:09:45 -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
|
|
|
MetaCrtc *crtc;
|
2020-02-26 04:37:53 -05:00
|
|
|
const MetaCrtcConfig *crtc_config;
|
2020-02-26 18:08:58 -05:00
|
|
|
const MetaCrtcModeInfo *crtc_mode_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
|
|
|
uint64_t hborder, vborder;
|
|
|
|
|
|
|
|
crtc = meta_output_get_assigned_crtc (output);
|
2020-02-26 04:37:53 -05:00
|
|
|
crtc_config = meta_crtc_get_config (crtc);
|
2020-02-26 18:08:58 -05:00
|
|
|
crtc_mode_info = meta_crtc_mode_get_info (crtc_config->mode);
|
|
|
|
|
|
|
|
hborder = MIN (128, (uint64_t) round (crtc_mode_info->width * 0.05));
|
|
|
|
vborder = MIN (128, (uint64_t) round (crtc_mode_info->height * 0.05));
|
2019-04-26 03:53:25 -04:00
|
|
|
|
2019-09-06 05:49:48 -04:00
|
|
|
g_debug ("Setting underscan of connector %s to %" G_GUINT64_FORMAT " x %" G_GUINT64_FORMAT,
|
2019-04-26 03:53:25 -04:00
|
|
|
meta_kms_connector_get_name (output_kms->kms_connector),
|
|
|
|
hborder, vborder);
|
|
|
|
|
2020-07-14 10:48:47 -04:00
|
|
|
meta_kms_update_set_underscanning (kms_update,
|
|
|
|
output_kms->kms_connector,
|
|
|
|
hborder, vborder);
|
2019-03-26 05:09:45 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-04-26 03:53:25 -04:00
|
|
|
g_debug ("Unsetting underscan of connector %s",
|
|
|
|
meta_kms_connector_get_name (output_kms->kms_connector));
|
|
|
|
|
2020-07-14 10:48:47 -04:00
|
|
|
meta_kms_update_unset_underscanning (kms_update,
|
|
|
|
output_kms->kms_connector);
|
2019-03-26 05:09:45 -04:00
|
|
|
}
|
2017-07-04 04:04:39 -04:00
|
|
|
}
|
|
|
|
|
2018-10-11 10:15:37 -04:00
|
|
|
uint32_t
|
2020-02-26 10:47:03 -05:00
|
|
|
meta_output_kms_get_connector_id (MetaOutputKms *output_kms)
|
2018-10-11 10:15:37 -04:00
|
|
|
{
|
2019-03-08 10:23:15 -05:00
|
|
|
return meta_kms_connector_get_id (output_kms->kms_connector);
|
2018-10-11 10:15:37 -04:00
|
|
|
}
|
|
|
|
|
2017-07-04 00:11:44 -04:00
|
|
|
void
|
2020-02-26 10:47:03 -05:00
|
|
|
meta_output_kms_set_power_save_mode (MetaOutputKms *output_kms,
|
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
|
|
|
uint64_t dpms_state,
|
|
|
|
MetaKmsUpdate *kms_update)
|
2017-07-04 00:11:44 -04:00
|
|
|
{
|
2019-09-06 05:49:48 -04:00
|
|
|
g_debug ("Setting DPMS state of connector %s to %" G_GUINT64_FORMAT,
|
2019-04-26 03:53:25 -04:00
|
|
|
meta_kms_connector_get_name (output_kms->kms_connector),
|
|
|
|
dpms_state);
|
|
|
|
|
2020-07-14 10:48:47 -04:00
|
|
|
meta_kms_update_set_dpms_state (kms_update,
|
|
|
|
output_kms->kms_connector,
|
|
|
|
dpms_state);
|
2017-07-04 00:11:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2020-02-26 10:47:03 -05:00
|
|
|
meta_output_kms_can_clone (MetaOutputKms *output_kms,
|
|
|
|
MetaOutputKms *other_output_kms)
|
2017-07-04 00:11:44 -04:00
|
|
|
{
|
2019-03-09 09:55:24 -05:00
|
|
|
return meta_kms_connector_can_clone (output_kms->kms_connector,
|
|
|
|
other_output_kms->kms_connector);
|
2017-07-04 00:11:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
GBytes *
|
2020-02-26 10:47:03 -05:00
|
|
|
meta_output_kms_read_edid (MetaOutputKms *output_kms)
|
2017-07-04 00:11:44 -04:00
|
|
|
{
|
2019-03-09 09:55:24 -05:00
|
|
|
const MetaKmsConnectorState *connector_state;
|
|
|
|
GBytes *edid_data;
|
2017-07-04 00:11:44 -04:00
|
|
|
|
2019-03-09 09:55:24 -05:00
|
|
|
connector_state =
|
|
|
|
meta_kms_connector_get_current_state (output_kms->kms_connector);
|
|
|
|
edid_data = connector_state->edid_data;
|
|
|
|
if (!edid_data)
|
2017-07-04 00:11:44 -04:00
|
|
|
return NULL;
|
|
|
|
|
2019-03-09 09:55:24 -05:00
|
|
|
return g_bytes_new_from_bytes (edid_data, 0, g_bytes_get_size (edid_data));
|
2017-07-04 00:11:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-02-26 03:45:07 -05:00
|
|
|
add_common_modes (MetaOutputInfo *output_info,
|
|
|
|
MetaGpuKms *gpu_kms)
|
2017-07-04 00:11:44 -04:00
|
|
|
{
|
2017-10-24 09:47:30 -04:00
|
|
|
MetaCrtcMode *crtc_mode;
|
2017-07-04 00:11:44 -04:00
|
|
|
GPtrArray *array;
|
2017-10-24 09:47:30 -04:00
|
|
|
float refresh_rate;
|
2017-07-04 00:11:44 -04:00
|
|
|
unsigned i;
|
|
|
|
unsigned max_hdisplay = 0;
|
|
|
|
unsigned max_vdisplay = 0;
|
|
|
|
float max_refresh_rate = 0.0;
|
2020-07-02 05:54:56 -04:00
|
|
|
MetaKmsDevice *kms_device;
|
|
|
|
MetaKmsModeFlag flag_filter;
|
|
|
|
GList *l;
|
2017-07-04 00:11:44 -04:00
|
|
|
|
2020-02-26 03:45:07 -05:00
|
|
|
for (i = 0; i < output_info->n_modes; i++)
|
2017-07-04 00:11:44 -04:00
|
|
|
{
|
2020-02-27 17:19:38 -05:00
|
|
|
MetaCrtcMode *crtc_mode = output_info->modes[i];
|
|
|
|
MetaCrtcModeKms *crtc_mode_kms = META_CRTC_MODE_KMS (crtc_mode);
|
2020-07-02 09:47:32 -04:00
|
|
|
MetaKmsMode *kms_mode = meta_crtc_mode_kms_get_kms_mode (crtc_mode_kms);
|
|
|
|
const drmModeModeInfo *drm_mode = meta_kms_mode_get_drm_mode (kms_mode);
|
2020-02-27 17:19:38 -05:00
|
|
|
|
2017-07-04 00:11:44 -04:00
|
|
|
refresh_rate = meta_calculate_drm_mode_refresh_rate (drm_mode);
|
|
|
|
max_hdisplay = MAX (max_hdisplay, drm_mode->hdisplay);
|
|
|
|
max_vdisplay = MAX (max_vdisplay, drm_mode->vdisplay);
|
|
|
|
max_refresh_rate = MAX (max_refresh_rate, refresh_rate);
|
|
|
|
}
|
|
|
|
|
|
|
|
max_refresh_rate = MAX (max_refresh_rate, 60.0);
|
|
|
|
max_refresh_rate *= (1 + SYNC_TOLERANCE);
|
|
|
|
|
2020-07-02 05:54:56 -04:00
|
|
|
kms_device = meta_gpu_kms_get_kms_device (gpu_kms);
|
|
|
|
|
2017-07-04 00:11:44 -04:00
|
|
|
array = g_ptr_array_new ();
|
2020-07-02 05:54:56 -04:00
|
|
|
|
2017-10-24 09:47:30 -04:00
|
|
|
if (max_hdisplay > max_vdisplay)
|
2020-07-02 05:54:56 -04:00
|
|
|
flag_filter = META_KMS_MODE_FLAG_FALLBACK_LANDSCAPE;
|
2017-10-24 09:47:30 -04:00
|
|
|
else
|
2020-07-02 05:54:56 -04:00
|
|
|
flag_filter = META_KMS_MODE_FLAG_FALLBACK_PORTRAIT;
|
|
|
|
|
|
|
|
for (l = meta_kms_device_get_fallback_modes (kms_device); l; l = l->next)
|
2017-10-24 09:47:30 -04:00
|
|
|
{
|
2020-07-02 05:54:56 -04:00
|
|
|
MetaKmsMode *fallback_mode = l->data;
|
|
|
|
const drmModeModeInfo *drm_mode;
|
|
|
|
|
|
|
|
if (!(meta_kms_mode_get_flags (fallback_mode) & flag_filter))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
drm_mode = meta_kms_mode_get_drm_mode (fallback_mode);
|
|
|
|
refresh_rate = meta_calculate_drm_mode_refresh_rate (drm_mode);
|
|
|
|
if (drm_mode->hdisplay > max_hdisplay ||
|
|
|
|
drm_mode->vdisplay > max_vdisplay ||
|
|
|
|
refresh_rate > max_refresh_rate)
|
|
|
|
continue;
|
|
|
|
|
2020-07-02 09:47:32 -04:00
|
|
|
crtc_mode = meta_gpu_kms_get_mode_from_kms_mode (gpu_kms, fallback_mode);
|
2020-07-02 05:54:56 -04:00
|
|
|
g_ptr_array_add (array, crtc_mode);
|
2017-07-04 00:11:44 -04:00
|
|
|
}
|
|
|
|
|
2020-02-26 03:45:07 -05:00
|
|
|
output_info->modes = g_renew (MetaCrtcMode *, output_info->modes,
|
|
|
|
output_info->n_modes + array->len);
|
|
|
|
memcpy (output_info->modes + output_info->n_modes, array->pdata,
|
2017-07-04 00:11:44 -04:00
|
|
|
array->len * sizeof (MetaCrtcMode *));
|
2020-02-26 03:45:07 -05:00
|
|
|
output_info->n_modes += array->len;
|
2017-07-04 00:11:44 -04:00
|
|
|
|
|
|
|
g_ptr_array_free (array, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
compare_modes (const void *one,
|
|
|
|
const void *two)
|
|
|
|
{
|
2020-02-26 18:08:58 -05:00
|
|
|
MetaCrtcMode *crtc_mode_one = *(MetaCrtcMode **) one;
|
|
|
|
MetaCrtcMode *crtc_mode_two = *(MetaCrtcMode **) two;
|
|
|
|
const MetaCrtcModeInfo *crtc_mode_info_one =
|
|
|
|
meta_crtc_mode_get_info (crtc_mode_one);
|
|
|
|
const MetaCrtcModeInfo *crtc_mode_info_two =
|
|
|
|
meta_crtc_mode_get_info (crtc_mode_two);
|
|
|
|
|
|
|
|
if (crtc_mode_info_one->width != crtc_mode_info_two->width)
|
|
|
|
return crtc_mode_info_one->width > crtc_mode_info_two->width ? -1 : 1;
|
|
|
|
if (crtc_mode_info_one->height != crtc_mode_info_two->height)
|
|
|
|
return crtc_mode_info_one->height > crtc_mode_info_two->height ? -1 : 1;
|
|
|
|
if (crtc_mode_info_one->refresh_rate != crtc_mode_info_two->refresh_rate)
|
|
|
|
return (crtc_mode_info_one->refresh_rate > crtc_mode_info_two->refresh_rate
|
|
|
|
? -1 : 1);
|
|
|
|
|
|
|
|
return g_strcmp0 (meta_crtc_mode_get_name (crtc_mode_one),
|
|
|
|
meta_crtc_mode_get_name (crtc_mode_two));
|
2017-07-04 00:11:44 -04:00
|
|
|
}
|
|
|
|
|
2017-11-03 03:55:07 -04:00
|
|
|
static gboolean
|
2020-02-26 03:45:07 -05:00
|
|
|
init_output_modes (MetaOutputInfo *output_info,
|
|
|
|
MetaGpuKms *gpu_kms,
|
|
|
|
MetaKmsConnector *kms_connector,
|
|
|
|
GError **error)
|
2017-07-04 00:11:44 -04:00
|
|
|
{
|
2019-03-09 09:55:24 -05:00
|
|
|
const MetaKmsConnectorState *connector_state;
|
2020-06-04 11:12:34 -04:00
|
|
|
GList *l;
|
2019-03-09 09:55:24 -05:00
|
|
|
int i;
|
|
|
|
|
2020-02-26 03:45:07 -05:00
|
|
|
connector_state = meta_kms_connector_get_current_state (kms_connector);
|
2017-07-04 00:11:44 -04:00
|
|
|
|
2020-02-26 03:45:07 -05:00
|
|
|
output_info->preferred_mode = NULL;
|
2019-03-09 09:55:24 -05:00
|
|
|
|
2020-06-04 11:12:34 -04:00
|
|
|
output_info->n_modes = g_list_length (connector_state->modes);
|
2020-02-26 03:45:07 -05:00
|
|
|
output_info->modes = g_new0 (MetaCrtcMode *, output_info->n_modes);
|
2020-06-04 11:12:34 -04:00
|
|
|
for (l = connector_state->modes, i = 0; l; l = l->next, i++)
|
2017-07-04 00:11:44 -04:00
|
|
|
{
|
2020-06-04 11:12:34 -04:00
|
|
|
MetaKmsMode *kms_mode = l->data;
|
|
|
|
const drmModeModeInfo *drm_mode = meta_kms_mode_get_drm_mode (kms_mode);
|
2017-07-04 00:11:44 -04:00
|
|
|
MetaCrtcMode *crtc_mode;
|
|
|
|
|
2020-07-02 09:47:32 -04:00
|
|
|
crtc_mode = meta_gpu_kms_get_mode_from_kms_mode (gpu_kms, kms_mode);
|
2020-02-26 03:45:07 -05:00
|
|
|
output_info->modes[i] = crtc_mode;
|
2019-03-09 09:55:24 -05:00
|
|
|
if (drm_mode->type & DRM_MODE_TYPE_PREFERRED)
|
2020-02-26 03:45:07 -05:00
|
|
|
output_info->preferred_mode = output_info->modes[i];
|
2017-07-04 00:11:44 -04:00
|
|
|
}
|
|
|
|
|
2017-11-03 03:55:07 -04:00
|
|
|
/* Presume that if the output supports scaling, then we have
|
|
|
|
* a panel fitter capable of adjusting any mode to suit.
|
|
|
|
*/
|
2019-03-09 09:55:24 -05:00
|
|
|
if (connector_state->has_scaling)
|
2020-02-26 03:45:07 -05:00
|
|
|
add_common_modes (output_info, gpu_kms);
|
2017-11-03 03:55:07 -04:00
|
|
|
|
2020-02-26 03:45:07 -05:00
|
|
|
if (!output_info->modes)
|
2017-11-03 03:55:07 -04:00
|
|
|
{
|
|
|
|
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
|
|
|
"No modes available");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-02-26 03:45:07 -05:00
|
|
|
qsort (output_info->modes, output_info->n_modes,
|
2017-11-03 03:55:07 -04:00
|
|
|
sizeof (MetaCrtcMode *), compare_modes);
|
|
|
|
|
2020-02-26 03:45:07 -05:00
|
|
|
if (!output_info->preferred_mode)
|
|
|
|
output_info->preferred_mode = output_info->modes[0];
|
2017-11-03 03:55:07 -04:00
|
|
|
|
|
|
|
return TRUE;
|
2017-07-04 00:11:44 -04:00
|
|
|
}
|
|
|
|
|
2020-02-26 10:47:03 -05:00
|
|
|
MetaOutputKms *
|
|
|
|
meta_output_kms_new (MetaGpuKms *gpu_kms,
|
|
|
|
MetaKmsConnector *kms_connector,
|
|
|
|
MetaOutput *old_output,
|
|
|
|
GError **error)
|
2017-07-04 00:11:44 -04:00
|
|
|
{
|
2017-07-10 06:19:32 -04:00
|
|
|
MetaGpu *gpu = META_GPU (gpu_kms);
|
2020-02-25 10:13:52 -05:00
|
|
|
uint32_t connector_id;
|
|
|
|
uint32_t gpu_id;
|
2020-02-26 03:45:07 -05:00
|
|
|
g_autoptr (MetaOutputInfo) output_info = NULL;
|
2017-07-04 00:11:44 -04:00
|
|
|
MetaOutput *output;
|
|
|
|
MetaOutputKms *output_kms;
|
2019-03-09 09:55:24 -05:00
|
|
|
const MetaKmsConnectorState *connector_state;
|
2017-07-04 00:11:44 -04:00
|
|
|
GArray *crtcs;
|
|
|
|
GList *l;
|
2020-02-25 10:13:52 -05:00
|
|
|
|
|
|
|
gpu_id = meta_gpu_kms_get_id (gpu_kms);
|
|
|
|
connector_id = meta_kms_connector_get_id (kms_connector);
|
2017-07-04 00:11:44 -04:00
|
|
|
|
2020-02-26 03:45:07 -05:00
|
|
|
output_info = meta_output_info_new ();
|
|
|
|
output_info->name = g_strdup (meta_kms_connector_get_name (kms_connector));
|
2019-03-08 10:23:15 -05:00
|
|
|
|
2019-03-09 09:55:24 -05:00
|
|
|
connector_state = meta_kms_connector_get_current_state (kms_connector);
|
|
|
|
|
2020-02-26 03:45:07 -05:00
|
|
|
output_info->panel_orientation_transform =
|
2019-11-10 10:50:36 -05:00
|
|
|
connector_state->panel_orientation_transform;
|
2020-02-26 03:45:07 -05:00
|
|
|
if (meta_monitor_transform_is_rotated (output_info->panel_orientation_transform))
|
2017-10-25 09:44:10 -04:00
|
|
|
{
|
2020-02-26 03:45:07 -05:00
|
|
|
output_info->width_mm = connector_state->height_mm;
|
|
|
|
output_info->height_mm = connector_state->width_mm;
|
2017-10-25 09:44:10 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-02-26 03:45:07 -05:00
|
|
|
output_info->width_mm = connector_state->width_mm;
|
|
|
|
output_info->height_mm = connector_state->height_mm;
|
2017-10-25 09:44:10 -04:00
|
|
|
}
|
|
|
|
|
2020-02-26 03:45:07 -05:00
|
|
|
if (!init_output_modes (output_info, gpu_kms, kms_connector, error))
|
|
|
|
return NULL;
|
2017-07-04 00:11:44 -04:00
|
|
|
|
2019-03-09 09:55:24 -05:00
|
|
|
crtcs = g_array_new (FALSE, FALSE, sizeof (MetaCrtc *));
|
2017-07-04 00:11:44 -04:00
|
|
|
|
2019-03-09 09:55:24 -05:00
|
|
|
for (l = meta_gpu_get_crtcs (gpu); l; l = l->next)
|
2017-07-04 00:11:44 -04:00
|
|
|
{
|
2020-02-26 13:47:44 -05:00
|
|
|
MetaCrtcKms *crtc_kms = META_CRTC_KMS (l->data);
|
|
|
|
MetaKmsCrtc *kms_crtc = meta_crtc_kms_get_kms_crtc (crtc_kms);
|
2019-03-09 09:55:24 -05:00
|
|
|
uint32_t crtc_idx;
|
2017-07-04 00:11:44 -04:00
|
|
|
|
2019-03-09 09:55:24 -05:00
|
|
|
crtc_idx = meta_kms_crtc_get_idx (kms_crtc);
|
|
|
|
if (connector_state->common_possible_crtcs & (1 << crtc_idx))
|
2020-02-26 13:47:44 -05:00
|
|
|
g_array_append_val (crtcs, crtc_kms);
|
2017-07-04 00:11:44 -04:00
|
|
|
}
|
|
|
|
|
2020-02-26 03:45:07 -05:00
|
|
|
output_info->n_possible_crtcs = crtcs->len;
|
|
|
|
output_info->possible_crtcs = (MetaCrtc **) g_array_free (crtcs, FALSE);
|
|
|
|
|
|
|
|
output_info->suggested_x = connector_state->suggested_x;
|
|
|
|
output_info->suggested_y = connector_state->suggested_y;
|
|
|
|
output_info->hotplug_mode_update = connector_state->hotplug_mode_update;
|
|
|
|
output_info->supports_underscanning =
|
|
|
|
meta_kms_connector_is_underscanning_supported (kms_connector);
|
|
|
|
|
|
|
|
meta_output_info_parse_edid (output_info, connector_state->edid_data);
|
|
|
|
|
|
|
|
output_info->connector_type = meta_kms_connector_get_connector_type (kms_connector);
|
|
|
|
|
|
|
|
output_info->tile_info = connector_state->tile_info;
|
|
|
|
|
2020-02-26 10:47:03 -05:00
|
|
|
output = g_object_new (META_TYPE_OUTPUT_KMS,
|
2020-02-26 03:45:07 -05:00
|
|
|
"id", ((uint64_t) gpu_id << 32) | connector_id,
|
|
|
|
"gpu", gpu,
|
|
|
|
"info", output_info,
|
|
|
|
NULL);
|
2020-02-26 10:47:03 -05:00
|
|
|
output_kms = META_OUTPUT_KMS (output);
|
2020-02-26 03:45:07 -05:00
|
|
|
output_kms->kms_connector = kms_connector;
|
2017-07-04 00:11:44 -04:00
|
|
|
|
2019-03-09 09:55:24 -05:00
|
|
|
if (connector_state->current_crtc_id)
|
2017-07-04 00:11:44 -04:00
|
|
|
{
|
2017-07-10 06:19:32 -04:00
|
|
|
for (l = meta_gpu_get_crtcs (gpu); l; l = l->next)
|
2017-07-04 00:11:44 -04:00
|
|
|
{
|
|
|
|
MetaCrtc *crtc = l->data;
|
|
|
|
|
2020-02-25 05:34:43 -05:00
|
|
|
if (meta_crtc_get_id (crtc) == connector_state->current_crtc_id)
|
2017-07-04 00:11:44 -04:00
|
|
|
{
|
2020-02-25 14:30:46 -05:00
|
|
|
MetaOutputAssignment output_assignment;
|
2020-02-25 12:37:21 -05:00
|
|
|
|
|
|
|
if (old_output)
|
|
|
|
{
|
2020-02-25 14:30:46 -05:00
|
|
|
output_assignment = (MetaOutputAssignment) {
|
2020-02-25 12:37:21 -05:00
|
|
|
.is_primary = meta_output_is_primary (old_output),
|
|
|
|
.is_presentation = meta_output_is_presentation (old_output),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-02-25 14:30:46 -05:00
|
|
|
output_assignment = (MetaOutputAssignment) {
|
2020-02-25 12:37:21 -05:00
|
|
|
.is_primary = FALSE,
|
|
|
|
.is_presentation = FALSE,
|
|
|
|
};
|
|
|
|
}
|
2020-02-25 14:30:46 -05:00
|
|
|
meta_output_assign_crtc (output, crtc, &output_assignment);
|
2017-07-04 00:11:44 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-11-03 06:25:30 -04:00
|
|
|
meta_output_unassign_crtc (output);
|
2017-07-04 00:11:44 -04:00
|
|
|
}
|
|
|
|
|
2020-02-26 10:47:03 -05:00
|
|
|
return output_kms;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_output_kms_init (MetaOutputKms *output_kms)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_output_kms_class_init (MetaOutputKmsClass *klass)
|
|
|
|
{
|
2017-07-04 00:11:44 -04:00
|
|
|
}
|