SDL2 source code analysis 8: video display summary, sdl2 source code

Source: Internet
Author: User

SDL2 source code analysis 8: video display summary, sdl2 source code
This article briefly summarizes the source code of the SDL video.
The structure of the SDL display video involves the following structure:

SDL_Window: indicates the window
SDL_Renderer: indicates the Renderer.
SDL_Texture: represents the texture
SDL_Rect: a rectangular box used to determine the position of the texture display.
Shows the relationship between the above structures.

PS: This figure is from the article "the simplest FFMPEG + SDL-Based Video Player ver2 (using SDL2.0)"


As shown in the figure, YUV/RGB pixel data is first loaded to SDL_Texture and then rendered to SDL_Window through SDL_Render. SDL_Rect can specify the display position.

SDL video display process

Shows the SDL video display process.


Clear image Link (right-click to save): Images:
1. Initialization: SDL_Init ()
2. Create SDL_Window: SDL_CreateWindow ()
3. Create SDL_Render: SDL_CreateRenderer ()
4. Create SDL_Texture: SDL_CreateTexture ()
5. Update SDL_Texture: SDL_UpdateTexture ()
6. Rendering SDL_Texture: SDL_RenderCopy ()
7. display: SDL_RenderPresent ()
8. Go back to step 4 and continue.
Shows the API call process when SDL plays a video. The following section summarizes the call relationships between these SDL APIs and the underlying system apis under different systems and rendering technologies.

Shows the function call relationships when using Direct3D to render videos in Windows.

PS: the white background function is the sdl api, the blue background function is the Win32 API, and the purple background function is the Direct3D API.


Clearer picture Link (right-click to save): http://my.csdn.net/leixiaohua1020/album/detail/1795753

We can see that when SDL uses Direct3D to render a video in Windows. The call relationships between functions are listed as follows:
SDL_CreateWindow () calls the following Win32 API:
CreateWindow ()
SetWindowText ()
ShowWindow ()
SetWindowPos ()

SDL_CreateRenderer () calls the following Direc3D API:
Direct3DCreate9 ()
IDirect3D9_GetDeviceCaps ()
IDirect3D9_CreateDevice ()
IDirect3DDevice9_SetFVF ()
IDirect3DDevice9_SetRenderState ()
IDirect3DDevice9_SetTextureStageState ()
IDirect3DDevice9_SetTransform ()
IDirect3DDevice9_CreatePixelShader ()

SDL_CreateTexture () calls the following Direc3D API:
IDirect3DDevice9_CreateTexture ()

SDL_UpdateTexture () calls the following Direc3D API:
IDirect3DTexture9_LockRect ()
Memcpy (): This is not D3D and is used to copy pixel data.
IDirect3DTexture9_UnlockRect ()

SDL_RenderCopy () calls the following Direc3D API:
IDirect3DDevice9_BeginScene ()
IDirect3DDevice9_SetRenderState ()
IDirect3DDevice9_SetSamplerState ()
IDirect3DDevice9_SetTexture ()
IDirect3DDevice9_SetPixelShader ()
IDirect3DDevice9_DrawPrimitiveUP ()

SDL_RenderPresent () calls the following Direc3D API:
IDirect3DDevice9_EndScene ()
IDirect3DDevice9_Present ()

In Windows, SDL-Windows-OpenGLSDL uses OpenGL to call functions when rendering videos, as shown in.
PS: the white background function is the sdl api, the blue background function is the Win32 API, and the purple background function OpenGL API.


Clearer picture Link (right-click to save): http://my.csdn.net/leixiaohua1020/album/detail/1795755


We can see that when SDL uses OpenGL to render a video in Windows. The call relationships between functions are listed as follows:
SDL_CreateWindow () calls the following Win32 API:
CreateWindow ()
SetWindowText ()
ShowWindow ()
SetWindowPos ()

SDL_CreateRenderer () calls the following OpenGL API:
GlCreateProgramObject ()
GlCreateShaderObject ()
GlShaderSource ()
GlCompileShader ()
GetObjectParameteriv ()
AttachObject ()
LinkProgram ()
UseProgramObject ()

SDL_CreateTexture () calls the following OpenGL API:
GlGenTextures ()
GlBindTexture ()
GlTexParameteri ()
GlTexImage2D ()

SDL_UpdateTexture () calls the following OpenGL API:
GlBindTexture ()
GlTexSubImage2D ()

SDL_RenderCopy () calls the following OpenGL API:
GlActiveTexture ()
GlBindTexture ()

SDL_RenderPresent () calls the following OpenGL API:
SwapBuffers ()


In Windows, SDL-Windows-SoftwareSDL uses Software to call functions when rendering videos, as shown in.
PS1: the white background function is the sdl api, and the blue background function is the Win32 API.
PS2: Software rendering is not thoroughly analyzed yet.
Clearer picture Link (right-click to save): http://my.csdn.net/leixiaohua1020/album/detail/1795757

We can see that when SDL uses Software to render a video in Windows. The call relationships between functions are listed as follows:
SDL_CreateWindow () calls the following Win32 API:
CreateWindow ()
SetWindowText ()
ShowWindow ()
SetWindowPos ()

SDL_CreateRenderer () calls the following Win32 API:
CreateCompatibleBitmap ()
GetDIBits ()
CreateCompatibleDC ()
CreateDIBSection ()
SelectObject ()

SDL_UpdateTexture () calls memcpy () to fill in pixel data.

SDL_RenderPresent () calls the following Win32 API:
BitBlt ()


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.