Files

165 lines
5.0 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_H
#define MESON_DISPLAY_H
#include <cstdint>
#include <memory>
#include <unordered_map>
#include <DrmTypes.h>
#include <HwcVsyncBase.h>
#include <IComposer.h>
#include <CompositionStrategyBase.h>
#include "MesonTypes.h"
#include "BitsMap.h"
#include "MesonLayer.h"
#include "DrmCrtc.h"
#include "DrmConnector.h"
#include "DrmVideoPlane.h"
#include "MesonDisplayPipe.h"
#include "ProcessorsManager.h"
#include "VideoPipeAdapter.h"
#define DISPLAY_WIDTH_BASE 1920
#define DISPLAY_HEIGHT_BASE 1080
class DisplayThread;
class MesonEventListener;
class MesonDisplay : public HwcVsyncObserver {
public:
MesonDisplay(uint32_t display);
virtual ~MesonDisplay();
uint32_t getDisplayId() { return mDisplayId; }
/* MESON interfaces. */
public:
/* Layer related. */
virtual int createLayer(int32_t &outLayer);
virtual int destroyLayer(int32_t inLayer);
virtual int32_t setTunnelId(int32_t layer, int32_t tunnelId);
virtual int32_t setLayerIndex(int32_t layer, int32_t index);
virtual int32_t setLayerZorder(int32_t layer, int32_t zorder);
virtual int32_t setLayerSourceCrop(int32_t layerId, struct rect crop);
virtual int32_t setLayerDispFrame(int32_t layer, drm_rect_t frame);
virtual int32_t getVsyncDelayLatency(int32_t layer);
virtual int32_t setVideoDisplaytoMainplane();
virtual int32_t getUiSize(int32_t* width, int32_t* height);
virtual int32_t setLayerTransform(int32_t layer, int32_t transform);
virtual int32_t getVideoDelay(int fps);
virtual int32_t waitVBlank();
/* MesonDisplay interface */
public:
virtual int32_t initialize();
virtual void onVsync(int64_t timestamp, uint32_t vsyncPeriodNanos, int vsyncType = 0);
virtual int validateDisplay(uint32_t* outNumTypes,
uint32_t* outNumRequests);
virtual int presentDisplay(int32_t* outPresentFence);
virtual int32_t setVsync(std::shared_ptr<HwcVsyncBase> vsync);
void setLayersPresentTime();
bool handleDisplayConnection();
void releaseLayers();
void setVsyncDelayLatency(int32_t latency);
void setVideoPlaneState(int state);
bool newGameBuffer();
virtual void onFrameAvailable();
int getLayerTotal();
void registerCallback(int32_t layerId, void *context, meson_callback_t *cb);
void registerPageFlipCallBack(int32_t layerId, void *context, adpt_page_flip_callback *cb);
protected:
int32_t createV2DComposer(int idx,
std::shared_ptr<IComposer> & composer);
void getComposers(std::vector<std::shared_ptr<IComposer>> & composers);
void initLayerIdGenerator();
uint32_t createLayerId();
void destroyLayerId(uint32_t id);
bool hasVtBuffer();
/* For compose. */
int collectLayersForPresent();
int collectComposersForPresent();
int collectPlanesForPresent();
int collectCompositionStgForPresent();
protected:
uint32_t mDisplayId;
std::shared_ptr<MesonDisplayPipe> mPipe;
std::shared_ptr<VideoPipeAdapter> mPipeAdapter;
std::shared_ptr<DrmCrtc> mCrtc;
std::shared_ptr<DrmConnector> mConnector;
std::vector<std::shared_ptr<DrmVideoPlane>> mPlanes;
std::unordered_map<int, std::shared_ptr<MesonLayer>> mLayers;
std::multimap<int, std::shared_ptr<IComposer>> mComposers;
std::shared_ptr<CompositionStrategyBase> mCompositionStrategy;
std::map<uint32_t, std::shared_ptr<DrmFramebufferBase>, std::less<uint32_t>> mFbs;
/* members used in present.*/
std::vector<std::shared_ptr<MesonLayer>> mPresentLayers;
std::vector<std::shared_ptr<IComposer>> mPresentComposers;
std::vector<std::shared_ptr<DrmVideoPlane>> mPresentPlanes;
std::shared_ptr<CompositionStrategyBase> mPresentCompositionStg;
nsecs_t mVsyncTimestamp;
int32_t mDelayLatency;
std::shared_ptr<DisplayThread> mDisplayThread;
std::shared_ptr<HwcVsyncBase> mVsync;
/* layer id generate */
std::shared_ptr<BitsMap> mLayersBitmap;
int32_t mLayerSeq;
bool mDisplayToMainPlane;
bool mEnablePrimaryPlane;
std::mutex mMutex;
std::shared_ptr<ProcessorsManager> mProcessorsManager;
std::shared_ptr<MesonEventListener> mListener;
int mState = -1;
std::string mDisableValue = "";
};
class VtDisplayObserver {
public:
VtDisplayObserver(MesonDisplay* display) {
mDisplay = display;
}
virtual ~VtDisplayObserver(){}
void onFrameAvailable() {
if (mDisplay)
mDisplay->onFrameAvailable();
}
protected:
MesonDisplay* mDisplay;
};
#endif /* MESON2_DISPLAY_H */