Changeset View
Changeset View
Standalone View
Standalone View
source/blender/windowmanager/intern/wm_files.c
| Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | |||||
| static ImBuf *blend_file_thumb_from_screenshot(bContext *C, BlendThumbnail **thumb_pt) | static ImBuf *blend_file_thumb_from_screenshot(bContext *C, BlendThumbnail **thumb_pt) | ||||
| { | { | ||||
| if (*thumb_pt) { | if (*thumb_pt) { | ||||
| /* We are given a valid thumbnail data, so just generate image from it. */ | /* We are given a valid thumbnail data, so just generate image from it. */ | ||||
| return BKE_main_thumbnail_to_imbuf(NULL, *thumb_pt); | return BKE_main_thumbnail_to_imbuf(NULL, *thumb_pt); | ||||
| } | } | ||||
| /* Redraw to remove menus that might be open. */ | |||||
| WM_redraw_windows(C); | |||||
| WM_cursor_wait(true); | |||||
| /* The window to capture should be a main window (without parent). */ | /* The window to capture should be a main window (without parent). */ | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| while (win && win->parent) { | while (win && win->parent) { | ||||
| win = win->parent; | win = win->parent; | ||||
| } | } | ||||
| int win_size[2]; | int win_size[2]; | ||||
| uint *buffer = WM_window_pixels_read(CTX_wm_manager(C), win, win_size); | uint *buffer = WM_window_pixels_read(CTX_wm_manager(C), win, win_size); | ||||
| Show All 16 Lines | |||||
| /* Thumbnail inside blend should be 128x128. */ | /* Thumbnail inside blend should be 128x128. */ | ||||
| ImBuf *thumb_ibuf = IMB_dupImBuf(ibuf); | ImBuf *thumb_ibuf = IMB_dupImBuf(ibuf); | ||||
| IMB_scaleImBuf(thumb_ibuf, ex, ey); | IMB_scaleImBuf(thumb_ibuf, ex, ey); | ||||
| BlendThumbnail *thumb = BKE_main_thumbnail_from_imbuf(NULL, thumb_ibuf); | BlendThumbnail *thumb = BKE_main_thumbnail_from_imbuf(NULL, thumb_ibuf); | ||||
| IMB_freeImBuf(thumb_ibuf); | IMB_freeImBuf(thumb_ibuf); | ||||
| *thumb_pt = thumb; | *thumb_pt = thumb; | ||||
| } | } | ||||
| WM_cursor_wait(false); | |||||
| /* Must be freed by caller. */ | /* Must be freed by caller. */ | ||||
| return ibuf; | return ibuf; | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| ▲ Show 20 Lines • Show All 178 Lines • ▼ Show 20 Lines | |||||
| /* Call pre-save callbacks before writing preview, | /* Call pre-save callbacks before writing preview, | ||||
| * that way you can generate custom file thumbnail. */ | * that way you can generate custom file thumbnail. */ | ||||
| BKE_callback_exec_null(bmain, BKE_CB_EVT_SAVE_PRE); | BKE_callback_exec_null(bmain, BKE_CB_EVT_SAVE_PRE); | ||||
| /* Enforce full override check/generation on file save. */ | /* Enforce full override check/generation on file save. */ | ||||
| BKE_lib_override_library_main_operations_create(bmain, true); | BKE_lib_override_library_main_operations_create(bmain, true); | ||||
| #ifndef WITH_HEADLESS | |||||
| /* Redraw to remove menus that might be open. */ | |||||
| WM_redraw_windows(C); | |||||
campbellbarton: Better check `!G.background`.
NOTE: ifdef checks make code harder to maintain. It makes sense… | |||||
| #endif /* WITH_HEADLESS */ | |||||
| /* don't forget not to return without! */ | |||||
| WM_cursor_wait(true); | |||||
| /* blend file thumbnail */ | /* blend file thumbnail */ | ||||
| /* Save before exit_editmode, otherwise derivedmeshes for shared data corrupt T27765. */ | /* Save before exit_editmode, otherwise derivedmeshes for shared data corrupt T27765. */ | ||||
| /* Main now can store a '.blend' thumbnail, useful for background mode | /* Main now can store a '.blend' thumbnail, useful for background mode | ||||
| * or thumbnail customization. */ | * or thumbnail customization. */ | ||||
| main_thumb = thumb = bmain->blen_thumb; | main_thumb = thumb = bmain->blen_thumb; | ||||
| if (BLI_thread_is_main()) { | if (BLI_thread_is_main()) { | ||||
| if (U.file_preview_type == USER_FILE_PREVIEW_SCREENSHOT) { | if (U.file_preview_type == USER_FILE_PREVIEW_SCREENSHOT) { | ||||
| ibuf_thumb = blend_file_thumb_from_screenshot(C, &thumb); | ibuf_thumb = blend_file_thumb_from_screenshot(C, &thumb); | ||||
| } | } | ||||
| else if (U.file_preview_type == USER_FILE_PREVIEW_CAMERA) { | else if (U.file_preview_type == USER_FILE_PREVIEW_CAMERA) { | ||||
| ibuf_thumb = blend_file_thumb_from_camera(C, CTX_data_scene(C), CTX_wm_screen(C), &thumb); | ibuf_thumb = blend_file_thumb_from_camera(C, CTX_data_scene(C), CTX_wm_screen(C), &thumb); | ||||
| } | } | ||||
| } | } | ||||
| /* operator now handles overwrite checks */ | /* operator now handles overwrite checks */ | ||||
| if (G.fileflags & G_FILE_AUTOPACK) { | if (G.fileflags & G_FILE_AUTOPACK) { | ||||
| BKE_packedfile_pack_all(bmain, reports, false); | BKE_packedfile_pack_all(bmain, reports, false); | ||||
| } | } | ||||
| /* don't forget not to return without! */ | |||||
| WM_cursor_wait(true); | |||||
| ED_editors_flush_edits(bmain); | ED_editors_flush_edits(bmain); | ||||
| /* First time saving. */ | /* First time saving. */ | ||||
| /* XXX(ton): temp solution to solve bug, real fix coming. */ | /* XXX(ton): temp solution to solve bug, real fix coming. */ | ||||
| if ((BKE_main_blendfile_path(bmain)[0] == '\0') && (use_save_as_copy == false)) { | if ((BKE_main_blendfile_path(bmain)[0] == '\0') && (use_save_as_copy == false)) { | ||||
| BLI_strncpy(bmain->name, filepath, sizeof(bmain->name)); | BLI_strncpy(bmain->name, filepath, sizeof(bmain->name)); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines | |||||
Better check !G.background.