[Bf-blender-cvs] [0dc6b92] asset-experiments: FileBrowser new preview code: bunch of fixes.
Bastien Montagne
noreply at git.blender.org
Wed Apr 1 22:29:10 CEST 2015
Commit: 0dc6b92fe6d7c14a339e5905e53bfa8676b20dff
Author: Bastien Montagne
Date: Wed Apr 1 22:26:25 2015 +0200
Branches: asset-experiments
https://developer.blender.org/rB0dc6b92fe6d7c14a339e5905e53bfa8676b20dff
FileBrowser new preview code: bunch of fixes.
Start to looks good... This commit adds a new timer helper, that only send notifiers
(kind of very restricted subset of wm_job stuff), since using jobs for previews
would be now counter-productive and way too much heavy.
Also fix/enhance how previews are generated (order), etc. etc.
Still WIP though, having some weird crashes and such lurking around.
===================================================================
M source/blender/editors/space_file/filelist.c
M source/blender/editors/space_file/filelist.h
M source/blender/editors/space_file/space_file.c
M source/blender/makesdna/DNA_space_types.h
M source/blender/windowmanager/WM_api.h
M source/blender/windowmanager/WM_types.h
M source/blender/windowmanager/intern/wm_window.c
M source/blender/windowmanager/wm_event_types.h
===================================================================
diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c
index 5be35b4..9c65785 100644
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@ -1099,21 +1099,28 @@ static void filelist_cache_previews_clear(FileListEntryCache *cache)
FileListEntryPreview *preview;
if (cache->previews_pool) {
- BLI_thread_queue_nowait(cache->previews_todo);
- BLI_thread_queue_nowait(cache->previews_done);
- BLI_task_pool_cancel(cache->previews_pool);
-
- while ((preview = BLI_thread_queue_pop(cache->previews_todo))) {
- printf("%s: TODO %d - %s - %p\n", __func__, preview->index, preview->path, preview->img);
+ while ((preview = BLI_thread_queue_pop_timeout(cache->previews_todo, 0))) {
+// printf("%s: TODO %d - %s - %p\n", __func__, preview->index, preview->path, preview->img);
MEM_freeN(preview);
}
- while ((preview = BLI_thread_queue_pop(cache->previews_done))) {
- printf("%s: DONE %d - %s - %p\n", __func__, preview->index, preview->path, preview->img);
+ while ((preview = BLI_thread_queue_pop_timeout(cache->previews_done, 0))) {
+// printf("%s: DONE %d - %s - %p\n", __func__, preview->index, preview->path, preview->img);
if (preview->img) {
IMB_freeImBuf(preview->img);
}
MEM_freeN(preview);
}
+ }
+}
+
+static void filelist_cache_previews_free(FileListEntryCache *cache)
+{
+ if (cache->previews_pool) {
+ BLI_thread_queue_nowait(cache->previews_todo);
+ BLI_thread_queue_nowait(cache->previews_done);
+ BLI_task_pool_cancel(cache->previews_pool);
+
+ filelist_cache_previews_clear(cache);
BLI_thread_queue_free(cache->previews_done);
BLI_thread_queue_free(cache->previews_todo);
@@ -1139,7 +1146,6 @@ static void filelist_cache_previews_push(FileList *filelist, FileDirEntry *entry
printf("%s: %d - %s - %p\n", __func__, preview->index, preview->path, preview->img);
BLI_thread_queue_push(cache->previews_todo, preview);
}
-
}
static void filelist_cache_init(FileListEntryCache *cache)
@@ -1152,7 +1158,7 @@ static void filelist_cache_init(FileListEntryCache *cache)
static void filelist_cache_free(FileListEntryCache *cache)
{
- filelist_cache_previews_clear(cache);
+ filelist_cache_previews_free(cache);
/* Note we nearly have nothing to do here, entries are just 'borrowed', not owned by cache... */
if (cache->misc_entries) {
@@ -1163,7 +1169,7 @@ static void filelist_cache_free(FileListEntryCache *cache)
static void filelist_cache_clear(FileListEntryCache *cache)
{
- filelist_cache_previews_clear(cache);
+ filelist_cache_previews_free(cache);
/* Note we nearly have nothing to do here, entries are just 'borrowed', not owned by cache... */
cache->block_cursor = cache->block_start_index = cache->block_end_index = 0;
@@ -1429,7 +1435,7 @@ bool filelist_file_cache_block(struct FileList *filelist, const int index)
BLI_assert((end_index - start_index) <= FILELIST_ENTRYCACHESIZE) ;
-// printf("Caching block [%d:%d] (current cache: [%d:%d])\n", start_index, end_index, cache->block_start_index, cache->block_end_index);
+ printf("Caching block [%d:%d] (current cache: [%d:%d])\n", start_index, end_index, cache->block_start_index, cache->block_end_index);
if ((start_index == cache->block_start_index) && (end_index == cache->block_end_index)) {
/* Nothing to do! */
@@ -1437,103 +1443,130 @@ bool filelist_file_cache_block(struct FileList *filelist, const int index)
}
if ((start_index >= cache->block_end_index) || (end_index <= cache->block_start_index)) {
+ printf("Full Recaching!\n");
+
/* New cached block does not overlap existing one, simple. */
memcpy(cache->block_entries, &filelist->filelist_intern.filtered[start_index],
sizeof(cache->block_entries[0]) * (end_index - start_index));
+
+ if (cache->previews_pool) {
+ filelist_cache_previews_clear(cache);
+ }
+
cache->block_start_index = start_index;
cache->block_end_index = end_index;
cache->block_cursor = 0;
+ }
+ else {
+ printf("Partial Recaching!\n");
+ /* At this point, we know we keep part of currently cached entries, so update previews if needed,
+ * and remove everything from working queue - we'll add all newly needed entries at the end. */
if (cache->previews_pool) {
- i = -(cache->block_end_index - cache->block_start_index);
- while (i++) {
- const int idx = (cache->block_cursor - i) % FILELIST_ENTRYCACHESIZE;
- FileDirEntry *entry = cache->block_entries[idx];
-
- filelist_cache_previews_push(filelist, entry, start_index - i);
- }
+ filelist_cache_previews_update(filelist);
+ filelist_cache_previews_clear(cache);
}
- return true;
- }
+ printf("\tpreview cleaned up...\n");
- if (end_index > cache->block_end_index) {
- /* Add (request) needed entries after already cached ones. */
- /* Note: We need some index black magic to wrap around (cycle) inside our FILELIST_ENTRYCACHESIZE array... */
- int size1 = end_index - cache->block_end_index;
- int size2 = 0;
- int idx1, idx2;
+ if (end_index > cache->block_end_index) {
+ /* Add (request) needed entries after already cached ones. */
+ /* Note: We need some index black magic to wrap around (cycle) inside our FILELIST_ENTRYCACHESIZE array... */
+ int size1 = end_index - cache->block_end_index;
+ int size2 = 0;
+ int idx1, idx2;
- idx1 = (cache->block_cursor + curr_block_size) % FILELIST_ENTRYCACHESIZE;
- if ((idx1 + size1) > FILELIST_ENTRYCACHESIZE) {
- size2 = size1;
- size1 = FILELIST_ENTRYCACHESIZE - idx1;
- size2 -= size1;
- idx2 = 0;
- }
+ idx1 = (cache->block_cursor + curr_block_size) % FILELIST_ENTRYCACHESIZE;
+ if ((idx1 + size1) > FILELIST_ENTRYCACHESIZE) {
+ size2 = size1;
+ size1 = FILELIST_ENTRYCACHESIZE - idx1;
+ size2 -= size1;
+ idx2 = 0;
+ }
- if (size2) {
- memcpy(&cache->block_entries[idx2], &filelist->filelist_intern.filtered[end_index - size2],
- sizeof(cache->block_entries[0]) * size2);
- }
- memcpy(&cache->block_entries[idx1], &filelist->filelist_intern.filtered[end_index - size1 - size2],
- sizeof(cache->block_entries[0]) * size1);
+ if (size2) {
+ memcpy(&cache->block_entries[idx2], &filelist->filelist_intern.filtered[end_index - size2],
+ sizeof(cache->block_entries[0]) * size2);
+ }
+ memcpy(&cache->block_entries[idx1], &filelist->filelist_intern.filtered[end_index - size1 - size2],
+ sizeof(cache->block_entries[0]) * size1);
- if (cache->previews_pool) {
- i = size1 + size2;
- while (i--) {
- const int idx = (cache->block_cursor + end_index - start_index - i - 1) % FILELIST_ENTRYCACHESIZE;
- FileDirEntry *entry = cache->block_entries[idx];
+ if (cache->previews_pool) {
+ i = size1 + size2;
+ while (i--) {
+ const int idx = (cache->block_cursor + end_index - start_index - i - 1) % FILELIST_ENTRYCACHESIZE;
+ FileDirEntry *entry = cache->block_entries[idx];
- filelist_cache_previews_push(filelist, entry, end_index - i);
+ filelist_cache_previews_push(filelist, entry, end_index - i);
+ }
}
}
- }
- cache->block_end_index = end_index;
+ cache->block_end_index = end_index;
- if (start_index < cache->block_start_index) {
- /* Add (request) needed entries before already cached ones. */
- /* Note: We need some index black magic to wrap around (cycle) inside our FILELIST_ENTRYCACHESIZE array... */
- int size1 = cache->block_start_index - start_index;
- int size2 = 0;
- int idx1, idx2;
+ printf("\tend-extended...\n");
- if (size1 > cache->block_cursor) {
- size2 = size1;
- size1 -= cache->block_cursor;
- size2 -= size1;
- idx2 = 0;
- idx1 = FILELIST_ENTRYCACHESIZE - size1;
+ if (start_index < cache->block_start_index) {
+ /* Add (request) needed entries before already cached ones. */
+ /* Note: We need some index black magic to wrap around (cycle) inside our FILELIST_ENTRYCACHESIZE array... */
+ int size1 = cache->block_start_index - start_index;
+ int size2 = 0;
+ int idx1, idx2;
- }
- else {
- idx1 = cache->block_cursor - size1;
- }
+ if (size1 > cache->block_cursor) {
+ size2 = size1;
+ size1 -= cache->block_cursor;
+ size2 -= size1;
+ idx2 = 0;
+ idx1 = FILELIST_ENTRYCACHESIZE - size1;
- if (size2) {
- memcpy(&cache->block_entries[idx2], &filelist->filelist_intern.filtered[start_index + size1],
- sizeof(cache->block_entries[0]) * size2);
- }
- memcpy(&cache->block_entries[idx1], &filelist->filelist_intern.filtered[start_index],
- sizeof(cache->block_entries[0]) * size1);
+ }
+ else {
+ idx1 = cache->block_cursor - size1;
+ }
- cache->block_cursor = idx1;
+ if (size2) {
+ memcpy(&cache->block_entries[idx2], &filelist->filelist_intern.filtered[start_index + size1],
+ sizeof(cache->block_entries[0]) * size2);
+ }
+ memcpy(&cache->block_entries[idx1], &filelist->filelist_intern.filtered[start_index],
+ sizeof(cache->block_entries[0]) * size1);
- if (cache->previews_pool) {
- i = -(size1 + size2);
- while (i++) {
- const int idx = (cache->block_cursor - i) % FILELIST_ENTRYCACHESIZE;
- FileDirEntry *entry = cache->block_entries[idx];
+ cache->block_cursor = idx1;
+
+ if (cache->previews_pool) {
+ i = -(size1 + size2);
+ while (i++) {
+ const int idx = (cache->block_cursor - i) % FILELIST_ENTRYCACHESIZE;
+ FileDirEntry *entry = cache->block_entries[idx];
- filelist_cache_previews_push(filelist, entry, start_index - i);
+ filelist_cache_previews_push(filelist, entry, start_index - i);
+ }
}
}
+ else if (start_index > cache->block_start_index) {
+ /* We do not free anything, just update start index and cursor. */
+ cache->block_cursor = (cache->block_cursor + start_index - cache->block_start_index) % FILELIST_ENTRYCACHESIZE;
+ }
+ cache->block_start_index = start_index;
+ printf("\tstart-extended...\n");
}
- else if (start_index > cache->block_start_index) {
- /* We do not free anything, just update start index and cursor. */
- cache->block_cursor = (cache->block_cursor + start_index - cache->block_start_index) % FILELIST_ENTRYCACHESIZE;
+
+ printf("Re-queueing previews...\n");
+
+ if (cache->
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list