Skip to content

Commit

Permalink
added Turnip graphics driver version switching for Shortcuts! Much be…
Browse files Browse the repository at this point in the history
…tter than glibc implementation
  • Loading branch information
coffincolors committed Sep 17, 2024
1 parent c467297 commit 41f2af5
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 10 deletions.
Binary file modified app/.gradle/8.5/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified app/.gradle/8.5/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified app/.gradle/8.5/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified app/.gradle/8.5/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified app/.gradle/8.5/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file modified app/.gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified app/.gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
Binary file modified app/.gradle/file-system.probe
Binary file not shown.
25 changes: 21 additions & 4 deletions app/src/main/java/com/winlator/XServerDisplayActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -1242,14 +1242,27 @@ private void extractGraphicsDriverFiles() {
String cacheId = graphicsDriver;
String selectedDriverVersion = container.getGraphicsDriverVersion(); // Fetch the selected version

// Adjust cacheId based on graphics driver
if (shortcut != null) {
selectedDriverVersion = shortcut.getExtra("graphicsDriverVersion", container.getGraphicsDriverVersion());
}

// Adjust cacheId based on the graphics driver and version
if (graphicsDriver.equals("turnip")) {
cacheId += "-" + DefaultVersion.TURNIP + "-" + DefaultVersion.ZINK;
cacheId += "-" + selectedDriverVersion; // Append version if using Turnip driver
cacheId += "-" + DefaultVersion.ZINK; // Append Zink version for Turnip driver
} else if (graphicsDriver.equals("virgl")) {
cacheId += "-" + DefaultVersion.VIRGL;
cacheId += "-" + DefaultVersion.VIRGL; // Append version for VirGL driver
}

Log.d("GraphicsDriverExtraction", "Cache ID: " + cacheId);

boolean changed = !cacheId.equals(container.getExtra("graphicsDriver"));

// If launching without a shortcut (container-only launch), always extract to reset to the container's default
if (shortcut == null) {
changed = true; // Force extraction when no shortcut is present to ensure correct driver is used
}

File rootDir = imageFs.getRootDir(); // Target the root directory of imagefs

if (changed) {
Expand All @@ -1261,6 +1274,8 @@ private void extractGraphicsDriverFiles() {
container.saveData();
}



if (graphicsDriver.equals("turnip")) {
if (dxwrapper.equals("dxvk")) {
DXVKConfigDialog.setEnvVars(this, dxwrapperConfig, envVars);
Expand Down Expand Up @@ -1289,7 +1304,8 @@ private void extractGraphicsDriverFiles() {

boolean extractionSucceeded = false;
if (changed) {
extractionSucceeded = TarCompressorUtils.extract(TarCompressorUtils.Type.ZSTD, this, "graphics_driver/turnip-" + DefaultVersion.TURNIP + ".tzst", rootDir) &&
// Use selectedDriverVersion instead of DefaultVersion.TURNIP
extractionSucceeded = TarCompressorUtils.extract(TarCompressorUtils.Type.ZSTD, this, "graphics_driver/turnip-" + selectedDriverVersion + ".tzst", rootDir) &&
TarCompressorUtils.extract(TarCompressorUtils.Type.ZSTD, this, "graphics_driver/zink-" + DefaultVersion.ZINK + ".tzst", rootDir);

if (extractionSucceeded) {
Expand All @@ -1299,6 +1315,7 @@ private void extractGraphicsDriverFiles() {
}
}


if (!extractionSucceeded) {
// Parse version string for the actual version number, removing "Turnip-"
String normalizedVersion = selectedDriverVersion.replaceFirst("Turnip-", "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
import com.winlator.R;
import com.winlator.container.Container;
import com.winlator.container.ContainerManager;
import com.winlator.container.Shortcut;
import com.winlator.contents.ContentProfile;
import com.winlator.contents.ContentsManager;
import com.winlator.core.AppUtils;
import com.winlator.core.DefaultVersion;

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -25,13 +25,58 @@ public class GraphicsDriverConfigDialog extends ContentDialog {
private static final String TAG = "GraphicsDriverConfigDialog"; // Tag for logging

private final Spinner sVersion;
private final ContainerManager containerManager;
private ContainerManager containerManager;
private String selectedVersion;

public interface OnGraphicsDriverVersionSelectedListener {
void onGraphicsDriverVersionSelected(String version);
}

public GraphicsDriverConfigDialog (View anchor, String initialVersion, Shortcut shortcut, OnGraphicsDriverVersionSelectedListener listener) {
super(anchor.getContext(), R.layout.graphics_driver_config_dialog);

setIcon(R.drawable.icon_settings);
setTitle(anchor.getContext().getString(R.string.graphics_driver_configuration));

sVersion = findViewById(R.id.SGraphicsDriverVersion);

// Ensure ContentsManager syncContents is called
ContentsManager contentsManager = new ContentsManager(anchor.getContext());
contentsManager.syncContents();

// Populate the spinner with available versions from ContentsManager
populateGraphicsDriverVersions(anchor.getContext(), contentsManager, initialVersion);

// Update the selectedVersion whenever the user selects a different version
sVersion.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
selectedVersion = sVersion.getSelectedItem().toString();
Log.d(TAG, "User selected version: " + selectedVersion); // Log the selected version
}

@Override
public void onNothingSelected(AdapterView<?> parent) {
// Do nothing
}
});

setOnConfirmCallback(() -> {
anchor.setTag(selectedVersion);

if (shortcut != null) {
// Apply the selected version to the shortcut
Log.d(TAG, "Applying selected version to shortcut: " + selectedVersion);
shortcut.putExtra("graphicsDriverVersion", selectedVersion);
}

// Pass the selected version back to ShortcutSettingsDialog
if (listener != null) {
listener.onGraphicsDriverVersionSelected(selectedVersion);
}
});
}

public GraphicsDriverConfigDialog(View anchor, ContainerManager containerManager, @Nullable Container container, @Nullable String initialVersion, OnGraphicsDriverVersionSelectedListener listener) {
super(anchor.getContext(), R.layout.graphics_driver_config_dialog);
this.containerManager = containerManager;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.winlator.contentdialog;



import android.content.Context;
import android.graphics.drawable.Icon;
import android.view.Menu;
Expand Down Expand Up @@ -34,6 +36,8 @@ public class ShortcutSettingsDialog extends ContentDialog {
private final Shortcut shortcut;
private InputControlsManager inputControlsManager;

private String graphicsDriverVersion;

public ShortcutSettingsDialog(ShortcutsFragment fragment, Shortcut shortcut) {
super(fragment.getContext(), R.layout.shortcut_settings_dialog);
this.fragment = fragment;
Expand Down Expand Up @@ -65,6 +69,14 @@ private void createContentView() {
contentsManager.syncContents();
ContainerDetailFragment.updateGraphicsDriverSpinner(context, contentsManager, sGraphicsDriver);

final View vGraphicsDriverConfig = findViewById(R.id.BTGraphicsDriverConfig);
vGraphicsDriverConfig.setTag(shortcut.getExtra("graphicsDriverVersion", shortcut.container.getGraphicsDriverVersion()));
vGraphicsDriverConfig.setOnClickListener((v) -> {

showGraphicsDriverConfigDialog(vGraphicsDriverConfig);

});

final View vDXWrapperConfig = findViewById(R.id.BTDXWrapperConfig);
vDXWrapperConfig.setTag(shortcut.getExtra("dxwrapperConfig", shortcut.container.getDXWrapperConfig()));

Expand Down Expand Up @@ -182,6 +194,7 @@ private void createContentView() {
}
else {
String graphicsDriver = StringUtils.parseIdentifier(sGraphicsDriver.getSelectedItem());
String graphicsDriverConfig = vGraphicsDriverConfig.getTag().toString();
String dxwrapper = StringUtils.parseIdentifier(sDXWrapper.getSelectedItem());
String dxwrapperConfig = vDXWrapperConfig.getTag().toString();
String audioDriver = StringUtils.parseIdentifier(sAudioDriver.getSelectedItem());
Expand All @@ -197,12 +210,15 @@ private void createContentView() {
shortcut.putExtra("execArgs", !execArgs.isEmpty() ? execArgs : null);
shortcut.putExtra("screenSize", !screenSize.equals(shortcut.container.getScreenSize()) ? screenSize : null);
shortcut.putExtra("graphicsDriver", !graphicsDriver.equals(shortcut.container.getGraphicsDriver()) ? graphicsDriver : null);
shortcut.putExtra("graphicsDriverVersion", graphicsDriverConfig);
shortcut.putExtra("dxwrapper", !dxwrapper.equals(shortcut.container.getDXWrapper()) ? dxwrapper : null);
shortcut.putExtra("dxwrapperConfig", !dxwrapperConfig.equals(shortcut.container.getDXWrapperConfig()) ? dxwrapperConfig : null);
shortcut.putExtra("audioDriver", !audioDriver.equals(shortcut.container.getAudioDriver())? audioDriver : null);
shortcut.putExtra("forceFullscreen", cbForceFullscreen.isChecked() ? "1" : null);
updateExtra("lc_all", shortcut.container.getLC_ALL(), lc_all);



if (cbUseSecondaryExec.isChecked()) {
String secondaryExec = etSecondaryExec.getText().toString().trim();
String execDelay = etExecDelay.getText().toString().trim();
Expand Down Expand Up @@ -239,6 +255,13 @@ private void createContentView() {
});
}

private void showGraphicsDriverConfigDialog(View anchor) {
new GraphicsDriverConfigDialog(anchor, graphicsDriverVersion, shortcut, version -> {
// Capture the selected version
graphicsDriverVersion = version;
}).show();
}

private void updateExtra(String extraName, String containerValue, String newValue) {
String extraValue = shortcut.getExtra(extraName);
if (extraValue.isEmpty() && containerValue.equals(newValue))
Expand Down
25 changes: 21 additions & 4 deletions app/src/main/res/layout/shortcut_settings_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,28 @@
android:layout_height="wrap_content"
android:text="@string/graphics_driver" />

<Spinner
style="@style/ComboBox"
<LinearLayout
android:layout_width="match_parent"
android:id="@+id/SGraphicsDriver"
android:entries="@array/graphics_driver_entries" />
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical">

<Spinner
style="@style/ComboBox"
android:layout_width="0dp"
android:layout_weight="1"
android:id="@+id/SGraphicsDriver"
android:entries="@array/graphics_driver_entries" />

<ImageButton
style="@style/ListMenuButton"
android:id="@+id/BTGraphicsDriverConfig"
android:layout_width="48dp"
android:layout_height="48dp"
android:padding="8dp"
android:src="@drawable/icon_settings"
android:visibility="visible" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
Expand Down

0 comments on commit 41f2af5

Please sign in to comment.