ReactOS 0.4.17-dev-934-g091855f
wic_render_target.c File Reference
#include "d2d1_private.h"
#include "initguid.h"
#include "wincodec.h"
Include dependency graph for wic_render_target.c:

Go to the source code of this file.

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (d2d)
 
static struct d2d_wic_render_target * impl_from_IUnknown (IUnknown *iface)
 
static HRESULT d2d_wic_render_target_present (IUnknown *outer_unknown)
 
static HRESULT STDMETHODCALLTYPE d2d_wic_render_target_QueryInterface (IUnknown *iface, REFIID iid, void **out)
 
static ULONG STDMETHODCALLTYPE d2d_wic_render_target_AddRef (IUnknown *iface)
 
static ULONG STDMETHODCALLTYPE d2d_wic_render_target_Release (IUnknown *iface)
 
HRESULT d2d_wic_render_target_init (struct d2d_wic_render_target *render_target, ID2D1Factory1 *factory, ID3D10Device1 *d3d_device, IWICBitmap *bitmap, const D2D1_RENDER_TARGET_PROPERTIES *desc)
 

Variables

static const struct IUnknownVtbl d2d_wic_render_target_vtbl
 
static const struct d2d_device_context_ops d2d_wic_render_target_ops
 

Function Documentation

◆ d2d_wic_render_target_AddRef()

static ULONG STDMETHODCALLTYPE d2d_wic_render_target_AddRef ( IUnknown *  iface)
static

Definition at line 111 of file wic_render_target.c.

112{
113 struct d2d_wic_render_target *render_target = impl_from_IUnknown(iface);
114 ULONG refcount = InterlockedIncrement(&render_target->refcount);
115
116 TRACE("%p increasing refcount to %lu.\n", iface, refcount);
117
118 return refcount;
119}
#define InterlockedIncrement
Definition: armddk.h:53
#define TRACE(s)
Definition: solgame.cpp:4
uint32_t ULONG
Definition: typedefs.h:59
static struct d2d_wic_render_target * impl_from_IUnknown(IUnknown *iface)

◆ d2d_wic_render_target_init()

HRESULT d2d_wic_render_target_init ( struct d2d_wic_render_target *  render_target,
ID2D1Factory1 *  factory,
ID3D10Device1 *  d3d_device,
IWICBitmap *  bitmap,
const D2D1_RENDER_TARGET_PROPERTIES *  desc 
)

Definition at line 152 of file wic_render_target.c.

154{
155 D3D10_TEXTURE2D_DESC texture_desc;
157 IDXGIDevice *dxgi_device;
159 HRESULT hr;
160
161 render_target->IUnknown_iface.lpVtbl = &d2d_wic_render_target_vtbl;
162
163 if (FAILED(hr = IWICBitmap_GetSize(bitmap, &render_target->width, &render_target->height)))
164 {
165 WARN("Failed to get bitmap dimensions, hr %#lx.\n", hr);
166 return hr;
167 }
168
169 texture_desc.Width = render_target->width;
170 texture_desc.Height = render_target->height;
171 texture_desc.MipLevels = 1;
172 texture_desc.ArraySize = 1;
173
174 texture_desc.Format = desc->pixelFormat.format;
175 if (texture_desc.Format == DXGI_FORMAT_UNKNOWN)
176 {
177 WICPixelFormatGUID bitmap_format;
178
179 if (FAILED(hr = IWICBitmap_GetPixelFormat(bitmap, &bitmap_format)))
180 {
181 WARN("Failed to get bitmap format, hr %#lx.\n", hr);
182 return hr;
183 }
184
185 if (IsEqualGUID(&bitmap_format, &GUID_WICPixelFormat32bppPBGRA)
186 || IsEqualGUID(&bitmap_format, &GUID_WICPixelFormat32bppBGR))
187 {
188 texture_desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
189 }
190 else if (IsEqualGUID(&bitmap_format, &GUID_WICPixelFormat32bppPRGBA)
191 || IsEqualGUID(&bitmap_format, &GUID_WICPixelFormat32bppRGB))
192 {
193 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
194 }
195 else
196 {
197 WARN("Unsupported WIC bitmap format %s.\n", debugstr_guid(&bitmap_format));
199 }
200 }
201
202 switch (texture_desc.Format)
203 {
206 render_target->bpp = 4;
207 break;
208
209 default:
210 FIXME("Unhandled format %#x.\n", texture_desc.Format);
212 }
213
214 texture_desc.SampleDesc.Count = 1;
215 texture_desc.SampleDesc.Quality = 0;
216 texture_desc.Usage = D3D10_USAGE_DEFAULT;
218 texture_desc.CPUAccessFlags = 0;
221
222 if (FAILED(hr = ID3D10Device1_CreateTexture2D(d3d_device, &texture_desc, NULL, &texture)))
223 {
224 WARN("Failed to create texture, hr %#lx.\n", hr);
225 return hr;
226 }
227
228 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&render_target->dxgi_surface);
229 ID3D10Texture2D_Release(texture);
230 if (FAILED(hr))
231 {
232 WARN("Failed to get DXGI surface interface, hr %#lx.\n", hr);
233 return hr;
234 }
235
236 texture_desc.Usage = D3D10_USAGE_STAGING;
237 texture_desc.BindFlags = 0;
239 texture_desc.MiscFlags = 0;
240
241 if (FAILED(hr = ID3D10Device1_CreateTexture2D(d3d_device, &texture_desc, NULL, &render_target->readback_texture)))
242 {
243 WARN("Failed to create readback texture, hr %#lx.\n", hr);
244 IDXGISurface_Release(render_target->dxgi_surface);
245 return hr;
246 }
247
248 if (FAILED(hr = ID3D10Device1_QueryInterface(d3d_device, &IID_IDXGIDevice, (void **)&dxgi_device)))
249 {
250 WARN("Failed to get DXGI device, hr %#lx.\n", hr);
251 IDXGISurface_Release(render_target->dxgi_surface);
252 return hr;
253 }
254
255 hr = d2d_factory_create_device(factory, dxgi_device, false, &IID_ID2D1Device, (void **)&device);
256 IDXGIDevice_Release(dxgi_device);
257 if (FAILED(hr))
258 {
259 WARN("Failed to create D2D device, hr %#lx.\n", hr);
260 IDXGISurface_Release(render_target->dxgi_surface);
261 return hr;
262 }
263
265 render_target->dxgi_surface, &render_target->IUnknown_iface,
266 &d2d_wic_render_target_ops, desc, (void **)&render_target->dxgi_inner);
267 ID2D1Device_Release(device);
268 if (FAILED(hr))
269 {
270 WARN("Failed to create DXGI surface render target, hr %#lx.\n", hr);
271 ID3D10Texture2D_Release(render_target->readback_texture);
272 IDXGISurface_Release(render_target->dxgi_surface);
273 return hr;
274 }
275
276 if (FAILED(hr = IUnknown_QueryInterface(render_target->dxgi_inner,
277 &IID_ID2D1RenderTarget, (void **)&render_target->dxgi_target)))
278 {
279 WARN("Failed to retrieve ID2D1RenderTarget interface, hr %#lx.\n", hr);
280 IUnknown_Release(render_target->dxgi_inner);
281 ID3D10Texture2D_Release(render_target->readback_texture);
282 IDXGISurface_Release(render_target->dxgi_surface);
283 return hr;
284 }
285
286 render_target->bitmap = bitmap;
287 IWICBitmap_AddRef(bitmap);
288
289 return S_OK;
290}
#define FIXME(fmt,...)
Definition: precomp.h:53
#define WARN(fmt,...)
Definition: precomp.h:61
@ D2D1_RENDER_TARGET_USAGE_GDI_COMPATIBLE
Definition: d2d1.idl:263
struct d2d_device * unsafe_impl_from_ID2D1Device(ID2D1Device1 *iface)
Definition: device.c:4522
HRESULT d2d_d3d_create_render_target(struct d2d_device *device, IDXGISurface *surface, IUnknown *outer_unknown, const struct d2d_device_context_ops *ops, const D2D1_RENDER_TARGET_PROPERTIES *desc, void **render_target)
Definition: device.c:4183
HRESULT d2d_factory_create_device(ID2D1Factory1 *factory, IDXGIDevice *dxgi_device, bool allow_get_dxgi_device, REFIID iid, void **device)
Definition: factory.c:516
#define D2DERR_UNSUPPORTED_PIXEL_FORMAT
Definition: d2derr.h:24
@ D3D10_USAGE_DEFAULT
Definition: d3d10.idl:461
@ D3D10_USAGE_STAGING
Definition: d3d10.idl:464
@ D3D10_CPU_ACCESS_READ
Definition: d3d10.idl:884
@ D3D10_RESOURCE_MISC_GDI_COMPATIBLE
Definition: d3d10.idl:892
@ D3D10_BIND_SHADER_RESOURCE
Definition: d3d10.idl:471
@ D3D10_BIND_RENDER_TARGET
Definition: d3d10.idl:473
HRESULT hr
Definition: delayimp.cpp:582
#define NULL
Definition: types.h:112
@ DXGI_FORMAT_B8G8R8A8_UNORM
Definition: dxgiformat.idl:110
@ DXGI_FORMAT_UNKNOWN
Definition: dxgiformat.idl:23
@ DXGI_FORMAT_R8G8B8A8_UNORM
Definition: dxgiformat.idl:51
GLenum GLuint texture
Definition: glext.h:6295
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
#define debugstr_guid
Definition: kernel32.h:35
D3D11_SHADER_VARIABLE_DESC desc
Definition: reflection.c:1683
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
DXGI_FORMAT Format
Definition: d3d10.idl:550
DXGI_SAMPLE_DESC SampleDesc
Definition: d3d10.idl:551
D3D10_USAGE Usage
Definition: d3d10.idl:552
Definition: uimain.c:89
ID3D10Texture2D * readback_texture
Definition: d2d1_private.h:243
ID2D1RenderTarget * dxgi_target
Definition: d2d1_private.h:241
IDXGISurface * dxgi_surface
Definition: d2d1_private.h:240
Definition: devices.h:37
Definition: main.c:439
static const struct IUnknownVtbl d2d_wic_render_target_vtbl
static const struct d2d_device_context_ops d2d_wic_render_target_ops

Referenced by d2d_factory_CreateWicBitmapRenderTarget().

◆ d2d_wic_render_target_present()

static HRESULT d2d_wic_render_target_present ( IUnknown *  outer_unknown)
static

Definition at line 30 of file wic_render_target.c.

31{
32 struct d2d_wic_render_target *render_target = impl_from_IUnknown(outer_unknown);
33 D3D10_MAPPED_TEXTURE2D mapped_texture;
34 ID3D10Resource *src_resource;
35 IWICBitmapLock *bitmap_lock;
36 UINT dst_size, dst_pitch;
38 WICRect dst_rect;
39 BYTE *src, *dst;
40 unsigned int i;
41 HRESULT hr;
42
43 if (FAILED(hr = IDXGISurface_QueryInterface(render_target->dxgi_surface,
44 &IID_ID3D10Resource, (void **)&src_resource)))
45 {
46 ERR("Failed to get source resource interface, hr %#lx.\n", hr);
47 goto end;
48 }
49
50 ID3D10Texture2D_GetDevice(render_target->readback_texture, &device);
51 ID3D10Device_CopyResource(device, (ID3D10Resource *)render_target->readback_texture, src_resource);
52 ID3D10Device_Release(device);
53 ID3D10Resource_Release(src_resource);
54
55 dst_rect.X = 0;
56 dst_rect.Y = 0;
57 dst_rect.Width = render_target->width;
58 dst_rect.Height = render_target->height;
59 if (FAILED(hr = IWICBitmap_Lock(render_target->bitmap, &dst_rect, WICBitmapLockWrite, &bitmap_lock)))
60 {
61 ERR("Failed to lock destination bitmap, hr %#lx.\n", hr);
62 goto end;
63 }
64
65 if (FAILED(hr = IWICBitmapLock_GetDataPointer(bitmap_lock, &dst_size, &dst)))
66 {
67 ERR("Failed to get data pointer, hr %#lx.\n", hr);
68 IWICBitmapLock_Release(bitmap_lock);
69 goto end;
70 }
71
72 if (FAILED(hr = IWICBitmapLock_GetStride(bitmap_lock, &dst_pitch)))
73 {
74 ERR("Failed to get stride, hr %#lx.\n", hr);
75 IWICBitmapLock_Release(bitmap_lock);
76 goto end;
77 }
78
79 if (FAILED(hr = ID3D10Texture2D_Map(render_target->readback_texture, 0, D3D10_MAP_READ, 0, &mapped_texture)))
80 {
81 ERR("Failed to map readback texture, hr %#lx.\n", hr);
82 IWICBitmapLock_Release(bitmap_lock);
83 goto end;
84 }
85
86 src = mapped_texture.pData;
87
88 for (i = 0; i < render_target->height; ++i)
89 {
90 memcpy(dst, src, render_target->bpp * render_target->width);
91 src += mapped_texture.RowPitch;
92 dst += dst_pitch;
93 }
94
95 ID3D10Texture2D_Unmap(render_target->readback_texture, 0);
96 IWICBitmapLock_Release(bitmap_lock);
97
98end:
99 return S_OK;
100}
#define ERR(fmt,...)
Definition: precomp.h:57
@ D3D10_MAP_READ
Definition: d3d10.idl:504
GLuint GLuint end
Definition: gl.h:1545
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int UINT
Definition: sysinfo.c:13
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
INT Height
Definition: wincodec.idl:335
INT Width
Definition: wincodec.idl:334
@ WICBitmapLockWrite
Definition: wincodec.idl:87
unsigned char BYTE
Definition: xxhash.c:193

◆ d2d_wic_render_target_QueryInterface()

static HRESULT STDMETHODCALLTYPE d2d_wic_render_target_QueryInterface ( IUnknown *  iface,
REFIID  iid,
void **  out 
)
static

Definition at line 102 of file wic_render_target.c.

103{
104 struct d2d_wic_render_target *render_target = impl_from_IUnknown(iface);
105
106 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
107
108 return IUnknown_QueryInterface(render_target->dxgi_inner, iid, out);
109}
wchar_t tm const _CrtWcstime_Writes_and_advances_ptr_ count wchar_t ** out
Definition: wcsftime.cpp:383

◆ d2d_wic_render_target_Release()

static ULONG STDMETHODCALLTYPE d2d_wic_render_target_Release ( IUnknown *  iface)
static

Definition at line 121 of file wic_render_target.c.

122{
123 struct d2d_wic_render_target *render_target = impl_from_IUnknown(iface);
124 ULONG refcount = InterlockedDecrement(&render_target->refcount);
125
126 TRACE("%p decreasing refcount to %lu.\n", iface, refcount);
127
128 if (!refcount)
129 {
130 IWICBitmap_Release(render_target->bitmap);
131 ID3D10Texture2D_Release(render_target->readback_texture);
132 IUnknown_Release(render_target->dxgi_inner);
133 IDXGISurface_Release(render_target->dxgi_surface);
134 free(render_target);
135 }
136
137 return refcount;
138}
#define InterlockedDecrement
Definition: armddk.h:52
#define free
Definition: debug_ros.c:5

◆ impl_from_IUnknown()

static struct d2d_wic_render_target * impl_from_IUnknown ( IUnknown *  iface)
inlinestatic

Definition at line 25 of file wic_render_target.c.

26{
27 return CONTAINING_RECORD(iface, struct d2d_wic_render_target, IUnknown_iface);
28}
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

Referenced by d2d_wic_render_target_AddRef(), d2d_wic_render_target_present(), d2d_wic_render_target_QueryInterface(), and d2d_wic_render_target_Release().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( d2d  )

Variable Documentation

◆ d2d_wic_render_target_ops

const struct d2d_device_context_ops d2d_wic_render_target_ops
static
Initial value:
=
{
}
static HRESULT d2d_wic_render_target_present(IUnknown *outer_unknown)

Definition at line 147 of file wic_render_target.c.

Referenced by d2d_wic_render_target_init().

◆ d2d_wic_render_target_vtbl

const struct IUnknownVtbl d2d_wic_render_target_vtbl
static
Initial value:
=
{
}
static ULONG STDMETHODCALLTYPE d2d_wic_render_target_Release(IUnknown *iface)
static ULONG STDMETHODCALLTYPE d2d_wic_render_target_AddRef(IUnknown *iface)
static HRESULT STDMETHODCALLTYPE d2d_wic_render_target_QueryInterface(IUnknown *iface, REFIID iid, void **out)

Definition at line 140 of file wic_render_target.c.

Referenced by d2d_wic_render_target_init().