--- nono/vm/planevram.cpp 2026/04/29 17:05:33 1.1.1.5 +++ nono/vm/planevram.cpp 2026/04/29 17:06:00 1.1.1.8 @@ -10,16 +10,10 @@ // #include "planevram.h" -#include "mybswap.h" +#include "missing_bswap.h" #include #include - -// v[] がいずれかでも true なら true を返す。 -static bool -AnyOf(const std::vector& v) -{ - return std::any_of(v.begin(), v.end(), [](bool x) { return x; }); -} +#include // コンストラクタ PlaneVRAMDevice::PlaneVRAMDevice(int width_, int height_) @@ -29,33 +23,14 @@ PlaneVRAMDevice::PlaneVRAMDevice(int wid nplane = -1; composite.Create(width_, height_); - - dirty.line.resize(height_); - pending.line.resize(height_); - - // レンダリング時に使うテーブルを事前に計算。 - InitDeptable(); -} - -// デストラクタ -PlaneVRAMDevice::~PlaneVRAMDevice() -{ -} - -// リセット -void -PlaneVRAMDevice::ResetHard(bool poweron) -{ - // XXX ここ? - Invalidate(); } -// レンダリング時に使うテーブルを事前に計算。 -void -PlaneVRAMDevice::InitDeptable() +// 初期化 +bool +PlaneVRAMDevice::Init() { - deptable.reset(new uint64[256]); - + // レンダリング時に使うテーブルを事前に計算。 + // // %abcdefgh の8ビットを // リトルエンディアンホストでは // %0000000h'0000000g'0000000f'0000000e'0000000d'0000000c'0000000b'0000000a @@ -63,7 +38,14 @@ PlaneVRAMDevice::InitDeptable() // %0000000a'0000000b'0000000c'0000000d'0000000e'0000000f'0000000g'0000000h // の64ビットに伸張する。 // (8ビットを各バイトの最下位ビットに対応させる) - for (uint i = 0; i < 256; i++) { + constexpr uint num = 256; + deptable.reset(new(std::nothrow) uint64[num]); + if ((bool)deptable == false) { + warnx("Could not allocate %zu bytes at %s", + sizeof(uint64) * num, __method__); + return false; + } + for (uint i = 0; i < num; i++) { uint64 res = 0; for (int bit = 0; bit < 8; bit++) { int n = bit * 8; @@ -74,13 +56,28 @@ PlaneVRAMDevice::InitDeptable() } deptable[i] = res; } + + return true; +} + +// デストラクタ +PlaneVRAMDevice::~PlaneVRAMDevice() +{ +} + +// リセット +void +PlaneVRAMDevice::ResetHard(bool poweron) +{ + // XXX ここ? + Invalidate(); } // 全画面の更新フラグを立てる void PlaneVRAMDevice::Invalidate() { - std::fill(dirty.line.begin(), dirty.line.end(), 1); + dirty.line.set(); } // VRAM には更新がないが再レンダリングが必要。 @@ -97,26 +94,20 @@ PlaneVRAMDevice::Invalidate2() bool PlaneVRAMDevice::Snap() { - const uint height = composite.GetHeight(); bool update_needed; // 更新 (dirty) があれば pending に重ねる。 { - std::unique_lock lock(mtx); - for (int y = 0; y < height; y++) { - // std::vector には operator|=() がない。 - if (__predict_false(dirty.line[y])) { - pending.line[y] = true; - dirty.line[y] = false; - } - } + std::lock_guard lock(mtx); + pending.line |= dirty.line; + dirty.line.reset(); if (__predict_false(dirty.invalidate2)) { pending.invalidate2 = true; dirty.invalidate2 = false; } - update_needed = AnyOf(pending.line) || pending.invalidate2; + update_needed = pending.line.any() || pending.invalidate2; } return update_needed; @@ -133,15 +124,15 @@ PlaneVRAMDevice::Render(BitmapRGBX& dst) // ローカルにコピー。 ModifyInfo modified; { - std::unique_lock lock(mtx); + std::lock_guard lock(mtx); modified.line = pending.line; - std::fill(pending.line.begin(), pending.line.end(), false); modified.invalidate2 = pending.invalidate2; + pending.line.reset(); pending.invalidate2 = false; } // VRAM に更新があれば composite を更新。 - if (AnyOf(modified.line)) { + if (modified.line.any()) { RenderVRAMToComposite(modified.line); updated = true; } @@ -159,7 +150,7 @@ PlaneVRAMDevice::Render(BitmapRGBX& dst) // VRAM から composite 画面を合成する。 // レンダラスレッドから呼ばれる。 void -PlaneVRAMDevice::RenderVRAMToComposite(const std::vector& modified) +PlaneVRAMDevice::RenderVRAMToComposite(const bitset1024& modified) { const uint width = composite.GetWidth(); const uint height = composite.GetHeight(); @@ -170,8 +161,7 @@ PlaneVRAMDevice::RenderVRAMToComposite(c // テキスト合成画面を描く for (uint y = 0; y < height; y++) { - bool mod = modified[y]; - if (mod == false) { + if (modified.test(y) == false) { continue; }