X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=drmdisplaycompositor.cpp;h=e8327cd50abdf361853372680445bd8a28db99a2;hb=b40363552334c0f57d59df41fc70c1a9a4517681;hp=95e23332d12e49904598bd6b6cf41e2635f803f1;hpb=6afbb6aef0c89b8e737624c4baa1208aaec6f48e;p=android-x86%2Fexternal-drm_hwcomposer.git diff --git a/drmdisplaycompositor.cpp b/drmdisplaycompositor.cpp index 95e2333..e8327cd 100644 --- a/drmdisplaycompositor.cpp +++ b/drmdisplaycompositor.cpp @@ -241,6 +241,7 @@ DrmDisplayCompositor::DrmDisplayCompositor() frame_worker_(this), initialized_(false), active_(false), + use_hw_overlays_(true), framebuffer_index_(0), squash_framebuffer_index_(0), dump_frames_composited_(0), @@ -478,7 +479,7 @@ int DrmDisplayCompositor::ApplyPreComposite( } int DrmDisplayCompositor::DisablePlanes(DrmDisplayComposition *display_comp) { - drmModePropertySetPtr pset = drmModePropertySetAlloc(); + drmModeAtomicReqPtr pset = drmModeAtomicAlloc(); if (!pset) { ALOGE("Failed to allocate property set"); return -ENOMEM; @@ -489,25 +490,25 @@ int DrmDisplayCompositor::DisablePlanes(DrmDisplayComposition *display_comp) { display_comp->composition_planes(); for (DrmCompositionPlane &comp_plane : comp_planes) { DrmPlane *plane = comp_plane.plane; - ret = - drmModePropertySetAdd(pset, plane->id(), plane->crtc_property().id(), - 0) || - drmModePropertySetAdd(pset, plane->id(), plane->fb_property().id(), 0); + ret = drmModeAtomicAddProperty(pset, plane->id(), + plane->crtc_property().id(), 0) < 0 || + drmModeAtomicAddProperty(pset, plane->id(), plane->fb_property().id(), + 0) < 0; if (ret) { ALOGE("Failed to add plane %d disable to pset", plane->id()); - drmModePropertySetFree(pset); + drmModeAtomicFree(pset); return ret; } } - ret = drmModePropertySetCommit(drm_->fd(), 0, drm_, pset); + ret = drmModeAtomicCommit(drm_->fd(), pset, 0, drm_); if (ret) { ALOGE("Failed to commit pset ret=%d\n", ret); - drmModePropertySetFree(pset); + drmModeAtomicFree(pset); return ret; } - drmModePropertySetFree(pset); + drmModeAtomicFree(pset); return 0; } @@ -593,6 +594,16 @@ int DrmDisplayCompositor::PrepareFrame(DrmDisplayComposition *display_comp) { return ret; } +/* rotation property bits copied from kernel*/ +#define DRM_ROTATE_MASK 0x0f +#define DRM_ROTATE_0 0 +#define DRM_ROTATE_90 1 +#define DRM_ROTATE_180 2 +#define DRM_ROTATE_270 3 +#define DRM_REFLECT_MASK (~DRM_ROTATE_MASK) +#define DRM_REFLECT_X 4 +#define DRM_REFLECT_Y 5 + int DrmDisplayCompositor::CommitFrame(DrmDisplayComposition *display_comp, bool test_only) { ATRACE_CALL(); @@ -618,20 +629,21 @@ int DrmDisplayCompositor::CommitFrame(DrmDisplayComposition *display_comp, return -ENODEV; } - drmModePropertySetPtr pset = drmModePropertySetAlloc(); + drmModeAtomicReqPtr pset = drmModeAtomicAlloc(); if (!pset) { ALOGE("Failed to allocate property set"); return -ENOMEM; } if (mode_.needs_modeset) { - ret = drmModePropertySetAdd(pset, crtc->id(), crtc->mode_property().id(), - mode_.blob_id) || - drmModePropertySetAdd(pset, connector->id(), - connector->crtc_id_property().id(), crtc->id()); + ret = drmModeAtomicAddProperty(pset, crtc->id(), crtc->mode_property().id(), + mode_.blob_id) < 0 || + drmModeAtomicAddProperty(pset, connector->id(), + connector->crtc_id_property().id(), + crtc->id()) < 0; if (ret) { ALOGE("Failed to add blob %d to pset", mode_.blob_id); - drmModePropertySetFree(pset); + drmModeAtomicFree(pset); return ret; } } @@ -663,11 +675,14 @@ int DrmDisplayCompositor::CommitFrame(DrmDisplayComposition *display_comp, DrmHwcLayer &layer = layers[comp_plane.source_layer]; if (!test_only && layer.acquire_fence.get() >= 0) { int acquire_fence = layer.acquire_fence.get(); + int total_fence_timeout = 0; for (int i = 0; i < kAcquireWaitTries; ++i) { - ret = sync_wait(acquire_fence, kAcquireWaitTimeoutMs); + int fence_timeout = kAcquireWaitTimeoutMs * (1 << i); + total_fence_timeout += fence_timeout; + ret = sync_wait(acquire_fence, fence_timeout); if (ret) ALOGW("Acquire fence %d wait %d failed (%d). Total time %d", - acquire_fence, i, ret, (i + 1) * kAcquireWaitTimeoutMs); + acquire_fence, i, ret, total_fence_timeout); } if (ret) { ALOGE("Failed to wait for acquire %d/%d", acquire_fence, ret); @@ -701,10 +716,10 @@ int DrmDisplayCompositor::CommitFrame(DrmDisplayComposition *display_comp, // Disable the plane if there's no framebuffer if (fb_id < 0) { - ret = drmModePropertySetAdd(pset, plane->id(), - plane->crtc_property().id(), 0) || - drmModePropertySetAdd(pset, plane->id(), plane->fb_property().id(), - 0); + ret = drmModeAtomicAddProperty(pset, plane->id(), + plane->crtc_property().id(), 0) < 0 || + drmModeAtomicAddProperty(pset, plane->id(), + plane->fb_property().id(), 0) < 0; if (ret) { ALOGE("Failed to add plane %d disable to pset", plane->id()); break; @@ -726,37 +741,43 @@ int DrmDisplayCompositor::CommitFrame(DrmDisplayComposition *display_comp, break; } - ret = - drmModePropertySetAdd(pset, plane->id(), plane->crtc_property().id(), - crtc->id()) || - drmModePropertySetAdd(pset, plane->id(), plane->fb_property().id(), - fb_id) || - drmModePropertySetAdd(pset, plane->id(), plane->crtc_x_property().id(), - display_frame.left) || - drmModePropertySetAdd(pset, plane->id(), plane->crtc_y_property().id(), - display_frame.top) || - drmModePropertySetAdd(pset, plane->id(), plane->crtc_w_property().id(), - display_frame.right - display_frame.left) || - drmModePropertySetAdd(pset, plane->id(), plane->crtc_h_property().id(), - display_frame.bottom - display_frame.top) || - drmModePropertySetAdd(pset, plane->id(), plane->src_x_property().id(), - (int)(source_crop.left) << 16) || - drmModePropertySetAdd(pset, plane->id(), plane->src_y_property().id(), - (int)(source_crop.top) << 16) || - drmModePropertySetAdd(pset, plane->id(), plane->src_w_property().id(), - (int)(source_crop.right - source_crop.left) - << 16) || - drmModePropertySetAdd(pset, plane->id(), plane->src_h_property().id(), - (int)(source_crop.bottom - source_crop.top) - << 16); + ret = drmModeAtomicAddProperty(pset, plane->id(), + plane->crtc_property().id(), crtc->id()) < 0; + ret |= drmModeAtomicAddProperty(pset, plane->id(), + plane->fb_property().id(), fb_id) < 0; + ret |= drmModeAtomicAddProperty(pset, plane->id(), + plane->crtc_x_property().id(), + display_frame.left) < 0; + ret |= drmModeAtomicAddProperty(pset, plane->id(), + plane->crtc_y_property().id(), + display_frame.top) < 0; + ret |= drmModeAtomicAddProperty( + pset, plane->id(), plane->crtc_w_property().id(), + display_frame.right - display_frame.left) < 0; + ret |= drmModeAtomicAddProperty( + pset, plane->id(), plane->crtc_h_property().id(), + display_frame.bottom - display_frame.top) < 0; + ret |= drmModeAtomicAddProperty(pset, plane->id(), + plane->src_x_property().id(), + (int)(source_crop.left) << 16) < 0; + ret |= drmModeAtomicAddProperty(pset, plane->id(), + plane->src_y_property().id(), + (int)(source_crop.top) << 16) < 0; + ret |= drmModeAtomicAddProperty( + pset, plane->id(), plane->src_w_property().id(), + (int)(source_crop.right - source_crop.left) << 16) < 0; + ret |= drmModeAtomicAddProperty( + pset, plane->id(), plane->src_h_property().id(), + (int)(source_crop.bottom - source_crop.top) << 16) < 0; if (ret) { ALOGE("Failed to add plane %d to set", plane->id()); break; } if (plane->rotation_property().id()) { - ret = drmModePropertySetAdd(pset, plane->id(), - plane->rotation_property().id(), rotation); + ret = drmModeAtomicAddProperty(pset, plane->id(), + plane->rotation_property().id(), + rotation) < 0; if (ret) { ALOGE("Failed to add rotation property %d to plane %d", plane->rotation_property().id(), plane->id()); @@ -765,8 +786,9 @@ int DrmDisplayCompositor::CommitFrame(DrmDisplayComposition *display_comp, } if (plane->alpha_property().id()) { - ret = drmModePropertySetAdd(pset, plane->id(), - plane->alpha_property().id(), alpha); + ret = drmModeAtomicAddProperty(pset, plane->id(), + plane->alpha_property().id(), + alpha) < 0; if (ret) { ALOGE("Failed to add alpha property %d to plane %d", plane->alpha_property().id(), plane->id()); @@ -781,18 +803,18 @@ out: if (test_only) flags |= DRM_MODE_ATOMIC_TEST_ONLY; - ret = drmModePropertySetCommit(drm_->fd(), flags, drm_, pset); + ret = drmModeAtomicCommit(drm_->fd(), pset, flags, drm_); if (ret) { if (test_only) ALOGI("Commit test pset failed ret=%d\n", ret); else ALOGE("Failed to commit pset ret=%d\n", ret); - drmModePropertySetFree(pset); + drmModeAtomicFree(pset); return ret; } } if (pset) - drmModePropertySetFree(pset); + drmModeAtomicFree(pset); if (!test_only && mode_.needs_modeset) { ret = drm_->DestroyPropertyBlob(mode_.old_blob_id); @@ -931,16 +953,22 @@ int DrmDisplayCompositor::Composite() { // is just a test, it won't actually commit the frame. If rejected, // squash the frame into one layer and use the squashed composition ret = CommitFrame(composition.get(), true); - if (ret) { + if (ret) ALOGI("Commit test failed, squashing frame for display %d", display_); - std::unique_ptr squashed = CreateComposition(); - ret = SquashFrame(composition.get(), squashed.get()); - if (!ret) { - composition = std::move(squashed); - } else { - ALOGE("Failed to squash frame for display %d", display_); - return ret; - } + use_hw_overlays_ = !ret; + } + + // If use_hw_overlays_ is false, we can't use hardware to composite the + // frame. So squash all layers into a single composition and queue that + // instead. + if (!use_hw_overlays_) { + std::unique_ptr squashed = CreateComposition(); + ret = SquashFrame(composition.get(), squashed.get()); + if (!ret) { + composition = std::move(squashed); + } else { + ALOGE("Failed to squash frame for display %d", display_); + return ret; } } frame_worker_.QueueFrame(std::move(composition), ret);