Blender V5.0
wm_playanim.cc File Reference
#include <algorithm>
#include <cerrno>
#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_string_utf8.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 "MOV_read.hh"
#include "MOV_util.hh"
#include "BKE_blender.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 "DNA_scene_types.h"
#include "DNA_userdef_types.h"
#include "BLF_api.hh"
#include "GHOST_C-api.h"
#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, blender::gpu::TextureFormat *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 std::optional< int > wm_main_playanim_intern (int argc, const char **argv, PlayArgs *args_next)
int 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 = {"image"}
static const char * message_prefix = "Animation Player"
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 91 of file wm_playanim.cc.

Referenced by frame_cache_limit_exceeded().

◆ USE_FRAME_CACHE_LIMIT

#define USE_FRAME_CACHE_LIMIT

Definition at line 89 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 165 of file wm_playanim.cc.

◆ WS_QUAL_CTRL

#define WS_QUAL_CTRL   (WS_QUAL_LCTRL | WS_QUAL_RCTRL)

Definition at line 168 of file wm_playanim.cc.

Referenced by ghost_event_proc().

◆ WS_QUAL_MOUSE

#define WS_QUAL_MOUSE   (WS_QUAL_LMOUSE | WS_QUAL_MMOUSE | WS_QUAL_RMOUSE)

Definition at line 172 of file wm_playanim.cc.

Referenced by ghost_event_proc().

◆ WS_QUAL_SHIFT

#define WS_QUAL_SHIFT   (WS_QUAL_LSHIFT | WS_QUAL_RSHIFT)

Definition at line 162 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 159 of file wm_playanim.cc.

Function Documentation

◆ buffer_from_filepath()

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

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

Referenced by build_pict_list_from_image_sequence().

◆ build_pict_list()

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()

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()

void frame_cache_limit_apply ( ImBuf * ibuf_keep)
static

◆ frame_cache_limit_exceeded()

bool frame_cache_limit_exceeded ( )
static

◆ frame_cache_remove()

◆ frame_cache_touch()

void frame_cache_touch ( PlayAnimPict * pic)
static

◆ ghost_event_proc()

bool ghost_event_proc ( GHOST_EventHandle ghost_event,
GHOST_TUserDataPtr ps_void_ptr )
static

Definition at line 1159 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(), i, PlayAnimPict::ibuf, PlayState::ibuf_size, GHOST_TEventKeyData::key, ListBase::last, PlayState::loading, MEM_malloc_arrayN(), 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_MOUSE, WS_QUAL_RMOUSE, WS_QUAL_SHIFT, GHOST_TEventCursorData::x, GHOST_TEventCursorData::y, and PlayState::zoom.

Referenced by wm_ghost_init(), and wm_main_playanim_intern().

◆ ibuf_from_picture()

◆ ocio_transform_ibuf()

◆ playanim_audio_resume()

void playanim_audio_resume ( PlayState & ps)
static

◆ playanim_audio_stop()

void playanim_audio_stop ( PlayState & )
static

Definition at line 1149 of file wm_playanim.cc.

Referenced by ghost_event_proc().

◆ playanim_change_frame()

◆ playanim_change_frame_tag()

void playanim_change_frame_tag ( PlayState & ps,
int cx )
static

Definition at line 1063 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()

void playanim_gpu_matrix ( )
static

Definition at line 307 of file wm_playanim.cc.

References GPU_matrix_ortho_set().

Referenced by ghost_event_proc(), and wm_main_playanim_intern().

◆ playanim_step()

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

Definition at line 482 of file wm_playanim.cc.

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

Referenced by wm_main_playanim_intern().

◆ playanim_toscreen()

◆ playanim_toscreen_ex()

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 665 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_SwapWindowBufferAcquire(), GHOST_SwapWindowBufferRelease(), GPU_backend_get_type(), GPU_BACKEND_METAL, GPU_blend(), GPU_BLEND_ALPHA, GPU_BLEND_NONE, GPU_clear_color(), GhostData::gpu_context, GPU_context_active_get(), GPU_context_active_set(), GPU_context_begin_frame(), GPU_context_end_frame(), 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(), 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()

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()

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

◆ pupdate_time()

int pupdate_time ( )
static

◆ update_sound_fps()

void update_sound_fps ( )
static

◆ WM_main_playanim()

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

◆ wm_main_playanim_intern()

std::optional< int > 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 1705 of file wm_playanim.cc.

References PlayAnimPict::anim, PlayArgs::argc, PlayState::argc_next, PlayArgs::argv, PlayState::argv_next, 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, COLOR_ROLE_DEFAULT_BYTE, PlayState::direction, PlayState::display_ctx, ColorManagedDisplaySettings::display_device, PlayDisplayContext::display_settings, PlayState::draw_flip, PlayAnimPict::error_message, ImBuf::fileframe, ImBuf::filepath, PlayAnimPict::filepath, ListBase::first, PlayState::font_id, PlayState::font_size, PlayAnimPict::frame, frame_cache_add(), frame_cache_limit_apply(), PlayAnimPict::frame_cache_node, frame_cache_touch(), PlayState::frame_step, ImBuf::ftype, g_frame_cache, g_playanim, GHOST_AddEventConsumer(), GHOST_CreateEventConsumer(), GHOST_CreateSystem(), PlayState::ghost_data, GHOST_DispatchEvents(), GHOST_DisposeEventConsumer(), GHOST_DisposeSystem(), GHOST_DisposeWindow(), ghost_event_proc(), GHOST_ProcessEvents(), GHOST_RemoveEventConsumer(), GHOST_SetBacktraceHandler(), GHOST_SwapWindowBufferAcquire(), GHOST_SwapWindowBufferRelease(), GHOST_UseNativePixels(), GHOST_UseWindowFrame(), PlayState::go, GPU_backend_ghost_system_set(), GPU_backend_type_selection_detect(), GPU_clear_color(), GhostData::gpu_context, 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(), i, IB_byte_data, PlayAnimPict::ibuf, ibuf_from_picture(), PlayState::ibuf_size, IMB_colormanagement_init_untonemapped_view_settings(), IMB_colormanagement_role_colorspace_name_get(), IMB_exit(), IMB_freeImBuf(), IMB_FTYPE_NONE, IMB_init(), IMB_load_image_from_filepath(), IMB_PROXY_NONE, IMB_TC_NONE, IMB_test_image(), ListBase::last, PlayState::loading, max_ii(), MAXFRAME, PlayAnimPict::mem, MEM_freeN(), message_prefix, MOV_close(), MOV_decode_frame(), MOV_exit(), MOV_get_fps(), MOV_init(), MOV_is_movie_file(), MOV_open_file(), PlayAnimPict::next, PlayState::next_frame, PlayState::no_frame_skip, PlayState::once, PlayState::picsbase, PlayState::picture, PlayState::pingpong, playanim_change_frame(), playanim_gpu_matrix(), playanim_step(), playanim_toscreen(), playanim_window_font_scale_from_dpi(), playanim_window_open(), playanim_window_size_get(), PlayAnimPict::prev, printf, pupdate_time(), PlayState::show_frame_indicator, PlayState::single_step, PlayDisplayContext::size, PlayState::stopped, STRNCPY(), STRNCPY_UTF8, GhostData::system, PlayDisplayContext::ui_scale, UNLIKELY, update_sound_fps(), PlayDisplayContext::view_settings, PlayState::wait, GhostData::window, WM_init_window_frame_get(), ImBuf::x, ImBuf::y, and PlayState::zoom.

Referenced by WM_main_playanim().

Variable Documentation

◆ from_disk

bool from_disk

Definition at line 367 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 = {"image"}
static

Definition at line 94 of file wm_playanim.cc.

◆ memory_limit

size_t memory_limit

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

Definition at line 391 of file wm_playanim.cc.

Referenced by BKE_undosys_stack_limit_steps_and_memory(), and ED_undo_push().

◆ message_prefix

const char* message_prefix = "Animation Player"
static

Used in user viable messages.

Definition at line 97 of file wm_playanim.cc.

Referenced by wm_main_playanim_intern().

◆ pics

ListBase pics

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

Definition at line 385 of file wm_playanim.cc.

◆ pics_len

int pics_len

Number if elements in pics.

Definition at line 387 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 389 of file wm_playanim.cc.

◆ swap_time

double swap_time

Definition at line 368 of file wm_playanim.cc.

◆ total_time