output.c 22.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * Copyright 2009 Henri Verbeet for CodeWeavers
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include "dxgi_private.h"

WINE_DEFAULT_DEBUG_CHANNEL(dxgi);

23 24 25 26 27
static inline DXGI_MODE_SCANLINE_ORDER dxgi_mode_scanline_order_from_wined3d(enum wined3d_scanline_ordering ordering)
{
    return (DXGI_MODE_SCANLINE_ORDER)ordering;
}

28 29 30 31 32
static inline DXGI_MODE_ROTATION dxgi_mode_rotation_from_wined3d(enum wined3d_display_rotation rotation)
{
    return (DXGI_MODE_ROTATION)rotation;
}

33 34 35 36 37 38 39
static void dxgi_mode_from_wined3d(DXGI_MODE_DESC *mode, const struct wined3d_display_mode *wined3d_mode)
{
    mode->Width = wined3d_mode->width;
    mode->Height = wined3d_mode->height;
    mode->RefreshRate.Numerator = wined3d_mode->refresh_rate;
    mode->RefreshRate.Denominator = 1;
    mode->Format = dxgi_format_from_wined3dformat(wined3d_mode->format_id);
40
    mode->ScanlineOrdering = dxgi_mode_scanline_order_from_wined3d(wined3d_mode->scanline_ordering);
41 42 43
    mode->Scaling = DXGI_MODE_SCALING_UNSPECIFIED; /* FIXME */
}

44 45 46 47 48 49 50
static void dxgi_mode1_from_wined3d(DXGI_MODE_DESC1 *mode, const struct wined3d_display_mode *wined3d_mode)
{
    mode->Width = wined3d_mode->width;
    mode->Height = wined3d_mode->height;
    mode->RefreshRate.Numerator = wined3d_mode->refresh_rate;
    mode->RefreshRate.Denominator = 1;
    mode->Format = dxgi_format_from_wined3dformat(wined3d_mode->format_id);
51
    mode->ScanlineOrdering = dxgi_mode_scanline_order_from_wined3d(wined3d_mode->scanline_ordering);
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
    mode->Scaling = DXGI_MODE_SCALING_UNSPECIFIED; /* FIXME */
    mode->Stereo = FALSE; /* FIXME */
}

static HRESULT dxgi_output_find_closest_matching_mode(struct dxgi_output *output,
        struct wined3d_display_mode *mode, IUnknown *device)
{
    HRESULT hr;

    if (!mode->width != !mode->height)
        return DXGI_ERROR_INVALID_CALL;

    if (mode->format_id == WINED3DFMT_UNKNOWN && !device)
        return DXGI_ERROR_INVALID_CALL;

    if (mode->format_id == WINED3DFMT_UNKNOWN)
    {
        FIXME("Matching formats to device not implemented.\n");
        return E_NOTIMPL;
    }

    wined3d_mutex_lock();
74
    hr = wined3d_output_find_closest_matching_mode(output->wined3d_output, mode);
75 76 77 78 79
    wined3d_mutex_unlock();

    return hr;
}

80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
static int dxgi_mode_desc_compare(const void *l, const void *r)
{
    const DXGI_MODE_DESC *left = l, *right = r;
    int a, b;

    if (left->Width != right->Width)
        return left->Width - right->Width;

    if (left->Height != right->Height)
        return left->Height - right->Height;

    a = left->RefreshRate.Numerator * right->RefreshRate.Denominator;
    b = right->RefreshRate.Numerator * left->RefreshRate.Denominator;
    if (a != b)
        return a - b;

    return 0;
}

99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
enum dxgi_mode_struct_version
{
    DXGI_MODE_STRUCT_VERSION_0,
    DXGI_MODE_STRUCT_VERSION_1,
};

static HRESULT dxgi_output_get_display_mode_list(struct dxgi_output *output,
        DXGI_FORMAT format, unsigned int *mode_count, void *modes,
        enum dxgi_mode_struct_version struct_version)
{
    enum wined3d_format_id wined3d_format;
    struct wined3d_display_mode mode;
    unsigned int i, max_count;
    HRESULT hr;

    if (!mode_count)
        return DXGI_ERROR_INVALID_CALL;

    if (format == DXGI_FORMAT_UNKNOWN)
    {
        *mode_count = 0;
        return S_OK;
    }

    wined3d_format = wined3dformat_from_dxgi_format(format);

    wined3d_mutex_lock();
126
    max_count = wined3d_output_get_mode_count(output->wined3d_output,
127
            wined3d_format, WINED3D_SCANLINE_ORDERING_UNKNOWN, false);
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145

    if (!modes)
    {
        wined3d_mutex_unlock();
        *mode_count = max_count;
        return S_OK;
    }

    if (max_count > *mode_count)
    {
        wined3d_mutex_unlock();
        return DXGI_ERROR_MORE_DATA;
    }

    *mode_count = max_count;

    for (i = 0; i < *mode_count; ++i)
    {
146
        if (FAILED(hr = wined3d_output_get_mode(output->wined3d_output, wined3d_format,
147
                WINED3D_SCANLINE_ORDERING_UNKNOWN, i, &mode, true)))
148
        {
149
            WARN("Failed to get output mode %u, hr %#lx.\n", i, hr);
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
            wined3d_mutex_unlock();
            return hr;
        }

        switch (struct_version)
        {
            case DXGI_MODE_STRUCT_VERSION_0:
            {
                DXGI_MODE_DESC *desc = modes;
                dxgi_mode_from_wined3d(&desc[i], &mode);
                break;
            }

            case DXGI_MODE_STRUCT_VERSION_1:
            {
                DXGI_MODE_DESC1 *desc = modes;
                dxgi_mode1_from_wined3d(&desc[i], &mode);
                break;
            }
        }
    }
    wined3d_mutex_unlock();

173 174 175 176 177 178 179 180 181 182
    switch (struct_version)
    {
        case DXGI_MODE_STRUCT_VERSION_0:
            qsort(modes, *mode_count, sizeof(DXGI_MODE_DESC), dxgi_mode_desc_compare);
            break;
        case DXGI_MODE_STRUCT_VERSION_1:
            qsort(modes, *mode_count, sizeof(DXGI_MODE_DESC1), dxgi_mode_desc_compare);
            break;
    }

183 184 185
    return S_OK;
}

186
static inline struct dxgi_output *impl_from_IDXGIOutput6(IDXGIOutput6 *iface)
187
{
188
    return CONTAINING_RECORD(iface, struct dxgi_output, IDXGIOutput6_iface);
189 190
}

191 192
/* IUnknown methods */

193
static HRESULT STDMETHODCALLTYPE dxgi_output_QueryInterface(IDXGIOutput6 *iface, REFIID iid, void **object)
194
{
195 196
    TRACE("iface %p, iid %s, object %p.\n", iface, debugstr_guid(iid), object);

197 198 199
    if (IsEqualGUID(iid, &IID_IDXGIOutput6)
            || IsEqualGUID(iid, &IID_IDXGIOutput5)
            || IsEqualGUID(iid, &IID_IDXGIOutput4)
200 201 202 203 204 205
            || IsEqualGUID(iid, &IID_IDXGIOutput3)
            || IsEqualGUID(iid, &IID_IDXGIOutput2)
            || IsEqualGUID(iid, &IID_IDXGIOutput1)
            || IsEqualGUID(iid, &IID_IDXGIOutput)
            || IsEqualGUID(iid, &IID_IDXGIObject)
            || IsEqualGUID(iid, &IID_IUnknown))
206 207 208 209 210 211
    {
        IUnknown_AddRef(iface);
        *object = iface;
        return S_OK;
    }

212
    WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
213 214 215 216 217

    *object = NULL;
    return E_NOINTERFACE;
}

218
static ULONG STDMETHODCALLTYPE dxgi_output_AddRef(IDXGIOutput6 *iface)
219
{
220
    struct dxgi_output *output = impl_from_IDXGIOutput6(iface);
221
    ULONG refcount = InterlockedIncrement(&output->refcount);
222

223
    TRACE("%p increasing refcount to %lu.\n", output, refcount);
224 225 226 227

    return refcount;
}

228
static ULONG STDMETHODCALLTYPE dxgi_output_Release(IDXGIOutput6 *iface)
229
{
230
    struct dxgi_output *output = impl_from_IDXGIOutput6(iface);
231
    ULONG refcount = InterlockedDecrement(&output->refcount);
232

233
    TRACE("%p decreasing refcount to %lu.\n", output, refcount);
234 235 236

    if (!refcount)
    {
237
        wined3d_private_store_cleanup(&output->private_store);
238
        IWineDXGIAdapter_Release(&output->adapter->IWineDXGIAdapter_iface);
239
        heap_free(output);
240 241 242 243 244 245 246
    }

    return refcount;
}

/* IDXGIObject methods */

247
static HRESULT STDMETHODCALLTYPE dxgi_output_SetPrivateData(IDXGIOutput6 *iface,
248 249
        REFGUID guid, UINT data_size, const void *data)
{
250
    struct dxgi_output *output = impl_from_IDXGIOutput6(iface);
251

252 253 254
    TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);

    return dxgi_set_private_data(&output->private_store, guid, data_size, data);
255 256
}

257
static HRESULT STDMETHODCALLTYPE dxgi_output_SetPrivateDataInterface(IDXGIOutput6 *iface,
258 259
        REFGUID guid, const IUnknown *object)
{
260
    struct dxgi_output *output = impl_from_IDXGIOutput6(iface);
261

262 263 264
    TRACE("iface %p, guid %s, object %p.\n", iface, debugstr_guid(guid), object);

    return dxgi_set_private_data_interface(&output->private_store, guid, object);
265 266
}

267
static HRESULT STDMETHODCALLTYPE dxgi_output_GetPrivateData(IDXGIOutput6 *iface,
268 269
        REFGUID guid, UINT *data_size, void *data)
{
270
    struct dxgi_output *output = impl_from_IDXGIOutput6(iface);
271

272 273 274
    TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);

    return dxgi_get_private_data(&output->private_store, guid, data_size, data);
275 276
}

277
static HRESULT STDMETHODCALLTYPE dxgi_output_GetParent(IDXGIOutput6 *iface,
278 279
        REFIID riid, void **parent)
{
280
    struct dxgi_output *output = impl_from_IDXGIOutput6(iface);
281

282 283
    TRACE("iface %p, riid %s, parent %p.\n", iface, debugstr_guid(riid), parent);

284
    return IWineDXGIAdapter_QueryInterface(&output->adapter->IWineDXGIAdapter_iface, riid, parent);
285 286 287 288
}

/* IDXGIOutput methods */

289
static HRESULT STDMETHODCALLTYPE dxgi_output_GetDesc(IDXGIOutput6 *iface, DXGI_OUTPUT_DESC *desc)
290
{
291
    struct dxgi_output *output = impl_from_IDXGIOutput6(iface);
292
    struct wined3d_output_desc wined3d_desc;
293 294
    enum wined3d_display_rotation rotation;
    struct wined3d_display_mode mode;
295 296 297 298 299 300 301 302
    HRESULT hr;

    TRACE("iface %p, desc %p.\n", iface, desc);

    if (!desc)
        return E_INVALIDARG;

    wined3d_mutex_lock();
303
    hr = wined3d_output_get_desc(output->wined3d_output, &wined3d_desc);
304 305
    if (FAILED(hr))
    {
306
        WARN("Failed to get output desc, hr %#lx.\n", hr);
307 308 309 310 311 312 313
        wined3d_mutex_unlock();
        return hr;
    }

    hr = wined3d_output_get_display_mode(output->wined3d_output, &mode, &rotation);
    if (FAILED(hr))
    {
314
        WARN("Failed to get output display mode, hr %#lx.\n", hr);
315
        wined3d_mutex_unlock();
316 317
        return hr;
    }
318
    wined3d_mutex_unlock();
319 320 321 322

    memcpy(desc->DeviceName, wined3d_desc.device_name, sizeof(desc->DeviceName));
    desc->DesktopCoordinates = wined3d_desc.desktop_rect;
    desc->AttachedToDesktop = wined3d_desc.attached_to_desktop;
323
    desc->Rotation = dxgi_mode_rotation_from_wined3d(rotation);
324
    desc->Monitor = wined3d_desc.monitor;
325

326
    return S_OK;
327 328
}

329
static HRESULT STDMETHODCALLTYPE dxgi_output_GetDisplayModeList(IDXGIOutput6 *iface,
330
        DXGI_FORMAT format, UINT flags, UINT *mode_count, DXGI_MODE_DESC *modes)
331
{
332
    struct dxgi_output *output = impl_from_IDXGIOutput6(iface);
333

334 335
    FIXME("iface %p, format %s, flags %#x, mode_count %p, modes %p partial stub!\n",
            iface, debug_dxgi_format(format), flags, mode_count, modes);
336

337 338
    return dxgi_output_get_display_mode_list(output,
            format, mode_count, modes, DXGI_MODE_STRUCT_VERSION_0);
339 340
}

341
static HRESULT STDMETHODCALLTYPE dxgi_output_FindClosestMatchingMode(IDXGIOutput6 *iface,
342 343
        const DXGI_MODE_DESC *mode, DXGI_MODE_DESC *closest_match, IUnknown *device)
{
344
    struct dxgi_output *output = impl_from_IDXGIOutput6(iface);
345 346 347
    struct wined3d_display_mode wined3d_mode;
    HRESULT hr;

348 349 350 351
    TRACE("iface %p, mode %p, closest_match %p, device %p.\n",
            iface, mode, closest_match, device);

    TRACE("Mode: %s.\n", debug_dxgi_mode(mode));
352 353

    wined3d_display_mode_from_dxgi(&wined3d_mode, mode);
354
    hr = dxgi_output_find_closest_matching_mode(output, &wined3d_mode, device);
355 356 357 358 359
    if (SUCCEEDED(hr))
    {
        dxgi_mode_from_wined3d(closest_match, &wined3d_mode);
        TRACE("Returning %s.\n", debug_dxgi_mode(closest_match));
    }
360

361
    return hr;
362 363
}

364
static HRESULT STDMETHODCALLTYPE dxgi_output_WaitForVBlank(IDXGIOutput6 *iface)
365
{
366 367 368 369 370 371
    static BOOL once = FALSE;

    if (!once++)
        FIXME("iface %p stub!\n", iface);
    else
        TRACE("iface %p stub!\n", iface);
372 373 374 375

    return E_NOTIMPL;
}

376
static HRESULT STDMETHODCALLTYPE dxgi_output_TakeOwnership(IDXGIOutput6 *iface, IUnknown *device, BOOL exclusive)
377
{
378
    struct dxgi_output *output = impl_from_IDXGIOutput6(iface);
379
    HRESULT hr;
380

381 382 383 384 385 386
    TRACE("iface %p, device %p, exclusive %d.\n", iface, device, exclusive);

    if (!device)
        return DXGI_ERROR_INVALID_CALL;

    wined3d_mutex_lock();
387
    hr = wined3d_output_take_ownership(output->wined3d_output, exclusive);
388 389 390
    wined3d_mutex_unlock();

    return hr;
391 392
}

393
static void STDMETHODCALLTYPE dxgi_output_ReleaseOwnership(IDXGIOutput6 *iface)
394
{
395
    struct dxgi_output *output = impl_from_IDXGIOutput6(iface);
396 397 398 399

    TRACE("iface %p.\n", iface);

    wined3d_mutex_lock();
400
    wined3d_output_release_ownership(output->wined3d_output);
401
    wined3d_mutex_unlock();
402 403
}

404
static HRESULT STDMETHODCALLTYPE dxgi_output_GetGammaControlCapabilities(IDXGIOutput6 *iface,
405 406
        DXGI_GAMMA_CONTROL_CAPABILITIES *gamma_caps)
{
407
    unsigned int i;
408

409 410 411 412 413 414 415 416 417 418 419 420 421 422
    TRACE("iface %p, gamma_caps %p.\n", iface, gamma_caps);

    if (!gamma_caps)
        return E_INVALIDARG;

    gamma_caps->ScaleAndOffsetSupported = FALSE;
    gamma_caps->MaxConvertedValue = 1.0f;
    gamma_caps->MinConvertedValue = 0.0f;
    gamma_caps->NumGammaControlPoints = 256;

    for (i = 0; i < gamma_caps->NumGammaControlPoints; ++i)
        gamma_caps->ControlPointPositions[i] = i / 255.0f;

    return S_OK;
423 424
}

425 426 427 428 429 430 431 432 433 434 435
static WORD uint16_from_float(float f)
{
    f *= 65535.0f;
    if (f < 0.0f)
        f = 0.0f;
    else if (f > 65535.0f)
        f = 65535.0f;

    return f + 0.5f;
}

436
static HRESULT STDMETHODCALLTYPE dxgi_output_SetGammaControl(IDXGIOutput6 *iface,
437 438
        const DXGI_GAMMA_CONTROL *gamma_control)
{
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463
    struct dxgi_output *output = impl_from_IDXGIOutput6(iface);
    struct wined3d_gamma_ramp ramp;
    const DXGI_RGB *p;
    unsigned int i;

    TRACE("iface %p, gamma_control %p.\n", iface, gamma_control);

    if (gamma_control->Scale.Red != 1.0f || gamma_control->Scale.Green != 1.0f || gamma_control->Scale.Blue != 1.0f)
        FIXME("Ignoring unhandled scale {%.8e, %.8e, %.8e}.\n", gamma_control->Scale.Red,
                gamma_control->Scale.Green, gamma_control->Scale.Blue);
    if (gamma_control->Offset.Red != 0.0f || gamma_control->Offset.Green != 0.0f || gamma_control->Offset.Blue != 0.0f)
        FIXME("Ignoring unhandled offset {%.8e, %.8e, %.8e}.\n", gamma_control->Offset.Red,
                gamma_control->Offset.Green, gamma_control->Offset.Blue);

    for (i = 0; i < 256; ++i)
    {
        p = &gamma_control->GammaCurve[i];
        ramp.red[i] = uint16_from_float(p->Red);
        ramp.green[i] = uint16_from_float(p->Green);
        ramp.blue[i] = uint16_from_float(p->Blue);
    }

    wined3d_mutex_lock();
    wined3d_output_set_gamma_ramp(output->wined3d_output, &ramp);
    wined3d_mutex_unlock();
464

465
    return S_OK;
466 467
}

468
static HRESULT STDMETHODCALLTYPE dxgi_output_GetGammaControl(IDXGIOutput6 *iface,
469
        DXGI_GAMMA_CONTROL *gamma_control)
470 471 472 473 474 475
{
    FIXME("iface %p, gamma_control %p stub!\n", iface, gamma_control);

    return E_NOTIMPL;
}

476
static HRESULT STDMETHODCALLTYPE dxgi_output_SetDisplaySurface(IDXGIOutput6 *iface, IDXGISurface *surface)
477 478 479 480 481 482
{
    FIXME("iface %p, surface %p stub!\n", iface, surface);

    return E_NOTIMPL;
}

483
static HRESULT STDMETHODCALLTYPE dxgi_output_GetDisplaySurfaceData(IDXGIOutput6 *iface, IDXGISurface *surface)
484 485 486 487 488 489
{
    FIXME("iface %p, surface %p stub!\n", iface, surface);

    return E_NOTIMPL;
}

490
static HRESULT STDMETHODCALLTYPE dxgi_output_GetFrameStatistics(IDXGIOutput6 *iface, DXGI_FRAME_STATISTICS *stats)
491 492 493 494 495 496
{
    FIXME("iface %p, stats %p stub!\n", iface, stats);

    return E_NOTIMPL;
}

497 498
/* IDXGIOutput1 methods */

499
static HRESULT STDMETHODCALLTYPE dxgi_output_GetDisplayModeList1(IDXGIOutput6 *iface,
500 501
        DXGI_FORMAT format, UINT flags, UINT *mode_count, DXGI_MODE_DESC1 *modes)
{
502
    struct dxgi_output *output = impl_from_IDXGIOutput6(iface);
503

504 505 506 507 508
    FIXME("iface %p, format %s, flags %#x, mode_count %p, modes %p partial stub!\n",
            iface, debug_dxgi_format(format), flags, mode_count, modes);

    return dxgi_output_get_display_mode_list(output,
            format, mode_count, modes, DXGI_MODE_STRUCT_VERSION_1);
509 510
}

511
static HRESULT STDMETHODCALLTYPE dxgi_output_FindClosestMatchingMode1(IDXGIOutput6 *iface,
512 513
        const DXGI_MODE_DESC1 *mode, DXGI_MODE_DESC1 *closest_match, IUnknown *device)
{
514
    struct dxgi_output *output = impl_from_IDXGIOutput6(iface);
515 516
    struct wined3d_display_mode wined3d_mode;
    HRESULT hr;
517

518 519 520 521
    TRACE("iface %p, mode %p, closest_match %p, device %p.\n",
            iface, mode, closest_match, device);

    TRACE("Mode: %s.\n", debug_dxgi_mode1(mode));
522 523 524 525 526 527 528 529 530 531

    wined3d_display_mode_from_dxgi1(&wined3d_mode, mode);
    hr = dxgi_output_find_closest_matching_mode(output, &wined3d_mode, device);
    if (SUCCEEDED(hr))
    {
        dxgi_mode1_from_wined3d(closest_match, &wined3d_mode);
        TRACE("Returning %s.\n", debug_dxgi_mode1(closest_match));
    }

    return hr;
532 533
}

534
static HRESULT STDMETHODCALLTYPE dxgi_output_GetDisplaySurfaceData1(IDXGIOutput6 *iface,
535 536 537 538 539 540 541
        IDXGIResource *resource)
{
    FIXME("iface %p, resource %p stub!\n", iface, resource);

    return E_NOTIMPL;
}

542
static HRESULT STDMETHODCALLTYPE dxgi_output_DuplicateOutput(IDXGIOutput6 *iface,
543 544 545 546 547 548 549 550 551
        IUnknown *device, IDXGIOutputDuplication **output_duplication)
{
    FIXME("iface %p, device %p, output_duplication %p stub!\n", iface, device, output_duplication);

    return E_NOTIMPL;
}

/* IDXGIOutput2 methods */

552
static BOOL STDMETHODCALLTYPE dxgi_output_SupportsOverlays(IDXGIOutput6 *iface)
553 554 555 556 557 558 559 560
{
    FIXME("iface %p stub!\n", iface);

    return FALSE;
}

/* IDXGIOutput3 methods */

561
static HRESULT STDMETHODCALLTYPE dxgi_output_CheckOverlaySupport(IDXGIOutput6 *iface,
562 563 564 565 566 567 568 569 570
        DXGI_FORMAT format, IUnknown *device, UINT *flags)
{
    FIXME("iface %p, format %#x, device %p, flags %p stub!\n", iface, format, device, flags);

    return E_NOTIMPL;
}

/* IDXGIOutput4 methods */

571
static HRESULT STDMETHODCALLTYPE dxgi_output_CheckOverlayColorSpaceSupport(IDXGIOutput6 *iface,
572 573 574 575 576 577 578 579
        DXGI_FORMAT format, DXGI_COLOR_SPACE_TYPE color_space, IUnknown *device, UINT *flags)
{
    FIXME("iface %p, format %#x, color_space %#x, device %p, flags %p stub!\n",
            iface, format, color_space, device, flags);

    return E_NOTIMPL;
}

580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599
/* IDXGIOutput5 methods */

static HRESULT STDMETHODCALLTYPE dxgi_output_DuplicateOutput1(IDXGIOutput6 *iface,
        IUnknown *device, UINT flags, UINT format_count, const DXGI_FORMAT *formats,
        IDXGIOutputDuplication **output_duplication)
{
    FIXME("iface %p, device %p, flags %#x, format_count %u, formats %p, "
            "output_duplication %p stub!\n", iface, device, flags, format_count,
            formats, output_duplication);

    return E_NOTIMPL;
}

/* IDXGIOutput6 methods */

static HRESULT STDMETHODCALLTYPE dxgi_output_GetDesc1(IDXGIOutput6 *iface,
        DXGI_OUTPUT_DESC1 *desc)
{
    struct dxgi_output *output = impl_from_IDXGIOutput6(iface);
    struct wined3d_output_desc wined3d_desc;
600 601
    enum wined3d_display_rotation rotation;
    struct wined3d_display_mode mode;
602 603 604 605 606 607 608 609 610
    HRESULT hr;

    FIXME("iface %p, desc %p semi-stub!\n", iface, desc);

    if (!desc)
        return E_INVALIDARG;

    wined3d_mutex_lock();
    hr = wined3d_output_get_desc(output->wined3d_output, &wined3d_desc);
611 612
    if (FAILED(hr))
    {
613
        WARN("Failed to get output desc, hr %#lx.\n", hr);
614 615 616 617 618 619 620
        wined3d_mutex_unlock();
        return hr;
    }

    hr = wined3d_output_get_display_mode(output->wined3d_output, &mode, &rotation);
    if (FAILED(hr))
    {
621
        WARN("Failed to get output display mode, hr %#lx.\n", hr);
622 623 624
        wined3d_mutex_unlock();
        return hr;
    }
625 626 627 628
    wined3d_mutex_unlock();

    if (FAILED(hr))
    {
629
        WARN("Failed to get output desc, hr %#lx.\n", hr);
630 631 632 633 634 635
        return hr;
    }

    memcpy(desc->DeviceName, wined3d_desc.device_name, sizeof(desc->DeviceName));
    desc->DesktopCoordinates = wined3d_desc.desktop_rect;
    desc->AttachedToDesktop = wined3d_desc.attached_to_desktop;
636
    desc->Rotation = dxgi_mode_rotation_from_wined3d(rotation);
637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665
    desc->Monitor = wined3d_desc.monitor;

    /* FIXME: fill this from monitor EDID */
    desc->BitsPerColor = 0;
    desc->ColorSpace = DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709;
    desc->RedPrimary[0] = 0.f;
    desc->RedPrimary[1] = 0.f;
    desc->GreenPrimary[0] = 0.f;
    desc->GreenPrimary[1] = 0.f;
    desc->BluePrimary[0] = 0.f;
    desc->BluePrimary[1] = 0.f;
    desc->WhitePoint[0] = 0.f;
    desc->WhitePoint[1] = 0.f;
    desc->MinLuminance = 0.f;
    desc->MaxLuminance = 0.f;
    desc->MaxFullFrameLuminance = 0.f;

    return S_OK;
}

static HRESULT STDMETHODCALLTYPE dxgi_output_CheckHardwareCompositionSupport(IDXGIOutput6 *iface,
        UINT *flags)
{
    FIXME("iface %p, flags %p stub!\n", iface, flags);

    return E_NOTIMPL;
}

static const struct IDXGIOutput6Vtbl dxgi_output_vtbl =
666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687
{
    dxgi_output_QueryInterface,
    dxgi_output_AddRef,
    dxgi_output_Release,
    /* IDXGIObject methods */
    dxgi_output_SetPrivateData,
    dxgi_output_SetPrivateDataInterface,
    dxgi_output_GetPrivateData,
    dxgi_output_GetParent,
    /* IDXGIOutput methods */
    dxgi_output_GetDesc,
    dxgi_output_GetDisplayModeList,
    dxgi_output_FindClosestMatchingMode,
    dxgi_output_WaitForVBlank,
    dxgi_output_TakeOwnership,
    dxgi_output_ReleaseOwnership,
    dxgi_output_GetGammaControlCapabilities,
    dxgi_output_SetGammaControl,
    dxgi_output_GetGammaControl,
    dxgi_output_SetDisplaySurface,
    dxgi_output_GetDisplaySurfaceData,
    dxgi_output_GetFrameStatistics,
688 689 690 691 692 693 694 695 696 697 698
    /* IDXGIOutput1 methods */
    dxgi_output_GetDisplayModeList1,
    dxgi_output_FindClosestMatchingMode1,
    dxgi_output_GetDisplaySurfaceData1,
    dxgi_output_DuplicateOutput,
    /* IDXGIOutput2 methods */
    dxgi_output_SupportsOverlays,
    /* IDXGIOutput3 methods */
    dxgi_output_CheckOverlaySupport,
    /* IDXGIOutput4 methods */
    dxgi_output_CheckOverlayColorSpaceSupport,
699 700 701 702 703
    /* IDXGIOutput5 methods */
    dxgi_output_DuplicateOutput1,
    /* IDXGIOutput6 methods */
    dxgi_output_GetDesc1,
    dxgi_output_CheckHardwareCompositionSupport,
704 705
};

706 707 708 709 710
struct dxgi_output *unsafe_impl_from_IDXGIOutput(IDXGIOutput *iface)
{
    if (!iface)
        return NULL;
    assert(iface->lpVtbl == (IDXGIOutputVtbl *)&dxgi_output_vtbl);
711
    return CONTAINING_RECORD(iface, struct dxgi_output, IDXGIOutput6_iface);
712 713
}

714 715
static void dxgi_output_init(struct dxgi_output *output, unsigned int output_idx,
        struct dxgi_adapter *adapter)
716
{
717
    output->IDXGIOutput6_iface.lpVtbl = &dxgi_output_vtbl;
718
    output->refcount = 1;
719
    output->wined3d_output = wined3d_adapter_get_output(adapter->wined3d_adapter, output_idx);
720
    wined3d_private_store_init(&output->private_store);
721
    output->adapter = adapter;
722
    IWineDXGIAdapter_AddRef(&output->adapter->IWineDXGIAdapter_iface);
723 724
}

725 726
HRESULT dxgi_output_create(struct dxgi_adapter *adapter, unsigned int output_idx,
        struct dxgi_output **output)
727
{
728
    if (!(*output = heap_alloc_zero(sizeof(**output))))
729 730
        return E_OUTOFMEMORY;

731
    dxgi_output_init(*output, output_idx, adapter);
732
    return S_OK;
733
}