From nobody Tue Apr 16 20:12:44 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 4VJwFS5PJZz5H0VS; Tue, 16 Apr 2024 20:12:44 +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 4VJwFS3gJMz4t33; Tue, 16 Apr 2024 20:12:44 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1713298364; 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=3IMe7bs29vb8MAbfQvCD8PATejo5ccwZmeWusAEsDjA=; b=uwMWnmDnJP8K3JaeUZgAfdjz6TSnoeV6AwxbQI8DZz1tFIfBs5CtJ/Vdrfa+1KN7ZKtrOg zX+U37k9GqMiJ0JvY5XMtzK2ERglVvq77NxbJIb1Ueo9sN+MNpmrErGQtxMM4KgaiOiHDC IAzp3gpZllqbDdWwwlt99YU0sbfQRXmiO4R1XJtS0vIU0RcIau6Jk55v2gVrYFsarq+XHo 6n8DRvv4XCUk7ajKgBFQicn94nE9sf6zyEaXM74p9q98zNvaUkegDY5Wp2rPqNPPTxyEZj S4Zf4VHzriPKuQu0RyZM32NE4zpghD+mhOKoTqZClTX4qJTehVgslP7LSsIxDw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1713298364; a=rsa-sha256; cv=none; b=U4VC5W1SKlvmVpeo8voAlilp24pEtc7pJvnULN2bKbRIB8YC2yyevvwOMzKk0I01WmqojA FRiijpIIHSV7DWiRsnVXHbMWtZnxhLnI+rWQJm+jRxFJS5Rni0zQic2McCdm51gJi7pNy6 KDgRV6oxRftKFKQFcBOMDahGjmxxXbWL4UM+0vrtVaIarVrqhJblNUbha9jD9GnO1oeiTY ierr3YcB9SKvE8kN0+8MjhQx/LbsDxsb02+TPkUehaUNwExO4ExrtogPEZvcQFH5tuoW4Q pqPumFfghD2+/OoOtb2+zZukm/1nNGm/ee7vnKgz5k1mmf64NiYPaMV25go3KA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1713298364; 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=3IMe7bs29vb8MAbfQvCD8PATejo5ccwZmeWusAEsDjA=; b=iKKtsQg/vMZ8ZssU03xOZeUlbd+CXm/kqVd1cVd6OIbAR+K1ZdzTtWo2da//uPzVcEA3GX C/mc9gmQXLcVH/R0WOV90W8WWQdT+VicjThA+AUPUTUIjzxIBsp9zDOIuQ4j+nUKQwElBr Jd0Nw5AwkA//utxmS1eOt8GqHMFdhIXj7zz1A6a3gHgkFRsilAhZF9h8TF2aTkF9NkaEC6 UB1nqTSStLRQ2jlIGJhyaWEorM1/Lt34FREiV0HZ/0RxUPWCE3IIQmnSuFf+82DEC/rGpZ GmnUaOx2MFI2lbeZfV6vfcGHqat6R/RMnGCr5UQTL6JKx828bnvxw3ijW84oaA== 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 4VJwFS3Fn7zxWP; Tue, 16 Apr 2024 20:12:44 +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 43GKCi7c037744; Tue, 16 Apr 2024 20:12:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 43GKCiI9037741; Tue, 16 Apr 2024 20:12:44 GMT (envelope-from git) Date: Tue, 16 Apr 2024 20:12:44 GMT Message-Id: <202404162012.43GKCiI9037741@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Warner Losh Subject: git: 8929f8454fff - stable/14 - 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-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/stable/14 X-Git-Reftype: branch X-Git-Commit: 8929f8454fffcae33e65689b806e236c16c6761b Auto-Submitted: auto-generated The branch stable/14 has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=8929f8454fffcae33e65689b806e236c16c6761b commit 8929f8454fffcae33e65689b806e236c16c6761b Author: Warner Losh AuthorDate: 2024-02-16 03:52:59 +0000 Commit: Warner Losh CommitDate: 2024-04-16 19:54:23 +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 (cherry picked from commit 061b68a76030f4147f5a30e60ab5f4296c1376b7) --- 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 *);