rrprovider.c revision a035e2b2
135c4bbdfSmrg/*
235c4bbdfSmrg * Copyright © 2012 Red Hat Inc.
335c4bbdfSmrg *
435c4bbdfSmrg * Permission to use, copy, modify, distribute, and sell this software and its
535c4bbdfSmrg * documentation for any purpose is hereby granted without fee, provided that
635c4bbdfSmrg * the above copyright notice appear in all copies and that both that copyright
735c4bbdfSmrg * notice and this permission notice appear in supporting documentation, and
835c4bbdfSmrg * that the name of the copyright holders not be used in advertising or
935c4bbdfSmrg * publicity pertaining to distribution of the software without specific,
1035c4bbdfSmrg * written prior permission.  The copyright holders make no representations
1135c4bbdfSmrg * about the suitability of this software for any purpose.  It is provided "as
1235c4bbdfSmrg * is" without express or implied warranty.
1335c4bbdfSmrg *
1435c4bbdfSmrg * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
1535c4bbdfSmrg * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
1635c4bbdfSmrg * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
1735c4bbdfSmrg * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
1835c4bbdfSmrg * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
1935c4bbdfSmrg * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
2035c4bbdfSmrg * OF THIS SOFTWARE.
2135c4bbdfSmrg *
2235c4bbdfSmrg * Authors: Dave Airlie
2335c4bbdfSmrg */
2435c4bbdfSmrg
2535c4bbdfSmrg#include "randrstr.h"
2635c4bbdfSmrg#include "swaprep.h"
2735c4bbdfSmrg
281b5d61b8Smrg#include <X11/Xatom.h>
291b5d61b8Smrg
30a035e2b2SmrgRESTYPE RRProviderType = 0;
3135c4bbdfSmrg
3235c4bbdfSmrg/*
3335c4bbdfSmrg * Initialize provider type error value
3435c4bbdfSmrg */
3535c4bbdfSmrgvoid
3635c4bbdfSmrgRRProviderInitErrorValue(void)
3735c4bbdfSmrg{
3835c4bbdfSmrg    SetResourceTypeErrorValue(RRProviderType, RRErrorBase + BadRRProvider);
3935c4bbdfSmrg}
4035c4bbdfSmrg
4135c4bbdfSmrg#define ADD_PROVIDER(_pScreen) do {                                 \
4235c4bbdfSmrg    pScrPriv = rrGetScrPriv((_pScreen));                            \
4335c4bbdfSmrg    if (pScrPriv->provider) {                                   \
4435c4bbdfSmrg        providers[count_providers] = pScrPriv->provider->id;    \
4535c4bbdfSmrg        if (client->swapped)                                    \
4635c4bbdfSmrg            swapl(&providers[count_providers]);                 \
4735c4bbdfSmrg        count_providers++;                                      \
4835c4bbdfSmrg    }                                                           \
4935c4bbdfSmrg    } while(0)
5035c4bbdfSmrg
5135c4bbdfSmrgint
5235c4bbdfSmrgProcRRGetProviders (ClientPtr client)
5335c4bbdfSmrg{
5435c4bbdfSmrg    REQUEST(xRRGetProvidersReq);
5535c4bbdfSmrg    xRRGetProvidersReply rep;
5635c4bbdfSmrg    WindowPtr pWin;
5735c4bbdfSmrg    ScreenPtr pScreen;
5835c4bbdfSmrg    rrScrPrivPtr pScrPriv;
5935c4bbdfSmrg    int rc;
6035c4bbdfSmrg    CARD8 *extra;
6135c4bbdfSmrg    unsigned int extraLen;
6235c4bbdfSmrg    RRProvider *providers;
6335c4bbdfSmrg    int total_providers = 0, count_providers = 0;
6435c4bbdfSmrg    ScreenPtr iter;
6535c4bbdfSmrg
6635c4bbdfSmrg    REQUEST_SIZE_MATCH(xRRGetProvidersReq);
6735c4bbdfSmrg    rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
6835c4bbdfSmrg    if (rc != Success)
6935c4bbdfSmrg        return rc;
7035c4bbdfSmrg
7135c4bbdfSmrg    pScreen = pWin->drawable.pScreen;
7235c4bbdfSmrg
7335c4bbdfSmrg    pScrPriv = rrGetScrPriv(pScreen);
7435c4bbdfSmrg
7535c4bbdfSmrg    if (pScrPriv->provider)
7635c4bbdfSmrg        total_providers++;
771b5d61b8Smrg    xorg_list_for_each_entry(iter, &pScreen->slave_list, slave_head) {
7835c4bbdfSmrg        pScrPriv = rrGetScrPriv(iter);
7935c4bbdfSmrg        total_providers += pScrPriv->provider ? 1 : 0;
8035c4bbdfSmrg    }
8135c4bbdfSmrg
8235c4bbdfSmrg    pScrPriv = rrGetScrPriv(pScreen);
8335c4bbdfSmrg
8435c4bbdfSmrg    if (!pScrPriv)
8535c4bbdfSmrg    {
8635c4bbdfSmrg        rep = (xRRGetProvidersReply) {
8735c4bbdfSmrg            .type = X_Reply,
8835c4bbdfSmrg            .sequenceNumber = client->sequence,
8935c4bbdfSmrg            .length = 0,
9035c4bbdfSmrg            .timestamp = currentTime.milliseconds,
9135c4bbdfSmrg            .nProviders = 0
9235c4bbdfSmrg        };
9335c4bbdfSmrg        extra = NULL;
9435c4bbdfSmrg        extraLen = 0;
9535c4bbdfSmrg    } else {
9635c4bbdfSmrg        rep = (xRRGetProvidersReply) {
9735c4bbdfSmrg            .type = X_Reply,
9835c4bbdfSmrg            .sequenceNumber = client->sequence,
9935c4bbdfSmrg            .timestamp = pScrPriv->lastSetTime.milliseconds,
10035c4bbdfSmrg            .nProviders = total_providers,
10135c4bbdfSmrg            .length = total_providers
10235c4bbdfSmrg        };
10335c4bbdfSmrg        extraLen = rep.length << 2;
10435c4bbdfSmrg        if (extraLen) {
10535c4bbdfSmrg            extra = malloc(extraLen);
10635c4bbdfSmrg            if (!extra)
10735c4bbdfSmrg                return BadAlloc;
10835c4bbdfSmrg        } else
10935c4bbdfSmrg            extra = NULL;
11035c4bbdfSmrg
11135c4bbdfSmrg        providers = (RRProvider *)extra;
11235c4bbdfSmrg        ADD_PROVIDER(pScreen);
1131b5d61b8Smrg        xorg_list_for_each_entry(iter, &pScreen->slave_list, slave_head) {
11435c4bbdfSmrg            ADD_PROVIDER(iter);
11535c4bbdfSmrg        }
11635c4bbdfSmrg    }
11735c4bbdfSmrg
11835c4bbdfSmrg    if (client->swapped) {
11935c4bbdfSmrg        swaps(&rep.sequenceNumber);
12035c4bbdfSmrg        swapl(&rep.length);
12135c4bbdfSmrg        swapl(&rep.timestamp);
12235c4bbdfSmrg        swaps(&rep.nProviders);
12335c4bbdfSmrg    }
12435c4bbdfSmrg    WriteToClient(client, sizeof(xRRGetProvidersReply), (char *)&rep);
12535c4bbdfSmrg    if (extraLen)
12635c4bbdfSmrg    {
12735c4bbdfSmrg        WriteToClient (client, extraLen, (char *) extra);
12835c4bbdfSmrg        free(extra);
12935c4bbdfSmrg    }
13035c4bbdfSmrg    return Success;
13135c4bbdfSmrg}
13235c4bbdfSmrg
13335c4bbdfSmrgint
13435c4bbdfSmrgProcRRGetProviderInfo (ClientPtr client)
13535c4bbdfSmrg{
13635c4bbdfSmrg    REQUEST(xRRGetProviderInfoReq);
13735c4bbdfSmrg    xRRGetProviderInfoReply rep;
13835c4bbdfSmrg    rrScrPrivPtr pScrPriv, pScrProvPriv;
13935c4bbdfSmrg    RRProviderPtr provider;
14035c4bbdfSmrg    ScreenPtr pScreen;
14135c4bbdfSmrg    CARD8 *extra;
14235c4bbdfSmrg    unsigned int extraLen = 0;
14335c4bbdfSmrg    RRCrtc *crtcs;
14435c4bbdfSmrg    RROutput *outputs;
14535c4bbdfSmrg    int i;
14635c4bbdfSmrg    char *name;
14735c4bbdfSmrg    ScreenPtr provscreen;
14835c4bbdfSmrg    RRProvider *providers;
14935c4bbdfSmrg    uint32_t *prov_cap;
15035c4bbdfSmrg
15135c4bbdfSmrg    REQUEST_SIZE_MATCH(xRRGetProviderInfoReq);
15235c4bbdfSmrg    VERIFY_RR_PROVIDER(stuff->provider, provider, DixReadAccess);
15335c4bbdfSmrg
15435c4bbdfSmrg    pScreen = provider->pScreen;
15535c4bbdfSmrg    pScrPriv = rrGetScrPriv(pScreen);
15635c4bbdfSmrg
15735c4bbdfSmrg    rep = (xRRGetProviderInfoReply) {
15835c4bbdfSmrg        .type = X_Reply,
15935c4bbdfSmrg        .status = RRSetConfigSuccess,
16035c4bbdfSmrg        .sequenceNumber = client->sequence,
16135c4bbdfSmrg        .length = 0,
16235c4bbdfSmrg        .capabilities = provider->capabilities,
16335c4bbdfSmrg        .nameLength = provider->nameLength,
16435c4bbdfSmrg        .timestamp = pScrPriv->lastSetTime.milliseconds,
16535c4bbdfSmrg        .nCrtcs = pScrPriv->numCrtcs,
16635c4bbdfSmrg        .nOutputs = pScrPriv->numOutputs,
16735c4bbdfSmrg        .nAssociatedProviders = 0
16835c4bbdfSmrg    };
16935c4bbdfSmrg
17035c4bbdfSmrg    /* count associated providers */
17135c4bbdfSmrg    if (provider->offload_sink)
17235c4bbdfSmrg        rep.nAssociatedProviders++;
1731b5d61b8Smrg    if (provider->output_source &&
1741b5d61b8Smrg            provider->output_source != provider->offload_sink)
17535c4bbdfSmrg        rep.nAssociatedProviders++;
1761b5d61b8Smrg    xorg_list_for_each_entry(provscreen, &pScreen->slave_list, slave_head) {
1771b5d61b8Smrg        if (provscreen->is_output_slave || provscreen->is_offload_slave)
1781b5d61b8Smrg            rep.nAssociatedProviders++;
1791b5d61b8Smrg    }
18035c4bbdfSmrg
18135c4bbdfSmrg    rep.length = (pScrPriv->numCrtcs + pScrPriv->numOutputs +
18235c4bbdfSmrg                  (rep.nAssociatedProviders * 2) + bytes_to_int32(rep.nameLength));
18335c4bbdfSmrg
18435c4bbdfSmrg    extraLen = rep.length << 2;
18535c4bbdfSmrg    if (extraLen) {
18635c4bbdfSmrg        extra = malloc(extraLen);
18735c4bbdfSmrg        if (!extra)
18835c4bbdfSmrg            return BadAlloc;
18935c4bbdfSmrg    }
19035c4bbdfSmrg    else
19135c4bbdfSmrg        extra = NULL;
19235c4bbdfSmrg
19335c4bbdfSmrg    crtcs = (RRCrtc *)extra;
19435c4bbdfSmrg    outputs = (RROutput *)(crtcs + rep.nCrtcs);
19535c4bbdfSmrg    providers = (RRProvider *)(outputs + rep.nOutputs);
19635c4bbdfSmrg    prov_cap = (unsigned int *)(providers + rep.nAssociatedProviders);
19735c4bbdfSmrg    name = (char *)(prov_cap + rep.nAssociatedProviders);
19835c4bbdfSmrg
19935c4bbdfSmrg    for (i = 0; i < pScrPriv->numCrtcs; i++) {
20035c4bbdfSmrg        crtcs[i] = pScrPriv->crtcs[i]->id;
20135c4bbdfSmrg        if (client->swapped)
20235c4bbdfSmrg            swapl(&crtcs[i]);
20335c4bbdfSmrg    }
20435c4bbdfSmrg
20535c4bbdfSmrg    for (i = 0; i < pScrPriv->numOutputs; i++) {
20635c4bbdfSmrg        outputs[i] = pScrPriv->outputs[i]->id;
20735c4bbdfSmrg        if (client->swapped)
20835c4bbdfSmrg            swapl(&outputs[i]);
20935c4bbdfSmrg    }
21035c4bbdfSmrg
21135c4bbdfSmrg    i = 0;
21235c4bbdfSmrg    if (provider->offload_sink) {
21335c4bbdfSmrg        providers[i] = provider->offload_sink->id;
21435c4bbdfSmrg        if (client->swapped)
21535c4bbdfSmrg            swapl(&providers[i]);
21635c4bbdfSmrg        prov_cap[i] = RR_Capability_SinkOffload;
21735c4bbdfSmrg        if (client->swapped)
21835c4bbdfSmrg            swapl(&prov_cap[i]);
21935c4bbdfSmrg        i++;
22035c4bbdfSmrg    }
22135c4bbdfSmrg    if (provider->output_source) {
22235c4bbdfSmrg        providers[i] = provider->output_source->id;
22335c4bbdfSmrg        if (client->swapped)
22435c4bbdfSmrg            swapl(&providers[i]);
22535c4bbdfSmrg        prov_cap[i] = RR_Capability_SourceOutput;
22635c4bbdfSmrg            swapl(&prov_cap[i]);
22735c4bbdfSmrg        i++;
22835c4bbdfSmrg    }
2291b5d61b8Smrg    xorg_list_for_each_entry(provscreen, &pScreen->slave_list, slave_head) {
2301b5d61b8Smrg        if (!provscreen->is_output_slave && !provscreen->is_offload_slave)
2311b5d61b8Smrg            continue;
23235c4bbdfSmrg        pScrProvPriv = rrGetScrPriv(provscreen);
23335c4bbdfSmrg        providers[i] = pScrProvPriv->provider->id;
23435c4bbdfSmrg        if (client->swapped)
23535c4bbdfSmrg            swapl(&providers[i]);
2361b5d61b8Smrg        prov_cap[i] = 0;
2371b5d61b8Smrg        if (provscreen->is_output_slave)
2381b5d61b8Smrg            prov_cap[i] |= RR_Capability_SinkOutput;
2391b5d61b8Smrg        if (provscreen->is_offload_slave)
2401b5d61b8Smrg            prov_cap[i] |= RR_Capability_SourceOffload;
24135c4bbdfSmrg        if (client->swapped)
24235c4bbdfSmrg            swapl(&prov_cap[i]);
24335c4bbdfSmrg        i++;
24435c4bbdfSmrg    }
24535c4bbdfSmrg
24635c4bbdfSmrg    memcpy(name, provider->name, rep.nameLength);
24735c4bbdfSmrg    if (client->swapped) {
24835c4bbdfSmrg              swaps(&rep.sequenceNumber);
24935c4bbdfSmrg        swapl(&rep.length);
25035c4bbdfSmrg        swapl(&rep.capabilities);
25135c4bbdfSmrg        swaps(&rep.nCrtcs);
25235c4bbdfSmrg        swaps(&rep.nOutputs);
25335c4bbdfSmrg        swaps(&rep.nameLength);
25435c4bbdfSmrg    }
25535c4bbdfSmrg    WriteToClient(client, sizeof(xRRGetProviderInfoReply), (char *)&rep);
25635c4bbdfSmrg    if (extraLen)
25735c4bbdfSmrg    {
25835c4bbdfSmrg        WriteToClient (client, extraLen, (char *) extra);
25935c4bbdfSmrg        free(extra);
26035c4bbdfSmrg    }
26135c4bbdfSmrg    return Success;
26235c4bbdfSmrg}
26335c4bbdfSmrg
2641b5d61b8Smrgstatic void
2651b5d61b8SmrgRRInitPrimeSyncProps(ScreenPtr pScreen)
2661b5d61b8Smrg{
2671b5d61b8Smrg    /*
2681b5d61b8Smrg     * TODO: When adding support for different sources for different outputs,
2691b5d61b8Smrg     * make sure this sets up the output properties only on outputs associated
2701b5d61b8Smrg     * with the correct source provider.
2711b5d61b8Smrg     */
2721b5d61b8Smrg
2731b5d61b8Smrg    rrScrPrivPtr pScrPriv = rrGetScrPriv(pScreen);
2741b5d61b8Smrg
2751b5d61b8Smrg    const char *syncStr = PRIME_SYNC_PROP;
2761b5d61b8Smrg    Atom syncProp = MakeAtom(syncStr, strlen(syncStr), TRUE);
2771b5d61b8Smrg
2781b5d61b8Smrg    int defaultVal = TRUE;
2791b5d61b8Smrg    INT32 validVals[2] = {FALSE, TRUE};
2801b5d61b8Smrg
2811b5d61b8Smrg    int i;
2821b5d61b8Smrg    for (i = 0; i < pScrPriv->numOutputs; i++) {
2831b5d61b8Smrg        if (!RRQueryOutputProperty(pScrPriv->outputs[i], syncProp)) {
2841b5d61b8Smrg            RRConfigureOutputProperty(pScrPriv->outputs[i], syncProp,
2851b5d61b8Smrg                                      TRUE, FALSE, FALSE,
2861b5d61b8Smrg                                      2, &validVals[0]);
2871b5d61b8Smrg            RRChangeOutputProperty(pScrPriv->outputs[i], syncProp, XA_INTEGER,
2881b5d61b8Smrg                                   8, PropModeReplace, 1, &defaultVal,
2891b5d61b8Smrg                                   FALSE, FALSE);
2901b5d61b8Smrg        }
2911b5d61b8Smrg    }
2921b5d61b8Smrg}
2931b5d61b8Smrg
2941b5d61b8Smrgstatic void
2951b5d61b8SmrgRRFiniPrimeSyncProps(ScreenPtr pScreen)
2961b5d61b8Smrg{
2971b5d61b8Smrg    /*
2981b5d61b8Smrg     * TODO: When adding support for different sources for different outputs,
2991b5d61b8Smrg     * make sure this tears down the output properties only on outputs
3001b5d61b8Smrg     * associated with the correct source provider.
3011b5d61b8Smrg     */
3021b5d61b8Smrg
3031b5d61b8Smrg    rrScrPrivPtr pScrPriv = rrGetScrPriv(pScreen);
3041b5d61b8Smrg    int i;
3051b5d61b8Smrg
3061b5d61b8Smrg    const char *syncStr = PRIME_SYNC_PROP;
3071b5d61b8Smrg    Atom syncProp = MakeAtom(syncStr, strlen(syncStr), FALSE);
3081b5d61b8Smrg    if (syncProp == None)
3091b5d61b8Smrg        return;
3101b5d61b8Smrg
3111b5d61b8Smrg    for (i = 0; i < pScrPriv->numOutputs; i++) {
3121b5d61b8Smrg        RRDeleteOutputProperty(pScrPriv->outputs[i], syncProp);
3131b5d61b8Smrg    }
3141b5d61b8Smrg}
3151b5d61b8Smrg
31635c4bbdfSmrgint
31735c4bbdfSmrgProcRRSetProviderOutputSource(ClientPtr client)
31835c4bbdfSmrg{
31935c4bbdfSmrg    REQUEST(xRRSetProviderOutputSourceReq);
32035c4bbdfSmrg    rrScrPrivPtr pScrPriv;
32135c4bbdfSmrg    RRProviderPtr provider, source_provider = NULL;
32235c4bbdfSmrg    ScreenPtr pScreen;
32335c4bbdfSmrg
32435c4bbdfSmrg    REQUEST_SIZE_MATCH(xRRSetProviderOutputSourceReq);
32535c4bbdfSmrg
32635c4bbdfSmrg    VERIFY_RR_PROVIDER(stuff->provider, provider, DixReadAccess);
32735c4bbdfSmrg
32835c4bbdfSmrg    if (!(provider->capabilities & RR_Capability_SinkOutput))
32935c4bbdfSmrg        return BadValue;
33035c4bbdfSmrg
33135c4bbdfSmrg    if (stuff->source_provider) {
33235c4bbdfSmrg        VERIFY_RR_PROVIDER(stuff->source_provider, source_provider, DixReadAccess);
33335c4bbdfSmrg
33435c4bbdfSmrg        if (!(source_provider->capabilities & RR_Capability_SourceOutput))
33535c4bbdfSmrg            return BadValue;
33635c4bbdfSmrg    }
33735c4bbdfSmrg
33835c4bbdfSmrg    pScreen = provider->pScreen;
33935c4bbdfSmrg    pScrPriv = rrGetScrPriv(pScreen);
34035c4bbdfSmrg
3411b5d61b8Smrg    if (!pScreen->isGPU)
3421b5d61b8Smrg        return BadValue;
3431b5d61b8Smrg
34435c4bbdfSmrg    pScrPriv->rrProviderSetOutputSource(pScreen, provider, source_provider);
34535c4bbdfSmrg
3461b5d61b8Smrg    RRInitPrimeSyncProps(pScreen);
3471b5d61b8Smrg
34835c4bbdfSmrg    provider->changed = TRUE;
34935c4bbdfSmrg    RRSetChanged(pScreen);
35035c4bbdfSmrg
35135c4bbdfSmrg    RRTellChanged (pScreen);
35235c4bbdfSmrg
35335c4bbdfSmrg    return Success;
35435c4bbdfSmrg}
35535c4bbdfSmrg
35635c4bbdfSmrgint
35735c4bbdfSmrgProcRRSetProviderOffloadSink(ClientPtr client)
35835c4bbdfSmrg{
35935c4bbdfSmrg    REQUEST(xRRSetProviderOffloadSinkReq);
36035c4bbdfSmrg    rrScrPrivPtr pScrPriv;
36135c4bbdfSmrg    RRProviderPtr provider, sink_provider = NULL;
36235c4bbdfSmrg    ScreenPtr pScreen;
36335c4bbdfSmrg
36435c4bbdfSmrg    REQUEST_SIZE_MATCH(xRRSetProviderOffloadSinkReq);
36535c4bbdfSmrg
36635c4bbdfSmrg    VERIFY_RR_PROVIDER(stuff->provider, provider, DixReadAccess);
36735c4bbdfSmrg    if (!(provider->capabilities & RR_Capability_SourceOffload))
36835c4bbdfSmrg        return BadValue;
36935c4bbdfSmrg    if (!provider->pScreen->isGPU)
37035c4bbdfSmrg        return BadValue;
37135c4bbdfSmrg
37235c4bbdfSmrg    if (stuff->sink_provider) {
37335c4bbdfSmrg        VERIFY_RR_PROVIDER(stuff->sink_provider, sink_provider, DixReadAccess);
37435c4bbdfSmrg        if (!(sink_provider->capabilities & RR_Capability_SinkOffload))
37535c4bbdfSmrg            return BadValue;
37635c4bbdfSmrg    }
37735c4bbdfSmrg    pScreen = provider->pScreen;
37835c4bbdfSmrg    pScrPriv = rrGetScrPriv(pScreen);
37935c4bbdfSmrg
38035c4bbdfSmrg    pScrPriv->rrProviderSetOffloadSink(pScreen, provider, sink_provider);
38135c4bbdfSmrg
38235c4bbdfSmrg    provider->changed = TRUE;
38335c4bbdfSmrg    RRSetChanged(pScreen);
38435c4bbdfSmrg
38535c4bbdfSmrg    RRTellChanged (pScreen);
38635c4bbdfSmrg
38735c4bbdfSmrg    return Success;
38835c4bbdfSmrg}
38935c4bbdfSmrg
39035c4bbdfSmrgRRProviderPtr
39135c4bbdfSmrgRRProviderCreate(ScreenPtr pScreen, const char *name,
39235c4bbdfSmrg                 int nameLength)
39335c4bbdfSmrg{
39435c4bbdfSmrg    RRProviderPtr provider;
39535c4bbdfSmrg    rrScrPrivPtr pScrPriv;
39635c4bbdfSmrg
39735c4bbdfSmrg    pScrPriv = rrGetScrPriv(pScreen);
39835c4bbdfSmrg
39935c4bbdfSmrg    provider = calloc(1, sizeof(RRProviderRec) + nameLength + 1);
40035c4bbdfSmrg    if (!provider)
40135c4bbdfSmrg        return NULL;
40235c4bbdfSmrg
40335c4bbdfSmrg    provider->id = FakeClientID(0);
40435c4bbdfSmrg    provider->pScreen = pScreen;
40535c4bbdfSmrg    provider->name = (char *) (provider + 1);
40635c4bbdfSmrg    provider->nameLength = nameLength;
40735c4bbdfSmrg    memcpy(provider->name, name, nameLength);
40835c4bbdfSmrg    provider->name[nameLength] = '\0';
40935c4bbdfSmrg    provider->changed = FALSE;
41035c4bbdfSmrg
41135c4bbdfSmrg    if (!AddResource (provider->id, RRProviderType, (void *) provider))
41235c4bbdfSmrg        return NULL;
41335c4bbdfSmrg    pScrPriv->provider = provider;
41435c4bbdfSmrg    return provider;
41535c4bbdfSmrg}
41635c4bbdfSmrg
41735c4bbdfSmrg/*
41835c4bbdfSmrg * Destroy a provider at shutdown
41935c4bbdfSmrg */
42035c4bbdfSmrgvoid
42135c4bbdfSmrgRRProviderDestroy (RRProviderPtr provider)
42235c4bbdfSmrg{
4231b5d61b8Smrg    RRFiniPrimeSyncProps(provider->pScreen);
42435c4bbdfSmrg    FreeResource (provider->id, 0);
42535c4bbdfSmrg}
42635c4bbdfSmrg
42735c4bbdfSmrgvoid
42835c4bbdfSmrgRRProviderSetCapabilities(RRProviderPtr provider, uint32_t capabilities)
42935c4bbdfSmrg{
43035c4bbdfSmrg    provider->capabilities = capabilities;
43135c4bbdfSmrg}
43235c4bbdfSmrg
43335c4bbdfSmrgstatic int
43435c4bbdfSmrgRRProviderDestroyResource (void *value, XID pid)
43535c4bbdfSmrg{
43635c4bbdfSmrg    RRProviderPtr provider = (RRProviderPtr)value;
43735c4bbdfSmrg    ScreenPtr pScreen = provider->pScreen;
43835c4bbdfSmrg
43935c4bbdfSmrg    if (pScreen)
44035c4bbdfSmrg    {
44135c4bbdfSmrg        rrScrPriv(pScreen);
44235c4bbdfSmrg
44335c4bbdfSmrg        if (pScrPriv->rrProviderDestroy)
44435c4bbdfSmrg            (*pScrPriv->rrProviderDestroy)(pScreen, provider);
44535c4bbdfSmrg        pScrPriv->provider = NULL;
44635c4bbdfSmrg    }
44735c4bbdfSmrg    free(provider);
44835c4bbdfSmrg    return 1;
44935c4bbdfSmrg}
45035c4bbdfSmrg
45135c4bbdfSmrgBool
45235c4bbdfSmrgRRProviderInit(void)
45335c4bbdfSmrg{
45435c4bbdfSmrg    RRProviderType = CreateNewResourceType(RRProviderDestroyResource, "Provider");
45535c4bbdfSmrg    if (!RRProviderType)
45635c4bbdfSmrg        return FALSE;
45735c4bbdfSmrg
45835c4bbdfSmrg    return TRUE;
45935c4bbdfSmrg}
46035c4bbdfSmrg
46135c4bbdfSmrgextern _X_EXPORT Bool
46235c4bbdfSmrgRRProviderLookup(XID id, RRProviderPtr *provider_p)
46335c4bbdfSmrg{
46435c4bbdfSmrg    int rc = dixLookupResourceByType((void **)provider_p, id,
46535c4bbdfSmrg                                   RRProviderType, NullClient, DixReadAccess);
46635c4bbdfSmrg    if (rc == Success)
46735c4bbdfSmrg        return TRUE;
46835c4bbdfSmrg    return FALSE;
46935c4bbdfSmrg}
47035c4bbdfSmrg
47135c4bbdfSmrgvoid
47235c4bbdfSmrgRRDeliverProviderEvent(ClientPtr client, WindowPtr pWin, RRProviderPtr provider)
47335c4bbdfSmrg{
47435c4bbdfSmrg    ScreenPtr pScreen = pWin->drawable.pScreen;
47535c4bbdfSmrg
47635c4bbdfSmrg    rrScrPriv(pScreen);
47735c4bbdfSmrg
47835c4bbdfSmrg    xRRProviderChangeNotifyEvent pe = {
47935c4bbdfSmrg        .type = RRNotify + RREventBase,
48035c4bbdfSmrg        .subCode = RRNotify_ProviderChange,
48135c4bbdfSmrg        .timestamp = pScrPriv->lastSetTime.milliseconds,
48235c4bbdfSmrg        .window = pWin->drawable.id,
48335c4bbdfSmrg        .provider = provider->id
48435c4bbdfSmrg    };
48535c4bbdfSmrg
48635c4bbdfSmrg    WriteEventsToClient(client, 1, (xEvent *) &pe);
48735c4bbdfSmrg}
488