Skip to content

Commit f50f19d

Browse files
authored
Merge pull request #1 from HR1025/private/dev
[what][feture] 添加 test_gl_compositor 用例
2 parents dde0b6e + 0ee925b commit f50f19d

File tree

11 files changed

+603
-26
lines changed

11 files changed

+603
-26
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ jobs:
1515
- run : rm -rf build
1616
- run : mkdir build
1717
- run : git submodule update --init --recursive
18-
- run : cd build && cmake .. -DUSE_OPENGL=ON -DUSE_EGL=ON -DUSE_GBM=ON -DUSE_SDL=ON -DUSE_SPRIV_CROSS=ON -DUSE_VULKAN=ON -DUSE_X11=ON -DUSE_VAAPI=ON -DUSE_OPENH264=ON && make -j4
18+
- run : cd build && cmake .. -DUSE_OPENGL=ON -DUSE_GBM=ON -DUSE_SDL=ON -DUSE_SPRIV_CROSS=ON -DUSE_VULKAN=ON -DUSE_X11=ON -DUSE_VAAPI=ON -DUSE_OPENH264=ON && make -j4

.vscode/launch.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "test_gl_compositor",
6+
"type": "cppdbg",
7+
"request": "launch",
8+
"program": "${workspaceFolder}/build/test_gl_compositor",
9+
"args": [
10+
],
11+
"stopAtEntry": false,
12+
"cwd": "${workspaceFolder}",
13+
"environment": [],
14+
"externalConsole": false,
15+
"MIMode": "gdb",
16+
"setupCommands": [
17+
{
18+
"description": "为 gdb 启用整齐打印",
19+
"text": "-enable-pretty-printing",
20+
"ignoreFailures": true
21+
}
22+
]
23+
}
24+
]
25+
}

CMakeLists.txt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ list(APPEND MMP_SAMPLE_INCS
1212
)
1313

1414
list(APPEND MMP_SAMPLE_SRCS
15-
${CMAKE_CURRENT_SOURCE_DIR}/PngA.c
16-
${CMAKE_CURRENT_SOURCE_DIR}/PngB.c
17-
${CMAKE_CURRENT_SOURCE_DIR}/AbstractDisplay.cpp
15+
${CMAKE_CURRENT_SOURCE_DIR}/source/PngA.c
16+
${CMAKE_CURRENT_SOURCE_DIR}/source/PngB.c
17+
${CMAKE_CURRENT_SOURCE_DIR}/source/AbstractDisplay.cpp
18+
${CMAKE_CURRENT_SOURCE_DIR}/source/SampleUtils.cpp
1819
)
1920

2021
list(APPEND MMP_SAMPLE_LIBS
@@ -39,13 +40,14 @@ if (SDL2_FOUND)
3940
message(" -- SDL LIBS : ${SDL2_LIBRARIES}")
4041
list(APPEND MMP_SAMPLE_INCS ${SDL2_INCLUDE_DIRS})
4142
list(APPEND MMP_SAMPLE_SRCS
42-
${CMAKE_CURRENT_SOURCE_DIR}/DisplaySDL.cpp
43+
${CMAKE_CURRENT_SOURCE_DIR}/source/DisplaySDL.cpp
4344
)
4445
list(APPEND MMP_SAMPLE_LIBS ${SDL2_LIBRARIES})
4546
add_definitions(-DSAMPLE_WITH_SDL)
4647
endif()
4748

4849
add_subdirectory(Core)
4950

50-
add_executable(test_gl_compositor ${CMAKE_CURRENT_SOURCE_DIR}/test_gl_compositor.cpp)
51-
target_link_libraries(test_gl_compositor ${MMP_SAMPLE_LIBS})
51+
add_executable(test_gl_compositor ${MMP_SAMPLE_SRCS} ${CMAKE_CURRENT_SOURCE_DIR}/test_gl_compositor.cpp)
52+
target_link_libraries(test_gl_compositor ${MMP_SAMPLE_LIBS})
53+
target_include_directories(test_gl_compositor PUBLIC ${MMP_SAMPLE_INCS})

Core

Submodule Core updated from 9a1a589 to ff610dc

README.md

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,63 @@
1-
# mmp_sample
1+
# README
2+
3+
简体中文
4+
5+
## 简介
6+
7+
`mmp_sample` 提供 [MMP-Core](https://github.com/HR1025/MMP-Core) 一些接口的使用方法, 示例以单独 *main.cpp* 展示.
8+
9+
也就是说, 不用特意去关注 `include``source` 下的代码, 都是一些简单的辅助接口.
10+
11+
更进一步, 只需要关心 `xxx.cpp` 中的 `int App::main(const ArgVec& args)` 实现.
12+
13+
示例都集中在项目的根目录, 以 `xxx.cpp` 命名; `.cpp` 的名称即为对应用例可执行程序名称.
14+
15+
## 编译
16+
17+
### Linux (Debian System)
18+
19+
```shell
20+
sudo apt install libgbm-dev libsdl2-dev libgl1-mesa-dev* nasm libx11-dev libdrm-dev libva-dev
21+
rm -rf build
22+
mkdir build
23+
git submodule update --init --recursive
24+
cd build && cmake .. -DUSE_OPENGL=ON -DUSE_GBM=ON -DUSE_SDL=ON -DUSE_SPRIV_CROSS=ON -DUSE_VULKAN=ON -DUSE_X11=ON -DUSE_VAAPI=ON -DUSE_OPENH264=ON && make -j4
25+
```
26+
27+
## 如何调试
28+
29+
选择一个能与 `CMake` 结合的 `IDE` 工具即可, `demo` 附带了 `vscode` 使用的 `launch.json`.
30+
31+
## 用例
32+
33+
>
34+
> 详细的配置可以通过 `-h` 进行查看.
35+
>
36+
37+
### test_gl_compositor
38+
39+
`test_gl_compositor` 展示了如何实现多画面合成的效果, `MMP-Core` 定义了三个术语 `Item``Layer``Compositor`;
40+
41+
多个 `Item` 可以被添加入同一个 `Layer`, 需要保证其互不相交;
42+
43+
多个 `Layer` 可以被添加入同一个 `Compositor`, 从而实现画面合成的功能.
44+
45+
`test_gl_compositor` 支持一些配置项, 如下:
46+
47+
- backend : 处理节点, 可能可选 OPENGL, OPENGL_ES, D3D11 和 VULKAN
48+
- split_num : 分屏数量, 如默认为 4, 会显示四分屏的效果
49+
- frame_per_second : 刷新帧率, 默认 60 帧
50+
- merry_go_around : 跑马灯效果, 按照每秒 2 帧的速度移动画面
51+
- duration : 持续时间, 单位为 s
52+
53+
效果图:
54+
55+
![test_gl_compositor](./images/test_gl_compositor.png)
56+
57+
## 其他
58+
59+
在不同的平台上, 或者不同的驱动上, 相同的测试用例可能出现不同的效果, 或者更严重点甚至无法运行或者崩溃.
60+
61+
这是由于跨平台和驱动所相关的兼容性问题, 难以在开发阶段发现并处理, 或者就是 `MMP-Core` 程序本身的逻辑错误.
62+
63+
一般来说简易的兼容性问题经过自己简单的定位以及修改, 基本上还是可以让程序运行起来的.

images/test_gl_compositor.png

66.2 KB
Loading

include/SampleUtils.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma once
2+
3+
#include <string>
4+
5+
#include "Common/AbstractPicture.h"
6+
#include "GPU/GL/GLCommon.h"
7+
8+
namespace Mmp
9+
{
10+
11+
AbstractPicture::ptr GetFrame1920x1080A();
12+
13+
AbstractPicture::ptr GetFrame1920x1080B();
14+
15+
GPUBackend GetGPUBackend(const std::string& str);
16+
17+
} // namespace Mmp

source/AbstractDisplay.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <vector>
44

55
#ifdef SAMPLE_WITH_SDL
6-
#include "SDL/DisplaySDL.h"
6+
#include "DisplaySDL.h"
77
#endif /* SAMPLE_WITH_SDL */
88

99
namespace Mmp

source/DisplaySDL.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -198,18 +198,6 @@ void DisplaySDL::UpdateWindow(const uint32_t* frameBuffer, PixelsInfo info)
198198
SDL_UpdateTexture(_texture, NULL, reinterpret_cast<const void*>(frameBuffer), sizeof(uint32_t)*_windowWidth);
199199
break;
200200
}
201-
case PixelFormat::NV12:
202-
{
203-
SDL_Rect rect;
204-
{
205-
rect.x = 0;
206-
rect.y = 0;
207-
rect.w = info.width;
208-
rect.h = info.height;
209-
}
210-
SDL_UpdateNVTexture(_texture, &rect, (uint8_t*)frameBuffer, info.width, (uint8_t*)frameBuffer + info.width * info.height, info.width);
211-
break;
212-
}
213201
default:
214202
{
215203
return;

source/SampleUtils.cpp

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#include "SampleUtils.h"
2+
3+
#include <cstring>
4+
#include <memory.h>
5+
6+
#include "GPU/GL/GLCommon.h"
7+
#include "Codec/CodecFactory.h"
8+
9+
#include "PngA.h"
10+
#include "PngB.h"
11+
12+
namespace Mmp
13+
{
14+
15+
AbstractPicture::ptr GetFrame1920x1080A()
16+
{
17+
using namespace Codec;
18+
// 1 - Read compress data from png array
19+
NormalPack::ptr pack = std::make_shared<NormalPack>(0);
20+
pack->SetCapacity(sizeof(bin2c_A_png));
21+
pack->SetSize((size_t)(sizeof(bin2c_A_png)));
22+
memcpy(pack->GetData(), bin2c_A_png, sizeof(bin2c_A_png));
23+
// 2 - decoder to pixel data
24+
AbstractFrame::ptr frame;
25+
{
26+
auto pngDecoder = DecoderFactory::DefaultFactory().CreateDecoder("PngDecoder");
27+
pngDecoder->Init();
28+
pngDecoder->Start();
29+
PngDecoderParameter parameter;
30+
parameter.format = PixelFormat::RGBA8888;
31+
pngDecoder->SetParameter(parameter);
32+
pngDecoder->Push(pack);
33+
if (!pngDecoder->Pop(frame))
34+
{
35+
assert(false);
36+
}
37+
pngDecoder->Stop();
38+
pngDecoder->Uninit();
39+
}
40+
return std::dynamic_pointer_cast<AbstractPicture>(frame);
41+
}
42+
43+
AbstractPicture::ptr GetFrame1920x1080B()
44+
{
45+
using namespace Codec;
46+
// 1 - Read compress data from png array
47+
NormalPack::ptr pack = std::make_shared<NormalPack>(0);
48+
pack->SetCapacity(sizeof(bin2c_B_png));
49+
pack->SetSize((size_t)(sizeof(bin2c_B_png)));
50+
memcpy(pack->GetData(), bin2c_B_png, sizeof(bin2c_B_png));
51+
// 2 - decoder to pixel data
52+
AbstractFrame::ptr frame;
53+
{
54+
auto pngDecoder = DecoderFactory::DefaultFactory().CreateDecoder("PngDecoder");
55+
pngDecoder->Init();
56+
pngDecoder->Start();
57+
PngDecoderParameter parameter;
58+
parameter.format = PixelFormat::RGBA8888;
59+
pngDecoder->SetParameter(parameter);
60+
pngDecoder->Push(pack);
61+
if (!pngDecoder->Pop(frame))
62+
{
63+
assert(false);
64+
}
65+
pngDecoder->Stop();
66+
pngDecoder->Uninit();
67+
}
68+
return std::dynamic_pointer_cast<AbstractPicture>(frame);
69+
}
70+
71+
GPUBackend GetGPUBackend(const std::string& str)
72+
{
73+
if ("OPENGL" == str)
74+
{
75+
return GPUBackend::OPENGL;
76+
}
77+
else if ("OPENGL_ES" == str)
78+
{
79+
return GPUBackend::OPENGL_ES;
80+
}
81+
else if ("D3D11" == str)
82+
{
83+
return GPUBackend::D3D11;
84+
}
85+
else if ("VULKAN" == str)
86+
{
87+
return GPUBackend::VULKAN;
88+
}
89+
else
90+
{
91+
return GPUBackend::OPENGL;
92+
}
93+
}
94+
95+
} // namespace Mmp

0 commit comments

Comments
 (0)