当前位置:网站首页>SDL2来源分析7:演出(SDL_RenderPresent())
SDL2来源分析7:演出(SDL_RenderPresent())
2022-07-06 12:56:00 【全栈程序员站长】
大家好,又见面了,我是全栈君。
=====================================================
SDL源代码分析系列文章上市:
SDL2源码分析5:更新纹理(SDL_UpdateTexture())
SDL2源码分析6:拷贝到渲染器(SDL_RenderCopy())
SDL2源码分析7:显示(SDL_RenderPresent())
=====================================================
上一篇文章分析了SDL纹理赋值给渲染目标的函数SDL_RenderCopy()。
这篇文章分析SDL显示视频最后的一个函数:SDL_RenderPresent()。
SDL播放视频的代码流程例如以下所看到的。 初始化:
SDL_Init(): 初始化SDL。 SDL_CreateWindow(): 创建窗体(Window)。 SDL_CreateRenderer(): 基于窗体创建渲染器(Render)。 SDL_CreateTexture(): 创建纹理(Texture)。
循环渲染数据:
SDL_UpdateTexture(): 设置纹理的数据。 SDL_RenderCopy(): 纹理复制给渲染器。 SDL_RenderPresent(): 显示。
上篇文章分析了该流程中的第6个函数SDL_RenderCopy()。本文继续分析该流程中的最后一个函数SDL_RenderPresent()。
SDL_RenderPresent()
函数简单介绍
SDL使用SDL_RenderPresent()显示画面。
SDL_RenderPresent()的原型例如以下。
void SDLCALL SDL_RenderPresent(SDL_Renderer * renderer);
參数renderer用于指定渲染器。
函数调用关系图
SDL_RenderPresent()关键函数的调用关系能够用下图表示。
上面的图片不太清晰,更清晰的图片上传到了相冊里面:
http://my.csdn.net/leixiaohua1020/album/detail/1794103
把相冊里面的图片保存下来就能够得到清晰的图片了。
源码分析
SDL_RenderPresent()的源码位于render\SDL_render.c中。
例如以下所看到的。
void SDL_RenderPresent(SDL_Renderer * renderer)
{
CHECK_RENDERER_MAGIC(renderer, );
/* Don't draw while we're hidden */
if (renderer->hidden) {
return;
}
renderer->RenderPresent(renderer);
}
从源码中能够看出,SDL_RenderPresent()调用了SDL_Render的RenderPresent()方法显示图像。
以下我们具体看一下几种不同的渲染器的RenderPresent()的方法。
1. Direct3D
Direct3D 渲染器中相应RenderPresent()的函数是D3D_RenderPresent()。它的源码例如以下所看到的(位于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);
}
}
从代码中能够看出,该函数调用了2个最关键Direct3D的API: IDirect3DDevice9_EndScene():结束一个场景。 IDirect3DDevice9_Present():显示。
2. OpenGL
OpenGL渲染器中相应RenderPresent()的函数是GL_RenderPresent(),它的源码例如以下所看到的(位于render\opengl\SDL_render_gl.c)。
static void GL_RenderPresent(SDL_Renderer * renderer)
{
GL_ActivateRenderer(renderer);
SDL_GL_SwapWindow(renderer->window);
}
代码比較简单,仅仅有两行。关键的显示函数位于SDL_GL_SwapWindow()函数中。以下看一下SDL_GL_SwapWindow()的代码(位于video\SDL_video.c。感觉这里调用关系略微有点乱…)。
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);
}
从上述代码中能够看出。SDL_GL_SwapWindow()调用了SDL_VideoDevice的GL_SwapWindow()函数。
我们看一下在“Windows视频驱动”的情况下,该函数的代码。在“Windows视频驱动”的情况下,调用GL_SwapWindow()实际上是调用了WIN_GL_SwapWindow()函数。看一下WIN_GL_SwapWindow()函数的代码(位于video\windows\SDL_windowsopengl.c)。
void WIN_GL_SwapWindow(_THIS, SDL_Window * window)
{
HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc;
SwapBuffers(hdc);
}
代码中调用了简单的一个函数SwapBuffers(),完毕了显示功能。
3. Software
Software渲染器中相应RenderPresent()的函数是SW_RenderPresent(),它的源码例如以下所看到的(位于render\software\SDL_render_sw.c)。
static void SW_RenderPresent(SDL_Renderer * renderer)
{
SDL_Window *window = renderer->window;
if (window) {
SDL_UpdateWindowSurface(window);
}
}
从代码中能够看出。SW_RenderPresent()调用了一个函数SDL_UpdateWindowSurface()。我们看一下SDL_UpdateWindowSurface()的代码(位于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()又调用了还有一个函数SDL_UpdateWindowSurfaceRects()。继续看SDL_UpdateWindowSurfaceRects()的代码。
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()调用了SDL_VideoDevice的UpdateWindowFramebuffer()函数。在“Windows视频驱动”的情况下。相当于调用了WIN_UpdateWindowFramebuffer()。
我们看一下该函数的代码(位于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;
}
经过一系列的寻找之后,最终找到了Software渲染视频展示“资源”:BitBlt()性能。
版权声明:本文博主原创文章。博客,未经同意不得转载。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/117099.html原文链接:https://javaforall.cn
边栏推荐
- Yyds dry inventory run kubeedge official example_ Counter demo counter
- JS according to the Chinese Alphabet (province) or according to the English alphabet - Za sort &az sort
- Word bag model and TF-IDF
- Hardware development notes (10): basic process of hardware development, making a USB to RS232 module (9): create ch340g/max232 package library sop-16 and associate principle primitive devices
- 基于深度学习的参考帧生成
- 3D人脸重建:从基础知识到识别/重建方法!
- OneNote in-depth evaluation: using resources, plug-ins, templates
- Yyds dry goods count re comb this of arrow function
- Comprehensive evaluation and recommendation of the most comprehensive knowledge base management tools in the whole network: flowus, baklib, jiandaoyun, ones wiki, pingcode, seed, mebox, Yifang cloud,
- [redis design and implementation] part I: summary of redis data structure and objects
猜你喜欢
【论文解读】用于白内障分级/分类的机器学习技术
基于深度学习的参考帧生成
Chris LATTNER, the father of llvm: why should we rebuild AI infrastructure software
硬件开发笔记(十): 硬件开发基本流程,制作一个USB转RS232的模块(九):创建CH340G/MAX232封装库sop-16并关联原理图元器件
Reinforcement learning - learning notes 5 | alphago
967- letter combination of telephone number
3D人脸重建:从基础知识到识别/重建方法!
Laravel笔记-自定义登录中新增登录5次失败锁账户功能(提高系统安全性)
OneNote in-depth evaluation: using resources, plug-ins, templates
Performance test process and plan
随机推荐
Reflection operation exercise
[MySQL] basic use of cursor
Yyds dry inventory run kubeedge official example_ Counter demo counter
C # use Oracle stored procedure to obtain result set instance
ACdreamoj1110(多重背包)
El table table - sortable sorting & disordered sorting when decimal and% appear
OAI 5G NR+USRP B210安装搭建
【论文解读】用于白内障分级/分类的机器学习技术
Select data Column subset in table R [duplicate] - select subset of columns in data table R [duplicate]
Simple continuous viewing PTA
038. (2.7) less anxiety
@PathVariable
Aiko ai Frontier promotion (7.6)
基于STM32单片机设计的红外测温仪(带人脸检测)
3D人脸重建:从基础知识到识别/重建方法!
Xcode6 error: "no matching provisioning profiles found for application"
Spiral square PTA
New database, multidimensional table platform inventory note, flowus, airtable, seatable, Vig table Vika, Feishu multidimensional table, heipayun, Zhixin information, YuQue
15 millions d'employés sont faciles à gérer et la base de données native du cloud gaussdb rend le Bureau des RH plus efficace
Swagger UI tutorial API document artifact