Blender V4.3
wm_playanim.cc File Reference
#include <cerrno>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/times.h>
#include <sys/wait.h>
#include <unistd.h>
#include "MEM_guardedalloc.h"
#include "CLG_log.h"
#include "BLI_fileops.h"
#include "BLI_listbase.h"
#include "BLI_math_vector_types.hh"
#include "BLI_path_utils.hh"
#include "BLI_rect.h"
#include "BLI_string.h"
#include "BLI_system.h"
#include "BLI_time.h"
#include "BLI_utildefines.h"
#include "IMB_colormanagement.hh"
#include "IMB_imbuf.hh"
#include "IMB_imbuf_types.hh"
#include "BKE_image.hh"
#include "BIF_glutil.hh"
#include "GPU_context.hh"
#include "GPU_framebuffer.hh"
#include "GPU_immediate.hh"
#include "GPU_immediate_util.hh"
#include "GPU_init_exit.hh"
#include "GPU_matrix.hh"
#include "GPU_state.hh"
#include "BLF_api.hh"
#include "DNA_scene_types.h"
#include "GHOST_C-api.h"
#include "DEG_depsgraph.hh"
#include "wm_window_private.hh"
#include "WM_api.hh"

Go to the source code of this file.

Classes

struct  GhostData
 
struct  PlayArgs
 
struct  PlayDisplayContext
 
struct  PlayState
 
struct  PlayAnimPict
 

Macros

#define USE_FRAME_CACHE_LIMIT
 
#define PLAY_FRAME_CACHE_MAX   30
 
#define WS_QUAL_SHIFT   (WS_QUAL_LSHIFT | WS_QUAL_RSHIFT)
 
#define WS_QUAL_ALT   (WS_QUAL_LALT | WS_QUAL_RALT)
 
#define WS_QUAL_CTRL   (WS_QUAL_LCTRL | WS_QUAL_RCTRL)
 
#define WS_QUAL_MOUSE   (WS_QUAL_LMOUSE | WS_QUAL_MMOUSE | WS_QUAL_RMOUSE)
 
#define USE_IMB_CACHE
 

Enumerations

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

Functions

static void playanim_window_zoom (PlayState &ps, const float zoom_offset)
 
static bool playanim_window_font_scale_from_dpi (PlayState &ps)
 
static blender::int2 playanim_window_size_get (GHOST_WindowHandle ghost_window)
 
static void playanim_gpu_matrix ()
 
static void playanim_event_qual_update (GhostData &ghost_data)
 
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 ()
 
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 ()
 
static void * ocio_transform_ibuf (const PlayDisplayContext &display_ctx, ImBuf *ibuf, bool *r_glsl_used, eGPUTextureFormat *r_format, eGPUDataFormat *r_data, void **r_buffer_cache_handle)
 
static void draw_display_buffer (const PlayDisplayContext &display_ctx, ImBuf *ibuf, const rctf *canvas, const bool draw_flip[2])
 
static void playanim_toscreen_ex (GhostData &ghost_data, const PlayDisplayContext &display_ctx, const PlayAnimPict *picture, ImBuf *ibuf, const int font_id, const int frame_step, const float draw_zoom, const bool draw_flip[2], const float frame_indicator_factor)
 
static void playanim_toscreen_on_load (GhostData &ghost_data, const PlayDisplayContext &display_ctx, const PlayAnimPict *picture, ImBuf *ibuf)
 
static void playanim_toscreen (PlayState &ps, const PlayAnimPict *picture, ImBuf *ibuf)
 
static void build_pict_list_from_anim (ListBase &picsbase, GhostData &ghost_data, const PlayDisplayContext &display_ctx, const char *filepath_first, const int frame_offset)
 
static void build_pict_list_from_image_sequence (ListBase &picsbase, GhostData &ghost_data, const PlayDisplayContext &display_ctx, const char *filepath_first, const int frame_offset, const int totframes, const int frame_step, const bool *loading_p)
 
static void build_pict_list (ListBase &picsbase, GhostData &ghost_data, const PlayDisplayContext &display_ctx, const char *filepath_first, const int totframes, const int frame_step, bool *loading_p)
 
static void update_sound_fps ()
 
static void playanim_change_frame_tag (PlayState &ps, int cx)
 
static void playanim_change_frame (PlayState &ps)
 
static void playanim_audio_resume (PlayState &ps)
 
static void playanim_audio_stop (PlayState &)
 
static bool ghost_event_proc (GHOST_EventHandle ghost_event, GHOST_TUserDataPtr ps_void_ptr)
 
static GHOST_WindowHandle playanim_window_open (GHOST_SystemHandle ghost_system, const char *title, int posx, int posy, int sizex, int sizey)
 
static bool wm_main_playanim_intern (int argc, const char **argv, PlayArgs *args_next)
 
void WM_main_playanim (int argc, const char **argv)
 
Local Utilities
static bool buffer_from_filepath (const char *filepath, void **r_mem, size_t *r_size, char **r_error_message)
 

Variables

static CLG_LogRef LOG = {"wm.playanim"}
 
struct { 
 
   bool   from_disk 
 
   double   swap_time 
 
   double   total_time 
 
g_playanim 
 
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.cc.

Macro Definition Documentation

◆ PLAY_FRAME_CACHE_MAX

#define PLAY_FRAME_CACHE_MAX   30

Definition at line 86 of file wm_playanim.cc.

Referenced by frame_cache_limit_exceeded().

◆ USE_FRAME_CACHE_LIMIT

#define USE_FRAME_CACHE_LIMIT

Definition at line 84 of file wm_playanim.cc.

◆ USE_IMB_CACHE

#define USE_IMB_CACHE

◆ WS_QUAL_ALT

#define WS_QUAL_ALT   (WS_QUAL_LALT | WS_QUAL_RALT)

Definition at line 158 of file wm_playanim.cc.

◆ WS_QUAL_CTRL

#define WS_QUAL_CTRL   (WS_QUAL_LCTRL | WS_QUAL_RCTRL)

Definition at line 161 of file wm_playanim.cc.

Referenced by ghost_event_proc().

◆ WS_QUAL_MOUSE

Definition at line 165 of file wm_playanim.cc.

◆ WS_QUAL_SHIFT

#define WS_QUAL_SHIFT   (WS_QUAL_LSHIFT | WS_QUAL_RSHIFT)

Definition at line 155 of file wm_playanim.cc.

Referenced by ghost_event_proc(), and playanim_toscreen().

Enumeration Type Documentation

◆ eWS_Qual

enum eWS_Qual

Use a flag to store held modifiers & mouse buttons.

Enumerator
WS_QUAL_LSHIFT 
WS_QUAL_RSHIFT 
WS_QUAL_LALT 
WS_QUAL_RALT 
WS_QUAL_LCTRL 
WS_QUAL_RCTRL 
WS_QUAL_LMOUSE 
WS_QUAL_MMOUSE 
WS_QUAL_RMOUSE 

Definition at line 152 of file wm_playanim.cc.

Function Documentation

◆ buffer_from_filepath()

static bool buffer_from_filepath ( const char * filepath,
void ** r_mem,
size_t * r_size,
char ** r_error_message )
static
Parameters
filepathThe file path to read into memory.
r_memOptional, when nullptr, don't allocate memory (just set the size).
r_sizeThe file-size of filepath.

Definition at line 104 of file wm_playanim.cc.

References BLI_file_descriptor_size(), BLI_open(), BLI_read(), BLI_sprintfN(), MEM_mallocN, MEM_SAFE_FREE, O_BINARY, PRId64, PRIu64, size(), and UNLIKELY.

Referenced by build_pict_list_from_image_sequence().

◆ build_pict_list()

static void build_pict_list ( ListBase & picsbase,
GhostData & ghost_data,
const PlayDisplayContext & display_ctx,
const char * filepath_first,
const int totframes,
const int frame_step,
bool * loading_p )
static

◆ build_pict_list_from_anim()

static void build_pict_list_from_anim ( ListBase & picsbase,
GhostData & ghost_data,
const PlayDisplayContext & display_ctx,
const char * filepath_first,
const int frame_offset )
static

◆ build_pict_list_from_image_sequence()

◆ draw_display_buffer()

◆ frame_cache_add()

◆ frame_cache_limit_apply()

static void frame_cache_limit_apply ( ImBuf * ibuf_keep)
static

◆ frame_cache_limit_exceeded()

static bool frame_cache_limit_exceeded ( )
static

◆ 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 ghost_event,
GHOST_TUserDataPtr ps_void_ptr )
static

Definition at line 1147 of file wm_playanim.cc.

References PlayState::argc_next, PlayState::argv_next, BLI_strdup(), GHOST_TEventButtonData::button, GHOST_TStringArray::count, data, GHOST_TEventDragnDropData::data, GHOST_TEventDragnDropData::dataType, PlayState::direction, PlayState::display_ctx, PlayState::draw_flip, ELEM, ImBuf::filepath, ListBase::first, float, PlayState::frame_step, g_playanim, GHOST_ActivateWindowDrawingContext(), PlayState::ghost_data, 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_kEventWindowDPIHintChanged, 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_kSuccess, GHOST_ScreenToClient(), ghost_system, PlayState::go, GPU_scissor(), GPU_viewport(), PlayAnimPict::ibuf, PlayState::ibuf_size, GHOST_TEventKeyData::key, ListBase::last, PlayState::loading, MEM_mallocN, PlayState::next_frame, PlayState::no_frame_skip, PlayState::once, PlayState::picsbase, PlayState::picture, PlayState::pingpong, playanim_audio_resume(), playanim_audio_stop(), playanim_change_frame_tag(), playanim_event_qual_update(), playanim_gpu_matrix(), playanim_toscreen(), playanim_window_font_scale_from_dpi(), playanim_window_size_get(), playanim_window_zoom(), printf, pupdate_time(), GhostData::qual, PlayState::show_frame_indicator, PlayState::single_step, PlayDisplayContext::size, PlayState::stopped, GHOST_TStringArray::strings, GhostData::system, update_sound_fps(), PlayState::wait, GhostData::window, WS_QUAL_CTRL, WS_QUAL_LMOUSE, WS_QUAL_MMOUSE, WS_QUAL_RMOUSE, WS_QUAL_SHIFT, GHOST_TEventCursorData::x, GHOST_TEventCursorData::y, and PlayState::zoom.

Referenced by wm_main_playanim_intern().

◆ ibuf_from_picture()

◆ ocio_transform_ibuf()

◆ playanim_audio_resume()

static void playanim_audio_resume ( PlayState & ps)
static

◆ playanim_audio_stop()

static void playanim_audio_stop ( PlayState & )
static

Definition at line 1137 of file wm_playanim.cc.

Referenced by ghost_event_proc().

◆ playanim_change_frame()

◆ playanim_change_frame_tag()

static void playanim_change_frame_tag ( PlayState & ps,
int cx )
static

Definition at line 1051 of file wm_playanim.cc.

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

Referenced by ghost_event_proc().

◆ playanim_event_qual_update()

◆ playanim_gpu_matrix()

static void playanim_gpu_matrix ( )
static

Definition at line 300 of file wm_playanim.cc.

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 474 of file wm_playanim.cc.

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

Referenced by wm_main_playanim_intern().

◆ playanim_toscreen()

◆ playanim_toscreen_ex()

static void playanim_toscreen_ex ( GhostData & ghost_data,
const PlayDisplayContext & display_ctx,
const PlayAnimPict * picture,
ImBuf * ibuf,
const int font_id,
const int frame_step,
const float draw_zoom,
const bool draw_flip[2],
const float frame_indicator_factor )
static
Parameters
font_idID of the font to display (-1 when no text should be displayed).
frame_stepFrame step (may be used in text display).
draw_zoomDefault to 1.0 (no zoom).
draw_flipX/Y flipping (ignored when null).
frame_indicator_factorDisplay a vertical frame-indicator (ignored when -1).

Definition at line 657 of file wm_playanim.cc.

References BLF_ASPECT, BLF_aspect(), BLF_color4f(), BLF_draw(), BLF_enable(), BLF_position(), BLI_rctf_init(), CLAMP, draw_display_buffer(), PlayAnimPict::error_message, FILE_MAX, PlayAnimPict::filepath, g_playanim, GHOST_ActivateWindowDrawingContext(), GHOST_SwapWindowBuffers(), GPU_backend_get_type(), GPU_BACKEND_METAL, GPU_blend(), GPU_BLEND_ALPHA, GPU_BLEND_NONE, GPU_clear_color(), GPU_COMP_F32, GhostData::gpu_context, GPU_context_active_get(), GPU_context_active_set(), GPU_FETCH_FLOAT, GPU_flush(), GPU_matrix_identity_projection_set(), GPU_matrix_identity_set(), GPU_matrix_pop(), GPU_matrix_pop_projection(), GPU_matrix_push(), GPU_matrix_push_projection(), GPU_matrix_scale_2f(), GPU_matrix_translate_2f(), GPU_PRIM_LINES, GPU_render_begin(), GPU_render_end(), GPU_render_step(), GPU_SHADER_3D_UNIFORM_COLOR, GPU_vertformat_attr_add(), imm_draw_box_checker_2d_ex(), immBegin(), immBindBuiltinProgram(), immEnd(), immUnbindProgram(), immUniformColor3ub(), immVertex2f(), immVertexFormat(), int, label, ImBuf::planes, playanim_window_size_get(), pos, pupdate_time(), PlayDisplayContext::size, SNPRINTF, PlayDisplayContext::ui_scale, GhostData::window, ImBuf::x, and ImBuf::y.

Referenced by playanim_toscreen(), and playanim_toscreen_on_load().

◆ playanim_toscreen_on_load()

static void playanim_toscreen_on_load ( GhostData & ghost_data,
const PlayDisplayContext & display_ctx,
const PlayAnimPict * picture,
ImBuf * ibuf )
static

◆ playanim_window_font_scale_from_dpi()

◆ playanim_window_open()

◆ playanim_window_size_get()

◆ playanim_window_zoom()

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

◆ pupdate_time()

static int pupdate_time ( )
static

◆ update_sound_fps()

static void update_sound_fps ( )
static

◆ WM_main_playanim()

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

◆ wm_main_playanim_intern()

static bool wm_main_playanim_intern ( int argc,
const char ** argv,
PlayArgs * args_next )
static
Returns
True when args_next is filled with arguments used to re-run this function (used for drag & drop).

Definition at line 1688 of file wm_playanim.cc.

References PlayArgs::argc, PlayArgs::argv, BLF_exit(), BLF_init(), BLF_load_mono_default(), BLI_freelistN(), BLI_listbase_is_empty(), BLI_pophead(), BLI_system_backtrace(), BLI_time_sleep_ms(), build_pict_list(), CLAMP, CLOG_WARN, COLOR_ROLE_DEFAULT_BYTE, DEG_free_node_types(), double(), ImBuf::filepath, frame_cache_add(), frame_cache_limit_apply(), frame_cache_touch(), ImBuf::ftype, g_frame_cache, g_playanim, GHOST_AddEventConsumer(), GHOST_CreateEventConsumer(), GHOST_CreateSystem(), GHOST_DispatchEvents(), GHOST_DisposeEventConsumer(), GHOST_DisposeSystem(), GHOST_DisposeWindow(), ghost_event_proc(), GHOST_ProcessEvents(), GHOST_RemoveEventConsumer(), GHOST_SetBacktraceHandler(), GHOST_SwapWindowBuffers(), GHOST_UseNativePixels(), PlayState::go, GPU_backend_ghost_system_set(), GPU_backend_type_selection_detect(), GPU_clear_color(), GPU_context_active_get(), GPU_context_active_set(), GPU_context_create(), GPU_context_discard(), GPU_exit(), GPU_init(), GPU_render_begin(), GPU_render_end(), GPU_render_step(), GPU_scissor(), GPU_viewport(), IB_rect, ibuf_from_picture(), 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_ffmpeg_init(), IMB_freeImBuf(), IMB_FTYPE_NONE, IMB_init(), IMB_isanim(), IMB_ispic(), IMB_loadiffname(), IMB_open_anim(), IMB_PROXY_NONE, IMB_TC_NONE, LOG, max_ii(), MAXFRAME, MEM_freeN(), MEM_get_memory_blocks_in_use, MEM_printmemlist, playanim_change_frame(), playanim_gpu_matrix(), playanim_step(), playanim_toscreen(), playanim_window_font_scale_from_dpi(), playanim_window_open(), playanim_window_size_get(), printf, pupdate_time(), STRNCPY, totblock, UNLIKELY, update_sound_fps(), ImBuf::x, and ImBuf::y.

Referenced by WM_main_playanim().

Variable Documentation

◆ from_disk

bool from_disk

Definition at line 360 of file wm_playanim.cc.

◆ [struct]

struct { ... } g_frame_cache

◆ [struct]

struct { ... } g_playanim
Initial value:
= {
false,
0.04,
0.0,
}

Various globals relating to playback.

Note
Avoid adding members here where possible, prefer PlayState or one of its members where possible.

Referenced by build_pict_list_from_image_sequence(), ghost_event_proc(), playanim_audio_resume(), playanim_change_frame(), playanim_toscreen_ex(), pupdate_time(), update_sound_fps(), and wm_main_playanim_intern().

◆ LOG

CLG_LogRef LOG = {"wm.playanim"}
static

◆ memory_limit

size_t memory_limit

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

Definition at line 384 of file wm_playanim.cc.

Referenced by BKE_undosys_stack_limit_steps_and_memory(), and ED_undo_push().

◆ pics

ListBase pics

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

Definition at line 378 of file wm_playanim.cc.

◆ pics_len

int pics_len

Number if elements in pics.

Definition at line 380 of file wm_playanim.cc.

◆ 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 382 of file wm_playanim.cc.

◆ swap_time

double swap_time

Definition at line 361 of file wm_playanim.cc.

◆ total_time