Blender  V3.3
Classes | Macros | Typedefs | Enumerations | Functions | Variables
wm_playanim.c File Reference
#include <fcntl.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/times.h>
#include <sys/wait.h>
#include <unistd.h>
#include "MEM_guardedalloc.h"
#include "PIL_time.h"
#include "BLI_fileops.h"
#include "BLI_listbase.h"
#include "BLI_path_util.h"
#include "BLI_rect.h"
#include "BLI_string.h"
#include "BLI_system.h"
#include "BLI_utildefines.h"
#include "IMB_colormanagement.h"
#include "IMB_imbuf.h"
#include "IMB_imbuf_types.h"
#include "BKE_image.h"
#include "BIF_glutil.h"
#include "GPU_context.h"
#include "GPU_framebuffer.h"
#include "GPU_immediate.h"
#include "GPU_immediate_util.h"
#include "GPU_init_exit.h"
#include "GPU_matrix.h"
#include "GPU_state.h"
#include "BLF_api.h"
#include "DNA_scene_types.h"
#include "ED_datafiles.h"
#include "GHOST_C-api.h"
#include "DEG_depsgraph.h"
#include "WM_api.h"

Go to the source code of this file.

Classes

struct  PlayState
 
struct  WindowStateGlobal
 
struct  PlayAnimPict
 

Macros

#define USE_FRAME_CACHE_LIMIT
 
#define PLAY_FRAME_CACHE_MAX   30
 
#define USE_IMB_CACHE
 

Typedefs

typedef struct PlayState PlayState
 
typedef enum eWS_Qual eWS_Qual
 
typedef struct PlayAnimPict PlayAnimPict
 

Enumerations

enum  eWS_Qual {
  WS_QUAL_LSHIFT = (1 << 0) , WS_QUAL_RSHIFT = (1 << 1) , WS_QUAL_SHIFT = (WS_QUAL_LSHIFT | WS_QUAL_RSHIFT) , WS_QUAL_LALT = (1 << 2) ,
  WS_QUAL_RALT = (1 << 3) , WS_QUAL_ALT = (WS_QUAL_LALT | WS_QUAL_RALT) , WS_QUAL_LCTRL = (1 << 4) , WS_QUAL_RCTRL = (1 << 5) ,
  WS_QUAL_CTRL = (WS_QUAL_LCTRL | WS_QUAL_RCTRL) , WS_QUAL_LMOUSE = (1 << 16) , WS_QUAL_MMOUSE = (1 << 17) , WS_QUAL_RMOUSE = (1 << 18) ,
  WS_QUAL_MOUSE = (WS_QUAL_LMOUSE | WS_QUAL_MMOUSE | WS_QUAL_RMOUSE)
}
 

Functions

static void playanim_window_zoom (struct PlayState *ps, const float zoom_offset)
 
static void playanim_window_get_size (int *r_width, int *r_height)
 
static void playanim_gl_matrix (void)
 
static void playanim_event_qual_update (void)
 
static void frame_cache_add (PlayAnimPict *pic)
 
static void frame_cache_remove (PlayAnimPict *pic)
 
static void frame_cache_touch (PlayAnimPict *pic)
 
static bool frame_cache_limit_exceeded (void)
 
static void frame_cache_limit_apply (ImBuf *ibuf_keep)
 
static ImBufibuf_from_picture (PlayAnimPict *pic)
 
static PlayAnimPictplayanim_step (PlayAnimPict *playanim, int step)
 
static int pupdate_time (void)
 
static voidocio_transform_ibuf (PlayState *ps, ImBuf *ibuf, bool *r_glsl_used, eGPUTextureFormat *r_format, eGPUDataFormat *r_data, void **r_buffer_cache_handle)
 
static void draw_display_buffer (PlayState *ps, ImBuf *ibuf)
 
static void playanim_toscreen (PlayState *ps, PlayAnimPict *picture, struct ImBuf *ibuf, int fontid, int fstep)
 
static void build_pict_list_ex (PlayState *ps, const char *first, int totframes, int fstep, int fontid)
 
static void build_pict_list (PlayState *ps, const char *first, int totframes, int fstep, int fontid)
 
static void update_sound_fps (void)
 
static void tag_change_frame (PlayState *ps, int cx)
 
static void change_frame (PlayState *ps)
 
static bool ghost_event_proc (GHOST_EventHandle evt, GHOST_TUserDataPtr ps_void)
 
static void playanim_window_open (const char *title, int posx, int posy, int sizex, int sizey)
 
static char * wm_main_playanim_intern (int argc, const char **argv)
 
void WM_main_playanim (int argc, const char **argv)
 

Variables

static struct WindowStateGlobal g_WS = {NULL}
 
static struct ListBase picsbase = {NULL, NULL}
 
static bool fromdisk = false
 
static double ptottime = 0.0
 
static double swaptime = 0.04
 
struct {
   struct ListBase   pics
 
   int   pics_len
 
   size_t   pics_size_in_memory
 
   size_t   memory_limit
 
g_frame_cache
 

Detailed Description

Animation player for image sequences & video's with sound support. Launched in a separate process from Blender's #RENDER_OT_play_rendered_anim

Note
This file uses ghost directly and none of the WM definitions. this could be made into its own module, alongside creator.

Definition in file wm_playanim.c.

Macro Definition Documentation

◆ PLAY_FRAME_CACHE_MAX

#define PLAY_FRAME_CACHE_MAX   30

Definition at line 79 of file wm_playanim.c.

◆ USE_FRAME_CACHE_LIMIT

#define USE_FRAME_CACHE_LIMIT

Definition at line 77 of file wm_playanim.c.

◆ USE_IMB_CACHE

#define USE_IMB_CACHE

Typedef Documentation

◆ eWS_Qual

typedef enum eWS_Qual eWS_Qual

◆ PlayAnimPict

typedef struct PlayAnimPict PlayAnimPict

◆ PlayState

typedef struct PlayState PlayState

The current state of the player.

Warning
Don't store results of parsing command-line arguments in this struct if they need to persist across playing back different files as these will be cleared when playing other files (drag & drop).

Enumeration Type Documentation

◆ eWS_Qual

enum eWS_Qual
Enumerator
WS_QUAL_LSHIFT 
WS_QUAL_RSHIFT 
WS_QUAL_SHIFT 
WS_QUAL_LALT 
WS_QUAL_RALT 
WS_QUAL_ALT 
WS_QUAL_LCTRL 
WS_QUAL_RCTRL 
WS_QUAL_CTRL 
WS_QUAL_LMOUSE 
WS_QUAL_MMOUSE 
WS_QUAL_RMOUSE 
WS_QUAL_MOUSE 

Definition at line 172 of file wm_playanim.c.

Function Documentation

◆ build_pict_list()

static void build_pict_list ( PlayState ps,
const char *  first,
int  totframes,
int  fstep,
int  fontid 
)
static

Definition at line 789 of file wm_playanim.c.

References build_pict_list_ex(), and PlayState::loading.

Referenced by wm_main_playanim_intern().

◆ build_pict_list_ex()

static void build_pict_list_ex ( PlayState ps,
const char *  first,
int  totframes,
int  fstep,
int  fontid 
)
static

◆ change_frame()

static void change_frame ( PlayState ps)
static

◆ draw_display_buffer()

static void draw_display_buffer ( PlayState ps,
ImBuf ibuf 
)
static

◆ frame_cache_add()

static void frame_cache_add ( PlayAnimPict pic)
static

◆ frame_cache_limit_apply()

static void frame_cache_limit_apply ( ImBuf ibuf_keep)
static

◆ frame_cache_limit_exceeded()

static bool frame_cache_limit_exceeded ( void  )
static

Definition at line 317 of file wm_playanim.c.

References g_frame_cache, and PLAY_FRAME_CACHE_MAX.

Referenced by build_pict_list_ex(), and frame_cache_limit_apply().

◆ frame_cache_remove()

static void frame_cache_remove ( PlayAnimPict pic)
static

◆ frame_cache_touch()

static void frame_cache_touch ( PlayAnimPict pic)
static

◆ ghost_event_proc()

static bool ghost_event_proc ( GHOST_EventHandle  evt,
GHOST_TUserDataPtr  ps_void 
)
static

Definition at line 874 of file wm_playanim.c.

References Freestyle::a, BLI_strncpy(), GHOST_TEventButtonData::button, GHOST_TStringArray::count, GHOST_TEventDragnDropData::data, GHOST_TEventDragnDropData::dataType, PlayState::direction, PlayState::draw_flip, PlayState::dropped_file, ELEM, ListBase::first, float(), PlayState::fontid, PlayState::fstep, g_WS, GHOST_ActivateWindowDrawingContext(), GHOST_GetCursorPosition(), GHOST_GetEventData(), GHOST_GetEventType(), GHOST_kButtonMaskLeft, GHOST_kButtonMaskMiddle, GHOST_kButtonMaskRight, GHOST_kDragnDropTypeFilenames, GHOST_kEventButtonDown, GHOST_kEventButtonUp, GHOST_kEventCursorMove, GHOST_kEventDraggingDropDone, GHOST_kEventKeyDown, GHOST_kEventKeyUp, GHOST_kEventQuitRequest, GHOST_kEventWindowActivate, GHOST_kEventWindowClose, GHOST_kEventWindowDeactivate, GHOST_kEventWindowMove, GHOST_kEventWindowSize, GHOST_kKey0, GHOST_kKey1, GHOST_kKey2, GHOST_kKey3, GHOST_kKey4, GHOST_kKey5, GHOST_kKey6, GHOST_kKey7, GHOST_kKey8, GHOST_kKey9, GHOST_kKeyA, GHOST_kKeyDownArrow, GHOST_kKeyEnter, GHOST_kKeyEqual, GHOST_kKeyEsc, GHOST_kKeyF, GHOST_kKeyI, GHOST_kKeyLeftArrow, GHOST_kKeyMinus, GHOST_kKeyNumpad0, GHOST_kKeyNumpad1, GHOST_kKeyNumpad2, GHOST_kKeyNumpad3, GHOST_kKeyNumpad4, GHOST_kKeyNumpad5, GHOST_kKeyNumpad6, GHOST_kKeyNumpad7, GHOST_kKeyNumpad8, GHOST_kKeyNumpad9, GHOST_kKeyNumpadEnter, GHOST_kKeyNumpadMinus, GHOST_kKeyNumpadPeriod, GHOST_kKeyNumpadPlus, GHOST_kKeyNumpadSlash, GHOST_kKeyP, GHOST_kKeyPeriod, GHOST_kKeyPlus, GHOST_kKeyRightArrow, GHOST_kKeySlash, GHOST_kKeySpace, GHOST_kKeyUpArrow, GHOST_ScreenToClient(), WindowStateGlobal::ghost_system, WindowStateGlobal::ghost_window, PlayState::go, GPU_scissor(), GPU_viewport(), PlayAnimPict::ibuf, PlayState::ibufx, PlayState::ibufy, PlayState::indicator, GHOST_TEventKeyData::key, ListBase::last, PlayState::loading, MIN2, ImBuf::name, PlayAnimPict::next, PlayState::next_frame, PlayState::noskip, NULL, PlayState::once, picsbase, PlayState::picture, PlayState::pingpong, playanim_event_qual_update(), playanim_gl_matrix(), playanim_toscreen(), playanim_window_get_size(), playanim_window_zoom(), ptottime, pupdate_time(), WindowStateGlobal::qual, PlayState::sstep, PlayState::stopped, GHOST_TStringArray::strings, swaptime, tag_change_frame(), type, update_sound_fps(), PlayState::wait2, PlayState::win_x, PlayState::win_y, WS_QUAL_CTRL, WS_QUAL_LMOUSE, WS_QUAL_MMOUSE, WS_QUAL_MOUSE, WS_QUAL_RMOUSE, WS_QUAL_SHIFT, GHOST_TEventCursorData::x, GHOST_TEventCursorData::y, and PlayState::zoom.

Referenced by wm_main_playanim_intern().

◆ ibuf_from_picture()

static ImBuf* ibuf_from_picture ( PlayAnimPict pic)
static

◆ ocio_transform_ibuf()

static void* ocio_transform_ibuf ( PlayState ps,
ImBuf ibuf,
bool r_glsl_used,
eGPUTextureFormat r_format,
eGPUDataFormat r_data,
void **  r_buffer_cache_handle 
)
static

◆ playanim_event_qual_update()

static void playanim_event_qual_update ( void  )
static

Definition at line 213 of file wm_playanim.c.

Referenced by ghost_event_proc().

◆ playanim_gl_matrix()

static void playanim_gl_matrix ( void  )
static

Definition at line 205 of file wm_playanim.c.

References GPU_matrix_ortho_set().

Referenced by ghost_event_proc(), and wm_main_playanim_intern().

◆ playanim_step()

static PlayAnimPict* playanim_step ( PlayAnimPict playanim,
int  step 
)
static

Definition at line 363 of file wm_playanim.c.

References PlayAnimPict::next, and PlayAnimPict::prev.

Referenced by wm_main_playanim_intern().

◆ playanim_toscreen()

static void playanim_toscreen ( PlayState ps,
PlayAnimPict picture,
struct ImBuf ibuf,
int  fontid,
int  fstep 
)
static

◆ playanim_window_get_size()

static void playanim_window_get_size ( int *  r_width,
int *  r_height 
)
static

◆ playanim_window_open()

static void playanim_window_open ( const char *  title,
int  posx,
int  posy,
int  sizex,
int  sizey 
)
static

◆ playanim_window_zoom()

static void playanim_window_zoom ( struct PlayState ps,
const float  zoom_offset 
)
static

◆ pupdate_time()

static int pupdate_time ( void  )
static

◆ tag_change_frame()

static void tag_change_frame ( PlayState ps,
int  cx 
)
static

Definition at line 808 of file wm_playanim.c.

References PlayState::frame_cursor_x, and PlayState::need_frame_update.

Referenced by ghost_event_proc().

◆ update_sound_fps()

static void update_sound_fps ( void  )
static

Definition at line 796 of file wm_playanim.c.

References swaptime.

Referenced by change_frame(), ghost_event_proc(), and wm_main_playanim_intern().

◆ WM_main_playanim()

void WM_main_playanim ( int  argc,
const char **  argv 
)

Definition at line 1846 of file wm_playanim.c.

References NULL, and wm_main_playanim_intern().

Referenced by arg_handle_playback_mode().

◆ wm_main_playanim_intern()

static char* wm_main_playanim_intern ( int  argc,
const char **  argv 
)
static
Returns
The a path used to restart the animation player or NULL to exit.

Definition at line 1387 of file wm_playanim.c.

References PlayAnimPict::anim, BLF_exit(), BLF_init(), BLF_load_font_stack(), BLF_load_mono_default(), BLF_size(), BLI_freelistN(), BLI_pophead(), BLI_strncpy(), BLI_system_backtrace(), build_pict_list(), change_frame(), CLAMP, COLOR_ROLE_DEFAULT_BYTE, DEG_free_node_types(), PlayState::direction, ColorManagedDisplaySettings::display_device, PlayState::display_settings, double(), PlayState::draw_flip, PlayState::dropped_file, FILE_MAX, ListBase::first, PlayState::fontid, frame_cache_add(), frame_cache_limit_apply(), PlayAnimPict::frame_cache_node, frame_cache_touch(), fromdisk, PlayState::fstep, ImBuf::ftype, g_frame_cache, g_WS, GHOST_AddEventConsumer(), GHOST_CreateEventConsumer(), GHOST_CreateSystem(), GHOST_DispatchEvents(), GHOST_DisposeWindow(), ghost_event_proc(), GHOST_GetMainDisplayDimensions(), GHOST_ProcessEvents(), GHOST_SetBacktraceHandler(), GHOST_SetTitle(), GHOST_SwapWindowBuffers(), WindowStateGlobal::ghost_system, WindowStateGlobal::ghost_window, PlayState::go, GPU_clear_color(), WindowStateGlobal::gpu_context, GPU_context_active_set(), GPU_context_create(), GPU_context_discard(), GPU_exit(), GPU_init(), GPU_scissor(), GPU_viewport(), IB_rect, PlayAnimPict::ibuf, ibuf_from_picture(), PlayState::ibufx, PlayState::ibufy, IMB_anim_absolute(), IMB_anim_get_fps(), IMB_close_anim(), IMB_colormanagement_init_default_view_settings(), IMB_colormanagement_role_colorspace_name_get(), IMB_exit(), IMB_freeImBuf(), IMB_FTYPE_NONE, IMB_isanim(), IMB_ispic(), IMB_loadiffname(), IMB_open_anim(), IMB_PROXY_NONE, IMB_TC_NONE, PlayState::indicator, ListBase::last, PlayState::loading, max_ii(), MAXFRAME, PlayAnimPict::mem, MEM_freeN, MEM_get_memory_blocks_in_use, MEM_printmemlist, ImBuf::name, PlayAnimPict::name, PlayAnimPict::next, PlayState::next_frame, PlayState::noskip, NULL, PlayState::once, picsbase, PlayState::picture, PIL_sleep_ms(), PlayState::pingpong, playanim_gl_matrix(), playanim_step(), playanim_toscreen(), playanim_window_get_size(), playanim_window_open(), PlayAnimPict::prev, ptottime, pupdate_time(), PlayState::sstep, PlayState::stopped, STRNCPY, swaptime, totblock, update_sound_fps(), PlayState::view_settings, PlayState::wait2, PlayState::win_x, PlayState::win_y, ImBuf::x, ImBuf::y, and PlayState::zoom.

Referenced by WM_main_playanim().

Variable Documentation

◆ fromdisk

bool fromdisk = false
static

Definition at line 258 of file wm_playanim.c.

Referenced by build_pict_list_ex(), and wm_main_playanim_intern().

◆ 

struct { ... } g_frame_cache
Initial value:
= {
.pics = {NULL, NULL},
.pics_len = 0,
.pics_size_in_memory = 0,
.memory_limit = 0,
}

Referenced by frame_cache_add(), frame_cache_limit_apply(), frame_cache_limit_exceeded(), frame_cache_remove(), frame_cache_touch(), and wm_main_playanim_intern().

◆ g_WS

struct WindowStateGlobal g_WS = {NULL}
static

◆ memory_limit

size_t memory_limit

Optionally limit the amount of memory used for cache (in bytes), ignored when zero.

Definition at line 273 of file wm_playanim.c.

Referenced by BKE_undosys_stack_limit_steps_and_memory(), and ED_undo_push().

◆ pics

struct ListBase pics

A list of LinkData nodes referencing PlayAnimPict to track cached frames.

Definition at line 252 of file wm_playanim.c.

◆ pics_len

int pics_len

Number if elements in pics.

Definition at line 269 of file wm_playanim.c.

◆ pics_size_in_memory

size_t pics_size_in_memory

Keep track of memory used by #g_frame_cache.pics when g_frame_cache.memory_limit != 0.

Definition at line 271 of file wm_playanim.c.

◆ picsbase

struct ListBase picsbase = {NULL, NULL}
static

◆ ptottime

double ptottime = 0.0
static

◆ swaptime

double swaptime = 0.04
static