diff options
author | Bastien Montagne <bastien@blender.org> | 2020-07-03 13:34:20 +0300 |
---|---|---|
committer | Bastien Montagne <bastien@blender.org> | 2020-07-03 13:56:21 +0300 |
commit | 8e0f8bb3e153d5cae0050ceb90e6b561069fe05b (patch) | |
tree | 16454036c57afed0efaf10bdf540fc1719f17bb1 /source/blender/blenkernel/intern | |
parent | 5fa6bd8a8ddbd13ef58d127546af2f57d1905be4 (diff) |
New undo cache management: Add Image IDs.
Some notes:
* `Image.cache` acts as some kind of 'main' cache, when it is NULL
(could not be restored), other caches should also be cleared. Oddly
enough, previous code was not clearing **all** caches, could not find
any reason for that behavior, so new code does a full clear.
* `imamap` is still used for Node previews from scenes' compositor,
however this is actually fully disabled in `direct_link_node()`.
* For render slots we cannot use offsetof as third part of the cache
key, so we are using a hash of the slot's name instead.
As far as I can tell, this fixes T76989: Visual glitches when undo after
reload multiple images by script (in Material Preview).
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/image.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index bb793b58a1d..e1d055512f0 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -185,6 +185,37 @@ static void image_free_data(ID *id) BLI_freelistN(&image->tiles); } +static void image_foreach_cache(ID *id, + IDTypeForeachCacheFunctionCallback function_callback, + void *user_data) +{ + Image *image = (Image *)id; + IDCacheKey key = { + .id_session_uuid = id->session_uuid, + .offset_in_ID = offsetof(Image, cache), + .cache_v = image->cache, + }; + function_callback(id, &key, (void **)&image->cache, user_data); + + for (int eye = 0; eye < 2; eye++) { + for (int a = 0; a < TEXTARGET_COUNT; a++) { + key.offset_in_ID = offsetof(Image, gputexture[a][eye]); + key.cache_v = image->gputexture[a][eye]; + function_callback(id, &key, (void **)&image->gputexture[a][eye], user_data); + } + } + + key.offset_in_ID = offsetof(Image, rr); + key.cache_v = image->rr; + function_callback(id, &key, (void **)&image->rr, user_data); + + LISTBASE_FOREACH (RenderSlot *, slot, &image->renderslots) { + key.offset_in_ID = (size_t)BLI_ghashutil_strhash_p(slot->name); + key.cache_v = slot->render; + function_callback(id, &key, (void **)&slot->render, user_data); + } +} + IDTypeInfo IDType_ID_IM = { .id_code = ID_IM, .id_filter = FILTER_ID_IM, @@ -200,6 +231,7 @@ IDTypeInfo IDType_ID_IM = { .free_data = image_free_data, .make_local = NULL, .foreach_id = NULL, + .foreach_cache = image_foreach_cache, }; /* prototypes */ |