Beispiel #1
0
ULONG __stdcall ddraw_surface_Release(IDirectDrawSurfaceImpl *This)
{
    printf("DirectDrawSurface::Release(This=%p)\n", This);

    This->Ref--;

    if(This->Ref == 0)
    {
        if(This->caps == DDSCAPS_PRIMARYSURFACE)
        {
            EnterCriticalSection(&ddraw->cs);
            ddraw->primary = NULL;
            LeaveCriticalSection(&ddraw->cs);
        }
        if(This->surface)
        {
            HeapFree(GetProcessHeap(), 0, This->surface);
        }
        if(This->palette)
        {
            IDirectDrawPalette_Release(This->palette);
        }
        HeapFree(GetProcessHeap(), 0, This);
        return 0;
    }
    return This->Ref;
}
Beispiel #2
0
//
// Release DirectDraw stuff before display mode change
//
VOID ReleaseChtuff (VOID)
{
	if (!DDr2)
		return;
	if (windclip)
	{
		IDirectDrawClipper_Release(windclip);
		windclip = NULL;
	}
	if (DDPalette)
	{
		IDirectDrawPalette_Release(DDPalette);
		DDPalette = NULL;
	}
	// If the app is fullscreen, the back buffer is attached to the
	// primary. Releasing the primary buffer will also release any
	// attached buffers, so explicitly releasing the back buffer is not
	// necessary.

	if (!bAppFullScreen && ScreenVirtual)
	{
		IDirectDrawSurface_Release(ScreenVirtual);   // release hidden surface
		ScreenVirtual = NULL;
	}
	if (ScreenReal)
	{
		IDirectDrawSurface_Release(ScreenReal);                      // and attached backbuffers for bAppFullScreen mode
		ScreenReal = NULL;
	}
}
Beispiel #3
0
void DDKillScreen()
{
	if (_lpDDClipper) IDirectDrawClipper_Release(_lpDDClipper);
	if (_lpDDPalette) IDirectDrawPalette_Release(_lpDDPalette);
	if (_lpDDSBack) IDirectDrawSurface_Release(_lpDDSBack);
	if (_lpDDSPrimary) {

		if (!GRMODEINFO(modex)) {
			DDBLTFX ddbltfx;
			HRESULT ddresult;

			memset(&ddbltfx, 0, sizeof(DDBLTFX));
	   	ddbltfx.dwSize = sizeof( ddbltfx );
		   ddbltfx.dwFillColor = (WORD)(BM_XRGB(0,0,0));

	   	ddresult = IDirectDrawSurface_Blt(
                            _lpDDSPrimary,  			// dest surface
                            NULL,                 	// dest rect
                            NULL,                  // src surface
                            NULL,                  // src rect
                            DDBLT_COLORFILL | DDBLT_WAIT,
                            &ddbltfx);
		}

		IDirectDrawSurface_Release(_lpDDSPrimary);
	}

	_lpDDClipper = NULL;
	_lpDDPalette = NULL;
	_lpDDSBack = NULL;
	_lpDDSPrimary = NULL;
}	
Beispiel #4
0
/* uninitialize DirectX */
static void DeInitDD(void)
{
    if (captured)
	ReleaseCapture(), captured = 0;	// free mouse

    // free DirectX objects
    if (lpSurfaces[0])
	IDirectDrawSurface_Release(lpSurfaces[0]);
    lpSurfaces[0] = NULL;
    if (BackSurface[0])
	IDirectDrawSurface_Release(BackSurface[0]);
    BackSurface[0] = NULL;
    if (BackSurface[1])
	IDirectDrawSurface_Release(BackSurface[1]);
    BackSurface[1] = NULL;
    if (dxPalette)
	IDirectDrawPalette_Release(dxPalette);
    dxPalette = NULL;
    if (lpDD2)
	IDirectDraw2_Release(lpDD2);
    lpDD2 = NULL;
    if (lpDD)
	IDirectDraw_Release(lpDD);
    lpDD = NULL;
    DeInitWindow();
    if (hModule != NULL)
	FreeLibrary(hModule), hModule = NULL;
    hWnd = NULL;
    directX = 0;
}
Beispiel #5
0
//
// Free the palette object
//
VOID DestroyDDPalette (VOID)
{
	if (DDPalette)
	{
		IDirectDrawPalette_Release(DDPalette);
		DDPalette = NULL;
	}
}
Beispiel #6
0
static void WINAPI VGA_DoExit(ULONG_PTR arg)
{
    VGA_DeinstallTimer();
    IDirectDrawSurface_SetPalette(lpddsurf,NULL);
    IDirectDrawSurface_Release(lpddsurf);
    lpddsurf=NULL;
    IDirectDrawPalette_Release(lpddpal);
    lpddpal=NULL;
    IDirectDraw_Release(lpddraw);
    lpddraw=NULL;
}
Beispiel #7
0
void DDKill()
{
//	Perform cleanup for full screen case and window case
	DDKillScreen();
	if (_lpDDPalette) IDirectDrawPalette_Release(_lpDDPalette);
	if (_lpDD) IDirectDraw_Release(_lpDD);

	_DDExclusive = _DDFullScreen = FALSE;
	_DDNumModes = 0;
	_DDLockCounter = 0;
	_lpDD = NULL;
}
Beispiel #8
0
static Bool
winDestroyColormapShadowDD (ColormapPtr pColormap)
{
  winScreenPriv(pColormap->pScreen);
  winCmapPriv(pColormap);
  HRESULT		ddrval = DD_OK;

  /*
   * Is colormap to be destroyed the default?
   *
   * Non-default colormaps should have had winUninstallColormap
   * called on them before we get here.  The default colormap
   * will not have had winUninstallColormap called on it.  Thus,
   * we need to handle the default colormap in a special way.
   */
  if (pColormap->flags & IsDefault)
    {
#if CYGDEBUG
      winDebug ("winDestroyColormapShadowDD - Destroying default "
	      "colormap\n");
#endif
      
      /*
       * FIXME: Walk the list of all screens, popping the default
       * palette out of each screen device context.
       */
      
      /* Pop the palette out of the primary surface */
      ddrval = IDirectDrawSurface2_SetPalette (pScreenPriv->pddsPrimary,
					       NULL);
      if (FAILED (ddrval))
	{
	  ErrorF ("winDestroyColormapShadowDD - Failed freeing the "
		  "default colormap DirectDraw palette.\n");
	  return FALSE;
	}

      /* Clear our private installed colormap pointer */
      pScreenPriv->pcmapInstalled = NULL;
    }
  
  /* Release the palette */
  IDirectDrawPalette_Release (pCmapPriv->lpDDPalette);
 
  /* Invalidate the colormap privates */
  pCmapPriv->lpDDPalette = NULL;

  return TRUE;
}
Beispiel #9
0
HRESULT __stdcall ddraw_surface_SetPalette(IDirectDrawSurfaceImpl *This, LPDIRECTDRAWPALETTE lpDDPalette)
{
    printf("DirectDrawSurface::SetPalette(This=%p, lpDDPalette=%p)\n", This, lpDDPalette);

    IDirectDrawPalette_AddRef(lpDDPalette);

    if(This->palette)
    {
        IDirectDrawPalette_Release(This->palette);
    }

    This->palette = (IDirectDrawPaletteImpl *)lpDDPalette;

    return DD_OK;
}
Beispiel #10
0
static void
DDDestroySurface(directx_priv *priv)
{
	int i;
	if (priv->lpddp != NULL) {
		IDirectDrawPalette_Release(priv->lpddp);
		priv->lpddp = NULL;
	}
	for (i = 0; i < GGI_DISPLAY_DIRECTX_FRAMES; ++i) {
		if (priv->lpbdds[i] != NULL) {
			IDirectDrawSurface_Release(priv->lpbdds[i]);
			priv->lpbdds[i] = NULL;
		}
	}
	if (priv->lppdds != NULL) {
		IDirectDrawSurface_Release(priv->lppdds);
		priv->lppdds = NULL;
	}
	if (priv->fullscreen) {
		IDirectDraw2_RestoreDisplayMode(priv->lpddext);
		IDirectDraw2_SetCooperativeLevel(priv->lpddext, priv->hWnd,
						DDSCL_NORMAL);
	}
}
Beispiel #11
0
static void test_ddraw_objects(void)
{
    HRESULT hr;
    unsigned long ref;
    IDirectDraw7 *DDraw7;
    IDirectDraw4 *DDraw4;
    IDirectDraw2 *DDraw2;
    IDirectDraw  *DDraw1;
    IDirectDrawPalette *palette;
    IDirectDrawSurface7 *surface;
    IDirectDrawSurface *surface1;
    IDirectDrawSurface4 *surface4;
    PALETTEENTRY Table[256];
    DDSURFACEDESC2 ddsd;

    hr = pDirectDrawCreateEx(NULL, (void **) &DDraw7, &IID_IDirectDraw7, NULL);
    ok(hr == DD_OK || hr==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreateEx returned: %x\n", hr);
    if(!DDraw7)
    {
        trace("Couldn't create DDraw interface, skipping tests\n");
        return;
    }

    hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirectDraw4, (void **) &DDraw4);
    ok(hr == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", hr);
    hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirectDraw2, (void **) &DDraw2);
    ok(hr == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", hr);
    hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirectDraw, (void **) &DDraw1);
    ok(hr == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", hr);

    ref = getRefcount( (IUnknown *) DDraw7);
    ok(ref == 1, "Got refcount %ld, expected 1\n", ref);

    /* Fails without a cooplevel */
    hr = IDirectDraw7_CreatePalette(DDraw7, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, NULL);
    ok(hr == DDERR_NOCOOPERATIVELEVELSET, "CreatePalette returned %08x\n", hr);

    /* This check is before the cooplevel check */
    hr = IDirectDraw7_CreatePalette(DDraw7, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, (void *) 0xdeadbeef);
    ok(hr == CLASS_E_NOAGGREGATION, "CreatePalette returned %08x\n", hr);

    hr = IDirectDraw7_SetCooperativeLevel(DDraw7, 0, DDSCL_NORMAL);
    ok(hr == DD_OK, "SetCooperativeLevel failed with %08x\n", hr);

    memset(&ddsd, 0, sizeof(ddsd));
    ddsd.dwSize = sizeof(ddsd);
    ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
    ddsd.dwWidth = 64;
    ddsd.dwHeight = 64;
    ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
    U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
    U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
    U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 8;

    hr = IDirectDraw7_CreateSurface(DDraw7, &ddsd, &surface, NULL);
    ok(hr == DD_OK, "CreateSurface failed with %08x\n", hr);

    /* DDraw refcount increased by 1 */
    ref = getRefcount( (IUnknown *) DDraw7);
    ok(ref == 2, "Got refcount %ld, expected 2\n", ref);

    /* Surface refcount starts with 1 */
    ref = getRefcount( (IUnknown *) surface);
    ok(ref == 1, "Got refcount %ld, expected 1\n", ref);

    hr = IDirectDraw7_CreatePalette(DDraw7, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, NULL);
    ok(hr == DD_OK, "CreatePalette returned %08x\n", hr);

    /* DDraw refcount increased by 1 */
    ref = getRefcount( (IUnknown *) DDraw7);
    ok(ref == 3, "Got refcount %ld, expected 3\n", ref);

    /* Palette starts with 1 */
    ref = getRefcount( (IUnknown *) palette);
    ok(ref == 1, "Got refcount %ld, expected 1\n", ref);

    /* Test attaching a palette to a surface */
    hr = IDirectDrawSurface7_SetPalette(surface, palette);
    ok(hr == DD_OK, "IDirectDrawSurface_SetPalette failed with %08x\n", hr);

    /* Palette refcount increased, surface stays the same */
    ref = getRefcount( (IUnknown *) palette);
    ok(ref == 2, "Got refcount %ld, expected 2\n", ref);
    ref = getRefcount( (IUnknown *) surface);
    ok(ref == 1, "Got refcount %ld, expected 1\n", ref);

    IDirectDrawSurface7_Release(surface);
    /* Increased before - decrease now */
    ref = getRefcount( (IUnknown *) DDraw7);
    ok(ref == 2, "Got refcount %ld, expected 2\n", ref);

    /* Releasing the surface detaches the palette */
    ref = getRefcount( (IUnknown *) palette);
    ok(ref == 1, "Got refcount %ld, expected 1\n", ref);

    IDirectDrawPalette_Release(palette);

    /* Increased before - decrease now */
    ref = getRefcount( (IUnknown *) DDraw7);
    ok(ref == 1, "Got refcount %ld, expected 1\n", ref);

    /* Not all interfaces are AddRefed when a palette is created */
    hr = IDirectDraw4_CreatePalette(DDraw4, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, NULL);
    ok(hr == DD_OK, "CreatePalette returned %08x\n", hr);
    ref = getRefcount( (IUnknown *) DDraw4);
    ok(ref == 2, "Got refcount %ld, expected 2\n", ref);
    IDirectDrawPalette_Release(palette);

    /* No addref here */
    hr = IDirectDraw2_CreatePalette(DDraw2, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, NULL);
    ok(hr == DD_OK, "CreatePalette returned %08x\n", hr);
    ref = getRefcount( (IUnknown *) DDraw2);
    ok(ref == 1, "Got refcount %ld, expected 1\n", ref);
    IDirectDrawPalette_Release(palette);

    /* No addref here */
    hr = IDirectDraw_CreatePalette(DDraw1, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, NULL);
    ok(hr == DD_OK, "CreatePalette returned %08x\n", hr);
    ref = getRefcount( (IUnknown *) DDraw1);
    ok(ref == 1, "Got refcount %ld, expected 1\n", ref);
    IDirectDrawPalette_Release(palette);

    /* Similar for surfaces */
    hr = IDirectDraw4_CreateSurface(DDraw4, &ddsd, &surface4, NULL);
    ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
    ref = getRefcount( (IUnknown *) DDraw4);
    ok(ref == 2, "Got refcount %ld, expected 2\n", ref);
    IDirectDrawSurface4_Release(surface4);

    ddsd.dwSize = sizeof(DDSURFACEDESC);
    hr = IDirectDraw2_CreateSurface(DDraw2, (DDSURFACEDESC *) &ddsd, &surface1, NULL);
    ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
    ref = getRefcount( (IUnknown *) DDraw2);
    ok(ref == 1, "Got refcount %ld, expected 1\n", ref);
    IDirectDrawSurface_Release(surface1);

    hr = IDirectDraw_CreateSurface(DDraw1, (DDSURFACEDESC *) &ddsd, &surface1, NULL);
    ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
    ref = getRefcount( (IUnknown *) DDraw1);
    ok(ref == 1, "Got refcount %ld, expected 1\n", ref);
    IDirectDrawSurface_Release(surface1);

    IDirectDraw7_Release(DDraw7);
    IDirectDraw4_Release(DDraw4);
    IDirectDraw2_Release(DDraw2);
    IDirectDraw_Release(DDraw1);
}
Beispiel #12
0
static int ResizeDD(int fullscreen)
{
    HRESULT ddrval;
    DDSURFACEDESC ddsd;
    /*DDCAPS2 ddscaps; */
    LPDIRECTDRAWCLIPPER pClipper;
    int dxwidth;
    int dxheight;
    int dxbpp;

    // free DirectX objects
    if (lpSurfaces[0])
	IDirectDrawSurface_Release(lpSurfaces[0]);
    lpSurfaces[0] = NULL;
    if (dxPalette)
	IDirectDrawPalette_Release(dxPalette);
    dxPalette = NULL;
    /* Set cooperative level */
    ddrval = IDirectDraw2_SetCooperativeLevel(lpDD2, hWnd,
					      fullscreen
					      ? (DDSCL_FULLSCREEN |
						 DDSCL_EXCLUSIVE |
						 DDSCL_ALLOWREBOOT)
					      : DDSCL_NORMAL);
    if (ddrval != DD_OK) {
	DeInitDD();
	x_error("Failed to set cooperative level");
	return 0;
    }

    if (fullscreen) {
	if (sscanf(dxsize, "%ix%ix%i", &dxwidth, &dxheight, &dxbpp) != 3) {
	    dxwidth = DXWIDTH;
	    dxheight = DXHEIGHT;
	    dxbpp = DXBPP;
	}
	displayX = dxwidth;
	displayY = dxheight;
	bitDepth = dxbpp;
	if (bitDepth < 10)
	    bitDepth = 8;
	if (bitDepth >= 10 && bitDepth < 20)
	    bitDepth = 16;
	if (bitDepth >= 20 && bitDepth < 28)
	    bitDepth = 24;
	if (bitDepth >= 32 && bitDepth < 32)
	    bitDepth = 32;

	/* set resolution and bit depth */
	ddrval =
	    IDirectDraw2_SetDisplayMode(lpDD2, displayX, displayY,
					bitDepth, 0, 0);
	if (ddrval != DD_OK) {
	    /* The display mode cannot be changed. 
	       The mode is either not supported or 
	       another application has exclusive mode.

	       Try 320x200x256 and 640x480x256 modes before giving up */
	    displayX = 320;
	    displayY = 200;
	    bitDepth = 8;
	    ddrval =
		IDirectDraw2_SetDisplayMode(lpDD2, displayX, displayY,
					    bitDepth, 0, 0);
	    if (ddrval != DD_OK) {
		displayY = 240;
		if (ddrval != DD_OK) {
		    displayX = 640;
		    displayY = 480;
		    ddrval =
			IDirectDraw2_SetDisplayMode(lpDD2, displayX,
						    displayY, bitDepth, 0,
						    0);
		    if (ddrval != DD_OK) {
			/* Bad luck... give up. */
			DeInitDD();
			return 0;
		    }
		}
	    }
	}
	SetRect(&rcViewport, 0, 0, displayX, displayY);
	rcScreen = rcViewport;
    } else {
	/* Get the dimensions of the viewport and screen bounds */
	GetClientRect(hWnd, &rcViewport);
	GetClientRect(hWnd, &rcScreen);
	ClientToScreen(hWnd, (POINT *) & rcScreen.left);
	ClientToScreen(hWnd, (POINT *) & rcScreen.right);
	/*bitDepth = GetDeviceCaps (hDC, BITSPIXEL); */

	/* Create clipper object for window */
	ddrval = IDirectDraw_CreateClipper(lpDD, 0, &pClipper, NULL);
	if (ddrval != DD_OK) {
	    DeInitDD();
	    x_error("Failed to create clipper object");
	    return 0;
	}
	/* Asociate it */
	IDirectDrawClipper_SetHWnd(pClipper, 0, hWnd);
    }
    /* Create the primary surface with one back buffer */
    CalculateBITMAPINFO();	// calculate BITMAPINFO structure

    memset(&ddsd, 0, sizeof(ddsd));
    ddsd.dwSize = sizeof(ddsd);
    ddsd.dwFlags = DDSD_CAPS;
    ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;

    ddrval = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpSurfaces[0], NULL);
    if (ddrval != DD_OK) {
	DeInitDD();
	x_error("Failed to create flipping surface");
	return 0;
    }

    if (!fullscreen) {
	IDirectDrawSurface_SetClipper(lpSurfaces[0], pClipper);
	IDirectDrawClipper_Release(pClipper);
	if (IDirectDrawSurface_GetSurfaceDesc(lpSurfaces[0], &ddsd) !=
	    DD_OK) {
	    DeInitDD();
	    x_error("Failed to get pixel format");
	    return 0;
	}
	bitDepth = ddsd.ddpfPixelFormat.u1.dwRGBBitCount;
    }

    if (bitDepth == 8) {
	/* create palette */
	ddrval =
	    IDirectDraw_CreatePalette(lpDD, DDPCAPS_8BIT,
				      (LPPALETTEENTRY) bmp->bmiColors,
				      &dxPalette, NULL);
	if (ddrval != DD_OK) {
	    DeInitDD();
	    x_error("Failed to create palette");
	    return 0;
	}

	/* set palette */
	IDirectDrawSurface_SetPalette(lpSurfaces[0], dxPalette);
    }
    if (fullscreen)
	SetCursor(NULL);
    needredraw = 1;
    return 1;

}
void DDReleasePalette( LPDIRECTDRAWPALETTE pPalette )
{
	Assert( pPalette != NULL );

	ATTEMPT( IDirectDrawPalette_Release( pPalette ) );
}