int DrmResources::SetDisplayActiveMode(int display, const DrmMode &mode) { DrmConnector *connector = GetConnectorForDisplay(display); if (!connector) { ALOGE("Could not locate connector for display %d", display); return -ENODEV; } int ret = CreateDisplayPipe(connector); if (ret) { ALOGE("Failed CreateDisplayPipe with %d", ret); return ret; } DrmCrtc *crtc = connector->encoder()->crtc(); DrmProperty old_mode; ret = GetCrtcProperty(*crtc, crtc->mode_property().name().c_str(), &old_mode); if (ret) { ALOGE("Failed to get old mode property from crtc %d", crtc->id()); return ret; } struct drm_mode_modeinfo drm_mode; memset(&drm_mode, 0, sizeof(drm_mode)); mode.ToDrmModeModeInfo(&drm_mode); uint32_t blob_id; ret = CreatePropertyBlob(&drm_mode, sizeof(struct drm_mode_modeinfo), &blob_id); if (ret) { ALOGE("Failed to create mode property blob %d", ret); return ret; } drmModePropertySetPtr pset = drmModePropertySetAlloc(); if (!pset) { ALOGE("Failed to allocate property set"); DestroyPropertyBlob(blob_id); return -ENOMEM; } ret = drmModePropertySetAdd(pset, crtc->id(), crtc->mode_property().id(), blob_id) || drmModePropertySetAdd(pset, connector->id(), connector->crtc_id_property().id(), crtc->id()); if (ret) { ALOGE("Failed to add blob %d to pset", blob_id); DestroyPropertyBlob(blob_id); drmModePropertySetFree(pset); return ret; } ret = drmModePropertySetCommit(fd_, DRM_MODE_ATOMIC_ALLOW_MODESET, NULL, pset); drmModePropertySetFree(pset); if (ret) { ALOGE("Failed to commit pset ret=%d\n", ret); DestroyPropertyBlob(blob_id); return ret; } connector->set_active_mode(mode); uint64_t old_blob_id; ret = old_mode.value(&old_blob_id); if (ret) { ALOGE("Could not get old blob id value %d", ret); return ret; } if (!old_blob_id) return 0; ret = DestroyPropertyBlob(old_blob_id); if (ret) { ALOGE("Failed to destroy old mode property blob", old_blob_id); return ret; } return 0; }
static void commit_state(struct my_ctx *ctx) { struct timespec pre, post; int i, r; #ifndef LEGACY_API if (!ctx->set) return; dprintf("kick: %d/%d\n", completed_fence, next_fence); last_fence = next_fence; next_fence++; clock_gettime(CLOCK_MONOTONIC, &pre); //r = drmModePropertySetCommit(fd, DRM_MODE_ATOMIC_TEST_ONLY, set); r = drmModePropertySetCommit(ctx->fd, ctx->flags, ctx, ctx->set); clock_gettime(CLOCK_MONOTONIC, &post); tp_sub(&post, &pre); printf("commit took %lu secs, %lu nsecs\n", post.tv_sec, post.tv_nsec); drmModePropertySetFree(ctx->set); ctx->set = NULL; if (r) { printf("setatomic returned %d:%s\n", errno, strerror(errno)); for (i = 0; i < ctx->count_crtcs; i++) { struct my_plane *p = &ctx->planes[i]; struct my_crtc *c = container_of(p->base.crtc, struct my_crtc, base); if (p->dirty) { unsigned int src_w = p->src.x2 - p->src.x1; unsigned int src_h = p->src.y2 - p->src.y1; unsigned int dst_w = p->dst.x2 - p->dst.x1; unsigned int dst_h = p->dst.y2 - p->dst.y1; printf("plane = %u, crtc = %u, fb = %u\n", p->base.plane_id, p->base.crtc->crtc_id, p->buf ? p->buf->fb_id : 0); printf("src = %u.%06ux%u.%06u+%u.%06u+%u.%06u\n", src_w >> 16, ((src_w & 0xffff) * 15625) >> 10, src_h >> 16, ((src_h & 0xffff) * 15625) >> 10, p->src.x1 >> 16, ((p->src.x1 & 0xffff) * 15625) >> 10, p->src.y1 >> 16, ((p->src.y1 & 0xffff) * 15625) >> 10); printf("dst = %ux%u+%d+%d\n", dst_w, dst_h, p->dst.x1, p->dst.y1); } if (c->primary->dirty) printf("crtc = %u, fb = %u\n", c->base.crtc_id, c->primary->buf ? c->primary->buf->fb_id : 0); if (c->dirty_mode) { print_mode("mode", &c->mode); printf("connector_id = %u\n", c->connector_ids[0]); } if (p->buf) { surface_buffer_put_fb(&p->surf.base, p->buf); p->buf = NULL; } if (c->primary->buf) { surface_buffer_put_fb(&c->primary->surf.base, c->primary->buf); c->primary->buf = NULL; } next_fence--; } return; }