From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 38C45C433F5 for ; Fri, 19 Nov 2021 20:24:35 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0C4CE61AA2 for ; Fri, 19 Nov 2021 20:24:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 0C4CE61AA2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5989B83757; Fri, 19 Nov 2021 21:24:31 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="NpCdcCKl"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0ADD383433; Fri, 19 Nov 2021 21:24:28 +0100 (CET) Received: from mail-ot1-x32d.google.com (mail-ot1-x32d.google.com [IPv6:2607:f8b0:4864:20::32d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 8B7BC83728 for ; Fri, 19 Nov 2021 21:24:21 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-ot1-x32d.google.com with SMTP id w6-20020a9d77c6000000b0055e804fa524so18455382otl.3 for ; Fri, 19 Nov 2021 12:24:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9hdLpm7yN75+HyMwP9rRyqOwt044Uq+mX8ukwO+YXiY=; b=NpCdcCKlTpYUZQYuA6oXE4L+hjtejTs07IjKM5qggOHJvGeXvOsdvuX1Jff/DzieYj Ow0XFeZLfQ13q199JJth4+pBuS8ls/jmL0yu7Q5dOeDHYuoXFTamduNjILYF+ifk1cpL IwfVg+BGfAa5obbHDqwyvEp1j6y1/h3/qLXbQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9hdLpm7yN75+HyMwP9rRyqOwt044Uq+mX8ukwO+YXiY=; b=Zd8Z0lvdG/Wda7OBGuEitkTiGRlu6ZFw581Y3eFE+/61pHMBsc3ik4v2GcWC3tW7Z3 GqzqB/9cYVSMWRvqfaOekpJuoGAw+g8bjYzUOTqpGHvEb7uB2zfpxs60OZXiTraZMf31 d8EZUk9J4G3vKwB3EEB28ThO74OXh3T2sBUVibf9ZRc9WyrnEvncS5NkoaVz/bVWyOTx 2C0QTLCUwrcIQrjnWtRnoFtwhiTv+tsaY/iJzT6V/mJGLG2cnow/XtE7sd0W2APvA/mc fZNG+i7xwxUZDw6w9Bf72kB95IzTnNG2PGJZRp//WDy34Kz/NsreVyoy+9TnYhNCRDkg 0NKg== X-Gm-Message-State: AOAM531WhshbQuQTP3uTAFCZqCgHtgL19PHh7dmV9w/y+rl5jKQG3PZg XFBWCZayIz7bq28+i/0U4Q01ZHpfes31Og== X-Google-Smtp-Source: ABdhPJyFUP+kKsTqk2zq2gnCg5vmIdNysFp47neVI97qooQfbaXNOHh/rIES/KgHSfuf+eBUhw6o3w== X-Received: by 2002:a05:6830:290b:: with SMTP id z11mr6881658otu.117.1637353460008; Fri, 19 Nov 2021 12:24:20 -0800 (PST) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id bl33sm197093oib.47.2021.11.19.12.24.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Nov 2021 12:24:19 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Anatolij Gustschin , Tom Rini , Simon Glass , Harald Seiler Subject: [PATCH 01/23] sandbox: video: Support 8bpp depth Date: Fri, 19 Nov 2021 13:23:45 -0700 Message-Id: <20211119202408.1815506-2-sjg@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211119202408.1815506-1-sjg@chromium.org> References: <20211119202408.1815506-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.37 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean At present sandbox only supports 16 and 32bpp depths, since those are the easy ones with SDL. We can support other depths by manually converting the pixel formats. Add support for this, to enable an 8ppp (monochrome) format. Signed-off-by: Simon Glass --- arch/sandbox/cpu/sdl.c | 65 ++++++++++++++++++++++++++++++++++--- drivers/video/sandbox_sdl.c | 23 +++++++++---- 2 files changed, 77 insertions(+), 11 deletions(-) diff --git a/arch/sandbox/cpu/sdl.c b/arch/sandbox/cpu/sdl.c index bef5abd039d..7ff0df2ee54 100644 --- a/arch/sandbox/cpu/sdl.c +++ b/arch/sandbox/cpu/sdl.c @@ -44,6 +44,8 @@ struct buf_info { * @stopping: true if audio will stop once it runs out of data * @texture: SDL texture to use for U-Boot display contents * @renderer: SDL renderer to use + * @src_depth: Number of bits per pixel in the source frame buffer (that we read + * from and render to SDL) */ static struct sdl_info { int width; @@ -61,6 +63,7 @@ static struct sdl_info { bool stopping; SDL_Texture *texture; SDL_Renderer *renderer; + int src_depth; } sdl; static void sandbox_sdl_poll_events(void) @@ -126,6 +129,9 @@ int sandbox_sdl_init_display(int width, int height, int log2_bpp, if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1")) printf("Unable to init hinting: %s", SDL_GetError()); + sdl.src_depth = 1 << log2_bpp; + if (log2_bpp != 4 && log2_bpp != 5) + log2_bpp = 5; sdl.depth = 1 << log2_bpp; sdl.pitch = sdl.width * sdl.depth / 8; SDL_Window *screen = SDL_CreateWindow("U-Boot", SDL_WINDOWPOS_UNDEFINED, @@ -137,10 +143,6 @@ int sandbox_sdl_init_display(int width, int height, int log2_bpp, SDL_GetError()); return -EIO; } - if (log2_bpp != 4 && log2_bpp != 5) { - printf("U-Boot SDL does not support depth %d\n", log2_bpp); - return -EINVAL; - } sdl.renderer = SDL_CreateRenderer(screen, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); @@ -165,6 +167,55 @@ int sandbox_sdl_init_display(int width, int height, int log2_bpp, return 0; } +static int copy_to_texture(void *lcd_base) +{ + char *dest; + int pitch, x, y; + int src_pitch; + void *pixels; + char *src; + int ret; + + if (sdl.src_depth == sdl.depth) { + SDL_UpdateTexture(sdl.texture, NULL, lcd_base, sdl.pitch); + return 0; + } + + /* + * We only support copying from an 8bpp to a 32bpp texture since the + * other cases are supported directly by the texture. + */ + if (sdl.depth != 32 && sdl.src_depth != 8) { + printf("Need depth 32bpp for copy\n"); + return -EINVAL; + } + + ret = SDL_LockTexture(sdl.texture, NULL, &pixels, &pitch); + if (ret) { + printf("SDL lock %d: %s\n", ret, SDL_GetError()); + return ret; + } + + /* Copy the pixels one by one */ + src_pitch = sdl.width * sdl.src_depth / 8; + for (y = 0; y < sdl.height; y++) { + char val; + + dest = pixels + y * pitch; + src = lcd_base + src_pitch * y; + for (x = 0; x < sdl.width; x++, dest += 4) { + val = *src++; + dest[0] = val; + dest[1] = val; + dest[2] = val; + dest[3] = 0; + } + } + SDL_UnlockTexture(sdl.texture); + + return 0; +} + int sandbox_sdl_sync(void *lcd_base) { struct SDL_Rect rect; @@ -173,7 +224,11 @@ int sandbox_sdl_sync(void *lcd_base) if (!sdl.texture) return 0; SDL_RenderClear(sdl.renderer); - SDL_UpdateTexture(sdl.texture, NULL, lcd_base, sdl.pitch); + ret = copy_to_texture(lcd_base); + if (ret) { + printf("copy_to_texture: %d: %s\n", ret, SDL_GetError()); + return -EIO; + } ret = SDL_RenderCopy(sdl.renderer, sdl.texture, NULL, NULL); if (ret) { printf("SDL copy %d: %s\n", ret, SDL_GetError()); diff --git a/drivers/video/sandbox_sdl.c b/drivers/video/sandbox_sdl.c index 5956b59ce49..32739de4feb 100644 --- a/drivers/video/sandbox_sdl.c +++ b/drivers/video/sandbox_sdl.c @@ -48,22 +48,33 @@ static int sandbox_sdl_probe(struct udevice *dev) return 0; } -static int sandbox_sdl_bind(struct udevice *dev) +static void set_bpp(struct udevice *dev, enum video_log2_bpp l2bpp) { struct video_uc_plat *uc_plat = dev_get_uclass_plat(dev); struct sandbox_sdl_plat *plat = dev_get_plat(dev); - int ret = 0; - plat->xres = dev_read_u32_default(dev, "xres", LCD_MAX_WIDTH); - plat->yres = dev_read_u32_default(dev, "yres", LCD_MAX_HEIGHT); - plat->bpix = dev_read_u32_default(dev, "log2-depth", VIDEO_BPP16); - plat->rot = dev_read_u32_default(dev, "rotate", 0); + plat->bpix = l2bpp; + uc_plat->size = plat->xres * plat->yres * (1 << plat->bpix) / 8; /* Allow space for two buffers, the lower one being the copy buffer */ log_debug("Frame buffer size %x\n", uc_plat->size); if (IS_ENABLED(CONFIG_VIDEO_COPY)) uc_plat->size *= 2; +} + +static int sandbox_sdl_bind(struct udevice *dev) +{ + struct sandbox_sdl_plat *plat = dev_get_plat(dev); + enum video_log2_bpp l2bpp; + int ret = 0; + + plat->xres = dev_read_u32_default(dev, "xres", LCD_MAX_WIDTH); + plat->yres = dev_read_u32_default(dev, "yres", LCD_MAX_HEIGHT); + l2bpp = dev_read_u32_default(dev, "log2-depth", VIDEO_BPP16); + plat->rot = dev_read_u32_default(dev, "rotate", 0); + + set_bpp(dev, l2bpp); return ret; } -- 2.34.0.rc2.393.gf8c9666880-goog