Files
BPI-CM9-Linux/aml-comp/vendor/amlogic/meson_videoserver/display/MesonDisplayPipe.h
T

135 lines
3.4 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.
*/
#ifndef MESON_DISPLAY_PIPE_H
#define MESON_DISPLAY_PIPE_H
#include <cstdint>
#include <condition_variable>
#include <memory>
#include <mutex>
#include <unordered_map>
#include "MesonTypes.h"
#include "DrmCrtc.h"
#include "DrmConnector.h"
#include "DrmEncoder.h"
#include "DrmVideoPlane.h"
class MesonPageFlip {
public:
MesonPageFlip() : mIndex(0) {}
~MesonPageFlip() {
mFlipData.clear();
}
void pushData(meson_page_flip_data info) {
std::lock_guard<std::mutex> lock(mMutex);
mFlipData.push_back(info);
}
std::vector<meson_page_flip_data> getData() {
return mFlipData;
}
void removeData(uint64_t id) {
std::lock_guard<std::mutex> lock(mMutex);
for (auto it = mFlipData.begin(); it != mFlipData.end(); it++) {
if (it->id == id) {
mFlipData.erase(it);
return;
}
}
}
void clearData() {
mFlipData.clear();
}
void initIndex() { mIndex = 0; }
void incIndex() { mIndex++; }
void decIndex() {
mIndex--;
if (mIndex < 0)
mIndex = 0;
}
int getIndex() { return mIndex; }
public:
std::mutex mMutex;
protected:
std::vector<meson_page_flip_data> mFlipData;
std::atomic<int> mIndex;
};
class MesonDisplayPipe : public CommitObserver {
public:
MesonDisplayPipe(int dispId);
~MesonDisplayPipe();
public:
int32_t getCrtc(std::shared_ptr<DrmCrtc> & crtc);
int32_t getPlanes(std::vector<std::shared_ptr<DrmVideoPlane>> & planes);
int32_t getConnector(std::shared_ptr<DrmConnector> & connector);
int32_t getVrefresh();
void getSize(int32_t &width, int32_t &height);
void enablePrimaryPlane();
void drmPageFlipInit();
void destroyThread();
void destroyPageFlip(uint64_t id);
void onPoll();
protected:
int32_t init();
int32_t openDrmDevice();
int32_t loadDrmResources();
bool updateRefresh();
void handleEvent();
static void *PageFlipThread(void *data);
static void pageFlipHandler(int fd, uint32_t frame, uint32_t sec,
uint32_t usec, uint32_t crtc_id, void *data);
protected:
int mPipeId;
int mDrmFd;
bool mEnablePrimaryPlane;
bool mFlipThread = false;
pthread_t mThread;
bool mThreadExit = false;
drmEventContext mEvctx = { 0 };
std::vector<std::shared_ptr<MesonPageFlip>> mPageFlip;
std::mutex mMutex;
std::condition_variable mCondition;
bool needRefresh;
std::shared_ptr<DrmCrtc> mCrtc;
std::shared_ptr<DrmConnector> mConnector;
std::unordered_multimap<uint32_t, std::shared_ptr<DrmVideoPlane>> mPlanesForPipe;
std::map<uint32_t, std::shared_ptr<DrmCrtc>> mCrtcs;
std::map<uint32_t, std::shared_ptr<DrmEncoder>> mEncoders;
std::map<uint32_t, std::shared_ptr<DrmConnector>> mConnectors;
};
#endif