Hey Ken,
Thanks for the response,
I have tried all of your suggestions but i am still having no luck 😟
I have added some information that i forgot to add before and may be relevant, so perhaps you can provide some more insight into my issue.
I tried the first method you suggested ie.
[pImage drawAtPoint:NSMakePoint(10, 10) fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1];
but no luck, i got the same result as before.
Ok so i have tried the second thing you suggested by checking the result of the -lockFocusIfCanDraw call and then trying the above...
So -lockFocusIfCanDraw returns true, however when i tried the code with this ie.
if (pImage)
{
if ([pView lockFocusIfCanDraw])
{
printf("DrawIntoView lockFocusIfCanDraw returned True, gonna try draw At point. \n");
[pImage drawAtPoint:NSMakePoint(10, 10) fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1];
[pView unlockFocus];
}
}
I Still dont get any image displayed.
Perhaps i misunderstand here, but i cannot see how there is any connection between the NSview i am given from the host and what i am trying to display?
surely i need to tell the NSview about what i am trying to draw?**
I have also tried drawing directly via getting the current context and using CGContextDrawImage to draw the image, but no luck 😟
(this actually causes a crash in the host application) eg.
CGImageRef iref = CGImageCreate(width,
height,
bitsPerComponent,
bitsPerPixel,
bytesPerRow,
colorSpaceRef,
bitmapInfo,
provider, /
NULL, /
YES, /
renderingIntent);
if ([pView lockFocusIfCanDraw])
{
if (iref)
{
CGContextRef cgcontext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
CGContextDrawImage(cgcontext, CGRectMake(10, 10, 100, 100), iref);
CGImageRelease(iref);
}
[pView unlockFocus];
}
NEW INFO....
Perhaps I should have mentioned this before but the plugin is updating a preview of an incoming video stream,
and is operating on a different Thread to the host application! AND may have a fully independent update/drawing schedule.
I would expect this to be updated on a fps basis, ie anywhere from 23-60 times a second.
So the host application is not actually "calling" any specific function in my plugin, instead it is making a call that starts it's own thread
and that thread has a pointer to the NSview which describes the area i want to draw into.
Sorry It's only now, after some more googling that I realise the part about different thread is significant.
Currently my code stands as such:
NSImage* pImage = [[NSImage alloc] initWithCGImage:iref size:NSMakeSize(width, height)];
if (pView.isHidden)
{
[pView setHidden:FALSE];
}
[pView setCanDrawConcurrently:TRUE];
if (pImage)
{
if ([pView lockFocusIfCanDraw])
{
printf("DrawIntoView lockFocusIfCanDraw returned True, gonna try draw At point. \n");
[pImage drawAtPoint:NSMakePoint(10, 10) fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1];
[pView unlockFocus];
}
else
printf("DrawIntoView lockFocusIfCanDraw returned FALSE!!!!!. \n");
}
Which i beleive is the best/closest thing to a working solution that i have,
but of course it doesn't actually you know, work.....
When checking the canDrawConcurrently property, i found it was initially set to 0, / false.
I'm not sure if setting it to true in my plugin is going to work? does this need to be set via the main thread?
Anyway, thank you for your initial resposnse, and I look forward to any more responses,
I will continue trying to get my head around this and hopefully find a solution,
(Any info regarding the starred ** section above would be v useful too)
Cheers,