Files
cuframes-composer/include/cuframes_composer/cpp/cell.hpp
T
gx f1c79eabde Phase 11b A: CMake C++17 + базовые headers
Branch phase11b-cpp — refactor композитора на ООП.

Что сделано в этом коммите:
  - CMakeLists.txt: CMAKE_CXX_STANDARD 17, language=CXX
  - include/cuframes_composer/cpp/cuda_raii.hpp: CudaBuffer + CudaStream
    как RAII обёртки (cuMemAlloc/cuMemFree, cuStreamCreate/Destroy).
    Non-copyable, movable. Zero-copy: handle CUdeviceptr передаётся
    идентично C-коду.
  - cpp/types.hpp: Rect (pixel coords) + NV12Ref (общий read-write
    референс на Y/UV plane'ы output буфера — composer + cells + decorations
    делят его без копий).
  - cpp/decoration.hpp: абстрактный Decoration с draw(stream, dst, parent_rect).
  - cpp/cell.hpp: абстрактный Cell с draw() = draw_content() +
    iterate decorations. Композиция через add_decoration().

Что НЕ сделано (следующие коммиты):
  - CameraCell, WidgetCell, BlankCell (cell-content реализации)
  - LabelDecoration, BorderDecoration (с FreeType/cugrid)
  - Layout (контейнер cells + apply_template)
  - Composer класс (owner SourcePool + Layout + OutputSurface)
  - extern "C" ABI shim для совместимости с control.c, grid_record.c
  - Удаление старых composer.c / overlay.c / layouts.c
  - Восстановление функционала JSON templates + auto-labels

Производительность: virtual call overhead 1 indirect call per cell per
frame (negligible), никаких heap allocations в hot path, CUDA pipeline
1:1 идентичен C-версии.

Refs: #195 (Phase 11b C++ refactor)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-03 21:27:44 +01:00

65 lines
2.2 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* Cell — базовый абстрактный класс ячейки композитора (Phase 11b).
*
* Cell — это прямоугольная область output frame, рисуемая в свою geom_.
* Реализации (CameraCell, WidgetCell, BlankCell) определяют content-рендер;
* декорации (Label, Border) добавляются композицией через add_decoration().
*
* Lifecycle:
* 1. Layout::apply_template() создаёт нужные Cell-подклассы.
* 2. На каждом compose: cell.draw(stream, dst) рисует свой контент
* + все decorations.
* 3. Layout уничтожает cells при apply нового template'а.
*
* Лицензия: LGPL-2.1+
*/
#ifndef CUFRAMES_COMPOSER_CPP_CELL_HPP
#define CUFRAMES_COMPOSER_CPP_CELL_HPP
#include "decoration.hpp"
#include "types.hpp"
#include <memory>
#include <vector>
namespace cfc {
class Cell {
public:
explicit Cell(const Rect& geom) : geom_(geom) {}
virtual ~Cell() = default;
Cell(const Cell&) = delete;
Cell& operator=(const Cell&) = delete;
/* Геометрия cell в pixel-координатах output frame. */
const Rect& geometry() const noexcept { return geom_; }
void set_geometry(const Rect& r) noexcept { geom_ = r; }
/* Добавить decoration (cell takes ownership). */
void add_decoration(std::unique_ptr<Decoration> d) {
decorations_.push_back(std::move(d));
}
/* Основной hook: рисует content + все decorations. Реализации обычно
* переопределяют только draw_content(), а draw_decorations() общий. */
void draw(CUstream stream, NV12Ref& dst) {
if (geom_.empty()) return;
draw_content(stream, dst);
for (auto& dec : decorations_) {
dec->draw(stream, dst, geom_);
}
}
protected:
/* Реализуется подклассом. */
virtual void draw_content(CUstream stream, NV12Ref& dst) = 0;
Rect geom_;
std::vector<std::unique_ptr<Decoration>> decorations_;
};
} // namespace cfc
#endif /* CUFRAMES_COMPOSER_CPP_CELL_HPP */