forked from HumbleUI/JWM
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
329 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#include <jni.h> | ||
#include "Library.hh" | ||
#include "impl/Library.hh" | ||
#include "Window.hh" | ||
#include "MainView.hh" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
#import <Cocoa/Cocoa.h> | ||
#import <Metal/Metal.h> | ||
#import <QuartzCore/CAMetalLayer.h> | ||
|
||
namespace jwm { | ||
class MetalContext { | ||
public: | ||
MetalContext(bool vsync): fVsync(vsync) {} | ||
~MetalContext(); | ||
|
||
void attach(NSView* mainView); | ||
void swapBuffers(); | ||
void resize(); | ||
|
||
int fWidth = 0; | ||
int fHeight = 0; | ||
int fSampleCount = 1; | ||
int fStencilBits = 8; | ||
bool fVsync = true; | ||
bool fValid = false; | ||
id<MTLDevice> fDevice; | ||
id<MTLCommandQueue> fQueue; | ||
CAMetalLayer* fMetalLayer; | ||
NSView* fMainView; | ||
id<CAMetalDrawable> fDrawableHandle; | ||
// id<MTLBinaryArchive> fPipelineArchive API_AVAILABLE(macos(11.0), ios(14.0)); | ||
}; | ||
|
||
void deleteMetalContext(MetalContext* instance); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#include <jni.h> | ||
#include "MetalContext.hh" | ||
#import <QuartzCore/CAConstraintLayoutManager.h> | ||
|
||
jwm::MetalContext::~MetalContext() { | ||
// MetalWindowContext_mac | ||
fMainView.layer = nil; | ||
fMainView.wantsLayer = NO; | ||
|
||
// MetalWindowContext | ||
fMetalLayer = nil; | ||
fValid = false; | ||
|
||
CFRelease(fQueue); | ||
CFRelease(fDevice); | ||
} | ||
|
||
void jwm::MetalContext::attach(NSView* mainView) { | ||
fMainView = mainView; | ||
|
||
// MetalWindowContext | ||
fDevice = MTLCreateSystemDefaultDevice(); | ||
fQueue = [fDevice newCommandQueue]; | ||
|
||
// MetalWindowContext_mac | ||
fMetalLayer = [CAMetalLayer layer]; | ||
fMetalLayer.device = fDevice; | ||
fMetalLayer.pixelFormat = MTLPixelFormatBGRA8Unorm; | ||
|
||
this->resize(); | ||
|
||
fMetalLayer.displaySyncEnabled = fVsync ? YES : NO; // TODO: need solution for 10.12 or lower | ||
fMetalLayer.layoutManager = [CAConstraintLayoutManager layoutManager]; | ||
fMetalLayer.autoresizingMask = kCALayerHeightSizable | kCALayerWidthSizable; | ||
fMetalLayer.contentsGravity = kCAGravityTopLeft; | ||
fMetalLayer.magnificationFilter = kCAFilterNearest; | ||
NSColorSpace* cs = fMainView.window.colorSpace; | ||
fMetalLayer.colorspace = cs.CGColorSpace; | ||
|
||
fMainView.layer = fMetalLayer; | ||
fMainView.wantsLayer = YES; | ||
|
||
fValid = true; | ||
} | ||
|
||
void jwm::MetalContext::resize() { | ||
// CGFloat backingScaleFactor = sk_app::GetBackingScaleFactor(fMainView); | ||
NSScreen* screen = fMainView.window.screen ?: [NSScreen mainScreen]; | ||
CGFloat backingScaleFactor = screen.backingScaleFactor; | ||
|
||
CGSize backingSize = fMainView.bounds.size; | ||
backingSize.width *= backingScaleFactor; | ||
backingSize.height *= backingScaleFactor; | ||
|
||
fMetalLayer.drawableSize = backingSize; | ||
fMetalLayer.contentsScale = backingScaleFactor; | ||
|
||
fWidth = backingSize.width; | ||
fHeight = backingSize.height; | ||
} | ||
|
||
// void jwm::MetalContext::swapBuffers() { | ||
// id<CAMetalDrawable> currentDrawable = (id<CAMetalDrawable>)fDrawableHandle; | ||
|
||
// id<MTLCommandBuffer> commandBuffer([*fQueue commandBuffer]); | ||
// commandBuffer.label = @"Present"; | ||
|
||
// [commandBuffer presentDrawable:currentDrawable]; | ||
// [commandBuffer commit]; | ||
// // ARC is off in sk_app, so we need to release the CF ref manually | ||
// CFRelease(fDrawableHandle); | ||
// fDrawableHandle = nil; | ||
// } | ||
|
||
// JNI | ||
|
||
void jwm::deleteMetalContext(jwm::MetalContext* instance) { | ||
delete instance; | ||
} | ||
|
||
extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_jwm_MetalContext__1nGetFinalizer | ||
(JNIEnv* env, jclass jclass) { | ||
return static_cast<jlong>(reinterpret_cast<uintptr_t>(&jwm::deleteMetalContext)); | ||
} | ||
|
||
extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_jwm_MetalContext__1nMake | ||
(JNIEnv* env, jclass jclass, jboolean vsync) { | ||
jwm::MetalContext* instance = new jwm::MetalContext(vsync); | ||
return reinterpret_cast<jlong>(instance); | ||
} | ||
|
||
extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_jwm_MetalContext__1nClose | ||
(JNIEnv* env, jclass jclass, jboolean vsync) { | ||
jwm::MetalContext* instance = new jwm::MetalContext(vsync); | ||
delete instance; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include <jni.h> | ||
|
||
typedef void (*FreeFunction)(void*); | ||
|
||
extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_jwm_impl_Managed__1nInvokeFinalizer | ||
(JNIEnv* env, jclass jclass, jlong finalizerPtr, jlong ptr) { | ||
void* instance = reinterpret_cast<void*>(static_cast<uintptr_t>(ptr)); | ||
FreeFunction finalizer = reinterpret_cast<FreeFunction>(static_cast<uintptr_t>(finalizerPtr)); | ||
finalizer(instance); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.jetbrains.jwm; | ||
|
||
import java.util.function.*; | ||
import lombok.*; | ||
import org.jetbrains.annotations.*; | ||
import org.jetbrains.jwm.impl.*; | ||
|
||
public class MetalContext extends Managed { | ||
static { Library.staticLoad(); } | ||
|
||
@ApiStatus.Internal | ||
public static class _FinalizerHolder { | ||
public static final long PTR = _nGetFinalizer(); | ||
} | ||
|
||
public MetalContext(boolean vsync) { | ||
super(_nMake(vsync), _FinalizerHolder.PTR); | ||
} | ||
|
||
@ApiStatus.Internal public static native long _nGetFinalizer(); | ||
@ApiStatus.Internal public static native long _nMake(boolean vsync); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package org.jetbrains.jwm; | ||
package org.jetbrains.impl.jwm; | ||
|
||
import java.io.*; | ||
import java.net.*; | ||
|
Oops, something went wrong.