layer.c 3.25 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 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
/*
 * Copyright 2017 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 "d2d1_private.h"

WINE_DEFAULT_DEBUG_CHANNEL(d2d);

static inline struct d2d_layer *impl_from_ID2D1Layer(ID2D1Layer *iface)
{
    return CONTAINING_RECORD(iface, struct d2d_layer, ID2D1Layer_iface);
}

static HRESULT STDMETHODCALLTYPE d2d_layer_QueryInterface(ID2D1Layer *iface, REFIID iid, void **out)
{
    TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);

    if (IsEqualGUID(iid, &IID_ID2D1Layer)
            || IsEqualGUID(iid, &IID_ID2D1Resource)
            || IsEqualGUID(iid, &IID_IUnknown))
    {
        ID2D1Layer_AddRef(iface);
        *out = iface;
        return S_OK;
    }

    WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));

    *out = NULL;
    return E_NOINTERFACE;
}

static ULONG STDMETHODCALLTYPE d2d_layer_AddRef(ID2D1Layer *iface)
{
    struct d2d_layer *layer = impl_from_ID2D1Layer(iface);
    ULONG refcount = InterlockedIncrement(&layer->refcount);

52
    TRACE("%p increasing refcount to %lu.\n", iface, refcount);
53 54 55 56 57 58 59 60 61

    return refcount;
}

static ULONG STDMETHODCALLTYPE d2d_layer_Release(ID2D1Layer *iface)
{
    struct d2d_layer *layer = impl_from_ID2D1Layer(iface);
    ULONG refcount = InterlockedDecrement(&layer->refcount);

62
    TRACE("%p decreasing refcount to %lu.\n", iface, refcount);
63 64 65 66

    if (!refcount)
    {
        ID2D1Factory_Release(layer->factory);
67
        free(layer);
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
    }

    return refcount;
}

static void STDMETHODCALLTYPE d2d_layer_GetFactory(ID2D1Layer *iface, ID2D1Factory **factory)
{
    struct d2d_layer *layer = impl_from_ID2D1Layer(iface);

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

    ID2D1Factory_AddRef(*factory = layer->factory);
}

static D2D1_SIZE_F * STDMETHODCALLTYPE d2d_layer_GetSize(ID2D1Layer *iface, D2D1_SIZE_F *size)
{
84 85 86
    struct d2d_layer *layer = impl_from_ID2D1Layer(iface);

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

88
    *size = layer->size;
89 90 91 92 93 94 95 96 97 98 99 100
    return size;
}

static const struct ID2D1LayerVtbl d2d_layer_vtbl =
{
    d2d_layer_QueryInterface,
    d2d_layer_AddRef,
    d2d_layer_Release,
    d2d_layer_GetFactory,
    d2d_layer_GetSize,
};

101
HRESULT d2d_layer_create(ID2D1Factory *factory, const D2D1_SIZE_F *size, struct d2d_layer **layer)
102
{
103
    if (!(*layer = calloc(1, sizeof(**layer))))
104 105 106 107 108
        return E_OUTOFMEMORY;

    (*layer)->ID2D1Layer_iface.lpVtbl = &d2d_layer_vtbl;
    (*layer)->refcount = 1;
    ID2D1Factory_AddRef((*layer)->factory = factory);
109 110
    if (size)
        (*layer)->size = *size;
111 112 113 114 115

    TRACE("Created layer %p.\n", *layer);

    return S_OK;
}