/* * @return \c true if the mode was truly replaced/changed * (comparing to previously set) */ static bool evdi_painter_replace_mode(struct evdi_painter *painter, const struct drm_display_mode *new_mode) { struct drm_display_mode *current_mode = &painter->current_mode; if (drm_mode_equal(current_mode, new_mode)) return false; drm_mode_copy(current_mode, new_mode); return true; }
static MetaMonitorMode * find_meta_mode (MetaMonitorManager *manager, const drmModeModeInfo *drm_mode) { unsigned k; for (k = 0; k < manager->n_modes; k++) { if (drm_mode_equal (drm_mode, manager->modes[k].driver_private)) return &manager->modes[k]; } g_assert_not_reached (); return NULL; }
static void meta_monitor_manager_kms_read_current (MetaMonitorManager *manager) { MetaMonitorManagerKms *manager_kms = META_MONITOR_MANAGER_KMS (manager); drmModeRes *resources; GHashTable *modes; GHashTableIter iter; drmModeModeInfo *mode; unsigned int i, j, k; unsigned int n_actual_outputs; int width, height; MetaOutput *old_outputs; unsigned int n_old_outputs; resources = drmModeGetResources(manager_kms->fd); modes = g_hash_table_new (drm_mode_hash, drm_mode_equal); manager->max_screen_width = resources->max_width; manager->max_screen_height = resources->max_height; manager->power_save_mode = META_POWER_SAVE_ON; old_outputs = manager->outputs; n_old_outputs = manager->n_outputs; /* Note: we must not free the public structures (output, crtc, monitor mode and monitor info) here, they must be kept alive until the API users are done with them after we emit monitors-changed, and thus are freed by the platform-independent layer. */ free_resources (manager_kms); manager_kms->n_connectors = resources->count_connectors; manager_kms->connectors = g_new (drmModeConnector *, manager_kms->n_connectors); for (i = 0; i < manager_kms->n_connectors; i++) { drmModeConnector *connector; connector = drmModeGetConnector (manager_kms->fd, resources->connectors[i]); manager_kms->connectors[i] = connector; if (connector->connection == DRM_MODE_CONNECTED) { /* Collect all modes for this connector */ for (j = 0; j < (unsigned)connector->count_modes; j++) g_hash_table_add (modes, &connector->modes[j]); } } manager_kms->n_encoders = resources->count_encoders; manager_kms->encoders = g_new (drmModeEncoder *, manager_kms->n_encoders); for (i = 0; i < manager_kms->n_encoders; i++) { manager_kms->encoders[i] = drmModeGetEncoder (manager_kms->fd, resources->encoders[i]); } manager->n_modes = g_hash_table_size (modes); manager->modes = g_new0 (MetaMonitorMode, manager->n_modes); g_hash_table_iter_init (&iter, modes); i = 0; while (g_hash_table_iter_next (&iter, NULL, (gpointer)&mode)) { MetaMonitorMode *meta_mode; meta_mode = &manager->modes[i]; meta_mode->mode_id = i; meta_mode->name = g_strndup (mode->name, DRM_DISPLAY_MODE_LEN); meta_mode->width = mode->hdisplay; meta_mode->height = mode->vdisplay; meta_mode->refresh_rate = (1000 * mode->clock / ((float)mode->htotal * mode->vtotal)); meta_mode->driver_private = g_slice_dup (drmModeModeInfo, mode); meta_mode->driver_notify = (GDestroyNotify)meta_monitor_mode_destroy_notify; i++; } g_hash_table_destroy (modes); manager->n_crtcs = resources->count_crtcs; manager->crtcs = g_new0 (MetaCRTC, manager->n_crtcs); width = 0; height = 0; for (i = 0; i < (unsigned)resources->count_crtcs; i++) { drmModeCrtc *crtc; MetaCRTC *meta_crtc; crtc = drmModeGetCrtc (manager_kms->fd, resources->crtcs[i]); meta_crtc = &manager->crtcs[i]; meta_crtc->crtc_id = crtc->crtc_id; meta_crtc->rect.x = crtc->x; meta_crtc->rect.y = crtc->y; meta_crtc->rect.width = crtc->width; meta_crtc->rect.height = crtc->height; meta_crtc->is_dirty = FALSE; meta_crtc->transform = META_MONITOR_TRANSFORM_NORMAL; /* FIXME: implement! */ meta_crtc->all_transforms = 1 << META_MONITOR_TRANSFORM_NORMAL; if (crtc->mode_valid) { for (j = 0; j < manager->n_modes; j++) { if (drm_mode_equal (&crtc->mode, manager->modes[j].driver_private)) { meta_crtc->current_mode = &manager->modes[j]; break; } } width = MAX (width, meta_crtc->rect.x + meta_crtc->rect.width); height = MAX (height, meta_crtc->rect.y + meta_crtc->rect.height); } drmModeFreeCrtc (crtc); } manager->screen_width = width; manager->screen_height = height; manager->outputs = g_new0 (MetaOutput, manager_kms->n_connectors); n_actual_outputs = 0; for (i = 0; i < manager_kms->n_connectors; i++) { MetaOutput *meta_output, *old_output; MetaOutputKms *output_kms; drmModeConnector *connector; GArray *crtcs; unsigned int crtc_mask; GBytes *edid; connector = manager_kms->connectors[i]; meta_output = &manager->outputs[n_actual_outputs]; if (connector->connection == DRM_MODE_CONNECTED) { meta_output->driver_private = output_kms = g_slice_new0 (MetaOutputKms); meta_output->driver_notify = (GDestroyNotify)meta_output_destroy_notify; meta_output->winsys_id = connector->connector_id; meta_output->name = make_output_name (connector); meta_output->width_mm = connector->mmWidth; meta_output->height_mm = connector->mmHeight; switch (connector->subpixel) { case DRM_MODE_SUBPIXEL_NONE: meta_output->subpixel_order = COGL_SUBPIXEL_ORDER_NONE; break; case DRM_MODE_SUBPIXEL_HORIZONTAL_RGB: meta_output->subpixel_order = COGL_SUBPIXEL_ORDER_HORIZONTAL_RGB; break; case DRM_MODE_SUBPIXEL_HORIZONTAL_BGR: meta_output->subpixel_order = COGL_SUBPIXEL_ORDER_HORIZONTAL_BGR; break; case DRM_MODE_SUBPIXEL_VERTICAL_RGB: meta_output->subpixel_order = COGL_SUBPIXEL_ORDER_VERTICAL_RGB; break; case DRM_MODE_SUBPIXEL_VERTICAL_BGR: meta_output->subpixel_order = COGL_SUBPIXEL_ORDER_VERTICAL_BGR; break; case DRM_MODE_SUBPIXEL_UNKNOWN: default: meta_output->subpixel_order = COGL_SUBPIXEL_ORDER_UNKNOWN; break; } meta_output->n_modes = connector->count_modes; meta_output->modes = g_new0 (MetaMonitorMode *, meta_output->n_modes); for (j = 0; j < meta_output->n_modes; j++) meta_output->modes[j] = find_meta_mode (manager, &connector->modes[j]); meta_output->preferred_mode = meta_output->modes[0]; output_kms->connector = connector; output_kms->n_encoders = connector->count_encoders; output_kms->encoders = g_new0 (drmModeEncoderPtr, output_kms->n_encoders); crtc_mask = ~(unsigned int)0; for (j = 0; j < output_kms->n_encoders; j++) { output_kms->encoders[j] = drmModeGetEncoder (manager_kms->fd, connector->encoders[j]); /* We only list CRTCs as supported if they are supported by all encoders for this connectors. This is what xf86-video-modesetting does (see drmmode_output_init()) */ crtc_mask &= output_kms->encoders[j]->possible_crtcs; if (output_kms->encoders[j]->encoder_id == connector->encoder_id) output_kms->current_encoder = output_kms->encoders[j]; } crtcs = g_array_new (FALSE, FALSE, sizeof (MetaCRTC*)); for (j = 0; j < manager->n_crtcs; j++) { if (crtc_mask & (1 << j)) { MetaCRTC *crtc = &manager->crtcs[j]; g_array_append_val (crtcs, crtc); } } meta_output->n_possible_crtcs = crtcs->len; meta_output->possible_crtcs = (void*)g_array_free (crtcs, FALSE); if (output_kms->current_encoder && output_kms->current_encoder->crtc_id != 0) { for (j = 0; j < manager->n_crtcs; j++) { if (manager->crtcs[j].crtc_id == output_kms->current_encoder->crtc_id) { meta_output->crtc = &manager->crtcs[j]; break; } } } else meta_output->crtc = NULL; old_output = find_output_by_id (old_outputs, n_old_outputs, meta_output->winsys_id); if (old_output) { meta_output->is_primary = old_output->is_primary; meta_output->is_presentation = old_output->is_presentation; } else { meta_output->is_primary = FALSE; meta_output->is_presentation = FALSE; } find_properties (manager_kms, output_kms); edid = read_output_edid (manager_kms, meta_output); if (edid) { MonitorInfo *parsed_edid; gsize len; parsed_edid = decode_edid (g_bytes_get_data (edid, &len)); if (parsed_edid) { meta_output->vendor = g_strndup (parsed_edid->manufacturer_code, 4); meta_output->product = g_strndup (parsed_edid->dsc_product_name, 14); meta_output->serial = g_strndup (parsed_edid->dsc_serial_number, 14); g_free (parsed_edid); } g_bytes_unref (edid); } if (!meta_output->vendor) { meta_output->vendor = g_strdup ("unknown"); meta_output->product = g_strdup ("unknown"); meta_output->serial = g_strdup ("unknown"); } /* FIXME: backlight is a very driver specific thing unfortunately, every DDX does its own thing, and the dumb KMS API does not include it. For example, xf86-video-intel has a list of paths to probe in /sys/class/backlight (one for each major HW maker, and then some). We can't do the same because we're not root. It might be best to leave backlight out of the story and rely on the setuid helper in gnome-settings-daemon. */ meta_output->backlight_min = 0; meta_output->backlight_max = 0; meta_output->backlight = -1; n_actual_outputs++; } }