Files

181 lines
6.3 KiB
C++
Raw Permalink Normal View History

2026-08-13 11:28:40 +08:00
/*
* Copyright (c) 2018 Amlogic, Inc. All rights reserved.
*
* This source code is subject to the terms and conditions defined in the
* file 'LICENSE' which is part of this source code package.
*
* Description:
*/
#ifndef COMPOSITION_STRATEGY_BASE_H
#define COMPOSITION_STRATEGY_BASE_H
#include <functional>
#include <queue>
2026-08-25 10:02:36 +08:00
#include <unordered_map>
2026-08-13 11:28:40 +08:00
#include "ICompositionStrategyBase.h"
#include "MesonLog.h"
#define OSD_OUTPUT_ONE_CHANNEL 1
#define OSD_FB_BEGIN_ZORDER 65 // osd zorder: 65 - 128
#define TOP_VIDEO_FB_BEGIN_ZORDER 129 // top video zorder: 129 - 192
#define BOTTOM_VIDEO_FB_BEGIN_ZORDER 1 // bottom video zorder: 1 - 64
#define OSD_SCALER_INPUT_MAX_WIDTH (1920)
#define OSD_SCALER_INPUT_MAX_HEIGHT (1080)
#define OSD_SCALER_INPUT_FACTOR (3.0)
#define OSD_SCALER_INPUT_MARGIN (1.1)
#define DEFAULT_REFRESH_RATE (60.0f)
#define IS_FB_COMPOSED(fb) \
((fb)->getZorder() >= mMinComposerZorder && (fb)->getZorder() <= mMaxComposerZorder)
class CompositionStrategyBase : public ICompositionStrategyBase {
public:
CompositionStrategyBase();
~CompositionStrategyBase() = default;
virtual const char* getName() {return "CompositionStrategyBase";}
virtual void setup(std::vector<std::shared_ptr<DrmFramebufferBase>> & layers,
std::vector<std::shared_ptr<IComposer>> & composers,
std::vector<std::shared_ptr<HwDisplayPlaneBase>> & planes,
std::shared_ptr<HwDisplayCrtcBase> & crtc,
uint32_t flags,
float scaleValue,
drm_mode_info_t mode);
virtual void updateComposition();
virtual int decideComposition();
virtual int commit() { return 0; }
virtual int commitTunnelVideo() { return 0; }
virtual int getDisplayPair(std::list<DisplayPair> & displayPairs);
virtual void dump(std::string & dumpstr);
protected:
virtual void init();
virtual int applyCompositionFlags();
int processVideoFbs();
int processGfxFbs();
int pickoutOsdFbs();
int countComposerFbs(int &belowClientNum, int &upClientNum, int &insideClientNum);
int confirmComposerRange();
int setOsdFbs2PlanePairs();
int selectComposer();
int fillComposerFbs();
void handleOverlayVideoZorder();
int checkCommitZorder();
void handleVPUOddScaleLimit();
void handleVPUScaleLimit();
void handleVPULimit(bool video);
void handleDisplayLayerZorder();
int handleOsdComposition();
int handleOsdCompositionWithVideo();
int32_t compareFbScale(drm_rect_t & aSrc, drm_rect_t & aDst, drm_rect_t & bSrc, drm_rect_t & bDst);
int deleteFbFromVectorFbs(
std::vector<std::shared_ptr<DrmFramebufferBase>> & inputFbs,
std::shared_ptr<DrmFramebufferBase> & Fb);
int chooseVideoFbsBaseNoOverlap(
std::vector<std::shared_ptr<DrmFramebufferBase>> & inputVideoFbs,
std::vector<std::shared_ptr<DrmFramebufferBase>> & outputVideoFbs);
int chooseOneVideoFbBaseBiggestWindow(
std::vector<std::shared_ptr<DrmFramebufferBase>> & inputVideoFbs,
std::shared_ptr<DrmFramebufferBase> & outputVideoFb);
int chooseOneVideoFbBaseVideoType(
std::vector<std::shared_ptr<DrmFramebufferBase>> & inputVideoFbs,
std::shared_ptr<DrmFramebufferBase> & outputVideoFb);
int chooseOneVideoFb(
std::shared_ptr<DrmFramebufferBase> & outputVideoFb,
bool bVideoCompose);
int chooseVideoFbFromLegacySideband(
std::vector<std::shared_ptr<DrmFramebufferBase>> & sidebandFbs,
std::shared_ptr<DrmFramebufferBase> & outputVideoFb);
bool chooseOneVideoFbBasePriority(
std::vector<std::shared_ptr<DrmFramebufferBase>> & inputVideoFbs,
std::shared_ptr<DrmFramebufferBase> & outputVideoFb);
bool checkAndHandle4Mosaic(uint32_t videoZorder);
void checkLayerValidate(std::shared_ptr<DrmFramebufferBase> & fb);
void fillDebugInfoStr();
bool hasPlaneSupport(std::shared_ptr<DrmFramebufferBase> fb);
void decidePlaneAssignment();
bool tryAllocate(int idx, const std::vector<std::shared_ptr<DrmFramebufferBase>>& layers, std::vector<std::shared_ptr<HwDisplayPlaneBase>>& planes,
std::vector<bool>& bUsed, std::unordered_map<uint32_t, uint32_t>& results);
protected:
/* Input Flags from SF */
bool mHDRMode;
bool mHideSecureLayer;
bool mForceClientComposer;
bool mForceVideoComposer;
bool mMosaicEnabled;
bool m4Mosaic;
bool mHideVideoForHdcpDev;
/* Input Fbs from SF, min zorder at begin, max zorder at end. */
std::map<uint32_t, std::shared_ptr<DrmFramebufferBase>, std::less<uint32_t>> mFramebuffers;
/*reffb is the fb used to setup the osddisplayframe.*/
std::shared_ptr<DrmFramebufferBase> mDisplayRefFb;
display_zoom_info_t mOsdDisplayFrame;
/* Composer */
std::shared_ptr<IComposer> mDummyComposer;
std::shared_ptr<IComposer> mClientComposer;
std::vector<std::shared_ptr<IComposer>> mVideoComposers;
std::vector<std::shared_ptr<IComposer>> mOtherComposers;
/* Get display planes from DisplayManager */
std::vector<std::shared_ptr<HwDisplayPlaneBase>> mOsdPlanes;
std::vector<std::shared_ptr<HwDisplayPlaneBase>> mHwcVideoPlanes; // Future VIDEO support : 2 HwcVideoPlane
std::vector<std::shared_ptr<HwDisplayPlaneBase>> mOtherPlanes;
/* Use for composer */
std::shared_ptr<IComposer> mComposer; // Handle composer Fbs
std::vector<std::shared_ptr<DrmFramebufferBase>> mOverlayFbs;
std::vector<std::shared_ptr<DrmFramebufferBase>> mComposerFbs; // Save Fbs that should be composered
std::vector<std::shared_ptr<DrmFramebufferBase>> mVideoComposerFbs;
/*crtc*/
std::shared_ptr<HwDisplayCrtcBase> mCrtc;
drm_mode_info_t mDisplayMode;
std::list<DisplayPair> mDisplayPairs;
bool mHaveClient;
bool mInsideVideoFbsFlag; // Has VIDEO between different OSD ui layers.
uint32_t mMinComposerZorder;
uint32_t mMaxComposerZorder;
uint32_t mMinVideoZorder;
uint32_t mMaxVideoZorder;
int mOsdPlaneNum;
int mVideoPlaneNum;
int mVideoComposerNum;
uint32_t mCompositionFlag;
float mScaleValue;
bool mIsSideBandDisable;
bool mIsVideoComposerV2D;
// Layer Zorder -> Plane ID
std::unordered_map<uint32_t, uint32_t> mLayerAssignment;
};
#endif/*COMPOSITION_STRATEGY_BASE_H*/