// Shared author identity and disposable render bindings must stay separate. { NSMutableDictionary *doc=DYMutablePlist([[[DYToolDocument alloc]init]autorelease].document); NSMutableDictionary *shared=(id)DYAddSharedMask(doc,DYMaskRectangle);NSString *maskID=shared[@"id"]; run.need(@"shared-mask-can-be-authored-before-any-module-assignment",shared&&DYValidToolDocument(doc)&&DYSharedMasks(doc).count==1&&DYMasksForTool(doc,@"shared").firstObject==shared&&DYMasksForTool(doc,@"base:hsl").count==0); NSDictionary *layer=DYInsertTool(doc,@"curve",@"base:curve");NSString *layerID=layer[@"id"]; BOOL assigned=DYSetSharedMaskAssigned(doc,maskID,@"base:hsl",YES)&&DYSetSharedMaskAssigned(doc,maskID,layerID,YES); run.record(@"shared-mask-two-module-bindings-retain-one-author-object",assigned&&DYValidToolDocument(doc)&&DYSharedMasks(doc).count==1&&DYMasksForTool(doc,@"base:hsl").firstObject==DYMasksForTool(doc,layerID).firstObject&&DYToolIDsForSharedMask(doc,maskID).count==2&&[doc[@"baseMasks"][@"hsl"][0][@"sharedID"]isEqual:maskID]&&[doc[@"schema"]isEqual:@3]); DYMaskParameters p=DYMaskAtTime(shared,kCMTimeZero);p.centerX=.31;shared[@"parameters"]=[NSData dataWithBytes:&p length:sizeof(p)];DYMaskParameters q=DYMaskAtTime(DYMasksForTool(doc,layerID).firstObject,kCMTimeZero); run.record(@"editing-one-shared-mask-updates-all-linked-modules",fabs(q.centerX-.31)<1e-6&&DYSharedMasks(doc).count==1); DYMaskParameters moved=p;moved.centerX=.71;DYMergeTracking(shared,@[DYMaskKey(kCMTimeZero,p,YES,1),DYMaskKey(CMTimeMake(2,24),moved,NO,.9)]); q=DYMaskAtTime(DYMasksForTool(doc,layerID).firstObject,CMTimeMake(1,24)); run.record(@"shared-tracking-is-single-timeline-for-every-module",fabs(q.centerX-.51)<1e-6&&[DYMasksForTool(doc,@"base:hsl").firstObject[@"keys"]count]==2); DYToolDocument *author=[[[DYToolDocument alloc]init]autorelease];author.document=doc;NSData *encoded=[NSKeyedArchiver archivedDataWithRootObject:author requiringSecureCoding:YES error:&error];DYToolDocument *decoded=[NSKeyedUnarchiver unarchivedObjectOfClass:DYToolDocument.class fromData:encoded error:&error]; run.record(@"shared-mask-archive-roundtrip-keeps-unique-object-and-links",[decoded isEqual:author]&&DYSharedMasks(decoded.document).count==1&&DYToolIDsForSharedMask(decoded.document,maskID).count==2); NSDictionary *snapshot=DYToolRenderSnapshot(doc,CMTimeMake(1,24)),*again=DYToolRenderSnapshot(doc,CMTimeMake(1,24));NSDictionary *base=DYMasksForTool(snapshot,@"base:hsl").firstObject,*extra=DYMasksForTool(snapshot,layerID).firstObject; run.record(@"shared-render-snapshot-freezes-all-bindings-with-stable-private-identities",DYValidToolDocument(snapshot)&&[snapshot isEqual:again]&&![base[@"id"]isEqual:extra[@"id"]]&&[base[@"sourceSharedID"]isEqual:maskID]&&[extra[@"sourceSharedID"]isEqual:maskID]&&[base[@"keys"]count]==0&&[extra[@"keys"]count]==0&&fabs(DYMaskAtTime(base,kCMTimeZero).centerX-.51)<1e-6&&[shared[@"keys"]count]==2); NSMutableDictionary *bad=DYMutablePlist(doc);bad[@"baseMasks"][@"hsl"]=[NSMutableArray arrayWithObjects:@{@"sharedID":maskID},@{@"sharedID":maskID},nil];run.record(@"shared-mask-rejects-duplicate-binding-in-one-module",!DYValidToolDocument(bad)); bad=DYMutablePlist(doc);bad[@"baseMasks"][@"hsl"]=[NSMutableArray arrayWithObject:@{@"sharedID":NSUUID.UUID.UUIDString}];run.record(@"shared-mask-rejects-dangling-reference",!DYValidToolDocument(bad)); bad=DYMutablePlist(doc);bad[@"baseMasks"][@"hsl"]=[NSMutableArray arrayWithObject:DYMutablePlist(shared)];run.record(@"shared-mask-rejects-copied-author-object-with-same-identity",!DYValidToolDocument(bad)); bad=DYMutablePlist(doc);bad[@"schema"]=@2;run.record(@"legacy-document-cannot-silently-contain-shared-references",!DYValidToolDocument(bad)); BOOL detached=DYSetSharedMaskAssigned(doc,maskID,@"base:hsl",NO);run.record(@"unlinking-one-module-keeps-shared-mask-and-other-module",detached&&DYMasksForTool(doc,@"base:hsl").count==0&&DYMasksForTool(doc,layerID).count==1&&DYSharedMasks(doc).count==1&&DYValidToolDocument(doc)); BOOL removed=DYRemoveSharedMask(doc,maskID);run.record(@"deleting-shared-mask-removes-all-references-without-deleting-modules",removed&&DYSharedMasks(doc).count==0&&DYMasksForTool(doc,layerID).count==0&&DYToolWithID(doc,layerID)&&DYValidToolDocument(doc)); NSMutableDictionary *legacy=DYMutablePlist([[[DYToolDocument alloc]init]autorelease].document);NSDictionary *old=DYNewMask(DYMaskEllipse);legacy[@"baseMasks"][@"curve"]=[NSMutableArray arrayWithObject:old];NSDictionary *promoted=DYShareToolMask(legacy,@"base:curve",old[@"id"]); run.record(@"sharing-legacy-mask-moves-one-object-without-changing-geometry-or-identity",promoted&&[promoted isEqual:old]&&DYSharedMasks(legacy).count==1&&DYMasksForTool(legacy,@"base:curve").firstObject==promoted&&DYValidToolDocument(legacy)); BOOL removedBase=DYSetBaseToolRemoved(legacy,@"curve",YES);run.record(@"removing-base-module-detaches-reference-and-preserves-shared-object",removedBase&&DYValidToolDocument(legacy)&&DYSharedMasks(legacy).count==1&&DYToolIDsForSharedMask(legacy,old[@"id"]).count==0); NSMutableDictionary *limits=DYMutablePlist([[[DYToolDocument alloc]init]autorelease].document);BOOL sixteen=YES;for(int i=0;i *editor=DYCreateWorkspaceMaskEditor(manager,@"shared");[editor refreshWithDocument:state time:kCMTimeZero];[editor selectMaskID:mask[@"id"]]; for(NSNumber *width in @[@377,@600,@860,@1200]){[editor setFrameSize:NSMakeSize(width.doubleValue,235)];[editor setFrameSize:NSMakeSize(MAX(width.doubleValue,editor.contentWidth),editor.contentHeight)];[editor layoutSubtreeIfNeeded];for(NSView *view in editor.subviews)if(!view.hidden)compactFits&=NSContainsRect(editor.bounds,view.frame)&&view.frame.size.width>0&&view.frame.size.height>0;for(NSDictionary *row in [editor valueForKey:@"_rows"]){NSView *label=row[@"label"],*field=row[@"field"],*slider=row[@"slider"];if(label.hidden)continue;compactRows&=!NSIntersectsRect(label.frame,field.frame)&&!NSIntersectsRect(label.frame,slider.frame)&&!NSIntersectsRect(field.frame,slider.frame)&&field.frame.size.width>=64&&slider.frame.size.width>=140;}} } run.record(@"workspace-six-mask-editors-flow-horizontally-at-235-point-height",compactFits&&compactRows); } // Exercise the actual IOSurface/Metal path against independently owned masks. // This reference never uses the shared-reference expander to construct masks. { [[source metalTextureForDevice:gpu]replaceRegion:MTLRegionMake2D(0,0,width,height) mipmapLevel:0 withBytes:input.data() bytesPerRow:width*8]; DYUniforms active=defaults;active.skinProtection.x=0;active.hslSectionEnabled=1;active.spiderSectionEnabled=1;active.spiderMix=1; active.hslHueA=active.hslHueB=(DYFloat4){24,24,24,24};active.hslSatA=active.hslSatB=(DYFloat4){25,25,25,25}; auto mesh=dy::neutralMesh(6,6);std::bitsetselected;for(int i=0;i10&&difference(first,spiderFrame).different>10); geometry.centerX=.72;sharedMask[@"parameters"]=[NSData dataWithBytes:&geometry length:sizeof(geometry)];Pixels edited=renderAt(sharedDocument,kCMTimeZero,active,@"gpu-shared-edited-rectangle-render"),editedReference=renderAt(independentDocument(),kCMTimeZero,active,@"gpu-independent-edited-rectangle-reference");Difference editedError=difference(edited,editedReference),editedChange=difference(first,edited); run.record(@"gpu-editing-unique-shared-geometry-updates-both-operations",editedError.nonfinite==0&&editedError.maximum<.0001&&editedChange.different>20&&alphaPreserved(edited),@{@"maximumReferenceError":@(editedError.maximum),@"changedComponents":@(editedChange.different),@"uniqueAuthorObjects":@(DYSharedMasks(sharedDocument).count)}); DYMaskParameters tracked=geometry;tracked.centerX=.28;BOOL merged=DYMergeTracking(sharedMask,@[DYMaskKey(kCMTimeZero,geometry,YES,1),DYMaskKey(CMTimeMake(2,24),tracked,NO,.93)]);CMTime middle=CMTimeMake(1,24);Pixels animated=renderAt(sharedDocument,middle,active,@"gpu-shared-tracking-middle-render"),animatedReference=renderAt(independentDocument(),middle,active,@"gpu-independent-tracking-middle-reference");Difference trackingError=difference(animated,animatedReference),trackingChange=difference(edited,animated); run.record(@"gpu-one-shared-trajectory-drives-hsl-and-spider-per-frame",merged&&trackingError.nonfinite==0&&trackingError.maximum<.0001&&trackingChange.different>20&&alphaPreserved(animated)&&DYSharedMasks(sharedDocument).count==1&&[DYMasksForTool(sharedDocument,@"base:hsl").firstObject[@"keys"]count]==2&&DYMasksForTool(sharedDocument,@"base:hsl").firstObject==DYMasksForTool(sharedDocument,@"base:spider").firstObject,@{@"maximumReferenceError":@(trackingError.maximum),@"changedComponents":@(trackingChange.different),@"evaluatedCenterX":@(DYMaskAtTime(sharedMask,middle).centerX)}); // Use the real preset serializer, then the same JSON/base64-plist path that // loadPreset validates, with a separate manager so other fixtures stay intact. DYDiagnosticManager *presetHost=[[[DYDiagnosticManager alloc]init]autorelease];DYCreateParameters(presetHost,&error);DYWriteTools(presetHost,sharedDocument,kCMTimeZero);DYAssetState *presetAssets=[[[DYAssetState alloc]init]autorelease];presetAssets.spiderMesh=meshData;presetAssets.spiderLinked=YES;DYWriteAssets(presetHost,presetAssets,kCMTimeZero);DYInspector *presetInspector=[[[DYInspector alloc]initWithAPIManager:presetHost renderer:renderer]autorelease];NSDictionary *preset=[presetInspector performSelector:@selector(presetSnapshot)];NSData *json=[NSJSONSerialization dataWithJSONObject:preset options:0 error:&error];NSDictionary *loaded=json?[NSJSONSerialization JSONObjectWithData:json options:0 error:&error]:nil;NSData *toolBytes=[loaded[@"tools"]isKindOfClass:NSString.class]?[[[NSData alloc]initWithBase64EncodedString:loaded[@"tools"] options:0]autorelease]:nil;NSDictionary *restored=toolBytes?[NSPropertyListSerialization propertyListWithData:toolBytes options:NSPropertyListImmutable format:NULL error:&error]:nil; run.record(@"preset-v7-json-roundtrip-preserves-unique-shared-object-and-trajectory",[loaded[@"version"]isEqual:@7]&&[loaded[@"format"]isEqual:@"com.dayu.color.preset"]&&DYValidToolDocument(restored)&&[restored isEqual:sharedDocument]&&DYSharedMasks(restored).count==1&&DYToolIDsForSharedMask(restored,sharedID).count==2&&[DYSpiderFromJSON(loaded[@"spider"])isEqual:meshData]); }