Skip to content

Commit fc4c644

Browse files
committed
[what] 适配 Windows 编译
1 parent f50f19d commit fc4c644

File tree

9 files changed

+102
-33
lines changed

9 files changed

+102
-33
lines changed

.github/workflows/ci.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,22 @@ 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_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
19+
20+
msvc2022-x64-make:
21+
runs-on: windows-2022
22+
steps:
23+
- uses: actions/checkout@v1
24+
- run : git submodule update --init --recursive
25+
- run : mkdir build
26+
- run : cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -S. -B./build -G "Visual Studio 17 2022" -T host=x64 -A x64
27+
- run : cmake --build build --config Release -j 16
28+
29+
msvc2022-x86-make:
30+
runs-on: windows-2022
31+
steps:
32+
- uses: actions/checkout@v1
33+
- run : git submodule update --init --recursive
34+
- run : mkdir build
35+
- run : cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -S. -B./build -G "Visual Studio 17 2022" -T host=x86 -A win32
36+
- run : cmake --build build --config Release -j 16

.vscode/launch.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"version": "0.2.0",
33
"configurations": [
44
{
5-
"name": "test_gl_compositor",
5+
"name": "test_gl_compositor(debian)",
66
"type": "cppdbg",
77
"request": "launch",
88
"program": "${workspaceFolder}/build/test_gl_compositor",
@@ -20,6 +20,17 @@
2020
"ignoreFailures": true
2121
}
2222
]
23+
},
24+
{
25+
"name": "test_gl_compositor(msvc)",
26+
"type": "cppvsdbg",
27+
"request": "launch",
28+
"program": "${workspaceFolder}/build/Debug/test_gl_compositor.exe",
29+
"args": [],
30+
"stopAtEntry": false,
31+
"cwd": "${fileDirname}",
32+
"environment": [],
33+
"console":"integratedTerminal"
2334
}
2435
]
2536
}

CMakeLists.txt

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ list(APPEND MMP_SAMPLE_SRCS
1616
${CMAKE_CURRENT_SOURCE_DIR}/source/PngB.c
1717
${CMAKE_CURRENT_SOURCE_DIR}/source/AbstractDisplay.cpp
1818
${CMAKE_CURRENT_SOURCE_DIR}/source/SampleUtils.cpp
19+
${CMAKE_CURRENT_SOURCE_DIR}/source/DisplaySDL.cpp
1920
)
2021

2122
list(APPEND MMP_SAMPLE_LIBS
@@ -27,25 +28,10 @@ list(APPEND MMP_SAMPLE_LIBS
2728
Mmp::Windows
2829
Mmp::PG
2930
Mmp::SL
31+
SDL2::SDL2
32+
SDL2::SDL2main
3033
)
3134

32-
if (NOT SDL2_FOUND)
33-
find_package(SDL2 CONFIG)
34-
endif()
35-
36-
if (SDL2_FOUND)
37-
message("-- Found SDL2")
38-
message(" -- SDL INCS : ${SDL2_INCLUDE_DIRS}")
39-
message(" -- SDL LIB DIR : ${SDL2_LIBRARY_DIRS}")
40-
message(" -- SDL LIBS : ${SDL2_LIBRARIES}")
41-
list(APPEND MMP_SAMPLE_INCS ${SDL2_INCLUDE_DIRS})
42-
list(APPEND MMP_SAMPLE_SRCS
43-
${CMAKE_CURRENT_SOURCE_DIR}/source/DisplaySDL.cpp
44-
)
45-
list(APPEND MMP_SAMPLE_LIBS ${SDL2_LIBRARIES})
46-
add_definitions(-DSAMPLE_WITH_SDL)
47-
endif()
48-
4935
add_subdirectory(Core)
5036

5137
add_executable(test_gl_compositor ${MMP_SAMPLE_SRCS} ${CMAKE_CURRENT_SOURCE_DIR}/test_gl_compositor.cpp)

Core

Submodule Core updated from ff610dc to 8b4cd2d

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 MMP. All Rights Reserved.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,35 @@
1717
### Linux (Debian System)
1818

1919
```shell
20-
sudo apt install libgbm-dev libsdl2-dev libgl1-mesa-dev* nasm libx11-dev libdrm-dev libva-dev
20+
sudo apt install libgbm-dev libgl1-mesa-dev* nasm libx11-dev libdrm-dev libva-dev
2121
rm -rf build
2222
mkdir build
2323
git submodule update --init --recursive
2424
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
2525
```
2626

27+
## Windows (MSVC 2022 x64)
28+
29+
```shell
30+
git submodule update --init --recursive
31+
mkdir build
32+
cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -S. -B./build -G "Visual Studio 17 2022" -T host=x86 -A win32
33+
cmake --build build --config Release -j 16
34+
```
35+
36+
## Windows (MSVC 2022 x86)
37+
38+
```shell
39+
git submodule update --init --recursive
40+
mkdir build
41+
cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -S. -B./build -G "Visual Studio 17 2022" -T host=x64 -A x64
42+
cmake --build build --config Release -j 16
43+
```
44+
45+
>
46+
> `Windows` 也可以直接使用 `IDE` 进行构建, 在构建时选择对应的工具链即可.
47+
>
48+
2749
## 如何调试
2850

2951
选择一个能与 `CMake` 结合的 `IDE` 工具即可, `demo` 附带了 `vscode` 使用的 `launch.json`.
@@ -32,7 +54,7 @@ cd build && cmake .. -DUSE_OPENGL=ON -DUSE_GBM=ON -DUSE_SDL=ON -DUSE_SPRIV_CROSS
3254

3355
>
3456
> 详细的配置可以通过 `-h` 进行查看.
35-
>
57+
>
3658
3759
### test_gl_compositor
3860

source/AbstractDisplay.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
#include <vector>
44

5-
#ifdef SAMPLE_WITH_SDL
6-
#include "DisplaySDL.h"
7-
#endif /* SAMPLE_WITH_SDL */
5+
#include "DisplaySDL.h"
86

97
namespace Mmp
108
{
@@ -30,12 +28,10 @@ AbstractDisplay::ptr AbstractDisplay::Create(const std::string& className)
3028
}
3129
return display;
3230
}
33-
#ifdef SAMPLE_WITH_SDL
3431
else if (className == "DisplaySDL")
3532
{
3633
return std::make_shared<DisplaySDL>();
3734
}
38-
#endif /* SAMPLE_WITH_SDL */
3935
else
4036
{
4137
return nullptr;

source/DisplaySDL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ bool DisplaySDL::Open(PixelsInfo info)
136136
DISPLAY_LOG_ERROR << "Create SDL window fail, error is: " << SDL_GetError();
137137
return false;
138138
}
139-
_render = SDL_CreateRenderer(_window, -1, SDL_RENDERER_SOFTWARE | SDL_RENDERER_TARGETTEXTURE);
139+
_render = SDL_CreateRenderer(_window, -1, SDL_RENDERER_TARGETTEXTURE);
140140
if (_render != nullptr)
141141
{
142142
DISPLAY_LOG_INFO << "Create SDL render Successfully";

test_gl_compositor.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ void App::HandleDuration(const std::string& name, const std::string& value)
135135

136136
void App::Initialize()
137137
{
138+
ThreadPool::ThreadPoolSingleton()->Init();
138139
Codec::CodecConfig::Instance()->Init();
139140
{
140141
_renderThread = std::thread([this]() -> void
@@ -184,6 +185,7 @@ void App::Uninitialize()
184185
_renderThread.join();
185186
}
186187
Codec::CodecConfig::Instance()->Uninit();
188+
ThreadPool::ThreadPoolSingleton()->Uninit();
187189
}
188190

189191
void App::defineOptions(OptionSet& options)
@@ -289,7 +291,8 @@ int App::main(const ArgVec& args)
289291
Gpu::Update2DTextures(GLDrawContex::Instance(), std::vector<Texture::ptr>({imageB}), sceneB);
290292
}
291293

292-
auto equalSplitScreen = [&](size_t count, size_t fps, uint32_t duration) -> void
294+
Promise<void>::ptr lastDraw;
295+
auto equalSplitScreen = [&](size_t count, size_t fps, uint64_t duration) -> void
293296
{
294297
Gpu::AbstractSceneLayer::ptr layer = Gpu::AbstractSceneLayer::Create();
295298
std::vector<Gpu::SceneItemParam> params;
@@ -362,19 +365,31 @@ int App::main(const ArgVec& args)
362365
itemParamOffset++;
363366
}
364367
layer->Draw(framebuffer);
365-
Gpu::Copy2DTexturesToMemory(GLDrawContex::Instance(), std::vector<Texture::ptr>({framebuffer}), fb);
366-
if (display)
368+
if (lastDraw)
367369
{
368-
display->UpdateWindow((const uint32_t*)(fb->GetData()), info);
370+
lastDraw->Wait();
369371
}
370-
curDrawTime++;
372+
Gpu::Copy2DTexturesToMemory(GLDrawContex::Instance(), std::vector<Texture::ptr>({framebuffer}), fb);
371373
if (stamp.elapsed()/1000 > 1000 / fps)
372374
{
373375
MMP_LOG_WARN << "overload, cost time is: " << stamp.elapsed()/1000 << " ms";
374376
}
377+
lastDraw = std::make_shared<Promise<void>>([display, fb, info]()
378+
{
379+
if (display)
380+
{
381+
display->UpdateWindow((const uint32_t*)(fb->GetData()), info);
382+
}
383+
});
384+
ThreadPool::ThreadPoolSingleton()->Commit(lastDraw);
385+
curDrawTime++;
375386
std::this_thread::sleep_for(std::chrono::milliseconds(1000 / fps - stamp.elapsed()/1000));
376387
}
377388
layer.reset();
389+
if (lastDraw)
390+
{
391+
lastDraw->Wait();
392+
}
378393
};
379394

380395
equalSplitScreen(splitNum, fps, duration);

0 commit comments

Comments
 (0)