--- nono/vm/planevram.h 2026/04/29 17:05:29 1.1.1.4 +++ nono/vm/planevram.h 2026/04/29 17:06:01 1.1.1.8 @@ -12,33 +12,45 @@ #pragma once #include "device.h" -#include "renderer.h" -#include +#include "bitmap.h" +#include +#include class PlaneVRAMDevice : public IODevice { using inherited = IODevice; + using bitset1024 = std::bitset<1024>; + + // 更新情報。 + struct ModifyInfo + { + // 1ライン単位の更新フラグ。 + // 仮想 Y 座標に対応するので Lunafb も TVRAM も 1024個。 + bitset1024 line {}; + + // パレットを更新した場合やスクロールした場合のように、 + // composite に変更がなくても bitmap を更新する必要がある場合は true。 + bool invalidate2 {}; + }; + public: PlaneVRAMDevice(int width_, int height_); ~PlaneVRAMDevice() override; + bool Init() override; void ResetHard(bool poweron) override; - // レンダリング時に使うテーブルを事前に計算する。 - void InitDeptable(); - // プレーン数を取得 uint GetPlaneCount() const { return nplane; } - // 更新情報を取得 - bool GetModify(ModifyInfo *) const; - - // 更新フラグをクリア - void ClearDirty(); + bool Snap(); // 画面を合成する - bool Render(BitmapRGBX& dst, const ModifyInfo& modify); + bool Render(BitmapRGBX& dst); + + // VRAM には更新がないが再レンダリングが必要。(パレット変更、スクロール等) + void Invalidate2(); // 合成ビットマップを取得する const BitmapI8& GetComposite() const { return composite; } @@ -51,10 +63,11 @@ class PlaneVRAMDevice : public IODevice void Invalidate(); // 垂直 VRAM から BitmapI8 バッファを作成する - void RenderVRAMToComposite(const ModifyInfo& modify); + void RenderVRAMToComposite(const bitset1024& modified); // BitmapI8 バッファから BitmapRGBX を作成する。 - void RenderCompositeToRGBX(BitmapRGBX& dst, const ModifyInfo& modify); + void RenderCompositeToRGBX(BitmapRGBX& dst, + const ModifyInfo& modified); // X 方向にはみ出したときに対応する仮想画面の Y 座標を返す。 virtual int GetWrapY(int) const = 0; @@ -71,9 +84,13 @@ class PlaneVRAMDevice : public IODevice // テキスト画面の合成ビットマップ BitmapI8 composite {}; - // 仮想画面の更新フラグ。仮想 Y 座標に対応するので - // Lunafb も TVRAM も 1024個。 - std::vector dirty {}; + // VM スレッド内での仮想画面の更新フラグ。 + ModifyInfo dirty {}; + + // レンダラスレッドで未処理の行。 + // VM スレッドからレンダラスレッドへの連絡用なので mtx で保護する。 + ModifyInfo pending {}; + std::mutex mtx {}; // レンダリング時に使う変換テーブル std::unique_ptr deptable {}; @@ -86,6 +103,6 @@ class PlaneVRAMDevice : public IODevice int yscroll {}; }; -static inline PlaneVRAMDevice *GetPlaneVRAMDevice() { +inline PlaneVRAMDevice *GetPlaneVRAMDevice() { return Object::GetObject(OBJ_PLANEVRAM); }