You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
159 lines
3.6 KiB
159 lines
3.6 KiB
/*
|
|
* Copyright (c) Hisilicon Technologies Co., Ltd. 2021-2023. All rights reserved.
|
|
* Description: ImageTexture for input
|
|
* Author: Hisilicon
|
|
* Created: 2021.04.16
|
|
*/
|
|
|
|
#ifndef IMAGEKIT_MAGIC_TEXTURE_H
|
|
#define IMAGEKIT_MAGIC_TEXTURE_H
|
|
|
|
#include <atomic>
|
|
|
|
#include "ImageBuf.h"
|
|
|
|
namespace PhoenixImage {
|
|
class EGLConsumer;
|
|
class BufClient;
|
|
class BufItem;
|
|
|
|
/**
|
|
* @brief Image texture class. .
|
|
*/
|
|
class ImageTexture {
|
|
public:
|
|
/**
|
|
* @brief ImageTexture constructor, geneate texture id internal.
|
|
* @param [in] The ImageTexture buffer provider.
|
|
*/
|
|
ImageTexture(BufHolder *buFHolder, int32_t width, int32_t height);
|
|
|
|
/**
|
|
* @brief ImageTexture constructor, using external texture id.
|
|
* @param [in] The ImageTexture buffer provider.
|
|
*/
|
|
ImageTexture(uint32_t tex, uint32_t textureTarget, int32_t width, int32_t height);
|
|
|
|
/**
|
|
* @brief ImageTexture destructor.
|
|
*/
|
|
~ImageTexture();
|
|
|
|
/**
|
|
* @brief acquires the most recently putted buffer by BufHolder, and sets the image contents of the target texture
|
|
* to it .
|
|
*/
|
|
int32_t UpdateTexureImage();
|
|
|
|
int32_t GetWidth();
|
|
|
|
int32_t GetHeight();
|
|
|
|
uint32_t GetTextureName();
|
|
|
|
uint32_t GetTextureTarget();
|
|
|
|
BufHolder* GetBufHolder();
|
|
|
|
/**
|
|
* @brief increase reference count_ of the object.
|
|
*/
|
|
void IncRef(void)
|
|
{
|
|
count_.fetch_add(1, std::memory_order_relaxed);
|
|
}
|
|
|
|
/**
|
|
* @brief decrease reference count_ of the object, the object will be freed if reference count_ is 0.
|
|
*/
|
|
size_t DecRef(void)
|
|
{
|
|
return count_.fetch_sub(1, std::memory_order_acq_rel);
|
|
}
|
|
|
|
bool GetRGBATexForced();
|
|
int32_t SetRGBATexForced(bool flag);
|
|
|
|
/**
|
|
* @brief set and get whther handle y and uv separatly for currrent texture or not .
|
|
*/
|
|
bool GetHandleYUVSeparatly();
|
|
int32_t SetHandleYUVSeparatly(bool flag);
|
|
|
|
/**
|
|
* @brief set and get whther handle as y texture for currrent texture or not .
|
|
*/
|
|
bool GetIsHandleY();
|
|
int32_t SetIsHandleY(bool flag);
|
|
|
|
/**
|
|
* @brief set and get whther handle as uv texture for currrent texture or not .
|
|
*/
|
|
bool GetIsHandleUV();
|
|
int32_t SetIsHandleUV(bool flag);
|
|
protected:
|
|
/**
|
|
* @brief Called by UpdateTexImage to get a new buffer.
|
|
*/
|
|
int32_t AcquireBuffer(BufItem *item);
|
|
|
|
/**
|
|
* @brief Called by eglConsumer_ to release last buffer.
|
|
*/
|
|
int32_t ReleaseBuffer(int32_t slot);
|
|
|
|
/**
|
|
* @brief free the slot when the consumer desctroyed.
|
|
*/
|
|
int32_t FreeBuffer(int32_t slot);
|
|
|
|
/**
|
|
* @brief Add release fence fd for current buffer.
|
|
*/
|
|
int32_t AddReleaseFenceFd(int32_t fd);
|
|
|
|
struct Slot {
|
|
ImageColorBuffer *colorBuffer_;
|
|
int32_t fenceFd_;
|
|
uint64_t frameNumber_;
|
|
};
|
|
|
|
Slot slots_[MAX_BUF_SLOTS];
|
|
|
|
mutable std::mutex mutex_;
|
|
|
|
std::unique_ptr<BufClient> bufClient_;
|
|
BufHolder *bufHolder_;
|
|
|
|
uint32_t texName_;
|
|
uint32_t texTarget_;
|
|
|
|
/* curSlot_ is the current slot index. */
|
|
int32_t curSlot_;
|
|
|
|
/* curFenceFd_ is the fence fd which comes from current slot. */
|
|
int32_t curFenceFd_;
|
|
|
|
/* curFrameNumber_ is the frame number . */
|
|
int32_t curFrameNumber_;
|
|
|
|
int32_t width_;
|
|
int32_t height_;
|
|
|
|
bool needFreeTexName_;
|
|
|
|
/* eglConsumer_ is the EGL client consumer for the texture */
|
|
std::unique_ptr<EGLConsumer> eglConsumer_;
|
|
friend class EGLConsumer;
|
|
|
|
private:
|
|
mutable std::atomic_size_t count_;
|
|
bool useRGBATexForced_;
|
|
bool handleYUVSeparatly_;
|
|
bool handleIsY_;
|
|
bool handleIsUV_;
|
|
};
|
|
} /* namespace PhoenixImage */
|
|
|
|
#endif
|