Skip to content

Commit

Permalink
[HACK] put together a release screen function to be used at a later t…
Browse files Browse the repository at this point in the history
…ime to implement ReleaseDC where it's not available
  • Loading branch information
aerisarn committed Feb 25, 2024
1 parent 239e0a2 commit a6cf6b2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
13 changes: 12 additions & 1 deletion src/gallium/frontends/wgl/stw_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,17 +313,22 @@ DrvDeleteContext(DHGLRC dhglrc)
{
struct stw_context *ctx ;
BOOL ret = false;
HDC drawDC = NULL;

if (!stw_dev)
return false;

stw_lock_contexts(stw_dev);
ctx = stw_lookup_context_locked(dhglrc);
handle_table_remove(stw_dev->ctx_table, dhglrc);
//we need to know if we are removing the last handle
dhglrc = handle_table_remove(stw_dev->ctx_table, dhglrc);
stw_unlock_contexts(stw_dev);


if (ctx) {
struct stw_context *curctx = stw_current_context();
drawDC = ctx->hDrawDC;


/* Unbind current if deleting current context. */
if (curctx == ctx)
Expand All @@ -333,6 +338,12 @@ DrvDeleteContext(DHGLRC dhglrc)
ret = true;
}

#ifdef _XBOX_UWP
//we can't releaseDC in this context. Maybe
if (NULL == dhglrc)
stw_destroy_screen(drawDC);
#endif

return ret;
}

Expand Down
22 changes: 22 additions & 0 deletions src/gallium/frontends/wgl/stw_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,28 @@ stw_init_screen(HDC hdc)
return stw_dev->screen != NULL;
}

void
stw_destroy_screen(HDC hdc)
{
stw_framebuffer_cleanup();

EnterCriticalSection(&stw_dev->screen_mutex);

if (stw_dev->screen_initialized) {
stw_dev->screen_initialized = false;
st_screen_destroy(stw_dev->fscreen);
stw_dev->screen->destroy(stw_dev->screen);
memset(stw_dev->fscreen, 0, sizeof(struct pipe_frontend_screen));
stw_dev->fscreen->get_param = stw_get_param;
}

LeaveCriticalSection(&stw_dev->screen_mutex);

util_dynarray_fini(&stw_dev->pixelformats);
stw_dev->pixelformat_count = 0;
ReleaseDC(WindowFromDC(hdc),hdc);
}

struct stw_device *
stw_get_device(void)
{
Expand Down
3 changes: 3 additions & 0 deletions src/gallium/frontends/wgl/stw_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ extern struct stw_device *stw_dev;
bool
stw_init_screen(HDC hdc);

void
stw_destroy_screen(HDC hdc);

struct stw_device *
stw_get_device(void);

Expand Down
7 changes: 5 additions & 2 deletions src/gallium/winsys/uwp/gdi_uwp.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "gdi_uwp.h"

#include "..\..\frontends\wgl\stw_pixelformat.h"
#include "..\..\frontends/wgl/stw_winsys.h"

#include <wrl.h>
#include <wrl/client.h>
Expand All @@ -14,6 +15,7 @@
#include <agile.h>
#include <concrt.h>


using namespace Windows::ApplicationModel;
using namespace Windows::ApplicationModel::Core;
using namespace Windows::ApplicationModel::Activation;
Expand All @@ -23,6 +25,8 @@ using namespace Windows::System;
using namespace Windows::Foundation;
using namespace Windows::Graphics::Display;

static int iPixelFormat = 0;

inline float ConvertDipsToPixels(float dips, float dpi)
{
static const float dipsPerInch = 96.0f;
Expand Down Expand Up @@ -71,11 +75,10 @@ ReleaseDC(
_In_opt_ HWND hWnd,
_In_ HDC hDC)
{
iPixelFormat = 0;
return 1;
}

static int iPixelFormat = 0;

int WINAPI GetPixelFormat(HDC hdc)
{
if (iPixelFormat == 0)
Expand Down

0 comments on commit a6cf6b2

Please sign in to comment.