Blender V5.3
wm_playanim.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
14
15#include <algorithm>
16#include <cerrno>
17#include <cstdlib>
18#include <cstring>
19#include <fcntl.h>
20#include <sys/types.h>
21
22#ifndef WIN32
23# include <sys/times.h>
24# include <sys/wait.h>
25# include <unistd.h>
26#else
27# include <io.h>
28#endif
29#include "MEM_guardedalloc.h"
30
31#include "CLG_log.h"
32
33#include "BLI_enum_flags.hh"
34#include "BLI_fileops.hh"
35#include "BLI_listbase.hh"
37#include "BLI_path_utils.hh"
38#include "BLI_rect.hh"
39#include "BLI_string.hh"
40#include "BLI_string_utf8.hh"
41#include "BLI_system.hh"
42#include "BLI_time.hh"
43
45#include "IMB_imbuf.hh"
46#include "IMB_imbuf_types.hh"
47
48#include "MOV_read.hh"
49#include "MOV_util.hh"
50
51#include "BKE_blender.hh"
52#include "BKE_image.hh"
53#include "BKE_sound.hh"
54
55#include "BIF_glutil.hh"
56
57#include "GPU_context.hh"
58#include "GPU_framebuffer.hh"
59#include "GPU_immediate.hh"
60#include "GPU_immediate_util.hh"
61#include "GPU_init_exit.hh"
62#include "GPU_matrix.hh"
63#include "GPU_state.hh"
64
65#include "DNA_scene_types.h"
66#include "DNA_userdef_types.h"
67
68#include "BLF_api.hh"
69
71#include "GHOST_IEvent.hh"
72#include "GHOST_ISystem.hh"
73#include "GHOST_IWindow.hh"
74#include "GHOST_Types.hh"
75
76#include "wm_window_private.hh"
77
78#include "WM_api.hh" /* Only for #WM_main_playanim. */
79
80#ifdef WITH_AUDASPACE
81# include <devices/IHandle.h>
82# include <file/File.h>
83#endif
84
85namespace blender {
86
87#ifdef WITH_AUDASPACE
88static struct {
89 AUD_Sound source;
90 AUD_Handle playback_handle;
91 AUD_Handle scrub_handle;
92 AUD_Device audio_device;
93} g_audaspace = {nullptr};
94#endif
95
96/* Simple limiter to avoid flooding memory. */
97#define USE_FRAME_CACHE_LIMIT
98#ifdef USE_FRAME_CACHE_LIMIT
99# define PLAY_FRAME_CACHE_MAX 30
100#endif
101
102static CLG_LogRef LOG = {"image"};
103
105static const char *message_prefix = "Animation Player";
106static const char *playanim_window_title = "Blender Animation Player";
107
108struct PlayState;
109static void playanim_window_zoom(PlayState &ps, const float zoom_offset);
111
112/* -------------------------------------------------------------------- */
115
121static bool buffer_from_filepath(const char *filepath,
122 void **r_mem,
123 size_t *r_size,
124 char **r_error_message)
125{
126 errno = 0;
127 const int file = BLI_open(filepath, O_BINARY | O_RDONLY, 0);
128 if (file == -1) [[unlikely]] {
129 *r_error_message = BLI_sprintfN("failure '%s' to open file", strerror(errno));
130 return false;
131 }
132
133 bool success = false;
134 uchar *mem = nullptr;
135 const size_t size = BLI_file_descriptor_size(file);
136 int64_t size_read;
137 if (size == size_t(-1)) [[unlikely]] {
138 *r_error_message = BLI_sprintfN("failure '%s' to access size", strerror(errno));
139 }
140 else if (r_mem && UNLIKELY(!(mem = MEM_new_array_uninitialized<uchar>(size, __func__)))) {
141 *r_error_message = BLI_sprintfN("error allocating buffer %" PRIu64 " size", uint64_t(size));
142 }
143 else if (r_mem && UNLIKELY((size_read = BLI_read(file, mem, size)) != size)) {
144 *r_error_message = BLI_sprintfN(
145 "error '%s' reading file "
146 "(expected %" PRIu64 ", was %" PRId64 ")",
147 strerror(errno),
148 uint64_t(size),
149 size_read);
150 }
151 else {
152 *r_size = size;
153 if (r_mem) {
154 *r_mem = mem;
155 mem = nullptr; /* `r_mem` owns, don't free on exit. */
156 }
157 success = true;
158 }
159
160 MEM_SAFE_DELETE(mem);
161 close(file);
162 return success;
163}
164
166
169 WS_QUAL_LSHIFT = (1 << 0),
170 WS_QUAL_RSHIFT = (1 << 1),
171#define WS_QUAL_SHIFT (WS_QUAL_LSHIFT | WS_QUAL_RSHIFT)
172 WS_QUAL_LALT = (1 << 2),
173 WS_QUAL_RALT = (1 << 3),
174#define WS_QUAL_ALT (WS_QUAL_LALT | WS_QUAL_RALT)
175 WS_QUAL_LCTRL = (1 << 4),
176 WS_QUAL_RCTRL = (1 << 5),
177 WS_QUAL_LCMD = (1 << 6),
178 WS_QUAL_RCMD = (1 << 7),
179#define WS_QUAL_CTRL (WS_QUAL_LCTRL | WS_QUAL_RCTRL | WS_QUAL_LCMD | WS_QUAL_RCMD)
180 WS_QUAL_LMOUSE = (1 << 16),
181 WS_QUAL_MMOUSE = (1 << 17),
182 WS_QUAL_RMOUSE = (1 << 18),
184};
186
197
198struct PlayArgs {
199 int argc;
200 char **argv;
201};
202
211 float ui_scale;
214
215#ifdef WITH_GHOST_CSD
216 bool use_window_csd;
217 float ui_window_csd_alpha;
218#endif
219};
220
221struct PlayAnimPict;
222
294
295/* For debugging. */
296#if 0
297static void print_ps(const PlayState &ps)
298{
299 printf("ps:\n");
300 printf(" direction=%d,\n", int(ps.direction));
301 printf(" once=%d,\n", ps.once);
302 printf(" pingpong=%d,\n", ps.pingpong);
303 printf(" no_frame_skip=%d,\n", ps.no_frame_skip);
304 printf(" single_step=%d,\n", ps.single_step);
305 printf(" wait=%d,\n", ps.wait);
306 printf(" stopped=%d,\n", ps.stopped);
307 printf(" go=%d,\n\n", ps.go);
308 fflush(stdout);
309}
310#endif
311
313{
315 ghost_window->getClientBounds(bounds);
316
317 const float native_pixel_size = ghost_window->getNativePixelSize();
318 const int2 window_size = {
319 int(bounds.getWidth() * native_pixel_size),
320 int(bounds.getHeight() * native_pixel_size),
321 };
322
323 return window_size;
324}
325
327 const bool use_window_csd,
328 const int32_t cx,
329 const int32_t cy)
330{
331 const int2 window_size = playanim_window_size_get(ghost_window);
332 if (cx >= 0 && cx < window_size[0] && cy >= 0 && cy <= window_size[1]) {
333#ifdef WITH_GHOST_CSD
334 if (use_window_csd) {
335 const GHOST_CSD_Layout *csd_layout = nullptr; /* Not needed to get the "body" area. */
336 const GHOST_TWindowState state = ghost_window->getState();
338 const int fractional_scale[2] = {GHOST_CSD_DPI_FRACTIONAL_BASE, ghost_window->getDPIHint()};
339 const int csd_elems_num = WM_window_csd_layout_callback(
340 window_size, fractional_scale, state, csd_layout, csd_elems);
341 for (int i = 0; i < csd_elems_num; i += 1) {
342 GHOST_CSD_Elem &elem = csd_elems[i];
343 if (elem.type == GHOST_kCSDTypeBody) {
344 if (!((cx >= elem.bounds[0][0] && cx <= elem.bounds[0][1]) &&
345 (cy >= elem.bounds[1][0] && cy <= elem.bounds[1][1])))
346 {
347 return false;
348 }
349 break;
350 }
351 }
352 }
353#else
354 UNUSED_VARS(use_window_csd);
355#endif /* !WITH_GHOST_CSD */
356
357 return true;
358 }
359 return false;
360}
361
362#ifdef WITH_GHOST_CSD
363static int32_t wm_window_csd_layout_callback(const int32_t window_size[2],
364 const int32_t fractional_scale[2],
365 GHOST_TWindowState window_state,
366 const GHOST_CSD_Layout *csd_layout,
367 GHOST_CSD_Elem *csd_elems)
368{
370 window_size, fractional_scale, char(window_state), csd_layout, csd_elems);
371}
372
373static void playanim_window_csd_params_update(GhostData &ghost_data)
374{
375 GHOST_CSD_Params csd_params = {
376 /*layout_callback*/ wm_window_csd_layout_callback,
377
378 /*cursor_drag_threshold*/ 6 /* NOTE: `U.drag_threshold_mouse` isn't initialized. */,
379 /*cursor_double_click_ms*/ 350 /* NOTE: `U.dbl_click_time` isn't initialized. */,
380 /*resize_margin_size*/ WM_WINDOW_CSD_RESIZE_MARGIN_SIZE,
381 /* Square corners to avoid window transparency and because they won't be expected here
382 * anyway. */
383 /*corner_radius*/ 0,
384 };
385 ghost_data.system->setWindowCSD(csd_params);
386}
387#endif /* WITH_GHOST_CSD */
388
390{
391 /* Unified matrix, note it affects offset for drawing. */
392 /* NOTE: cannot use GPU_matrix_ortho_2d_set here because shader ignores. */
393 GPU_matrix_ortho_set(0.0f, 1.0f, 0.0f, 1.0f, -1.0, 1.0f);
394}
395
396/* Implementation. */
397static void playanim_event_qual_update(GhostData &ghost_data)
398{
399 bool val;
400
401 /* Shift. */
403 SET_FLAG_FROM_TEST(ghost_data.qual, val, WS_QUAL_LSHIFT);
404
406 SET_FLAG_FROM_TEST(ghost_data.qual, val, WS_QUAL_RSHIFT);
407
408 /* Control. */
410 SET_FLAG_FROM_TEST(ghost_data.qual, val, WS_QUAL_LCTRL);
411
413 SET_FLAG_FROM_TEST(ghost_data.qual, val, WS_QUAL_RCTRL);
414
415/* Command, equivalent to control on macOS. */
416#ifdef __APPLE__
418 SET_FLAG_FROM_TEST(ghost_data.qual, val, WS_QUAL_LCMD);
419
421 SET_FLAG_FROM_TEST(ghost_data.qual, val, WS_QUAL_RCMD);
422#endif
423
424 /* Alt. */
426 SET_FLAG_FROM_TEST(ghost_data.qual, val, WS_QUAL_LALT);
427
429 SET_FLAG_FROM_TEST(ghost_data.qual, val, WS_QUAL_RALT);
430}
431
435 size_t size;
437 const char *filepath;
442 int frame;
443
444#ifdef USE_FRAME_CACHE_LIMIT
448#endif
449};
450
456static struct {
457 bool from_disk;
458 double swap_time;
459 double total_time;
460#ifdef WITH_AUDASPACE
461 double fps_movie;
462#endif
463} g_playanim = {
464 /*from_disk*/ false,
465 /*swap_time*/ 0.04,
466 /*total_time*/ 0.0,
467#ifdef WITH_AUDASPACE
468 /*fps_movie*/ 0.0,
469#endif
471
472#ifdef USE_FRAME_CACHE_LIMIT
473static struct {
475 ListBaseT<LinkData> pics;
477 int pics_len;
479 size_t pics_size_in_memory;
481 size_t memory_limit;
482} g_frame_cache = {
483 /*pics*/ {nullptr, nullptr},
484 /*pics_len*/ 0,
485 /*pics_size_in_memory*/ 0,
486 /*memory_limit*/ 0,
488
490{
493 g_frame_cache.pics_len++;
494
495 if (g_frame_cache.memory_limit != 0) {
496 BLI_assert(pic->size_in_memory == 0);
498 g_frame_cache.pics_size_in_memory += pic->size_in_memory;
499 }
500}
501
503{
505 IMB_freeImBuf(pic->ibuf);
506 if (g_frame_cache.memory_limit != 0) {
507 BLI_assert(pic->size_in_memory != 0);
508 g_frame_cache.pics_size_in_memory -= pic->size_in_memory;
509 pic->size_in_memory = 0;
510 }
511 pic->ibuf = nullptr;
512 pic->frame_cache_node = nullptr;
514 g_frame_cache.pics_len--;
515}
516
517/* Don't free the current frame by moving it to the head of the list. */
524
526{
527 return g_frame_cache.memory_limit ?
528 (g_frame_cache.pics_size_in_memory > g_frame_cache.memory_limit) :
530}
531
532static void frame_cache_limit_apply(ImBuf *ibuf_keep)
533{
534 /* Really basic memory conservation scheme. Keep frames in a FIFO queue. */
535 LinkData *node = g_frame_cache.pics.last();
536 while (node && frame_cache_limit_exceeded()) {
537 PlayAnimPict *pic = static_cast<PlayAnimPict *>(node->data);
539
540 node = node->prev;
541 if (pic->ibuf && pic->ibuf != ibuf_keep) {
543 }
544 }
545}
546
547#endif /* USE_FRAME_CACHE_LIMIT */
548
550{
551 ImBuf *ibuf = nullptr;
552
553 if (pic->ibuf) {
554 ibuf = pic->ibuf;
555 }
556 else if (pic->anim) {
557 ibuf = MOV_decode_frame(pic->anim, pic->frame, IMB_PROXY_NONE);
558 }
559 else if (pic->mem) {
560 /* Use correct color-space here. */
562 pic->mem, pic->size, ImBufFlags::ByteData, pic->filepath, pic->filepath);
563 }
564 else {
565 /* Use correct color-space here. */
567 }
568
569 return ibuf;
570}
571
573{
574 if (step > 0) {
575 while (step-- && playanim) {
576 playanim = playanim->next;
577 }
578 }
579 else if (step < 0) {
580 while (step++ && playanim) {
581 playanim = playanim->prev;
582 }
583 }
584 return playanim;
585}
586
587static int pupdate_time()
588{
589 static double time_last;
590
591 double time = BLI_time_now_seconds();
592
593 g_playanim.total_time += (time - time_last);
594 time_last = time;
595 return (g_playanim.total_time < 0.0);
596}
597
598static const void *setup_draw_ocio_transform(const PlayDisplayContext &display_ctx,
599 const ImBuf *ibuf,
600 gpu::TextureFormat &r_texture_format,
601 eGPUDataFormat &r_data_format)
602{
603 r_texture_format = gpu::TextureFormat::Invalid;
604 r_data_format = GPU_DATA_FLOAT;
605 if (ibuf == nullptr || (ibuf->float_data() == nullptr && ibuf->byte_data() == nullptr)) {
606 return nullptr;
607 }
608
609 const ColorSpace *colorspace = ibuf->float_data() ? ibuf->float_buffer.colorspace :
612 &display_ctx.display_settings,
614 ibuf->dither,
615 false,
616 false))
617 {
618 return nullptr;
619 }
620
621 if (ibuf->float_data()) {
622 r_data_format = GPU_DATA_FLOAT;
623 if (ibuf->channels == 4) {
624 r_texture_format = gpu::TextureFormat::SFLOAT_16_16_16_16;
625 }
626 else if (ibuf->channels == 3) {
627 r_texture_format = gpu::TextureFormat::SFLOAT_16_16_16;
628 }
629 else if (ibuf->channels == 1) {
630 r_texture_format = gpu::TextureFormat::SFLOAT_16;
631 }
632 return ibuf->float_data();
633 }
634
635 r_data_format = GPU_DATA_UBYTE;
636 r_texture_format = gpu::TextureFormat::UNORM_8_8_8_8;
637 return ibuf->byte_data();
638}
639
640static void draw_display_buffer(const PlayDisplayContext &display_ctx,
641 const ImBuf *ibuf,
642 const rctf *canvas,
643 const bool draw_flip[2])
644{
645 /* Format needs to be created prior to any #immBindShader call.
646 * Do it here because OCIO binds its own shader. */
647 GPUVertFormat *imm_format = immVertexFormat();
648 uint pos = GPU_vertformat_attr_add(imm_format, "pos", gpu::VertAttrType::SFLOAT_32_32);
649 uint texCoord = GPU_vertformat_attr_add(imm_format, "texCoord", gpu::VertAttrType::SFLOAT_32_32);
650
651 gpu::TextureFormat texture_format;
652 eGPUDataFormat data_format;
653 const void *texture_data = setup_draw_ocio_transform(
654 display_ctx, ibuf, texture_format, data_format);
655 if (texture_data == nullptr) {
656 return;
657 }
658
659 /* NOTE: This may fail, especially for large images that exceed the GPU's texture size limit.
660 * Large images could be supported although this isn't so common for animation playback. */
662 "display_buf", ibuf->x, ibuf->y, 1, texture_format, GPU_TEXTURE_USAGE_SHADER_READ, nullptr);
663
664 if (texture) {
665 GPU_texture_update(texture, data_format, texture_data);
668 }
669
671
672 rctf preview;
673 BLI_rctf_init(&preview, 0.0f, 1.0f, 0.0f, 1.0f);
674 if (draw_flip[0]) {
675 std::swap(preview.xmin, preview.xmax);
676 }
677 if (draw_flip[1]) {
678 std::swap(preview.ymin, preview.ymax);
679 }
680
681 immAttr2f(texCoord, preview.xmin, preview.ymin);
682 immVertex2f(pos, canvas->xmin, canvas->ymin);
683
684 immAttr2f(texCoord, preview.xmin, preview.ymax);
685 immVertex2f(pos, canvas->xmin, canvas->ymax);
686
687 immAttr2f(texCoord, preview.xmax, preview.ymax);
688 immVertex2f(pos, canvas->xmax, canvas->ymax);
689
690 immAttr2f(texCoord, preview.xmax, preview.ymin);
691 immVertex2f(pos, canvas->xmax, canvas->ymin);
692
693 immEnd();
694
695 if (texture) {
698 }
699
701}
702
711static void playanim_toscreen_ex(GhostData &ghost_data,
712 const PlayDisplayContext &display_ctx,
713 const PlayAnimPict *picture,
714 const ImBuf *ibuf,
715 /* Run-time drawing arguments (not used on-load). */
716 const bool show_status,
717 const int font_id,
718 const int frame_step,
719 const float draw_zoom,
720 const bool draw_flip[2],
721 const float frame_indicator_factor)
722{
723 ghost_data.window->activateDrawingContext();
725
726 ghost_data.window->swapBufferAcquire();
727 GPUContext *restore_context = GPU_context_active_get();
728
731
732 GPU_clear_color(0.1f, 0.1f, 0.1f, 0.0f);
733
734 /* A null `ibuf` is an exceptional case and should almost never happen.
735 * if it does, this function displays a warning along with the file-path that failed. */
736 if (ibuf) {
737 /* Size within window. */
738 float span_x = (draw_zoom * ibuf->x) / float(display_ctx.size[0]);
739 float span_y = (draw_zoom * ibuf->y) / float(display_ctx.size[1]);
740
741 /* Offset within window. */
742 float offs_x = 0.5f * (1.0f - span_x);
743 float offs_y = 0.5f * (1.0f - span_y);
744
745 CLAMP(offs_x, 0.0f, 1.0f);
746 CLAMP(offs_y, 0.0f, 1.0f);
747
748 /* Checkerboard for case alpha. */
749 if (ibuf->can_contain_alpha()) {
751
753 offs_y,
754 offs_x + span_x,
755 offs_y + span_y,
756 float4{0.15, 0.15, 0.15, 1.0},
757 float4{0.20, 0.20, 0.20, 1.0},
758 8);
759 }
760 rctf canvas;
761 BLI_rctf_init(&canvas, offs_x, offs_x + span_x, offs_y, offs_y + span_y);
762
763 draw_display_buffer(display_ctx, ibuf, &canvas, draw_flip);
764
766 }
767
768 pupdate_time();
769
770 if (show_status && (font_id != -1) && (picture != nullptr)) {
771 const int font_margin = int(10 * display_ctx.ui_scale);
772 float fsizex_inv, fsizey_inv;
773 char label[32 + FILE_MAX];
774 if (ibuf) {
775 SNPRINTF(label, "%s | %.2f frames/s", picture->filepath, frame_step / g_playanim.swap_time);
776 }
777 else {
778 SNPRINTF(label,
779 "%s | %s",
780 picture->filepath,
781 picture->error_message ? picture->error_message : "<unknown error>");
782 }
783
784 const int2 window_size = playanim_window_size_get(ghost_data.window);
785 fsizex_inv = 1.0f / window_size[0];
786 fsizey_inv = 1.0f / window_size[1];
787
788 BLF_color4f(font_id, 1.0, 1.0, 1.0, 1.0);
789
790 /* FIXME(@ideasman42): Font positioning doesn't work because the aspect causes the position
791 * to be rounded to zero, investigate making BLF support this,
792 * for now use GPU matrix API to adjust the text position. */
793#if 0
794 BLF_enable(font_id, BLF_ASPECT);
795 BLF_aspect(font_id, fsizex_inv, fsizey_inv, 1.0f);
796 BLF_position(font_id, font_margin * fsizex_inv, font_margin * fsizey_inv, 0.0f);
797 BLF_draw(font_id, label, sizeof(label));
798#else
800 GPU_matrix_scale_2f(fsizex_inv, fsizey_inv);
801 GPU_matrix_translate_2f(font_margin, font_margin);
802 BLF_position(font_id, 0, 0, 0.0f);
803 BLF_draw(font_id, label, sizeof(label));
805#endif
806 }
807
808 if (frame_indicator_factor != -1.0f) {
809 float fac = frame_indicator_factor;
810 fac = 2.0f * fac - 1.0f;
815
816 uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32);
817
819 immUniformColor3ub(0, 255, 0);
820
822 immVertex2f(pos, fac, -1.0f);
823 immVertex2f(pos, fac, 1.0f);
824 immEnd();
825
827
830 }
831
833
834#ifdef WITH_GHOST_CSD
835 if (display_ctx.use_window_csd && (display_ctx.ui_window_csd_alpha > 0.0f)) {
836 const GHOST_TWindowState state = ghost_data.window->getState();
839
840 const GHOST_CSD_Layout *csd_layout = &ghost_data.system->getWindowCSD_Layout();
841 const uint16_t dpi = ghost_data.window->getDPIHint();
842 const int2 window_size = playanim_window_size_get(ghost_data.window);
843 const bool is_active = true; /* Alpha is zero when inactive. */
844 const int font_size = 11; /* Un-scaled (same as default panel point size). */
845
846 const uchar text_color[3] = {255, 255, 255};
848 state,
849 csd_layout,
850 is_active,
851 dpi,
853 font_id,
854 font_size,
855 nullptr,
856 text_color,
857 display_ctx.ui_window_csd_alpha);
859
860 GPU_viewport(0, 0, window_size[0], window_size[1]);
861 GPU_scissor(0, 0, window_size[0], window_size[1]);
863 }
864 }
865#endif /* WITH_GHOST_CSD */
866
868 GPU_flush();
869 }
870
872 ghost_data.window->swapBufferRelease();
873 GPU_context_active_set(restore_context);
875}
876
877static void playanim_toscreen_on_load(GhostData &ghost_data,
878 const PlayDisplayContext &display_ctx,
879 const PlayAnimPict *picture,
880 const ImBuf *ibuf)
881{
882 const bool show_status = false;
883 const int font_id = -1; /* Don't draw text. */
884 const int frame_step = -1;
885 const float zoom = 1.0f;
886 const float frame_indicator_factor = -1.0f;
887 const bool draw_flip[2] = {false, false};
888
889 playanim_toscreen_ex(ghost_data,
890 display_ctx,
891 picture,
892 ibuf,
893 show_status,
894 font_id,
895 frame_step,
896 zoom,
897 draw_flip,
898 frame_indicator_factor);
899}
900
901static void playanim_toscreen(PlayState &ps, const PlayAnimPict *picture, const ImBuf *ibuf)
902{
903 float frame_indicator_factor = -1.0f;
904 if (ps.show_frame_indicator) {
905 const int frame_range = ps.picsbase.last()->frame - ps.picsbase.first()->frame;
906 if (frame_range > 0) {
907 frame_indicator_factor = float(double(picture->frame) / double(frame_range));
908 }
909 else {
910 BLI_assert_msg(ps.picsbase.is_single(), "Multiple frames without a valid range!");
911 }
912 }
913
914 bool show_status = false;
916 /* Always inform the user of an error, this should be an exceptional case. */
917 (ibuf == nullptr))
918 {
919 show_status = true;
920 }
921
922 BLI_assert(ps.loading == false);
924 ps.display_ctx,
925 picture,
926 ibuf,
927 show_status,
928 ps.font_id,
929 ps.frame_step,
930 ps.zoom,
931 ps.draw_flip,
932 frame_indicator_factor);
933}
934
935static void build_pict_list_from_anim(ListBaseT<PlayAnimPict> &picsbase,
936 GhostData &ghost_data,
937 const PlayDisplayContext &display_ctx,
938 const char *filepath_first,
939 const int frame_offset)
940{
941 /* OCIO_TODO: support different input color space. */
942 MovieReader *anim = MOV_open_file(filepath_first, ImBufFlags::Zero, 0, false, nullptr);
943 if (anim == nullptr) {
944 CLOG_WARN(&LOG, "couldn't open anim '%s'", filepath_first);
945 return;
946 }
947
948 ImBuf *ibuf = MOV_decode_frame(anim, 0, IMB_PROXY_NONE);
949 if (ibuf) {
950 playanim_toscreen_on_load(ghost_data, display_ctx, nullptr, ibuf);
951 IMB_freeImBuf(ibuf);
952 }
953
954 for (int pic = 0; pic < MOV_get_duration_frames(anim); pic++) {
956 picture->anim = anim;
957 picture->frame = pic + frame_offset;
958 picture->filepath = BLI_sprintfN("%s : %4.d", filepath_first, pic + 1);
959 BLI_addtail(&picsbase, picture);
960 }
961
962 const PlayAnimPict *picture = picsbase.last();
963 if (!(picture && picture->anim == anim)) {
964 MOV_close(anim);
965 CLOG_WARN(&LOG, "no frames added for: '%s'", filepath_first);
966 }
967}
968
969static void build_pict_list_from_image_sequence(ListBaseT<PlayAnimPict> &picsbase,
970 GhostData &ghost_data,
971 const PlayDisplayContext &display_ctx,
972 const char *filepath_first,
973 const int frame_offset,
974 const int totframes,
975 const int frame_step,
976 const bool *loading_p)
977{
978 /* Load images into cache until the cache is full,
979 * this resolves choppiness for images that are slow to load, see: #81751. */
980 bool fill_cache = (
981#ifdef USE_FRAME_CACHE_LIMIT
982 true
983#else
984 false
985#endif
986 );
987
988 int fp_framenr;
989 struct {
990 char head[FILE_MAX], tail[FILE_MAX];
991 ushort digits;
992 } fp_decoded;
993
994 char filepath[FILE_MAX];
995 STRNCPY(filepath, filepath_first);
996 fp_framenr = BLI_path_sequence_decode(filepath,
997 fp_decoded.head,
998 sizeof(fp_decoded.head),
999 fp_decoded.tail,
1000 sizeof(fp_decoded.tail),
1001 &fp_decoded.digits);
1002
1003 pupdate_time();
1004 g_playanim.total_time = 1.0;
1005
1006 for (int pic = 0; pic < totframes; pic++) {
1007 if (!IMB_test_image(filepath)) {
1008 break;
1009 }
1010
1011 bool has_error = false;
1012 char *error_message = nullptr;
1013 void *mem = nullptr;
1014 size_t size = -1;
1016 filepath, g_playanim.from_disk ? nullptr : &mem, &size, &error_message))
1017 {
1018 has_error = true;
1019 size = 0;
1020 }
1021
1022 PlayAnimPict *picture = MEM_new_zeroed<PlayAnimPict>("picture");
1023 picture->size = size;
1024 picture->mem = static_cast<uchar *>(mem);
1025 picture->filepath = BLI_strdup(filepath);
1026 picture->error_message = error_message;
1027 picture->frame = pic + frame_offset;
1028 BLI_addtail(&picsbase, picture);
1029
1030 pupdate_time();
1031
1032 const bool display_imbuf = g_playanim.total_time > 1.0;
1033
1034 if (has_error) {
1035 CLOG_WARN(&LOG,
1036 "Picture %s failed: %s",
1037 filepath,
1038 error_message ? error_message : "<unknown error>");
1039 }
1040 else if (display_imbuf || fill_cache) {
1041 /* OCIO_TODO: support different input color space. */
1042 ImBuf *ibuf = ibuf_from_picture(picture);
1043
1044 if (ibuf) {
1045 if (display_imbuf) {
1046 playanim_toscreen_on_load(ghost_data, display_ctx, picture, ibuf);
1047 }
1048#ifdef USE_FRAME_CACHE_LIMIT
1049 if (fill_cache) {
1050 picture->ibuf = ibuf;
1051 frame_cache_add(picture);
1052 fill_cache = !frame_cache_limit_exceeded();
1053 }
1054 else
1055#endif
1056 {
1057 IMB_freeImBuf(ibuf);
1058 }
1059 }
1060
1061 if (display_imbuf) {
1062 pupdate_time();
1063 g_playanim.total_time = 0.0;
1064 }
1065 }
1066
1067 /* Create a new file-path each time. */
1068 fp_framenr += frame_step;
1069 BLI_path_sequence_encode(filepath,
1070 sizeof(filepath),
1071 fp_decoded.head,
1072 fp_decoded.tail,
1073 fp_decoded.digits,
1074 fp_framenr);
1075
1076 while (ghost_data.system->processEvents(false)) {
1077 ghost_data.system->dispatchEvents();
1078 if (*loading_p == false) {
1079 break;
1080 }
1081 }
1082 }
1083}
1084
1085static void build_pict_list(ListBaseT<PlayAnimPict> &picsbase,
1086 GhostData &ghost_data,
1087 const PlayDisplayContext &display_ctx,
1088 const char *filepath_first,
1089 const int totframes,
1090 const int frame_step,
1091 bool *loading_p)
1092{
1093 *loading_p = true;
1094
1095 /* NOTE(@ideasman42): When loading many files (e.g. expanded from shell globing)
1096 * it's important the frame number increases each time. Otherwise playing `*.png`
1097 * in a directory will expand into many arguments, each calling this function adding
1098 * a frame that's set to zero. */
1099 const PlayAnimPict *picture_last = picsbase.last();
1100 const int frame_offset = picture_last ? (picture_last->frame + 1) : 0;
1101
1102 bool do_image_load = false;
1103 if (MOV_is_movie_file(filepath_first)) {
1104 build_pict_list_from_anim(picsbase, ghost_data, display_ctx, filepath_first, frame_offset);
1105
1106 if (picsbase.last_ == picture_last) {
1107 /* FFMPEG detected JPEG2000 as a video which would load with zero duration.
1108 * Resolve this by using images as a fallback when a video file has no frames to display. */
1109 do_image_load = true;
1110 }
1111 }
1112 else {
1113 do_image_load = true;
1114 }
1115
1116 if (do_image_load) {
1118 ghost_data,
1119 display_ctx,
1120 filepath_first,
1121 frame_offset,
1122 totframes,
1123 frame_step,
1124 loading_p);
1125 }
1126
1127 *loading_p = false;
1128}
1129
1130static void update_sound_fps()
1131{
1132#ifdef WITH_AUDASPACE
1133 if (g_audaspace.playback_handle) {
1134 /* Swap-time stores the 1.0/fps ratio. */
1135 double speed = 1.0 / (g_playanim.swap_time * g_playanim.fps_movie);
1136
1137 g_audaspace.playback_handle->setPitch(speed);
1138 }
1139#endif
1140}
1141
1142static void playanim_change_frame_tag(PlayState &ps, int cx)
1143{
1144 ps.need_frame_update = true;
1145 ps.frame_cursor_x = cx;
1146}
1147
1149{
1150 if (!ps.need_frame_update) {
1151 return;
1152 }
1154 return;
1155 }
1156
1157 const int2 window_size = playanim_window_size_get(ps.ghost_data.window);
1158 const int i_last = ps.picsbase.last()->frame;
1159 /* Without this the frame-indicator location isn't closest to the cursor. */
1160 const int correct_rounding = (window_size[0] / (i_last + 1)) / 2;
1161 const int i = clamp_i(
1162 (i_last * (ps.frame_cursor_x + correct_rounding)) / window_size[0], 0, i_last);
1163
1164#ifdef WITH_AUDASPACE
1165 if (g_audaspace.scrub_handle) {
1166 g_audaspace.scrub_handle->stop();
1167 g_audaspace.scrub_handle = nullptr;
1168 }
1169
1170 if (g_audaspace.playback_handle) {
1171 aud::Status status = g_audaspace.playback_handle->getStatus();
1172 if (status != aud::STATUS_PLAYING) {
1173 g_audaspace.playback_handle->stop();
1174 g_audaspace.playback_handle = bke::sound_device_play(g_audaspace.audio_device,
1175 g_audaspace.source);
1176 if (g_audaspace.playback_handle) {
1177 g_audaspace.playback_handle->seek(i / g_playanim.fps_movie);
1178 g_audaspace.scrub_handle = bke::sound_pause_after(g_audaspace.playback_handle,
1179 1.0 / g_playanim.fps_movie);
1180 }
1182 }
1183 else {
1184 g_audaspace.playback_handle->seek(i / g_playanim.fps_movie);
1185 g_audaspace.scrub_handle = bke::sound_pause_after(g_audaspace.playback_handle,
1186 1.0 / g_playanim.fps_movie);
1187 }
1188 }
1189 else if (g_audaspace.source) {
1190 g_audaspace.playback_handle = bke::sound_device_play(g_audaspace.audio_device,
1191 g_audaspace.source);
1192 if (g_audaspace.playback_handle) {
1193 g_audaspace.playback_handle->seek(i / g_playanim.fps_movie);
1194 g_audaspace.scrub_handle = bke::sound_pause_after(g_audaspace.playback_handle,
1195 1.0 / g_playanim.fps_movie);
1196 }
1198 }
1199#endif
1200
1201 ps.picture = static_cast<PlayAnimPict *>(BLI_findlink(&ps.picsbase, i));
1202 BLI_assert(ps.picture != nullptr);
1203
1204 ps.single_step = true;
1205 ps.wait = false;
1206 ps.next_frame = 0;
1207
1208 ps.need_frame_update = false;
1209}
1210
1212{
1213#ifdef WITH_AUDASPACE
1214 /* TODO: store in ps direct? */
1215 const int i = BLI_findindex(&ps.picsbase, ps.picture);
1216 if (g_audaspace.playback_handle) {
1217 g_audaspace.playback_handle->stop();
1218 }
1219 g_audaspace.playback_handle = bke::sound_device_play(g_audaspace.audio_device,
1220 g_audaspace.source);
1221 if (g_audaspace.playback_handle) {
1222 g_audaspace.playback_handle->seek(i / g_playanim.fps_movie);
1223 }
1225#else
1226 UNUSED_VARS(ps);
1227#endif
1228}
1229
1230static void playanim_audio_stop(PlayState & /*ps*/)
1231{
1232#ifdef WITH_AUDASPACE
1233 if (g_audaspace.playback_handle) {
1234 g_audaspace.playback_handle->stop();
1235 g_audaspace.playback_handle = nullptr;
1236 }
1237#endif
1238}
1239
1240static bool ghost_event_proc(const GHOST_IEvent *ghost_event, GHOST_TUserDataPtr ps_void_ptr)
1241{
1242 PlayState &ps = *static_cast<PlayState *>(ps_void_ptr);
1243 const GHOST_TEventType type = ghost_event->getType();
1244 GHOST_TEventDataPtr data = ghost_event->getData();
1245 /* Convert ghost event into value keyboard or mouse. */
1246 const int val = ELEM(type, GHOST_kEventKeyDown, GHOST_kEventButtonDown);
1247 GHOST_ISystem *ghost_system = ps.ghost_data.system;
1248 GHOST_IWindow *ghost_window = ps.ghost_data.window;
1249
1250 // print_ps(ps);
1251
1253
1254 /* First check if we're busy loading files. */
1255 if (ps.loading) {
1256 switch (type) {
1258 case GHOST_kEventKeyUp: {
1259 const GHOST_TEventKeyData *key_data = static_cast<const GHOST_TEventKeyData *>(data);
1260 switch (key_data->key) {
1261 case GHOST_kKeyEsc:
1262 ps.loading = false;
1263 break;
1264 default:
1265 break;
1266 }
1267 break;
1268 }
1269 default:
1270 break;
1271 }
1272 return true;
1273 }
1274
1275 if (ps.wait && ps.stopped == false) {
1276 ps.stopped = true;
1277 }
1278
1279 if (ps.wait) {
1280 pupdate_time();
1281 g_playanim.total_time = 0.0;
1282 }
1283
1284 switch (type) {
1286 case GHOST_kEventKeyUp: {
1287 const GHOST_TEventKeyData *key_data = static_cast<const GHOST_TEventKeyData *>(data);
1288 switch (key_data->key) {
1289 case GHOST_kKeyA:
1290 if (val) {
1292 }
1293 break;
1294 case GHOST_kKeyI:
1295 if (val) {
1297 }
1298 break;
1299 case GHOST_kKeyP:
1300 if (val) {
1301 ps.pingpong = !ps.pingpong;
1302 }
1303 break;
1304 case GHOST_kKeyF: {
1305 if (val) {
1306 int axis = (ps.ghost_data.qual & WS_QUAL_SHIFT) ? 1 : 0;
1307 ps.draw_flip[axis] = !ps.draw_flip[axis];
1308 }
1309 break;
1310 }
1311 case GHOST_kKey1:
1312 case GHOST_kKeyNumpad1:
1313 if (val) {
1314 g_playanim.swap_time = ps.frame_step / 60.0;
1316 }
1317 break;
1318 case GHOST_kKey2:
1319 case GHOST_kKeyNumpad2:
1320 if (val) {
1321 g_playanim.swap_time = ps.frame_step / 50.0;
1323 }
1324 break;
1325 case GHOST_kKey3:
1326 case GHOST_kKeyNumpad3:
1327 if (val) {
1328 g_playanim.swap_time = ps.frame_step / 30.0;
1330 }
1331 break;
1332 case GHOST_kKey4:
1333 case GHOST_kKeyNumpad4:
1334 if (ps.ghost_data.qual & WS_QUAL_SHIFT) {
1335 g_playanim.swap_time = ps.frame_step / 24.0;
1337 }
1338 else {
1339 g_playanim.swap_time = ps.frame_step / 25.0;
1341 }
1342 break;
1343 case GHOST_kKey5:
1344 case GHOST_kKeyNumpad5:
1345 if (val) {
1346 g_playanim.swap_time = ps.frame_step / 20.0;
1348 }
1349 break;
1350 case GHOST_kKey6:
1351 case GHOST_kKeyNumpad6:
1352 if (val) {
1353 g_playanim.swap_time = ps.frame_step / 15.0;
1355 }
1356 break;
1357 case GHOST_kKey7:
1358 case GHOST_kKeyNumpad7:
1359 if (val) {
1360 g_playanim.swap_time = ps.frame_step / 12.0;
1362 }
1363 break;
1364 case GHOST_kKey8:
1365 case GHOST_kKeyNumpad8:
1366 if (val) {
1367 g_playanim.swap_time = ps.frame_step / 10.0;
1369 }
1370 break;
1371 case GHOST_kKey9:
1372 case GHOST_kKeyNumpad9:
1373 if (val) {
1374 g_playanim.swap_time = ps.frame_step / 6.0;
1376 }
1377 break;
1379 if (val) {
1380 ps.single_step = true;
1381 ps.wait = false;
1383
1384 if (ps.ghost_data.qual & WS_QUAL_SHIFT) {
1385 ps.picture = ps.picsbase.first();
1386 ps.next_frame = 0;
1387 }
1388 else {
1389 ps.next_frame = -1;
1390 }
1391 }
1392 break;
1394 if (val) {
1395 ps.wait = false;
1397
1398 if (ps.ghost_data.qual & WS_QUAL_SHIFT) {
1399 ps.next_frame = ps.direction = -1;
1400 }
1401 else {
1402 ps.next_frame = -10;
1403 ps.single_step = true;
1404 }
1405 }
1406 break;
1408 if (val) {
1409 ps.single_step = true;
1410 ps.wait = false;
1412
1413 if (ps.ghost_data.qual & WS_QUAL_SHIFT) {
1414 ps.picture = ps.picsbase.last();
1415 ps.next_frame = 0;
1416 }
1417 else {
1418 ps.next_frame = 1;
1419 }
1420 }
1421 break;
1422 case GHOST_kKeyUpArrow:
1423 if (val) {
1424 ps.wait = false;
1425 if (ps.ghost_data.qual & WS_QUAL_SHIFT) {
1426 ps.next_frame = ps.direction = 1;
1427 if (ps.single_step == false) {
1429 }
1430 }
1431 else {
1432 ps.next_frame = 10;
1433 ps.single_step = true;
1435 }
1436 }
1437 break;
1438
1439 case GHOST_kKeySlash:
1441 if (val) {
1442 if (ps.ghost_data.qual & WS_QUAL_SHIFT) {
1443 if (ps.picture && ps.picture->ibuf) {
1444 printf(" Name: %s | Speed: %.2f frames/s\n",
1445 ps.picture->ibuf->filepath.c_str(),
1446 ps.frame_step / g_playanim.swap_time);
1447 }
1448 }
1449 else {
1450 g_playanim.swap_time = ps.frame_step / 5.0;
1452 }
1453 }
1454 break;
1455 case GHOST_kKey0:
1456 case GHOST_kKeyNumpad0:
1457 if (val) {
1458 if (ps.once) {
1459 ps.once = ps.wait = false;
1460 }
1461 else {
1462 ps.picture = nullptr;
1463 ps.once = true;
1464 ps.wait = false;
1465 }
1466 }
1467 break;
1468
1469 case GHOST_kKeySpace:
1470 if (val) {
1471 if (ps.wait || ps.single_step) {
1472 ps.wait = ps.single_step = false;
1474 }
1475 else {
1476 ps.single_step = true;
1477 ps.wait = true;
1479 }
1480 }
1481 break;
1482 case GHOST_kKeyEnter:
1484 if (val) {
1485 ps.wait = ps.single_step = false;
1487 }
1488 break;
1489 case GHOST_kKeyPeriod:
1491 if (val) {
1492 if (ps.single_step) {
1493 ps.wait = false;
1494 }
1495 else {
1496 ps.single_step = true;
1497 ps.wait = !ps.wait;
1499 }
1500 }
1501 break;
1502 case GHOST_kKeyEqual:
1503 case GHOST_kKeyPlus:
1504 case GHOST_kKeyNumpadPlus: {
1505 if (val == 0) {
1506 break;
1507 }
1508 if (ps.ghost_data.qual & WS_QUAL_CTRL) {
1509 playanim_window_zoom(ps, 0.1f);
1510 }
1511 else {
1512 if (g_playanim.swap_time > ps.frame_step / 60.0) {
1513 g_playanim.swap_time /= 1.1;
1515 }
1516 }
1517 break;
1518 }
1519 case GHOST_kKeyMinus:
1520 case GHOST_kKeyNumpadMinus: {
1521 if (val == 0) {
1522 break;
1523 }
1524 if (ps.ghost_data.qual & WS_QUAL_CTRL) {
1525 playanim_window_zoom(ps, -0.1f);
1526 }
1527 else {
1528 if (g_playanim.swap_time < ps.frame_step / 5.0) {
1529 g_playanim.swap_time *= 1.1;
1531 }
1532 }
1533 break;
1534 }
1535 case GHOST_kKeyEsc:
1536 ps.go = false;
1537 break;
1538 default:
1539 break;
1540 }
1541 break;
1542 }
1544 case GHOST_kEventButtonUp: {
1545#ifdef WITH_GHOST_CSD
1546 const bool use_window_csd = ps.display_ctx.use_window_csd;
1547#else
1548 const bool use_window_csd = false;
1549#endif
1550 const GHOST_TEventButtonData *bd = static_cast<const GHOST_TEventButtonData *>(data);
1551 int cx, cy;
1552 const bool inside_window = (ghost_system->getCursorPositionClientRelative(
1553 ghost_window, cx, cy) == GHOST_kSuccess) &&
1555 ghost_window, use_window_csd, cx, cy);
1556
1557 if (bd->button == GHOST_kButtonMaskLeft) {
1558 if (type == GHOST_kEventButtonDown) {
1559 if (inside_window) {
1562 }
1563 }
1564 else {
1566 }
1567 }
1568 else if (bd->button == GHOST_kButtonMaskMiddle) {
1569 if (type == GHOST_kEventButtonDown) {
1570 if (inside_window) {
1572 }
1573 }
1574 else {
1576 }
1577 }
1578 else if (bd->button == GHOST_kButtonMaskRight) {
1579 if (type == GHOST_kEventButtonDown) {
1580 if (inside_window) {
1582 }
1583 }
1584 else {
1586 }
1587 }
1588 break;
1589 }
1591#ifdef WITH_GHOST_CSD
1592 if (ps.display_ctx.use_window_csd) {
1593 const GHOST_TEventCursorData *cd = static_cast<const GHOST_TEventCursorData *>(data);
1594 float &alpha = ps.display_ctx.ui_window_csd_alpha;
1595 const int2 window_size = playanim_window_size_get(ghost_window);
1596
1597 /* The vertical range to highlight the title (when the cursor is near). */
1598 const int upper_y = window_size.y / 6;
1599 const int lower_y = window_size.y / 3;
1600 const int y = cd->y;
1601 if ((y > lower_y) || UNLIKELY(upper_y == lower_y)) {
1602 alpha = 0.0f;
1603 }
1604 if (y < upper_y) {
1605 alpha = 1.0f;
1606 }
1607 else {
1608 alpha = (lower_y - y) / float(lower_y - upper_y);
1609 }
1610 }
1611#endif
1612
1613 if (ps.ghost_data.qual & WS_QUAL_LMOUSE) {
1614 const GHOST_TEventCursorData *cd = static_cast<const GHOST_TEventCursorData *>(data);
1615 int cx, cy;
1616
1617 /* Ignore 'in-between' events, since they can make scrubbing lag.
1618 *
1619 * Ideally we would keep into the event queue and see if this is the last motion event.
1620 * however the API currently doesn't support this. */
1621 {
1622 int x_test, y_test;
1623 if (ghost_system->getCursorPositionClientRelative(ghost_window, cx, cy) ==
1625 {
1626 ghost_window->screenToClient(cd->x, cd->y, x_test, y_test);
1627 if (cx != x_test || cy != y_test) {
1628 /* We're not the last event... skipping. */
1629 break;
1630 }
1631 }
1632 }
1633
1634 const float native_pixel_size = ghost_window->getNativePixelSize();
1635 playanim_change_frame_tag(ps, cx * native_pixel_size);
1636 }
1637 break;
1638 }
1641#ifdef WITH_GHOST_CSD
1642 if (ps.display_ctx.use_window_csd) {
1643 ps.display_ctx.ui_window_csd_alpha = 0.0f;
1644 }
1645#endif
1647 break;
1648 }
1651 float zoomx, zoomy;
1652
1653 ps.display_ctx.size = playanim_window_size_get(ghost_window);
1654 ghost_window->activateDrawingContext();
1655
1656 zoomx = float(ps.display_ctx.size[0]) / ps.ibuf_size[0];
1657 zoomy = float(ps.display_ctx.size[1]) / ps.ibuf_size[1];
1658
1659 /* Zoom always show entire image. */
1660 ps.zoom = std::min(zoomx, zoomy);
1661
1662 GPU_viewport(0, 0, ps.display_ctx.size[0], ps.display_ctx.size[1]);
1663 GPU_scissor(0, 0, ps.display_ctx.size[0], ps.display_ctx.size[1]);
1664
1666
1667 g_playanim.total_time = 0.0;
1668
1669 playanim_toscreen(ps, ps.picture, ps.picture ? ps.picture->ibuf : nullptr);
1670
1671 break;
1672 }
1675 ps.go = false;
1676 break;
1677 }
1679 /* Rely on frame-change to redraw. */
1681 break;
1682 }
1684 const GHOST_TEventDragnDropData *ddd = static_cast<const GHOST_TEventDragnDropData *>(data);
1685
1687 const GHOST_TStringArray *stra = static_cast<const GHOST_TStringArray *>(ddd->data);
1688 ps.argc_next = stra->count;
1689 ps.argv_next = MEM_new_array_uninitialized<char *>(size_t(ps.argc_next), __func__);
1690 for (int i = 0; i < stra->count; i++) {
1691 ps.argv_next[i] = BLI_strdup(reinterpret_cast<const char *>(stra->strings[i]));
1692 }
1693 ps.go = false;
1694 printf("dropped %s, %d file(s)\n", ps.argv_next[0], ps.argc_next);
1695 }
1696 break;
1697 }
1698 default:
1699 /* Quiet warnings. */
1700 break;
1701 }
1702
1703 return true;
1704}
1705
1707 GHOST_ISystem *ghost_system, const char *title, int posx, int posy, int sizex, int sizey)
1708{
1709 GHOST_GPUSettings gpu_settings = {0};
1710 const GPUBackendType gpu_backend = GPU_backend_type_selection_get();
1711 gpu_settings.context_type = wm_ghost_drawing_context_type(gpu_backend);
1714 gpu_settings.flags |= GHOST_gpuVSyncIsOverridden;
1716 }
1717
1718 {
1719 bool screen_size_valid = false;
1720 uint32_t screen_size[2] = {};
1721 ghost_system->getMainDisplayDimensions(screen_size[0], screen_size[1]);
1722
1723 if (screen_size[0] > 0 && screen_size[1] > 0) {
1724 screen_size_valid = true;
1725 }
1726 else {
1727 /* Unlikely the screen size fails to access,
1728 * if this happens it's still important to clamp the window size by *something*. */
1729 screen_size[0] = 1024;
1730 screen_size[1] = 1024;
1731 }
1732
1733 if (screen_size_valid) {
1734 if (ghost_system->getCapabilities() & GHOST_kCapabilityWindowPosition) {
1735 posy = (screen_size[1] - posy - sizey);
1736 }
1737 }
1738 else {
1739 posx = 0;
1740 posy = 0;
1741 }
1742
1743 /* NOTE: ideally the GPU could be queried for the maximum supported window size,
1744 * this isn't so simple as the GPU back-end's capabilities are initialized *after* the window
1745 * has been created. Further, it's quite unlikely the users main monitor size is larger
1746 * than the maximum window size supported by the GPU. */
1747
1748 /* Clamp the size so very large requests aren't rejected by the GPU.
1749 * Halve until a usable range is reached instead of scaling down to meet the screen size
1750 * since fractional scaling tends not to look so nice. */
1751 while (sizex >= int(screen_size[0]) || sizey >= int(screen_size[1])) {
1752 sizex /= 2;
1753 sizey /= 2;
1754 }
1755 /* Unlikely but ensure the size is *never* zero. */
1756 CLAMP_MIN(sizex, 1);
1757 CLAMP_MIN(sizey, 1);
1758 }
1759
1760 return ghost_system->createWindow(
1761 title, posx, posy, sizex, sizey, GHOST_kWindowStateNormal, gpu_settings);
1762}
1763
1764static void playanim_window_zoom(PlayState &ps, const float zoom_offset)
1765{
1766 int2 size;
1767 // int2 ofs; /* UNUSED. */
1768
1769 if (ps.zoom + zoom_offset > 0.0f) {
1770 ps.zoom += zoom_offset;
1771 }
1772
1773 // playanim_window_get_position(&ofs[0], &ofs[1]);
1774 // size = playanim_window_size_get(ps.ghost_data.window);
1775 // ofs[0] += size[0] / 2; /* UNUSED. */
1776 // ofs[1] += size[1] / 2; /* UNUSED. */
1777 const float native_pixel_size = ps.ghost_data.window->getNativePixelSize();
1778 size[0] = ps.zoom * ps.ibuf_size[0] / native_pixel_size;
1779 size[1] = ps.zoom * ps.ibuf_size[1] / native_pixel_size;
1780 // ofs[0] -= size[0] / 2; /* UNUSED. */
1781 // ofs[1] -= size[1] / 2; /* UNUSED. */
1782 // window_set_position(ps.ghost_data.window, size[0], size[1]);
1783 ps.ghost_data.window->setClientSize(size[0], size[1]);
1784}
1785
1787{
1788 const float scale = (ps.ghost_data.window->getDPIHint() *
1789 ps.ghost_data.window->getNativePixelSize() / 96.0f);
1790 const float font_size_base = 11.0f; /* Font size un-scaled. */
1791 const int font_size = int((font_size_base * scale) + 0.5f);
1792 bool changed = false;
1793 if (ps.font_size != font_size) {
1794 BLF_size(ps.font_id, font_size);
1795 ps.font_size = font_size;
1796 changed = true;
1797 }
1798 if (ps.display_ctx.ui_scale != scale) {
1800 }
1801 return changed;
1802}
1803
1808static std::optional<int> wm_main_playanim_intern(int argc, const char **argv, PlayArgs *args_next)
1809{
1810 ImBuf *ibuf = nullptr;
1811 int2 window_pos = {0, 0};
1812 int frame_start = -1;
1813 int frame_end = -1;
1814
1815 PlayState ps{};
1816
1817 ps.go = true;
1818 ps.direction = true;
1819 ps.next_frame = 1;
1820 ps.once = false;
1821 ps.pingpong = false;
1822 ps.no_frame_skip = false;
1823 ps.single_step = false;
1824 ps.wait = false;
1825 ps.stopped = false;
1826 ps.loading = false;
1827 ps.picture = nullptr;
1828 ps.show_frame_indicator = false;
1829 ps.argc_next = 0;
1830 ps.argv_next = nullptr;
1831 ps.zoom = 1.0f;
1832 ps.draw_flip[0] = false;
1833 ps.draw_flip[1] = false;
1834
1835 ps.frame_step = 1;
1836
1837 ps.font_id = -1;
1838
1839 IMB_init();
1840 MOV_init();
1841
1842#ifdef WITH_GHOST_CSD
1843 ps.display_ctx.use_window_csd = false; /* Initialize after GHOST's system. */
1844 ps.display_ctx.ui_window_csd_alpha = 0.0f;
1845#endif
1846
1851 ps.display_ctx.ui_scale = 1.0f;
1852
1853 while ((argc > 0) && (argv[0][0] == '-')) {
1854 switch (argv[0][1]) {
1855 case 'm': {
1856 g_playanim.from_disk = true;
1857 break;
1858 }
1859 case 'p': {
1860 if (argc > 2) {
1861 window_pos[0] = atoi(argv[1]);
1862 window_pos[1] = atoi(argv[2]);
1863 argc -= 2;
1864 argv += 2;
1865 }
1866 else {
1867 printf("too few arguments for -p (need 2): skipping\n");
1868 }
1869 break;
1870 }
1871 case 'f': {
1872 if (argc > 2) {
1873 double fps = atof(argv[1]);
1874 double fps_base = atof(argv[2]);
1875 if (fps == 0.0) {
1876 fps = 1;
1877 printf("invalid fps, forcing 1\n");
1878 }
1879 g_playanim.swap_time = fps_base / fps;
1880 argc -= 2;
1881 argv += 2;
1882 }
1883 else {
1884 printf("too few arguments for -f (need 2): skipping\n");
1885 }
1886 break;
1887 }
1888 case 's': {
1889 frame_start = atoi(argv[1]);
1890 CLAMP(frame_start, 1, MAXFRAME);
1891 argc--;
1892 argv++;
1893 break;
1894 }
1895 case 'e': {
1896 frame_end = atoi(argv[1]);
1897 CLAMP(frame_end, 1, MAXFRAME);
1898 argc--;
1899 argv++;
1900 break;
1901 }
1902 case 'j': {
1903 ps.frame_step = atoi(argv[1]);
1904 CLAMP(ps.frame_step, 1, MAXFRAME);
1905 g_playanim.swap_time *= ps.frame_step;
1906 argc--;
1907 argv++;
1908 break;
1909 }
1910 case 'c': {
1911#ifdef USE_FRAME_CACHE_LIMIT
1912 const int memory_in_mb = max_ii(0, atoi(argv[1]));
1913 g_frame_cache.memory_limit = size_t(memory_in_mb) * (1024 * 1024);
1914#endif
1915 argc--;
1916 argv++;
1917 break;
1918 }
1919 default: {
1920 printf("unknown option '%c': skipping\n", argv[0][1]);
1921 break;
1922 }
1923 }
1924 argc--;
1925 argv++;
1926 }
1927
1928 const char *filepath = nullptr;
1929 GHOST_IEventConsumer *ghost_event_consumer = nullptr;
1930
1931 {
1932 std::optional<int> exit_code = [&]() -> std::optional<int> {
1933 if (argc == 0) {
1934 fprintf(stderr, "%s: no filepath argument given\n", message_prefix);
1935 return EXIT_FAILURE;
1936 }
1937
1938 filepath = argv[0];
1939 if (MOV_is_movie_file(filepath)) {
1940 /* OCIO_TODO: support different input color spaces. */
1941 /* Image buffer is used for display, which does support displaying any buffer from any
1942 * colorspace. Skip colorspace conversions in the movie module to improve performance. */
1943 MovieReader *anim = MOV_open_file(filepath, ImBufFlags::Zero, 0, true, nullptr);
1944 if (anim) {
1945 ibuf = MOV_decode_frame(anim, 0, IMB_PROXY_NONE);
1946 MOV_close(anim);
1947 anim = nullptr;
1948 }
1949 }
1950 else if (IMB_test_image(filepath)) {
1951 /* Pass. */
1952 }
1953 else {
1954 fprintf(stderr, "%s: '%s' not an image file\n", message_prefix, filepath);
1955 return EXIT_FAILURE;
1956 }
1957
1958 if (ibuf == nullptr) {
1959 /* OCIO_TODO: support different input color space. */
1961 }
1962
1963 if (ibuf == nullptr) {
1964 fprintf(stderr, "%s: '%s' couldn't open\n", message_prefix, filepath);
1965 return EXIT_FAILURE;
1966 }
1967
1968 /* Select GPU backend. */
1970
1971 /* Init GHOST and open window. */
1974
1977 if (ps.ghost_data.system == nullptr) [[unlikely]] {
1978 /* GHOST will have reported the back-ends that failed to load. */
1979 fprintf(stderr, "%s: unable to initialize GHOST, exiting!\n", message_prefix);
1980 return EXIT_FAILURE;
1981 }
1982
1983#ifdef WITH_GHOST_CSD
1984 ps.display_ctx.use_window_csd = (ps.ghost_data.system->getCapabilities() &
1986 if (ps.display_ctx.use_window_csd) {
1987 playanim_window_csd_params_update(ps.ghost_data);
1988 }
1989#endif
1990
1993
1996 window_pos[0],
1997 window_pos[1],
1998 ibuf->x,
1999 ibuf->y);
2000
2001 if (ps.ghost_data.window == nullptr) [[unlikely]] {
2002 fprintf(stderr, "%s: unable to create window, exiting!\n", message_prefix);
2003 return EXIT_FAILURE;
2004 }
2005
2006 ghost_event_consumer = new GHOST_CallbackEventConsumer(ghost_event_proc, &ps);
2007 ps.ghost_data.system->addEventConsumer(ghost_event_consumer);
2008
2009 return std::nullopt;
2010 }();
2011
2012 if (exit_code) {
2013 if (ps.ghost_data.system) {
2015 }
2016 if (ibuf) {
2017 IMB_freeImBuf(ibuf);
2018 }
2019 IMB_exit();
2020 MOV_exit();
2021 return exit_code;
2022 }
2023 }
2024
2025 // GHOST_ActivateWindowDrawingContext(ps.ghost_data.window);
2026
2027 /* Init Blender GPU context. */
2030 GPU_init();
2031
2032 /* Initialize the font. */
2033 BLF_init();
2034 ps.font_id = BLF_load_mono_default(false);
2035
2036 ps.font_size = -1; /* Force update. */
2038
2039 ps.ibuf_size[0] = ibuf->x;
2040 ps.ibuf_size[1] = ibuf->y;
2041
2042 ps.display_ctx.size = ps.ibuf_size;
2043
2047 GPU_clear_color(0.1f, 0.1f, 0.1f, 0.0f);
2048
2049 {
2050 const int2 window_size = playanim_window_size_get(ps.ghost_data.window);
2051 GPU_viewport(0, 0, window_size[0], window_size[1]);
2052 GPU_scissor(0, 0, window_size[0], window_size[1]);
2054 }
2055
2058
2059 /* One of the frames was invalid or not passed in. */
2060 if (frame_start == -1 || frame_end == -1) {
2061 frame_start = 1;
2062 if (argc == 1) {
2063 /* A single file was passed in, attempt to load all images from an image sequence.
2064 * (if it is an image sequence). */
2065 frame_end = MAXFRAME;
2066 }
2067 else {
2068 /* Multiple files passed in, show each file without expanding image sequences.
2069 * This occurs when dropping multiple files. */
2070 frame_end = 1;
2071 }
2072 }
2073
2075 ps.ghost_data,
2076 ps.display_ctx,
2077 filepath,
2078 (frame_end - frame_start) + 1,
2079 ps.frame_step,
2080 &ps.loading);
2081
2082#ifdef WITH_AUDASPACE
2083 g_audaspace.source = AUD_Sound(new aud::File(filepath));
2084 if (!BLI_listbase_is_empty(&ps.picsbase)) {
2085 const MovieReader *anim_movie = ps.picsbase.first()->anim;
2086 if (anim_movie) {
2087 g_playanim.fps_movie = MOV_get_fps(anim_movie);
2088 /* Enforce same fps for movie as sound. */
2089 g_playanim.swap_time = ps.frame_step / g_playanim.fps_movie;
2090 }
2091 }
2092#endif
2093
2094 for (int i = 1; i < argc; i++) {
2095 filepath = argv[i];
2097 ps.ghost_data,
2098 ps.display_ctx,
2099 filepath,
2100 (frame_end - frame_start) + 1,
2101 ps.frame_step,
2102 &ps.loading);
2103 }
2104
2105 IMB_freeImBuf(ibuf);
2106 ibuf = nullptr;
2107
2108 pupdate_time();
2109 g_playanim.total_time = 0.0;
2110
2111/* Newly added in 2.6x, without this images never get freed. */
2112#define USE_IMB_CACHE
2113
2114 while (ps.go) {
2115 if (ps.pingpong) {
2116 ps.direction = -ps.direction;
2117 }
2118
2119 if (ps.direction == 1) {
2120 ps.picture = ps.picsbase.first();
2121 }
2122 else {
2123 ps.picture = ps.picsbase.last();
2124 }
2125
2126 if (ps.picture == nullptr) {
2127 printf("couldn't find pictures\n");
2128 ps.go = false;
2129 }
2130 if (ps.pingpong) {
2131 if (ps.direction == 1) {
2132 ps.picture = ps.picture->next;
2133 }
2134 else {
2135 ps.picture = ps.picture->prev;
2136 }
2137 }
2138 g_playanim.total_time = std::min(g_playanim.total_time, 0.0);
2139
2140#ifdef WITH_AUDASPACE
2141 if (g_audaspace.playback_handle) {
2142 g_audaspace.playback_handle->stop();
2143 }
2144 g_audaspace.playback_handle = bke::sound_device_play(g_audaspace.audio_device,
2145 g_audaspace.source);
2147#endif
2148
2149 while (ps.picture) {
2150 bool has_event;
2151#ifndef USE_IMB_CACHE
2152 if (ibuf != nullptr && ibuf->ftype == IMB_FTYPE_NONE) {
2153 IMB_freeImBuf(ibuf);
2154 }
2155#endif
2156
2157 ibuf = ibuf_from_picture(ps.picture);
2158
2159 {
2160#ifdef USE_IMB_CACHE
2161 ps.picture->ibuf = ibuf;
2162#endif
2163 if (ibuf) {
2164#ifdef USE_FRAME_CACHE_LIMIT
2165 if (ps.picture->frame_cache_node == nullptr) {
2167 }
2168 else {
2170 }
2172#endif /* USE_FRAME_CACHE_LIMIT */
2173
2174 ibuf->filepath = ps.picture->filepath;
2175 ibuf->fileframe = ps.picture->frame;
2176 }
2177
2178 while (pupdate_time()) {
2180 }
2181 g_playanim.total_time -= g_playanim.swap_time;
2182 playanim_toscreen(ps, ps.picture, ibuf);
2183 }
2184
2185 if (ps.once) {
2186 if (ps.picture->next == nullptr) {
2187 ps.wait = true;
2188 }
2189 else if (ps.picture->prev == nullptr) {
2190 ps.wait = true;
2191 }
2192 }
2193
2194 ps.next_frame = ps.direction;
2195
2197 GPUContext *restore_context = GPU_context_active_get();
2199 while ((has_event = ps.ghost_data.system->processEvents(false))) {
2201 }
2203 GPU_context_active_set(restore_context);
2204
2205 if (ps.go == false) {
2206 break;
2207 }
2209 if (!has_event) {
2211 }
2212 if (ps.wait) {
2213 continue;
2214 }
2215
2216 ps.wait = ps.single_step;
2217
2218 if (ps.wait == false && ps.stopped) {
2219 ps.stopped = false;
2220 }
2221
2222 pupdate_time();
2223
2224 if (ps.picture && ps.next_frame) {
2225 /* Advance to the next frame, always at least set one step.
2226 * Implement frame-skipping when enabled and playback is not fast enough. */
2227 while (ps.picture) {
2229
2230 if (ps.once && ps.picture != nullptr) {
2231 if (ps.picture->next == nullptr) {
2232 ps.wait = true;
2233 }
2234 else if (ps.picture->prev == nullptr) {
2235 ps.wait = true;
2236 }
2237 }
2238
2239 if (ps.wait || g_playanim.total_time < g_playanim.swap_time || ps.no_frame_skip) {
2240 break;
2241 }
2242 g_playanim.total_time -= g_playanim.swap_time;
2243 }
2244 if (ps.picture == nullptr && ps.single_step) {
2246 }
2247 }
2248 if (ps.go == false) {
2249 break;
2250 }
2251 }
2252 }
2253 while ((ps.picture = static_cast<PlayAnimPict *>(BLI_pophead(&ps.picsbase)))) {
2254 if (ps.picture->anim) {
2255 if ((ps.picture->next == nullptr) || (ps.picture->next->anim != ps.picture->anim)) {
2256 MOV_close(ps.picture->anim);
2257 }
2258 }
2259
2260 if (ps.picture->ibuf) {
2262 }
2263 if (ps.picture->mem) {
2264 MEM_delete(ps.picture->mem);
2265 }
2266 if (ps.picture->error_message) {
2267 MEM_delete(ps.picture->error_message);
2268 }
2269 MEM_delete(ps.picture->filepath);
2270 MEM_delete(ps.picture);
2271 }
2272
2273/* Cleanup. */
2274#ifndef USE_IMB_CACHE
2275 if (ibuf) {
2276 IMB_freeImBuf(ibuf);
2277 }
2278#endif
2279
2280#ifdef USE_FRAME_CACHE_LIMIT
2281 g_frame_cache.pics.free_no_destruct();
2282 g_frame_cache.pics_len = 0;
2283 g_frame_cache.pics_size_in_memory = 0;
2284#endif
2285
2286#ifdef WITH_AUDASPACE
2287 if (g_audaspace.playback_handle) {
2288 g_audaspace.playback_handle->stop();
2289 g_audaspace.playback_handle = nullptr;
2290 }
2291 if (g_audaspace.scrub_handle) {
2292 g_audaspace.scrub_handle->stop();
2293 g_audaspace.scrub_handle = nullptr;
2294 }
2295 g_audaspace.source.reset();
2296#endif
2297
2298 /* Free subsystems the animation player is responsible for starting.
2299 * The rest is handled by #BKE_blender_atexit, see early-exit logic in `creator.cc`. */
2300
2301 BLF_exit();
2302
2303 /* NOTE: Must happen before GPU Context destruction as GPU resources are released via
2304 * Color Management module. */
2305 IMB_exit();
2306 MOV_exit();
2307
2308 if (ps.ghost_data.gpu_context) {
2310 GPU_exit();
2312 ps.ghost_data.gpu_context = nullptr;
2313 }
2314 ps.ghost_data.system->removeEventConsumer(ghost_event_consumer);
2315 delete ghost_event_consumer;
2316
2318
2320
2321 if (ps.argv_next) {
2322 args_next->argc = ps.argc_next;
2323 args_next->argv = ps.argv_next;
2324 /* Returning none, run this function again with the *next* arguments. */
2325 return std::nullopt;
2326 }
2327
2328 return EXIT_SUCCESS;
2329}
2330
2331int WM_main_playanim(int argc, const char **argv)
2332{
2333#ifdef WITH_AUDASPACE
2334 {
2335 aud::DeviceSpecs specs;
2336
2337 specs.rate = aud::RATE_48000;
2338 specs.format = aud::FORMAT_FLOAT32;
2339 specs.channels = aud::CHANNELS_STEREO;
2340
2341 bke::sound_system_initialize();
2342
2343 if (!(g_audaspace.audio_device = bke::sound_device_init(nullptr, specs, 1024, "Blender"))) {
2344 g_audaspace.audio_device = bke::sound_device_init("None", specs, 0, "Blender");
2345 }
2346 }
2347#endif
2348
2349 std::optional<int> exit_code = std::nullopt;
2350 PlayArgs args_next = {0};
2351 do {
2352 PlayArgs args_free = args_next;
2353 args_next = {0};
2354
2355 if ((exit_code = wm_main_playanim_intern(argc, argv, &args_next))) {
2356 argc = 0;
2357 argv = nullptr;
2358 }
2359 else {
2360 argc = args_next.argc;
2361 argv = const_cast<const char **>(args_next.argv);
2362 }
2363
2364 if (args_free.argv) {
2365 for (int i = 0; i < args_free.argc; i++) {
2366 MEM_delete(args_free.argv[i]);
2367 }
2368 MEM_delete(args_free.argv);
2369 }
2370 } while (argv != nullptr);
2371 /* Set in the loop. */
2372 BLI_assert(exit_code.has_value());
2373
2374#ifdef WITH_AUDASPACE
2375 bke::sound_device_exit();
2376 g_audaspace.audio_device.reset();
2377#endif
2378
2379 /* Cleanup sub-systems started before this function was called. */
2381
2382 return exit_code.value();
2383}
2384
2385} // namespace blender
Blender util stuff.
std::shared_ptr< void > AUD_Sound
std::shared_ptr< void > AUD_Handle
std::shared_ptr< void > AUD_Device
File and directory operations.
#define O_BINARY
#define FILE_MAX
#define SNPRINTF(dst, format,...)
#define STRNCPY_UTF8(dst, src)
Platform independent time functions.
#define CLOG_WARN(clg_ref,...)
Definition CLG_log.h:189
#define MAXFRAME
void * GHOST_TUserDataPtr
const void * GHOST_TEventDataPtr
#define GHOST_CSD_DPI_FRACTIONAL_BASE
GHOST_TWindowState
@ GHOST_kWindowStateMaximized
@ GHOST_kWindowStateNormal
GHOST_TEventType
@ GHOST_kEventWindowClose
@ GHOST_kEventWindowMove
@ GHOST_kEventWindowSize
@ GHOST_kEventDraggingDropDone
@ GHOST_kEventCursorMove
@ GHOST_kEventButtonUp
@ GHOST_kEventWindowActivate
@ GHOST_kEventWindowDeactivate
@ GHOST_kEventButtonDown
@ GHOST_kEventKeyDown
@ GHOST_kEventWindowDPIHintChanged
@ GHOST_kEventKeyUp
@ GHOST_kEventQuitRequest
@ GHOST_kCSDTypeBody
@ GHOST_kCapabilityWindowDecorationServerSide
@ GHOST_kCapabilityWindowPosition
@ GHOST_kKey5
@ GHOST_kKey4
@ GHOST_kKeyNumpad3
@ GHOST_kKeyNumpad1
@ GHOST_kKey3
@ GHOST_kKeyI
@ GHOST_kKeyEnter
@ GHOST_kKeyP
@ GHOST_kKeyNumpadSlash
@ GHOST_kKeyRightArrow
@ GHOST_kKeyNumpad4
@ GHOST_kKeyMinus
@ GHOST_kKey6
@ GHOST_kKey0
@ GHOST_kKeyDownArrow
@ GHOST_kKeyNumpadPeriod
@ GHOST_kKeyF
@ GHOST_kKey1
@ GHOST_kKey8
@ GHOST_kKeyNumpad2
@ GHOST_kKeyPeriod
@ GHOST_kKeyNumpadPlus
@ GHOST_kKey9
@ GHOST_kKeyNumpad5
@ GHOST_kKeyLeftArrow
@ GHOST_kKeyEqual
@ GHOST_kKey7
@ GHOST_kKeyNumpad6
@ GHOST_kKeyNumpad8
@ GHOST_kKeyNumpad9
@ GHOST_kKeyUpArrow
@ GHOST_kKeyNumpad0
@ GHOST_kKeyA
@ GHOST_kKey2
@ GHOST_kKeyNumpad7
@ GHOST_kKeyEsc
@ GHOST_kKeyPlus
@ GHOST_kKeySlash
@ GHOST_kKeyNumpadEnter
@ GHOST_kKeyNumpadMinus
@ GHOST_kKeySpace
@ GHOST_kModifierKeyRightControl
@ GHOST_kModifierKeyLeftControl
@ GHOST_kModifierKeyRightAlt
@ GHOST_kModifierKeyRightShift
@ GHOST_kModifierKeyLeftAlt
@ GHOST_kModifierKeyLeftShift
@ GHOST_kModifierKeyLeftOS
@ GHOST_kModifierKeyRightOS
@ GHOST_kSuccess
@ GHOST_gpuVSyncIsOverridden
@ GHOST_kDragnDropTypeFilenames
@ GHOST_kButtonMaskRight
@ GHOST_kButtonMaskLeft
@ GHOST_kButtonMaskMiddle
GHOST_TVSyncModes
#define GHOST_kCSDType_NUM
Read Blender memory allocation and freeing.
#define CLAMP(a, b, c)
#define UNUSED_VARS(...)
#define SET_FLAG_FROM_TEST(value, test, flag)
#define UNLIKELY(x)
#define ELEM(...)
#define BLI_assert_msg(a, msg)
#define CLAMP_MIN(a, b)
GHOST_CallbackEventConsumer(GHOST_EventCallbackProcPtr eventCallback, GHOST_TUserDataPtr user_data)
virtual GHOST_TEventType getType() const =0
virtual GHOST_TEventDataPtr getData() const =0
static GHOST_ISystem * getSystem()
static GHOST_TSuccess createSystem(bool verbose=true, bool background=false)
virtual GHOST_TSuccess getModifierKeyState(GHOST_TModifierKey mask, bool &is_down) const =0
static void setUseWindowFrame(bool use_window_frame)
static void setBacktraceFn(GHOST_TBacktraceFn backtrace_fn)
virtual void getMainDisplayDimensions(uint32_t &width, uint32_t &height) const =0
virtual GHOST_IWindow * createWindow(const char *title, int32_t left, int32_t top, uint32_t width, uint32_t height, GHOST_TWindowState state, GHOST_GPUSettings gpu_settings, const bool exclusive=false, const bool is_dialog=false, const GHOST_IWindow *parent_window=nullptr)=0
virtual GHOST_TSuccess addEventConsumer(GHOST_IEventConsumer *consumer)=0
virtual bool useNativePixel()=0
static GHOST_TSuccess disposeSystem()
virtual void dispatchEvents()=0
virtual const GHOST_CSD_Layout & getWindowCSD_Layout() const =0
virtual GHOST_TCapabilityFlag getCapabilities() const =0
virtual GHOST_TSuccess getCursorPositionClientRelative(const GHOST_IWindow *window, int32_t &x, int32_t &y) const =0
virtual GHOST_TSuccess disposeWindow(GHOST_IWindow *window)=0
virtual GHOST_TSuccess removeEventConsumer(GHOST_IEventConsumer *consumer)=0
virtual bool processEvents(bool waitForEvent)=0
virtual void getClientBounds(GHOST_Rect &bounds) const =0
virtual GHOST_TSuccess activateDrawingContext()=0
virtual GHOST_TSuccess swapBufferRelease()=0
virtual GHOST_TSuccess setClientSize(uint32_t width, uint32_t height)=0
virtual float getNativePixelSize()=0
virtual GHOST_IContext * getDrawingContext()=0
virtual void screenToClient(int32_t inX, int32_t inY, int32_t &outX, int32_t &outY) const =0
virtual GHOST_TSuccess swapBufferAcquire()=0
virtual uint16_t getDPIHint()=0
virtual GHOST_TWindowState getState() const =0
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
float3x3 scale(float3x3 mat, float2 scale)
#define PRIu64
Definition inttypes.h:132
#define PRId64
Definition inttypes.h:78
const int state
ENUM_OPERATORS(Layer::Flags)
BMesh Iterators.
void WM_window_csd_draw_titlebar_ex(const int win_size[2], const char win_state, const GHOST_CSD_Layout *csd_layout, const bool is_active, const uint16_t dpi, const char *title, const int font_id, const int font_size, const uchar border_color[3], const uchar text_color[3], const float alpha)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned __int64 uint64_t
Definition BKE_text.h:91
__int64 int64_t
Definition BKE_text.h:90
void GPU_exit()
static PlayAnimPict * playanim_step(PlayAnimPict *playanim, int step)
char * STRNCPY(char(&dst)[N], const char *src)
void GPU_texture_update(gpu::Texture *texture, eGPUDataFormat data_format, const void *data)
static const char * playanim_window_title
void BLF_aspect(int fontid, float x, float y, float z)
Definition blf.cc:379
void BLF_position(int fontid, float x, float y, float z)
Definition blf.cc:390
void immEnd()
unsigned int uint
Definition BKE_text.h:55
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void IMB_colormanagement_finish_glsl_draw()
void GPU_clear_color(float red, float green, float blue, float alpha)
void BLI_addhead(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:98
int WM_window_csd_layout_callback(const int window_size[2], const int fractional_scale[2], const char window_state, const GHOST_CSD_Layout *csd_layout, GHOST_CSD_Elem *csd_elems)
GPUContext * GPU_context_create(GHOST_IWindow *ghost_window, GHOST_IContext *ghost_context)
void MOV_init()
static void draw_display_buffer(const PlayDisplayContext &display_ctx, const ImBuf *ibuf, const rctf *canvas, const bool draw_flip[2])
void BLI_time_sleep_ms(int ms)
Definition time.cc:91
static void update_sound_fps()
void GPU_matrix_identity_set()
void MOV_close(MovieReader *anim)
Definition movie_read.cc:70
GPUVertFormat * immVertexFormat()
GPUBackendType GPU_backend_get_type()
void GPU_context_end_frame(GPUContext *ctx)
void GPU_render_step(bool force_resource_release=false)
unsigned short ushort
Definition BKE_text.h:56
int BLF_load_mono_default(bool unique)
void immBegin(GPUPrimType, uint vertex_len)
int64_t BLI_read(int fd, void *buf, size_t nbytes)
Definition fileops_c.cc:98
char * BLI_sprintfN(const char *__restrict format,...) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_PRINTF_FORMAT(1
ImBuf * MOV_decode_frame(MovieReader *anim, int frame_index, IMB_Proxy_Size preview_size)
bool GPU_backend_type_selection_detect()
bool IMB_colormanagement_setup_glsl_draw_from_space(const ColorManagedViewSettings *view_settings, const ColorManagedDisplaySettings *display_settings, const ColorSpace *from_colorspace, float dither, bool predivide, bool do_overlay_merge, ColorManagedDisplaySpace display_space=DISPLAY_SPACE_DRAW, float opacity=1.0f)
static void build_pict_list_from_anim(ListBaseT< PlayAnimPict > &picsbase, GhostData &ghost_data, const PlayDisplayContext &display_ctx, const char *filepath_first, const int frame_offset)
static void playanim_toscreen(PlayState &ps, const PlayAnimPict *picture, const ImBuf *ibuf)
void imm_draw_box_checker_2d_ex(float x1, float y1, float x2, float y2, const float color_primary[4], const float color_secondary[4], int checker_size)
BLI_INLINE bool BLI_listbase_is_empty(const ListBase *lb)
void GPU_matrix_identity_projection_set()
MINLINE int max_ii(int a, int b)
int GPU_backend_vsync_get()
void GPU_render_begin()
void GPU_context_active_set(GPUContext *)
int BLI_open(const char *filepath, int oflag, int pmode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void immAttr2f(uint attr_id, float x, float y)
void MOV_exit()
void immUnbindProgram()
void BLF_color4f(int fontid, float r, float g, float b, float a)
Definition blf.cc:516
void GPU_context_begin_frame(GPUContext *ctx)
size_t IMB_get_size_in_memory(const ImBuf *ibuf)
void GPU_matrix_scale_2f(float x, float y)
@ GPU_BLEND_NONE
Definition GPU_state.hh:88
@ GPU_BLEND_ALPHA
Definition GPU_state.hh:90
void * BLI_pophead(ListBase *listbase) ATTR_NONNULL(1)
Definition listbase.cc:259
VecBase< float, 4 > float4
bool MOV_is_movie_file(const char *filepath)
static std::optional< int > wm_main_playanim_intern(int argc, const char **argv, PlayArgs *args_next)
unsigned short uint16_t
Definition BKE_text.h:80
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
static int2 playanim_window_size_get(GHOST_IWindow *ghost_window)
static void build_pict_list(ListBaseT< PlayAnimPict > &picsbase, GhostData &ghost_data, const PlayDisplayContext &display_ctx, const char *filepath_first, const int totframes, const int frame_step, bool *loading_p)
ImBuf * IMB_load_image_from_filepath(const char *filepath, ImBufFlags flags, ColorManagedColorspaceSettings *colorspace_settings=nullptr)
Definition readimage.cc:201
static ImBuf * ibuf_from_picture(PlayAnimPict *pic)
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:541
unsigned int uint32_t
Definition BKE_text.h:81
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:593
void BLF_size(int fontid, float size)
Definition blf.cc:445
MovieReader * MOV_open_file(const char *filepath, const ImBufFlags ib_flags, const int streamindex, const bool keep_original_colorspace, ColorManagedColorspaceSettings *colorspace_settings)
void GPU_init()
static void playanim_toscreen_ex(GhostData &ghost_data, const PlayDisplayContext &display_ctx, const PlayAnimPict *picture, const ImBuf *ibuf, const bool show_status, const int font_id, const int frame_step, const float draw_zoom, const bool draw_flip[2], const float frame_indicator_factor)
void IMB_freeImBuf(ImBuf *ibuf)
VecBase< int32_t, 2 > int2
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void immVertex2f(uint attr_id, float x, float y)
unsigned char uchar
Definition BKE_text.h:58
@ GPU_TEXTURE_USAGE_SHADER_READ
void GPU_render_end()
GPUBackendType GPU_backend_type_selection_get()
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:138
const char * IMB_colormanagement_role_colorspace_name_get(int role)
BMesh const char void * data
static void frame_cache_add(PlayAnimPict *pic)
static const char * message_prefix
void GPU_texture_filter_mode(gpu::Texture *texture, bool use_filter)
void IMB_init()
Definition module.cc:26
void BLI_freelinkN(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:277
LinkData * BLI_genericNodeN(void *data)
Definition listbase.cc:936
void immUniformColor3ub(unsigned char r, unsigned char g, unsigned char b)
void BKE_blender_atexit()
Definition blender.cc:509
static const void * setup_draw_ocio_transform(const PlayDisplayContext &display_ctx, const ImBuf *ibuf, gpu::TextureFormat &r_texture_format, eGPUDataFormat &r_data_format)
void GPU_matrix_translate_2f(float x, float y)
void BLF_draw(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_NONNULL(2)
Definition blf.cc:587
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
void IMB_colormanagement_init_untonemapped_view_settings(ColorManagedViewSettings *view_settings, const ColorManagedDisplaySettings *display_settings)
bool WM_init_window_frame_get()
static void frame_cache_limit_apply(ImBuf *ibuf_keep)
static bool playanim_window_contains_point(GHOST_IWindow *ghost_window, const bool use_window_csd, const int32_t cx, const int32_t cy)
static bool ghost_event_proc(const GHOST_IEvent *ghost_event, GHOST_TUserDataPtr ps_void_ptr)
void GPU_scissor(int x, int y, int width, int height)
Definition gpu_state.cc:178
void BLI_system_backtrace(FILE *fp)
Definition system.cc:112
ImBuf * IMB_load_image_from_memory(const unsigned char *mem, size_t size, ImBufFlags flags, const char *descr, const char *filepath=nullptr, ColorManagedColorspaceSettings *colorspace_settings=nullptr)
Definition readimage.cc:132
static void playanim_gpu_matrix()
int BLF_init()
Definition blf.cc:63
void GPU_flush()
Definition gpu_state.cc:284
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
void GPU_matrix_pop_projection()
static void playanim_audio_stop(PlayState &)
static void playanim_event_qual_update(GhostData &ghost_data)
GHOST_TDrawingContextType wm_ghost_drawing_context_type(const GPUBackendType gpu_backend)
void GPU_texture_bind(gpu::Texture *texture, int unit)
static struct blender::@313270353156307301103354366216022061050065355272 g_playanim
void GPU_texture_free(gpu::Texture *texture)
static void playanim_audio_resume(PlayState &ps)
void GPU_viewport(int x, int y, int width, int height)
Definition gpu_state.cc:184
float MOV_get_fps(const MovieReader *anim)
bool GPU_backend_vsync_is_overridden()
bool IMB_test_image(const char *filepath)
void GPU_matrix_ortho_set(float left, float right, float bottom, float top, float near, float far)
int BLI_path_sequence_decode(const char *path, char *head, size_t head_maxncpy, char *tail, size_t tail_maxncpy, unsigned short *r_digits_len)
Definition path_utils.cc:61
static void build_pict_list_from_image_sequence(ListBaseT< PlayAnimPict > &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)
signed int int32_t
Definition BKE_text.h:78
static void playanim_window_zoom(PlayState &ps, const float zoom_offset)
void BLI_path_sequence_encode(char *path, size_t path_maxncpy, const char *head, const char *tail, unsigned short numlen, int pic)
size_t BLI_file_descriptor_size(int file) ATTR_WARN_UNUSED_RESULT
Definition storage.cc:219
static void frame_cache_touch(PlayAnimPict *pic)
static CLG_LogRef LOG
Definition logging.cpp:12
double BLI_time_now_seconds()
Definition time.cc:30
static void frame_cache_remove(PlayAnimPict *pic)
void GPU_backend_ghost_system_set(GHOST_ISystem *ghost_system_handle)
void GPU_texture_unbind(gpu::Texture *texture)
static bool playanim_window_font_scale_from_dpi(PlayState &ps)
static void playanim_change_frame_tag(PlayState &ps, int cx)
static bool buffer_from_filepath(const char *filepath, void **r_mem, size_t *r_size, char **r_error_message)
GHOST_GPUDevice GPU_backend_preferred_device_get()
void GPU_blend(GPUBlend blend)
Definition gpu_state.cc:44
static GHOST_IWindow * playanim_window_open(GHOST_ISystem *ghost_system, const char *title, int posx, int posy, int sizex, int sizey)
int MOV_get_duration_frames(const MovieReader *anim)
static int pupdate_time()
void GPU_matrix_pop()
static bool frame_cache_limit_exceeded()
void GPU_matrix_push_projection()
MINLINE int clamp_i(int value, int min, int max)
static struct blender::@052266112127172122142261357116237105236273151356 g_frame_cache
static void playanim_toscreen_on_load(GhostData &ghost_data, const PlayDisplayContext &display_ctx, const PlayAnimPict *picture, const ImBuf *ibuf)
void BLF_enable(int fontid, FontFlags flag)
Definition blf.cc:322
@ BLF_ASPECT
Definition BLF_enums.hh:41
gpu::Texture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_matrix_push()
GPUContext * GPU_context_active_get()
ocio::ColorSpace ColorSpace
Definition BLF_api.hh:42
void GPU_context_discard(GPUContext *)
void BLI_rctf_init(struct rctf *rect, float xmin, float xmax, float ymin, float ymax)
Definition rct.cc:418
int WM_main_playanim(int argc, const char **argv)
void BLF_exit()
Definition blf.cc:72
void IMB_exit()
Definition module.cc:32
static void playanim_change_frame(PlayState &ps)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
int32_t bounds[2][2]
GHOST_TCSD_Type type
GHOST_TVSyncModes vsync
GHOST_TDrawingContextType context_type
GHOST_GPUDevice preferred_device
GHOST_TDragnDropTypes dataType
GHOST_TDragnDropDataPtr data
GHOST_IWindow * window
GHOST_ISystem * system
GPUContext * gpu_context
const ColorSpace * colorspace
const ColorSpace * colorspace
ImBufFloatBuffer float_buffer
ImBufByteBuffer byte_buffer
const uint8_t * byte_data() const
const float * float_data() const
std::string filepath
eImbFileType ftype
bool can_contain_alpha() const
LinkData * frame_cache_node
PlayAnimPict * prev
PlayAnimPict * next
ColorManagedViewSettings view_settings
ColorManagedDisplaySettings display_settings
ListBaseT< PlayAnimPict > picsbase
PlayAnimPict * picture
PlayDisplayContext display_ctx
ListBaseT< LinkData > pics
#define WS_QUAL_SHIFT
#define PLAY_FRAME_CACHE_MAX
#define WS_QUAL_CTRL
#define WS_QUAL_MOUSE
#define WM_WINDOW_CSD_RESIZE_MARGIN_SIZE