feat: load LUT libraries and selections in background with cancellation and visible-only thumbnails

这个提交包含在:
mac 于 2026-11-01 11:08:10 +08:00 提交
1 父节点 57830ca744
当前提交 87baa785fd
9 个文件已更改
+710 -100

没有与搜索条件相匹配的文件

+97
查看文件
@@ -0,0 +1,97 @@
#import <AppKit/AppKit.h>
#import "../大鱼调色/Plugin/DYLUTLibrary.h"
#ifndef DY_LUT_BASELINE
#import "../大鱼调色/Plugin/DYLUTBrowser.h"
@interface DYLUTBrowser (Acceptance)
- (void)layoutBrowser;
- (void)rebuildGrid;
- (void)thumbnailClicked:(id)sender;
- (void)clearSelection:(id)sender;
- (void)importSelectedURLs:(NSArray *)urls;
@end
#endif
#include <string>
#include <unistd.h>
static NSMutableArray *checks;
static void require(BOOL pass,NSString *name) {
[checks addObject:@{@"name":name,@"pass":@(pass)}];
if(!pass){fprintf(stderr,"FAIL: %s\n",name.UTF8String);exit(1);}
}
static void pump(BOOL (^done)(void)) {
NSTimeInterval until=NSProcessInfo.processInfo.systemUptime+60;
while(!done()&&NSProcessInfo.processInfo.systemUptime<until)
[[NSRunLoop mainRunLoop]runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:.01]];
require(done(),@"background operation completes within timeout");
}
static NSData *cube(NSUInteger n) {
std::string text="TITLE \"Synthetic responsiveness fixture\"\nLUT_3D_SIZE "+std::to_string(n)+"\n";char row[100];
for(NSUInteger z=0;z<n;z++)for(NSUInteger y=0;y<n;y++)for(NSUInteger x=0;x<n;x++){
snprintf(row,sizeof(row),"%.7f %.7f %.7f\n",double(x)/(n-1),double(y)/(n-1),double(z)/(n-1));text+=row;
}
return [NSData dataWithBytes:text.data() length:text.size()];
}
int main(int argc,const char *argv[]) {@autoreleasepool {
require(argc==2,@"report destination supplied");checks=[NSMutableArray new];
NSFileManager *fm=NSFileManager.defaultManager;NSError *error=nil;
NSURL *root=[NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:[@"dayu-lut-responsive-" stringByAppendingString:NSUUID.UUID.UUIDString]] isDirectory:YES];
NSURL *source=[root URLByAppendingPathComponent:@"Pack" isDirectory:YES],*destination=[root URLByAppendingPathComponent:@"Library" isDirectory:YES];
require([fm createDirectoryAtURL:source withIntermediateDirectories:YES attributes:nil error:&error],@"isolated source folder created");
NSData *large=cube(65);const NSUInteger count=24;
for(NSUInteger i=0;i<count;i++)require([large writeToURL:[source URLByAppendingPathComponent:[NSString stringWithFormat:@"Large-%02lu.cube",(unsigned long)i]] atomically:NO],@"synthetic 65-cube file written");
NSURL *anchor=[root URLByAppendingPathComponent:@"Anchor.cube"];require([cube(2)writeToURL:anchor atomically:NO],@"anchor fixture written");
DYLUTLibrary *library=[[[DYLUTLibrary alloc]initWithRootURL:destination]autorelease];
require([library importURLs:@[anchor] error:&error].count==1,@"preexisting library item imported");
__block NSTimeInterval last=NSProcessInfo.processInfo.systemUptime,maxGap=0;__block NSUInteger ticks=0,snapshots=0;
NSTimer *timer=[NSTimer scheduledTimerWithTimeInterval:.005 repeats:YES block:^(NSTimer *t){NSTimeInterval now=NSProcessInfo.processInfo.systemUptime;maxGap=MAX(maxGap,now-last);last=now;ticks++;snapshots+=library.entries.count>0&&library.folders.count>0;}];
NSTimeInterval start=NSProcessInfo.processInfo.systemUptime;__block BOOL done=NO;__block NSUInteger importedCount=0;
#ifdef DY_LUT_BASELINE
NSArray *imported=[library importURLs:@[source] error:&error];importedCount=imported.count;done=YES;
#else
[library importURLsAsync:@[source] completion:^(NSArray *imported,NSError *failure){require(NSThread.isMainThread,@"import completion is on main queue");require(failure==nil,@"bulk import succeeds");importedCount=imported.count;done=YES;}];
#endif
pump(^{return done;});NSTimeInterval duration=NSProcessInfo.processInfo.systemUptime-start;
NSDate *settle=[NSDate dateWithTimeIntervalSinceNow:.03];while(settle.timeIntervalSinceNow>0)[[NSRunLoop mainRunLoop]runMode:NSDefaultRunLoopMode beforeDate:settle];[timer invalidate];
require(importedCount==count&&library.entries.count==count+1,@"all files and previous entry preserved");
NSMutableDictionary *report=[NSMutableDictionary dictionaryWithDictionary:@{@"bulkFiles":@(count),@"cubeDimension":@65,@"sourceBytes":@(large.length*count),@"importSeconds":@(duration),@"mainHeartbeatMaxGapMS":@(maxGap*1000),@"mainHeartbeatTicks":@(ticks),@"snapshotsReadDuringImport":@(snapshots)}];
#ifndef DY_LUT_BASELINE
require(ticks>10&&maxGap<.15,@"main run loop stays responsive while importing");
done=NO;__block BOOL cancelledDuringCopy=NO;
NSProgress *cancelled=[library importURLsAsync:@[source] completion:^(NSArray *items,NSError *failure){require(!items&&failure.code==NSUserCancelledError,@"cancelled import returns cancellation");done=YES;}];
NSTimer *canceller=[NSTimer scheduledTimerWithTimeInterval:.001 repeats:YES block:^(NSTimer *t){if(cancelled.completedUnitCount>count){cancelledDuringCopy=YES;[cancelled cancel];[t invalidate];}}];
pump(^{return done;});[canceller invalidate];require(cancelledDuringCopy,@"cancel exercised after copy had begun");
require([library reload:&error]&&library.entries.count==count+1,@"cancel rolls back newly copied files only");
done=NO;NSProgress *scan=[library reloadAsync:^(NSError *failure){require(failure.code==NSUserCancelledError,@"cancelled scan reports cancellation");done=YES;}];[scan cancel];pump(^{return done;});
require(library.entries.count==count+1,@"cancelled scan preserves previous snapshot");
done=NO;DYLUTPrepareAsync([source URLByAppendingPathComponent:@"Large-00.cube"].path,^(NSError *failure){require(!failure&&NSThread.isMainThread,@"cold selection prepares off thread and completes on main");done=YES;});pump(^{return done;});
NSURL *bad=[root URLByAppendingPathComponent:@"Invalid.cube"];[@"invalid LUT" writeToURL:bad atomically:NO encoding:NSUTF8StringEncoding error:&error];
done=NO;DYLUTPrepareAsync(bad.path,^(NSError *failure){require(failure!=nil,@"invalid selection reports failure asynchronously");done=YES;});pump(^{return done;});
// Real browser objects, never shown; its grid should represent thousands of
// files with only visible/overscan buttons, including after a distant scroll.
NSURL *catalog=[destination URLByAppendingPathComponent:@"Catalog" isDirectory:YES];[fm createDirectoryAtURL:catalog withIntermediateDirectories:NO attributes:nil error:&error];
BOOL catalogOK=YES;for(NSUInteger i=0;i<3000;i++){NSString *path=[catalog.path stringByAppendingPathComponent:[NSString stringWithFormat:@"Catalog-%04lu.cube",(unsigned long)i]];if(link(anchor.path.fileSystemRepresentation,path.fileSystemRepresentation)!=0){catalogOK=NO;break;}}require(catalogOK,@"3000 catalog fixtures created");
[NSApplication sharedApplication];[NSApp setActivationPolicy:NSApplicationActivationPolicyProhibited];
NSMutableArray *selected=[NSMutableArray array];
DYLUTBrowser *browser=[[DYLUTBrowser alloc]initWithLibrary:library preview:nil selectedPath:nil palette:@{} selection:^(NSString *path){[selected addObject:path?:@""];}];
pump(^{return [browser valueForKey:@"libraryTask"]==nil;});
NSUInteger visible=[[browser valueForKey:@"visibleEntries"]count],tileCount=[[browser valueForKey:@"tiles"]count];
require(visible==3025&&tileCount>0&&tileCount<200,@"large catalog creates only visible thumbnail controls");
NSScrollView *scroll=[browser valueForKey:@"gridScroll"];[scroll.contentView scrollToPoint:NSMakePoint(0,scroll.documentView.frame.size.height-scroll.contentSize.height)];[browser layoutBrowser];
require([[browser valueForKey:@"tiles"]count]<200,@"scrolling keeps thumbnail view count bounded");
NSSearchField *search=[browser valueForKey:@"search"];search.stringValue=@"Catalog-000";[browser rebuildGrid];
require([[browser valueForKey:@"visibleEntries"]count]==10,@"search remains usable after catalog loading");
NSDictionary *tiles=[browser valueForKey:@"tiles"];NSArray *keys=[tiles.allKeys sortedArrayUsingSelector:@selector(compare:)];
[browser thumbnailClicked:tiles[keys[0]]];[browser thumbnailClicked:tiles[keys[1]]];pump(^{return [browser valueForKey:@"selectionTask"]==nil;});
require(selected.count==1&&[selected.lastObject isEqual:keys[1]],@"rapid selection applies only the latest LUT");
[browser thumbnailClicked:tiles[keys[0]]];[browser clearSelection:nil];pump(^{return [browser valueForKey:@"selectionTask"]==nil;});
require([selected.lastObject isEqual:@""],@"clear selection supersedes pending LUT application");
[browser importSelectedURLs:@[source]];[browser close];done=NO;[library reloadAsync:^(NSError *failure){require(!failure,@"scan after browser close completes");done=YES;}];pump(^{return done;});
require(library.entries.count==3025,@"closing during import cancels without changing existing library");
[browser release];report[@"largeCatalogEntries"]=@(visible);report[@"initialLiveThumbnailViews"]=@(tileCount);report[@"pass"]=@YES;
#else
report[@"mode"]=@"baseline synchronous import";
#endif
report[@"checks"]=checks;report[@"scope"]=@"Synthetic 24 x 65-cube import with real main-run-loop heartbeat and snapshot reads; headless browser cancellation, latest selection and 3,025-entry virtualization. No user library or visible test app.";
NSData *json=[NSJSONSerialization dataWithJSONObject:report options:NSJSONWritingPrettyPrinted error:&error];require([json writeToFile:[NSString stringWithUTF8String:argv[1]] atomically:YES],@"report written");
require([fm removeItemAtURL:root error:&error],@"isolated fixtures removed");printf("PASS: import %.3fs, main gap %.1fms, %lu ticks\n",duration,maxGap*1000,(unsigned long)ticks);[checks release];return 0;
}}