当前位置:网站首页>Sdl2 source analysis 7: performance (sdl_renderpresent())
Sdl2 source analysis 7: performance (sdl_renderpresent())
2022-07-06 21:20:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm the king of the whole stack .
=====================================================
SDL Source code analysis series articles on the market :
SDL2 Source code analysis 1: initialization (SDL_Init())
SDL2 Source code analysis 2: forms (SDL_Window)
SDL2 Source code analysis 3: Renderers (SDL_Renderer)
SDL2 Source code analysis 4: texture (SDL_Texture)
SDL2 Source code analysis 5: Update texture (SDL_UpdateTexture())
SDL2 Source code analysis 6: Copy to the render (SDL_RenderCopy())
SDL2 Source code analysis 7: Show (SDL_RenderPresent())
SDL2 Source code analysis 8: Video display summary
=====================================================
The last article analyzed SDL Texture assignment function to render target SDL_RenderCopy().
This article analyzes SDL Show the last function of the video :SDL_RenderPresent().
SDL The code flow of playing video, such as the following . initialization :
SDL_Init(): initialization SDL. SDL_CreateWindow(): Create a form (Window). SDL_CreateRenderer(): Create a renderer based on the form (Render). SDL_CreateTexture(): Create texture (Texture).
Loop render data :
SDL_UpdateTexture(): Set texture data . SDL_RenderCopy(): Texture copy to renderer . SDL_RenderPresent(): Show .
The last article analyzed the... In this process 6 A function SDL_RenderCopy(). This article continues to analyze the last function in the process SDL_RenderPresent().
SDL_RenderPresent()
Function introduction
SDL Use SDL_RenderPresent() display frame .
SDL_RenderPresent() The prototype of is as follows .
void SDLCALL SDL_RenderPresent(SDL_Renderer * renderer);
Parameters renderer Lets you specify the renderer .
Function call graph
SDL_RenderPresent() The calling relationship of key functions can be represented by the following figure .
The picture above is not very clear , Clearer pictures are uploaded to the album :
http://my.csdn.net/leixiaohua1020/album/detail/1794103
Save the pictures in the album to get clear pictures .
Source code analysis
SDL_RenderPresent() The source code of is located in render\SDL_render.c in .
As you can see below .
void SDL_RenderPresent(SDL_Renderer * renderer)
{
CHECK_RENDERER_MAGIC(renderer, );
/* Don't draw while we're hidden */
if (renderer->hidden) {
return;
}
renderer->RenderPresent(renderer);
}
From the source code, we can see ,SDL_RenderPresent() Called SDL_Render Of RenderPresent() Method to display the image .
Let's take a look at several different renderers RenderPresent() Methods .
1. Direct3D
Direct3D Corresponding in the renderer RenderPresent() The function of is D3D_RenderPresent(). Its source code, such as the following ( be located render\direct3d\SDL_render_d3d.c).
static void D3D_RenderPresent(SDL_Renderer * renderer)
{
D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
HRESULT result;
if (!data->beginScene) {
IDirect3DDevice9_EndScene(data->device);
data->beginScene = SDL_TRUE;
}
result = IDirect3DDevice9_TestCooperativeLevel(data->device);
if (result == D3DERR_DEVICELOST) {
/* We'll reset later */
return;
}
if (result == D3DERR_DEVICENOTRESET) {
D3D_Reset(renderer);
}
result = IDirect3DDevice9_Present(data->device, NULL, NULL, NULL, NULL);
if (FAILED(result)) {
D3D_SetError("Present()", result);
}
}
As you can see from the code , This function calls 2 The key Direct3D Of API: IDirect3DDevice9_EndScene(): End a scene . IDirect3DDevice9_Present(): Show .
2. OpenGL
OpenGL Corresponding in the renderer RenderPresent() The function of is GL_RenderPresent(), Its source code, such as the following ( be located render\opengl\SDL_render_gl.c).
static void GL_RenderPresent(SDL_Renderer * renderer)
{
GL_ActivateRenderer(renderer);
SDL_GL_SwapWindow(renderer->window);
}
The code is relatively simple , There are only two lines . The key display functions are located in SDL_GL_SwapWindow() Function . Let's take a look at SDL_GL_SwapWindow() Code for ( be located video\SDL_video.c. I feel that the calling relationship here is a little messy …).
void SDL_GL_SwapWindow(SDL_Window * window)
{
CHECK_WINDOW_MAGIC(window, );
if (!(window->flags & SDL_WINDOW_OPENGL)) {
SDL_SetError("The specified window isn't an OpenGL window");
return;
}
if (SDL_GL_GetCurrentWindow() != window) {
SDL_SetError("The specified window has not been made current");
return;
}
_this->GL_SwapWindow(_this, window);
}
From the above code, we can see .SDL_GL_SwapWindow() Called SDL_VideoDevice Of GL_SwapWindow() function .
Let's see “Windows Video drive ” Under the circumstances , The code for this function . stay “Windows Video drive ” Under the circumstances , call GL_SwapWindow() It's actually called WIN_GL_SwapWindow() function . to glance at WIN_GL_SwapWindow() Function code ( be located video\windows\SDL_windowsopengl.c).
void WIN_GL_SwapWindow(_THIS, SDL_Window * window)
{
HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc;
SwapBuffers(hdc);
}
A simple function is called in the code SwapBuffers(), Finished the display function .
3. Software
Software Corresponding in the renderer RenderPresent() The function of is SW_RenderPresent(), Its source code, such as the following ( be located render\software\SDL_render_sw.c).
static void SW_RenderPresent(SDL_Renderer * renderer)
{
SDL_Window *window = renderer->window;
if (window) {
SDL_UpdateWindowSurface(window);
}
}
As you can see from the code .SW_RenderPresent() A function was called SDL_UpdateWindowSurface(). Let's see SDL_UpdateWindowSurface() Code for ( be located video\SDL_video.c).
int SDL_UpdateWindowSurface(SDL_Window * window)
{
SDL_Rect full_rect;
CHECK_WINDOW_MAGIC(window, -1);
full_rect.x = 0;
full_rect.y = 0;
full_rect.w = window->w;
full_rect.h = window->h;
return SDL_UpdateWindowSurfaceRects(window, &full_rect, 1);
}
SDL_UpdateWindowSurface() Another function is called SDL_UpdateWindowSurfaceRects(). Continue to look at SDL_UpdateWindowSurfaceRects() Code for .
int SDL_UpdateWindowSurfaceRects(SDL_Window * window, const SDL_Rect * rects,
int numrects)
{
CHECK_WINDOW_MAGIC(window, -1);
if (!window->surface_valid) {
return SDL_SetError("Window surface is invalid, please call SDL_GetWindowSurface() to get a new surface");
}
return _this->UpdateWindowFramebuffer(_this, window, rects, numrects);
}
SDL_UpdateWindowSurfaceRects() Called SDL_VideoDevice Of UpdateWindowFramebuffer() function . stay “Windows Video drive ” Under the circumstances . Equivalent to calling WIN_UpdateWindowFramebuffer().
Let's take a look at the code of this function ( be located video\windows\SDL_windowsframebuffer.c)
int WIN_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects)
{
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
BitBlt(data->hdc, 0, 0, window->w, window->h, data->mdc, 0, 0, SRCCOPY);
return 0;
}
After a series of searching , Finally found Software Render the video show “ resources ”:BitBlt() performance .
Copyright notice : This article is the original article of the blogger . Blog , Do not reprint without permission .
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/117099.html Link to the original text :https://javaforall.cn
边栏推荐
- ACdreamoj1110(多重背包)
- JS操作dom元素(一)——获取DOM节点的六种方式
- Reviewer dis's whole research direction is not just reviewing my manuscript. What should I do?
- This year, Jianzhi Tencent
- R语言可视化两个以上的分类(类别)变量之间的关系、使用vcd包中的Mosaic函数创建马赛克图( Mosaic plots)、分别可视化两个、三个、四个分类变量的关系的马赛克图
- document.write()的用法-写入文本——修改样式、位置控制
- HMS core machine learning service creates a new "sound" state of simultaneous interpreting translation, and AI makes international exchanges smoother
- 【力扣刷题】32. 最长有效括号
- MLP (multilayer perceptron neural network) is a multilayer fully connected neural network model.
- 如何实现常见框架
猜你喜欢
for循环中break与continue的区别——break-完全结束循环 & continue-终止本次循环
Four common ways and performance comparison of ArrayList de duplication (jmh performance analysis)
KDD 2022 | 通过知识增强的提示学习实现统一的对话式推荐
【力扣刷题】一维动态规划记录(53零钱兑换、300最长递增子序列、53最大子数组和)
[MySQL] basic use of cursor
968 edit distance
3D face reconstruction: from basic knowledge to recognition / reconstruction methods!
【论文解读】用于白内障分级/分类的机器学习技术
Reinforcement learning - learning notes 5 | alphago
2017 8th Blue Bridge Cup group a provincial tournament
随机推荐
@Detailed differences among getmapping, @postmapping and @requestmapping, with actual combat code (all)
2022 fields Award Announced! The first Korean Xu Long'er was on the list, and four post-80s women won the prize. Ukrainian female mathematicians became the only two women to win the prize in history
R3live notes: image processing section
OSPF多区域配置
2017 8th Blue Bridge Cup group a provincial tournament
14年本科毕业,转行软件测试,薪资13.5K
Chris LATTNER, the father of llvm: why should we rebuild AI infrastructure software
The difference between break and continue in the for loop -- break completely end the loop & continue terminate this loop
Internet News: Geely officially acquired Meizu; Intensive insulin purchase was fully implemented in 31 provinces
2022菲尔兹奖揭晓!首位韩裔许埈珥上榜,四位80后得奖,乌克兰女数学家成史上唯二获奖女性
Is it profitable to host an Olympic Games?
[sliding window] group B of the 9th Landbridge cup provincial tournament: log statistics
Nodejs教程之让我们用 typescript 创建你的第一个 expressjs 应用程序
Vim 基本配置和经常使用的命令
Start the embedded room: system startup with limited resources
【力扣刷题】一维动态规划记录(53零钱兑换、300最长递增子序列、53最大子数组和)
Le langage r visualise les relations entre plus de deux variables de classification (catégories), crée des plots Mosaiques en utilisant la fonction Mosaic dans le paquet VCD, et visualise les relation
Absolute primes (C language)
el-table表格——获取单击的是第几行和第几列 & 表格排序之el-table与sort-change、el-table-column与sort-method & 清除排序-clearSort
Forward maximum matching method