Skip to content

Commit fdd4d04

Browse files
committed
Significant speed-up when using FVTerm::copyArea with multipl overlapping and transparent layers
1 parent c294f28 commit fdd4d04

File tree

22 files changed

+1875
-308
lines changed

22 files changed

+1875
-308
lines changed

.github/workflows/netbsd.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ jobs:
3030
sudo -E pkgin clean
3131
sudo -E pkgin update
3232
# https://ftp.netbsd.org/pub/pkgsrc/current/pkgsrc/index-all.html
33-
sudo -E pkgin -y install gcc13 automake autoconf autoconf-archive libtool pkgconf cppunit
34-
export CXX=/usr/pkg/gcc13/bin/g++
33+
sudo -E pkgin -y install gcc14 automake autoconf autoconf-archive libtool pkgconf cppunit
34+
export CXX=/usr/pkg/gcc14/bin/g++
3535
$CXX --version
3636
autoreconf -v --install --force
3737
./configure --prefix=/usr

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2025-02-09 Markus Gans <[email protected]>
2+
* Significant speed-up when using FVTerm::copyArea with multiple
3+
overlapping and transparent layers. This reduces the CPU load
4+
of the process by ⅔.
5+
16
2024-12-24 Markus Gans <[email protected]>
27
* Better FChar color value direct access
38

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ Explore the power of FINAL CUT with these examples:
7878
![FProgressbar](doc/progress-bar.png)
7979
<br />*FProgressbar widget*<br /><br />
8080

81+
![XPM Viewer](doc/xpmview.png)
82+
<br />*X PixMap (XPM) viewer example*<br /><br />
83+
8184
![FTextView](doc/textview.png)
8285
<br />*Scrollable text in an FTextView widget*<br /><br />
8386

doc/xpmview.png

6.61 KB
Loading

examples/eventloop.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* *
44
* This file is part of the FINAL CUT widget toolkit *
55
* *
6-
* Copyright 2023 Andreas Noe *
6+
* Copyright 2023-2025 Andreas Noe *
77
* *
88
* FINAL CUT is free software; you can redistribute it and/or modify *
99
* it under the terms of the GNU Lesser General Public License as *
@@ -42,6 +42,8 @@ struct Global
4242
struct termios Global::original_term_io_settings{};
4343
std::atomic<bool> Global::wait{true};
4444

45+
// Function prototype
46+
void wait_5_seconds (const finalcut::BackendMonitor*);
4547

4648
//----------------------------------------------------------------------
4749
static void onExit()

examples/parallax-scrolling.cpp

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* *
44
* This file is part of the FINAL CUT widget toolkit *
55
* *
6-
* Copyright 2021-2024 Markus Gans *
6+
* Copyright 2021-2025 Markus Gans *
77
* *
88
* FINAL CUT is free software; you can redistribute it and/or modify *
99
* it under the terms of the GNU Lesser General Public License as *
@@ -133,34 +133,6 @@ constexpr std::array<const char*, 97> saturn_xpm = \
133133
" "
134134
}};
135135

136-
struct restoreOverlaid : public fc::FVTerm
137-
{
138-
~restoreOverlaid() override;
139-
140-
void operator () (fc::FVTerm& obj) const
141-
{
142-
const auto* win_list = getWindowList();
143-
144-
if ( ! win_list || win_list->empty() )
145-
return;
146-
147-
auto obj_vwin = obj.getVWin();
148-
bool overlaid{false};
149-
150-
for (const auto* window : *win_list)
151-
{
152-
const auto* win = static_cast<const fc::FWidget*>(window);
153-
const auto* win_vwin = win->getVWin();
154-
155-
if ( overlaid && win_vwin && win_vwin->visible )
156-
putArea (win->getTermPos(), win_vwin);
157-
else if ( obj_vwin == win_vwin )
158-
overlaid = true;
159-
}
160-
}
161-
};
162-
163-
restoreOverlaid::~restoreOverlaid() = default;
164136

165137
template <>
166138
struct std::hash<fc::FPoint>
@@ -206,7 +178,6 @@ void TextWindow::setPos (const fc::FPoint& pos, bool)
206178
{
207179
fc::FWindow::setPos (pos, false);
208180
putArea (getTermPos(), getVWin());
209-
restoreOverlaid{}(*this);
210181
}
211182

212183
//----------------------------------------------------------------------
@@ -272,7 +243,6 @@ void SpaceWindow::setPos (const fc::FPoint& pos, bool)
272243
{
273244
fc::FWindow::setPos (pos, false);
274245
putArea (getTermPos(), getVWin());
275-
restoreOverlaid{}(*this);
276246
}
277247

278248
//----------------------------------------------------------------------
@@ -323,26 +293,42 @@ void SpaceWindow::adjustSize()
323293
//----------------------------------------------------------------------
324294
// class PictureSpaceWindow
325295
//----------------------------------------------------------------------
326-
class PictureSpaceWindow final : public SpaceWindow
296+
class PictureSpaceWindow final : public fc::FWindow
327297
{
328298
public:
329299
// Constructor
330-
explicit PictureSpaceWindow (fc::FColor, fc::FColor, fc::FWidget* = nullptr);
300+
explicit PictureSpaceWindow (fc::FWidget* = nullptr);
301+
void setPos (const fc::FPoint&, bool = true) override;
331302

332303
private:
333304
// Method
334305
void draw() override;
306+
void initLayout() override;
307+
void adjustSize() override;
335308
};
336309

337310
//----------------------------------------------------------------------
338-
PictureSpaceWindow::PictureSpaceWindow (fc::FColor fg, fc::FColor bg, fc::FWidget* parent)
339-
: SpaceWindow{fg, bg, parent}
340-
{ }
311+
PictureSpaceWindow::PictureSpaceWindow (fc::FWidget* parent)
312+
: fc::FWindow{parent}
313+
{
314+
fc::FWidget::setForegroundColor (fc::FColor::White);
315+
fc::FWidget::setBackgroundColor (fc::FColor::Black);
316+
}
317+
318+
//----------------------------------------------------------------------
319+
void PictureSpaceWindow::setPos (const fc::FPoint& pos, bool)
320+
{
321+
fc::FWindow::setPos (pos, false);
322+
putArea (getTermPos(), getVWin());
323+
}
341324

342325
//----------------------------------------------------------------------
343326
void PictureSpaceWindow::draw()
344327
{
345-
SpaceWindow::draw();
328+
setColor();
329+
setTransparent();
330+
clearArea();
331+
unsetTransparent();
346332

347333
if ( fc::FVTerm::getFOutput()->getMaxColor() < 16 )
348334
return;
@@ -362,6 +348,20 @@ void PictureSpaceWindow::draw()
362348
copyArea (getVWin(), fc::FPoint(10, 10), planet.get());
363349
}
364350

351+
//----------------------------------------------------------------------
352+
void PictureSpaceWindow::initLayout()
353+
{
354+
auto term_size = fc::FSize({getDesktopWidth(), getDesktopHeight()});
355+
setSize(term_size, false);
356+
fc::FWidget::initLayout();
357+
}
358+
359+
//----------------------------------------------------------------------
360+
void PictureSpaceWindow::adjustSize()
361+
{
362+
fc::FWindow::adjustSize();
363+
initLayout();
364+
}
365365

366366
//----------------------------------------------------------------------
367367
// class ParallaxScrolling
@@ -385,13 +385,14 @@ class ParallaxScrolling final : public fc::FWidget
385385
void onClose (fc::FCloseEvent*) override;
386386

387387
// Data members
388-
TextWindow text_layer{fc::FColor::Yellow, fc::FColor::Black, this};
389388
SpaceWindow layer1_lhs{fc::FColor::DarkGray, fc::FColor::Black, this};
390389
SpaceWindow layer1_rhs{fc::FColor::DarkGray, fc::FColor::Black, this};
391390
SpaceWindow layer2_lhs{fc::FColor::LightGray, fc::FColor::Black, this};
392391
SpaceWindow layer2_rhs{fc::FColor::LightGray, fc::FColor::Black, this};
393392
SpaceWindow layer3_lhs{fc::FColor::White, fc::FColor::Black, this};
394-
PictureSpaceWindow layer3_rhs{fc::FColor::White, fc::FColor::Black, this};
393+
SpaceWindow layer3_rhs{fc::FColor::White, fc::FColor::Black, this};
394+
PictureSpaceWindow picture{this};
395+
TextWindow text_layer{fc::FColor::Yellow, fc::FColor::Black, this};
395396
int timer1{-1};
396397
int timer2{-1};
397398
int timer3{-1};
@@ -427,6 +428,7 @@ void ParallaxScrolling::initLayout()
427428
setGeometry({1, 1}, term_size, false);
428429
auto lhs_pos = fc::FPoint{1, 1};
429430
auto rhs_pos = fc::FPoint{int(getDesktopWidth() + 1), 1};
431+
picture.setPos(rhs_pos, false);
430432
layer1_lhs.setPos(lhs_pos, false);
431433
layer2_lhs.setPos(lhs_pos, false);
432434
layer3_lhs.setPos(lhs_pos, false);
@@ -478,6 +480,7 @@ void ParallaxScrolling::onTimer (fc::FTimerEvent* ev)
478480
else if ( timer3 == timer_id )
479481
{
480482
scrollLeft (layer3_lhs, layer3_rhs);
483+
picture.setPos (layer3_rhs.getPos());
481484
}
482485

483486
forceTerminalUpdate();

0 commit comments

Comments
 (0)