libretro, add Pico pad overlay and storyware pages handling

This commit is contained in:
kub 2024-03-25 18:49:19 +01:00
parent 15cc45c0da
commit 5f9901e098
17 changed files with 3415 additions and 477 deletions

View file

@ -0,0 +1,92 @@
/* Copyright (C) 2010-2020 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (trans_stream.c).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <streams/trans_stream.h>
/**
* trans_stream_trans_full:
* @data : (optional) existing stream data, or a target
* for the new stream data to be saved
* @in : input data
* @in_size : input size
* @out : output data
* @out_size : output size
* @error : (optional) output for error code
*
* Perform a full transcoding from a source to a destination.
*/
bool trans_stream_trans_full(
struct trans_stream_backend *backend, void **data,
const uint8_t *in, uint32_t in_size,
uint8_t *out, uint32_t out_size,
enum trans_stream_error *error)
{
void *rdata;
bool ret;
uint32_t rd, wn;
if (data && *data)
rdata = *data;
else
{
if (!(rdata = backend->stream_new()))
{
if (error)
*error = TRANS_STREAM_ERROR_ALLOCATION_FAILURE;
return false;
}
}
backend->set_in(rdata, in, in_size);
backend->set_out(rdata, out, out_size);
ret = backend->trans(rdata, true, &rd, &wn, error);
if (data)
*data = rdata;
else
backend->stream_free(rdata);
return ret;
}
const struct trans_stream_backend* trans_stream_get_zlib_deflate_backend(void)
{
#if HAVE_ZLIB
return &zlib_deflate_backend;
#else
return NULL;
#endif
}
const struct trans_stream_backend* trans_stream_get_zlib_inflate_backend(void)
{
#if HAVE_ZLIB
return &zlib_inflate_backend;
#else
return NULL;
#endif
}
const struct trans_stream_backend* trans_stream_get_pipe_backend(void)
{
return &pipe_backend;
}

View file

@ -0,0 +1,111 @@
/* Copyright (C) 2010-2020 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (trans_stream_pipe.c).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdlib.h>
#include <string.h>
#include <streams/trans_stream.h>
struct pipe_trans_stream
{
const uint8_t *in;
uint8_t *out;
uint32_t in_size, out_size;
};
static void *pipe_stream_new(void)
{
struct pipe_trans_stream *stream =
(struct pipe_trans_stream*)malloc(sizeof(*stream));
if (!stream)
return NULL;
stream->in = NULL;
stream->out = NULL;
stream->in_size = 0;
stream->out_size = 0;
return stream;
}
static void pipe_stream_free(void *data)
{
free(data);
}
static void pipe_set_in(void *data, const uint8_t *in, uint32_t in_size)
{
struct pipe_trans_stream *p = (struct pipe_trans_stream *) data;
if (!p)
return;
p->in = in;
p->in_size = in_size;
}
static void pipe_set_out(void *data, uint8_t *out, uint32_t out_size)
{
struct pipe_trans_stream *p = (struct pipe_trans_stream *) data;
if (!p)
return;
p->out = out;
p->out_size = out_size;
}
static bool pipe_trans(
void *data, bool flush,
uint32_t *rd, uint32_t *wn,
enum trans_stream_error *error)
{
struct pipe_trans_stream *p = (struct pipe_trans_stream *) data;
if (p->out_size < p->in_size)
{
memcpy(p->out, p->in, p->out_size);
*rd = *wn = p->out_size;
p->in += p->out_size;
p->out += p->out_size;
*error = TRANS_STREAM_ERROR_BUFFER_FULL;
return false;
}
memcpy(p->out, p->in, p->in_size);
*rd = *wn = p->in_size;
p->in += p->in_size;
p->out += p->in_size;
*error = TRANS_STREAM_ERROR_NONE;
return true;
}
const struct trans_stream_backend pipe_backend = {
"pipe",
&pipe_backend,
pipe_stream_new,
pipe_stream_free,
NULL,
pipe_set_in,
pipe_set_out,
pipe_trans
};

View file

@ -0,0 +1,330 @@
/* Copyright (C) 2010-2020 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (trans_stream_zlib.c).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdlib.h>
#include <string.h>
#include <zlib.h>
#include <string/stdstring.h>
#include <streams/trans_stream.h>
struct zlib_trans_stream
{
z_stream z;
int ex; /* window_bits or level */
bool inited;
};
static void *zlib_deflate_stream_new(void)
{
struct zlib_trans_stream *ret = (struct zlib_trans_stream*)
malloc(sizeof(*ret));
if (!ret)
return NULL;
ret->inited = false;
ret->ex = 9;
ret->z.next_in = NULL;
ret->z.avail_in = 0;
ret->z.total_in = 0;
ret->z.next_out = NULL;
ret->z.avail_out = 0;
ret->z.total_out = 0;
ret->z.msg = NULL;
ret->z.state = NULL;
ret->z.zalloc = NULL;
ret->z.zfree = NULL;
ret->z.opaque = NULL;
ret->z.data_type = 0;
ret->z.adler = 0;
ret->z.reserved = 0;
return (void *)ret;
}
static void *zlib_inflate_stream_new(void)
{
struct zlib_trans_stream *ret = (struct zlib_trans_stream*)
malloc(sizeof(*ret));
if (!ret)
return NULL;
ret->inited = false;
ret->ex = MAX_WBITS;
ret->z.next_in = NULL;
ret->z.avail_in = 0;
ret->z.total_in = 0;
ret->z.next_out = NULL;
ret->z.avail_out = 0;
ret->z.total_out = 0;
ret->z.msg = NULL;
ret->z.state = NULL;
ret->z.zalloc = NULL;
ret->z.zfree = NULL;
ret->z.opaque = NULL;
ret->z.data_type = 0;
ret->z.adler = 0;
ret->z.reserved = 0;
return (void *)ret;
}
static void zlib_deflate_stream_free(void *data)
{
struct zlib_trans_stream *z = (struct zlib_trans_stream *) data;
if (!z)
return;
if (z->inited)
deflateEnd(&z->z);
free(z);
}
static void zlib_inflate_stream_free(void *data)
{
struct zlib_trans_stream *z = (struct zlib_trans_stream *) data;
if (!z)
return;
if (z->inited)
inflateEnd(&z->z);
if (z)
free(z);
}
static bool zlib_deflate_define(void *data, const char *prop, uint32_t val)
{
struct zlib_trans_stream *z = (struct zlib_trans_stream *) data;
if (string_is_equal(prop, "level"))
{
if (z)
z->ex = (int) val;
return true;
}
return false;
}
static bool zlib_inflate_define(void *data, const char *prop, uint32_t val)
{
struct zlib_trans_stream *z = (struct zlib_trans_stream *) data;
if (string_is_equal(prop, "window_bits"))
{
if (z)
z->ex = (int) val;
return true;
}
return false;
}
static void zlib_deflate_set_in(void *data, const uint8_t *in, uint32_t in_size)
{
struct zlib_trans_stream *z = (struct zlib_trans_stream *) data;
if (!z)
return;
z->z.next_in = (uint8_t *) in;
z->z.avail_in = in_size;
if (!z->inited)
{
deflateInit(&z->z, z->ex);
z->inited = true;
}
}
static void zlib_inflate_set_in(void *data, const uint8_t *in, uint32_t in_size)
{
struct zlib_trans_stream *z = (struct zlib_trans_stream *) data;
if (!z)
return;
z->z.next_in = (uint8_t *) in;
z->z.avail_in = in_size;
if (!z->inited)
{
inflateInit2(&z->z, z->ex);
z->inited = true;
}
}
static void zlib_set_out(void *data, uint8_t *out, uint32_t out_size)
{
struct zlib_trans_stream *z = (struct zlib_trans_stream *) data;
if (!z)
return;
z->z.next_out = out;
z->z.avail_out = out_size;
}
static bool zlib_deflate_trans(
void *data, bool flush,
uint32_t *rd, uint32_t *wn,
enum trans_stream_error *error)
{
int zret = 0;
bool ret = false;
uint32_t pre_avail_in = 0;
uint32_t pre_avail_out = 0;
struct zlib_trans_stream *zt = (struct zlib_trans_stream *) data;
z_stream *z = &zt->z;
if (!zt->inited)
{
deflateInit(z, zt->ex);
zt->inited = true;
}
pre_avail_in = z->avail_in;
pre_avail_out = z->avail_out;
zret = deflate(z, flush ? Z_FINISH : Z_NO_FLUSH);
if (zret == Z_OK)
{
if (error)
*error = TRANS_STREAM_ERROR_AGAIN;
}
else if (zret == Z_STREAM_END)
{
if (error)
*error = TRANS_STREAM_ERROR_NONE;
}
else
{
if (error)
*error = TRANS_STREAM_ERROR_OTHER;
return false;
}
ret = true;
if (z->avail_out == 0)
{
/* Filled buffer, maybe an error */
if (z->avail_in != 0)
{
ret = false;
if (error)
*error = TRANS_STREAM_ERROR_BUFFER_FULL;
}
}
*rd = pre_avail_in - z->avail_in;
*wn = pre_avail_out - z->avail_out;
if (flush && zret == Z_STREAM_END)
{
deflateEnd(z);
zt->inited = false;
}
return ret;
}
static bool zlib_inflate_trans(
void *data, bool flush,
uint32_t *rd, uint32_t *wn,
enum trans_stream_error *error)
{
int zret;
bool ret = false;
uint32_t pre_avail_in = 0;
uint32_t pre_avail_out = 0;
struct zlib_trans_stream *zt = (struct zlib_trans_stream *) data;
z_stream *z = &zt->z;
if (!zt->inited)
{
inflateInit2(z, zt->ex);
zt->inited = true;
}
pre_avail_in = z->avail_in;
pre_avail_out = z->avail_out;
zret = inflate(z, flush ? Z_FINISH : Z_NO_FLUSH);
if (zret == Z_OK)
{
if (error)
*error = TRANS_STREAM_ERROR_AGAIN;
}
else if (zret == Z_STREAM_END)
{
if (error)
*error = TRANS_STREAM_ERROR_NONE;
}
else
{
if (error)
*error = TRANS_STREAM_ERROR_OTHER;
return false;
}
ret = true;
if (z->avail_out == 0)
{
/* Filled buffer, maybe an error */
if (z->avail_in != 0)
{
ret = false;
if (error)
*error = TRANS_STREAM_ERROR_BUFFER_FULL;
}
}
*rd = pre_avail_in - z->avail_in;
*wn = pre_avail_out - z->avail_out;
if (flush && zret == Z_STREAM_END)
{
inflateEnd(z);
zt->inited = false;
}
return ret;
}
const struct trans_stream_backend zlib_deflate_backend = {
"zlib_deflate",
&zlib_inflate_backend,
zlib_deflate_stream_new,
zlib_deflate_stream_free,
zlib_deflate_define,
zlib_deflate_set_in,
zlib_set_out,
zlib_deflate_trans
};
const struct trans_stream_backend zlib_inflate_backend = {
"zlib_inflate",
&zlib_deflate_backend,
zlib_inflate_stream_new,
zlib_inflate_stream_free,
zlib_inflate_define,
zlib_inflate_set_in,
zlib_set_out,
zlib_inflate_trans
};