## XAppGpuOffloadHelper

XAppGpuOffloadHelper — Simple interface for Switcheroo.

## Functions

XAppGpuOffloadHelper * | xapp_gpu_offload_helper_get ()
XAppGpuOffloadHelper * | xapp_gpu_offload_helper_get_sync ()
gboolean | xapp_gpu_offload_helper_is_ready ()
gboolean | xapp_gpu_offload_helper_is_offload_supported ()
gint | xapp_gpu_offload_helper_get_n_gpus ()
GList * | xapp_gpu_offload_helper_get_offload_infos ()
XAppGpuInfo * | xapp_gpu_offload_helper_get_default_info ()
XAppGpuInfo * | xapp_gpu_offload_helper_get_info_by_id ()
gchar * | xapp_gpu_info_get_shell_env_prefix ()

## Signals

void | ready | Action

## Types and Values

#define | XAPP_TYPE_GPU_OFFLOAD_HELPER
struct | XAppGpuInfo
| XAppGpuOffloadHelper

## Object Hierarchy

        GBoxed
        ╰── XAppGpuInfo
        GObject
        ╰── XAppGpuOffloadHelper

## Description

XAppGpuOffloadHelper is class that provides a reliable property cache and simple return methods for getting offload_helper parameters and conditions from the Switcheroo interface.

Since 2.6

## Functions

### xapp_gpu_offload_helper_get ()

    XAppGpuOffloadHelper *
    xapp_gpu_offload_helper_get (void);

Creates a new XAppGpuOffloadHelper instance.

The “ready” signal will be emitted when the helper is initialized (successfully or not).

#### Returns

a new XAppGpuOffloadHelper.

[transfer none]

Since: 2.6

### xapp_gpu_offload_helper_get_sync ()

    XAppGpuOffloadHelper *
    xapp_gpu_offload_helper_get_sync (void);

Creates a new XAppGpuOffloadHelper instance. This performs initialization synchronously, and can potentially block.

Use `xapp_gpu_offload_helper_is_ready()` to see if the helper was initialized successfully.

#### Returns

a new XAppGpuOffloadHelper, fully initialized.

[transfer none]

Since: 2.6

### xapp_gpu_offload_helper_is_ready ()

    gboolean
    xapp_gpu_offload_helper_is_ready (XAppGpuOffloadHelper *helper);

Checks if the helper is ready and valid. This does not mean offload support exists.

#### Parameters

helper | The XAppGpuOffloadHelper. |

#### Returns

`TRUE` if the helper has been successfully initialized.

Since: 2.6

### xapp_gpu_offload_helper_is_offload_supported ()

    gboolean
    xapp_gpu_offload_helper_is_offload_supported
                                   (XAppGpuOffloadHelper *helper);

Checks if there is a non-default GPU available for offloading.

#### Parameters

helper | The XAppGpuOffloadHelper. |

#### Returns

`TRUE` if there is an extra GPU available.

Since: 2.6

### xapp_gpu_offload_helper_get_n_gpus ()

    gint
    xapp_gpu_offload_helper_get_n_gpus (XAppGpuOffloadHelper *helper);

Gets the number of GPUs noticed by Switcheroo.

#### Parameters

helper | The XAppGpuOffloadHelper. |

#### Returns

the total number of GPUs. A return value larger than 1 implies there are offloadable GPUs available.

Since: 2.6

### xapp_gpu_offload_helper_get_offload_infos ()

    GList *
    xapp_gpu_offload_helper_get_offload_infos
                                   (XAppGpuOffloadHelper *helper);

Generates a list of XAppGpuInfos that can be offloaded to, if there are any.

#### Parameters

helper | The XAppGpuOffloadHelper. |

#### Returns

a list of XAppGpuInfos or `NULL` if there is only a single GPU. The elements are owned by `helper` but the container itself should be freed.

[element-type XAppGpuInfo][transfer container]

Since: 2.6

### xapp_gpu_offload_helper_get_default_info ()

    XAppGpuInfo *
    xapp_gpu_offload_helper_get_default_info
                                   (XAppGpuOffloadHelper *helper);

Returns an XAppGpuInfo for the default GPU.

#### Parameters

helper | The XAppGpuOffloadHelper. |

#### Returns

the default XAppGpuInfo. Do not free.

[transfer none]

Since: 2.6

### xapp_gpu_offload_helper_get_info_by_id ()

    XAppGpuInfo *
    xapp_gpu_offload_helper_get_info_by_id
                                   (XAppGpuOffloadHelper *helper,
                                    gint id);

Returns an XAppGpuInfo with the given ID.

#### Parameters

helper | The XAppGpuOffloadHelper. |
id | The ID of the info to retrieve. |

#### Returns

the appropriate XAppGpuInfo, or `NULL` if `id` was invalid.

[transfer none]

Since: 2.6

### xapp_gpu_info_get_shell_env_prefix ()

    gchar *
    xapp_gpu_info_get_shell_env_prefix (XAppGpuInfo *info);

Creates a new string in a form intended to prefix a shell command, containing the appropriate name/values for this gpu. For example:

__GLX_VENDOR_LIBRARY_NAME=nvidia __NV_PRIME_RENDER_OFFLOAD=1

#### Parameters

info | An XAppGpuInfo. |

#### Returns

A new string, free with `g_free()`.

Since 2.6.

[transfer full]

## Types and Values

### XAPP_TYPE_GPU_OFFLOAD_HELPER

    #define XAPP_TYPE_GPU_OFFLOAD_HELPER xapp_gpu_offload_helper_get_type ()

### struct XAppGpuInfo

    struct XAppGpuInfo {
        gint id;
        gboolean is_default;
        gchar *display_name;
        gchar **env_strv;
    };

Information about a single GPU used for offloading. The length of `env_strv` will always be an even number.

#### Members

gint `id`; | An identifier that can be used to refer to this GPU. |
gboolean `is_default`; | Whether this GPU is used by default. |
gchar *`display_name`; | User-visible name of the GPU. |
gchar **`env_strv`; | A string array containing alternating environment variables names and values to use to enable the gpu. | [array zero-terminated=1]

### XAppGpuOffloadHelper

    typedef struct _XAppGpuOffloadHelper XAppGpuOffloadHelper;

## Signal Details

### The `“ready”` signal

    void
    user_function (XAppGpuOffloadHelper *helper,
                   gboolean              success,
                   gpointer              user_data)

This signal is emitted by the helper when it has completed gathering GPU information. It will only be sent once.

#### Parameters

helper | the XAppGpuOffloadHelper |
success | Whether or not the helper initialize successfully. |
user_data | user data set when the signal handler was connected. |

Flags: Action