d2d1: Implement d2d_d3d_render_target_CreateLayer().

Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Henri Verbeet 2017-06-02 17:56:31 +02:00 committed by Alexandre Julliard
parent b332c1a6d5
commit 6d638b9e28
5 changed files with 180 additions and 2 deletions

View File

@ -11,6 +11,7 @@ C_SRCS = \
factory.c \
geometry.c \
hwnd_render_target.c \
layer.c \
mesh.c \
render_target.c \
state_block.c \

View File

@ -236,6 +236,16 @@ struct d2d_stroke_style
HRESULT d2d_stroke_style_init(struct d2d_stroke_style *style, ID2D1Factory *factory,
const D2D1_STROKE_STYLE_PROPERTIES *desc, const float *dashes, UINT32 dash_count) DECLSPEC_HIDDEN;
struct d2d_layer
{
ID2D1Layer ID2D1Layer_iface;
LONG refcount;
ID2D1Factory *factory;
};
HRESULT d2d_layer_create(ID2D1Factory *factory, struct d2d_layer **layer) DECLSPEC_HIDDEN;
struct d2d_mesh
{
ID2D1Mesh ID2D1Mesh_iface;

115
dlls/d2d1/layer.c Normal file
View File

@ -0,0 +1,115 @@
/*
* 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 "config.h"
#include "wine/port.h"
#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);
TRACE("%p increasing refcount to %u.\n", iface, refcount);
return refcount;
}
static ULONG STDMETHODCALLTYPE d2d_layer_Release(ID2D1Layer *iface)
{
struct d2d_layer *layer = impl_from_ID2D1Layer(iface);
ULONG refcount = InterlockedDecrement(&layer->refcount);
TRACE("%p decreasing refcount to %u.\n", iface, refcount);
if (!refcount)
{
ID2D1Factory_Release(layer->factory);
HeapFree(GetProcessHeap(), 0, layer);
}
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)
{
FIXME("iface %p, size %p stub!\n", iface, size);
size->width = 0;
size->height = 0;
return size;
}
static const struct ID2D1LayerVtbl d2d_layer_vtbl =
{
d2d_layer_QueryInterface,
d2d_layer_AddRef,
d2d_layer_Release,
d2d_layer_GetFactory,
d2d_layer_GetSize,
};
HRESULT d2d_layer_create(ID2D1Factory *factory, struct d2d_layer **layer)
{
if (!(*layer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(**layer))))
return E_OUTOFMEMORY;
(*layer)->ID2D1Layer_iface.lpVtbl = &d2d_layer_vtbl;
(*layer)->refcount = 1;
ID2D1Factory_AddRef((*layer)->factory = factory);
TRACE("Created layer %p.\n", *layer);
return S_OK;
}

View File

@ -458,9 +458,16 @@ static HRESULT STDMETHODCALLTYPE d2d_d3d_render_target_CreateCompatibleRenderTar
static HRESULT STDMETHODCALLTYPE d2d_d3d_render_target_CreateLayer(ID2D1RenderTarget *iface,
const D2D1_SIZE_F *size, ID2D1Layer **layer)
{
FIXME("iface %p, size %p, layer %p stub!\n", iface, size, layer);
struct d2d_d3d_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
struct d2d_layer *object;
HRESULT hr;
return E_NOTIMPL;
TRACE("iface %p, size %p, layer %p.\n", iface, size, layer);
if (SUCCEEDED(hr = d2d_layer_create(render_target->factory, &object)))
*layer = &object->ID2D1Layer_iface;
return hr;
}
static HRESULT STDMETHODCALLTYPE d2d_d3d_render_target_CreateMesh(ID2D1RenderTarget *iface, ID2D1Mesh **mesh)

View File

@ -4528,6 +4528,50 @@ todo_wine
ID2D1Factory_Release(factory);
}
static void test_layer(void)
{
ID2D1Factory *factory, *layer_factory;
IDXGISwapChain *swapchain;
ID2D1RenderTarget *rt;
ID3D10Device1 *device;
IDXGISurface *surface;
ID2D1Layer *layer;
ULONG refcount;
HWND window;
HRESULT hr;
if (!(device = create_device()))
{
skip("Failed to create device, skipping tests.\n");
return;
}
window = create_window();
swapchain = create_swapchain(device, window, TRUE);
hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_IDXGISurface, (void **)&surface);
ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
rt = create_render_target(surface);
ok(!!rt, "Failed to create render target.\n");
ID2D1RenderTarget_GetFactory(rt, &factory);
ID2D1RenderTarget_SetDpi(rt, 192.0f, 48.0f);
ID2D1RenderTarget_SetAntialiasMode(rt, D2D1_ANTIALIAS_MODE_ALIASED);
hr = ID2D1RenderTarget_CreateLayer(rt, NULL, &layer);
ok(SUCCEEDED(hr), "Failed to create layer, hr %#x.\n", hr);
ID2D1Layer_GetFactory(layer, &layer_factory);
ok(layer_factory == factory, "Got unexpected layer factory %p, expected %p.\n", layer_factory, factory);
ID2D1Factory_Release(layer_factory);
ID2D1Layer_Release(layer);
ID2D1RenderTarget_Release(rt);
refcount = ID2D1Factory_Release(factory);
ok(!refcount, "Factory has %u references left.\n", refcount);
IDXGISurface_Release(surface);
IDXGISwapChain_Release(swapchain);
ID3D10Device1_Release(device);
DestroyWindow(window);
}
START_TEST(d2d1)
{
test_clip();
@ -4552,4 +4596,5 @@ START_TEST(d2d1)
test_gradient();
test_draw_geometry();
test_gdi_interop();
test_layer();
}