/* * 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 #include #include #include #include #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 lock(mMutex); mFlipData.push_back(info); } std::vector getData() { return mFlipData; } void removeData(uint64_t id) { std::lock_guard 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 mFlipData; std::atomic mIndex; }; class MesonDisplayPipe : public CommitObserver { public: MesonDisplayPipe(int dispId); ~MesonDisplayPipe(); public: int32_t getCrtc(std::shared_ptr & crtc); int32_t getPlanes(std::vector> & planes); int32_t getConnector(std::shared_ptr & 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> mPageFlip; std::mutex mMutex; std::condition_variable mCondition; bool needRefresh; std::shared_ptr mCrtc; std::shared_ptr mConnector; std::unordered_multimap> mPlanesForPipe; std::map> mCrtcs; std::map> mEncoders; std::map> mConnectors; }; #endif