Skip to content

Commit d2450da

Browse files
committed
Total simplification....let matoya fix itself.
1 parent c014061 commit d2450da

File tree

11 files changed

+40
-149
lines changed

11 files changed

+40
-149
lines changed

GNUmakefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ OBJS = \
2424
src/async.o \
2525
src/crypto.o \
2626
src/dtls.o \
27-
src/error.o \
2827
src/file.o \
2928
src/hash.o \
3029
src/http.o \

makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ OBJS = \
2727
src\async.obj \
2828
src\crypto.obj \
2929
src\dtls.obj \
30-
src\error.obj \
3130
src\file.obj \
3231
src\hash.obj \
3332
src\http.obj \

src/error.c

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/error.h

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/matoya.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,6 @@ typedef bool (*MTY_MenuItemCheckedFunc)(void *opaque);
7777
typedef intptr_t (*MTY_WMsgFunc)(MTY_App *app, MTY_Window window, void *hwnd, uint32_t msg,
7878
intptr_t wparam, uintptr_t lparam, bool *shouldReturn, void *opaque);
7979

80-
/// @brief Error codes indicating the current state of the platform.
81-
/// @details Warnings are positive, errors are negative, 0 (::MTY_ERROR_OK) means no error.
82-
typedef enum {
83-
MTY_ERROR_OK = 0, ///< No errors.
84-
MTY_ERROR_GFX_INVISIBLE_CONTENT = 11, ///< Warning from the gfx driver that rendered content is hidden (for example, when app is in the UAC prompt on Windows)
85-
MTY_ERROR_GFX_REVISIBLE_CONTENT = 12, ///< Notice from the gfx driver that rendered content that was hidden is now visible
86-
MTY_ERROR_GFX_ERROR = -11, ///< Generic gfx error
87-
MTY_ERROR_GFX_DEVICE_REMOVED = -21, ///< Generally indicates that the display was unplugged or disabled abruptly
88-
MTY_ERROR_MAKE_32 = INT32_MAX,
89-
} MTY_Error;
90-
9180
/// @brief 3D graphics APIs.
9281
typedef enum {
9382
MTY_GFX_NONE = 0, ///< No 3D graphics API.
@@ -2628,11 +2617,6 @@ MTY_ThreadDetach(MTY_ThreadFunc func, void *opaque);
26282617
MTY_EXPORT int64_t
26292618
MTY_ThreadGetID(MTY_Thread *ctx);
26302619

2631-
/// @brief Get the next error code for the given thread.
2632-
/// @param ctx An MTY_Thread.
2633-
MTY_EXPORT MTY_Error
2634-
MTY_ThreadGetError(MTY_Thread *ctx);
2635-
26362620
/// @brief Create an MTY_Mutex for synchronization.
26372621
/// @details A mutex can be locked by only one thread at a time. Other threads trying
26382622
/// to take the same mutex will block until it becomes unlocked.

src/thread.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,7 @@
1010

1111
#include "rwlock.h"
1212
#include "tlocal.h"
13-
#include "error.h"
1413

15-
// Thread
16-
17-
MTY_Error MTY_ThreadGetError(MTY_Thread *ctx)
18-
{
19-
// `ctx` is not used since errors are managed via tlocal state
20-
21-
MTY_Error e = MTY_ERROR_OK;
22-
error_local_get_next_error(&e);
23-
return e;
24-
}
2514

2615
// RWLock
2716

src/unix/apple/gfx/metal-ui.m

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,3 @@ void mty_metal_ui_destroy(struct gfx_ui **gfx_ui, MTY_Device *device)
236236
MTY_Free(ctx);
237237
*gfx_ui = NULL;
238238
}
239-
240-
int32_t mty_metal_ui_get_error(struct gfx_ui *gfx_ui)
241-
{
242-
return 0;
243-
}

src/windows/gfx/d3d11-ctx.c

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ GFX_CTX_PROTOTYPES(_d3d11_)
1212
#include "gfx/sync.h"
1313
#include "dxgi-sync.h"
1414

15-
#include "d3d11-error.h"
16-
1715
#define DXGI_FATAL(e) ( \
1816
(e) == DXGI_ERROR_DEVICE_REMOVED || \
1917
(e) == DXGI_ERROR_DRIVER_INTERNAL_ERROR || \
@@ -24,6 +22,7 @@ GFX_CTX_PROTOTYPES(_d3d11_)
2422
#define D3D11_CTX_WAIT 2000
2523

2624
struct d3d11_ctx {
25+
bool ready;
2726
HWND hwnd;
2827
struct sync sync;
2928
struct dxgi_sync *dxgi_sync;
@@ -49,6 +48,8 @@ static void d3d11_ctx_get_size(struct d3d11_ctx *ctx, uint32_t *width, uint32_t
4948

5049
static void d3d11_ctx_free(struct d3d11_ctx *ctx)
5150
{
51+
ctx->ready = false;
52+
5253
if (ctx->back_buffer)
5354
ID3D11RenderTargetView_Release(ctx->back_buffer);
5455

@@ -190,12 +191,18 @@ static bool d3d11_ctx_init(struct d3d11_ctx *ctx)
190191
if (device2)
191192
IDXGIDevice2_Release(device2);
192193

193-
if (e != S_OK) {
194-
d3d11_push_local_error(e);
194+
ctx->ready = e == S_OK;
195+
196+
if (!ctx->ready)
195197
d3d11_ctx_free(ctx);
196-
}
197198

198-
return e == S_OK;
199+
return ctx->ready;
200+
}
201+
202+
static bool d3d11_ctx_reinit(struct d3d11_ctx *ctx)
203+
{
204+
d3d11_ctx_free(ctx);
205+
return d3d11_ctx_init(ctx);
199206
}
200207

201208
int32_t mty_d3d11_error_handler_default(int32_t e1, int32_t e2, void *opaque)
@@ -247,18 +254,27 @@ MTY_Device *mty_d3d11_ctx_get_device(struct gfx_ctx *gfx_ctx)
247254
{
248255
struct d3d11_ctx *ctx = (struct d3d11_ctx *) gfx_ctx;
249256

257+
if (!ctx->ready)
258+
d3d11_ctx_reinit(ctx);
259+
250260
return (MTY_Device *) ctx->device;
251261
}
252262

253263
MTY_Context *mty_d3d11_ctx_get_context(struct gfx_ctx *gfx_ctx)
254264
{
255265
struct d3d11_ctx *ctx = (struct d3d11_ctx *) gfx_ctx;
256266

267+
if (!ctx->ready)
268+
d3d11_ctx_reinit(ctx);
269+
257270
return (MTY_Context *) ctx->context;
258271
}
259272

260273
static void d3d11_ctx_refresh(struct d3d11_ctx *ctx)
261274
{
275+
if (!ctx->ready && !d3d11_ctx_reinit(ctx))
276+
return;
277+
262278
uint32_t width = ctx->width;
263279
uint32_t height = ctx->height;
264280

@@ -275,10 +291,7 @@ static void d3d11_ctx_refresh(struct d3d11_ctx *ctx)
275291

276292
if (DXGI_FATAL(e)) {
277293
MTY_Log("'IDXGISwapChain2_ResizeBuffers' failed with HRESULT 0x%X", e);
278-
d3d11_push_local_error(e);
279-
280-
d3d11_ctx_free(ctx);
281-
d3d11_ctx_init(ctx);
294+
ctx->ready = false;
282295
}
283296
}
284297
}
@@ -287,6 +300,9 @@ MTY_Surface *mty_d3d11_ctx_get_surface(struct gfx_ctx *gfx_ctx)
287300
{
288301
struct d3d11_ctx *ctx = (struct d3d11_ctx *) gfx_ctx;
289302

303+
if (!ctx->ready && !d3d11_ctx_reinit(ctx))
304+
return NULL;
305+
290306
HRESULT e = S_OK;
291307
ID3D11Resource *resource = NULL;
292308

@@ -314,9 +330,7 @@ MTY_Surface *mty_d3d11_ctx_get_surface(struct gfx_ctx *gfx_ctx)
314330
if (resource)
315331
ID3D11Resource_Release(resource);
316332

317-
if (e != S_OK)
318-
d3d11_push_local_error(e);
319-
333+
ctx->ready = e == S_OK;
320334

321335
return (MTY_Surface *) ctx->back_buffer;
322336
}
@@ -335,6 +349,9 @@ void mty_d3d11_ctx_present(struct gfx_ctx *gfx_ctx)
335349
{
336350
struct d3d11_ctx *ctx = (struct d3d11_ctx *) gfx_ctx;
337351

352+
if (!ctx->ready && !d3d11_ctx_reinit(ctx))
353+
return;
354+
338355
if (ctx->back_buffer) {
339356
int64_t interval = sync_next_interval(&ctx->sync);
340357
UINT flags = interval > 0 ? 0 : DXGI_PRESENT_ALLOW_TEARING;
@@ -356,16 +373,13 @@ void mty_d3d11_ctx_present(struct gfx_ctx *gfx_ctx)
356373

357374
if (DXGI_FATAL(e)) {
358375
MTY_Log("'IDXGISwapChain2_Present' failed with HRESULT 0x%X", e);
359-
d3d11_push_local_error(e);
360-
361-
d3d11_ctx_free(ctx);
362-
d3d11_ctx_init(ctx);
376+
ctx->ready = false;
363377

364378
} else {
365379
DWORD we = WaitForSingleObjectEx(ctx->waitable, D3D11_CTX_WAIT, TRUE);
366380
if (we != WAIT_OBJECT_0) {
367381
MTY_Log("'WaitForSingleObjectEx' failed with error 0x%X", we);
368-
d3d11_push_local_error(e);
382+
ctx->ready = false;
369383
}
370384
}
371385
}

src/windows/gfx/d3d11-error.h

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/windows/gfx/d3d11-ui.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@ static
1717
static
1818
#include "shaders/vsui.h"
1919

20-
#include "d3d11-error.h"
21-
2220
struct d3d11_ui_buffer {
2321
ID3D11Buffer *b;
2422
ID3D11Resource *res;
2523
uint32_t len;
2624
};
2725

2826
struct d3d11_ui {
27+
bool ready;
2928
struct d3d11_ui_buffer vb;
3029
struct d3d11_ui_buffer ib;
3130
ID3D11VertexShader *vs;
@@ -151,11 +150,10 @@ struct gfx_ui *mty_d3d11_ui_create(MTY_Device *device)
151150

152151
except:
153152

154-
if (e != S_OK) {
155-
d3d11_push_local_error(e);
156-
mty_d3d11_ui_destroy((struct gfx_ui **) &ctx, device);
157-
}
153+
ctx->ready = e == S_OK;
158154

155+
if (!ctx->ready)
156+
mty_d3d11_ui_destroy((struct gfx_ui **) &ctx, device);
159157

160158
return (struct gfx_ui *) ctx;
161159
}
@@ -201,6 +199,9 @@ bool mty_d3d11_ui_render(struct gfx_ui *gfx_ui, MTY_Device *device, MTY_Context
201199
const MTY_DrawData *dd, MTY_Hash *cache, MTY_Surface *dest)
202200
{
203201
struct d3d11_ui *ctx = (struct d3d11_ui *) gfx_ui;
202+
if (!ctx->ready)
203+
return false;
204+
204205
ID3D11Device *_device = (ID3D11Device *) device;
205206
ID3D11DeviceContext *_context = (ID3D11DeviceContext *) context;
206207
ID3D11RenderTargetView *_dest = (ID3D11RenderTargetView *) dest;
@@ -349,8 +350,7 @@ bool mty_d3d11_ui_render(struct gfx_ui *gfx_ui, MTY_Device *device, MTY_Context
349350

350351
except:
351352

352-
if (e != S_OK)
353-
d3d11_push_local_error(e);
353+
ctx->ready = e == S_OK;
354354

355355
return result;
356356
}
@@ -408,7 +408,6 @@ void *mty_d3d11_ui_create_texture(struct gfx_ui *gfx_ui, MTY_Device *device, con
408408
ID3D11Texture2D_Release(tex);
409409

410410
if (e != S_OK && srv) {
411-
d3d11_push_local_error(e);
412411
ID3D11ShaderResourceView_Release(srv);
413412
srv = NULL;
414413
}

0 commit comments

Comments
 (0)