Skip to content

Commit 8508eaf

Browse files
committed
fix buffer rendering
1 parent ca79922 commit 8508eaf

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

libs/d3d9/i915/idirect3d9.cpp

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <config.hpp>
22
#include <opendx.h>
33
#include "../idirect3d9.hpp"
4+
#include "cairo.h"
45
#include "gtk/gtk.h"
56
#include "idirect3d9.hpp"
67
#include <drm/drm.h>
@@ -212,6 +213,24 @@ export IDirect3DDevice9* IDirect3D9_i915::createDevice(
212213
// save_to_ppm("framebuffer.ppm", framebuffer, create_req.width, create_req.height, create_req.pitch);
213214
// munmap(framebuffer, create_req.pitch * create_req.height);
214215

216+
//experiment: set master if config allows it
217+
#ifdef DEBUG
218+
//if tty, force master
219+
const char* term = std::getenv("TERM");
220+
if (term != nullptr && strcmp(term, "linux") == 0) {
221+
DLOG(" Setting DRM master (experimental)");
222+
if (drmSetMaster(fd) != 0) {
223+
std::cerr << "\033[1;31m" //RED BOLD
224+
<< "[IDirect3D9_i915] ODX ERROR: Failed to set DRM master" << std::endl
225+
<< "[IDirect3D9_i915] IDirect3DC9::CreateDevice fails and returns NULL.\033[0;0m" << std::endl
226+
<< std::endl;
227+
// return nullptr;
228+
} else {
229+
DLOG(" DRM master set");
230+
}
231+
}
232+
#endif
233+
215234
// drmSetMaster(fd);
216235

217236
//inject framebuffer into HWND (through GdkD3DContext)
@@ -253,26 +272,26 @@ static void on_drawing_area_realize(GtkWidget *widget, gpointer user_data) {
253272
gtk_drawing_area_set_draw_func(
254273
GTK_DRAWING_AREA(widget),
255274
draw_function,
256-
&framebuffer,
275+
framebuffer,
257276
NULL
258277
);
259278
// gdk_draw_context_begin_draw(GDK_DRAW_CONTEXT(context), nullptr);
260279
// gdk_draw_context_end_draw(GDK_DRAW_CONTEXT(context));
261280
}
262281

263282
static void draw_function(GtkDrawingArea *area, cairo_t *cr, int width, int height, gpointer user_data) {
264-
265-
DLOG("libopendx.so: gdk_d3d_context_draw(): Drawing framebuffer to widget");
266-
uint32_t* framebuffer = *(uint32_t**)user_data;
283+
284+
DLOG("d3d9_i915.so: draw_function(): Drawing framebuffer to widget");
285+
uint32_t* framebuffer = (uint32_t*)user_data;
267286
if (framebuffer == nullptr) {
268-
DLOG("libopendx.so: gdk_d3d_context_draw(): No framebuffer set, skipping draw");
287+
DLOG("d3d9_i915.so: draw_function(): No framebuffer set, skipping draw");
269288
return;
270289
}
271290

272291
cairo_surface_t *cairo_surface =
273292
cairo_image_surface_create_for_data(
274293
(unsigned char*)framebuffer,
275-
CAIRO_FORMAT_ARGB32,
294+
CAIRO_FORMAT_RGB24,
276295
width,
277296
height,
278297
width * 4 // pitch (bytes per row)

0 commit comments

Comments
 (0)