in skiko/src/awtMain/cpp/windows/directXRedrawer.cc [304:361]
JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_redrawer_Direct3DRedrawer_createDirectXDevice(
JNIEnv *env, jobject redrawer, jlong adapterPtr, jlong contentHandle, jboolean transparency) {
gr_cp<IDXGIFactory4> deviceFactory;
if (!SUCCEEDED(CreateDXGIFactory1(IID_PPV_ARGS(&deviceFactory)))) {
return 0;
}
if (adapterPtr == 0) {
return 0;
}
gr_cp<IDXGIAdapter1> adapter((IDXGIAdapter1 *) adapterPtr);
D3D_FEATURE_LEVEL maxSupportedFeatureLevel = D3D_FEATURE_LEVEL_12_0;
D3D_FEATURE_LEVEL featureLevels[] = {
// TODO add D3D_FEATURE_LEVEL_12_2
D3D_FEATURE_LEVEL_12_1,
D3D_FEATURE_LEVEL_12_0
};
for (int i = 0; i < _countof(featureLevels); i++) {
if (SUCCEEDED(D3D12CreateDevice(adapter.get(), featureLevels[i], _uuidof(ID3D12Device), nullptr))) {
maxSupportedFeatureLevel = featureLevels[i];
break;
}
}
gr_cp<ID3D12Device> device;
if (!SUCCEEDED(D3D12CreateDevice(adapter.get(), maxSupportedFeatureLevel, IID_PPV_ARGS(&device)))) {
return 0;
}
// Create the command queue
gr_cp<ID3D12CommandQueue> queue;
D3D12_COMMAND_QUEUE_DESC queueDesc = {};
queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
if (!SUCCEEDED(device->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&queue)))) {
return 0;
}
HWND hWnd = fromJavaPointer<HWND>(contentHandle);
DirectXDevice *d3dDevice = new DirectXDevice();
d3dDevice->backendContext.fAdapter = adapter;
d3dDevice->backendContext.fDevice = device;
d3dDevice->backendContext.fQueue = queue;
d3dDevice->backendContext.fProtectedContext = GrProtected::kNo;
d3dDevice->device = device;
d3dDevice->queue = queue;
d3dDevice->hWnd = hWnd;
if (transparency) {
const LONG style = GetWindowLong(hWnd, GWL_EXSTYLE);
SetWindowLong(hWnd, GWL_EXSTYLE, style | WS_EX_TRANSPARENT);
}
return toJavaPointer(d3dDevice);
}