Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hardware info #97

Merged
merged 2 commits into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions samples/SkijaInjectSample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ val additionalArguments = mutableMapOf<String, String>()

val casualRun = tasks.named<JavaExec>("run") {
systemProperty("skiko.fps.enabled", "true")
systemProperty("skiko.hardwareInfo.enabled", "true")
// Use systemProperty("skiko.library.path", "/tmp") to test loader.
System.getProperties().entries
.associate {
Expand Down
6 changes: 6 additions & 0 deletions skiko/src/jvmMain/cpp/common/openglapi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,10 @@ JNIEXPORT jint JNICALL Java_org_jetbrains_skiko_OpenGLApi_glGetIntegerv(JNIEnv *
return (jint)data;
}

JNIEXPORT jstring JNICALL Java_org_jetbrains_skiko_OpenGLApi_glGetString(JNIEnv * env, jobject object, jint value) {
const char *content = reinterpret_cast<const char *>(glGetString(value));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alignment.

jstring result = env->NewStringUTF(content);
return result;
}

}
21 changes: 21 additions & 0 deletions skiko/src/jvmMain/cpp/windows/directXRedrawer.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#ifdef SK_DIRECT3D
#include <stdexcept>
#include <locale>
#include <Windows.h>
#include <jawt_md.h>
#include "jni_helpers.h"
Expand Down Expand Up @@ -387,6 +388,26 @@ HRESULT D3DCompile(
DirectXDevice *d3dDevice = fromJavaPointer<DirectXDevice*>(devicePtr);
delete d3dDevice;
}

JNIEXPORT jstring JNICALL Java_org_jetbrains_skiko_redrawer_Direct3DRedrawer_getAdapterName(JNIEnv * env, jobject redrawer, jlong devicePtr) {
DirectXDevice *d3dDevice = fromJavaPointer<DirectXDevice*>(devicePtr);

DXGI_ADAPTER_DESC1 desc;
d3dDevice->backendContext.fAdapter->GetDesc1(&desc);
std::wstring w_tmp(desc.Description);
std::string currentAdapterName(w_tmp.begin(), w_tmp.end());
jstring result = env->NewStringUTF(currentAdapterName.c_str());
return result;
}

JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_redrawer_Direct3DRedrawer_getAdapterMemorySize(JNIEnv * env, jobject redrawer, jlong devicePtr) {
DirectXDevice *d3dDevice = fromJavaPointer<DirectXDevice*>(devicePtr);

DXGI_ADAPTER_DESC1 desc;
d3dDevice->backendContext.fAdapter->GetDesc1(&desc);
__int64 result = desc.DedicatedVideoMemory;
return (jlong)result;
}
}

#endif
4 changes: 4 additions & 0 deletions skiko/src/jvmMain/kotlin/org/jetbrains/skiko/OpenGLApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ class OpenGLApi private constructor() {
val GL_TEXTURE_BINDING_2D = 0x8069
val GL_DRAW_FRAMEBUFFER_BINDING = 0x8CA6
val GL_COLOR_BUFFER_BIT = 0x00004000
val GL_VENDOR = 0x1F00
val GL_RENDERER = 0x1F01
val GL_TOTAL_MEMORY = 0x9048

// OpenGL functions
external fun glViewport(x: Int, y: Int, width: Int, height: Int)
Expand All @@ -20,6 +23,7 @@ class OpenGLApi private constructor() {
external fun glEnable(flag: Int)
external fun glBindTexture(target: Int, texture: Int)
external fun glGetIntegerv(pname: Int): Int
external fun glGetString(value: Int): String

companion object {
init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,7 @@ internal abstract class ContextHandler(val layer: SkiaLayer) {
renderTarget?.close()
}

open fun hardwareInfo(): String = ""

protected open fun destroyContext() = Unit
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ internal class Direct3DContextHandler(layer: SkiaLayer) : ContextHandler(layer)
throw Exception("Failed to create DirectX12 device.")
}
context = directXRedrawer.makeContext(device)
val printDeviceEnabled = System.getProperty("skiko.hardwareInfo.enabled") == "true"
if (System.getProperty("skiko.hardwareInfo.enabled") == "true") {
println(hardwareInfo())
}
}
} catch (e: Exception) {
println("${e.message}\nFailed to create Skia Direct3D context!")
Expand Down Expand Up @@ -68,4 +72,10 @@ internal class Direct3DContextHandler(layer: SkiaLayer) : ContextHandler(layer)
context?.close()
directXRedrawer.disposeDevice(device)
}

override fun hardwareInfo(): String {
return "DIRECT3D (dx12) hardware info:\n" +
"Video card: ${directXRedrawer.getAdapterName(device)}\n" +
"Total memory: ${directXRedrawer.getAdapterMemorySize(device) / 1024 / 1024} MB\n"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ internal class MetalContextHandler(layer: SkiaLayer) : ContextHandler(layer) {
try {
if (context == null) {
context = metalRedrawer.makeContext()
if (System.getProperty("skiko.hardwareInfo.enabled") == "true") {
println(hardwareInfo())
}
}
} catch (e: Exception) {
println("${e.message}\nFailed to create Skia Metal context!")
Expand Down Expand Up @@ -53,4 +56,10 @@ internal class MetalContextHandler(layer: SkiaLayer) : ContextHandler(layer) {
override fun destroyContext() {
context?.close()
}

override fun hardwareInfo(): String {
return "METAL hardware info:\n" +
"Video card: ${metalRedrawer.getAdapterName()}\n" +
"Total memory: ${metalRedrawer.getAdapterMemorySize() / 1024 / 1024} MB\n"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ internal class OpenGLContextHandler(layer: SkiaLayer) : ContextHandler(layer) {
try {
if (context == null) {
context = makeGLContext()
if (System.getProperty("skiko.hardwareInfo.enabled") == "true") {
println(hardwareInfo())
}
}
} catch (e: Exception) {
println("Failed to create Skia OpenGL context!")
Expand Down Expand Up @@ -51,4 +54,12 @@ internal class OpenGLContextHandler(layer: SkiaLayer) : ContextHandler(layer) {

canvas = surface!!.canvas
}

override fun hardwareInfo(): String {
val gl = OpenGLApi.instance
return "OPENGL hardware info:\n" +
"Vendor: ${gl.glGetString(gl.GL_VENDOR)}\n" +
"Model: ${gl.glGetString(gl.GL_RENDERER)}\n" +
"Total memory: ${gl.glGetIntegerv(gl.GL_TOTAL_MEMORY) / 1024} MB\n"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,6 @@ internal class Direct3DRedrawer(
external fun resizeBuffers(device: Long, width: Int, height: Int)
private external fun finishFrame(device: Long, context: Long, surface: Long, isVsyncEnabled: Boolean)
external fun disposeDevice(device: Long)
external fun getAdapterName(device: Long): String
external fun getAdapterMemorySize(device: Long): Long
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ internal class MetalRedrawer(

fun finishFrame() = finishFrame(device)

fun getAdapterName(): String = getAdapterName(device)
fun getAdapterMemorySize(): Long = getAdapterMemorySize(device)

private external fun createMetalDevice(platformInfo: Long): Long
private external fun makeMetalContext(device: Long): Long
private external fun makeMetalRenderTarget(device: Long, width: Int, height: Int): Long
Expand All @@ -106,4 +109,6 @@ internal class MetalRedrawer(
private external fun resizeLayers(device: Long, x: Int, y: Int, width: Int, height: Int)
private external fun setContentScale(device: Long, contentScale: Float)
private external fun isOccluded(window: Long): Boolean
private external fun getAdapterName(device: Long): String
private external fun getAdapterMemorySize(device: Long): Long
}
17 changes: 17 additions & 0 deletions skiko/src/jvmMain/objectiveC/macos/MetalRedrawer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,23 @@ JNIEXPORT void JNICALL Java_org_jetbrains_skiko_redrawer_MetalRedrawer_disposeDe
[device release];
}

JNIEXPORT jstring JNICALL Java_org_jetbrains_skiko_redrawer_MetalRedrawer_getAdapterName(
JNIEnv *env, jobject redrawer, jlong devicePtr)
{
MetalDevice *device = (MetalDevice *) devicePtr;
const char *currentAdapterName = [[device.device name] cStringUsingEncoding:NSASCIIStringEncoding];
jstring result = env->NewStringUTF(currentAdapterName);
return result;
}

JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_redrawer_MetalRedrawer_getAdapterMemorySize(
JNIEnv *env, jobject redrawer, jlong devicePtr)
{
MetalDevice *device = (MetalDevice *) devicePtr;
uint64_t totalMemory = [device.device recommendedMaxWorkingSetSize];
return (jlong)totalMemory;
}

JNIEXPORT jboolean JNICALL Java_org_jetbrains_skiko_redrawer_MetalRedrawer_isOccluded(
JNIEnv *env, jobject redrawer, jlong windowPtr) {
NSWindow* window = (NSWindow*)windowPtr;
Expand Down