|
|
/*
|
|
|
* Copyright (c) Hisilicon Technologies Co., Ltd. 2019-2020. All rights reserved.
|
|
|
* Description: DolGLDrawSurface
|
|
|
* Author:
|
|
|
* Create: 2019-08-22
|
|
|
*/
|
|
|
|
|
|
#ifndef DOL_GL_DRAW_SURFACE_H
|
|
|
#define DOL_GL_DRAW_SURFACE_H
|
|
|
|
|
|
#include "GLDrawThread.h"
|
|
|
|
|
|
namespace dolgles {
|
|
|
// DolGLES function
|
|
|
#define DOL_ENDABLE_DRAW_TEXT ENDABLE_DRAW_TEXT
|
|
|
#define DOL_ENDABLE_BLIT ENDABLE_BLIT
|
|
|
#define DOL_ENDABLE_DISPLAY_BITMAP ENDABLE_DISPLAY_BITMAP
|
|
|
#define DOL_ENDABLE_DRAW_RECT ENDABLE_DRAW_RECT
|
|
|
#define DOL_ENDABLE_DISPLAY_FBO ENDABLE_DISPLAY_FBO
|
|
|
#define DOL_ENDABLE_FBO ENDABLE_FBO
|
|
|
#define DOL_ENDABLE_DRAW_ROUND ENDABLE_DRAW_ROUND
|
|
|
|
|
|
struct TagDolRectInfo {
|
|
|
EGL_U32 x;
|
|
|
EGL_U32 y;
|
|
|
EGL_U32 width;
|
|
|
EGL_U32 height;
|
|
|
};
|
|
|
|
|
|
using DolRectInfo = TagDolRectInfo;
|
|
|
|
|
|
struct TagDolRoundInfo {
|
|
|
EGL_U32 x;
|
|
|
EGL_U32 y;
|
|
|
EGL_U32 rw; // oval radius of horizontal axle
|
|
|
EGL_U32 rh; // oval radius of vertical axle
|
|
|
};
|
|
|
|
|
|
using DolRoundInfo = TagDolRoundInfo;
|
|
|
|
|
|
struct TagDolBlitInfo {
|
|
|
EGL_U32 srcFBO;
|
|
|
EGL_U32 dstFBO;
|
|
|
DolRectInfo srcRect;
|
|
|
DolRectInfo dstRect;
|
|
|
};
|
|
|
|
|
|
using DolBlitInfo = TagDolBlitInfo;
|
|
|
|
|
|
struct TagDolColorRGBA {
|
|
|
EGL_U8 red;
|
|
|
EGL_U8 green;
|
|
|
EGL_U8 blue;
|
|
|
EGL_U8 alpha;
|
|
|
};
|
|
|
|
|
|
using DolColorRGBA = TagDolColorRGBA;
|
|
|
|
|
|
struct TagDolTextInfo {
|
|
|
const EGL_CHAR16 *text;
|
|
|
EGL_U32 textLen;
|
|
|
DolColorRGBA fgColor;
|
|
|
DolColorRGBA bgColor;
|
|
|
EGL_U8 justify;
|
|
|
EGL_U32 fontSize;
|
|
|
bool isBold;
|
|
|
bool isUnderLine;
|
|
|
bool isItalic;
|
|
|
};
|
|
|
|
|
|
using DolTextInfo = TagDolTextInfo;
|
|
|
|
|
|
struct TagDolBitmapInfo {
|
|
|
void *bitmap;
|
|
|
EGL_S32 format;
|
|
|
DolRectInfo srcRect;
|
|
|
DolRectInfo dstRect;
|
|
|
};
|
|
|
|
|
|
using DolBitmapInfo = TagDolBitmapInfo;
|
|
|
|
|
|
enum {
|
|
|
DOL_NO_ERROR = 0,
|
|
|
// EGL create context error
|
|
|
DOL_EGL_GET_DISPLAY_FAIL = 1,
|
|
|
DOL_EGL_INIT_FAIL = 2,
|
|
|
DOL_EGL_CHOOSE_CONFIG_FAIL = 3,
|
|
|
DOL_EGL_CREATE_CONTEXT_FAIL = 4,
|
|
|
DOL_EGL_CREATE_WINDOW_FAIL = 5,
|
|
|
DOL_EGL_NO_INIT_SURFACE = 6,
|
|
|
// create FBO error
|
|
|
DOL_FRAMEBUFFER_COMPLETE = 10,
|
|
|
DOL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT = 11,
|
|
|
DOL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT = 12,
|
|
|
DOL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS = 13,
|
|
|
DOL_FRAMEBUFFER_UNSUPPORTED = 14,
|
|
|
DOL_FRAMEBUFFER_NUM_IS_MAX = 15,
|
|
|
DOL_FRAMEBUFFER_INVALID = 16,
|
|
|
// GL error
|
|
|
DOL_CREATE_SHADER_PROGRAM_FAIL = 20,
|
|
|
DOL_CREATE_TEXTURE_FAIL = 21,
|
|
|
// Freetype error
|
|
|
DOL_FREETYPE_INIT_FAIL = 30,
|
|
|
DOL_FREETYPE_NEW_FACE_FALI = 31,
|
|
|
DOL_FREETYPE_CALCULATE_TEXTURE_SIZE_FAIL = 32,
|
|
|
|
|
|
DOL_DRAW_CMD_QUEUE_IS_EMPTY = 50,
|
|
|
|
|
|
DOL_UNKNOWN_ERROR = 100,
|
|
|
DOL_INVALID_PARAM = 101,
|
|
|
DOL_NO_INIT_GLES = 102,
|
|
|
DOL_NULL_POINTER_ERROR = 103
|
|
|
};
|
|
|
|
|
|
typedef enum {
|
|
|
CAPTION_OSD_PF_CLUT8 = 0,
|
|
|
/* *<Palette */ /* CNcomment/:调色板 */
|
|
|
CAPTION_OSD_PF_CLUT1,
|
|
|
CAPTION_OSD_PF_CLUT4,
|
|
|
CAPTION_OSD_PF_4444,
|
|
|
/* *<Each pixel occupies 16 bits, and the A/R/G/B components each occupies 4 bits. */
|
|
|
/* CNcomment/:一个像素占16bit,ARGB每分量占4bit, */
|
|
|
CAPTION_OSD_PF_0444,
|
|
|
/* *<Each pixel occupies 16 bits, and the A/R/G/B components each occupies 4 bits. */
|
|
|
/* CNcomment/:一个像素占16bit,ARGB每分量占4bit,, A分量不起作用 */
|
|
|
CAPTION_OSD_PF_1555,
|
|
|
/* *<Each pixel occupies 16 bits, the R/G/B components each occupies 5 bits, and the A component occupies 1 bit. */
|
|
|
/* CNcomment/:一个像素占16bit,RGB每分量占5bit,A分量1bit, */
|
|
|
CAPTION_OSD_PF_0555,
|
|
|
/* *<Each pixel occupies 16 bits, the R/G/B components each occupies 5 bits, and the A component occupies 1 bit. */
|
|
|
/* CNcomment/:一个像素占16bit,RGB每分量占5bit,A分量1bit,, A分量不起作用 */
|
|
|
CAPTION_OSD_PF_565,
|
|
|
/* *<Each pixel occupies 16 bits, and the R/G/B components each occupies 5 bits, 6 bits, and 5 bits respectively. */
|
|
|
/* CNcomment/:一个像素占16bit,RGB每分量分别占5bit、6bit和5bit, */
|
|
|
CAPTION_OSD_PF_8565,
|
|
|
/* *<Each pixel occupies 24 bits,
|
|
|
and the A/R/G/B components each occupies 8 bits, 5 bits, 6 bits, and 5 bits respectively. */
|
|
|
/* CNcomment/:一个像素占24bit,ARGB每分量分别占8bit, 5bit、6bit和5bit */
|
|
|
CAPTION_OSD_PF_8888,
|
|
|
/* *<Each pixel occupies 32 bits, and the A/R/G/B components each occupies 8 bits. */
|
|
|
/* CNcomment/:一个像素占32bit,ARGB每分量占8bit, */
|
|
|
CAPTION_OSD_PF_0888,
|
|
|
/* *<Each pixel occupies 24 bits, and the A/R/G/B components each occupies 8 bits. */
|
|
|
/* CNcomment/:一个像素占24bit,ARGB每分量占8bit,,A分量不起作用 */
|
|
|
CAPTION_OSD_PF_YUV400,
|
|
|
/* *<Semi-planar YUV 400 format */ /* CNcomment/:semi-planar YUV 400格式 */
|
|
|
CAPTION_OSD_PF_YUV420,
|
|
|
/* *<Semi-planar YUV 420 format */ /* CNcomment/:semi-planar YUV 420格式 */
|
|
|
CAPTION_OSD_PF_YUV422,
|
|
|
/* *<Semi-planar YUV 422 format and horizontal sampling format */
|
|
|
/* CNcomment/:semi-planar YUV 422格式 水平采样格式 */
|
|
|
CAPTION_OSD_PF_YUV422_V,
|
|
|
/* *<Semi-planar YUV 422 format and vertical sampling format */
|
|
|
/* CNcomment/:semi-planar YUV 422格式 垂直采样格式 */
|
|
|
CAPTION_OSD_PF_YUV444,
|
|
|
/* *<Semi-planar YUV 444 format */ /* CNcomment/:semi-planar YUV 444格式 */
|
|
|
|
|
|
CAPTION_OSD_PF_A1,
|
|
|
CAPTION_OSD_PF_A8,
|
|
|
|
|
|
CAPTION_OSD_PF_YUV888,
|
|
|
CAPTION_OSD_PF_YUV8888,
|
|
|
CAPTION_OSD_PF_RLE8,
|
|
|
CAPTION_OSD_PF_BUTT
|
|
|
} CAPTION_OSD_PF_E;
|
|
|
|
|
|
// EGL context and opengles drawing need to be in the same thread,
|
|
|
// otherwise drawing is invalid
|
|
|
class DolGLDrawSurface {
|
|
|
public:
|
|
|
DolGLDrawSurface();
|
|
|
~DolGLDrawSurface();
|
|
|
|
|
|
// Create draw thread and gles conext
|
|
|
EGL_S32 DolCreateGLContext();
|
|
|
|
|
|
// Destory gles conext and draw thread
|
|
|
EGL_S32 DolDestoryGLContext();
|
|
|
|
|
|
// Init drawing environment
|
|
|
EGL_S32 Init(EGL_U32 enable);
|
|
|
|
|
|
// Create eglsurface and connect window surface
|
|
|
EGL_S32 DolConnectWindowSurface(EGLNativeWindowType nativeWindow);
|
|
|
|
|
|
/*
|
|
|
* Feature: create framebuffer object
|
|
|
* Parameter: width and height
|
|
|
* return: FrameBuffObject
|
|
|
*/
|
|
|
EGL_S32 DolCreateGLFBO(EGL_U32 &fboHandleIndex, EGL_U32 width, EGL_U32 height, EGL_S32 format);
|
|
|
|
|
|
// Release FBO
|
|
|
EGL_S32 DolDestoryGLFBO(EGL_U32 fboHandleIndex);
|
|
|
|
|
|
// Clear FBO
|
|
|
EGL_S32 DolClearGLFBO(EGL_U32 fboHandleIndex);
|
|
|
|
|
|
// Display FBO
|
|
|
EGL_S32 DolDisplayFBO(EGL_U32 fboHandleIndex, const DolRectInfo &srcRect, const DolRectInfo &dstRect);
|
|
|
|
|
|
// Source rect crop or move to tagert FBO rect
|
|
|
EGL_S32 DolBlit(const DolBlitInfo &blitInfo);
|
|
|
|
|
|
// Draw text on framebuffer object
|
|
|
EGL_S32 DolDrawText(EGL_U32 fboHandleIndex, const DolTextInfo &textInfo, const DolRectInfo &rect);
|
|
|
|
|
|
// Draw bitmap on framebuffer object
|
|
|
EGL_S32 DolDrawBitmap(EGL_U32 fboHandleIndex, const DolBitmapInfo &dolBitmapInfo);
|
|
|
|
|
|
// Draw bitmap by blend mode on framebuffer object
|
|
|
EGL_S32 DolDrawBitmapByBlend(EGL_U32 fboHandleIndex, const DolBitmapInfo &dolBitmapInfo);
|
|
|
|
|
|
// Display bitmap
|
|
|
EGL_S32 DolDisplayBitmap(const DolBitmapInfo &dolBitmapInfo);
|
|
|
|
|
|
// Draw rect on framebuffer object
|
|
|
EGL_S32 DolDrawRect(EGL_U32 fboHandleIndex, const DolRectInfo &rect, const DolColorRGBA &color);
|
|
|
|
|
|
// Draw round on framebuffer object
|
|
|
EGL_S32 DolDrawRound(EGL_U32 fboHandleIndex, const DolRoundInfo &round, const DolColorRGBA &color);
|
|
|
|
|
|
// Calculation size of the text
|
|
|
EGL_S32 DolGetTextSize(const DolTextInfo &textInfo, EGL_U32 &width, EGL_U32 &height);
|
|
|
|
|
|
// Load font lib to textture
|
|
|
EGL_S32 DolLoadFont(const std::string &fontLibPath, EGL_U32 fontSize);
|
|
|
|
|
|
EGL_U32 DolGetWindowWidth() const;
|
|
|
|
|
|
EGL_U32 DolGetWindowHeight() const;
|
|
|
|
|
|
EGL_S32 DolRefreshOnSrceen();
|
|
|
|
|
|
private:
|
|
|
GLint ConvertFormatToGLES(EGL_S32 dolFormat) const;
|
|
|
|
|
|
void ScreenCoordToVCoord(const DolRectInfo &rect,
|
|
|
GLRectInfo &glRect, EGL_U32 screenWidth, EGL_U32 screenHeight) const;
|
|
|
|
|
|
void ScreenCoordToVCoord(const DolRoundInfo &round,
|
|
|
GLRoundInfo &glRound, EGL_U32 screenWidth, EGL_U32 screenHeight) const;
|
|
|
|
|
|
void ScreenCoordToFboCoord(const DolRectInfo &rect,
|
|
|
GLRectInfo &glRect, EGL_U32 screenWidth, EGL_U32 screenHeight) const;
|
|
|
|
|
|
void ConvertGLColor(const DolColorRGBA &colorRGBA, ColorRGBA &color) const;
|
|
|
|
|
|
void SetTextInfo(const DolTextInfo &dolText, GLTextInfo &textInfo) const;
|
|
|
|
|
|
void SetBitmapInfo(GLBitmapInfo &bitmapInfo, const DolBitmapInfo &dolBitmapInfo,
|
|
|
EGL_U32 screenWidth, EGL_U32 screenHeight) const;
|
|
|
|
|
|
void DrawRect(const FrameBuffObject &fbo, const DolRectInfo &rect, const DolColorRGBA &color);
|
|
|
|
|
|
void CorrectTextColor(DolColorRGBA &fgColor, const DolColorRGBA &bgColor);
|
|
|
|
|
|
void DrawTextUnderline(const FrameBuffObject &fbo, const DolTextInfo &textInfo, DolRectInfo &rect);
|
|
|
|
|
|
void DrawBackground(const FrameBuffObject &fbo, const DolRectInfo &rect, const DolColorRGBA &color);
|
|
|
|
|
|
void DrawText(const FrameBuffObject &fbo, DolTextInfo &textInfo, DolRectInfo &rect);
|
|
|
|
|
|
std::shared_ptr<GLDrawThread> drawThread;
|
|
|
|
|
|
EGLNativeWindowType mNativeWindow;
|
|
|
EGL_U32 winWidth;
|
|
|
EGL_U32 winHeight;
|
|
|
mutex mMutex;
|
|
|
};
|
|
|
}; // namespace dolgles
|
|
|
|
|
|
#endif // end DOL_GL_DRAW_SURFACE_H
|