Hi,

Thank you for the reply. We use Java jni to call cocoa api.
Here is the pseudo code when we drag the display to another display(non
retina)
1.     Get imageRep(non retina) from existing NSImage object
2.     In our code we have only one image rep at any point of time, we will
not have non-retina imageRep. So create using drawinrect api
3.     Create context using
NSGraphicsContext.graphicsContextWithBitmapImageRep(imageRep)

From your response the I feel the problem could be in the way ImageRep is
created for non retina display. I will investigate further and see if there
are any problems in the ImageRep creation code.

If some one wants to review the code for creating ImageRep its here
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/bundles/org.eclipse.swt/Eclipse%20SWT/cocoa/org/eclipse/swt/internal/graphics/ImageUtil.java#n38

Thank you
Sravan

On Wed, Mar 4, 2020 at 10:30 PM Richard Charles <rcharles...@gmail.com>
wrote:

> I have a very similar setup. I tried the following.
>
> NSBundle *bundle = [NSBundle mainBundle];
> NSData *data = [NSData dataWithContentsOfFile:[bundle 
> pathForResource:@"AAScreenShot"
> ofType:@"jpg"]];
> NSBitmapImageRep *imageRep = [NSBitmapImageRep imageRepWithData:data];
> NSGraphicsContext *context = [NSGraphicsContext
> graphicsContextWithBitmapImageRep:imageRep];
> printf("Graphics Context %p\n", context);
>
> Execute the above code and I get a graphics context when the window is in
> the high resolution display. Move the window to the secondary normal
> resolution display, execute the code, and I get another graphics context.
> You must be doing something wrong.
>
> Normally a graphics context is valid for a given display. When the window
> moves from one display to another your app needs to detect this a pull
> another context.
>
>
> https://developer.apple.com/library/archive/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_contexts/opengl_contexts.html
>
> "A renderer change can occur when the user drags a window from one display
> to another or when a display is attached or removed.”
>
> This might not be true with an offscreen context which might remain valid
> regardless of the display.
>
> --Richard Charles
>
>
> > On Mar 3, 2020, at 11:19 PM, Sravan Kumar Lakkimsetti via Cocoa-dev <
> cocoa-dev@lists.apple.com> wrote:
> >
> > Hi,
> >
> > In our product we use
> >
> https://developer.apple.com/documentation/appkit/nsgraphicscontext/1529827-graphicscontextwithbitmapimagere?language=objc
> > to create Graphics Context for drawing on top of image.
> >
> > This particular API returns null in some cases. One particular case is
> > troubling us. Would like to know why this happens and how to resolve.
> >
> > Here is the problem.
> > There are two monitors attached to Mac. Main display is retina display
> and
> > secondary display is non-retina display. The application is moved from
> main
> > display(retina display) to secondary display(non-retina display). In this
> > case our application redraws the GUI(to use higher resolution images) In
> > this process we are creating graphics context using the above api. This
> api
> > returns null if the main display is retina and secondary display is
> > non-retina.
> >
> > It would be helpful if anyone can suggest on how to identify why this api
> > returns null
> >
> > Thanks
> > Sravan
> >
>
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to