diff --git a/README.md b/README.md index 1b9b5311a..75dace9b2 100644 --- a/README.md +++ b/README.md @@ -119,7 +119,7 @@ Circle supports the following features: | | (not on Raspberry Pi 4) | | | | uGUI (by Achim Doebler) | | | | LVGL (by LVGL Kft) | x | -| | 2D graphics class in base library | | +| | 2D graphics class in base library | x | | | | | | Not supported | Bluetooth | | diff --git a/lib/2dgraphics.cpp b/lib/2dgraphics.cpp index 5ae01af06..2043912ec 100644 --- a/lib/2dgraphics.cpp +++ b/lib/2dgraphics.cpp @@ -5,7 +5,7 @@ // Copyright (C) 2021 Stephane Damo // // Circle - A C++ bare metal environment for Raspberry Pi -// Copyright (C) 2014-2023 R. Stange +// Copyright (C) 2014-2024 R. Stange // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -39,6 +39,8 @@ C2DGraphics::C2DGraphics (unsigned nWidth, unsigned nHeight, boolean bVSync, uns C2DGraphics::~C2DGraphics (void) { + delete [] m_Buffer; + if(m_pFrameBuffer) { delete m_pFrameBuffer; @@ -47,8 +49,12 @@ C2DGraphics::~C2DGraphics (void) boolean C2DGraphics::Initialize (void) { +#if RASPPI <= 4 m_pFrameBuffer = new CBcmFrameBuffer (m_nWidth, m_nHeight, DEPTH, m_nWidth, 2*m_nHeight, m_nDisplay, TRUE); +#else + m_pFrameBuffer = new CBcmFrameBuffer (m_nWidth, m_nHeight, DEPTH, 0, 0, m_nDisplay, FALSE); +#endif #if DEPTH == 8 m_pFrameBuffer->SetPalette (RED_COLOR, RED_COLOR16); @@ -76,8 +82,13 @@ boolean C2DGraphics::Initialize (void) m_baseBuffer = (TScreenColor *) (uintptr) m_pFrameBuffer->GetBuffer(); m_nWidth = m_pFrameBuffer->GetWidth(); m_nHeight = m_pFrameBuffer->GetHeight(); - m_Buffer = m_baseBuffer + m_nWidth * m_nHeight; - + + m_Buffer = new TScreenColor[m_nWidth * m_nHeight]; + if (!m_Buffer) + { + return FALSE; + } + return TRUE; } @@ -89,6 +100,7 @@ boolean C2DGraphics::Resize (unsigned nWidth, unsigned nHeight) m_nWidth = nWidth; m_nHeight = nHeight; + delete [] m_Buffer; m_Buffer = 0; m_bBufferSwapped = TRUE; @@ -361,15 +373,17 @@ TScreenColor* C2DGraphics::GetBuffer () void C2DGraphics::UpdateDisplay() { - +#if RASPPI <= 4 if(m_bVSync) { - m_pFrameBuffer->SetVirtualOffset(0, m_bBufferSwapped ? m_nHeight : 0); m_pFrameBuffer->WaitForVerticalSync(); + memcpy (m_baseBuffer + m_bBufferSwapped * m_nWidth * m_nHeight, m_Buffer, + m_nWidth * m_nHeight * sizeof(TScreenColor)); + m_pFrameBuffer->SetVirtualOffset(0, m_bBufferSwapped ? m_nHeight : 0); m_bBufferSwapped = !m_bBufferSwapped; - m_Buffer = m_baseBuffer + m_bBufferSwapped * m_nWidth * m_nHeight; } else +#endif { memcpy(m_baseBuffer, m_Buffer, m_nWidth * m_nHeight * sizeof(TScreenColor)); } diff --git a/sample/README b/sample/README index 2262a68b9..27dee671c 100644 --- a/sample/README +++ b/sample/README @@ -39,7 +39,7 @@ SAMPLES 38-bootloader HTTP- and TFTP-based bootloader with Web front-end 39-umsdplugging [PnP,5] Plug in and remove USB flash drives, list directory 40-irqlatency [PnP] Displays the maximum measured IRQ latency -41-screenanimations 2D graphical shapes demo on screen without flickering or screen tearing +41-screenanimations [5] 2D graphical shapes demo on screen without flickering or screen tearing 42-soundinput [5] I2S or USB to PWM sound data converter and digital sound recorder Samples marked with [PnP] are enabled for USB plug-and-play.