c/direct_mode: Port to plain C.

This commit is contained in:
Lubosz Sarnecki 2020-04-01 18:22:23 +02:00
parent 16d6500923
commit 6158a23dd9
3 changed files with 123 additions and 104 deletions

View file

@ -86,7 +86,7 @@ if(BUILD_COMPOSITOR_MAIN)
endif() endif()
if(BUILD_WITH_XCB AND BUILD_WITH_XLIB) if(BUILD_WITH_XCB AND BUILD_WITH_XLIB)
list(APPEND MAIN_SOURCE_FILES list(APPEND MAIN_SOURCE_FILES
main/comp_window_direct_mode.cpp main/comp_window_direct_mode.c
) )
endif() endif()

View file

@ -13,11 +13,6 @@
#include <X11/Xlib-xcb.h> #include <X11/Xlib-xcb.h>
#include <X11/extensions/Xrandr.h> #include <X11/extensions/Xrandr.h>
#include <map>
#include <string>
#include <vector>
#include <utility>
#include <cstring>
#include <inttypes.h> #include <inttypes.h>
#include "util/u_misc.h" #include "util/u_misc.h"
@ -37,7 +32,7 @@
*/ */
struct comp_window_direct_randr_display struct comp_window_direct_randr_display
{ {
std::string name; char *name;
xcb_randr_output_t output; xcb_randr_output_t output;
xcb_randr_mode_info_t primary_mode; xcb_randr_mode_info_t primary_mode;
VkDisplayKHR display; VkDisplayKHR display;
@ -45,7 +40,7 @@ struct comp_window_direct_randr_display
struct comp_window_direct_nvidia_display struct comp_window_direct_nvidia_display
{ {
std::string name; char *name;
VkDisplayPropertiesKHR display_properties; VkDisplayPropertiesKHR display_properties;
VkDisplayKHR display; VkDisplayKHR display;
}; };
@ -56,14 +51,16 @@ struct comp_window_direct_nvidia_display
*/ */
struct comp_window_direct struct comp_window_direct
{ {
struct comp_window base = comp_window(); struct comp_window base;
Display *dpy = nullptr; Display *dpy;
xcb_screen_t *screen = nullptr; xcb_screen_t *screen;
std::vector<comp_window_direct_randr_display> randr_displays = {}; struct comp_window_direct_randr_display *randr_displays;
uint16_t num_randr_displays;
std::vector<comp_window_direct_nvidia_display> nv_displays = {}; struct comp_window_direct_nvidia_display *nv_displays;
uint16_t num_nv_displays;
}; };
@ -86,10 +83,10 @@ comp_window_direct_init_randr(struct comp_window *w);
static bool static bool
comp_window_direct_init_nvidia(struct comp_window *w); comp_window_direct_init_nvidia(struct comp_window *w);
static comp_window_direct_randr_display * static struct comp_window_direct_randr_display *
comp_window_direct_current_randr_display(struct comp_window_direct *w); comp_window_direct_current_randr_display(struct comp_window_direct *w);
static comp_window_direct_nvidia_display * static struct comp_window_direct_nvidia_display *
comp_window_direct_current_nvidia_display(struct comp_window_direct *w); comp_window_direct_current_nvidia_display(struct comp_window_direct *w);
static void static void
@ -139,10 +136,11 @@ comp_window_direct_update_window_title(struct comp_window *w,
* *
*/ */
extern "C" struct comp_window * struct comp_window *
comp_window_direct_create(struct comp_compositor *c) comp_window_direct_create(struct comp_compositor *c)
{ {
auto w = new comp_window_direct(); struct comp_window_direct *w =
U_TYPED_CALLOC(struct comp_window_direct);
w->base.name = "direct"; w->base.name = "direct";
w->base.destroy = comp_window_direct_destroy; w->base.destroy = comp_window_direct_destroy;
@ -162,11 +160,11 @@ comp_window_direct_create(struct comp_compositor *c)
static void static void
comp_window_direct_destroy(struct comp_window *w) comp_window_direct_destroy(struct comp_window *w)
{ {
comp_window_direct *w_direct = (comp_window_direct *)w; struct comp_window_direct *w_direct = (struct comp_window_direct *)w;
vk_bundle *vk = &w->c->vk; struct vk_bundle *vk = &w->c->vk;
for (uint32_t i = 0; i < w_direct->randr_displays.size(); i++) { for (uint32_t i = 0; i < w_direct->num_randr_displays; i++) {
comp_window_direct_randr_display *d = struct comp_window_direct_randr_display *d =
&w_direct->randr_displays[i]; &w_direct->randr_displays[i];
if (d->display == VK_NULL_HANDLE) { if (d->display == VK_NULL_HANDLE) {
@ -175,32 +173,40 @@ comp_window_direct_destroy(struct comp_window *w)
vk->vkReleaseDisplayEXT(vk->physical_device, d->display); vk->vkReleaseDisplayEXT(vk->physical_device, d->display);
d->display = VK_NULL_HANDLE; d->display = VK_NULL_HANDLE;
free(d->name);
} }
for (uint32_t i = 0; i < w_direct->nv_displays.size(); i++) { for (uint32_t i = 0; i < w_direct->num_nv_displays; i++) {
comp_window_direct_nvidia_display *d = struct comp_window_direct_nvidia_display *d =
&w_direct->nv_displays[i]; &w_direct->nv_displays[i];
d->display = VK_NULL_HANDLE; d->display = VK_NULL_HANDLE;
free(d->name);
} }
if (w_direct->nv_displays != NULL)
free(w_direct->nv_displays);
if (w_direct->randr_displays != NULL)
free(w_direct->randr_displays);
if (w_direct->dpy) { if (w_direct->dpy) {
XCloseDisplay(w_direct->dpy); XCloseDisplay(w_direct->dpy);
w_direct->dpy = nullptr; w_direct->dpy = NULL;
} }
delete reinterpret_cast<struct comp_window_direct *>(w); free(w);
} }
static void static void
comp_window_direct_list_randr_screens(struct comp_window_direct *w) comp_window_direct_list_randr_screens(struct comp_window_direct *w)
{ {
int display_i = 0; for (int i = 0; i < w->num_randr_displays; i++) {
for (const comp_window_direct_randr_display &d : w->randr_displays) { const struct comp_window_direct_randr_display *d =
COMP_DEBUG(w->base.c, "%d: %s %dx%d@%.2f", display_i, &w->randr_displays[i];
d.name.c_str(), d.primary_mode.width, COMP_DEBUG(
d.primary_mode.height, w->base.c, "%d: %s %dx%d@%.2f", i, d->name,
(double)d.primary_mode.dot_clock / d->primary_mode.width, d->primary_mode.height,
(d.primary_mode.htotal * d.primary_mode.vtotal)); (double)d->primary_mode.dot_clock /
display_i++; (d->primary_mode.htotal * d->primary_mode.vtotal));
} }
} }
@ -213,7 +219,7 @@ comp_window_direct_init_randr(struct comp_window *w)
return false; return false;
} }
comp_window_direct *w_direct = (comp_window_direct *)w; struct comp_window_direct *w_direct = (struct comp_window_direct *)w;
if (!comp_window_direct_connect(w_direct)) { if (!comp_window_direct_connect(w_direct)) {
return false; return false;
@ -228,33 +234,32 @@ comp_window_direct_init_randr(struct comp_window *w)
comp_window_direct_get_randr_outputs(w_direct); comp_window_direct_get_randr_outputs(w_direct);
if (w_direct->randr_displays.empty()) { if (w_direct->num_randr_displays == 0) {
COMP_ERROR(w->c, "No non-desktop output available."); COMP_ERROR(w->c, "No non-desktop output available.");
return false; return false;
} }
if (w->c->settings.display > (int)w_direct->randr_displays.size() - 1) { if (w->c->settings.display > (int)w_direct->num_randr_displays - 1) {
COMP_DEBUG(w->c, COMP_DEBUG(w->c,
"Requested display %d, but only %d displays are " "Requested display %d, but only %d displays are "
"available.", "available.",
w->c->settings.display, w->c->settings.display,
(int)w_direct->randr_displays.size()); w_direct->num_randr_displays);
w->c->settings.display = 0; w->c->settings.display = 0;
comp_window_direct_randr_display *d = struct comp_window_direct_randr_display *d =
comp_window_direct_current_randr_display(w_direct); comp_window_direct_current_randr_display(w_direct);
COMP_DEBUG(w->c, "Selecting '%s' instead.", d->name.c_str()); COMP_DEBUG(w->c, "Selecting '%s' instead.", d->name);
} }
if (w->c->settings.display < 0) { if (w->c->settings.display < 0) {
w->c->settings.display = 0; w->c->settings.display = 0;
comp_window_direct_randr_display *d = struct comp_window_direct_randr_display *d =
comp_window_direct_current_randr_display(w_direct); comp_window_direct_current_randr_display(w_direct);
COMP_DEBUG(w->c, "Selecting '%s' first display.", COMP_DEBUG(w->c, "Selecting '%s' first display.", d->name);
d->name.c_str());
} }
comp_window_direct_randr_display *d = struct comp_window_direct_randr_display *d =
comp_window_direct_current_randr_display(w_direct); comp_window_direct_current_randr_display(w_direct);
w->c->settings.width = d->primary_mode.width; w->c->settings.width = d->primary_mode.width;
w->c->settings.height = d->primary_mode.height; w->c->settings.height = d->primary_mode.height;
@ -280,11 +285,24 @@ append_nvidia_entry_on_match(struct comp_window_direct *w,
// we have a match with this whitelist entry. // we have a match with this whitelist entry.
w->base.c->settings.width = disp->physicalResolution.width; w->base.c->settings.width = disp->physicalResolution.width;
w->base.c->settings.height = disp->physicalResolution.height; w->base.c->settings.height = disp->physicalResolution.height;
comp_window_direct_nvidia_display d = { struct comp_window_direct_nvidia_display d = {
.name = std::string(disp->displayName), .name = U_TYPED_ARRAY_CALLOC(char, disp_entry_length + 1),
.display_properties = *disp, .display_properties = *disp,
.display = disp->display}; .display = disp->display};
w->nv_displays.push_back(d);
memcpy(d.name, disp->displayName, disp_entry_length);
d.name[disp_entry_length] = '\0';
w->num_nv_displays += 1;
U_ARRAY_REALLOC_OR_FREE(w->nv_displays,
struct comp_window_direct_nvidia_display,
w->num_nv_displays);
if (w->nv_displays == NULL)
COMP_ERROR(w->base.c, "Unable to reallocate randr_displays");
w->nv_displays[w->num_nv_displays - 1] = d;
return true; return true;
} }
@ -298,7 +316,7 @@ comp_window_direct_init_nvidia(struct comp_window *w)
return false; return false;
} }
comp_window_direct *w_direct = (comp_window_direct *)w; struct comp_window_direct *w_direct = (struct comp_window_direct *)w;
if (!comp_window_direct_connect(w_direct)) { if (!comp_window_direct_connect(w_direct)) {
return false; return false;
@ -342,28 +360,28 @@ comp_window_direct_init_nvidia(struct comp_window *w)
return true; return true;
} }
static comp_window_direct_randr_display * static struct comp_window_direct_randr_display *
comp_window_direct_current_randr_display(struct comp_window_direct *w) comp_window_direct_current_randr_display(struct comp_window_direct *w)
{ {
int index = w->base.c->settings.display; int index = w->base.c->settings.display;
if (index == -1) if (index == -1)
index = 0; index = 0;
if (w->randr_displays.size() <= (uint32_t)index) if (w->num_randr_displays <= (uint32_t)index)
return nullptr; return NULL;
return &w->randr_displays[index]; return &w->randr_displays[index];
} }
static comp_window_direct_nvidia_display * static struct comp_window_direct_nvidia_display *
comp_window_direct_current_nvidia_display(struct comp_window_direct *w) comp_window_direct_current_nvidia_display(struct comp_window_direct *w)
{ {
int index = w->base.c->settings.display; int index = w->base.c->settings.display;
if (index == -1) if (index == -1)
index = 0; index = 0;
if (w->nv_displays.size() <= (uint32_t)index) if (w->num_nv_displays <= (uint32_t)index)
return nullptr; return NULL;
return &w->nv_displays[index]; return &w->nv_displays[index];
} }
@ -379,10 +397,10 @@ choose_best_vk_mode_auto(struct comp_window_direct *w,
{ {
struct struct
{ {
uint16_t width = 0; uint16_t width;
uint16_t height = 0; uint16_t height;
float refresh = 0; float refresh;
int index = 0; int index;
} best_mode; } best_mode;
// First priority: choose mode that maximizes rendered pixels. // First priority: choose mode that maximizes rendered pixels.
@ -444,8 +462,7 @@ comp_window_direct_get_primary_display_mode(struct comp_window_direct *w,
VkResult ret; VkResult ret;
ret = vk->vkGetDisplayModePropertiesKHR( ret = vk->vkGetDisplayModePropertiesKHR(
w->base.swapchain.vk->physical_device, display, &mode_count, w->base.swapchain.vk->physical_device, display, &mode_count, NULL);
nullptr);
if (ret != VK_SUCCESS) { if (ret != VK_SUCCESS) {
COMP_ERROR(w->base.c, "vkGetDisplayModePropertiesKHR: %s", COMP_ERROR(w->base.c, "vkGetDisplayModePropertiesKHR: %s",
vk_result_string(ret)); vk_result_string(ret));
@ -454,15 +471,15 @@ comp_window_direct_get_primary_display_mode(struct comp_window_direct *w,
COMP_DEBUG(w->base.c, "Found %d modes", mode_count); COMP_DEBUG(w->base.c, "Found %d modes", mode_count);
VkDisplayModePropertiesKHR *mode_properties; VkDisplayModePropertiesKHR *mode_properties =
mode_properties = new VkDisplayModePropertiesKHR[mode_count]; U_TYPED_ARRAY_CALLOC(VkDisplayModePropertiesKHR, mode_count);
ret = vk->vkGetDisplayModePropertiesKHR( ret = vk->vkGetDisplayModePropertiesKHR(
w->base.swapchain.vk->physical_device, display, &mode_count, w->base.swapchain.vk->physical_device, display, &mode_count,
mode_properties); mode_properties);
if (ret != VK_SUCCESS) { if (ret != VK_SUCCESS) {
COMP_ERROR(w->base.c, "vkGetDisplayModePropertiesKHR: %s", COMP_ERROR(w->base.c, "vkGetDisplayModePropertiesKHR: %s",
vk_result_string(ret)); vk_result_string(ret));
delete[] mode_properties; free(mode_properties);
return VK_NULL_HANDLE; return VK_NULL_HANDLE;
} }
@ -509,7 +526,7 @@ comp_window_direct_get_primary_display_mode(struct comp_window_direct *w,
w->base.c->settings.nominal_frame_interval_ns = new_frame_interval; w->base.c->settings.nominal_frame_interval_ns = new_frame_interval;
delete[] mode_properties; free(mode_properties);
return props.displayMode; return props.displayMode;
} }
@ -533,19 +550,18 @@ comp_window_direct_create_surface(struct comp_window_direct *w,
uint32_t width, uint32_t width,
uint32_t height) uint32_t height)
{ {
comp_window_direct_randr_display *d = struct comp_window_direct_randr_display *d =
comp_window_direct_current_randr_display(w); comp_window_direct_current_randr_display(w);
comp_window_direct_nvidia_display *nvd = struct comp_window_direct_nvidia_display *nvd =
comp_window_direct_current_nvidia_display(w); comp_window_direct_current_nvidia_display(w);
struct vk_bundle *vk = w->base.swapchain.vk; struct vk_bundle *vk = w->base.swapchain.vk;
VkResult ret = VK_ERROR_INCOMPATIBLE_DISPLAY_KHR; VkResult ret = VK_ERROR_INCOMPATIBLE_DISPLAY_KHR;
VkDisplayKHR _display = {}; VkDisplayKHR _display = VK_NULL_HANDLE;
if (d) { if (d) {
COMP_DEBUG( COMP_DEBUG(
w->base.c, "Will use display: %s %dx%d@%.2f", w->base.c, "Will use display: %s %dx%d@%.2f", d->name,
d->name.c_str(), d->primary_mode.width, d->primary_mode.width, d->primary_mode.height,
d->primary_mode.height,
(double)d->primary_mode.dot_clock / (double)d->primary_mode.dot_clock /
(d->primary_mode.htotal * d->primary_mode.vtotal)); (d->primary_mode.htotal * d->primary_mode.vtotal));
@ -559,8 +575,7 @@ comp_window_direct_create_surface(struct comp_window_direct *w,
} }
if (nvd) { if (nvd) {
COMP_DEBUG(w->base.c, "Will use display: %s", COMP_DEBUG(w->base.c, "Will use display: %s", nvd->name);
nvd->name.c_str());
ret = comp_window_direct_acquire_xlib_display(w, nvd->display); ret = comp_window_direct_acquire_xlib_display(w, nvd->display);
_display = nvd->display; _display = nvd->display;
} }
@ -573,8 +588,7 @@ comp_window_direct_create_surface(struct comp_window_direct *w,
// Get plane properties // Get plane properties
uint32_t plane_property_count; uint32_t plane_property_count;
ret = vk->vkGetPhysicalDeviceDisplayPlanePropertiesKHR( ret = vk->vkGetPhysicalDeviceDisplayPlanePropertiesKHR(
w->base.swapchain.vk->physical_device, &plane_property_count, w->base.swapchain.vk->physical_device, &plane_property_count, NULL);
nullptr);
if (ret != VK_SUCCESS) { if (ret != VK_SUCCESS) {
COMP_ERROR(w->base.c, COMP_ERROR(w->base.c,
"vkGetPhysicalDeviceDisplayPlanePropertiesKHR: %s", "vkGetPhysicalDeviceDisplayPlanePropertiesKHR: %s",
@ -585,8 +599,8 @@ comp_window_direct_create_surface(struct comp_window_direct *w,
COMP_DEBUG(w->base.c, "Found %d plane properites.", COMP_DEBUG(w->base.c, "Found %d plane properites.",
plane_property_count); plane_property_count);
VkDisplayPlanePropertiesKHR *plane_properties = VkDisplayPlanePropertiesKHR *plane_properties = U_TYPED_ARRAY_CALLOC(
new VkDisplayPlanePropertiesKHR[plane_property_count]; VkDisplayPlanePropertiesKHR, plane_property_count);
ret = vk->vkGetPhysicalDeviceDisplayPlanePropertiesKHR( ret = vk->vkGetPhysicalDeviceDisplayPlanePropertiesKHR(
w->base.swapchain.vk->physical_device, &plane_property_count, w->base.swapchain.vk->physical_device, &plane_property_count,
@ -595,7 +609,7 @@ comp_window_direct_create_surface(struct comp_window_direct *w,
COMP_ERROR(w->base.c, COMP_ERROR(w->base.c,
"vkGetPhysicalDeviceDisplayPlanePropertiesKHR: %s", "vkGetPhysicalDeviceDisplayPlanePropertiesKHR: %s",
vk_result_string(ret)); vk_result_string(ret));
delete[] plane_properties; free(plane_properties);
return ret; return ret;
} }
@ -611,7 +625,7 @@ comp_window_direct_create_surface(struct comp_window_direct *w,
VkDisplaySurfaceCreateInfoKHR surface_info = { VkDisplaySurfaceCreateInfoKHR surface_info = {
.sType = VK_STRUCTURE_TYPE_DISPLAY_SURFACE_CREATE_INFO_KHR, .sType = VK_STRUCTURE_TYPE_DISPLAY_SURFACE_CREATE_INFO_KHR,
.pNext = nullptr, .pNext = NULL,
.flags = 0, .flags = 0,
.displayMode = display_mode, .displayMode = display_mode,
.planeIndex = plane_index, .planeIndex = plane_index,
@ -627,9 +641,9 @@ comp_window_direct_create_surface(struct comp_window_direct *w,
}; };
VkResult result = vk->vkCreateDisplayPlaneSurfaceKHR( VkResult result = vk->vkCreateDisplayPlaneSurfaceKHR(
instance, &surface_info, nullptr, surface); instance, &surface_info, NULL, surface);
delete[] plane_properties; free(plane_properties);
return result; return result;
} }
@ -639,11 +653,9 @@ comp_window_direct_init_swapchain(struct comp_window *w,
uint32_t width, uint32_t width,
uint32_t height) uint32_t height)
{ {
comp_window_direct *w_direct = (comp_window_direct *)w; struct comp_window_direct *w_direct = (struct comp_window_direct *)w;
VkResult ret;
VkResult ret = comp_window_direct_create_surface(
ret = comp_window_direct_create_surface(
w_direct, w->swapchain.vk->instance, &w->swapchain.surface, width, w_direct, w->swapchain.vk->instance, &w->swapchain.surface, width,
height); height);
if (ret != VK_SUCCESS) { if (ret != VK_SUCCESS) {
@ -661,8 +673,8 @@ comp_window_direct_init_swapchain(struct comp_window *w,
static int static int
comp_window_direct_connect(struct comp_window_direct *w) comp_window_direct_connect(struct comp_window_direct *w)
{ {
w->dpy = XOpenDisplay(nullptr); w->dpy = XOpenDisplay(NULL);
if (w->dpy == nullptr) { if (w->dpy == NULL) {
COMP_ERROR(w->base.c, "Could not open X display."); COMP_ERROR(w->base.c, "Could not open X display.");
return false; return false;
} }
@ -747,20 +759,27 @@ append_randr_display(struct comp_window_direct *w,
COMP_ERROR(w->base.c, "No mode with id %d found??", COMP_ERROR(w->base.c, "No mode with id %d found??",
output_modes[0]); output_modes[0]);
char *name_str = U_TYPED_ARRAY_CALLOC(char, name_len + 1);
memcpy(name_str, name, name_len);
name_str[name_len] = '\0';
comp_window_direct_randr_display d = { struct comp_window_direct_randr_display d = {
.name = std::string(name_str), .name = U_TYPED_ARRAY_CALLOC(char, name_len + 1),
.output = xcb_output, .output = xcb_output,
.primary_mode = *mode_info, .primary_mode = *mode_info,
.display = VK_NULL_HANDLE, .display = VK_NULL_HANDLE,
}; };
free(name_str); memcpy(d.name, name, name_len);
d.name[name_len] = '\0';
w->randr_displays.push_back(d); w->num_randr_displays += 1;
U_ARRAY_REALLOC_OR_FREE(w->randr_displays,
struct comp_window_direct_randr_display,
w->num_randr_displays);
if (w->randr_displays == NULL)
COMP_ERROR(w->base.c, "Unable to reallocate randr_displays");
w->randr_displays[w->num_randr_displays - 1] = d;
} }
static void static void
@ -773,7 +792,7 @@ comp_window_direct_get_randr_outputs(struct comp_window_direct *w)
xcb_randr_query_version_reply_t *version_reply = xcb_randr_query_version_reply_t *version_reply =
xcb_randr_query_version_reply(connection, version_cookie, NULL); xcb_randr_query_version_reply(connection, version_cookie, NULL);
if (version_reply == nullptr) { if (version_reply == NULL) {
COMP_ERROR(w->base.c, "Could not get RandR version."); COMP_ERROR(w->base.c, "Could not get RandR version.");
return; return;
} }
@ -788,20 +807,20 @@ comp_window_direct_get_randr_outputs(struct comp_window_direct *w)
free(version_reply); free(version_reply);
xcb_generic_error_t *error = nullptr; xcb_generic_error_t *error = NULL;
xcb_intern_atom_cookie_t non_desktop_cookie = xcb_intern_atom( xcb_intern_atom_cookie_t non_desktop_cookie = xcb_intern_atom(
connection, 1, strlen("non-desktop"), "non-desktop"); connection, 1, strlen("non-desktop"), "non-desktop");
xcb_intern_atom_reply_t *non_desktop_reply = xcb_intern_atom_reply_t *non_desktop_reply =
xcb_intern_atom_reply(connection, non_desktop_cookie, &error); xcb_intern_atom_reply(connection, non_desktop_cookie, &error);
if (error != nullptr) { if (error != NULL) {
COMP_ERROR(w->base.c, "xcb_intern_atom_reply returned error %d", COMP_ERROR(w->base.c, "xcb_intern_atom_reply returned error %d",
error->error_code); error->error_code);
return; return;
} }
if (non_desktop_reply == nullptr) { if (non_desktop_reply == NULL) {
COMP_ERROR(w->base.c, "non-desktop reply nullptr"); COMP_ERROR(w->base.c, "non-desktop reply NULL");
return; return;
} }
@ -814,7 +833,7 @@ comp_window_direct_get_randr_outputs(struct comp_window_direct *w)
xcb_randr_get_screen_resources(connection, w->screen->root); xcb_randr_get_screen_resources(connection, w->screen->root);
xcb_randr_get_screen_resources_reply_t *resources_reply = xcb_randr_get_screen_resources_reply_t *resources_reply =
xcb_randr_get_screen_resources_reply(connection, resources_cookie, xcb_randr_get_screen_resources_reply(connection, resources_cookie,
nullptr); NULL);
xcb_randr_output_t *xcb_outputs = xcb_randr_output_t *xcb_outputs =
xcb_randr_get_screen_resources_outputs(resources_reply); xcb_randr_get_screen_resources_outputs(resources_reply);
@ -830,7 +849,7 @@ comp_window_direct_get_randr_outputs(struct comp_window_direct *w)
XCB_CURRENT_TIME); XCB_CURRENT_TIME);
xcb_randr_get_output_info_reply_t *output_reply = xcb_randr_get_output_info_reply_t *output_reply =
xcb_randr_get_output_info_reply(connection, output_cookie, xcb_randr_get_output_info_reply(connection, output_cookie,
nullptr); NULL);
// Only outputs with an available mode should be used // Only outputs with an available mode should be used
// (it is possible to see 'ghost' outputs with non-desktop=1). // (it is possible to see 'ghost' outputs with non-desktop=1).
@ -844,10 +863,10 @@ comp_window_direct_get_randr_outputs(struct comp_window_direct *w)
prop_cookie = xcb_randr_get_output_property( prop_cookie = xcb_randr_get_output_property(
connection, xcb_outputs[i], non_desktop_reply->atom, connection, xcb_outputs[i], non_desktop_reply->atom,
XCB_ATOM_NONE, 0, 4, 0, 0); XCB_ATOM_NONE, 0, 4, 0, 0);
xcb_randr_get_output_property_reply_t *prop_reply = nullptr; xcb_randr_get_output_property_reply_t *prop_reply = NULL;
prop_reply = xcb_randr_get_output_property_reply( prop_reply = xcb_randr_get_output_property_reply(
connection, prop_cookie, &error); connection, prop_cookie, &error);
if (error != nullptr) { if (error != NULL) {
COMP_ERROR(w->base.c, COMP_ERROR(w->base.c,
"xcb_randr_get_output_property_reply " "xcb_randr_get_output_property_reply "
"returned error %d", "returned error %d",
@ -856,8 +875,8 @@ comp_window_direct_get_randr_outputs(struct comp_window_direct *w)
continue; continue;
} }
if (prop_reply == nullptr) { if (prop_reply == NULL) {
COMP_ERROR(w->base.c, "property reply == nullptr"); COMP_ERROR(w->base.c, "property reply == NULL");
free(prop_reply); free(prop_reply);
continue; continue;
} }

View file

@ -33,7 +33,7 @@ if build_xcb
endif endif
if build_xcb_xrandr_direct if build_xcb_xrandr_direct
compositor_srcs += ['main/comp_window_direct_mode.cpp'] compositor_srcs += ['main/comp_window_direct_mode.c']
compositor_deps += [xcb_randr, x11_xcb] compositor_deps += [xcb_randr, x11_xcb]
endif endif