2006-05-13 22:22:16 +02:00
|
|
|
/*
|
|
|
|
* 2D Surface implementation without OpenGL
|
|
|
|
*
|
|
|
|
* Copyright 1997-2000 Marcus Meissner
|
|
|
|
* Copyright 1998-2000 Lionel Ulmer
|
|
|
|
* Copyright 2000-2001 TransGaming Technologies Inc.
|
|
|
|
* Copyright 2002-2005 Jason Edmeades
|
|
|
|
* Copyright 2002-2003 Raphael Junqueira
|
|
|
|
* Copyright 2004 Christian Costa
|
|
|
|
* Copyright 2005 Oliver Stieber
|
2008-10-18 19:21:20 +02:00
|
|
|
* Copyright 2006-2008 Stefan Dösinger
|
2006-05-13 22:22:16 +02:00
|
|
|
*
|
|
|
|
* 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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2006-05-13 22:22:16 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
#include "wined3d_private.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
/* Use the d3d_surface debug channel to have one channel for all surfaces */
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d_surface);
|
|
|
|
|
2009-06-15 09:06:49 +02:00
|
|
|
void surface_gdi_cleanup(IWineD3DSurfaceImpl *This)
|
2009-06-15 09:06:49 +02:00
|
|
|
{
|
|
|
|
TRACE("(%p) : Cleaning up.\n", This);
|
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & SFLAG_DIBSECTION)
|
2009-06-15 09:06:49 +02:00
|
|
|
{
|
|
|
|
/* Release the DC. */
|
|
|
|
SelectObject(This->hDC, This->dib.holdbitmap);
|
|
|
|
DeleteDC(This->hDC);
|
|
|
|
/* Release the DIB section. */
|
|
|
|
DeleteObject(This->dib.DIBsection);
|
|
|
|
This->dib.bitmap_data = NULL;
|
|
|
|
This->resource.allocatedMemory = NULL;
|
|
|
|
}
|
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & SFLAG_USERPTR) IWineD3DSurface_SetMem((IWineD3DSurface *)This, NULL);
|
2009-06-15 09:06:49 +02:00
|
|
|
if (This->overlay_dest) list_remove(&This->overlay_entry);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->palette9);
|
|
|
|
|
2011-03-01 09:47:56 +01:00
|
|
|
resource_cleanup(&This->resource);
|
2009-06-15 09:06:49 +02:00
|
|
|
}
|
|
|
|
|
2011-01-24 11:19:37 +01:00
|
|
|
static void gdi_surface_realize_palette(IWineD3DSurfaceImpl *surface)
|
|
|
|
{
|
2011-02-02 20:22:53 +01:00
|
|
|
struct wined3d_palette *palette = surface->palette;
|
2011-01-24 11:19:37 +01:00
|
|
|
|
|
|
|
TRACE("surface %p.\n", surface);
|
|
|
|
|
|
|
|
if (!palette) return;
|
|
|
|
|
|
|
|
if (surface->flags & SFLAG_DIBSECTION)
|
|
|
|
{
|
|
|
|
RGBQUAD col[256];
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
TRACE("Updating the DC's palette.\n");
|
|
|
|
|
|
|
|
for (i = 0; i < 256; ++i)
|
|
|
|
{
|
|
|
|
col[i].rgbRed = palette->palents[i].peRed;
|
|
|
|
col[i].rgbGreen = palette->palents[i].peGreen;
|
|
|
|
col[i].rgbBlue = palette->palents[i].peBlue;
|
|
|
|
col[i].rgbReserved = 0;
|
|
|
|
}
|
|
|
|
SetDIBColorTable(surface->hDC, 0, 256, col);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update the image because of the palette change. Some games like e.g.
|
|
|
|
* Red Alert call SetEntries a lot to implement fading. */
|
|
|
|
/* Tell the swapchain to update the screen. */
|
|
|
|
if (surface->container.type == WINED3D_CONTAINER_SWAPCHAIN)
|
|
|
|
{
|
|
|
|
IWineD3DSwapChainImpl *swapchain = surface->container.u.swapchain;
|
|
|
|
if (surface == swapchain->front_buffer)
|
|
|
|
{
|
|
|
|
x11_copy_to_screen(swapchain, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-24 11:19:38 +01:00
|
|
|
static HRESULT gdi_surface_draw_overlay(IWineD3DSurfaceImpl *surface)
|
|
|
|
{
|
|
|
|
FIXME("GDI surfaces can't draw overlays yet.\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2011-01-24 11:19:37 +01:00
|
|
|
static const struct wined3d_surface_ops gdi_surface_ops =
|
|
|
|
{
|
|
|
|
gdi_surface_realize_palette,
|
2011-01-24 11:19:38 +01:00
|
|
|
gdi_surface_draw_overlay,
|
2011-01-24 11:19:37 +01:00
|
|
|
};
|
|
|
|
|
2007-09-17 15:04:46 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* IWineD3DSurface::Release, GDI version
|
|
|
|
*
|
|
|
|
* In general a normal COM Release method, but the GDI version doesn't have
|
|
|
|
* to destroy all the GL things.
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2008-12-02 15:31:17 +01:00
|
|
|
static ULONG WINAPI IWineGDISurfaceImpl_Release(IWineD3DSurface *iface) {
|
2007-09-17 15:04:46 +02:00
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
|
|
|
|
ULONG ref = InterlockedDecrement(&This->resource.ref);
|
|
|
|
TRACE("(%p) : Releasing from %d\n", This, ref + 1);
|
|
|
|
|
2009-06-15 09:06:49 +02:00
|
|
|
if (!ref)
|
|
|
|
{
|
|
|
|
surface_gdi_cleanup(This);
|
2007-09-17 15:04:46 +02:00
|
|
|
|
2009-06-15 09:06:49 +02:00
|
|
|
TRACE("(%p) Released.\n", This);
|
2007-09-17 15:04:46 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
2009-06-15 09:06:49 +02:00
|
|
|
|
2007-09-17 15:04:46 +02:00
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
2006-05-13 22:22:16 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* IWineD3DSurface::PreLoad, GDI version
|
|
|
|
*
|
|
|
|
* This call is unsupported on GDI surfaces, if it's called something went
|
|
|
|
* wrong in the parent library. Write an informative warning
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2006-06-10 13:15:32 +02:00
|
|
|
static void WINAPI
|
2006-05-13 22:22:16 +02:00
|
|
|
IWineGDISurfaceImpl_PreLoad(IWineD3DSurface *iface)
|
|
|
|
{
|
|
|
|
ERR("(%p): PreLoad is not supported on X11 surfaces!\n", iface);
|
|
|
|
ERR("(%p): Most likely the parent library did something wrong.\n", iface);
|
|
|
|
ERR("(%p): Please report to wine-devel\n", iface);
|
|
|
|
}
|
|
|
|
|
2010-10-14 13:04:02 +02:00
|
|
|
static HRESULT WINAPI IWineGDISurfaceImpl_Map(IWineD3DSurface *iface,
|
2010-11-18 20:50:40 +01:00
|
|
|
WINED3DLOCKED_RECT *pLockedRect, const RECT *pRect, DWORD flags)
|
2006-05-13 22:22:16 +02:00
|
|
|
{
|
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
|
|
|
|
|
2007-11-08 22:44:34 +01:00
|
|
|
/* Already locked? */
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & SFLAG_LOCKED)
|
2007-11-08 22:44:34 +01:00
|
|
|
{
|
2009-04-23 09:24:26 +02:00
|
|
|
WARN("(%p) Surface already locked\n", This);
|
2007-11-08 22:44:34 +01:00
|
|
|
/* What should I return here? */
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
2010-11-12 13:12:04 +01:00
|
|
|
This->flags |= SFLAG_LOCKED;
|
2007-11-08 22:44:34 +01:00
|
|
|
|
2006-07-25 16:38:02 +02:00
|
|
|
if(!This->resource.allocatedMemory) {
|
|
|
|
/* This happens on gdi surfaces if the application set a user pointer and resets it.
|
|
|
|
* Recreate the DIB section
|
|
|
|
*/
|
2007-10-09 22:19:39 +02:00
|
|
|
IWineD3DBaseSurfaceImpl_CreateDIBSection(iface);
|
|
|
|
This->resource.allocatedMemory = This->dib.bitmap_data;
|
2006-05-13 22:22:16 +02:00
|
|
|
}
|
|
|
|
|
2010-11-18 20:50:40 +01:00
|
|
|
return IWineD3DBaseSurfaceImpl_Map(iface, pLockedRect, pRect, flags);
|
2006-05-13 22:22:16 +02:00
|
|
|
}
|
|
|
|
|
2010-10-14 13:04:02 +02:00
|
|
|
static HRESULT WINAPI IWineGDISurfaceImpl_Unmap(IWineD3DSurface *iface)
|
2006-05-13 22:22:16 +02:00
|
|
|
{
|
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (!(This->flags & SFLAG_LOCKED))
|
2006-05-13 22:22:16 +02:00
|
|
|
{
|
2010-10-14 13:04:02 +02:00
|
|
|
WARN("Trying to unmap unmapped surfaces %p.\n", iface);
|
2008-12-18 16:43:06 +01:00
|
|
|
return WINEDDERR_NOTLOCKED;
|
2006-05-13 22:22:16 +02:00
|
|
|
}
|
|
|
|
|
2008-08-05 21:23:00 +02:00
|
|
|
/* Tell the swapchain to update the screen */
|
2010-08-16 20:00:27 +02:00
|
|
|
if (This->container.type == WINED3D_CONTAINER_SWAPCHAIN)
|
2008-10-16 11:52:54 +02:00
|
|
|
{
|
2010-08-16 20:00:27 +02:00
|
|
|
IWineD3DSwapChainImpl *swapchain = This->container.u.swapchain;
|
2010-04-26 21:33:00 +02:00
|
|
|
if (This == swapchain->front_buffer)
|
2009-06-27 21:35:24 +02:00
|
|
|
{
|
|
|
|
x11_copy_to_screen(swapchain, &This->lockedRect);
|
|
|
|
}
|
2006-05-13 22:22:16 +02:00
|
|
|
}
|
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
This->flags &= ~SFLAG_LOCKED;
|
2006-05-13 22:22:16 +02:00
|
|
|
memset(&This->lockedRect, 0, sizeof(RECT));
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* IWineD3DSurface::Flip, GDI version
|
|
|
|
*
|
|
|
|
* Flips 2 flipping enabled surfaces. Determining the 2 targets is done by
|
|
|
|
* the parent library. This implementation changes the data pointers of the
|
|
|
|
* surfaces and copies the new front buffer content to the screen
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* override: Flipping target(e.g. back buffer)
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* WINED3D_OK on success
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2010-11-18 20:50:40 +01:00
|
|
|
static HRESULT WINAPI IWineGDISurfaceImpl_Flip(IWineD3DSurface *iface, IWineD3DSurface *override, DWORD flags)
|
2006-05-13 22:22:16 +02:00
|
|
|
{
|
2010-08-16 20:00:27 +02:00
|
|
|
IWineD3DSurfaceImpl *surface = (IWineD3DSurfaceImpl *)iface;
|
|
|
|
IWineD3DSwapChainImpl *swapchain;
|
2008-08-05 21:23:00 +02:00
|
|
|
HRESULT hr;
|
2006-05-13 22:22:16 +02:00
|
|
|
|
2010-08-16 20:00:27 +02:00
|
|
|
if (surface->container.type != WINED3D_CONTAINER_SWAPCHAIN)
|
2008-10-16 11:52:54 +02:00
|
|
|
{
|
2008-08-05 21:23:00 +02:00
|
|
|
ERR("Flipped surface is not on a swapchain\n");
|
|
|
|
return WINEDDERR_NOTFLIPPABLE;
|
2006-07-05 18:35:21 +02:00
|
|
|
}
|
|
|
|
|
2010-08-16 20:00:27 +02:00
|
|
|
swapchain = surface->container.u.swapchain;
|
2010-04-06 20:05:18 +02:00
|
|
|
hr = IWineD3DSwapChain_Present((IWineD3DSwapChain *)swapchain,
|
|
|
|
NULL, NULL, swapchain->win_handle, NULL, 0);
|
2010-08-16 20:00:27 +02:00
|
|
|
|
2008-08-05 21:23:00 +02:00
|
|
|
return hr;
|
2006-05-13 22:22:16 +02:00
|
|
|
}
|
|
|
|
|
2008-12-02 15:31:17 +01:00
|
|
|
static HRESULT WINAPI IWineGDISurfaceImpl_GetDC(IWineD3DSurface *iface, HDC *pHDC) {
|
2007-09-17 14:23:13 +02:00
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
|
|
|
|
WINED3DLOCKED_RECT lock;
|
|
|
|
HRESULT hr;
|
|
|
|
RGBQUAD col[256];
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n",This,pHDC);
|
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (!(This->flags & SFLAG_DIBSECTION))
|
2009-09-05 16:37:19 +02:00
|
|
|
{
|
|
|
|
WARN("DC not supported on this surface\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & SFLAG_USERPTR)
|
|
|
|
{
|
2007-09-17 14:23:13 +02:00
|
|
|
ERR("Not supported on surfaces with an application-provided surfaces\n");
|
|
|
|
return WINEDDERR_NODC;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Give more detailed info for ddraw */
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & SFLAG_DCINUSE)
|
2007-09-17 14:23:13 +02:00
|
|
|
return WINEDDERR_DCALREADYCREATED;
|
|
|
|
|
|
|
|
/* Can't GetDC if the surface is locked */
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & SFLAG_LOCKED)
|
2007-09-17 14:23:13 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
|
|
|
memset(&lock, 0, sizeof(lock)); /* To be sure */
|
|
|
|
|
|
|
|
/* Should have a DIB section already */
|
|
|
|
|
2010-10-14 13:04:02 +02:00
|
|
|
/* Map the surface. */
|
|
|
|
hr = IWineD3DSurface_Map(iface, &lock, NULL, 0);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
ERR("IWineD3DSurface_Map failed, hr %#x.\n", hr);
|
2007-09-17 14:23:13 +02:00
|
|
|
/* keep the dib section */
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2010-08-30 20:29:49 +02:00
|
|
|
if (This->resource.format->id == WINED3DFMT_P8_UINT
|
|
|
|
|| This->resource.format->id == WINED3DFMT_P8_UINT_A8_UNORM)
|
2009-03-13 10:44:18 +01:00
|
|
|
{
|
2007-09-17 14:23:13 +02:00
|
|
|
unsigned int n;
|
2008-12-01 15:32:15 +01:00
|
|
|
const PALETTEENTRY *pal = NULL;
|
2007-09-17 14:23:13 +02:00
|
|
|
|
2008-03-25 01:03:55 +01:00
|
|
|
if(This->palette) {
|
|
|
|
pal = This->palette->palents;
|
2007-09-17 14:23:13 +02:00
|
|
|
} else {
|
2008-08-05 21:23:00 +02:00
|
|
|
IWineD3DSurfaceImpl *dds_primary;
|
|
|
|
IWineD3DSwapChainImpl *swapchain;
|
2011-01-19 19:20:12 +01:00
|
|
|
swapchain = This->resource.device->swapchains[0];
|
2010-04-26 21:33:00 +02:00
|
|
|
dds_primary = swapchain->front_buffer;
|
2008-03-25 01:03:55 +01:00
|
|
|
if (dds_primary && dds_primary->palette)
|
|
|
|
pal = dds_primary->palette->palents;
|
|
|
|
}
|
2007-09-17 14:23:13 +02:00
|
|
|
|
2008-03-25 01:03:55 +01:00
|
|
|
if (pal) {
|
2007-09-17 14:23:13 +02:00
|
|
|
for (n=0; n<256; n++) {
|
2008-03-25 01:03:55 +01:00
|
|
|
col[n].rgbRed = pal[n].peRed;
|
|
|
|
col[n].rgbGreen = pal[n].peGreen;
|
|
|
|
col[n].rgbBlue = pal[n].peBlue;
|
2007-09-17 14:23:13 +02:00
|
|
|
col[n].rgbReserved = 0;
|
|
|
|
}
|
2008-03-25 01:03:55 +01:00
|
|
|
SetDIBColorTable(This->hDC, 0, 256, col);
|
2007-09-17 14:23:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*pHDC = This->hDC;
|
|
|
|
TRACE("returning %p\n",*pHDC);
|
2010-11-12 13:12:04 +01:00
|
|
|
This->flags |= SFLAG_DCINUSE;
|
2007-09-17 14:23:13 +02:00
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2008-12-02 15:31:17 +01:00
|
|
|
static HRESULT WINAPI IWineGDISurfaceImpl_ReleaseDC(IWineD3DSurface *iface, HDC hDC) {
|
2007-09-17 12:53:34 +02:00
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n",This,hDC);
|
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (!(This->flags & SFLAG_DCINUSE))
|
2008-12-16 00:01:11 +01:00
|
|
|
return WINEDDERR_NODC;
|
2007-09-17 12:53:34 +02:00
|
|
|
|
|
|
|
if (This->hDC !=hDC) {
|
|
|
|
WARN("Application tries to release an invalid DC(%p), surface dc is %p\n", hDC, This->hDC);
|
2008-12-16 00:01:11 +01:00
|
|
|
return WINEDDERR_NODC;
|
2007-09-17 12:53:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* we locked first, so unlock now */
|
2010-10-14 13:04:02 +02:00
|
|
|
IWineD3DSurface_Unmap(iface);
|
2007-09-17 12:53:34 +02:00
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
This->flags &= ~SFLAG_DCINUSE;
|
2007-09-17 12:53:34 +02:00
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2006-05-13 22:22:16 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* IWineD3DSurface::PrivateSetup, GDI version
|
|
|
|
*
|
|
|
|
* Initializes the GDI surface, aka creates the DIB section we render to
|
|
|
|
* The DIB section creation is done by calling GetDC, which will create the
|
|
|
|
* section and releasing the dc to allow the app to use it. The dib section
|
|
|
|
* will stay until the surface is released
|
|
|
|
*
|
|
|
|
* GDI surfaces do not need to be a power of 2 in size, so the pow2 sizes
|
|
|
|
* are set to the real sizes to save memory. The NONPOW2 flag is unset to
|
|
|
|
* avoid confusion in the shared surface code.
|
|
|
|
*
|
|
|
|
* Returns:
|
2007-02-14 23:30:40 +01:00
|
|
|
* WINED3D_OK on success
|
2006-05-13 22:22:16 +02:00
|
|
|
* The return values of called methods on failure
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2008-12-02 15:31:17 +01:00
|
|
|
static HRESULT WINAPI
|
2006-05-13 22:22:16 +02:00
|
|
|
IWineGDISurfaceImpl_PrivateSetup(IWineD3DSurface *iface)
|
|
|
|
{
|
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
|
2009-09-05 16:37:19 +02:00
|
|
|
HRESULT hr;
|
2006-05-13 22:22:16 +02:00
|
|
|
|
2011-01-24 11:19:37 +01:00
|
|
|
This->surface_ops = &gdi_surface_ops;
|
|
|
|
|
2006-10-05 17:56:54 +02:00
|
|
|
if(This->resource.usage & WINED3DUSAGE_OVERLAY)
|
|
|
|
{
|
|
|
|
ERR("(%p) Overlays not yet supported by GDI surfaces\n", This);
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
2009-09-05 16:37:19 +02:00
|
|
|
|
2006-05-29 10:53:43 +02:00
|
|
|
/* Sysmem textures have memory already allocated -
|
|
|
|
* release it, this avoids an unnecessary memcpy
|
|
|
|
*/
|
2009-09-05 16:37:19 +02:00
|
|
|
hr = IWineD3DBaseSurfaceImpl_CreateDIBSection(iface);
|
|
|
|
if(SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->resource.heapMemory);
|
|
|
|
This->resource.heapMemory = NULL;
|
|
|
|
This->resource.allocatedMemory = This->dib.bitmap_data;
|
|
|
|
}
|
2006-05-29 10:53:43 +02:00
|
|
|
|
2006-05-13 22:22:16 +02:00
|
|
|
/* We don't mind the nonpow2 stuff in GDI */
|
2011-03-08 19:41:07 +01:00
|
|
|
This->pow2Width = This->resource.width;
|
|
|
|
This->pow2Height = This->resource.height;
|
2006-06-01 01:13:36 +02:00
|
|
|
|
2006-05-13 22:22:16 +02:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2008-12-02 15:31:17 +01:00
|
|
|
static HRESULT WINAPI IWineGDISurfaceImpl_SetMem(IWineD3DSurface *iface, void *Mem) {
|
2007-09-17 15:16:37 +02:00
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
|
|
|
|
|
|
|
|
/* Render targets depend on their hdc, and we can't create an hdc on a user pointer */
|
|
|
|
if(This->resource.usage & WINED3DUSAGE_RENDERTARGET) {
|
|
|
|
ERR("Not supported on render targets\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & (SFLAG_LOCKED | SFLAG_DCINUSE))
|
|
|
|
{
|
2007-09-17 15:16:37 +02:00
|
|
|
WARN("Surface is locked or the HDC is in use\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(Mem && Mem != This->resource.allocatedMemory) {
|
|
|
|
void *release = NULL;
|
|
|
|
|
|
|
|
/* Do I have to copy the old surface content? */
|
2010-11-12 13:12:04 +01:00
|
|
|
if (This->flags & SFLAG_DIBSECTION)
|
|
|
|
{
|
2007-09-17 15:16:37 +02:00
|
|
|
/* Release the DC. No need to hold the critical section for the update
|
|
|
|
* Thread because this thread runs only on front buffers, but this method
|
|
|
|
* fails for render targets in the check above.
|
|
|
|
*/
|
|
|
|
SelectObject(This->hDC, This->dib.holdbitmap);
|
|
|
|
DeleteDC(This->hDC);
|
|
|
|
/* Release the DIB section */
|
|
|
|
DeleteObject(This->dib.DIBsection);
|
|
|
|
This->dib.bitmap_data = NULL;
|
|
|
|
This->resource.allocatedMemory = NULL;
|
|
|
|
This->hDC = NULL;
|
2010-11-12 13:12:04 +01:00
|
|
|
This->flags &= ~SFLAG_DIBSECTION;
|
|
|
|
}
|
|
|
|
else if(!(This->flags & SFLAG_USERPTR))
|
|
|
|
{
|
2007-09-17 15:16:37 +02:00
|
|
|
release = This->resource.allocatedMemory;
|
|
|
|
}
|
|
|
|
This->resource.allocatedMemory = Mem;
|
2010-11-12 13:12:04 +01:00
|
|
|
This->flags |= SFLAG_USERPTR | SFLAG_INSYSMEM;
|
2007-09-17 15:16:37 +02:00
|
|
|
|
|
|
|
/* Now free the old memory if any */
|
|
|
|
HeapFree(GetProcessHeap(), 0, release);
|
2010-10-14 13:04:02 +02:00
|
|
|
}
|
2010-11-12 13:12:04 +01:00
|
|
|
else if (This->flags & SFLAG_USERPTR)
|
2010-10-14 13:04:02 +02:00
|
|
|
{
|
|
|
|
/* Map() and GetDC() will re-create the dib section and allocated memory. */
|
2007-09-17 15:16:37 +02:00
|
|
|
This->resource.allocatedMemory = NULL;
|
2010-11-12 13:12:04 +01:00
|
|
|
This->flags &= ~SFLAG_USERPTR;
|
2007-09-17 15:16:37 +02:00
|
|
|
}
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2008-02-25 11:18:03 +01:00
|
|
|
static WINED3DSURFTYPE WINAPI IWineGDISurfaceImpl_GetImplType(IWineD3DSurface *iface) {
|
|
|
|
return SURFACE_GDI;
|
|
|
|
}
|
|
|
|
|
2007-09-16 16:27:58 +02:00
|
|
|
/* FIXME: This vtable should not use any IWineD3DSurface* implementation functions,
|
|
|
|
* only IWineD3DBaseSurface and IWineGDISurface ones.
|
|
|
|
*/
|
2006-05-13 22:22:16 +02:00
|
|
|
const IWineD3DSurfaceVtbl IWineGDISurface_Vtbl =
|
|
|
|
{
|
|
|
|
/* IUnknown */
|
2007-09-16 13:29:44 +02:00
|
|
|
IWineD3DBaseSurfaceImpl_QueryInterface,
|
2007-09-16 13:42:18 +02:00
|
|
|
IWineD3DBaseSurfaceImpl_AddRef,
|
2007-09-17 15:04:46 +02:00
|
|
|
IWineGDISurfaceImpl_Release,
|
2006-05-13 22:22:16 +02:00
|
|
|
/* IWineD3DResource */
|
2007-09-16 13:42:18 +02:00
|
|
|
IWineD3DBaseSurfaceImpl_GetParent,
|
|
|
|
IWineD3DBaseSurfaceImpl_SetPrivateData,
|
|
|
|
IWineD3DBaseSurfaceImpl_GetPrivateData,
|
|
|
|
IWineD3DBaseSurfaceImpl_FreePrivateData,
|
|
|
|
IWineD3DBaseSurfaceImpl_SetPriority,
|
|
|
|
IWineD3DBaseSurfaceImpl_GetPriority,
|
2006-05-13 22:22:16 +02:00
|
|
|
IWineGDISurfaceImpl_PreLoad,
|
2007-09-16 13:42:18 +02:00
|
|
|
IWineD3DBaseSurfaceImpl_GetType,
|
2006-05-13 22:22:16 +02:00
|
|
|
/* IWineD3DSurface */
|
2011-03-01 09:47:56 +01:00
|
|
|
IWineD3DBaseSurfaceImpl_GetResource,
|
2007-09-16 14:03:39 +02:00
|
|
|
IWineD3DBaseSurfaceImpl_GetDesc,
|
2010-10-14 13:04:02 +02:00
|
|
|
IWineGDISurfaceImpl_Map,
|
|
|
|
IWineGDISurfaceImpl_Unmap,
|
2007-09-17 14:23:13 +02:00
|
|
|
IWineGDISurfaceImpl_GetDC,
|
2007-09-17 12:53:34 +02:00
|
|
|
IWineGDISurfaceImpl_ReleaseDC,
|
2006-05-13 22:22:16 +02:00
|
|
|
IWineGDISurfaceImpl_Flip,
|
2007-09-17 16:03:21 +02:00
|
|
|
IWineD3DBaseSurfaceImpl_Blt,
|
2007-09-16 14:03:39 +02:00
|
|
|
IWineD3DBaseSurfaceImpl_GetBltStatus,
|
|
|
|
IWineD3DBaseSurfaceImpl_GetFlipStatus,
|
|
|
|
IWineD3DBaseSurfaceImpl_IsLost,
|
|
|
|
IWineD3DBaseSurfaceImpl_Restore,
|
2007-09-17 16:03:21 +02:00
|
|
|
IWineD3DBaseSurfaceImpl_BltFast,
|
2007-09-16 16:27:58 +02:00
|
|
|
IWineD3DBaseSurfaceImpl_GetPalette,
|
|
|
|
IWineD3DBaseSurfaceImpl_SetPalette,
|
|
|
|
IWineD3DBaseSurfaceImpl_SetColorKey,
|
|
|
|
IWineD3DBaseSurfaceImpl_GetPitch,
|
2007-09-17 15:16:37 +02:00
|
|
|
IWineGDISurfaceImpl_SetMem,
|
2007-09-16 16:27:58 +02:00
|
|
|
IWineD3DBaseSurfaceImpl_SetOverlayPosition,
|
|
|
|
IWineD3DBaseSurfaceImpl_GetOverlayPosition,
|
|
|
|
IWineD3DBaseSurfaceImpl_UpdateOverlayZOrder,
|
|
|
|
IWineD3DBaseSurfaceImpl_UpdateOverlay,
|
|
|
|
IWineD3DBaseSurfaceImpl_SetClipper,
|
|
|
|
IWineD3DBaseSurfaceImpl_GetClipper,
|
2006-05-13 22:22:16 +02:00
|
|
|
/* Internal use: */
|
2007-09-16 16:49:02 +02:00
|
|
|
IWineD3DBaseSurfaceImpl_SetFormat,
|
2007-10-09 22:17:59 +02:00
|
|
|
IWineGDISurfaceImpl_PrivateSetup,
|
2008-08-01 20:12:18 +02:00
|
|
|
IWineGDISurfaceImpl_GetImplType,
|
2006-05-13 22:22:16 +02:00
|
|
|
};
|