xref: /reactos/dll/directx/wine/d3drm/texture.c (revision e1338178)
1 /*
2  * Implementation of IDirect3DRMTextureX interfaces
3  *
4  * Copyright 2012 Christian Costa
5  * Copyright 2016 Aaryaman Vasishta
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21 
22 #include "d3drm_private.h"
23 
24 WINE_DEFAULT_DEBUG_CHANNEL(d3drm);
25 
26 static inline struct d3drm_texture *impl_from_IDirect3DRMTexture(IDirect3DRMTexture *iface)
27 {
28     return CONTAINING_RECORD(iface, struct d3drm_texture, IDirect3DRMTexture_iface);
29 }
30 
31 static inline struct d3drm_texture *impl_from_IDirect3DRMTexture2(IDirect3DRMTexture2 *iface)
32 {
33     return CONTAINING_RECORD(iface, struct d3drm_texture, IDirect3DRMTexture2_iface);
34 }
35 
36 static inline struct d3drm_texture *impl_from_IDirect3DRMTexture3(IDirect3DRMTexture3 *iface)
37 {
38     return CONTAINING_RECORD(iface, struct d3drm_texture, IDirect3DRMTexture3_iface);
39 }
40 
41 static void d3drm_texture_destroy(struct d3drm_texture *texture)
42 {
43     TRACE("texture %p is being destroyed.\n", texture);
44 
45     d3drm_object_cleanup((IDirect3DRMObject*)&texture->IDirect3DRMTexture_iface, &texture->obj);
46     if (texture->image || texture->surface)
47         IDirect3DRM_Release(texture->d3drm);
48     if (texture->surface)
49         IDirectDrawSurface_Release(texture->surface);
50     heap_free(texture);
51 }
52 
53 static BOOL d3drm_validate_image(D3DRMIMAGE *image)
54 {
55     if (!image
56             || !image->red_mask
57             || !image->green_mask
58             || !image->blue_mask
59             || !image->buffer1
60             || !(image->rgb || (image->palette && image->palette_size)))
61     {
62         return FALSE;
63     }
64 
65     return TRUE;
66 }
67 
68 static BOOL d3drm_image_palettise(D3DRMIMAGE *image, unsigned char *src_data,
69         SIZE_T w, SIZE_T h, BOOL flip)
70 {
71     unsigned char *dst_data, *src_ptr, *dst_ptr;
72     SIZE_T src_pitch, dst_pitch, i, x, y;
73     D3DRMPALETTEENTRY *palette, *entry;
74     unsigned int colour_count = 0;
75 
76     if (w > (~(SIZE_T)0 - 3) / h)
77         return FALSE;
78 
79     src_pitch = flip ? -w * 3 : w * 3;
80     dst_pitch = (w + 3) & ~3;
81 
82     if (!(dst_data = heap_alloc(dst_pitch * h)))
83     {
84         WARN("Failed to allocate image buffer.\n");
85         return FALSE;
86     }
87     memset(dst_data, 0xff, dst_pitch * h);
88 
89     if (!(palette = heap_alloc(256 * sizeof(*palette))))
90     {
91         WARN("Failed to allocate palette.\n");
92         heap_free(dst_data);
93         return FALSE;
94     }
95 
96     src_ptr = flip ? &src_data[(h - 1) * w * 3] : src_data;
97     dst_ptr = dst_data;
98 
99     for (y = 0; y < h; ++y)
100     {
101         for (x = 0; x < w; ++x)
102         {
103             for (i = 0; i < colour_count; ++i)
104             {
105                 entry = &palette[i];
106                 if (entry->red == src_ptr[x * 3 + 0]
107                         && entry->green == src_ptr[x * 3 + 1]
108                         && entry->blue == src_ptr[x * 3 + 2])
109                     break;
110             }
111 
112             if (i == colour_count)
113             {
114                 if (colour_count == 256)
115                 {
116                     heap_free(dst_data);
117                     heap_free(palette);
118                     return FALSE;
119                 }
120 
121                 entry = &palette[colour_count++];
122                 entry->red = src_ptr[x * 3 + 0];
123                 entry->green = src_ptr[x * 3 + 1];
124                 entry->blue = src_ptr[x * 3 + 2];
125                 entry->flags = D3DRMPALETTE_READONLY;
126             }
127 
128             dst_ptr[x] = i;
129         }
130 
131         src_ptr += src_pitch;
132         dst_ptr += dst_pitch;
133     }
134 
135     image->depth = 8;
136     image->rgb = 0;
137     image->bytes_per_line = dst_pitch;
138     image->buffer1 = dst_data;
139     image->red_mask = 0xff;
140     image->green_mask = 0xff;
141     image->blue_mask = 0xff;
142     image->palette_size = colour_count;
143     if (!(image->palette = heap_realloc(palette, colour_count * sizeof(*palette))))
144         image->palette = palette;
145 
146     return TRUE;
147 }
148 
149 static HRESULT d3drm_image_load_32(D3DRMIMAGE *image, unsigned char *src_data,
150         LONGLONG src_data_size, SIZE_T w, SIZE_T h, BOOL flip)
151 {
152     unsigned char *dst_data, *src_ptr, *dst_ptr;
153     SIZE_T src_pitch, dst_pitch, x, y;
154 
155     if (d3drm_image_palettise(image, src_data, w, h, flip))
156         return D3DRM_OK;
157 
158     if (w > (~(SIZE_T)0 / 4) / h)
159         return D3DRMERR_BADALLOC;
160 
161     src_pitch = flip ? -w * 3 : w * 3;
162     dst_pitch = w * 4;
163 
164     if (!(dst_data = heap_alloc(dst_pitch * h)))
165     {
166         WARN("Failed to allocate image buffer.\n");
167         return D3DRMERR_BADALLOC;
168     }
169 
170     src_ptr = flip ? &src_data[(h - 1) * w * 3] : src_data;
171     dst_ptr = dst_data;
172 
173     for (y = 0; y < h; ++y)
174     {
175         for (x = 0; x < w; ++x)
176         {
177             dst_ptr[x * 4 + 0] = src_ptr[x * 3 + 0];
178             dst_ptr[x * 4 + 1] = src_ptr[x * 3 + 1];
179             dst_ptr[x * 4 + 2] = src_ptr[x * 3 + 2];
180             dst_ptr[x * 4 + 3] = 0xff;
181         }
182 
183         src_ptr += src_pitch;
184         dst_ptr += dst_pitch;
185     }
186 
187     image->depth = 32;
188     image->rgb = 1;
189     image->bytes_per_line = dst_pitch;
190     image->buffer1 = dst_data;
191     image->red_mask = 0xff0000;
192     image->green_mask = 0x00ff00;
193     image->blue_mask = 0x0000ff;
194     image->palette_size = 0;
195     image->palette = NULL;
196 
197     return D3DRM_OK;
198 }
199 
200 static HRESULT d3drm_image_load_8(D3DRMIMAGE *image, const RGBQUAD *palette,
201         unsigned char *src_data, LONGLONG src_data_size, SIZE_T w, SIZE_T h, BOOL flip)
202 {
203     unsigned char *dst_data;
204     SIZE_T i;
205 
206     if (w > ~(SIZE_T)0 / h)
207         return D3DRMERR_BADALLOC;
208 
209     if (!(dst_data = heap_alloc(w * h)))
210     {
211         WARN("Failed to allocate image buffer.\n");
212         return D3DRMERR_BADALLOC;
213     }
214 
215     if (!(image->palette = heap_alloc(256 * sizeof(*image->palette))))
216     {
217         WARN("Failed to allocate palette.\n");
218         heap_free(dst_data);
219         return D3DRMERR_BADALLOC;
220     }
221 
222     memcpy(image->palette, palette, 256 * sizeof(*image->palette));
223     for (i = 0; i < 256; ++i)
224     {
225         image->palette[i].flags = D3DRMPALETTE_READONLY;
226     }
227 
228     if (flip)
229     {
230         for (i = 0; i < h; ++i)
231         {
232             memcpy(&dst_data[i * w], &src_data[(h - 1 - i) * w], w);
233         }
234     }
235     else
236     {
237         memcpy(dst_data, src_data, w * h);
238     }
239 
240     image->depth = 8;
241     image->rgb = 0;
242     image->bytes_per_line = w;
243     image->buffer1 = dst_data;
244     image->red_mask = 0xff;
245     image->green_mask = 0xff;
246     image->blue_mask = 0xff;
247     image->palette_size = 256;
248 
249     return D3DRM_OK;
250 }
251 
252 static void CDECL destroy_image_callback(IDirect3DRMObject *obj, void *arg)
253 {
254     D3DRMIMAGE *image = arg;
255 
256     TRACE("texture object %p, image %p.\n", obj, image);
257 
258     heap_free(image->buffer1);
259     heap_free(image);
260 }
261 
262 static HRESULT d3drm_texture_load(struct d3drm_texture *texture,
263         const char *path, BOOL flip, D3DRMIMAGE **image_out)
264 {
265     BITMAPFILEHEADER *header;
266     unsigned int w, h, bpp;
267     HANDLE file, mapping;
268     LARGE_INTEGER size;
269     D3DRMIMAGE *image;
270     BITMAPINFO *info;
271     LONGLONG rem;
272     HRESULT hr;
273 
274     if ((file = CreateFileA(path, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0)) == INVALID_HANDLE_VALUE)
275         return D3DRMERR_BADOBJECT;
276 
277     mapping = CreateFileMappingW(file, NULL, PAGE_READONLY, 0, 0, NULL);
278     CloseHandle(file);
279     if (!mapping || mapping == INVALID_HANDLE_VALUE)
280         return D3DRMERR_BADVALUE;
281 
282     if (!GetFileSizeEx(mapping, &size))
283     {
284         CloseHandle(mapping);
285         return D3DRMERR_BADVALUE;
286     }
287     rem = size.QuadPart;
288 
289     header = MapViewOfFile(mapping, FILE_MAP_READ, 0, 0, 0);
290     CloseHandle(mapping);
291     if (!header)
292         return D3DRMERR_BADVALUE;
293 
294     hr = D3DRMERR_BADALLOC;
295     if (!(image = heap_alloc_zero(sizeof(*image))))
296         goto fail;
297 
298     hr = D3DRMERR_BADFILE;
299     if (rem < sizeof(*header) || header->bfType != 0x4d42 /* BM */)
300         goto fail;
301     rem -= sizeof(*header);
302 
303     info = (BITMAPINFO *)&header[1];
304     /* Only allow version 1 DIB's (BITMAPINFOHEADER) to be loaded. */
305     if (rem < sizeof(info->bmiHeader) || info->bmiHeader.biSize != sizeof(info->bmiHeader))
306         goto fail;
307     rem -= sizeof(info->bmiHeader);
308 
309     w = info->bmiHeader.biWidth;
310     h = abs(info->bmiHeader.biHeight);
311     bpp = info->bmiHeader.biBitCount == 24 ? 32 : info->bmiHeader.biBitCount;
312     if (bpp != 8 && bpp != 32)
313         goto fail;
314 
315     image->width = w;
316     image->height = h;
317     image->aspectx = 1;
318     image->aspecty = 1;
319     if (bpp == 8)
320     {
321         rem -= 256 * sizeof(*info->bmiColors);
322         if (w > rem / h)
323             goto fail;
324         hr = d3drm_image_load_8(image, info->bmiColors, (unsigned char *)&info->bmiColors[256], rem, w, h, flip);
325     }
326     else
327     {
328         if (w > (rem / 3) / h)
329             goto fail;
330         hr = d3drm_image_load_32(image, (unsigned char *)&info->bmiColors, rem, w, h, flip);
331     }
332     if (FAILED(hr))
333         goto fail;
334 
335     /* Use an internal destroy callback to destroy the image struct. */
336     hr = IDirect3DRMObject_AddDestroyCallback(&texture->IDirect3DRMTexture3_iface, destroy_image_callback, image);
337 
338     *image_out = image;
339 
340     UnmapViewOfFile(header);
341 
342     return hr;
343 
344 fail:
345     heap_free(image);
346     UnmapViewOfFile(header);
347 
348     return hr;
349 }
350 
351 static HRESULT WINAPI d3drm_texture1_QueryInterface(IDirect3DRMTexture *iface, REFIID riid, void **out)
352 {
353     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture(iface);
354 
355     TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
356 
357     return IDirect3DRMTexture3_QueryInterface(&texture->IDirect3DRMTexture3_iface, riid, out);
358 }
359 
360 static ULONG WINAPI d3drm_texture1_AddRef(IDirect3DRMTexture *iface)
361 {
362     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture(iface);
363 
364     TRACE("iface %p.\n", iface);
365 
366     return IDirect3DRMTexture3_AddRef(&texture->IDirect3DRMTexture3_iface);
367 }
368 
369 static ULONG WINAPI d3drm_texture1_Release(IDirect3DRMTexture *iface)
370 {
371     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture(iface);
372 
373     TRACE("iface %p.\n", iface);
374 
375     return IDirect3DRMTexture3_Release(&texture->IDirect3DRMTexture3_iface);
376 }
377 
378 static HRESULT WINAPI d3drm_texture1_Clone(IDirect3DRMTexture *iface,
379         IUnknown *outer, REFIID iid, void **out)
380 {
381     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture(iface);
382 
383     TRACE("iface %p, outer %p, iid %s, out %p.\n", iface, outer, debugstr_guid(iid), out);
384 
385     return IDirect3DRMTexture3_Clone(&texture->IDirect3DRMTexture3_iface, outer, iid, out);
386 }
387 
388 static HRESULT WINAPI d3drm_texture1_AddDestroyCallback(IDirect3DRMTexture *iface,
389         D3DRMOBJECTCALLBACK cb, void *ctx)
390 {
391     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture(iface);
392 
393     TRACE("iface %p, cb %p, ctx %p\n", iface, cb, ctx);
394 
395     return IDirect3DRMTexture3_AddDestroyCallback(&texture->IDirect3DRMTexture3_iface, cb, ctx);
396 }
397 
398 static HRESULT WINAPI d3drm_texture1_DeleteDestroyCallback(IDirect3DRMTexture *iface,
399         D3DRMOBJECTCALLBACK cb, void *ctx)
400 {
401     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture(iface);
402 
403     TRACE("iface %p, cb %p, ctx %p\n", iface, cb, ctx);
404 
405     return IDirect3DRMTexture3_DeleteDestroyCallback(&texture->IDirect3DRMTexture3_iface, cb, ctx);
406 }
407 
408 static HRESULT WINAPI d3drm_texture1_SetAppData(IDirect3DRMTexture *iface, DWORD data)
409 {
410     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture(iface);
411 
412     TRACE("iface %p, data %#x.\n", iface, data);
413 
414     return IDirect3DRMTexture3_SetAppData(&texture->IDirect3DRMTexture3_iface, data);
415 }
416 
417 static DWORD WINAPI d3drm_texture1_GetAppData(IDirect3DRMTexture *iface)
418 {
419     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture(iface);
420 
421     TRACE("iface %p.\n", iface);
422 
423     return IDirect3DRMTexture3_GetAppData(&texture->IDirect3DRMTexture3_iface);
424 }
425 
426 static HRESULT WINAPI d3drm_texture1_SetName(IDirect3DRMTexture *iface, const char *name)
427 {
428     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture(iface);
429 
430     TRACE("iface %p, name %s.\n", iface, debugstr_a(name));
431 
432     return IDirect3DRMTexture3_SetName(&texture->IDirect3DRMTexture3_iface, name);
433 }
434 
435 static HRESULT WINAPI d3drm_texture1_GetName(IDirect3DRMTexture *iface, DWORD *size, char *name)
436 {
437     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture(iface);
438 
439     TRACE("iface %p, size %p, name %p.\n", iface, size, name);
440 
441     return IDirect3DRMTexture3_GetName(&texture->IDirect3DRMTexture3_iface, size, name);
442 }
443 
444 static HRESULT WINAPI d3drm_texture1_GetClassName(IDirect3DRMTexture *iface, DWORD *size, char *name)
445 {
446     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture(iface);
447 
448     TRACE("iface %p, size %p, name %p.\n", iface, size, name);
449 
450     return IDirect3DRMTexture3_GetClassName(&texture->IDirect3DRMTexture3_iface, size, name);
451 }
452 
453 static HRESULT WINAPI d3drm_texture1_InitFromFile(IDirect3DRMTexture *iface, const char *filename)
454 {
455     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture(iface);
456     D3DRMIMAGE *image;
457     HRESULT hr;
458 
459     TRACE("iface %p, filename %s.\n", iface, debugstr_a(filename));
460 
461     if (FAILED(hr = d3drm_texture_load(texture, filename, FALSE, &image)))
462         return hr;
463 
464     return IDirect3DRMTexture3_InitFromImage(&texture->IDirect3DRMTexture3_iface, image);
465 }
466 
467 static HRESULT WINAPI d3drm_texture1_InitFromSurface(IDirect3DRMTexture *iface,
468         IDirectDrawSurface *surface)
469 {
470     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture(iface);
471 
472     TRACE("iface %p, surface %p.\n", iface, surface);
473 
474     return IDirect3DRMTexture3_InitFromSurface(&texture->IDirect3DRMTexture3_iface, surface);
475 }
476 
477 static HRESULT WINAPI d3drm_texture1_InitFromResource(IDirect3DRMTexture *iface, HRSRC resource)
478 {
479     FIXME("iface %p, resource %p stub!\n", iface, resource);
480 
481     return E_NOTIMPL;
482 }
483 
484 static HRESULT WINAPI d3drm_texture1_Changed(IDirect3DRMTexture *iface, BOOL pixels, BOOL palette)
485 {
486     FIXME("iface %p, pixels %#x, palette %#x stub!\n", iface, pixels, palette);
487 
488     return E_NOTIMPL;
489 }
490 
491 static HRESULT WINAPI d3drm_texture1_SetColors(IDirect3DRMTexture *iface, DWORD max_colors)
492 {
493     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture(iface);
494 
495     TRACE("iface %p, max_colors %u.\n", iface, max_colors);
496 
497     return IDirect3DRMTexture3_SetColors(&texture->IDirect3DRMTexture3_iface, max_colors);
498 }
499 
500 static HRESULT WINAPI d3drm_texture1_SetShades(IDirect3DRMTexture *iface, DWORD max_shades)
501 {
502     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture(iface);
503 
504     TRACE("iface %p, max_shades %u.\n", iface, max_shades);
505 
506     return IDirect3DRMTexture3_SetShades(&texture->IDirect3DRMTexture3_iface, max_shades);
507 }
508 
509 static HRESULT WINAPI d3drm_texture1_SetDecalSize(IDirect3DRMTexture *iface, D3DVALUE width, D3DVALUE height)
510 {
511     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture(iface);
512 
513     TRACE("iface %p, width %.8e, height %.8e.\n", iface, width, height);
514 
515     return IDirect3DRMTexture3_SetDecalSize(&texture->IDirect3DRMTexture3_iface, width, height);
516 }
517 
518 static HRESULT WINAPI d3drm_texture1_SetDecalOrigin(IDirect3DRMTexture *iface, LONG x, LONG y)
519 {
520     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture(iface);
521 
522     TRACE("iface %p, x %d, y %d.\n", iface, x, y);
523 
524     return IDirect3DRMTexture3_SetDecalOrigin(&texture->IDirect3DRMTexture3_iface, x, y);
525 }
526 
527 static HRESULT WINAPI d3drm_texture1_SetDecalScale(IDirect3DRMTexture *iface, DWORD scale)
528 {
529     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture(iface);
530 
531     TRACE("iface %p, scale %u.\n", iface, scale);
532 
533     return IDirect3DRMTexture3_SetDecalScale(&texture->IDirect3DRMTexture3_iface, scale);
534 }
535 
536 static HRESULT WINAPI d3drm_texture1_SetDecalTransparency(IDirect3DRMTexture *iface, BOOL transparency)
537 {
538     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture(iface);
539 
540     TRACE("iface %p, transparency %#x.\n", iface, transparency);
541 
542     return IDirect3DRMTexture3_SetDecalTransparency(&texture->IDirect3DRMTexture3_iface, transparency);
543 }
544 
545 static HRESULT WINAPI d3drm_texture1_SetDecalTransparentColor(IDirect3DRMTexture *iface, D3DCOLOR color)
546 {
547     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture(iface);
548 
549     TRACE("iface %p, color 0x%08x.\n", iface, color);
550 
551     return IDirect3DRMTexture3_SetDecalTransparentColor(&texture->IDirect3DRMTexture3_iface, color);
552 }
553 
554 static HRESULT WINAPI d3drm_texture1_GetDecalSize(IDirect3DRMTexture *iface, D3DVALUE *width, D3DVALUE *height)
555 {
556     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture(iface);
557 
558     TRACE("iface %p, width %p, height %p.\n", iface, width, height);
559 
560     return IDirect3DRMTexture3_GetDecalSize(&texture->IDirect3DRMTexture3_iface, width, height);
561 }
562 
563 static HRESULT WINAPI d3drm_texture1_GetDecalOrigin(IDirect3DRMTexture *iface, LONG *x, LONG *y)
564 {
565     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture(iface);
566 
567     TRACE("iface %p, x %p, y %p.\n", iface, x, y);
568 
569     return IDirect3DRMTexture3_GetDecalOrigin(&texture->IDirect3DRMTexture3_iface, x, y);
570 }
571 
572 static D3DRMIMAGE * WINAPI d3drm_texture1_GetImage(IDirect3DRMTexture *iface)
573 {
574     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture(iface);
575 
576     TRACE("iface %p.\n", iface);
577 
578     return IDirect3DRMTexture3_GetImage(&texture->IDirect3DRMTexture3_iface);
579 }
580 
581 static DWORD WINAPI d3drm_texture1_GetShades(IDirect3DRMTexture *iface)
582 {
583     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture(iface);
584 
585     TRACE("iface %p.\n", iface);
586 
587     return IDirect3DRMTexture3_GetShades(&texture->IDirect3DRMTexture3_iface);
588 }
589 
590 static DWORD WINAPI d3drm_texture1_GetColors(IDirect3DRMTexture *iface)
591 {
592     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture(iface);
593 
594     TRACE("iface %p.\n", iface);
595 
596     return IDirect3DRMTexture3_GetColors(&texture->IDirect3DRMTexture3_iface);
597 }
598 
599 static DWORD WINAPI d3drm_texture1_GetDecalScale(IDirect3DRMTexture *iface)
600 {
601     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture(iface);
602 
603     TRACE("iface %p.\n", iface);
604 
605     return IDirect3DRMTexture3_GetDecalScale(&texture->IDirect3DRMTexture3_iface);
606 }
607 
608 static BOOL WINAPI d3drm_texture1_GetDecalTransparency(IDirect3DRMTexture *iface)
609 {
610     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture(iface);
611 
612     TRACE("iface %p.\n", iface);
613 
614     return IDirect3DRMTexture3_GetDecalTransparency(&texture->IDirect3DRMTexture3_iface);
615 }
616 
617 static D3DCOLOR WINAPI d3drm_texture1_GetDecalTransparentColor(IDirect3DRMTexture *iface)
618 {
619     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture(iface);
620 
621     TRACE("iface %p.\n", iface);
622 
623     return IDirect3DRMTexture3_GetDecalTransparentColor(&texture->IDirect3DRMTexture3_iface);
624 }
625 
626 static const struct IDirect3DRMTextureVtbl d3drm_texture1_vtbl =
627 {
628     d3drm_texture1_QueryInterface,
629     d3drm_texture1_AddRef,
630     d3drm_texture1_Release,
631     d3drm_texture1_Clone,
632     d3drm_texture1_AddDestroyCallback,
633     d3drm_texture1_DeleteDestroyCallback,
634     d3drm_texture1_SetAppData,
635     d3drm_texture1_GetAppData,
636     d3drm_texture1_SetName,
637     d3drm_texture1_GetName,
638     d3drm_texture1_GetClassName,
639     d3drm_texture1_InitFromFile,
640     d3drm_texture1_InitFromSurface,
641     d3drm_texture1_InitFromResource,
642     d3drm_texture1_Changed,
643     d3drm_texture1_SetColors,
644     d3drm_texture1_SetShades,
645     d3drm_texture1_SetDecalSize,
646     d3drm_texture1_SetDecalOrigin,
647     d3drm_texture1_SetDecalScale,
648     d3drm_texture1_SetDecalTransparency,
649     d3drm_texture1_SetDecalTransparentColor,
650     d3drm_texture1_GetDecalSize,
651     d3drm_texture1_GetDecalOrigin,
652     d3drm_texture1_GetImage,
653     d3drm_texture1_GetShades,
654     d3drm_texture1_GetColors,
655     d3drm_texture1_GetDecalScale,
656     d3drm_texture1_GetDecalTransparency,
657     d3drm_texture1_GetDecalTransparentColor,
658 };
659 
660 static HRESULT WINAPI d3drm_texture2_QueryInterface(IDirect3DRMTexture2 *iface, REFIID riid, void **out)
661 {
662     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture2(iface);
663 
664     TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
665 
666     return IDirect3DRMTexture3_QueryInterface(&texture->IDirect3DRMTexture3_iface, riid, out);
667 }
668 
669 static ULONG WINAPI d3drm_texture2_AddRef(IDirect3DRMTexture2 *iface)
670 {
671     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture2(iface);
672 
673     TRACE("iface %p.\n", iface);
674 
675     return IDirect3DRMTexture3_AddRef(&texture->IDirect3DRMTexture3_iface);
676 }
677 
678 static ULONG WINAPI d3drm_texture2_Release(IDirect3DRMTexture2 *iface)
679 {
680     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture2(iface);
681 
682     TRACE("iface %p.\n", iface);
683 
684     return IDirect3DRMTexture3_Release(&texture->IDirect3DRMTexture3_iface);
685 }
686 
687 static HRESULT WINAPI d3drm_texture2_Clone(IDirect3DRMTexture2 *iface,
688         IUnknown *outer, REFIID iid, void **out)
689 {
690     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture2(iface);
691 
692     TRACE("iface %p, outer %p, iid %s, out %p.\n", iface, outer, debugstr_guid(iid), out);
693 
694     return IDirect3DRMTexture3_Clone(&texture->IDirect3DRMTexture3_iface, outer, iid, out);
695 }
696 
697 static HRESULT WINAPI d3drm_texture2_AddDestroyCallback(IDirect3DRMTexture2 *iface,
698         D3DRMOBJECTCALLBACK cb, void *ctx)
699 {
700     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture2(iface);
701 
702     TRACE("iface %p, cb %p, ctx %p\n", iface, cb, ctx);
703 
704     return IDirect3DRMTexture3_AddDestroyCallback(&texture->IDirect3DRMTexture3_iface, cb, ctx);
705 }
706 
707 static HRESULT WINAPI d3drm_texture2_DeleteDestroyCallback(IDirect3DRMTexture2 *iface,
708         D3DRMOBJECTCALLBACK cb, void *ctx)
709 {
710     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture2(iface);
711 
712     TRACE("iface %p, cb %p, ctx %p\n", iface, cb, ctx);
713 
714     return IDirect3DRMTexture3_DeleteDestroyCallback(&texture->IDirect3DRMTexture3_iface, cb, ctx);
715 }
716 
717 static HRESULT WINAPI d3drm_texture2_SetAppData(IDirect3DRMTexture2 *iface, DWORD data)
718 {
719     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture2(iface);
720 
721     TRACE("iface %p, data %#x.\n", iface, data);
722 
723     return IDirect3DRMTexture3_SetAppData(&texture->IDirect3DRMTexture3_iface, data);
724 }
725 
726 static DWORD WINAPI d3drm_texture2_GetAppData(IDirect3DRMTexture2 *iface)
727 {
728     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture2(iface);
729 
730     TRACE("iface %p.\n", iface);
731 
732     return IDirect3DRMTexture3_GetAppData(&texture->IDirect3DRMTexture3_iface);
733 }
734 
735 static HRESULT WINAPI d3drm_texture2_SetName(IDirect3DRMTexture2 *iface, const char *name)
736 {
737     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture2(iface);
738 
739     TRACE("iface %p, name %s.\n", iface, debugstr_a(name));
740 
741     return IDirect3DRMTexture3_SetName(&texture->IDirect3DRMTexture3_iface, name);
742 }
743 
744 static HRESULT WINAPI d3drm_texture2_GetName(IDirect3DRMTexture2 *iface, DWORD *size, char *name)
745 {
746     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture2(iface);
747 
748     TRACE("iface %p, size %p, name %p.\n", iface, size, name);
749 
750     return IDirect3DRMTexture3_GetName(&texture->IDirect3DRMTexture3_iface, size, name);
751 }
752 
753 static HRESULT WINAPI d3drm_texture2_GetClassName(IDirect3DRMTexture2 *iface, DWORD *size, char *name)
754 {
755     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture2(iface);
756 
757     TRACE("iface %p, size %p, name %p.\n", iface, size, name);
758 
759     return IDirect3DRMTexture3_GetClassName(&texture->IDirect3DRMTexture3_iface, size, name);
760 }
761 
762 static HRESULT WINAPI d3drm_texture2_InitFromFile(IDirect3DRMTexture2 *iface, const char *filename)
763 {
764     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture2(iface);
765 
766     TRACE("iface %p, filename %s.\n", iface, debugstr_a(filename));
767 
768     return IDirect3DRMTexture3_InitFromFile(&texture->IDirect3DRMTexture3_iface, filename);
769 }
770 
771 static HRESULT WINAPI d3drm_texture2_InitFromSurface(IDirect3DRMTexture2 *iface,
772         IDirectDrawSurface *surface)
773 {
774     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture2(iface);
775 
776     TRACE("iface %p, surface %p.\n", iface, surface);
777 
778     return IDirect3DRMTexture3_InitFromSurface(&texture->IDirect3DRMTexture3_iface, surface);
779 }
780 
781 static HRESULT WINAPI d3drm_texture2_InitFromResource(IDirect3DRMTexture2 *iface, HRSRC resource)
782 {
783     FIXME("iface %p, resource %p stub!\n", iface, resource);
784 
785     return E_NOTIMPL;
786 }
787 
788 static HRESULT WINAPI d3drm_texture2_Changed(IDirect3DRMTexture2 *iface, BOOL pixels, BOOL palette)
789 {
790     FIXME("iface %p, pixels %#x, palette %#x stub!\n", iface, pixels, palette);
791 
792     return E_NOTIMPL;
793 }
794 
795 static HRESULT WINAPI d3drm_texture2_SetColors(IDirect3DRMTexture2 *iface, DWORD max_colors)
796 {
797     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture2(iface);
798 
799     TRACE("iface %p, max_colors %u.\n", iface, max_colors);
800 
801     return IDirect3DRMTexture3_SetColors(&texture->IDirect3DRMTexture3_iface, max_colors);
802 }
803 
804 static HRESULT WINAPI d3drm_texture2_SetShades(IDirect3DRMTexture2 *iface, DWORD max_shades)
805 {
806     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture2(iface);
807 
808     TRACE("iface %p, max_shades %u.\n", iface, max_shades);
809 
810     return IDirect3DRMTexture3_SetShades(&texture->IDirect3DRMTexture3_iface, max_shades);
811 }
812 
813 static HRESULT WINAPI d3drm_texture2_SetDecalSize(IDirect3DRMTexture2 *iface, D3DVALUE width, D3DVALUE height)
814 {
815     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture2(iface);
816 
817     TRACE("iface %p, width %.8e, height %.8e.\n", iface, width, height);
818 
819     return IDirect3DRMTexture3_SetDecalSize(&texture->IDirect3DRMTexture3_iface, width, height);
820 }
821 
822 static HRESULT WINAPI d3drm_texture2_SetDecalOrigin(IDirect3DRMTexture2 *iface, LONG x, LONG y)
823 {
824     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture2(iface);
825 
826     TRACE("iface %p, x %d, y %d.\n", iface, x, y);
827 
828     return IDirect3DRMTexture3_SetDecalOrigin(&texture->IDirect3DRMTexture3_iface, x, y);
829 }
830 
831 static HRESULT WINAPI d3drm_texture2_SetDecalScale(IDirect3DRMTexture2 *iface, DWORD scale)
832 {
833     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture2(iface);
834 
835     TRACE("iface %p, scale %u.\n", iface, scale);
836 
837     return IDirect3DRMTexture3_SetDecalScale(&texture->IDirect3DRMTexture3_iface, scale);
838 }
839 
840 static HRESULT WINAPI d3drm_texture2_SetDecalTransparency(IDirect3DRMTexture2 *iface, BOOL transparency)
841 {
842     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture2(iface);
843 
844     TRACE("iface %p, transparency %#x.\n", iface, transparency);
845 
846     return IDirect3DRMTexture3_SetDecalTransparency(&texture->IDirect3DRMTexture3_iface, transparency);
847 }
848 
849 static HRESULT WINAPI d3drm_texture2_SetDecalTransparentColor(IDirect3DRMTexture2 *iface, D3DCOLOR color)
850 {
851     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture2(iface);
852 
853     TRACE("iface %p, color 0x%08x.\n", iface, color);
854 
855     return IDirect3DRMTexture3_SetDecalTransparentColor(&texture->IDirect3DRMTexture3_iface, color);
856 }
857 
858 static HRESULT WINAPI d3drm_texture2_GetDecalSize(IDirect3DRMTexture2 *iface, D3DVALUE *width, D3DVALUE *height)
859 {
860     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture2(iface);
861 
862     TRACE("iface %p, width %p, height %p.\n", iface, width, height);
863 
864     return IDirect3DRMTexture3_GetDecalSize(&texture->IDirect3DRMTexture3_iface, width, height);
865 }
866 
867 static HRESULT WINAPI d3drm_texture2_GetDecalOrigin(IDirect3DRMTexture2 *iface, LONG *x, LONG *y)
868 {
869     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture2(iface);
870 
871     TRACE("iface %p, x %p, y %p.\n", iface, x, y);
872 
873     return IDirect3DRMTexture3_GetDecalOrigin(&texture->IDirect3DRMTexture3_iface, x, y);
874 }
875 
876 static D3DRMIMAGE * WINAPI d3drm_texture2_GetImage(IDirect3DRMTexture2 *iface)
877 {
878     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture2(iface);
879 
880     TRACE("iface %p.\n", iface);
881 
882     return IDirect3DRMTexture3_GetImage(&texture->IDirect3DRMTexture3_iface);
883 }
884 
885 static DWORD WINAPI d3drm_texture2_GetShades(IDirect3DRMTexture2 *iface)
886 {
887     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture2(iface);
888 
889     TRACE("iface %p.\n", iface);
890 
891     return IDirect3DRMTexture3_GetShades(&texture->IDirect3DRMTexture3_iface);
892 }
893 
894 static DWORD WINAPI d3drm_texture2_GetColors(IDirect3DRMTexture2 *iface)
895 {
896     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture2(iface);
897 
898     TRACE("iface %p.\n", iface);
899 
900     return IDirect3DRMTexture3_GetColors(&texture->IDirect3DRMTexture3_iface);
901 }
902 
903 static DWORD WINAPI d3drm_texture2_GetDecalScale(IDirect3DRMTexture2 *iface)
904 {
905     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture2(iface);
906 
907     TRACE("iface %p.\n", iface);
908 
909     return IDirect3DRMTexture3_GetDecalScale(&texture->IDirect3DRMTexture3_iface);
910 }
911 
912 static BOOL WINAPI d3drm_texture2_GetDecalTransparency(IDirect3DRMTexture2 *iface)
913 {
914     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture2(iface);
915 
916     TRACE("iface %p.\n", iface);
917 
918     return IDirect3DRMTexture3_GetDecalTransparency(&texture->IDirect3DRMTexture3_iface);
919 }
920 
921 static D3DCOLOR WINAPI d3drm_texture2_GetDecalTransparentColor(IDirect3DRMTexture2 *iface)
922 {
923     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture2(iface);
924 
925     TRACE("iface %p.\n", iface);
926 
927     return IDirect3DRMTexture3_GetDecalTransparentColor(&texture->IDirect3DRMTexture3_iface);
928 }
929 
930 static HRESULT WINAPI d3drm_texture2_InitFromImage(IDirect3DRMTexture2 *iface, D3DRMIMAGE *image)
931 {
932     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture2(iface);
933 
934     TRACE("iface %p, image %p.\n", iface, image);
935 
936     return IDirect3DRMTexture3_InitFromImage(&texture->IDirect3DRMTexture3_iface, image);
937 }
938 
939 static HRESULT WINAPI d3drm_texture2_InitFromResource2(IDirect3DRMTexture2 *iface,
940         HMODULE module, const char *name, const char *type)
941 {
942     FIXME("iface %p, module %p, name %s, type %s stub!\n",
943             iface, module, debugstr_a(name), debugstr_a(type));
944 
945     return E_NOTIMPL;
946 }
947 
948 static HRESULT WINAPI d3drm_texture2_GenerateMIPMap(IDirect3DRMTexture2 *iface, DWORD flags)
949 {
950     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture2(iface);
951 
952     TRACE("iface %p, flags %#x.\n", iface, flags);
953 
954     return IDirect3DRMTexture3_GenerateMIPMap(&texture->IDirect3DRMTexture3_iface, flags);
955 }
956 
957 static const struct IDirect3DRMTexture2Vtbl d3drm_texture2_vtbl =
958 {
959     d3drm_texture2_QueryInterface,
960     d3drm_texture2_AddRef,
961     d3drm_texture2_Release,
962     d3drm_texture2_Clone,
963     d3drm_texture2_AddDestroyCallback,
964     d3drm_texture2_DeleteDestroyCallback,
965     d3drm_texture2_SetAppData,
966     d3drm_texture2_GetAppData,
967     d3drm_texture2_SetName,
968     d3drm_texture2_GetName,
969     d3drm_texture2_GetClassName,
970     d3drm_texture2_InitFromFile,
971     d3drm_texture2_InitFromSurface,
972     d3drm_texture2_InitFromResource,
973     d3drm_texture2_Changed,
974     d3drm_texture2_SetColors,
975     d3drm_texture2_SetShades,
976     d3drm_texture2_SetDecalSize,
977     d3drm_texture2_SetDecalOrigin,
978     d3drm_texture2_SetDecalScale,
979     d3drm_texture2_SetDecalTransparency,
980     d3drm_texture2_SetDecalTransparentColor,
981     d3drm_texture2_GetDecalSize,
982     d3drm_texture2_GetDecalOrigin,
983     d3drm_texture2_GetImage,
984     d3drm_texture2_GetShades,
985     d3drm_texture2_GetColors,
986     d3drm_texture2_GetDecalScale,
987     d3drm_texture2_GetDecalTransparency,
988     d3drm_texture2_GetDecalTransparentColor,
989     d3drm_texture2_InitFromImage,
990     d3drm_texture2_InitFromResource2,
991     d3drm_texture2_GenerateMIPMap,
992 };
993 
994 static HRESULT WINAPI d3drm_texture3_QueryInterface(IDirect3DRMTexture3 *iface, REFIID riid, void **out)
995 {
996     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture3(iface);
997 
998     TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
999 
1000     if (IsEqualGUID(riid, &IID_IDirect3DRMTexture)
1001             || IsEqualGUID(riid, &IID_IDirect3DRMVisual)
1002             || IsEqualGUID(riid, &IID_IDirect3DRMObject)
1003             || IsEqualGUID(riid, &IID_IUnknown))
1004     {
1005         *out = &texture->IDirect3DRMTexture_iface;
1006     }
1007     else if (IsEqualGUID(riid, &IID_IDirect3DRMTexture2))
1008     {
1009         *out = &texture->IDirect3DRMTexture2_iface;
1010     }
1011     else if (IsEqualGUID(riid, &IID_IDirect3DRMTexture3))
1012     {
1013         *out = &texture->IDirect3DRMTexture3_iface;
1014     }
1015     else
1016     {
1017         *out = NULL;
1018         WARN("%s not implemented, returning CLASS_E_CLASSNOTAVAILABLE.\n", debugstr_guid(riid));
1019         return CLASS_E_CLASSNOTAVAILABLE;
1020     }
1021 
1022     IUnknown_AddRef((IUnknown *)*out);
1023     return S_OK;
1024 }
1025 
1026 static ULONG WINAPI d3drm_texture3_AddRef(IDirect3DRMTexture3 *iface)
1027 {
1028     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture3(iface);
1029     ULONG refcount = InterlockedIncrement(&texture->obj.ref);
1030 
1031     TRACE("%p increasing refcount to %u.\n", iface, refcount);
1032 
1033     return refcount;
1034 }
1035 
1036 static ULONG WINAPI d3drm_texture3_Release(IDirect3DRMTexture3 *iface)
1037 {
1038     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture3(iface);
1039     ULONG refcount = InterlockedDecrement(&texture->obj.ref);
1040 
1041     TRACE("%p decreasing refcount to %u.\n", iface, refcount);
1042 
1043     if (!refcount)
1044         d3drm_texture_destroy(texture);
1045 
1046     return refcount;
1047 }
1048 
1049 static HRESULT WINAPI d3drm_texture3_Clone(IDirect3DRMTexture3 *iface,
1050         IUnknown *outer, REFIID iid, void **out)
1051 {
1052     FIXME("iface %p, outer %p, iid %s, out %p stub!\n", iface, outer, debugstr_guid(iid), out);
1053 
1054     return E_NOTIMPL;
1055 }
1056 
1057 static HRESULT WINAPI d3drm_texture3_AddDestroyCallback(IDirect3DRMTexture3 *iface,
1058         D3DRMOBJECTCALLBACK cb, void *ctx)
1059 {
1060     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture3(iface);
1061 
1062     TRACE("iface %p, cb %p, ctx %p\n", iface, cb, ctx);
1063 
1064     return d3drm_object_add_destroy_callback(&texture->obj, cb, ctx);
1065 }
1066 
1067 static HRESULT WINAPI d3drm_texture3_DeleteDestroyCallback(IDirect3DRMTexture3 *iface,
1068         D3DRMOBJECTCALLBACK cb, void *ctx)
1069 {
1070     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture3(iface);
1071 
1072     TRACE("iface %p, cb %p, ctx %p\n", iface, cb, ctx);
1073 
1074     return d3drm_object_delete_destroy_callback(&texture->obj, cb, ctx);
1075 }
1076 
1077 static HRESULT WINAPI d3drm_texture3_SetAppData(IDirect3DRMTexture3 *iface, DWORD data)
1078 {
1079     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture3(iface);
1080 
1081     TRACE("iface %p, data %#x.\n", iface, data);
1082 
1083     texture->obj.appdata = data;
1084 
1085     return D3DRM_OK;
1086 }
1087 
1088 static DWORD WINAPI d3drm_texture3_GetAppData(IDirect3DRMTexture3 *iface)
1089 {
1090     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture3(iface);
1091 
1092     TRACE("iface %p.\n", iface);
1093 
1094     return texture->obj.appdata;
1095 }
1096 
1097 static HRESULT WINAPI d3drm_texture3_SetName(IDirect3DRMTexture3 *iface, const char *name)
1098 {
1099     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture3(iface);
1100 
1101     TRACE("iface %p, name %s.\n", iface, debugstr_a(name));
1102 
1103     return d3drm_object_set_name(&texture->obj, name);
1104 }
1105 
1106 static HRESULT WINAPI d3drm_texture3_GetName(IDirect3DRMTexture3 *iface, DWORD *size, char *name)
1107 {
1108     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture3(iface);
1109 
1110     TRACE("iface %p, size %p, name %p.\n", iface, size, name);
1111 
1112     return d3drm_object_get_name(&texture->obj, size, name);
1113 }
1114 
1115 static HRESULT WINAPI d3drm_texture3_GetClassName(IDirect3DRMTexture3 *iface, DWORD *size, char *name)
1116 {
1117     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture3(iface);
1118 
1119     TRACE("iface %p, size %p, name %p.\n", iface, size, name);
1120 
1121     return d3drm_object_get_class_name(&texture->obj, size, name);
1122 }
1123 
1124 static HRESULT WINAPI d3drm_texture3_InitFromFile(IDirect3DRMTexture3 *iface, const char *filename)
1125 {
1126     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture3(iface);
1127     D3DRMIMAGE *image;
1128     HRESULT hr;
1129 
1130     TRACE("iface %p, filename %s.\n", iface, debugstr_a(filename));
1131 
1132     if (FAILED(hr = d3drm_texture_load(texture, filename, TRUE, &image)))
1133         return hr;
1134 
1135     return IDirect3DRMTexture3_InitFromImage(iface, image);
1136 }
1137 
1138 static HRESULT WINAPI d3drm_texture3_InitFromSurface(IDirect3DRMTexture3 *iface,
1139         IDirectDrawSurface *surface)
1140 {
1141     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture3(iface);
1142 
1143     TRACE("iface %p, surface %p.\n", iface, surface);
1144 
1145     if (!surface)
1146         return D3DRMERR_BADOBJECT;
1147 
1148     /* d3drm intentionally leaks a reference to IDirect3DRM here if texture has already been initialized. */
1149     IDirect3DRM_AddRef(texture->d3drm);
1150 
1151     if (texture->image || texture->surface)
1152         return D3DRMERR_BADOBJECT;
1153 
1154     texture->surface = surface;
1155     IDirectDrawSurface_AddRef(texture->surface);
1156     return D3DRM_OK;
1157 }
1158 
1159 static HRESULT WINAPI d3drm_texture3_InitFromResource(IDirect3DRMTexture3 *iface, HRSRC resource)
1160 {
1161     FIXME("iface %p, resource %p stub!\n", iface, resource);
1162 
1163     return E_NOTIMPL;
1164 }
1165 
1166 static HRESULT WINAPI d3drm_texture3_Changed(IDirect3DRMTexture3 *iface,
1167         DWORD flags, DWORD rect_count, RECT *rects)
1168 {
1169     FIXME("iface %p, flags %#x, rect_count %u, rects %p stub!\n", iface, flags, rect_count, rects);
1170 
1171     return E_NOTIMPL;
1172 }
1173 
1174 static HRESULT WINAPI d3drm_texture3_SetColors(IDirect3DRMTexture3 *iface, DWORD max_colors)
1175 {
1176     FIXME("iface %p, max_colors %u stub!\n", iface, max_colors);
1177 
1178     return E_NOTIMPL;
1179 }
1180 
1181 static HRESULT WINAPI d3drm_texture3_SetShades(IDirect3DRMTexture3 *iface, DWORD max_shades)
1182 {
1183     FIXME("iface %p, max_shades %u stub!\n", iface, max_shades);
1184 
1185     return E_NOTIMPL;
1186 }
1187 
1188 static HRESULT WINAPI d3drm_texture3_SetDecalSize(IDirect3DRMTexture3 *iface, D3DVALUE width, D3DVALUE height)
1189 {
1190     FIXME("iface %p, width %.8e, height %.8e stub!\n", iface, width, height);
1191 
1192     return E_NOTIMPL;
1193 }
1194 
1195 static HRESULT WINAPI d3drm_texture3_SetDecalOrigin(IDirect3DRMTexture3 *iface, LONG x, LONG y)
1196 {
1197     FIXME("iface %p, x %d, y %d stub!\n", iface, x, y);
1198 
1199     return E_NOTIMPL;
1200 }
1201 
1202 static HRESULT WINAPI d3drm_texture3_SetDecalScale(IDirect3DRMTexture3 *iface, DWORD scale)
1203 {
1204     FIXME("iface %p, scale %u stub!\n", iface, scale);
1205 
1206     return E_NOTIMPL;
1207 }
1208 
1209 static HRESULT WINAPI d3drm_texture3_SetDecalTransparency(IDirect3DRMTexture3 *iface, BOOL transparency)
1210 {
1211     FIXME("iface %p, transparency %#x stub!\n", iface, transparency);
1212 
1213     return E_NOTIMPL;
1214 }
1215 
1216 static HRESULT WINAPI d3drm_texture3_SetDecalTransparentColor(IDirect3DRMTexture3 *iface, D3DCOLOR color)
1217 {
1218     FIXME("iface %p, color 0x%08x stub!\n", iface, color);
1219 
1220     return E_NOTIMPL;
1221 }
1222 
1223 static HRESULT WINAPI d3drm_texture3_GetDecalSize(IDirect3DRMTexture3 *iface, D3DVALUE *width, D3DVALUE *height)
1224 {
1225     FIXME("iface %p, width %p, height %p stub!\n", iface, width, height);
1226 
1227     return E_NOTIMPL;
1228 }
1229 
1230 static HRESULT WINAPI d3drm_texture3_GetDecalOrigin(IDirect3DRMTexture3 *iface, LONG *x, LONG *y)
1231 {
1232     FIXME("iface %p, x %p, y %p stub!\n", iface, x, y);
1233 
1234     return E_NOTIMPL;
1235 }
1236 
1237 static D3DRMIMAGE * WINAPI d3drm_texture3_GetImage(IDirect3DRMTexture3 *iface)
1238 {
1239     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture3(iface);
1240 
1241     TRACE("iface %p.\n", iface);
1242 
1243     return texture->image;
1244 }
1245 
1246 static DWORD WINAPI d3drm_texture3_GetShades(IDirect3DRMTexture3 *iface)
1247 {
1248     FIXME("iface %p stub!\n", iface);
1249 
1250     return 0;
1251 }
1252 
1253 static DWORD WINAPI d3drm_texture3_GetColors(IDirect3DRMTexture3 *iface)
1254 {
1255     FIXME("iface %p stub!\n", iface);
1256 
1257     return 0;
1258 }
1259 
1260 static DWORD WINAPI d3drm_texture3_GetDecalScale(IDirect3DRMTexture3 *iface)
1261 {
1262     FIXME("iface %p stub!\n", iface);
1263 
1264     return 0;
1265 }
1266 
1267 static BOOL WINAPI d3drm_texture3_GetDecalTransparency(IDirect3DRMTexture3 *iface)
1268 {
1269     FIXME("iface %p stub!\n", iface);
1270 
1271     return FALSE;
1272 }
1273 
1274 static D3DCOLOR WINAPI d3drm_texture3_GetDecalTransparentColor(IDirect3DRMTexture3 *iface)
1275 {
1276     FIXME("iface %p stub!\n", iface);
1277 
1278     return 0;
1279 }
1280 
1281 static HRESULT WINAPI d3drm_texture3_InitFromImage(IDirect3DRMTexture3 *iface, D3DRMIMAGE *image)
1282 {
1283     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture3(iface);
1284 
1285     TRACE("iface %p, image %p.\n", iface, image);
1286 
1287     if (!d3drm_validate_image(image))
1288         return D3DRMERR_BADOBJECT;
1289 
1290     /* d3drm intentionally leaks a reference to IDirect3DRM here if texture has already been initialized. */
1291     IDirect3DRM_AddRef(texture->d3drm);
1292 
1293     if (texture->image || texture->surface)
1294         return D3DRMERR_BADOBJECT;
1295 
1296     texture->image = image;
1297 
1298     return D3DRM_OK;
1299 }
1300 
1301 static HRESULT WINAPI d3drm_texture3_InitFromResource2(IDirect3DRMTexture3 *iface,
1302         HMODULE module, const char *name, const char *type)
1303 {
1304     FIXME("iface %p, module %p, name %s, type %s stub!\n",
1305             iface, module, debugstr_a(name), debugstr_a(type));
1306 
1307     return E_NOTIMPL;
1308 }
1309 
1310 static HRESULT WINAPI d3drm_texture3_GenerateMIPMap(IDirect3DRMTexture3 *iface, DWORD flags)
1311 {
1312     FIXME("iface %p, flags %#x stub!\n", iface, flags);
1313 
1314     return E_NOTIMPL;
1315 }
1316 
1317 static HRESULT WINAPI d3drm_texture3_GetSurface(IDirect3DRMTexture3 *iface,
1318         DWORD flags, IDirectDrawSurface **surface)
1319 {
1320     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture3(iface);
1321 
1322     TRACE("iface %p, flags %#x, surface %p.\n", iface, flags, surface);
1323 
1324     if (flags)
1325         FIXME("unexpected flags %#x.\n", flags);
1326 
1327     if (!surface)
1328         return D3DRMERR_BADVALUE;
1329 
1330     if (texture->image)
1331         return D3DRMERR_NOTCREATEDFROMDDS;
1332 
1333     *surface = texture->surface;
1334     IDirectDrawSurface_AddRef(*surface);
1335 
1336     return D3DRM_OK;
1337 }
1338 
1339 static HRESULT WINAPI d3drm_texture3_SetCacheOptions(IDirect3DRMTexture3 *iface, LONG importance, DWORD flags)
1340 {
1341     FIXME("iface %p, importance %d, flags %#x stub!\n", iface, importance, flags);
1342 
1343     return E_NOTIMPL;
1344 }
1345 
1346 static HRESULT WINAPI d3drm_texture3_GetCacheOptions(IDirect3DRMTexture3 *iface,
1347         LONG *importance, DWORD *flags)
1348 {
1349     FIXME("iface %p, importance %p, flags %p stub!\n", iface, importance, flags);
1350 
1351     return E_NOTIMPL;
1352 }
1353 
1354 static HRESULT WINAPI d3drm_texture3_SetDownsampleCallback(IDirect3DRMTexture3 *iface,
1355         D3DRMDOWNSAMPLECALLBACK cb, void *ctx)
1356 {
1357     FIXME("iface %p, cb %p, ctx %p stub!\n", iface, cb, ctx);
1358 
1359     return E_NOTIMPL;
1360 }
1361 
1362 static HRESULT WINAPI d3drm_texture3_SetValidationCallback(IDirect3DRMTexture3 *iface,
1363         D3DRMVALIDATIONCALLBACK cb, void *ctx)
1364 {
1365     FIXME("iface %p, cb %p, ctx %p stub!\n", iface, cb, ctx);
1366 
1367     return E_NOTIMPL;
1368 }
1369 
1370 static const struct IDirect3DRMTexture3Vtbl d3drm_texture3_vtbl =
1371 {
1372     d3drm_texture3_QueryInterface,
1373     d3drm_texture3_AddRef,
1374     d3drm_texture3_Release,
1375     d3drm_texture3_Clone,
1376     d3drm_texture3_AddDestroyCallback,
1377     d3drm_texture3_DeleteDestroyCallback,
1378     d3drm_texture3_SetAppData,
1379     d3drm_texture3_GetAppData,
1380     d3drm_texture3_SetName,
1381     d3drm_texture3_GetName,
1382     d3drm_texture3_GetClassName,
1383     d3drm_texture3_InitFromFile,
1384     d3drm_texture3_InitFromSurface,
1385     d3drm_texture3_InitFromResource,
1386     d3drm_texture3_Changed,
1387     d3drm_texture3_SetColors,
1388     d3drm_texture3_SetShades,
1389     d3drm_texture3_SetDecalSize,
1390     d3drm_texture3_SetDecalOrigin,
1391     d3drm_texture3_SetDecalScale,
1392     d3drm_texture3_SetDecalTransparency,
1393     d3drm_texture3_SetDecalTransparentColor,
1394     d3drm_texture3_GetDecalSize,
1395     d3drm_texture3_GetDecalOrigin,
1396     d3drm_texture3_GetImage,
1397     d3drm_texture3_GetShades,
1398     d3drm_texture3_GetColors,
1399     d3drm_texture3_GetDecalScale,
1400     d3drm_texture3_GetDecalTransparency,
1401     d3drm_texture3_GetDecalTransparentColor,
1402     d3drm_texture3_InitFromImage,
1403     d3drm_texture3_InitFromResource2,
1404     d3drm_texture3_GenerateMIPMap,
1405     d3drm_texture3_GetSurface,
1406     d3drm_texture3_SetCacheOptions,
1407     d3drm_texture3_GetCacheOptions,
1408     d3drm_texture3_SetDownsampleCallback,
1409     d3drm_texture3_SetValidationCallback,
1410 };
1411 
1412 HRESULT d3drm_texture_create(struct d3drm_texture **texture, IDirect3DRM *d3drm)
1413 {
1414     static const char classname[] = "Texture";
1415     struct d3drm_texture *object;
1416 
1417     TRACE("texture %p.\n", texture);
1418 
1419     if (!(object = heap_alloc_zero(sizeof(*object))))
1420         return E_OUTOFMEMORY;
1421 
1422     object->IDirect3DRMTexture_iface.lpVtbl = &d3drm_texture1_vtbl;
1423     object->IDirect3DRMTexture2_iface.lpVtbl = &d3drm_texture2_vtbl;
1424     object->IDirect3DRMTexture3_iface.lpVtbl = &d3drm_texture3_vtbl;
1425     object->d3drm = d3drm;
1426 
1427     d3drm_object_init(&object->obj, classname);
1428 
1429     *texture = object;
1430 
1431     return D3DRM_OK;
1432 }
1433