Skip to content

Commit

Permalink
MacOS retina support
Browse files Browse the repository at this point in the history
  • Loading branch information
khogeland committed Mar 14, 2024
1 parent 2430809 commit bffe2f2
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions rlawt_mac.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <jawt_md.h>
#include <OpenGL/gl3.h>
#include <QuartzCore/QuartzCore.h>
#include <AppKit/AppKit.h>

@protocol CanSetContentsChanged
-(void)setContentsChanged;
Expand Down Expand Up @@ -110,8 +111,9 @@ static void propsPutInt(CFMutableDictionaryRef props, const CFStringRef key, int
static bool rlawtCreateIOSurface(JNIEnv *env, AWTContext *ctx) {
CFMutableDictionaryRef props = CFDictionaryCreateMutable(NULL, 4, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CGSize size = ctx->layer.frame.size;
propsPutInt(props, kIOSurfaceHeight, size.height);
propsPutInt(props, kIOSurfaceWidth, size.width);
CGFloat scale = [[NSScreen mainScreen] backingScaleFactor];
propsPutInt(props, kIOSurfaceHeight, size.height*scale);
propsPutInt(props, kIOSurfaceWidth, size.width*scale);
propsPutInt(props, kIOSurfaceBytesPerElement, 4);
propsPutInt(props, kIOSurfacePixelFormat, (int)'BGRA');

Expand All @@ -128,7 +130,7 @@ static bool rlawtCreateIOSurface(JNIEnv *env, AWTContext *ctx) {
CGLError err = CGLTexImageIOSurface2D(
ctx->context,
target, GL_RGBA,
size.width, size.height,
size.width*scale, size.height*scale,
GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV,
buf,
0);
Expand Down Expand Up @@ -217,7 +219,8 @@ JNIEXPORT void JNICALL Java_net_runelite_rlawt_AWTContext_createGLContext(JNIEnv
layer.needsDisplayOnBoundsChange = false;
layer.magnificationFilter = kCAFilterNearest;
layer.contentsGravity = kCAGravityCenter;
layer.affineTransform = CGAffineTransformMakeScale(1, -1);
CGFloat scale = 1.0/[[NSScreen mainScreen] backingScaleFactor];
layer.affineTransform = CGAffineTransformMakeScale(scale, -scale);

ctx->layer = layer;
dspi.layer = layer;
Expand Down

0 comments on commit bffe2f2

Please sign in to comment.