diff --git a/internal/graphicsdriver/playstation5/graphics_playstation5.cpp b/internal/graphicsdriver/playstation5/graphics_playstation5.cpp index 45bcb8511..ad87d98ee 100644 --- a/internal/graphicsdriver/playstation5/graphics_playstation5.cpp +++ b/internal/graphicsdriver/playstation5/graphics_playstation5.cpp @@ -25,14 +25,15 @@ extern "C" ebitengine_Error ebitengine_NewImage(int *image, int width, return {}; } -extern "C" ebitengine_Error -ebitengine_ReadPixels(int image, ebitengine_PixelsArgs *args, int arg_count) { - return {}; -} +extern "C" void ebitengine_ReadPixels(int image, uint8_t *pixels, + ebitengine_Region region) {} -extern "C" ebitengine_Error -ebitengine_WritePixels(int image, const ebitengine_PixelsArgs *args, - int arg_count) { +extern "C" ebitengine_Error ebitengine_FlushReadPixels(int image) { return {}; } + +extern "C" void ebitengine_WritePixels(int image, const uint8_t *pixels, + ebitengine_Region region) {} + +extern "C" ebitengine_Error ebitengine_FlushWritePixels(int image) { return {}; } diff --git a/internal/graphicsdriver/playstation5/graphics_playstation5.go b/internal/graphicsdriver/playstation5/graphics_playstation5.go index 56d3c1669..754238738 100644 --- a/internal/graphicsdriver/playstation5/graphics_playstation5.go +++ b/internal/graphicsdriver/playstation5/graphics_playstation5.go @@ -180,38 +180,32 @@ func (i *Image) Dispose() { } func (i *Image) ReadPixels(args []graphicsdriver.PixelsArgs) error { - cArgs := make([]C.ebitengine_PixelsArgs, 0, len(args)) for _, a := range args { - cArgs = append(cArgs, C.ebitengine_PixelsArgs{ - min_x: C.int(a.Region.Min.X), - min_y: C.int(a.Region.Min.Y), - max_x: C.int(a.Region.Max.X), - max_y: C.int(a.Region.Max.Y), - pixels: (*C.uint8_t)(unsafe.Pointer(unsafe.SliceData(a.Pixels))), - }) + region := C.ebitengine_Region{ + min_x: C.int(a.Region.Min.X), + min_y: C.int(a.Region.Min.Y), + max_x: C.int(a.Region.Max.X), + max_y: C.int(a.Region.Max.Y), + } + C.ebitengine_ReadPixels(C.int(i.id), (*C.uint8_t)(unsafe.Pointer(unsafe.SliceData(a.Pixels))), region) } - defer runtime.KeepAlive(cArgs) - - if err := C.ebitengine_ReadPixels(C.int(i.id), unsafe.SliceData(cArgs), C.int(len(cArgs))); !C.ebitengine_IsErrorNil(&err) { + if err := C.ebitengine_FlushReadPixels(C.int(i.id)); !C.ebitengine_IsErrorNil(&err) { return newPlaystation5Error("(*playstation5.Image).ReadPixels", err) } return nil } func (i *Image) WritePixels(args []graphicsdriver.PixelsArgs) error { - cArgs := make([]C.ebitengine_PixelsArgs, 0, len(args)) for _, a := range args { - cArgs = append(cArgs, C.ebitengine_PixelsArgs{ - min_x: C.int(a.Region.Min.X), - min_y: C.int(a.Region.Min.Y), - max_x: C.int(a.Region.Max.X), - max_y: C.int(a.Region.Max.Y), - pixels: (*C.uint8_t)(unsafe.Pointer(unsafe.SliceData(a.Pixels))), - }) + region := C.ebitengine_Region{ + min_x: C.int(a.Region.Min.X), + min_y: C.int(a.Region.Min.Y), + max_x: C.int(a.Region.Max.X), + max_y: C.int(a.Region.Max.Y), + } + C.ebitengine_WritePixels(C.int(i.id), (*C.uint8_t)(unsafe.Pointer(unsafe.SliceData(a.Pixels))), region) } - defer runtime.KeepAlive(cArgs) - - if err := C.ebitengine_WritePixels(C.int(i.id), unsafe.SliceData(cArgs), C.int(len(cArgs))); !C.ebitengine_IsErrorNil(&err) { + if err := C.ebitengine_FlushWritePixels(C.int(i.id)); !C.ebitengine_IsErrorNil(&err) { return newPlaystation5Error("(*playstation5.Image).WritePixels", err) } return nil diff --git a/internal/graphicsdriver/playstation5/graphics_playstation5.h b/internal/graphicsdriver/playstation5/graphics_playstation5.h index 88709e491..46b30dcb7 100644 --- a/internal/graphicsdriver/playstation5/graphics_playstation5.h +++ b/internal/graphicsdriver/playstation5/graphics_playstation5.h @@ -34,13 +34,12 @@ static bool ebitengine_IsErrorNil(ebitengine_Error *err) { return err->message == NULL && err->code == 0; } -typedef struct ebitengine_PixelsArgs { - uint8_t *pixels; +typedef struct ebitengine_Region { int min_x; int min_y; int max_x; int max_y; -} ebitengine_PixelsArgs; +} ebitengine_Region; typedef struct ebitengine_DstRegion { int min_x; @@ -63,11 +62,12 @@ ebitengine_Error ebitengine_InitializeGraphics(void); ebitengine_Error ebitengine_NewImage(int *image, int width, int height); ebitengine_Error ebitengine_NewScreenFramebufferImage(int *image, int width, int height); -ebitengine_Error ebitengine_ReadPixels(int image, ebitengine_PixelsArgs *args, - int arg_count); -ebitengine_Error ebitengine_WritePixels(int image, - const ebitengine_PixelsArgs *args, - int arg_count); +void ebitengine_ReadPixels(int image, uint8_t *pixels, + ebitengine_Region region); +ebitengine_Error ebitengine_FlushReadPixels(int image); +void ebitengine_WritePixels(int image, const uint8_t *pixels, + ebitengine_Region region); +ebitengine_Error ebitengine_FlushWritePixels(int image); void ebitengine_DisposeImage(int id); void ebitengine_Begin();