From nobody Fri Feb 16 04:00:23 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4TbdWC5PJYz59ZK0; Fri, 16 Feb 2024 04:00:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TbdWC3f54z4H1y; Fri, 16 Feb 2024 04:00:23 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708056023; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=VZwDpXDeKU+S1XVkeo3+wqvJDocRmmyhwVxGOrQSOa8=; b=IwxMBQiEa1zNe7qofSMtocx/zIiPm22hRnQPoIqlxhyGmfTpUTbKLR+OR1eBl4XwVl0Iac E9TjUzUiKyN4HdPEF863zCPyVGA6JIPFpqLtcd54jjkauuZLCw+FsaxD8nzUp0TbUASTVt aIYOwIWgaP6PiTJuWBntjTGxuglpQorIt6g2wTzkwEeet9Lz0NnQ4ZcZI2uwp0eGn2sQAT diZo0xc3imxy23kn313WTE+I4iB/wL03AczqdSUkotm4ksVL9y/Z9QLoRDe/XIXvBGCXso BjHJmDXVrXyAf+6FvP7QDqTCSHHB3Y5GZpC1H455sBeHqlXYMFvSsiLsVOwJUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708056023; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=VZwDpXDeKU+S1XVkeo3+wqvJDocRmmyhwVxGOrQSOa8=; b=cNlg6v3cq6XtK/b75jRcx/AlcjLC/4HptWDUb10jIzzDRJvYmG7Y/EjFzTdJNirfc0xIlx 6S6F8AJHW/JDFuiFj9dpO1Hm5Qli+49j3CsbqeV5o6gBco9f5Jah0g6P9Bh9eNiDsB3Igh w76g2wwyQYmVHvrgR2KkrX3XsGKUIR2+xSQN1YWLCDKlN3cCZwPT8LuWvaXTJ0yf8jCevn Gud0OowSiNHf7p33mxfFFtj0msJ6/TUKhU6ulyiKsMboRxJ7oa4ioQXlOb+pvZZncqE6Le qnXPUxDyJv8xs5wJoqUSJ+9E64J+lAugU87VjSZrEbqvv3Y42RlikiArekXFpg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1708056023; a=rsa-sha256; cv=none; b=eKIJaWp+CudRwFbUB1WAdluaGfB/Fpxs9Ydr5fbF+p0PZH9GddkdblieL+cuEwhTOg9PDC cdOkB7dJbzKFeCP1njLRsTt/l4j70KkhwEmA3l7pfVOuyEL0700/U6+Jz02ONYsny/+g7U k6fq7QMwM93PT4AbJU7eFz3/VSybLayxdrMgeWv6UguoMkSLFKe4YjT0Tfjz2ZIhXBYtqc wQvnnQol6VVugugj2vQEOecVQfHOiKEgxlSzdPPkQ+h+f7u4LpOSslgyK4L1JeBmplRrAc /ap+J0ZZfXT9TGRigH6SyYRcFeCKvEfXLAp6IgmJez9P+cqzrG8mZZLxtY9s8A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4TbdWC2lVpz18Jk; Fri, 16 Feb 2024 04:00:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 41G40NJs018864; Fri, 16 Feb 2024 04:00:23 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41G40NMe018861; Fri, 16 Feb 2024 04:00:23 GMT (envelope-from git) Date: Fri, 16 Feb 2024 04:00:23 GMT Message-Id: <202402160400.41G40NMe018861@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: 061b68a76030 - main - loader: Separate gfx to a new file. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 061b68a76030f4147f5a30e60ab5f4296c1376b7 Auto-Submitted: auto-generated The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=061b68a76030f4147f5a30e60ab5f4296c1376b7 commit 061b68a76030f4147f5a30e60ab5f4296c1376b7 Author: Warner Losh AuthorDate: 2024-02-16 03:52:59 +0000 Commit: Warner Losh CommitDate: 2024-02-16 03:59:22 +0000 loader: Separate gfx to a new file. Move gfx lua hook registration to a new file. Sponsored by: Netflix Reviewed by: kevans, jhb Differential Revision: https://reviews.freebsd.org/D43901 --- stand/liblua/Makefile | 3 +- stand/liblua/gfx_utils.c | 242 +++++++++++++++++++++++++++++++++++++++++++++++ stand/liblua/lutils.c | 202 --------------------------------------- stand/liblua/lutils.h | 1 + 4 files changed, 245 insertions(+), 203 deletions(-) diff --git a/stand/liblua/Makefile b/stand/liblua/Makefile index b2f17811ff84..bbfa21e07f53 100644 --- a/stand/liblua/Makefile +++ b/stand/liblua/Makefile @@ -23,6 +23,7 @@ SRCS+= lauxlib.c lbaselib.c lstrlib.c loadlib.c # Our utilities. SRCS+= lerrno.c lpager.c lstd.c lutils.c +SRCS+= gfx_utils.c .PATH: ${FLUASRC}/modules SRCS+= lfs.c @@ -34,7 +35,7 @@ CFLAGS+= -ffreestanding -nostdlib -DLUA_USE_POSIX CFLAGS+= -fno-stack-protector -D__BSD_VISIBLE CFLAGS+= -I${BOOTSRC}/include -I${LIBLUASRC} -I${LUASRC} -I${LDRSRC} -CFLAGS.lutils.c+= -I${SRCTOP}/sys/teken -I${SRCTOP}/contrib/pnglite +CFLAGS.gfx_utils.c+= -I${SRCTOP}/sys/teken -I${SRCTOP}/contrib/pnglite .if ${MACHINE_CPUARCH} == "amd64" && ${DO32:U0} == 0 CFLAGS+= -fPIC diff --git a/stand/liblua/gfx_utils.c b/stand/liblua/gfx_utils.c new file mode 100644 index 000000000000..fe208dc990d8 --- /dev/null +++ b/stand/liblua/gfx_utils.c @@ -0,0 +1,242 @@ +/*- + * Copyright (c) 2024 Netflix, Inc. + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +/* Copied from a file that likely shoulve have had this at the top */ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright 2020 Toomas Soome + * Copyright 2020 RackTop Systems, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include "lua.h" +#include "lauxlib.h" +#include "lutils.h" +#include +#include + +/* + * put image using terminal coordinates. + */ +static int +lua_term_putimage(lua_State *L) +{ + const char *name; + png_t png; + uint32_t x1, y1, x2, y2, f; + int nargs, ret = 0, error; + + nargs = lua_gettop(L); + if (nargs != 6) { + lua_pushboolean(L, 0); + return 1; + } + + name = luaL_checkstring(L, 1); + x1 = luaL_checknumber(L, 2); + y1 = luaL_checknumber(L, 3); + x2 = luaL_checknumber(L, 4); + y2 = luaL_checknumber(L, 5); + f = luaL_checknumber(L, 6); + + x1 = gfx_state.tg_origin.tp_col + x1 * gfx_state.tg_font.vf_width; + y1 = gfx_state.tg_origin.tp_row + y1 * gfx_state.tg_font.vf_height; + if (x2 != 0) { + x2 = gfx_state.tg_origin.tp_col + + x2 * gfx_state.tg_font.vf_width; + } + if (y2 != 0) { + y2 = gfx_state.tg_origin.tp_row + + y2 * gfx_state.tg_font.vf_height; + } + + if ((error = png_open(&png, name)) != PNG_NO_ERROR) { + if (f & FL_PUTIMAGE_DEBUG) + printf("%s\n", png_error_string(error)); + } else { + if (gfx_fb_putimage(&png, x1, y1, x2, y2, f) == 0) + ret = 1; + (void) png_close(&png); + } + lua_pushboolean(L, ret); + return 1; +} + +static int +lua_fb_putimage(lua_State *L) +{ + const char *name; + png_t png; + uint32_t x1, y1, x2, y2, f; + int nargs, ret = 0, error; + + nargs = lua_gettop(L); + if (nargs != 6) { + lua_pushboolean(L, 0); + return 1; + } + + name = luaL_checkstring(L, 1); + x1 = luaL_checknumber(L, 2); + y1 = luaL_checknumber(L, 3); + x2 = luaL_checknumber(L, 4); + y2 = luaL_checknumber(L, 5); + f = luaL_checknumber(L, 6); + + if ((error = png_open(&png, name)) != PNG_NO_ERROR) { + if (f & FL_PUTIMAGE_DEBUG) + printf("%s\n", png_error_string(error)); + } else { + if (gfx_fb_putimage(&png, x1, y1, x2, y2, f) == 0) + ret = 1; + (void) png_close(&png); + } + lua_pushboolean(L, ret); + return 1; +} + +static int +lua_fb_setpixel(lua_State *L) +{ + uint32_t x, y; + int nargs; + + nargs = lua_gettop(L); + if (nargs != 2) { + lua_pushnil(L); + return 1; + } + + x = luaL_checknumber(L, 1); + y = luaL_checknumber(L, 2); + gfx_fb_setpixel(x, y); + return 0; +} + +static int +lua_fb_line(lua_State *L) +{ + uint32_t x0, y0, x1, y1, wd; + int nargs; + + nargs = lua_gettop(L); + if (nargs != 5) { + lua_pushnil(L); + return 1; + } + + x0 = luaL_checknumber(L, 1); + y0 = luaL_checknumber(L, 2); + x1 = luaL_checknumber(L, 3); + y1 = luaL_checknumber(L, 4); + wd = luaL_checknumber(L, 5); + gfx_fb_line(x0, y0, x1, y1, wd); + return 0; +} + +static int +lua_fb_bezier(lua_State *L) +{ + uint32_t x0, y0, x1, y1, x2, y2, width; + int nargs; + + nargs = lua_gettop(L); + if (nargs != 7) { + lua_pushnil(L); + return 1; + } + + x0 = luaL_checknumber(L, 1); + y0 = luaL_checknumber(L, 2); + x1 = luaL_checknumber(L, 3); + y1 = luaL_checknumber(L, 4); + x2 = luaL_checknumber(L, 5); + y2 = luaL_checknumber(L, 6); + width = luaL_checknumber(L, 7); + gfx_fb_bezier(x0, y0, x1, y1, x2, y2, width); + return 0; +} + +static int +lua_fb_drawrect(lua_State *L) +{ + uint32_t x0, y0, x1, y1, fill; + int nargs; + + nargs = lua_gettop(L); + if (nargs != 5) { + lua_pushnil(L); + return 1; + } + + x0 = luaL_checknumber(L, 1); + y0 = luaL_checknumber(L, 2); + x1 = luaL_checknumber(L, 3); + y1 = luaL_checknumber(L, 4); + fill = luaL_checknumber(L, 5); + gfx_fb_drawrect(x0, y0, x1, y1, fill); + return 0; +} + +static int +lua_term_drawrect(lua_State *L) +{ + uint32_t x0, y0, x1, y1; + int nargs; + + nargs = lua_gettop(L); + if (nargs != 4) { + lua_pushnil(L); + return 1; + } + + x0 = luaL_checknumber(L, 1); + y0 = luaL_checknumber(L, 2); + x1 = luaL_checknumber(L, 3); + y1 = luaL_checknumber(L, 4); + gfx_term_drawrect(x0, y0, x1, y1); + return 0; +} + +#define REG_SIMPLE(n) { #n, lua_ ## n } +static const struct luaL_Reg gfxlib[] = { + REG_SIMPLE(fb_bezier), + REG_SIMPLE(fb_drawrect), + REG_SIMPLE(fb_line), + REG_SIMPLE(fb_putimage), + REG_SIMPLE(fb_setpixel), + REG_SIMPLE(term_drawrect), + REG_SIMPLE(term_putimage), + { NULL, NULL }, +}; + +int +luaopen_gfx(lua_State *L) +{ + luaL_newlib(L, gfxlib); + return 1; +} diff --git a/stand/liblua/lutils.c b/stand/liblua/lutils.c index 0dbd8a6f720b..20876f965f0c 100644 --- a/stand/liblua/lutils.c +++ b/stand/liblua/lutils.c @@ -32,8 +32,6 @@ #include "lstd.h" #include "lutils.h" #include "bootstrap.h" -#include -#include /* * Like loader.perform, except args are passed already parsed @@ -380,189 +378,6 @@ lua_writefile(lua_State *L) return 1; } -/* - * put image using terminal coordinates. - */ -static int -lua_term_putimage(lua_State *L) -{ - const char *name; - png_t png; - uint32_t x1, y1, x2, y2, f; - int nargs, ret = 0, error; - - nargs = lua_gettop(L); - if (nargs != 6) { - lua_pushboolean(L, 0); - return 1; - } - - name = luaL_checkstring(L, 1); - x1 = luaL_checknumber(L, 2); - y1 = luaL_checknumber(L, 3); - x2 = luaL_checknumber(L, 4); - y2 = luaL_checknumber(L, 5); - f = luaL_checknumber(L, 6); - - x1 = gfx_state.tg_origin.tp_col + x1 * gfx_state.tg_font.vf_width; - y1 = gfx_state.tg_origin.tp_row + y1 * gfx_state.tg_font.vf_height; - if (x2 != 0) { - x2 = gfx_state.tg_origin.tp_col + - x2 * gfx_state.tg_font.vf_width; - } - if (y2 != 0) { - y2 = gfx_state.tg_origin.tp_row + - y2 * gfx_state.tg_font.vf_height; - } - - if ((error = png_open(&png, name)) != PNG_NO_ERROR) { - if (f & FL_PUTIMAGE_DEBUG) - printf("%s\n", png_error_string(error)); - } else { - if (gfx_fb_putimage(&png, x1, y1, x2, y2, f) == 0) - ret = 1; - (void) png_close(&png); - } - lua_pushboolean(L, ret); - return 1; -} - -static int -lua_fb_putimage(lua_State *L) -{ - const char *name; - png_t png; - uint32_t x1, y1, x2, y2, f; - int nargs, ret = 0, error; - - nargs = lua_gettop(L); - if (nargs != 6) { - lua_pushboolean(L, 0); - return 1; - } - - name = luaL_checkstring(L, 1); - x1 = luaL_checknumber(L, 2); - y1 = luaL_checknumber(L, 3); - x2 = luaL_checknumber(L, 4); - y2 = luaL_checknumber(L, 5); - f = luaL_checknumber(L, 6); - - if ((error = png_open(&png, name)) != PNG_NO_ERROR) { - if (f & FL_PUTIMAGE_DEBUG) - printf("%s\n", png_error_string(error)); - } else { - if (gfx_fb_putimage(&png, x1, y1, x2, y2, f) == 0) - ret = 1; - (void) png_close(&png); - } - lua_pushboolean(L, ret); - return 1; -} - -static int -lua_fb_setpixel(lua_State *L) -{ - uint32_t x, y; - int nargs; - - nargs = lua_gettop(L); - if (nargs != 2) { - lua_pushnil(L); - return 1; - } - - x = luaL_checknumber(L, 1); - y = luaL_checknumber(L, 2); - gfx_fb_setpixel(x, y); - return 0; -} - -static int -lua_fb_line(lua_State *L) -{ - uint32_t x0, y0, x1, y1, wd; - int nargs; - - nargs = lua_gettop(L); - if (nargs != 5) { - lua_pushnil(L); - return 1; - } - - x0 = luaL_checknumber(L, 1); - y0 = luaL_checknumber(L, 2); - x1 = luaL_checknumber(L, 3); - y1 = luaL_checknumber(L, 4); - wd = luaL_checknumber(L, 5); - gfx_fb_line(x0, y0, x1, y1, wd); - return 0; -} - -static int -lua_fb_bezier(lua_State *L) -{ - uint32_t x0, y0, x1, y1, x2, y2, width; - int nargs; - - nargs = lua_gettop(L); - if (nargs != 7) { - lua_pushnil(L); - return 1; - } - - x0 = luaL_checknumber(L, 1); - y0 = luaL_checknumber(L, 2); - x1 = luaL_checknumber(L, 3); - y1 = luaL_checknumber(L, 4); - x2 = luaL_checknumber(L, 5); - y2 = luaL_checknumber(L, 6); - width = luaL_checknumber(L, 7); - gfx_fb_bezier(x0, y0, x1, y1, x2, y2, width); - return 0; -} - -static int -lua_fb_drawrect(lua_State *L) -{ - uint32_t x0, y0, x1, y1, fill; - int nargs; - - nargs = lua_gettop(L); - if (nargs != 5) { - lua_pushnil(L); - return 1; - } - - x0 = luaL_checknumber(L, 1); - y0 = luaL_checknumber(L, 2); - x1 = luaL_checknumber(L, 3); - y1 = luaL_checknumber(L, 4); - fill = luaL_checknumber(L, 5); - gfx_fb_drawrect(x0, y0, x1, y1, fill); - return 0; -} - -static int -lua_term_drawrect(lua_State *L) -{ - uint32_t x0, y0, x1, y1; - int nargs; - - nargs = lua_gettop(L); - if (nargs != 4) { - lua_pushnil(L); - return 1; - } - - x0 = luaL_checknumber(L, 1); - y0 = luaL_checknumber(L, 2); - x1 = luaL_checknumber(L, 3); - y1 = luaL_checknumber(L, 4); - gfx_term_drawrect(x0, y0, x1, y1); - return 0; -} - #define REG_SIMPLE(n) { #n, lua_ ## n } static const struct luaL_Reg loaderlib[] = { REG_SIMPLE(delay), @@ -581,17 +396,6 @@ static const struct luaL_Reg loaderlib[] = { { NULL, NULL }, }; -static const struct luaL_Reg gfxlib[] = { - REG_SIMPLE(fb_bezier), - REG_SIMPLE(fb_drawrect), - REG_SIMPLE(fb_line), - REG_SIMPLE(fb_putimage), - REG_SIMPLE(fb_setpixel), - REG_SIMPLE(term_drawrect), - REG_SIMPLE(term_putimage), - { NULL, NULL }, -}; - static const struct luaL_Reg iolib[] = { { "close", lua_closefile }, REG_SIMPLE(getchar), @@ -631,12 +435,6 @@ lua_add_features(lua_State *L) lua_setfield(L, -2, "features"); } -static void -luaopen_gfx(lua_State *L) -{ - luaL_newlib(L, gfxlib); -} - int luaopen_loader(lua_State *L) { diff --git a/stand/liblua/lutils.h b/stand/liblua/lutils.h index 280fb77aa665..c1fd6af496e5 100644 --- a/stand/liblua/lutils.h +++ b/stand/liblua/lutils.h @@ -26,6 +26,7 @@ #include +int luaopen_gfx(lua_State *); int luaopen_loader(lua_State *); int luaopen_io(lua_State *); int luaopen_pager(lua_State *);