Skip to content

Commit

Permalink
Merge pull request #22 from tillt/till/fix-vimage-threading
Browse files Browse the repository at this point in the history
fix: fixing threading issue in vimage
  • Loading branch information
tillt authored Nov 22, 2023
2 parents c4c2e70 + 1142ff1 commit f4bcfe0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions KompleteSynthesia.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MACOSX_DEPLOYMENT_TARGET = 12.0;
MARKETING_VERSION = 0.60;
PRODUCT_BUNDLE_IDENTIFIER = tillt.KompleteSynthesia;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down Expand Up @@ -481,7 +481,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MACOSX_DEPLOYMENT_TARGET = 12.0;
MARKETING_VERSION = 0.60;
PRODUCT_BUNDLE_IDENTIFIER = tillt.KompleteSynthesia;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
17 changes: 13 additions & 4 deletions KompleteSynthesia/VideoController.m
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,17 @@ - (BOOL)startMirroring
atomic_fetch_or(&self->mirrorActive, 1);

while(self->stopMirroring == 0) {
CGImageRef original = CGWindowListCreateImage(CGRectNull, kCGWindowListOptionIncludingWindow, windowNumber, kCGWindowImageBoundsIgnoreFraming);
CGImageRef original = CGWindowListCreateImage(CGRectNull,
kCGWindowListOptionIncludingWindow,
windowNumber,
kCGWindowImageBoundsIgnoreFraming);
if (original == nil) {
NSLog(@"window disappeared, lets stop this");
goto doneMirroring;
}

[self drawCGImage:original screen:0 x:0 y:0 error:nil];

CGImageRelease(original);

// FIXME: We should try to find something more reliable than a fixed delay...
Expand Down Expand Up @@ -214,7 +219,7 @@ - (void)NIImageFromCGImage:(CGImageRef)source destination:(NIImage*)destination
_screenSize.width * 4
};

vImageScale_ARGB8888(&sourceBuffer, &resizedBuffer, nil, kvImageHighQualityResampling);
vImageScale_ARGB8888(&sourceBuffer, &resizedBuffer, nil, kvImageHighQualityResampling | kvImageDoNotTile);

sourceBuffer.data = resizeBuffer;
sourceBuffer.height = _screenSize.height;
Expand All @@ -230,10 +235,12 @@ - (void)NIImageFromCGImage:(CGImageRef)source destination:(NIImage*)destination
};

vImage_Error err = kvImageNoError;
// Do not attempt to invoke internal tiling with the image converter: `kvImageDoNotTile`
// should prevent https://github.com/tillt/KompleteSynthesia/issues/21.
vImageConverterRef converter = vImageConverter_CreateWithCGImageFormat(&sourceFormat,
&screenFormat,
NULL,
kvImageNoFlags,
kvImageDoNotTile,
&err);
vImage_Buffer destinationBuffer = {
destination->data,
Expand All @@ -242,11 +249,13 @@ - (void)NIImageFromCGImage:(CGImageRef)source destination:(NIImage*)destination
destination->width * 2
};

// Do not attempt to invoke internal tiling with the image converter: `kvImageDoNotTile`
// should prevent https://github.com/tillt/KompleteSynthesia/issues/21.
vImageConvert_AnyToAny(converter,
&sourceBuffer,
&destinationBuffer,
tempBuffer,
kvImageNoFlags);
kvImageDoNotTile);

vImageConverter_Release(converter);

Expand Down

0 comments on commit f4bcfe0

Please sign in to comment.