=====================================================
SDL源代碼分析系列文章列表:
SDL2源代碼分析5:更新紋理(SDL_UpdateTexture())
SDL2源代碼分析6:複製到渲染器(SDL_RenderCopy())
SDL2源代碼分析7:顯示(SDL_RenderPresent())
=====================================================
本文簡單總結一下SDL顯示視頻的源代碼。
SDL顯示視頻的結構體
SDL顯示視頻涉及到下列結構體:SDL_Window:代表了窗口上述幾個結構體之間的關係如下圖所示。
SDL_Renderer:代表了渲染器
SDL_Texture:代表了紋理
SDL_Rect:一個矩形框,用於確定紋理顯示的位置。
PS:該圖源自於文章《最簡單的基於FFMPEG+SDL的視頻播放器 ver2 (採用SDL2.0)》
SDL顯示視頻的流程
SDL顯示視頻的流程如下圖所示。
1. 初始化:SDL_Init()
2. 創建SDL_Window:SDL_CreateWindow()
3. 創建SDL_Render:SDL_CreateRenderer()
4. 創建SDL_Texture:SDL_CreateTexture()
5. 更新SDL_Texture:SDL_UpdateTexture()
6. 渲染SDL_Texture:SDL_RenderCopy()
7. 顯示:SDL_RenderPresent()
8. 返回步驟4繼續執行
上圖中顯示了SDL播放視頻的時候API的調用流程。下文總結一下在不同的系統以及渲染技術下,這些SDL的API和系統底層API之間的調用關係。
SDL-Windows-Direct3D
SDL在Windows系統下,使用Direct3D渲染視頻的時候的函數調用關係如下圖所示。PS:白色背景函數爲SDL的API;藍色背景的函數爲Win32的API;紫色背景的函數Direct3D的API。
更清晰的圖片鏈接(右鍵保存):http://my.csdn.net/leixiaohua1020/album/detail/1795753
SDL_CreateWindow()調用瞭如下Win32的API:
CreateWindow()
SetWindowText()
ShowWindow()
SetWindowPos()
SDL_CreateRenderer()調用瞭如下Direc3D的API:
Direct3DCreate9()
IDirect3D9_GetDeviceCaps()
IDirect3D9_CreateDevice()
IDirect3DDevice9_SetFVF()
IDirect3DDevice9_SetRenderState()
IDirect3DDevice9_SetTextureStageState()
IDirect3DDevice9_SetTransform()
IDirect3DDevice9_CreatePixelShader()
SDL_CreateTexture()調用瞭如下Direc3D的API:
IDirect3DDevice9_CreateTexture()
SDL_UpdateTexture()調用瞭如下Direc3D的API:
IDirect3DTexture9_LockRect()
memcpy():這個不算D3D的,用於拷貝像素數據。
IDirect3DTexture9_UnlockRect()
SDL_RenderCopy()調用瞭如下Direc3D的API:
IDirect3DDevice9_BeginScene()
IDirect3DDevice9_SetRenderState()
IDirect3DDevice9_SetSamplerState()
IDirect3DDevice9_SetTexture()
IDirect3DDevice9_SetPixelShader()
IDirect3DDevice9_DrawPrimitiveUP()
SDL_RenderPresent()調用瞭如下Direc3D的API:
IDirect3DDevice9_EndScene()
IDirect3DDevice9_Present()
SDL-Windows-OpenGL
SDL在Windows系統下,使用OpenGL渲染視頻的時候的函數調用關係如下圖所示。PS:白色背景函數爲SDL的API;藍色背景的函數爲Win32的API;紫色背景的函數OpenGL的API。
更清晰的圖片鏈接(右鍵保存):http://my.csdn.net/leixiaohua1020/album/detail/1795755
SDL_CreateWindow()調用瞭如下Win32的API:
CreateWindow()
SetWindowText()
ShowWindow()
SetWindowPos()
SDL_CreateRenderer()調用瞭如下OpenGL的API:
glCreateProgramObject()
glCreateShaderObject()
glShaderSource()
glCompileShader()
GetObjectParameteriv()
AttachObject()
LinkProgram()
UseProgramObject()
SDL_CreateTexture()調用瞭如下OpenGL的API:
glGenTextures()
glBindTexture()
glTexParameteri()
glTexImage2D()
SDL_UpdateTexture()調用瞭如下OpenGL的API:
glBindTexture()
glTexSubImage2D()
SDL_RenderCopy()調用瞭如下OpenGL的API:
glActiveTexture()
glBindTexture()
SDL_RenderPresent()調用瞭如下OpenGL的API:
SwapBuffers()
SDL-Windows-Software
SDL在Windows系統下,使用Software渲染視頻的時候的函數調用關係如下圖所示。PS1:白色背景函數爲SDL的API;藍色背景的函數爲Win32的API。
PS2:Software渲染目前還沒有透徹分析。
SDL_CreateWindow()調用瞭如下Win32的API:
CreateWindow()
SetWindowText()
ShowWindow()
SetWindowPos()
SDL_CreateRenderer()調用瞭如下Win32的API:
CreateCompatibleBitmap()
GetDIBits()
CreateCompatibleDC()
CreateDIBSection()
SelectObject()
SDL_UpdateTexture()調用了memcpy()填充像素數據。
SDL_RenderPresent()調用瞭如下Win32的API:
BitBlt()