65 lines
1.7 KiB
C++
65 lines
1.7 KiB
C++
/*
|
|
* Copyright (C) 2024 Amlogic Corporation.
|
|
*
|
|
* 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.
|
|
*/
|
|
|
|
#include "DrmCrtc.h"
|
|
#include "DispAdptLog.h"
|
|
|
|
DrmCrtc::DrmCrtc(int drmFd, drmModeCrtcPtr p, uint32_t pipe)
|
|
: mDrmFd(drmFd),
|
|
mId(p->crtc_id),
|
|
mPipe(pipe)
|
|
{
|
|
}
|
|
|
|
int32_t DrmCrtc::waitTime(int clock, nsecs_t timeout)
|
|
{
|
|
struct timespec next = {0, 0};
|
|
|
|
clock_gettime(clock, &next);
|
|
|
|
next.tv_sec += timeout / 1000000000LL;
|
|
next.tv_nsec += timeout % 1000000000LL;
|
|
if (next.tv_nsec > 1000000000LL) {
|
|
next.tv_sec++;
|
|
next.tv_nsec -= 1000000000LL;
|
|
}
|
|
|
|
int err;
|
|
do {
|
|
err = clock_nanosleep(clock, TIMER_ABSTIME, &next, NULL);
|
|
} while (err == EINTR);
|
|
|
|
return err;
|
|
}
|
|
|
|
int32_t DrmCrtc::waitVBlank(nsecs_t & timestamp)
|
|
{
|
|
uint32_t reqType = DRM_VBLANK_RELATIVE | (mPipe == 0 ? 0 : (1 << mPipe));
|
|
|
|
drmVBlank vbl;
|
|
vbl.request.type = (drmVBlankSeqType)reqType;
|
|
vbl.request.sequence = 1;
|
|
int32_t ret = drmWaitVBlank(mDrmFd, &vbl);
|
|
if (!ret) {
|
|
timestamp = vbl.reply.tval_sec * 1000000000LL + vbl.reply.tval_usec *1000LL;
|
|
} else {
|
|
DISPLAY_LOGD("waitVBlank failed crtc[%d]ret[%d]", mId, ret);
|
|
ret = waitTime(CLOCK_MONOTONIC, 16000000);
|
|
}
|
|
return ret;
|
|
}
|