static int stereo_find_crtc(drmModeRes *res, drmModeConnector *conn, struct gbm_dev *dev) { drmModeEncoder *enc; unsigned int i, j; int32_t crtc; /* first try the currently conected encoder+crtc */ if (conn->encoder_id) { enc = drmModeGetEncoder(dev->fd, conn->encoder_id); if (enc->crtc_id >= 0) { drmModeFreeEncoder(enc); dev->crtc = enc->crtc_id; return 0; } } /* If the connector is not currently bound to an encoder * iterate all other available encoders to find a matching * CRTC. */ for (i = 0; i < conn->count_encoders; ++i) { enc = drmModeGetEncoder(dev->fd, conn->encoders[i]); if (!enc) { fprintf(stderr, "cannot retrieve encoder %u:%u (%d): %m\n", i, conn->encoders[i], errno); continue; } /* iterate all global CRTCs */ for (j = 0; j < res->count_crtcs; ++j) { /* check whether this CRTC works with the encoder */ if (!(enc->possible_crtcs & (1 << j))) continue; /* check that no other device already uses this CRTC */ crtc = res->crtcs[j]; /* we have found a CRTC, so save it and return */ if (crtc >= 0) { drmModeFreeEncoder(enc); dev->crtc = crtc; return 0; } } drmModeFreeEncoder(enc); } fprintf(stderr, "cannot find suitable CRTC for connector %u\n", conn->connector_id); return -ENOENT; }
static drmModeCrtc * find_crtc_for_connector (int fd, drmModeRes * res, drmModeConnector * conn, guint * pipe) { int i; int crtc_id; drmModeEncoder *enc; drmModeCrtc *crtc; guint32 crtcs_for_connector = 0; crtc_id = -1; for (i = 0; i < res->count_encoders; i++) { enc = drmModeGetEncoder (fd, res->encoders[i]); if (enc) { if (enc->encoder_id == conn->encoder_id) { crtc_id = enc->crtc_id; drmModeFreeEncoder (enc); break; } drmModeFreeEncoder (enc); } } /* If no active crtc was found, pick the first possible crtc */ if (crtc_id == -1) { for (i = 0; i < conn->count_encoders; i++) { enc = drmModeGetEncoder (fd, conn->encoders[i]); crtcs_for_connector |= enc->possible_crtcs; drmModeFreeEncoder (enc); } if (crtcs_for_connector != 0) crtc_id = res->crtcs[ffs (crtcs_for_connector) - 1]; } if (crtc_id == -1) return NULL; for (i = 0; i < res->count_crtcs; i++) { crtc = drmModeGetCrtc (fd, res->crtcs[i]); if (crtc) { if (crtc_id == crtc->crtc_id) { if (pipe) *pipe = i; return crtc; } drmModeFreeCrtc (crtc); } } return NULL; }
static void output_free (int fd, CoglOutputKMS *output) { if (output->modes) g_free (output->modes); if (output->encoder) drmModeFreeEncoder (output->encoder); if (output->connector) { if (output->saved_crtc) { int ret = drmModeSetCrtc (fd, output->saved_crtc->crtc_id, output->saved_crtc->buffer_id, output->saved_crtc->x, output->saved_crtc->y, &output->connector->connector_id, 1, &output->saved_crtc->mode); if (ret) g_warning (G_STRLOC ": Error restoring saved CRTC"); } drmModeFreeConnector (output->connector); } g_slice_free (CoglOutputKMS, output); }
/* XXX: Checking this repeatedly actually hangs the GPU. I have literally no * idea why. */ static void connector_check_current_state(struct kms_atomic_connector_state *connector) { struct kms_atomic_connector_state connector_kernel; drmModeConnectorPtr legacy; uint32_t crtc_id; legacy = drmModeGetConnectorCurrent(connector->state->desc->fd, connector->obj); igt_assert(legacy); if (legacy->encoder_id) { drmModeEncoderPtr legacy_enc; legacy_enc = drmModeGetEncoder(connector->state->desc->fd, legacy->encoder_id); igt_assert(legacy_enc); crtc_id = legacy_enc->crtc_id; drmModeFreeEncoder(legacy_enc); } else { crtc_id = 0; } igt_assert_eq_u32(crtc_id, connector->crtc_id); memcpy(&connector_kernel, connector, sizeof(connector_kernel)); connector_get_current_state(&connector_kernel); do_or_die(memcmp(&connector_kernel, connector, sizeof(connector_kernel))); drmModeFreeConnector(legacy); }
/** * Remember the original CRTC status and set the CRTC */ static boolean drm_display_set_crtc(struct native_display *ndpy, int crtc_idx, uint32_t buffer_id, uint32_t x, uint32_t y, uint32_t *connectors, int num_connectors, drmModeModeInfoPtr mode) { struct drm_display *drmdpy = drm_display(ndpy); struct drm_crtc *drmcrtc = &drmdpy->saved_crtcs[crtc_idx]; uint32_t crtc_id; int err; if (drmcrtc->crtc) { crtc_id = drmcrtc->crtc->crtc_id; } else { int count = 0, i; /* * Choose the CRTC once. It could be more dynamic, but let's keep it * simple for now. */ crtc_id = drm_display_choose_crtc(&drmdpy->base, connectors, num_connectors); /* save the original CRTC status */ drmcrtc->crtc = drmModeGetCrtc(drmdpy->fd, crtc_id); if (!drmcrtc->crtc) return FALSE; for (i = 0; i < drmdpy->num_connectors; i++) { struct drm_connector *drmconn = &drmdpy->connectors[i]; drmModeConnectorPtr connector = drmconn->connector; drmModeEncoderPtr encoder; encoder = drmModeGetEncoder(drmdpy->fd, connector->encoder_id); if (encoder) { if (encoder->crtc_id == crtc_id) { drmcrtc->connectors[count++] = connector->connector_id; if (count >= Elements(drmcrtc->connectors)) break; } drmModeFreeEncoder(encoder); } } drmcrtc->num_connectors = count; } err = drmModeSetCrtc(drmdpy->fd, crtc_id, buffer_id, x, y, connectors, num_connectors, mode); if (err) { drmModeFreeCrtc(drmcrtc->crtc); drmcrtc->crtc = NULL; drmcrtc->num_connectors = 0; return FALSE; } return TRUE; }
void Drm::resetOutput(int index) { DrmOutput *output = &mOutputs[index]; output->connected = false; memset(&output->mode, 0, sizeof(drmModeModeInfo)); if (output->connector) { drmModeFreeConnector(output->connector); output->connector = 0; } if (output->encoder) { drmModeFreeEncoder(output->encoder); output->encoder = 0; } if (output->crtc) { drmModeFreeCrtc(output->crtc); output->crtc = 0; } if (output->fbId) { drmModeRmFB(mDrmFd, output->fbId); output->fbId = 0; } if (output->fbHandle) { Hwcomposer::getInstance().getBufferManager()->freeFrameBuffer(output->fbHandle); output->fbHandle = 0; } }
static void free_drm_resources(void) { if (g_gbm_surface) gbm_surface_destroy(g_gbm_surface); if (g_gbm_dev) gbm_device_destroy(g_gbm_dev); if (g_encoder) drmModeFreeEncoder(g_encoder); if (g_connector) drmModeFreeConnector(g_connector); if (g_resources) drmModeFreeResources(g_resources); if (g_orig_crtc) drmModeFreeCrtc(g_orig_crtc); if (g_drm_fd >= 0) close(g_drm_fd); g_gbm_surface = NULL; g_gbm_dev = NULL; g_encoder = NULL; g_connector = NULL; g_resources = NULL; g_orig_crtc = NULL; g_drm_fd = -1; }
static bool find_available_crtc(drmModeRes * resources, drmModeConnector * connector, uint32_t taken_crtcs, uint32_t * crtc) { uint32_t encoder_index, crtc_index; uint32_t possible_crtcs; drmModeEncoder * encoder; for (encoder_index = 0; encoder_index < connector->count_encoders; ++encoder_index) { encoder = drmModeGetEncoder(swc.drm->fd, connector->encoders[encoder_index]); possible_crtcs = encoder->possible_crtcs; drmModeFreeEncoder(encoder); for (crtc_index = 0; crtc_index < resources->count_crtcs; ++crtc_index) { if ((possible_crtcs & (1 << crtc_index)) && !(taken_crtcs & (1 << crtc_index))) { *crtc = crtc_index; return true; } } } return false; }
static void free_drm_resources(gfx_ctx_drm_egl_data_t *drm) { if (!drm) return; if (drm->g_gbm_surface) gbm_surface_destroy(drm->g_gbm_surface); if (drm->g_gbm_dev) gbm_device_destroy(drm->g_gbm_dev); if (drm->g_encoder) drmModeFreeEncoder(drm->g_encoder); if (drm->g_connector) drmModeFreeConnector(drm->g_connector); if (drm->g_resources) drmModeFreeResources(drm->g_resources); if (drm->g_orig_crtc) drmModeFreeCrtc(drm->g_orig_crtc); if (drm->g_drm_fd >= 0) close(drm->g_drm_fd); drm->g_gbm_surface = NULL; drm->g_gbm_dev = NULL; drm->g_encoder = NULL; drm->g_connector = NULL; drm->g_resources = NULL; drm->g_orig_crtc = NULL; drm->g_drm_fd = -1; }
static drmModeEncoder * find_encoder_for_connector (ply_renderer_backend_t *backend, drmModeConnector *connector) { int i; drmModeEncoder *encoder; assert (backend != NULL); for (i = 0; i < connector->count_encoders; i++) { encoder = drmModeGetEncoder (backend->device_fd, connector->encoders[i]); if (encoder == NULL) continue; if (encoder->encoder_id == connector->encoder_id) return encoder; drmModeFreeEncoder (encoder); } return NULL; }
static void clean_up_drm(struct exynos_drm *d, int fd) { if (d->encoder) drmModeFreeEncoder(d->encoder); if (d->connector) drmModeFreeConnector(d->connector); if (d->resources) drmModeFreeResources(d->resources); free(d); close(fd); }
/*!*********************************************************************** @Function OsReleaseOS @description Destroys main window *************************************************************************/ void PVRShellInit::OsReleaseOS() { gbm_surface_destroy(m_psGbmSurface); gbm_device_destroy(m_psGbmDev); drmModeFreeCrtc(m_psDrmCrtc); drmModeFreeEncoder(m_psDrmEncoder); drmModeFreeConnector(m_psDrmConnector); drmModeFreeResources(m_psDrmResources); drmClose(m_i32DrmFile); }
/** * Choose a CRTC that supports all given connectors. */ static uint32_t drm_display_choose_crtc(struct native_display *ndpy, uint32_t *connectors, int num_connectors) { struct drm_display *drmdpy = drm_display(ndpy); int idx; for (idx = 0; idx < drmdpy->resources->count_crtcs; idx++) { boolean found_crtc = TRUE; int i, j; for (i = 0; i < num_connectors; i++) { drmModeConnectorPtr connector; int encoder_idx = -1; connector = drmModeGetConnector(drmdpy->fd, connectors[i]); if (!connector) { found_crtc = FALSE; break; } /* find an encoder the CRTC supports */ for (j = 0; j < connector->count_encoders; j++) { drmModeEncoderPtr encoder = drmModeGetEncoder(drmdpy->fd, connector->encoders[j]); if (encoder->possible_crtcs & (1 << idx)) { encoder_idx = j; break; } drmModeFreeEncoder(encoder); } drmModeFreeConnector(connector); if (encoder_idx < 0) { found_crtc = FALSE; break; } } if (found_crtc) break; } if (idx >= drmdpy->resources->count_crtcs) { _eglLog(_EGL_WARNING, "failed to find a CRTC that supports the given %d connectors", num_connectors); return 0; } return drmdpy->resources->crtcs[idx]; }
static void free_resources (MetaMonitorManagerKms *manager_kms) { unsigned i; for (i = 0; i < manager_kms->n_encoders; i++) drmModeFreeEncoder (manager_kms->encoders[i]); for (i = 0; i < manager_kms->n_connectors; i++) drmModeFreeConnector (manager_kms->connectors[i]); g_free (manager_kms->encoders); g_free (manager_kms->connectors); }
static drmModeCrtc * find_crtc_for_connector (int fd, drmModeRes * res, drmModeConnector * conn, guint * pipe) { int i; int crtc_id; drmModeEncoder *enc; drmModeCrtc *crtc; crtc_id = -1; for (i = 0; i < res->count_encoders; i++) { enc = drmModeGetEncoder (fd, res->encoders[i]); if (enc) { if (enc->encoder_id == conn->encoder_id) { crtc_id = enc->crtc_id; drmModeFreeEncoder (enc); break; } drmModeFreeEncoder (enc); } } if (crtc_id == -1) return NULL; for (i = 0; i < res->count_crtcs; i++) { crtc = drmModeGetCrtc (fd, res->crtcs[i]); if (crtc) { if (crtc_id == crtc->crtc_id) { if (pipe) *pipe = i; return crtc; } drmModeFreeCrtc (crtc); } } return NULL; }
void QKmsScreen::initializeScreenMode() { //Determine optimal mode for screen drmModeRes *resources = drmModeGetResources(m_device->fd()); if (!resources) qFatal("drmModeGetResources failed"); drmModeConnector *connector = drmModeGetConnector(m_device->fd(), m_connectorId); drmModeModeInfo *mode = 0; for (int i = 0; i < connector->count_modes; ++i) { if (connector->modes[i].type & DRM_MODE_TYPE_PREFERRED) { mode = &connector->modes[i]; break; } } if (!mode) mode = &builtin_1024x768; drmModeEncoder *encoder = drmModeGetEncoder(m_device->fd(), connector->encoders[0]); if (encoder == 0) qFatal("No encoder for connector."); int i; for (i = 0; i < resources->count_crtcs; i++) { if (encoder->possible_crtcs & (1 << i)) break; } if (i == resources->count_crtcs) qFatal("No usable crtc for encoder."); m_oldCrtc = drmModeGetCrtc(m_device->fd(), encoder->crtc_id); m_crtcId = resources->crtcs[i]; m_mode = *mode; m_geometry = QRect(0, 0, m_mode.hdisplay, m_mode.vdisplay); qDebug() << "kms initialized with geometry" << m_geometry; m_depth = 32; m_format = QImage::Format_RGB32; m_physicalSize = QSizeF(connector->mmWidth, connector->mmHeight); m_gbmSurface = gbm_surface_create(m_device->gbmDevice(), m_mode.hdisplay, m_mode.vdisplay, GBM_BO_FORMAT_XRGB8888, GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING); qDebug() << "created gbm surface" << m_gbmSurface << m_mode.hdisplay << m_mode.vdisplay; //Cleanup drmModeFreeEncoder(encoder); drmModeFreeConnector(connector); drmModeFreeResources(resources); }
drmModeEncoderPtr IntelHWComposerDrm::getEncoder(int disp) { if (mDrmFd < 0) { ALOGE("%s: invalid drm FD\n", __func__); return NULL; } uint32_t req_encoder_type = 0; switch (disp) { case OUTPUT_MIPI0: case OUTPUT_MIPI1: req_encoder_type = DRM_MODE_ENCODER_MIPI; break; case OUTPUT_HDMI: req_encoder_type = DRM_MODE_ENCODER_TMDS; break; default: ALOGW("%s: invalid device number: %d\n", __func__, disp); return NULL; } drmModeResPtr resources = drmModeGetResources(mDrmFd); if (!resources || !resources->encoders) { ALOGE("%s: fail to get drm resources. %s\n", __func__, strerror(errno)); return NULL; } drmModeEncoderPtr encoder = NULL; for (int i = 0; i < resources->count_encoders; i++) { encoder = drmModeGetEncoder(mDrmFd, resources->encoders[i]); if (!encoder) { ALOGW("%s: Failed to get encoder\n", __func__); continue; } if (encoder->encoder_type == req_encoder_type) break; drmModeFreeEncoder(encoder); encoder = NULL; } drmModeFreeResources(resources); if (encoder == NULL) ALOGW("%s: fail to get required encoder\n", __func__); return encoder; }
static void meta_output_destroy_notify (MetaOutput *output) { MetaOutputKms *output_kms; unsigned i; output_kms = output->driver_private; for (i = 0; i < output_kms->n_encoders; i++) drmModeFreeEncoder (output_kms->encoders[i]); g_free (output_kms->encoders); g_slice_free (MetaOutputKms, output_kms); }
static EGLBoolean setup_kms(int fd, struct kms *kms) { drmModeRes *resources; drmModeConnector *connector; drmModeEncoder *encoder; int i; resources = drmModeGetResources(fd); if (!resources) { fprintf(stderr, "drmModeGetResources failed\n"); return EGL_FALSE; } for (i = 0; i < resources->count_connectors; i++) { connector = drmModeGetConnector(fd, resources->connectors[i]); if (connector == NULL) continue; if (connector->connection == DRM_MODE_CONNECTED && connector->count_modes > 0) break; drmModeFreeConnector(connector); } if (i == resources->count_connectors) { fprintf(stderr, "No currently active connector found.\n"); return EGL_FALSE; } for (i = 0; i < resources->count_encoders; i++) { encoder = drmModeGetEncoder(fd, resources->encoders[i]); if (encoder == NULL) continue; if (encoder->encoder_id == connector->encoder_id) break; drmModeFreeEncoder(encoder); } kms->connector = connector; kms->encoder = encoder; kms->mode = connector->modes[0]; return EGL_TRUE; }
static void printEncoders(int fd, uint32_t* ids, uint32_t count) { int i; for (i = 0; i < count; i++) { drmModeEncoder *enc; enc = drmModeGetEncoder(fd, ids[i]); fprintf(stdout, " Encoder %u:\n", enc->encoder_id); fprintf(stdout, " Type: %s\n", getEncoderType(enc->encoder_type)); fprintf(stdout, " CRTC: %u\n", enc->crtc_id); fprintf(stdout, " Possible CRTCs: %1$u, %1$#08x, %1$#016o, %2$s\n", enc->possible_crtcs, bitList(enc->possible_crtcs)); fprintf(stdout, " Possible Clones: %1$u, %1$#08x, %1$#016o, %2$s\n", enc->possible_clones, bitList(enc->possible_clones)); fprintf(stdout, "\n"); drmModeFreeEncoder(enc); } }
static void exit_drm(void) { drmModeRes *resources; int i; resources = (drmModeRes *)drm.resource_id; for (i = 0; i < resources->count_connectors; i++) { drmModeFreeEncoder((drmModeEncoderPtr)drm.encoder[i]); drmModeFreeConnector(drm.connectors[i]); } drmModeFreeResources((drmModeResPtr)drm.resource_id); drmClose(drm.fd); return; }
void drm_free(void) { if (g_drm_encoder) drmModeFreeEncoder(g_drm_encoder); if (g_drm_connector) drmModeFreeConnector(g_drm_connector); if (g_drm_resources) drmModeFreeResources(g_drm_resources); memset(&g_drm_fds, 0, sizeof(struct pollfd)); memset(&g_drm_evctx, 0, sizeof(drmEventContext)); g_drm_encoder = NULL; g_drm_connector = NULL; g_drm_resources = NULL; }
void QKmsScreen::initializeScreenMode() { //Determine optimal mode for screen drmModeRes *resources = drmModeGetResources(m_device->fd()); if (!resources) qFatal("drmModeGetResources failed"); drmModeConnector *connector = drmModeGetConnector(m_device->fd(), m_connectorId); drmModeModeInfo *mode = 0; if (connector->count_modes > 0) mode = &connector->modes[0]; else mode = &builtin_1024x768; drmModeEncoder *encoder = drmModeGetEncoder(m_device->fd(), connector->encoders[0]); if (encoder == 0) qFatal("No encoder for connector."); int i; for (i = 0; i < resources->count_crtcs; i++) { if (encoder->possible_crtcs & (1 << i)) break; } if (i == resources->count_crtcs) qFatal("No usable crtc for encoder."); m_crtcId = resources->crtcs[i]; m_mode = *mode; m_geometry = QRect(0, 0, m_mode.hdisplay, m_mode.vdisplay); m_depth = 32; m_format = QImage::Format_RGB32; m_physicalSize = QSizeF(connector->mmWidth, connector->mmHeight); //Setup three buffers for current mode m_bufferManager.setupBuffersForMode(m_mode, 3); //Set the Mode of the screen. int ret = drmModeSetCrtc(m_device->fd(), m_crtcId, m_bufferManager.displayFramebufferId(), 0, 0, &m_connectorId, 1, &m_mode); if (ret) qFatal("failed to set mode"); //Cleanup drmModeFreeEncoder(encoder); drmModeFreeConnector(connector); drmModeFreeResources(resources); }
/** * Get the index of the CRTC of the monitor connected to a connector * * @param connection The identifier for the connection to the card * @param connector_index The index of the connector * @return The index of the CRTC */ int blueshift_drm_get_crtc(int connection, int connector_index) { card_connection* card = card_connections + connection; drmModeEncoder* encoder = drmModeGetEncoder(card->fd, card->connectors[connector_index]->encoder_id); uint32_t crtc_id = encoder->crtc_id; drmModeRes* res = card->res; int crtc; int n; drmModeFreeEncoder(encoder); n = res->count_crtcs; for (crtc = 0; crtc < n; crtc++) if (*(res->crtcs + crtc) == crtc_id) return crtc; return -1; }
void destroy_sp_dev(struct sp_dev *dev) { int i; if (dev->planes) { for (i = 0; i < dev->num_planes; i++) { if (dev->planes[i].in_use) put_sp_plane(&dev->planes[i]); if (dev->planes[i].plane) drmModeFreePlane(dev->planes[i].plane); if (dev->planes[i].bo) free_sp_bo(dev->planes[i].bo); } free(dev->planes); } if (dev->crtcs) { for (i = 0; i < dev->num_crtcs; i++) { if (dev->crtcs[i].crtc) drmModeFreeCrtc(dev->crtcs[i].crtc); if (dev->crtcs[i].scanout) free_sp_bo(dev->crtcs[i].scanout); } free(dev->crtcs); } if (dev->encoders) { for (i = 0; i < dev->num_encoders; i++) { if (dev->encoders[i]) drmModeFreeEncoder(dev->encoders[i]); } free(dev->encoders); } if (dev->connectors) { for (i = 0; i < dev->num_connectors; i++) { if (dev->connectors[i]) drmModeFreeConnector(dev->connectors[i]); } free(dev->connectors); } close(dev->fd); free(dev); }
static void set_stereo_mode(struct connector *c) { int i, n; if (specified_mode_num != -1) n = 1; else n = c->connector->count_modes; for (i = 0; i < n; i++) { if (specified_mode_num == -1) c->mode = c->connector->modes[i]; if (!c->mode_valid) continue; if (!(c->mode.flags & DRM_MODE_FLAG_3D_MASK)) continue; igt_info("CRTC(%u): [%d]", c->crtc, i); kmstest_dump_mode(&c->mode); do_set_stereo_mode(c); if (qr_code) { set_single(); pause(); } else if (sleep_between_modes) sleep(sleep_between_modes); if (do_dpms) { kmstest_set_connector_dpms(drm_fd, c->connector, DRM_MODE_DPMS_OFF); sleep(sleep_between_modes); kmstest_set_connector_dpms(drm_fd, c->connector, DRM_MODE_DPMS_ON); } } drmModeFreeEncoder(c->encoder); drmModeFreeConnector(c->connector); }
void CDRMUtils::DestroyDrm() { RestoreOriginalMode(); drmDropMaster(m_fd); close(m_fd); m_fd = -1; drmModeFreeResources(m_drm_resources); m_drm_resources = nullptr; drmModeFreeConnector(m_connector->connector); drmModeFreeObjectProperties(m_connector->props); delete [] m_connector->props_info; delete m_connector; m_connector = nullptr; drmModeFreeEncoder(m_encoder->encoder); delete m_encoder; m_encoder = nullptr; drmModeFreeCrtc(m_crtc->crtc); drmModeFreeObjectProperties(m_crtc->props); delete [] m_crtc->props_info; delete m_crtc; m_crtc = nullptr; drmModeFreePlane(m_primary_plane->plane); drmModeFreeObjectProperties(m_primary_plane->props); delete [] m_primary_plane->props_info; delete m_primary_plane; m_primary_plane = nullptr; drmModeFreePlane(m_overlay_plane->plane); drmModeFreeObjectProperties(m_overlay_plane->props); delete [] m_overlay_plane->props_info; delete m_overlay_plane; m_overlay_plane = nullptr; }
void NativeStateDRM::cleanup() { // Restore CRTC state if necessary if (crtc_) { int status = drmModeSetCrtc(fd_, crtc_->crtc_id, crtc_->buffer_id, crtc_->x, crtc_->y, &connector_->connector_id, 1, &crtc_->mode); if (status < 0) { Log::error("Failed to restore original CRTC: %d\n", status); } drmModeFreeCrtc(crtc_); crtc_ = 0; } if (surface_) { gbm_surface_destroy(surface_); surface_ = 0; } if (dev_) { gbm_device_destroy(dev_); dev_ = 0; } if (connector_) { drmModeFreeConnector(connector_); connector_ = 0; } if (encoder_) { drmModeFreeEncoder(encoder_); encoder_ = 0; } if (resources_) { drmModeFreeResources(resources_); resources_ = 0; } if (fd_ > 0) { drmClose(fd_); } fd_ = 0; mode_ = 0; }
bool CDRMUtils::GetEncoder() { for(auto i = 0; i < m_drm_resources->count_encoders; i++) { m_encoder->encoder = drmModeGetEncoder(m_fd, m_drm_resources->encoders[i]); if(m_encoder->encoder->encoder_id == m_connector->connector->encoder_id) { CLog::Log(LOGDEBUG, "CDRMUtils::%s - found encoder: %d", __FUNCTION__, m_encoder->encoder->encoder_id); break; } drmModeFreeEncoder(m_encoder->encoder); m_encoder->encoder = nullptr; } if(!m_encoder->encoder) { CLog::Log(LOGERROR, "CDRMUtils::%s - could not get encoder: %s", __FUNCTION__, strerror(errno)); return false; } return true; }
bool drm_get_encoder(int fd) { unsigned i; for (i = 0; (int)i < g_drm_resources->count_encoders; i++) { g_drm_encoder = drmModeGetEncoder(fd, g_drm_resources->encoders[i]); if (!g_drm_encoder) continue; if (g_drm_encoder->encoder_id == g_drm_connector->encoder_id) break; drmModeFreeEncoder(g_drm_encoder); g_drm_encoder = NULL; } if (!g_drm_encoder) { RARCH_WARN("[DRM]: Couldn't find DRM encoder.\n"); return false; } for (i = 0; (int)i < g_drm_connector->count_modes; i++) { RARCH_LOG("[DRM]: Mode %d: (%s) %d x %d, %u Hz\n", i, g_drm_connector->modes[i].name, g_drm_connector->modes[i].hdisplay, g_drm_connector->modes[i].vdisplay, g_drm_connector->modes[i].vrefresh); } return true; }