diff options
author | Robert Foss <robert.foss@collabora.com> | 2017-02-20 17:43:57 -0500 |
---|---|---|
committer | Robert Foss <robert.foss@collabora.com> | 2017-03-24 18:32:42 -0400 |
commit | eb9cae14dda568b16b40f022f4467f2ee1d9b6e0 (patch) | |
tree | d312f3653e3da31ac8c8e5b6bcc562d62b156a02 | |
parent | 1498f452480378c17ec5ec6a4abc4f0f26edfa66 (diff) | |
download | drm_hwcomposer-eb9cae14dda568b16b40f022f4467f2ee1d9b6e0.tar.gz drm_hwcomposer-eb9cae14dda568b16b40f022f4467f2ee1d9b6e0.tar.xz |
drm_hwcomposer: Remove vsyncworkerhwc2_fence_v4_vsyncworkerhwc2_fence_v4
Removes vsyncworker since it is no longer used.
BUG=None
TEST=make
Change-Id: Iddfca031c88d39dc710980ba78f4cd5ebe9f0d7a
Signed-off-by: Robert Foss <robert.foss@collabora.com>
-rw-r--r-- | Android.mk | 1 | ||||
-rw-r--r-- | drmhwctwo.cpp | 60 | ||||
-rw-r--r-- | drmhwctwo.h | 7 | ||||
-rw-r--r-- | vsyncworker.cpp | 202 | ||||
-rw-r--r-- | vsyncworker.h | 62 |
5 files changed, 41 insertions, 291 deletions
@@ -57,7 +57,6 @@ LOCAL_SRC_FILES := \ platformnv.cpp \ separate_rects.cpp \ virtualcompositorworker.cpp \ - vsyncworker.cpp \ worker.cpp LOCAL_CPPFLAGS += \ diff --git a/drmhwctwo.cpp b/drmhwctwo.cpp index 45511c6..c430cc8 100644 --- a/drmhwctwo.cpp +++ b/drmhwctwo.cpp @@ -21,7 +21,6 @@ #include "drmhwcomposer.h" #include "drmhwctwo.h" #include "platform.h" -#include "vsyncworker.h" #include <inttypes.h> #include <string> @@ -33,20 +32,26 @@ namespace android { -class DrmVsyncCallback : public VsyncCallback { - public: - DrmVsyncCallback(hwc2_callback_data_t data, hwc2_function_pointer_t hook) - : data_(data), hook_(hook) { - } +class VBlankEventHandler : public DrmEventHandler { + public: + VBlankEventHandler(hwc2_function_pointer_t func, + hwc2_callback_data_t data, + hwc2_display_t display) : + func_(func), + data_(data), + display_(display) { + + } - void Callback(int display, int64_t timestamp) { - auto hook = reinterpret_cast<HWC2_PFN_VSYNC>(hook_); - hook(data_, display, timestamp); + void HandleEvent(uint64_t timestamp_us) { + auto func = reinterpret_cast<HWC2_PFN_VSYNC>(func_); + func(data_, display_, timestamp_us); } - private: - hwc2_callback_data_t data_; - hwc2_function_pointer_t hook_; + private: + hwc2_function_pointer_t func_; + hwc2_callback_data_t data_; + hwc2_display_t display_; }; DrmHwcTwo::DrmHwcTwo() { @@ -149,7 +154,7 @@ HWC2::Error DrmHwcTwo::RegisterCallback(int32_t descriptor, case HWC2::Callback::Vsync: { for (std::pair<const hwc2_display_t, DrmHwcTwo::HwcDisplay> &d : displays_) - d.second.RegisterVsyncCallback(data, function); + d.second.RegisterVsyncCallback(function, data, d.first); break; } default: @@ -225,7 +230,6 @@ HWC2::Error DrmHwcTwo::HwcDisplay::Init(std::vector<DrmPlane *> *planes) { if (err != HWC2::Error::None) return err; - ret = vsync_worker_.Init(drm_, display); if (ret) { ALOGE("Failed to create event worker for d=%d %d\n", display, ret); return HWC2::Error::BadDisplay; @@ -234,15 +238,20 @@ HWC2::Error DrmHwcTwo::HwcDisplay::Init(std::vector<DrmPlane *> *planes) { return SetActiveConfig(default_config); } -HWC2::Error DrmHwcTwo::HwcDisplay::RegisterVsyncCallback( - hwc2_callback_data_t data, hwc2_function_pointer_t func) { +HWC2::Error DrmHwcTwo::HwcDisplay::RegisterVsyncCallback(hwc2_function_pointer_t func, + hwc2_callback_data_t data, + hwc2_display_t display) { supported(__func__); - auto callback = std::make_shared<DrmVsyncCallback>(data, func); - int ret = vsync_worker_.RegisterCallback(std::move(callback)); - if (ret) { - ALOGE("Failed to register callback d=%" PRIu64 " ret=%d", handle_, ret); - return HWC2::Error::BadDisplay; + + auto event_listener = drm_->event_listener(); + if (!event_listener) { + ALOGE("Event listener not initialized"); + return HWC2::Error::NoResources; } + + auto handler = std::make_shared<VBlankEventHandler>(func, data, display); + event_listener->RegisterVBlankHandler(handler); + return HWC2::Error::None; } @@ -685,7 +694,14 @@ HWC2::Error DrmHwcTwo::HwcDisplay::SetPowerMode(int32_t mode_in) { HWC2::Error DrmHwcTwo::HwcDisplay::SetVsyncEnabled(int32_t enabled) { supported(__func__); - vsync_worker_.VSyncControl(enabled); + + auto event_listener = drm_->event_listener(); + if (!event_listener) { + ALOGE("Event listener not initialized"); + return HWC2::Error::NoResources; + } + + event_listener->SetVBlankHandlerEnabled(enabled); return HWC2::Error::None; } diff --git a/drmhwctwo.h b/drmhwctwo.h index 2d50b7e..27773f3 100644 --- a/drmhwctwo.h +++ b/drmhwctwo.h @@ -18,7 +18,6 @@ #include "drmhwcomposer.h" #include "drmresources.h" #include "platform.h" -#include "vsyncworker.h" #include <hardware/hwcomposer2.h> @@ -141,8 +140,9 @@ class DrmHwcTwo : public hwc2_device_t { HwcDisplay(const HwcDisplay &) = delete; HWC2::Error Init(std::vector<DrmPlane *> *planes); - HWC2::Error RegisterVsyncCallback(hwc2_callback_data_t data, - hwc2_function_pointer_t func); + HWC2::Error RegisterVsyncCallback(hwc2_function_pointer_t func, + hwc2_callback_data_t data, + hwc2_display_t display); // HWC Hooks HWC2::Error AcceptDisplayChanges(); @@ -198,7 +198,6 @@ class DrmHwcTwo : public hwc2_device_t { std::vector<DrmPlane *> overlay_planes_; std::vector<DrmPlane *> cursor_planes_; - VSyncWorker vsync_worker_; DrmConnector *connector_ = NULL; DrmCrtc *crtc_ = NULL; hwc2_display_t handle_; diff --git a/vsyncworker.cpp b/vsyncworker.cpp deleted file mode 100644 index cc9c96b..0000000 --- a/vsyncworker.cpp +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Copyright (C) 2015 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "hwc-vsync-worker" - -#include "drmresources.h" -#include "vsyncworker.h" -#include "worker.h" - -#include <map> -#include <stdlib.h> -#include <time.h> -#include <xf86drm.h> -#include <xf86drmMode.h> - -#include <cutils/log.h> -#include <hardware/hardware.h> - -namespace android { - -VSyncWorker::VSyncWorker() - : Worker("vsync", HAL_PRIORITY_URGENT_DISPLAY), - drm_(NULL), - display_(-1), - last_timestamp_(-1) { -} - -VSyncWorker::~VSyncWorker() { -} - -int VSyncWorker::Init(DrmResources *drm, int display) { - drm_ = drm; - display_ = display; - - return InitWorker(); -} - -int VSyncWorker::RegisterCallback(std::shared_ptr<VsyncCallback> callback) { - int ret = Lock(); - if (ret) { - ALOGE("Failed to lock vsync worker lock %d\n", ret); - return ret; - } - - callback_ = callback; - - ret = Unlock(); - if (ret) { - ALOGE("Failed to unlock vsync worker lock %d\n", ret); - return ret; - } - return 0; -} - -int VSyncWorker::VSyncControl(bool enabled) { - int ret = Lock(); - if (ret) { - ALOGE("Failed to lock vsync worker lock %d\n", ret); - return ret; - } - - enabled_ = enabled; - last_timestamp_ = -1; - int signal_ret = SignalLocked(); - - ret = Unlock(); - if (ret) { - ALOGE("Failed to unlock vsync worker lock %d\n", ret); - return ret; - } - - return signal_ret; -} - -/* - * Returns the timestamp of the next vsync in phase with last_timestamp_. - * For example: - * last_timestamp_ = 137 - * frame_ns = 50 - * current = 683 - * - * ret = (50 * ((683 - 137)/50 + 1)) + 137 - * ret = 687 - * - * Thus, we must sleep until timestamp 687 to maintain phase with the last - * timestamp. - */ -int64_t VSyncWorker::GetPhasedVSync(int64_t frame_ns, int64_t current) { - if (last_timestamp_ < 0) - return current + frame_ns; - - return frame_ns * ((current - last_timestamp_) / frame_ns + 1) + - last_timestamp_; -} - -static const int64_t kOneSecondNs = 1 * 1000 * 1000 * 1000; - -int VSyncWorker::SyntheticWaitVBlank(int64_t *timestamp) { - struct timespec vsync; - int ret = clock_gettime(CLOCK_MONOTONIC, &vsync); - - float refresh = 60.0f; // Default to 60Hz refresh rate - DrmConnector *conn = drm_->GetConnectorForDisplay(display_); - if (conn && conn->active_mode().v_refresh() != 0.0f) - refresh = conn->active_mode().v_refresh(); - else - ALOGW("Vsync worker active with conn=%p refresh=%f\n", conn, - conn ? conn->active_mode().v_refresh() : 0.0f); - - int64_t phased_timestamp = GetPhasedVSync( - kOneSecondNs / refresh, vsync.tv_sec * kOneSecondNs + vsync.tv_nsec); - vsync.tv_sec = phased_timestamp / kOneSecondNs; - vsync.tv_nsec = phased_timestamp - (vsync.tv_sec * kOneSecondNs); - do { - ret = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &vsync, NULL); - } while (ret == -1 && errno == EINTR); - if (ret) - return ret; - - *timestamp = (int64_t)vsync.tv_sec * kOneSecondNs + (int64_t)vsync.tv_nsec; - return 0; -} - -void VSyncWorker::Routine() { - int ret = Lock(); - if (ret) { - ALOGE("Failed to lock worker %d", ret); - return; - } - - if (!enabled_) { - ret = WaitForSignalOrExitLocked(); - if (ret == -EINTR) { - return; - } - } - - bool enabled = enabled_; - int display = display_; - std::shared_ptr<VsyncCallback> callback(callback_); - - ret = Unlock(); - if (ret) { - ALOGE("Failed to unlock worker %d", ret); - } - - if (!enabled) - return; - - DrmCrtc *crtc = drm_->GetCrtcForDisplay(display); - if (!crtc) { - ALOGE("Failed to get crtc for display"); - return; - } - uint32_t high_crtc = (crtc->pipe() << DRM_VBLANK_HIGH_CRTC_SHIFT); - - drmVBlank vblank; - memset(&vblank, 0, sizeof(vblank)); - vblank.request.type = (drmVBlankSeqType)( - DRM_VBLANK_RELATIVE | (high_crtc & DRM_VBLANK_HIGH_CRTC_MASK)); - vblank.request.sequence = 1; - - int64_t timestamp; - ret = drmWaitVBlank(drm_->fd(), &vblank); - if (ret == -EINTR) { - return; - } else if (ret) { - ret = SyntheticWaitVBlank(×tamp); - if (ret) - return; - } else { - timestamp = (int64_t)vblank.reply.tval_sec * kOneSecondNs + - (int64_t)vblank.reply.tval_usec * 1000; - } - - /* - * There's a race here where a change in callback_ will not take effect until - * the next subsequent requested vsync. This is unavoidable since we can't - * call the vsync hook while holding the thread lock. - * - * We could shorten the race window by caching callback_ right before calling - * the hook. However, in practice, callback_ is only updated once, so it's not - * worth the overhead. - */ - if (callback) - callback->Callback(display, timestamp); - last_timestamp_ = timestamp; -} -} diff --git a/vsyncworker.h b/vsyncworker.h deleted file mode 100644 index fcff6cb..0000000 --- a/vsyncworker.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2015 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ANDROID_EVENT_WORKER_H_ -#define ANDROID_EVENT_WORKER_H_ - -#include "drmresources.h" -#include "worker.h" - -#include <map> -#include <stdint.h> - -#include <hardware/hardware.h> -#include <hardware/hwcomposer.h> - -namespace android { - -class VSyncWorker : public Worker { - public: - VSyncWorker(); - ~VSyncWorker() override; - - int Init(DrmResources *drm, int display); - int RegisterCallback(std::shared_ptr<VsyncCallback> callback); - - int VSyncControl(bool enabled); - - protected: - void InitRoutine(){}; - void Routine() override; - - private: - int64_t GetPhasedVSync(int64_t frame_ns, int64_t current); - int SyntheticWaitVBlank(int64_t *timestamp); - - DrmResources *drm_; - - // shared_ptr since we need to use this outside of the thread lock (to - // actually call the hook) and we don't want the memory freed until we're - // done - std::shared_ptr<VsyncCallback> callback_ = NULL; - - int display_; - bool enabled_; - int64_t last_timestamp_; -}; -} - -#endif |