Add tracked clone stamps and reduce canvas redraw work
这个提交包含在:
1 父节点
504e08e425
当前提交
0782b5e654
17 个文件已更改
+347
-53
没有与搜索条件相匹配的文件
@@ -24,9 +24,56 @@
|
||||
- (BOOL)managedProfile:(DYColorProfile*)profile input:(id<MTLTexture>)input output:(id<MTLTexture>)output entry:(NSMutableDictionary*)entry error:(NSError**)error {
|
||||
if(!profile)return NO;NSMutableDictionary*cache=entry[@"managedProfiles"];if(!cache){cache=[NSMutableDictionary dictionary];entry[@"managedProfiles"]=cache;}DYColorProfileGPU*p=cache[profile.key];if(!p){p=[[[DYColorProfileGPU alloc]initWithDevice:entry[@"device"] profile:profile error:error]autorelease];if(!p)return NO;if(cache.count>=16)[cache removeAllObjects];cache[profile.key]=p;}return [p renderInput:input output:output alpha:dycm::Alpha::Premultiplied workspaceBudget:2ull*1024*1024*1024 cancelled:nullptr error:error];
|
||||
}
|
||||
// Each stamp reads the same original frame. A later stamp may cover an
|
||||
// earlier one, but overlapping source and destination never feed back.
|
||||
- (FxImageTile*)sourceByApplyingStamps:(NSArray*)masks source:(FxImageTile*)source registry:(uint64_t)registry error:(NSError**)error{
|
||||
std::vector<DYCloneStamp> stamps;
|
||||
FxRect image=source.imagePixelBounds,bounds=source.tilePixelBounds;
|
||||
if(image.right<=image.left||image.top<=image.bottom)return source;
|
||||
float aspect=float(image.right-image.left)/(image.top-image.bottom);
|
||||
for(NSDictionary *mask in masks){
|
||||
NSArray *patch=mask[@"stampSource"];
|
||||
if(!patch||![mask[@"enabled"]boolValue])continue;
|
||||
DYMaskParameters p=DYMaskAtTime(mask,kCMTimeInvalid);
|
||||
if(p.strength<=0)continue;
|
||||
float c=cosf(p.angle),s=sinf(p.angle);
|
||||
stamps.push_back({p.centerX,p.centerY,[patch[0]floatValue],[patch[1]floatValue],[patch[2]floatValue],[patch[3]floatValue],
|
||||
2*c/p.width,2*s/(p.width*aspect),-2*s*aspect/p.height,2*c/p.height,p.feather,p.strength,p.inputBlack,p.inputWhite,p.inputGamma});
|
||||
}
|
||||
if(stamps.empty())return source;
|
||||
if(image.left!=bounds.left||image.right!=bounds.right||image.top!=bounds.top||image.bottom!=bounds.bottom){
|
||||
fail(error,@"仿制图章需要宿主提供完整的源画面。");return nil;
|
||||
}
|
||||
NSDictionary *entry=[self device:registry error:error];if(!entry)return nil;
|
||||
id<MTLDevice>device=entry[@"device"];
|
||||
id<MTLTexture>input=[source metalTextureForDevice:device];
|
||||
if(!input||input.framebufferOnly){fail(error,@"仿制图章无法读取源画面。");return nil;}
|
||||
MTLTextureDescriptor *desc=[MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatRGBA32Float width:input.width height:input.height mipmapped:NO];
|
||||
desc.storageMode=MTLStorageModePrivate;desc.usage=MTLTextureUsageShaderRead|MTLTextureUsageShaderWrite;
|
||||
id<MTLTexture>output=[[device newTextureWithDescriptor:desc]autorelease];
|
||||
id<MTLCommandBuffer>commands=[entry[@"queue"]commandBuffer];
|
||||
id<MTLComputeCommandEncoder>encoder=[commands computeCommandEncoder];
|
||||
if(!output||!encoder){fail(error,@"无法分配仿制图章缓冲区。");return nil;}
|
||||
uint32_t count=(uint32_t)stamps.size(),flip=source.imageOrigin==kFxImageOrigin_BOTTOM_LEFT;
|
||||
[encoder setComputePipelineState:entry[@"dyCloneStamps"]];
|
||||
[encoder setTexture:input atIndex:0];[encoder setTexture:output atIndex:1];
|
||||
[encoder setBytes:stamps.data() length:count*sizeof(DYCloneStamp) atIndex:0];
|
||||
[encoder setBytes:&count length:sizeof(count) atIndex:1];[encoder setBytes:&flip length:sizeof(flip) atIndex:2];
|
||||
[encoder dispatchThreads:MTLSizeMake(output.width,output.height,1) threadsPerThreadgroup:MTLSizeMake(16,16,1)];
|
||||
[encoder endEncoding];[commands commit];[commands waitUntilCompleted];
|
||||
if(commands.status!=MTLCommandBufferStatusCompleted){fail(error,commands.error.localizedDescription);return nil;}
|
||||
DYExportTile *tile=[[[DYExportTile alloc]initWithTexture:output registry:registry]autorelease];
|
||||
[tile setBounds:bounds origin:source.imageOrigin];[tile setPixelAspect:source.pixelAspect];[tile inheritColorSpace:source.colorSpace];
|
||||
return tile;
|
||||
}
|
||||
- (BOOL)renderSource:(FxImageTile*)src destination:(FxImageTile*)dst uniforms:(DYUniforms)u paths:(NSDictionary*)paths spider:(NSData*)spider tools:(NSDictionary*)tools colorManagement:(NSDictionary*)state hostPrimaries:(NSInteger)primaries error:(NSError**)error {@synchronized(self){return DYRenderWithPool(error,[&]()->BOOL{
|
||||
if(state&&![state isKindOfClass:NSDictionary.class])return fail(error,@"色彩管理状态无效。");
|
||||
NSDictionary*context=DYHostColorContext(src,dst,primaries);@synchronized(_previewLock){[_colorContext release];_colorContext=[context copy];}
|
||||
if(tools[@"sharedMasks"]){
|
||||
if(!DYValidToolDocument(tools))return fail(error,@"调色层或蒙版数据无效。");
|
||||
FxImageTile *stamped=[self sourceByApplyingStamps:DYSharedMasks(tools) source:src registry:dst.deviceRegistryID error:error];if(!stamped)return NO;
|
||||
return [self renderSource:stamped destination:dst uniforms:u paths:paths spider:spider tools:DYResolvedToolDocument(tools) colorManagement:state hostPrimaries:primaries error:error];
|
||||
}
|
||||
if(!state.count)return [self renderSource:src destination:dst uniforms:u paths:paths spider:spider tools:tools error:error];
|
||||
if(!DYManagedColorValid(state,error))return NO;if(!tools)tools=@{@"schema":@2,@"layers":@[],@"baseMasks":@{}};if(!DYValidToolDocument(tools))return fail(error,@"调色层或蒙版数据无效。");
|
||||
if(tools[@"sharedMasks"])tools=DYResolvedToolDocument(tools);
|
||||
|
||||
在新工单中引用
屏蔽一个用户