Blender V5.3
image_undo.cc File Reference
#include "CLG_log.h"
#include "MEM_guardedalloc.h"
#include "BLI_index_range.hh"
#include "BLI_listbase.hh"
#include "BLI_map.hh"
#include "BLI_math_base_c.hh"
#include "BLI_math_vector.hh"
#include "BLI_mutex.hh"
#include "BLI_rect.hh"
#include "BLI_string.hh"
#include "BLI_task.hh"
#include "BLI_threads.hh"
#include "BLI_utildefines.hh"
#include "DNA_image_types.h"
#include "DNA_object_types.h"
#include "DNA_screen_types.h"
#include "DNA_space_types.h"
#include "DNA_userdef_types.h"
#include "DNA_windowmanager_types.h"
#include "IMB_imbuf.hh"
#include "IMB_imbuf_types.hh"
#include "IMB_partial_update.hh"
#include "BKE_context.hh"
#include "BKE_image.hh"
#include "BKE_image_gpu.hh"
#include "BKE_paint.hh"
#include "BKE_paint_types.hh"
#include "BKE_undo_system.hh"
#include "DEG_depsgraph.hh"
#include "ED_object.hh"
#include "ED_paint.hh"
#include "ED_undo.hh"
#include "ED_util.hh"
#include "WM_api.hh"

Go to the source code of this file.

Classes

struct  blender::PaintTileKey
struct  blender::PaintTile
struct  blender::PaintTileMap
struct  blender::UndoImageTile
struct  blender::UndoImageBuf
struct  blender::UndoImageHandle
struct  blender::ImageUndoStep

Namespaces

namespace  blender
 BMesh Iterators.

Functions

Paint Tiles

Created on demand while painting, use to access the previous state for some paint operations.

These buffers are also used for undo when available.

static void blender::calc_tile_rect (const ImBuf &ibuf, const int x_tile, const int y_tile, int2 &r_tile_pos, int2 &r_tile_size)
static rcti blender::calc_tile_region (const ImBuf &ibuf, const int x_tile, const int y_tile)
static void blender::ptile_free (PaintTile *ptile)
static void blender::ptile_invalidate_map (PaintTileMap *paint_tile_map)
const ImBuf * blender::ED_image_paint_tile_find (PaintTileMap *paint_tile_map, Image *image, ImBuf *ibuf, ImageUser *iuser, int x_tile, int y_tile, unsigned short **r_mask, bool validate)
const ImBuf * blender::ED_image_paint_tile_push (PaintTileMap *paint_tile_map, Image *image, ImBuf *ibuf, ImageUser *iuser, int x_tile, int y_tile, unsigned short **r_mask, bool **r_valid)
static void blender::ptile_restore_runtime_map (PaintTileMap *paint_tile_map)
Image Undo Tile
static uint32_t blender::index_from_xy (uint32_t tile_x, uint32_t tile_y, const uint32_t tiles_dims[2])
static UndoImageTile * blender::utile_alloc (bool has_float)
static void blender::utile_init_from_imbuf (UndoImageTile *utile, const int x_tile, const int y_tile, const ImBuf *ibuf)
static void blender::utile_restore (const UndoImageTile *utile, const int x_tile, const int y_tile, ImBuf *ibuf)
static void blender::utile_decref (UndoImageTile *utile)
Image Undo Buffer
static UndoImageBuf * blender::ubuf_from_image_no_tiles (Image *image, const ImBuf *ibuf)
static void blender::ubuf_from_image_all_tiles (UndoImageBuf *ubuf, const ImBuf *ibuf)
static bool blender::ubuf_ensure_compat_ibuf (const UndoImageBuf *ubuf, ImBuf *ibuf)
static void blender::ubuf_free (UndoImageBuf *ubuf)
Image Undo Internal Utilities
static UndoImageBuf * blender::uhandle_lookup_ubuf (UndoImageHandle *uh, const Image *, const StringRef ibuf_filepath, const int ibuf_fileframe)
static UndoImageBuf * blender::uhandle_add_ubuf (UndoImageHandle *uh, Image *image, ImBuf *ibuf)
static UndoImageBuf * blender::uhandle_ensure_ubuf (UndoImageHandle *uh, Image *image, ImBuf *ibuf)
static UndoImageHandle * blender::uhandle_lookup_by_name (ListBaseT< UndoImageHandle > *undo_handles, const Image *image, int tile_number)
static UndoImageHandle * blender::uhandle_lookup (ListBaseT< UndoImageHandle > *undo_handles, const Image *image, int tile_number)
static UndoImageHandle * blender::uhandle_add (ListBaseT< UndoImageHandle > *undo_handles, Image *image, ImageUser *iuser)
static UndoImageHandle * blender::uhandle_ensure (ListBaseT< UndoImageHandle > *undo_handles, Image *image, ImageUser *iuser)
Implements ED Undo System
static UndoImageBuf * blender::ubuf_lookup_from_reference (ImageUndoStep *us_prev, const Image *image, int tile_number, const UndoImageBuf *ubuf)
static void blender::image_undosys_step_encode_init (bContext *, UndoStep *us_p)
static bool blender::image_undosys_step_encode (bContext *C, Main *, UndoStep *us_p)
static void blender::image_undosys_step_decode_undo_impl (ImageUndoStep *us)
static void blender::image_undosys_step_decode_redo_impl (ImageUndoStep *us)
static void blender::image_undosys_step_decode_undo (ImageUndoStep *us, bool is_final)
static void blender::image_undosys_step_decode_redo (ImageUndoStep *us)
static void blender::image_undosys_step_decode (bContext *C, Main *bmain, UndoStep *us_p, const eUndoStepDir dir, bool is_final)
static void blender::image_undosys_step_free (UndoStep *us_p)
static void blender::image_undosys_foreach_ID_ref (UndoStep *us_p, UndoTypeForEachIDRefFn foreach_ID_ref_fn, void *user_data)
void blender::ED_image_undosys_type (UndoType *ut)
Utilities
PaintTileMap * blender::ED_image_paint_tile_map_get ()
void blender::ED_image_undo_restore (UndoStep *us)
static ImageUndoStep * blender::image_undo_push_begin (const char *name, PaintMode paint_mode)
void blender::ED_image_undo_push_begin (const char *name, PaintMode paint_mode)
void blender::ED_image_undo_push_begin_with_image (const char *name, Image *image, ImBuf *ibuf, ImageUser *iuser)
void blender::ED_image_undo_push_begin_with_image_all_udims (const char *name, Image *image, ImageUser *iuser)
void blender::ED_image_undo_push (Image *image, ImBuf *ibuf, ImageUser *iuser, ImageUndoStep *us)
void blender::ED_image_undo_push_end ()

Variables

static CLG_LogRef blender::LOG = {"undo.image"}

Image Undo Handle

enum class  blender::RestoreMode { blender::Changed , blender::FullUpdateChanged , blender::All }
static void blender::uhandle_restore_list (ListBaseT< UndoImageHandle > *undo_handles, const bool use_init, const RestoreMode mode=RestoreMode::Changed)
static void blender::uhandle_free_list (ListBaseT< UndoImageHandle > *undo_handles)

Detailed Description

Overview

  • Each undo step is a #ImageUndoStep
  • Each #ImageUndoStep stores a list of #UndoImageHandle
    • Each #UndoImageHandle stores a list of #UndoImageBuf (this is the undo systems equivalent of an #ImBuf).
      • Each #UndoImageBuf stores an array of #UndoImageTile The tiles are shared between #UndoImageBuf's to avoid duplication.

When the undo system manages an image, there will always be a full copy (as a #UndoImageBuf) each new undo step only stores modified tiles.

Changeset IDs are used to track the correspondence between image buffers used in the main database and in the undo stack. An ImBuf may be allocated, freed, reloaded or resized as part of global memfile undo steps. A matching changeset ID means that it's the same image buffer and individual tiles can be restored, rather than having to do a full image buffer restore.

Definition in file image_undo.cc.