fix: make pen drafts immediate and serializable, reject stale edits, and align tracked path ROI and optical flow with local reference evidence

这个提交包含在:
mac 于 2026-11-01 23:15:31 +08:00 提交
1 父节点 38adc259e0
当前提交 0b53fdcdfd
9 个文件已更改
+522 -55

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

+3 -3
查看文件
@@ -15,7 +15,7 @@
- (dy::GrayFrame)toolGrayFrame:(FxImageTile*)tile error:(NSError**)error {
@synchronized(_toolCaptureDevices){FxRect b=tile.tilePixelBounds,image=tile.imagePixelBounds;if(b.left!=image.left||b.right!=image.right||b.bottom!=image.bottom||b.top!=image.top)return {};
NSNumber *key=@(tile.deviceRegistryID);NSMutableDictionary *entry=_toolCaptureDevices[key];if(!entry){NSArray *devices=MTLCopyAllDevices();id<MTLDevice>d=nil;for(id<MTLDevice>candidate in devices)if(candidate.registryID==tile.deviceRegistryID)d=candidate;if(d){id<MTLLibrary>library=[d newLibraryWithURL:[[NSBundle bundleForClass:self.class]URLForResource:@"default" withExtension:@"metallib"]error:error];id<MTLFunction>function=[library newFunctionWithName:@"dyToolCapture"];id<MTLComputePipelineState>pipeline=function?[d newComputePipelineStateWithFunction:function error:error]:nil;id<MTLCommandQueue>queue=[d newCommandQueue];if(pipeline&&queue){entry=[NSMutableDictionary dictionaryWithDictionary:@{@"device":d,@"pipeline":pipeline,@"queue":queue}];_toolCaptureDevices[key]=entry;}[pipeline release];[queue release];[function release];[library release];}[devices release];if(!entry)return {};}
id<MTLTexture>texture=[tile metalTextureForDevice:entry[@"device"]];if(!texture)return {};double aspect=MAX(.01,tile.pixelAspect),displayHeight=texture.height/aspect,scale=MIN(1.,MIN(3840./texture.width,2160./displayHeight));unsigned width=(unsigned)floor(texture.width*scale),height=(unsigned)floor(displayHeight*scale);if(width<16||height<16||height>2160||width>3840)return {};
id<MTLTexture>texture=[tile metalTextureForDevice:entry[@"device"]];if(!texture)return {};double aspect=tile.pixelAspect;if(!std::isfinite(aspect)||aspect<=0)return {};aspect=MAX(.01,aspect);double displayHeight=texture.height/aspect,scale=MIN(1.,MIN(3840./texture.width,2160./displayHeight));unsigned width=(unsigned)floor(texture.width*scale),height=(unsigned)floor(displayHeight*scale);if(width<16||height<16||height>2160||width>3840)return {};
id<MTLBuffer>buffer=[entry[@"device"]newBufferWithLength:width*height*sizeof(float) options:MTLResourceStorageModeShared];if(!buffer)return {};vector_uint3 info={width,height,(unsigned)(tile.imageOrigin==kFxImageOrigin_BOTTOM_LEFT)};id<MTLCommandBuffer>commands=[entry[@"queue"]commandBuffer];id<MTLComputeCommandEncoder>encoder=[commands computeCommandEncoder];[encoder setComputePipelineState:entry[@"pipeline"]];[encoder setTexture:texture atIndex:0];[encoder setBuffer:buffer offset:0 atIndex:0];[encoder setBytes:&info length:sizeof(info) atIndex:1];[encoder dispatchThreads:MTLSizeMake(width,height,1) threadsPerThreadgroup:MTLSizeMake(16,16,1)];[encoder endEncoding];[commands commit];[commands waitUntilCompleted];dy::GrayFrame frame;if(commands.status==MTLCommandBufferStatusCompleted){frame={int(width),int(height),std::vector<float>(width*height)};memcpy(frame.pixels.data(),buffer.contents,width*height*sizeof(float));}[buffer release];return frame;
}
}
@@ -25,14 +25,14 @@
}
- (void)toolCanvasSelection:(NSNotification*)notification {
NSString *node=notification.userInfo[@"node"],*mask=notification.userInfo[@"mask"];if(!node||!mask)return;NSDictionary *document=notification.userInfo[@"document"];if(document&&DYValidToolDocument(document)){DYToolDocument *immutable=[[[DYToolDocument alloc]init]autorelease];immutable.document=document;[self adoptToolCanvasDocument:immutable.document];}os_log(OS_LOG_DEFAULT,"dayu_tool_canvas_selected");
@synchronized(self){if(_trackingActive.load()&&(![_trackingNode isEqual:node]||![_trackingMaskID isEqual:mask])){_trackingCancelled.store(true);_trackingDiscard=YES;}[_selectedToolNode release];_selectedToolNode=[node copy];[_selectedToolMask release];_selectedToolMask=[mask copy];_toolCanvasHidden=[notification.userInfo[@"hidden"]boolValue];_toolDrawingPen=[notification.userInfo[@"draw"]boolValue];++_toolCanvasRevision;_toolCanvasEditTime=kCMTimeInvalid;[_toolCanvasDraft release];_toolCanvasDraft=nil;[_toolCanvasOriginal release];_toolCanvasOriginal=nil;}[self postToolCanvasStatus:_toolDrawingPen?@"钢笔:点击放点,拖出曲柄;点首节点或完成绘制闭合。":@"已选中本层蒙版"];
@synchronized(self){if(_trackingActive.load()&&(![_trackingNode isEqual:node]||![_trackingMaskID isEqual:mask])){_trackingCancelled.store(true);_trackingDiscard=YES;}[_selectedToolNode release];_selectedToolNode=[node copy];[_selectedToolMask release];_selectedToolMask=[mask copy];_toolCanvasHidden=[notification.userInfo[@"hidden"]boolValue];_toolDrawingPen=[notification.userInfo[@"draw"]boolValue];++_toolCanvasRevision;_toolCanvasEditTime=kCMTimeInvalid;_toolDragPart=0;[_toolCanvasDraft release];_toolCanvasDraft=nil;[_toolCanvasOriginal release];_toolCanvasOriginal=nil;}[self postToolCanvasStatus:_toolDrawingPen?@"钢笔:点击放点,拖出曲柄;点首节点或完成绘制闭合。":@"已选中本层蒙版"];
}
- (BOOL)toolCanvasVisible {@synchronized(self){return _selectedToolNode&&_selectedToolMask&&!_toolCanvasHidden;}}
- (NSDictionary*)toolCanvasMaskAtTime:(CMTime)time {
@synchronized(self){if(_toolCanvasHidden||!_selectedToolMask)return nil;NSDictionary *m=_toolCanvasDraft?:[self toolMask:_selectedToolMask node:_selectedToolNode document:_toolCanvasDocument];if(!m)return nil;DYMaskParameters p=DYMaskAtTime(m,time);return @{@"id":m[@"id"],@"parameters":[NSData dataWithBytes:&p length:sizeof(p)],@"nodes":(_toolDrawingPen&&!_toolCanvasDraft)?[NSData data]:(m[@"nodes"]?:[NSData data]),@"drawing":@(_toolDrawingPen),@"coverage":@(_toolShowCoverage)};}
}
- (void)toolTrackRequested:(NSNotification*)notification {
NSInteger direction=[notification.userInfo[@"direction"]integerValue];if(direction==9){_trackingCancelled.store(true);return;}if(_trackingActive.load()){[self toolStatus:@"请先取消当前跟踪"];return;}
NSInteger direction=[notification.userInfo[@"direction"]integerValue];if(direction==9){_trackingCancelled.store(true);return;}@synchronized(self){if(_toolDrawingPen||_toolCanvasCommitPending){[self postToolCanvasStatus:@"请先完成或取消钢笔绘制,再开始跟踪。"];return;}}if(_trackingActive.load()){[self toolStatus:@"请先取消当前跟踪"];return;}
id<FxCustomParameterActionAPI_v4>a=[_apiManager apiForProtocol:@protocol(FxCustomParameterActionAPI_v4)];if(!a)return;[a startAction:self];@try{
id<FxAnalysisAPI>analysis=[_apiManager apiForProtocol:@protocol(FxAnalysisAPI)];FxAnalysisState state=[analysis analysisStateForEffect];if(!analysis||state==kFxAnalysisState_AnalysisRequested||state==kFxAnalysisState_AnalysisStarted){[self toolStatus:@"宿主未就绪,请等待当前分析结束"];return;}
CMTime time=a.currentTime;NSDictionary *doc=DYReadTools(_apiManager,time).document;NSDictionary *mask=[self toolMask:notification.userInfo[@"mask"] node:notification.userInfo[@"node"] document:doc];if(!mask||![mask[@"enabled"]boolValue]){[self toolStatus:@"请先选择当前工具的启用蒙版"];return;}DYMaskParameters seed=DYMaskAtTime(mask,time);if(seed.kind>DYMaskBezier||(seed.kind==DYMaskBezier&&[mask[@"nodes"]length]<3*sizeof(DYBezierNode))){[self toolStatus:@"跟踪需要矩形、椭圆或闭合钢笔区域"];return;}