diff options
89 files changed, 1743 insertions, 1616 deletions
diff --git a/kms++/inc/kms++/atomicreq.h b/kms++/inc/kms++/atomicreq.h index a678b54..780cc8f 100644 --- a/kms++/inc/kms++/atomicreq.h +++ b/kms++/inc/kms++/atomicreq.h @@ -20,9 +20,9 @@ public: AtomicReq& operator=(const AtomicReq& other) = delete; void add(uint32_t ob_id, uint32_t prop_id, uint64_t value); - void add(DrmPropObject *ob, Property *prop, uint64_t value); - void add(DrmPropObject *ob, const std::string& prop, uint64_t value); - void add(DrmPropObject *ob, const std::map<std::string, uint64_t>& values); + void add(DrmPropObject* ob, Property* prop, uint64_t value); + void add(DrmPropObject* ob, const std::string& prop, uint64_t value); + void add(DrmPropObject* ob, const std::map<std::string, uint64_t>& values); void add_display(Connector* conn, Crtc* crtc, Blob* videomode, Plane* primary, Framebuffer* fb); @@ -36,4 +36,4 @@ private: _drmModeAtomicReq* m_req; }; -} +} // namespace kms diff --git a/kms++/inc/kms++/blob.h b/kms++/inc/kms++/blob.h index 31e915c..011613d 100644 --- a/kms++/inc/kms++/blob.h +++ b/kms++/inc/kms++/blob.h @@ -5,7 +5,6 @@ namespace kms { - class Blob : public DrmObject { public: @@ -19,4 +18,4 @@ private: bool m_created; }; -} +} // namespace kms diff --git a/kms++/inc/kms++/card.h b/kms++/inc/kms++/card.h index f60b184..bf6f9bf 100644 --- a/kms++/inc/kms++/card.h +++ b/kms++/inc/kms++/card.h @@ -11,8 +11,7 @@ namespace kms { -struct CardVersion -{ +struct CardVersion { int major; int minor; int patchlevel; @@ -24,6 +23,7 @@ struct CardVersion class Card { friend class Framebuffer; + public: static std::unique_ptr<Card> open_named_card(const std::string& name); @@ -95,4 +95,4 @@ private: CardVersion m_version; }; -} +} // namespace kms diff --git a/kms++/inc/kms++/connector.h b/kms++/inc/kms++/connector.h index 323d37d..f45a487 100644 --- a/kms++/inc/kms++/connector.h +++ b/kms++/inc/kms++/connector.h @@ -7,11 +7,9 @@ namespace kms { - struct ConnectorPriv; -enum class ConnectorStatus -{ +enum class ConnectorStatus { Unknown, Connected, Disconnected, @@ -20,6 +18,7 @@ enum class ConnectorStatus class Connector : public DrmPropObject { friend class Card; + public: void refresh(); @@ -44,6 +43,7 @@ public: const std::string& subpixel_str() const; std::vector<Videomode> get_modes() const; std::vector<Encoder*> get_encoders() const; + private: Connector(Card& card, uint32_t id, uint32_t idx); ~Connector() override; @@ -59,4 +59,4 @@ private: Crtc* m_saved_crtc; }; -} +} // namespace kms diff --git a/kms++/inc/kms++/crtc.h b/kms++/inc/kms++/crtc.h index 990fc20..1ba8a07 100644 --- a/kms++/inc/kms++/crtc.h +++ b/kms++/inc/kms++/crtc.h @@ -6,13 +6,13 @@ namespace kms { - struct CrtcPriv; class Crtc : public DrmPropObject { friend class Card; friend class Connector; + public: void refresh(); @@ -21,7 +21,7 @@ public: int set_mode(Connector* conn, const Videomode& mode); int set_mode(Connector* conn, Framebuffer& fb, const Videomode& mode); - int set_plane(Plane *plane, Framebuffer &fb, + int set_plane(Plane* plane, Framebuffer& fb, int32_t dst_x, int32_t dst_y, uint32_t dst_w, uint32_t dst_h, float src_x, float src_y, float src_w, float src_h); int disable_mode(); @@ -30,7 +30,7 @@ public: Plane* get_primary_plane(); - int page_flip(Framebuffer& fb, void *data); + int page_flip(Framebuffer& fb, void* data); uint32_t buffer_id() const; uint32_t x() const; @@ -40,15 +40,16 @@ public: int mode_valid() const; Videomode mode() const; int gamma_size() const; + private: Crtc(Card& card, uint32_t id, uint32_t idx); ~Crtc() override; void setup() override; - void restore_mode(Connector *conn); + void restore_mode(Connector* conn); CrtcPriv* m_priv; std::vector<Plane*> m_possible_planes; }; -} +} // namespace kms diff --git a/kms++/inc/kms++/decls.h b/kms++/inc/kms++/decls.h index 438dad5..a4b5631 100644 --- a/kms++/inc/kms++/decls.h +++ b/kms++/inc/kms++/decls.h @@ -18,4 +18,4 @@ class PageFlipHandlerBase; class Plane; class Property; struct Videomode; -} +} // namespace kms diff --git a/kms++/inc/kms++/dmabufframebuffer.h b/kms++/inc/kms++/dmabufframebuffer.h index 328dd2b..6643a81 100644 --- a/kms++/inc/kms++/dmabufframebuffer.h +++ b/kms++/inc/kms++/dmabufframebuffer.h @@ -8,7 +8,6 @@ namespace kms { - class DmabufFramebuffer : public Framebuffer { public: @@ -42,7 +41,7 @@ private: uint32_t stride; uint32_t offset; uint64_t modifier; - uint8_t *map; + uint8_t* map; }; unsigned m_num_planes; @@ -53,4 +52,4 @@ private: uint32_t m_sync_flags = 0; }; -} +} // namespace kms diff --git a/kms++/inc/kms++/drmobject.h b/kms++/inc/kms++/drmobject.h index a939aa7..e15ed4c 100644 --- a/kms++/inc/kms++/drmobject.h +++ b/kms++/inc/kms++/drmobject.h @@ -6,10 +6,10 @@ namespace kms { - class DrmObject { friend class Card; + public: DrmObject(const DrmObject& other) = delete; DrmObject& operator=(const DrmObject& other) = delete; @@ -26,7 +26,7 @@ protected: virtual ~DrmObject(); - virtual void setup() { } + virtual void setup() {} virtual void set_id(uint32_t id); @@ -37,4 +37,4 @@ private: uint32_t m_object_type; uint32_t m_idx; }; -} +} // namespace kms diff --git a/kms++/inc/kms++/drmpropobject.h b/kms++/inc/kms++/drmpropobject.h index 48e0265..dc3a806 100644 --- a/kms++/inc/kms++/drmpropobject.h +++ b/kms++/inc/kms++/drmpropobject.h @@ -8,10 +8,10 @@ namespace kms { - class DrmPropObject : public DrmObject { friend class Card; + public: void refresh_props(); @@ -38,4 +38,4 @@ protected: private: std::map<uint32_t, uint64_t> m_prop_values; }; -} +} // namespace kms diff --git a/kms++/inc/kms++/dumbframebuffer.h b/kms++/inc/kms++/dumbframebuffer.h index 15ea982..af5fe42 100644 --- a/kms++/inc/kms++/dumbframebuffer.h +++ b/kms++/inc/kms++/dumbframebuffer.h @@ -7,7 +7,6 @@ namespace kms { - class DumbFramebuffer : public Framebuffer { public: @@ -35,7 +34,7 @@ private: uint32_t size; uint32_t stride; uint32_t offset; - uint8_t *map; + uint8_t* map; }; unsigned m_num_planes; @@ -43,4 +42,4 @@ private: PixelFormat m_format; }; -} +} // namespace kms diff --git a/kms++/inc/kms++/encoder.h b/kms++/inc/kms++/encoder.h index 72c0213..9476d80 100644 --- a/kms++/inc/kms++/encoder.h +++ b/kms++/inc/kms++/encoder.h @@ -5,12 +5,12 @@ namespace kms { - struct EncoderPriv; class Encoder : public DrmPropObject { friend class Card; + public: void refresh(); @@ -18,10 +18,11 @@ public: std::vector<Crtc*> get_possible_crtcs() const; const std::string& get_encoder_type() const; + private: Encoder(Card& card, uint32_t id, uint32_t idx); ~Encoder() override; EncoderPriv* m_priv; }; -} +} // namespace kms diff --git a/kms++/inc/kms++/extframebuffer.h b/kms++/inc/kms++/extframebuffer.h index 3fb74ca..00dc9bf 100644 --- a/kms++/inc/kms++/extframebuffer.h +++ b/kms++/inc/kms++/extframebuffer.h @@ -8,7 +8,6 @@ namespace kms { - class ExtFramebuffer : public Framebuffer { public: @@ -34,7 +33,7 @@ private: uint32_t stride; uint32_t offset; uint64_t modifier; - uint8_t *map; + uint8_t* map; }; unsigned m_num_planes; @@ -43,4 +42,4 @@ private: PixelFormat m_format; }; -} +} // namespace kms diff --git a/kms++/inc/kms++/framebuffer.h b/kms++/inc/kms++/framebuffer.h index bcfd1f0..6f77b98 100644 --- a/kms++/inc/kms++/framebuffer.h +++ b/kms++/inc/kms++/framebuffer.h @@ -5,16 +5,16 @@ namespace kms { -enum class CpuAccess -{ +enum class CpuAccess { Read, Write, ReadWrite, }; -class IFramebuffer { +class IFramebuffer +{ public: - virtual ~IFramebuffer() { } + virtual ~IFramebuffer() {} virtual uint32_t width() const = 0; virtual uint32_t height() const = 0; @@ -28,8 +28,8 @@ public: virtual uint8_t* map(unsigned plane) { throw std::runtime_error("not implemented"); } virtual int prime_fd(unsigned plane) { throw std::runtime_error("not implemented"); } - virtual void begin_cpu_access(CpuAccess access) { } - virtual void end_cpu_access() { } + virtual void begin_cpu_access(CpuAccess access) {} + virtual void end_cpu_access() {} }; class Framebuffer : public DrmObject, public IFramebuffer @@ -42,6 +42,7 @@ public: uint32_t height() const override { return m_height; } void flush(); + protected: Framebuffer(Card& card, uint32_t width, uint32_t height); @@ -50,4 +51,4 @@ private: uint32_t m_height; }; -} +} // namespace kms diff --git a/kms++/inc/kms++/mode_cvt.h b/kms++/inc/kms++/mode_cvt.h index 8902e4a..3fa8a07 100644 --- a/kms++/inc/kms++/mode_cvt.h +++ b/kms++/inc/kms++/mode_cvt.h @@ -4,7 +4,6 @@ namespace kms { - Videomode videomode_from_cvt(uint32_t hact, uint32_t vact, uint32_t refresh, bool ilace, bool reduced_v2, bool video_optimized); } diff --git a/kms++/inc/kms++/modedb.h b/kms++/inc/kms++/modedb.h index b6447c6..0650442 100644 --- a/kms++/inc/kms++/modedb.h +++ b/kms++/inc/kms++/modedb.h @@ -13,4 +13,4 @@ extern const Videomode cea_modes[]; const Videomode& find_dmt(uint32_t width, uint32_t height, float vrefresh, bool ilace); const Videomode& find_cea(uint32_t width, uint32_t height, float vrefresh, bool ilace); -} +} // namespace kms diff --git a/kms++/inc/kms++/omap/omapcard.h b/kms++/inc/kms++/omap/omapcard.h index 2f1f528..123205b 100644 --- a/kms++/inc/kms++/omap/omapcard.h +++ b/kms++/inc/kms++/omap/omapcard.h @@ -17,4 +17,4 @@ public: private: struct omap_device* m_omap_dev; }; -} +} // namespace kms diff --git a/kms++/inc/kms++/omap/omapframebuffer.h b/kms++/inc/kms++/omap/omapframebuffer.h index 70bf946..72329b4 100644 --- a/kms++/inc/kms++/omap/omapframebuffer.h +++ b/kms++/inc/kms++/omap/omapframebuffer.h @@ -12,8 +12,7 @@ class OmapCard; class OmapFramebuffer : public Framebuffer { public: - enum Flags - { + enum Flags { None = 0, Tiled = 1 << 0, MemContig = 1 << 1, @@ -59,4 +58,4 @@ private: PixelFormat m_format; }; -} +} // namespace kms diff --git a/kms++/inc/kms++/pagefliphandler.h b/kms++/inc/kms++/pagefliphandler.h index 79cda0d..2f5fdcd 100644 --- a/kms++/inc/kms++/pagefliphandler.h +++ b/kms++/inc/kms++/pagefliphandler.h @@ -1,11 +1,12 @@ #pragma once -namespace kms { +namespace kms +{ class PageFlipHandlerBase { public: - PageFlipHandlerBase() { } - virtual ~PageFlipHandlerBase() { } + PageFlipHandlerBase() {} + virtual ~PageFlipHandlerBase() {} virtual void handle_page_flip(uint32_t frame, double time) = 0; }; -} +} // namespace kms diff --git a/kms++/inc/kms++/pipeline.h b/kms++/inc/kms++/pipeline.h index ef04ec1..236e582 100644 --- a/kms++/inc/kms++/pipeline.h +++ b/kms++/inc/kms++/pipeline.h @@ -8,4 +8,4 @@ struct Pipeline { Crtc* crtc; Connector* connector; }; -} +} // namespace kms diff --git a/kms++/inc/kms++/pixelformats.h b/kms++/inc/kms++/pixelformats.h index 4e453a2..6f2671b 100644 --- a/kms++/inc/kms++/pixelformats.h +++ b/kms++/inc/kms++/pixelformats.h @@ -6,13 +6,12 @@ namespace kms { -constexpr uint32_t MakeFourCC(const char *fourcc) +constexpr uint32_t MakeFourCC(const char* fourcc) { return fourcc[0] | (fourcc[1] << 8) | (fourcc[2] << 16) | (fourcc[3] << 24); } -enum class PixelFormat : uint32_t -{ +enum class PixelFormat : uint32_t { Undefined = 0, NV12 = MakeFourCC("NV12"), @@ -82,21 +81,18 @@ static inline std::string PixelFormatToFourCC(PixelFormat f) return std::string(buf); } -enum class PixelColorType -{ +enum class PixelColorType { RGB, YUV, }; -struct PixelFormatPlaneInfo -{ +struct PixelFormatPlaneInfo { uint8_t bitspp; uint8_t xsub; uint8_t ysub; }; -struct PixelFormatInfo -{ +struct PixelFormatInfo { PixelColorType type; uint8_t num_planes; struct PixelFormatPlaneInfo planes[4]; @@ -104,4 +100,4 @@ struct PixelFormatInfo const struct PixelFormatInfo& get_pixel_format_info(PixelFormat format); -} +} // namespace kms diff --git a/kms++/inc/kms++/plane.h b/kms++/inc/kms++/plane.h index 1d78537..d3cfde5 100644 --- a/kms++/inc/kms++/plane.h +++ b/kms++/inc/kms++/plane.h @@ -4,9 +4,7 @@ namespace kms { - -enum class PlaneType -{ +enum class PlaneType { Overlay = 1 << 0, Primary = 1 << 1, Cursor = 1 << 2, @@ -17,6 +15,7 @@ struct PlanePriv; class Plane : public DrmPropObject { friend class Card; + public: bool supports_crtc(Crtc* crtc) const; bool supports_format(PixelFormat fmt) const; @@ -33,10 +32,11 @@ public: uint32_t x() const; uint32_t y() const; uint32_t gamma_size() const; + private: Plane(Card& card, uint32_t id, uint32_t idx); ~Plane() override; PlanePriv* m_priv; }; -} +} // namespace kms diff --git a/kms++/inc/kms++/property.h b/kms++/inc/kms++/property.h index 8d6088e..7c7b834 100644 --- a/kms++/inc/kms++/property.h +++ b/kms++/inc/kms++/property.h @@ -6,11 +6,9 @@ namespace kms { - struct PropertyPriv; -enum class PropertyType -{ +enum class PropertyType { Range, Enum, Blob, @@ -22,6 +20,7 @@ enum class PropertyType class Property : public DrmObject { friend class Card; + public: const std::string& name() const; @@ -32,6 +31,7 @@ public: std::map<uint64_t, std::string> get_enums() const; std::vector<uint64_t> get_values() const; std::vector<uint32_t> get_blob_ids() const; + private: Property(Card& card, uint32_t id); ~Property() override; @@ -41,4 +41,4 @@ private: PropertyPriv* m_priv; std::string m_name; }; -} +} // namespace kms diff --git a/kms++/inc/kms++/videomode.h b/kms++/inc/kms++/videomode.h index 3aacd57..7209ea9 100644 --- a/kms++/inc/kms++/videomode.h +++ b/kms++/inc/kms++/videomode.h @@ -8,16 +8,13 @@ namespace kms { - -enum class SyncPolarity -{ +enum class SyncPolarity { Undefined, Positive, Negative, }; -struct Videomode -{ +struct Videomode { std::string name; uint32_t clock; @@ -26,8 +23,8 @@ struct Videomode uint32_t vrefresh; - uint32_t flags; // DRM_MODE_FLAG_* - uint32_t type; // DRM_MODE_TYPE_* + uint32_t flags; // DRM_MODE_FLAG_* + uint32_t type; // DRM_MODE_TYPE_* std::unique_ptr<Blob> to_blob(Card& card) const; @@ -59,4 +56,4 @@ struct Videomode struct Videomode videomode_from_timings(uint32_t clock_khz, uint16_t hact, uint16_t hfp, uint16_t hsw, uint16_t hbp, uint16_t vact, uint16_t vfp, uint16_t vsw, uint16_t vbp); -} +} // namespace kms diff --git a/kms++/src/atomicreq.cpp b/kms++/src/atomicreq.cpp index 28128f2..e01d7c2 100644 --- a/kms++/src/atomicreq.cpp +++ b/kms++/src/atomicreq.cpp @@ -14,10 +14,21 @@ struct _drmModeAtomicReq; typedef struct _drmModeAtomicReq* drmModeAtomicReqPtr; -static inline drmModeAtomicReqPtr drmModeAtomicAlloc() { return 0; } -static inline void drmModeAtomicFree(drmModeAtomicReqPtr) { } -static inline int drmModeAtomicAddProperty(drmModeAtomicReqPtr, uint32_t, uint32_t, uint64_t) { return 0; } -static inline int drmModeAtomicCommit(int, drmModeAtomicReqPtr, int, void*) { return 0; } +static inline drmModeAtomicReqPtr drmModeAtomicAlloc() +{ + return 0; +} +static inline void drmModeAtomicFree(drmModeAtomicReqPtr) +{ +} +static inline int drmModeAtomicAddProperty(drmModeAtomicReqPtr, uint32_t, uint32_t, uint64_t) +{ + return 0; +} +static inline int drmModeAtomicCommit(int, drmModeAtomicReqPtr, int, void*) +{ + return 0; +} #endif // DRM_CLIENT_CAP_ATOMIC @@ -44,7 +55,7 @@ void AtomicReq::add(uint32_t ob_id, uint32_t prop_id, uint64_t value) throw std::invalid_argument("foo"); } -void AtomicReq::add(DrmPropObject* ob, Property *prop, uint64_t value) +void AtomicReq::add(DrmPropObject* ob, Property* prop, uint64_t value) { add(ob->id(), prop->id(), value); } @@ -56,33 +67,33 @@ void AtomicReq::add(kms::DrmPropObject* ob, const string& prop, uint64_t value) void AtomicReq::add(kms::DrmPropObject* ob, const map<string, uint64_t>& values) { - for(const auto& kvp : values) + for (const auto& kvp : values) add(ob, kvp.first, kvp.second); } void AtomicReq::add_display(Connector* conn, Crtc* crtc, Blob* videomode, Plane* primary, Framebuffer* fb) { add(conn, { - { "CRTC_ID", crtc->id() }, - }); + { "CRTC_ID", crtc->id() }, + }); add(crtc, { - { "ACTIVE", 1 }, - { "MODE_ID", videomode->id() }, - }); + { "ACTIVE", 1 }, + { "MODE_ID", videomode->id() }, + }); add(primary, { - { "FB_ID", fb->id() }, - { "CRTC_ID", crtc->id() }, - { "SRC_X", 0 << 16 }, - { "SRC_Y", 0 << 16 }, - { "SRC_W", fb->width() << 16 }, - { "SRC_H", fb->height() << 16 }, - { "CRTC_X", 0 }, - { "CRTC_Y", 0 }, - { "CRTC_W", fb->width() }, - { "CRTC_H", fb->height() }, - }); + { "FB_ID", fb->id() }, + { "CRTC_ID", crtc->id() }, + { "SRC_X", 0 << 16 }, + { "SRC_Y", 0 << 16 }, + { "SRC_W", fb->width() << 16 }, + { "SRC_H", fb->height() << 16 }, + { "CRTC_X", 0 }, + { "CRTC_Y", 0 }, + { "CRTC_W", fb->width() }, + { "CRTC_H", fb->height() }, + }); } int AtomicReq::test(bool allow_modeset) @@ -114,4 +125,4 @@ int AtomicReq::commit_sync(bool allow_modeset) return drmModeAtomicCommit(m_card.fd(), m_req, flags, 0); } -} +} // namespace kms diff --git a/kms++/src/blob.cpp b/kms++/src/blob.cpp index e1cd1f8..431863a 100644 --- a/kms++/src/blob.cpp +++ b/kms++/src/blob.cpp @@ -7,7 +7,6 @@ using namespace std; namespace kms { - Blob::Blob(Card& card, uint32_t blob_id) : DrmObject(card, blob_id, DRM_MODE_OBJECT_BLOB), m_created(false) { @@ -48,4 +47,4 @@ vector<uint8_t> Blob::data() return v; } -} +} // namespace kms diff --git a/kms++/src/card.cpp b/kms++/src/card.cpp index 3a7ab70..935969d 100644 --- a/kms++/src/card.cpp +++ b/kms++/src/card.cpp @@ -22,20 +22,19 @@ using namespace std; namespace kms { - static vector<string> glob(const string& pattern) { glob_t glob_result; memset(&glob_result, 0, sizeof(glob_result)); int r = glob(pattern.c_str(), 0, NULL, &glob_result); - if(r != 0) { + if (r != 0) { globfree(&glob_result); throw runtime_error("failed to find DRM cards"); } vector<string> filenames; - for(size_t i = 0; i < glob_result.gl_pathc; ++i) + for (size_t i = 0; i < glob_result.gl_pathc; ++i) filenames.push_back(string(glob_result.gl_pathv[i])); globfree(&glob_result); @@ -315,7 +314,7 @@ void Card::restore_modes() Connector* Card::get_first_connected_connector() const { - for(auto c : m_connectors) { + for (auto c : m_connectors) { if (c->connected()) return c; } @@ -334,23 +333,37 @@ DrmObject* Card::get_object(uint32_t id) const std::vector<kms::DrmObject*> Card::get_objects() const { vector<DrmObject*> v; - for(auto pair : m_obmap) + for (auto pair : m_obmap) v.push_back(pair.second); return v; } -Connector* Card::get_connector(uint32_t id) const { return dynamic_cast<Connector*>(get_object(id)); } -Crtc* Card::get_crtc(uint32_t id) const { return dynamic_cast<Crtc*>(get_object(id)); } -Encoder* Card::get_encoder(uint32_t id) const { return dynamic_cast<Encoder*>(get_object(id)); } -Property* Card::get_prop(uint32_t id) const { return dynamic_cast<Property*>(get_object(id)); } -Plane* Card::get_plane(uint32_t id) const { return dynamic_cast<Plane*>(get_object(id)); } +Connector* Card::get_connector(uint32_t id) const +{ + return dynamic_cast<Connector*>(get_object(id)); +} +Crtc* Card::get_crtc(uint32_t id) const +{ + return dynamic_cast<Crtc*>(get_object(id)); +} +Encoder* Card::get_encoder(uint32_t id) const +{ + return dynamic_cast<Encoder*>(get_object(id)); +} +Property* Card::get_prop(uint32_t id) const +{ + return dynamic_cast<Property*>(get_object(id)); +} +Plane* Card::get_plane(uint32_t id) const +{ + return dynamic_cast<Plane*>(get_object(id)); +} std::vector<kms::Pipeline> Card::get_connected_pipelines() { vector<Pipeline> outputs; - for (auto conn : get_connectors()) - { + for (auto conn : get_connectors()) { if (conn->connected() == false) continue; @@ -370,7 +383,7 @@ std::vector<kms::Pipeline> Card::get_connected_pipelines() to_string(conn->idx()) + " has no possible crtcs"); - outputs.push_back(Pipeline { crtc, conn }); + outputs.push_back(Pipeline{ crtc, conn }); } return outputs; @@ -378,7 +391,7 @@ std::vector<kms::Pipeline> Card::get_connected_pipelines() static void page_flip_handler(int fd, unsigned int frame, unsigned int sec, unsigned int usec, - void *data) + void* data) { auto handler = (PageFlipHandlerBase*)data; double time = sec + usec / 1000000.0; @@ -387,7 +400,7 @@ static void page_flip_handler(int fd, unsigned int frame, void Card::call_page_flip_handlers() { - drmEventContext ev { }; + drmEventContext ev{}; ev.version = DRM_EVENT_CONTEXT_VERSION; ev.page_flip_handler = page_flip_handler; @@ -400,18 +413,18 @@ int Card::disable_all() for (Crtc* c : m_crtcs) { req.add(c, { - { "ACTIVE", 0 }, - }); + { "ACTIVE", 0 }, + }); } for (Plane* p : m_planes) { req.add(p, { - { "FB_ID", 0 }, - { "CRTC_ID", 0 }, - }); + { "FB_ID", 0 }, + { "CRTC_ID", 0 }, + }); } return req.commit_sync(true); } -} +} // namespace kms diff --git a/kms++/src/connector.cpp b/kms++/src/connector.cpp index a408619..92bab80 100644 --- a/kms++/src/connector.cpp +++ b/kms++/src/connector.cpp @@ -12,7 +12,6 @@ using namespace std; namespace kms { - #ifndef DRM_MODE_CONNECTOR_DPI #define DRM_MODE_CONNECTOR_DPI 17 #endif @@ -46,7 +45,10 @@ static const map<int, string> connection_str = { }; static const map<int, string> subpix_str = { -#define DEF_SUBPIX(c) { DRM_MODE_SUBPIXEL_##c, #c } +#define DEF_SUBPIX(c) \ + { \ + DRM_MODE_SUBPIXEL_##c, #c \ + } DEF_SUBPIX(UNKNOWN), DEF_SUBPIX(HORIZONTAL_RGB), DEF_SUBPIX(HORIZONTAL_BGR), @@ -56,13 +58,12 @@ static const map<int, string> subpix_str = { #undef DEF_SUBPIX }; -struct ConnectorPriv -{ +struct ConnectorPriv { drmModeConnectorPtr drm_connector; }; -Connector::Connector(Card &card, uint32_t id, uint32_t idx) - :DrmPropObject(card, id, DRM_MODE_OBJECT_CONNECTOR, idx) +Connector::Connector(Card& card, uint32_t id, uint32_t idx) + : DrmPropObject(card, id, DRM_MODE_OBJECT_CONNECTOR, idx) { m_priv = new ConnectorPriv(); @@ -193,7 +194,7 @@ Videomode Connector::get_mode(unsigned xres, unsigned yres, float vrefresh, bool bool Connector::connected() const { return m_priv->drm_connector->connection == DRM_MODE_CONNECTED || - m_priv->drm_connector->connection == DRM_MODE_UNKNOWNCONNECTION; + m_priv->drm_connector->connection == DRM_MODE_UNKNOWNCONNECTION; } ConnectorStatus Connector::connector_status() const @@ -267,7 +268,7 @@ std::vector<Videomode> Connector::get_modes() const for (int i = 0; i < m_priv->drm_connector->count_modes; i++) modes.push_back(drm_mode_to_video_mode( - m_priv->drm_connector->modes[i])); + m_priv->drm_connector->modes[i])); return modes; } @@ -283,4 +284,4 @@ std::vector<Encoder*> Connector::get_encoders() const return encoders; } -} +} // namespace kms diff --git a/kms++/src/crtc.cpp b/kms++/src/crtc.cpp index 7ffaaff..6dc4333 100644 --- a/kms++/src/crtc.cpp +++ b/kms++/src/crtc.cpp @@ -11,14 +11,12 @@ using namespace std; namespace kms { - -struct CrtcPriv -{ +struct CrtcPriv { drmModeCrtcPtr drm_crtc; }; -Crtc::Crtc(Card &card, uint32_t id, uint32_t idx) - :DrmPropObject(card, id, DRM_MODE_OBJECT_CRTC, idx) +Crtc::Crtc(Card& card, uint32_t id, uint32_t idx) + : DrmPropObject(card, id, DRM_MODE_OBJECT_CRTC, idx) { m_priv = new CrtcPriv(); m_priv->drm_crtc = drmModeGetCrtc(this->card().fd(), this->id()); @@ -65,13 +63,13 @@ int Crtc::set_mode(Connector* conn, const Videomode& mode) unique_ptr<Blob> blob = mode.to_blob(card()); req.add(conn, { - { "CRTC_ID", this->id() }, - }); + { "CRTC_ID", this->id() }, + }); req.add(this, { - { "ACTIVE", 1 }, - { "MODE_ID", blob->id() }, - }); + { "ACTIVE", 1 }, + { "MODE_ID", blob->id() }, + }); int r = req.commit_sync(true); @@ -117,7 +115,7 @@ int Crtc::disable_plane(Plane* plane) Plane* Crtc::get_primary_plane() { - Plane *primary = nullptr; + Plane* primary = nullptr; for (Plane* p : get_possible_planes()) { if (p->plane_type() != PlaneType::Primary) @@ -135,7 +133,7 @@ Plane* Crtc::get_primary_plane() throw invalid_argument(string("No primary plane for crtc ") + to_string(id())); } -int Crtc::page_flip(Framebuffer& fb, void *data) +int Crtc::page_flip(Framebuffer& fb, void* data) { return drmModePageFlip(card().fd(), id(), fb.id(), DRM_MODE_PAGE_FLIP_EVENT, data); } @@ -180,4 +178,4 @@ int Crtc::gamma_size() const return m_priv->drm_crtc->gamma_size; } -} +} // namespace kms diff --git a/kms++/src/dmabufframebuffer.cpp b/kms++/src/dmabufframebuffer.cpp index 991d96c..cb76f09 100644 --- a/kms++/src/dmabufframebuffer.cpp +++ b/kms++/src/dmabufframebuffer.cpp @@ -62,8 +62,7 @@ DmabufFramebuffer::DmabufFramebuffer(Card& card, uint32_t width, uint32_t height bo_handles, pitches.data(), offsets.data(), &id, 0); if (r) throw invalid_argument(string("drmModeAddFB2 failed: ") + strerror(errno)); - } - else { + } else { modifiers.resize(4); r = drmModeAddFB2WithModifiers(card.fd(), width, height, (uint32_t)format, bo_handles, pitches.data(), offsets.data(), modifiers.data(), &id, DRM_MODE_FB_MODIFIERS); @@ -86,8 +85,8 @@ uint8_t* DmabufFramebuffer::map(unsigned plane) if (p.map) return p.map; - p.map = (uint8_t *)mmap(0, p.size, PROT_READ | PROT_WRITE, MAP_SHARED, - p.prime_fd, 0); + p.map = (uint8_t*)mmap(0, p.size, PROT_READ | PROT_WRITE, MAP_SHARED, + p.prime_fd, 0); if (p.map == MAP_FAILED) throw invalid_argument(string("mmap failed: ") + strerror(errno)); @@ -118,7 +117,7 @@ void DmabufFramebuffer::begin_cpu_access(CpuAccess access) break; } - dma_buf_sync dbs { + dma_buf_sync dbs{ .flags = DMA_BUF_SYNC_START | m_sync_flags }; @@ -134,7 +133,7 @@ void DmabufFramebuffer::end_cpu_access() if (m_sync_flags == 0) throw runtime_error("begin_cpu sync not started"); - dma_buf_sync dbs { + dma_buf_sync dbs{ .flags = DMA_BUF_SYNC_END | m_sync_flags }; @@ -147,4 +146,4 @@ void DmabufFramebuffer::end_cpu_access() m_sync_flags = 0; } -} +} // namespace kms diff --git a/kms++/src/drmobject.cpp b/kms++/src/drmobject.cpp index 9c0f5ae..f01c8af 100644 --- a/kms++/src/drmobject.cpp +++ b/kms++/src/drmobject.cpp @@ -11,24 +11,22 @@ using namespace std; namespace kms { - DrmObject::DrmObject(Card& card, uint32_t object_type) - :m_card(card), m_id(-1), m_object_type(object_type), m_idx(0) + : m_card(card), m_id(-1), m_object_type(object_type), m_idx(0) { } DrmObject::DrmObject(Card& card, uint32_t id, uint32_t object_type, uint32_t idx) - :m_card(card), m_id(id), m_object_type(object_type), m_idx(idx) + : m_card(card), m_id(id), m_object_type(object_type), m_idx(idx) { } DrmObject::~DrmObject() { - } void DrmObject::set_id(uint32_t id) { m_id = id; } -} +} // namespace kms diff --git a/kms++/src/drmpropobject.cpp b/kms++/src/drmpropobject.cpp index c78f70a..616aef7 100644 --- a/kms++/src/drmpropobject.cpp +++ b/kms++/src/drmpropobject.cpp @@ -11,7 +11,6 @@ using namespace std; namespace kms { - DrmPropObject::DrmPropObject(Card& card, uint32_t object_type) : DrmObject(card, object_type) { @@ -25,7 +24,6 @@ DrmPropObject::DrmPropObject(Card& card, uint32_t id, uint32_t object_type, uint DrmPropObject::~DrmPropObject() { - } void DrmPropObject::refresh_props() @@ -90,7 +88,7 @@ int DrmPropObject::set_prop_value(uint32_t id, uint64_t value) return drmModeObjectSetProperty(card().fd(), this->id(), this->object_type(), id, value); } -int DrmPropObject::set_prop_value(const string &name, uint64_t value) +int DrmPropObject::set_prop_value(const string& name, uint64_t value) { Property* prop = get_prop(name); @@ -100,4 +98,4 @@ int DrmPropObject::set_prop_value(const string &name, uint64_t value) return set_prop_value(prop->id(), value); } -} +} // namespace kms diff --git a/kms++/src/dumbframebuffer.cpp b/kms++/src/dumbframebuffer.cpp index 4c3c031..fc50586 100644 --- a/kms++/src/dumbframebuffer.cpp +++ b/kms++/src/dumbframebuffer.cpp @@ -19,14 +19,13 @@ using namespace std; namespace kms { - -DumbFramebuffer::DumbFramebuffer(Card &card, uint32_t width, uint32_t height, const string& fourcc) - :DumbFramebuffer(card, width, height, FourCCToPixelFormat(fourcc)) +DumbFramebuffer::DumbFramebuffer(Card& card, uint32_t width, uint32_t height, const string& fourcc) + : DumbFramebuffer(card, width, height, FourCCToPixelFormat(fourcc)) { } DumbFramebuffer::DumbFramebuffer(Card& card, uint32_t width, uint32_t height, PixelFormat format) - :Framebuffer(card, width, height), m_format(format) + : Framebuffer(card, width, height), m_format(format) { int r; @@ -65,16 +64,22 @@ DumbFramebuffer::DumbFramebuffer(Card& card, uint32_t width, uint32_t height, Pi /* create framebuffer object for the dumb-buffer */ uint32_t bo_handles[4] = { - m_planes[0].handle, m_planes[1].handle, - m_planes[2].handle, m_planes[3].handle, + m_planes[0].handle, + m_planes[1].handle, + m_planes[2].handle, + m_planes[3].handle, }; uint32_t pitches[4] = { - m_planes[0].stride, m_planes[1].stride, - m_planes[2].stride, m_planes[3].stride, + m_planes[0].stride, + m_planes[1].stride, + m_planes[2].stride, + m_planes[3].stride, }; uint32_t offsets[4] = { - m_planes[0].offset, m_planes[1].offset, - m_planes[2].offset, m_planes[3].offset, + m_planes[0].offset, + m_planes[1].offset, + m_planes[2].offset, + m_planes[3].offset, }; uint32_t id; r = drmModeAddFB2(card.fd(), width, height, (uint32_t)format, @@ -121,8 +126,8 @@ uint8_t* DumbFramebuffer::map(unsigned plane) throw invalid_argument(string("DRM_IOCTL_MODE_MAP_DUMB failed: ") + strerror(errno)); /* perform actual memory mapping */ - p.map = (uint8_t *)mmap(0, p.size, PROT_READ | PROT_WRITE, MAP_SHARED, - card().fd(), mreq.offset); + p.map = (uint8_t*)mmap(0, p.size, PROT_READ | PROT_WRITE, MAP_SHARED, + card().fd(), mreq.offset); if (p.map == MAP_FAILED) throw invalid_argument(string("mmap failed: ") + strerror(errno)); @@ -142,4 +147,4 @@ int DumbFramebuffer::prime_fd(unsigned int plane) return m_planes.at(plane).prime_fd; } -} +} // namespace kms diff --git a/kms++/src/encoder.cpp b/kms++/src/encoder.cpp index 30a241a..8144b9f 100644 --- a/kms++/src/encoder.cpp +++ b/kms++/src/encoder.cpp @@ -12,14 +12,15 @@ using namespace std; namespace kms { - -struct EncoderPriv -{ +struct EncoderPriv { drmModeEncoderPtr drm_encoder; }; static const map<int, string> encoder_types = { -#define DEF_ENC(c) { DRM_MODE_ENCODER_##c, #c } +#define DEF_ENC(c) \ + { \ + DRM_MODE_ENCODER_##c, #c \ + } DEF_ENC(NONE), DEF_ENC(DAC), DEF_ENC(TMDS), @@ -32,8 +33,8 @@ static const map<int, string> encoder_types = { #undef DEF_ENC }; -Encoder::Encoder(Card &card, uint32_t id, uint32_t idx) - :DrmPropObject(card, id, DRM_MODE_OBJECT_ENCODER, idx) +Encoder::Encoder(Card& card, uint32_t id, uint32_t idx) + : DrmPropObject(card, id, DRM_MODE_OBJECT_ENCODER, idx) { m_priv = new EncoderPriv(); m_priv->drm_encoder = drmModeGetEncoder(this->card().fd(), this->id()); @@ -83,4 +84,4 @@ const string& Encoder::get_encoder_type() const return encoder_types.at(m_priv->drm_encoder->encoder_type); } -} +} // namespace kms diff --git a/kms++/src/extframebuffer.cpp b/kms++/src/extframebuffer.cpp index 4ea563c..78b6fbb 100644 --- a/kms++/src/extframebuffer.cpp +++ b/kms++/src/extframebuffer.cpp @@ -13,7 +13,6 @@ using namespace std; namespace kms { - ExtFramebuffer::ExtFramebuffer(Card& card, uint32_t width, uint32_t height, PixelFormat format, vector<uint32_t> handles, vector<uint32_t> pitches, vector<uint32_t> offsets, vector<uint64_t> modifiers) : Framebuffer(card, width, height) @@ -46,8 +45,7 @@ ExtFramebuffer::ExtFramebuffer(Card& card, uint32_t width, uint32_t height, Pixe if (modifiers.empty()) { r = drmModeAddFB2(card.fd(), width, height, (uint32_t)format, handles.data(), pitches.data(), offsets.data(), &id, 0); - } - else { + } else { modifiers.resize(4); r = drmModeAddFB2WithModifiers(card.fd(), width, height, (uint32_t)format, handles.data(), pitches.data(), offsets.data(), modifiers.data(), &id, DRM_MODE_FB_MODIFIERS); } @@ -63,4 +61,4 @@ ExtFramebuffer::~ExtFramebuffer() drmModeRmFB(card().fd(), id()); } -} +} // namespace kms diff --git a/kms++/src/framebuffer.cpp b/kms++/src/framebuffer.cpp index 39c4e16..f1cba3b 100644 --- a/kms++/src/framebuffer.cpp +++ b/kms++/src/framebuffer.cpp @@ -11,7 +11,6 @@ using namespace std; namespace kms { - Framebuffer::Framebuffer(Card& card, uint32_t width, uint32_t height) : DrmObject(card, DRM_MODE_OBJECT_FB), m_width(width), m_height(height) { @@ -37,7 +36,7 @@ Framebuffer::Framebuffer(Card& card, uint32_t id) void Framebuffer::flush() { - drmModeClip clip { }; + drmModeClip clip{}; clip.x1 = clip.y1 = 0; clip.x2 = width(); clip.y2 = height(); @@ -52,5 +51,4 @@ Framebuffer::~Framebuffer() card().m_framebuffers.erase(iter); } - -} +} // namespace kms diff --git a/kms++/src/helpers.cpp b/kms++/src/helpers.cpp index 8bd082b..9079a23 100644 --- a/kms++/src/helpers.cpp +++ b/kms++/src/helpers.cpp @@ -9,7 +9,7 @@ namespace kms { Videomode drm_mode_to_video_mode(const drmModeModeInfo& drmmode) { - Videomode mode = { }; + Videomode mode = {}; auto& src = drmmode; auto& dst = mode; @@ -40,7 +40,7 @@ Videomode drm_mode_to_video_mode(const drmModeModeInfo& drmmode) drmModeModeInfo video_mode_to_drm_mode(const Videomode& mode) { - drmModeModeInfo drmmode = { }; + drmModeModeInfo drmmode = {}; auto& src = mode; auto& dst = drmmode; @@ -69,4 +69,4 @@ drmModeModeInfo video_mode_to_drm_mode(const Videomode& mode) return drmmode; } -} +} // namespace kms diff --git a/kms++/src/helpers.h b/kms++/src/helpers.h index 4eb597c..58926bf 100644 --- a/kms++/src/helpers.h +++ b/kms++/src/helpers.h @@ -9,4 +9,4 @@ struct Videomode; Videomode drm_mode_to_video_mode(const drmModeModeInfo& drmmode); drmModeModeInfo video_mode_to_drm_mode(const Videomode& mode); -} +} // namespace kms diff --git a/kms++/src/mode_cvt.cpp b/kms++/src/mode_cvt.cpp index 41503c7..a7a10b8 100644 --- a/kms++/src/mode_cvt.cpp +++ b/kms++/src/mode_cvt.cpp @@ -7,12 +7,10 @@ using namespace std; namespace kms { - static float CELL_GRAN = 8; static float CELL_GRAN_RND = round(CELL_GRAN); -struct CVTConsts -{ +struct CVTConsts { float CLOCK_STEP; float MIN_V_BPORCH; float RB_H_BLANK; @@ -24,30 +22,28 @@ struct CVTConsts float REFRESH_MULTIPLIER; }; -static const CVTConsts cvt_consts_v1 = -{ - .CLOCK_STEP = 0.25, // Fixed - .MIN_V_BPORCH = 6, // Min - .RB_H_BLANK = 160, // Fixed - .RB_H_FPORCH = 48, // Fixed - .RB_H_SYNC = 32, // Fixed - .RB_H_BPORCH = 80, // Fixed - .RB_MIN_V_BLANK = 460, // Min - .RB_V_FPORCH = 3, // Fixed - .REFRESH_MULTIPLIER = 1,// Fixed +static const CVTConsts cvt_consts_v1 = { + .CLOCK_STEP = 0.25, // Fixed + .MIN_V_BPORCH = 6, // Min + .RB_H_BLANK = 160, // Fixed + .RB_H_FPORCH = 48, // Fixed + .RB_H_SYNC = 32, // Fixed + .RB_H_BPORCH = 80, // Fixed + .RB_MIN_V_BLANK = 460, // Min + .RB_V_FPORCH = 3, // Fixed + .REFRESH_MULTIPLIER = 1, // Fixed }; -static const CVTConsts cvt_consts_v2 = -{ - .CLOCK_STEP = 0.001, // Fixed - .MIN_V_BPORCH = 6, // Fixed - .RB_H_BLANK = 80, // Fixed - .RB_H_FPORCH = 8, // Fixed - .RB_H_SYNC = 32, // Fixed - .RB_H_BPORCH = 40, // Fixed - .RB_MIN_V_BLANK = 460, // Min - .RB_V_FPORCH = 1, // Min - .REFRESH_MULTIPLIER = 1,// or 1000/1001 +static const CVTConsts cvt_consts_v2 = { + .CLOCK_STEP = 0.001, // Fixed + .MIN_V_BPORCH = 6, // Fixed + .RB_H_BLANK = 80, // Fixed + .RB_H_FPORCH = 8, // Fixed + .RB_H_SYNC = 32, // Fixed + .RB_H_BPORCH = 40, // Fixed + .RB_MIN_V_BLANK = 460, // Min + .RB_V_FPORCH = 1, // Min + .REFRESH_MULTIPLIER = 1, // or 1000/1001 }; Videomode videomode_from_cvt(uint32_t hact, uint32_t vact, uint32_t refresh, bool ilace, bool reduced_v2, bool video_optimized) @@ -55,7 +51,7 @@ Videomode videomode_from_cvt(uint32_t hact, uint32_t vact, uint32_t refresh, boo CVTConsts c = reduced_v2 ? cvt_consts_v2 : cvt_consts_v1; if (video_optimized) - c.REFRESH_MULTIPLIER = 1000.0/1001.0; + c.REFRESH_MULTIPLIER = 1000.0 / 1001.0; bool INT_RQD = ilace; @@ -151,4 +147,4 @@ Videomode videomode_from_cvt(uint32_t hact, uint32_t vact, uint32_t refresh, boo return mode; } -} +} // namespace kms diff --git a/kms++/src/modedb.cpp b/kms++/src/modedb.cpp index 5d5d373..081100a 100644 --- a/kms++/src/modedb.cpp +++ b/kms++/src/modedb.cpp @@ -8,7 +8,6 @@ using namespace std; namespace kms { - static const Videomode& find_from_table(const Videomode* modes, uint32_t width, uint32_t height, float vrefresh, bool ilace) { for (unsigned i = 0; modes[i].clock; ++i) { @@ -56,4 +55,4 @@ const Videomode& find_cea(uint32_t width, uint32_t height, float vrefresh, bool return find_from_table(cea_modes, width, height, vrefresh, ilace); } -} +} // namespace kms diff --git a/kms++/src/modedb_cea.cpp b/kms++/src/modedb_cea.cpp index a99a612..b09472f 100644 --- a/kms++/src/modedb_cea.cpp +++ b/kms++/src/modedb_cea.cpp @@ -35,14 +35,13 @@ namespace kms { - #define DIV_ROUND(n, d) (((n) + (d) / 2) / (d)) -#define DRM_MODE(nm, c, hd, hss, hse, ht, hsk, vd, vss, vse, vt, vs, f) \ - .name = nm, .clock = (c), \ +#define DRM_MODE(nm, c, hd, hss, hse, ht, hsk, vd, vss, vse, vt, vs, f) \ + .name = nm, .clock = (c), \ .hdisplay = (hd), .hsync_start = (hss), .hsync_end = (hse), .htotal = (ht), .hskew = (hsk), \ - .vdisplay = (vd), .vsync_start = (vss), .vsync_end = (vse), .vtotal = (vt), .vscan = (vs), \ - .vrefresh = DIV_ROUND(c * 1000, ht * vt) * (((f) & DRM_MODE_FLAG_INTERLACE) ? 2 : 1), \ + .vdisplay = (vd), .vsync_start = (vss), .vsync_end = (vse), .vtotal = (vt), .vscan = (vs), \ + .vrefresh = DIV_ROUND(c * 1000, ht * vt) * (((f)&DRM_MODE_FLAG_INTERLACE) ? 2 : 1), \ .flags = (f), .type = 0 /* @@ -51,352 +50,416 @@ namespace kms */ const Videomode cea_modes[] = { /* 1 - 640x480@60Hz */ - { DRM_MODE("640x480", 25175, 640, 656, - 752, 800, 0, 480, 490, 492, 525, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), + { + DRM_MODE("640x480", 25175, 640, 656, + 752, 800, 0, 480, 490, 492, 525, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), }, /* 2 - 720x480@60Hz */ - { DRM_MODE("720x480", 27000, 720, 736, - 798, 858, 0, 480, 489, 495, 525, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), + { + DRM_MODE("720x480", 27000, 720, 736, + 798, 858, 0, 480, 489, 495, 525, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), }, /* 3 - 720x480@60Hz */ - { DRM_MODE("720x480", 27000, 720, 736, - 798, 858, 0, 480, 489, 495, 525, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), + { + DRM_MODE("720x480", 27000, 720, 736, + 798, 858, 0, 480, 489, 495, 525, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), }, /* 4 - 1280x720@60Hz */ - { DRM_MODE("1280x720", 74250, 1280, 1390, - 1430, 1650, 0, 720, 725, 730, 750, 0, - DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC), + { + DRM_MODE("1280x720", 74250, 1280, 1390, + 1430, 1650, 0, 720, 725, 730, 750, 0, + DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC), }, /* 5 - 1920x1080i@60Hz */ - { DRM_MODE("1920x1080i", 74250, 1920, 2008, - 2052, 2200, 0, 1080, 1084, 1094, 1125, 0, - DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC | - DRM_MODE_FLAG_INTERLACE), + { + DRM_MODE("1920x1080i", 74250, 1920, 2008, + 2052, 2200, 0, 1080, 1084, 1094, 1125, 0, + DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC | + DRM_MODE_FLAG_INTERLACE), }, /* 6 - 720(1440)x480i@60Hz */ - { DRM_MODE("720x480i", 13500, 720, 739, - 801, 858, 0, 480, 488, 494, 525, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | - DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK), + { + DRM_MODE("720x480i", 13500, 720, 739, + 801, 858, 0, 480, 488, 494, 525, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | + DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK), }, /* 7 - 720(1440)x480i@60Hz */ - { DRM_MODE("720x480i", 13500, 720, 739, - 801, 858, 0, 480, 488, 494, 525, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | - DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK), + { + DRM_MODE("720x480i", 13500, 720, 739, + 801, 858, 0, 480, 488, 494, 525, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | + DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK), }, /* 8 - 720(1440)x240@60Hz */ - { DRM_MODE("720x240", 13500, 720, 739, - 801, 858, 0, 240, 244, 247, 262, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | - DRM_MODE_FLAG_DBLCLK), + { + DRM_MODE("720x240", 13500, 720, 739, + 801, 858, 0, 240, 244, 247, 262, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | + DRM_MODE_FLAG_DBLCLK), }, /* 9 - 720(1440)x240@60Hz */ - { DRM_MODE("720x240", 13500, 720, 739, - 801, 858, 0, 240, 244, 247, 262, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | - DRM_MODE_FLAG_DBLCLK), + { + DRM_MODE("720x240", 13500, 720, 739, + 801, 858, 0, 240, 244, 247, 262, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | + DRM_MODE_FLAG_DBLCLK), }, /* 10 - 2880x480i@60Hz */ - { DRM_MODE("2880x480i", 54000, 2880, 2956, - 3204, 3432, 0, 480, 488, 494, 525, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | - DRM_MODE_FLAG_INTERLACE), + { + DRM_MODE("2880x480i", 54000, 2880, 2956, + 3204, 3432, 0, 480, 488, 494, 525, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | + DRM_MODE_FLAG_INTERLACE), }, /* 11 - 2880x480i@60Hz */ - { DRM_MODE("2880x480i", 54000, 2880, 2956, - 3204, 3432, 0, 480, 488, 494, 525, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | - DRM_MODE_FLAG_INTERLACE), + { + DRM_MODE("2880x480i", 54000, 2880, 2956, + 3204, 3432, 0, 480, 488, 494, 525, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | + DRM_MODE_FLAG_INTERLACE), }, /* 12 - 2880x240@60Hz */ - { DRM_MODE("2880x240", 54000, 2880, 2956, - 3204, 3432, 0, 240, 244, 247, 262, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), + { + DRM_MODE("2880x240", 54000, 2880, 2956, + 3204, 3432, 0, 240, 244, 247, 262, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), }, /* 13 - 2880x240@60Hz */ - { DRM_MODE("2880x240", 54000, 2880, 2956, - 3204, 3432, 0, 240, 244, 247, 262, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), + { + DRM_MODE("2880x240", 54000, 2880, 2956, + 3204, 3432, 0, 240, 244, 247, 262, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), }, /* 14 - 1440x480@60Hz */ - { DRM_MODE("1440x480", 54000, 1440, 1472, - 1596, 1716, 0, 480, 489, 495, 525, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), + { + DRM_MODE("1440x480", 54000, 1440, 1472, + 1596, 1716, 0, 480, 489, 495, 525, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), }, /* 15 - 1440x480@60Hz */ - { DRM_MODE("1440x480", 54000, 1440, 1472, - 1596, 1716, 0, 480, 489, 495, 525, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), + { + DRM_MODE("1440x480", 54000, 1440, 1472, + 1596, 1716, 0, 480, 489, 495, 525, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), }, /* 16 - 1920x1080@60Hz */ - { DRM_MODE("1920x1080", 148500, 1920, 2008, - 2052, 2200, 0, 1080, 1084, 1089, 1125, 0, - DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC), + { + DRM_MODE("1920x1080", 148500, 1920, 2008, + 2052, 2200, 0, 1080, 1084, 1089, 1125, 0, + DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC), }, /* 17 - 720x576@50Hz */ - { DRM_MODE("720x576", 27000, 720, 732, - 796, 864, 0, 576, 581, 586, 625, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), + { + DRM_MODE("720x576", 27000, 720, 732, + 796, 864, 0, 576, 581, 586, 625, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), }, /* 18 - 720x576@50Hz */ - { DRM_MODE("720x576", 27000, 720, 732, - 796, 864, 0, 576, 581, 586, 625, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), + { + DRM_MODE("720x576", 27000, 720, 732, + 796, 864, 0, 576, 581, 586, 625, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), }, /* 19 - 1280x720@50Hz */ - { DRM_MODE("1280x720", 74250, 1280, 1720, - 1760, 1980, 0, 720, 725, 730, 750, 0, - DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC), + { + DRM_MODE("1280x720", 74250, 1280, 1720, + 1760, 1980, 0, 720, 725, 730, 750, 0, + DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC), }, /* 20 - 1920x1080i@50Hz */ - { DRM_MODE("1920x1080i", 74250, 1920, 2448, - 2492, 2640, 0, 1080, 1084, 1094, 1125, 0, - DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC | - DRM_MODE_FLAG_INTERLACE), + { + DRM_MODE("1920x1080i", 74250, 1920, 2448, + 2492, 2640, 0, 1080, 1084, 1094, 1125, 0, + DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC | + DRM_MODE_FLAG_INTERLACE), }, /* 21 - 720(1440)x576i@50Hz */ - { DRM_MODE("720x576i", 13500, 720, 732, - 795, 864, 0, 576, 580, 586, 625, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | - DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK), + { + DRM_MODE("720x576i", 13500, 720, 732, + 795, 864, 0, 576, 580, 586, 625, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | + DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK), }, /* 22 - 720(1440)x576i@50Hz */ - { DRM_MODE("720x576i", 13500, 720, 732, - 795, 864, 0, 576, 580, 586, 625, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | - DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK), + { + DRM_MODE("720x576i", 13500, 720, 732, + 795, 864, 0, 576, 580, 586, 625, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | + DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK), }, /* 23 - 720(1440)x288@50Hz */ - { DRM_MODE("720x288", 13500, 720, 732, - 795, 864, 0, 288, 290, 293, 312, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | - DRM_MODE_FLAG_DBLCLK), + { + DRM_MODE("720x288", 13500, 720, 732, + 795, 864, 0, 288, 290, 293, 312, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | + DRM_MODE_FLAG_DBLCLK), }, /* 24 - 720(1440)x288@50Hz */ - { DRM_MODE("720x288", 13500, 720, 732, - 795, 864, 0, 288, 290, 293, 312, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | - DRM_MODE_FLAG_DBLCLK), + { + DRM_MODE("720x288", 13500, 720, 732, + 795, 864, 0, 288, 290, 293, 312, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | + DRM_MODE_FLAG_DBLCLK), }, /* 25 - 2880x576i@50Hz */ - { DRM_MODE("2880x576i", 54000, 2880, 2928, - 3180, 3456, 0, 576, 580, 586, 625, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | - DRM_MODE_FLAG_INTERLACE), + { + DRM_MODE("2880x576i", 54000, 2880, 2928, + 3180, 3456, 0, 576, 580, 586, 625, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | + DRM_MODE_FLAG_INTERLACE), }, /* 26 - 2880x576i@50Hz */ - { DRM_MODE("2880x576i", 54000, 2880, 2928, - 3180, 3456, 0, 576, 580, 586, 625, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | - DRM_MODE_FLAG_INTERLACE), + { + DRM_MODE("2880x576i", 54000, 2880, 2928, + 3180, 3456, 0, 576, 580, 586, 625, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | + DRM_MODE_FLAG_INTERLACE), }, /* 27 - 2880x288@50Hz */ - { DRM_MODE("2880x288", 54000, 2880, 2928, - 3180, 3456, 0, 288, 290, 293, 312, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), + { + DRM_MODE("2880x288", 54000, 2880, 2928, + 3180, 3456, 0, 288, 290, 293, 312, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), }, /* 28 - 2880x288@50Hz */ - { DRM_MODE("2880x288", 54000, 2880, 2928, - 3180, 3456, 0, 288, 290, 293, 312, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), + { + DRM_MODE("2880x288", 54000, 2880, 2928, + 3180, 3456, 0, 288, 290, 293, 312, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), }, /* 29 - 1440x576@50Hz */ - { DRM_MODE("1440x576", 54000, 1440, 1464, - 1592, 1728, 0, 576, 581, 586, 625, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), + { + DRM_MODE("1440x576", 54000, 1440, 1464, + 1592, 1728, 0, 576, 581, 586, 625, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), }, /* 30 - 1440x576@50Hz */ - { DRM_MODE("1440x576", 54000, 1440, 1464, - 1592, 1728, 0, 576, 581, 586, 625, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), + { + DRM_MODE("1440x576", 54000, 1440, 1464, + 1592, 1728, 0, 576, 581, 586, 625, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), }, /* 31 - 1920x1080@50Hz */ - { DRM_MODE("1920x1080", 148500, 1920, 2448, - 2492, 2640, 0, 1080, 1084, 1089, 1125, 0, - DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC), + { + DRM_MODE("1920x1080", 148500, 1920, 2448, + 2492, 2640, 0, 1080, 1084, 1089, 1125, 0, + DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC), }, /* 32 - 1920x1080@24Hz */ - { DRM_MODE("1920x1080", 74250, 1920, 2558, - 2602, 2750, 0, 1080, 1084, 1089, 1125, 0, - DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC), + { + DRM_MODE("1920x1080", 74250, 1920, 2558, + 2602, 2750, 0, 1080, 1084, 1089, 1125, 0, + DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC), }, /* 33 - 1920x1080@25Hz */ - { DRM_MODE("1920x1080", 74250, 1920, 2448, - 2492, 2640, 0, 1080, 1084, 1089, 1125, 0, - DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC), + { + DRM_MODE("1920x1080", 74250, 1920, 2448, + 2492, 2640, 0, 1080, 1084, 1089, 1125, 0, + DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC), }, /* 34 - 1920x1080@30Hz */ - { DRM_MODE("1920x1080", 74250, 1920, 2008, - 2052, 2200, 0, 1080, 1084, 1089, 1125, 0, - DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC), + { + DRM_MODE("1920x1080", 74250, 1920, 2008, + 2052, 2200, 0, 1080, 1084, 1089, 1125, 0, + DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC), }, /* 35 - 2880x480@60Hz */ - { DRM_MODE("2880x480", 108000, 2880, 2944, - 3192, 3432, 0, 480, 489, 495, 525, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), + { + DRM_MODE("2880x480", 108000, 2880, 2944, + 3192, 3432, 0, 480, 489, 495, 525, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), }, /* 36 - 2880x480@60Hz */ - { DRM_MODE("2880x480", 108000, 2880, 2944, - 3192, 3432, 0, 480, 489, 495, 525, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), + { + DRM_MODE("2880x480", 108000, 2880, 2944, + 3192, 3432, 0, 480, 489, 495, 525, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), }, /* 37 - 2880x576@50Hz */ - { DRM_MODE("2880x576", 108000, 2880, 2928, - 3184, 3456, 0, 576, 581, 586, 625, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), + { + DRM_MODE("2880x576", 108000, 2880, 2928, + 3184, 3456, 0, 576, 581, 586, 625, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), }, /* 38 - 2880x576@50Hz */ - { DRM_MODE("2880x576", 108000, 2880, 2928, - 3184, 3456, 0, 576, 581, 586, 625, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), + { + DRM_MODE("2880x576", 108000, 2880, 2928, + 3184, 3456, 0, 576, 581, 586, 625, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), }, /* 39 - 1920x1080i@50Hz */ - { DRM_MODE("1920x1080i", 72000, 1920, 1952, - 2120, 2304, 0, 1080, 1126, 1136, 1250, 0, - DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC | - DRM_MODE_FLAG_INTERLACE), + { + DRM_MODE("1920x1080i", 72000, 1920, 1952, + 2120, 2304, 0, 1080, 1126, 1136, 1250, 0, + DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC | + DRM_MODE_FLAG_INTERLACE), }, /* 40 - 1920x1080i@100Hz */ - { DRM_MODE("1920x1080i", 148500, 1920, 2448, - 2492, 2640, 0, 1080, 1084, 1094, 1125, 0, - DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC | - DRM_MODE_FLAG_INTERLACE), + { + DRM_MODE("1920x1080i", 148500, 1920, 2448, + 2492, 2640, 0, 1080, 1084, 1094, 1125, 0, + DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC | + DRM_MODE_FLAG_INTERLACE), }, /* 41 - 1280x720@100Hz */ - { DRM_MODE("1280x720", 148500, 1280, 1720, - 1760, 1980, 0, 720, 725, 730, 750, 0, - DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC), + { + DRM_MODE("1280x720", 148500, 1280, 1720, + 1760, 1980, 0, 720, 725, 730, 750, 0, + DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC), }, /* 42 - 720x576@100Hz */ - { DRM_MODE("720x576", 54000, 720, 732, - 796, 864, 0, 576, 581, 586, 625, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), + { + DRM_MODE("720x576", 54000, 720, 732, + 796, 864, 0, 576, 581, 586, 625, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), }, /* 43 - 720x576@100Hz */ - { DRM_MODE("720x576", 54000, 720, 732, - 796, 864, 0, 576, 581, 586, 625, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), + { + DRM_MODE("720x576", 54000, 720, 732, + 796, 864, 0, 576, 581, 586, 625, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), }, /* 44 - 720(1440)x576i@100Hz */ - { DRM_MODE("720x576i", 27000, 720, 732, - 795, 864, 0, 576, 580, 586, 625, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | - DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK), + { + DRM_MODE("720x576i", 27000, 720, 732, + 795, 864, 0, 576, 580, 586, 625, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | + DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK), }, /* 45 - 720(1440)x576i@100Hz */ - { DRM_MODE("720x576i", 27000, 720, 732, - 795, 864, 0, 576, 580, 586, 625, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | - DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK), + { + DRM_MODE("720x576i", 27000, 720, 732, + 795, 864, 0, 576, 580, 586, 625, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | + DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK), }, /* 46 - 1920x1080i@120Hz */ - { DRM_MODE("1920x1080i", 148500, 1920, 2008, - 2052, 2200, 0, 1080, 1084, 1094, 1125, 0, - DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC | - DRM_MODE_FLAG_INTERLACE), + { + DRM_MODE("1920x1080i", 148500, 1920, 2008, + 2052, 2200, 0, 1080, 1084, 1094, 1125, 0, + DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC | + DRM_MODE_FLAG_INTERLACE), }, /* 47 - 1280x720@120Hz */ - { DRM_MODE("1280x720", 148500, 1280, 1390, - 1430, 1650, 0, 720, 725, 730, 750, 0, - DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC), + { + DRM_MODE("1280x720", 148500, 1280, 1390, + 1430, 1650, 0, 720, 725, 730, 750, 0, + DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC), }, /* 48 - 720x480@120Hz */ - { DRM_MODE("720x480", 54000, 720, 736, - 798, 858, 0, 480, 489, 495, 525, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), + { + DRM_MODE("720x480", 54000, 720, 736, + 798, 858, 0, 480, 489, 495, 525, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), }, /* 49 - 720x480@120Hz */ - { DRM_MODE("720x480", 54000, 720, 736, - 798, 858, 0, 480, 489, 495, 525, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), + { + DRM_MODE("720x480", 54000, 720, 736, + 798, 858, 0, 480, 489, 495, 525, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), }, /* 50 - 720(1440)x480i@120Hz */ - { DRM_MODE("720x480i", 27000, 720, 739, - 801, 858, 0, 480, 488, 494, 525, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | - DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK), + { + DRM_MODE("720x480i", 27000, 720, 739, + 801, 858, 0, 480, 488, 494, 525, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | + DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK), }, /* 51 - 720(1440)x480i@120Hz */ - { DRM_MODE("720x480i", 27000, 720, 739, - 801, 858, 0, 480, 488, 494, 525, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | - DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK), + { + DRM_MODE("720x480i", 27000, 720, 739, + 801, 858, 0, 480, 488, 494, 525, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | + DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK), }, /* 52 - 720x576@200Hz */ - { DRM_MODE("720x576", 108000, 720, 732, - 796, 864, 0, 576, 581, 586, 625, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), + { + DRM_MODE("720x576", 108000, 720, 732, + 796, 864, 0, 576, 581, 586, 625, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), }, /* 53 - 720x576@200Hz */ - { DRM_MODE("720x576", 108000, 720, 732, - 796, 864, 0, 576, 581, 586, 625, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), + { + DRM_MODE("720x576", 108000, 720, 732, + 796, 864, 0, 576, 581, 586, 625, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), }, /* 54 - 720(1440)x576i@200Hz */ - { DRM_MODE("720x576i", 54000, 720, 732, - 795, 864, 0, 576, 580, 586, 625, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | - DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK), + { + DRM_MODE("720x576i", 54000, 720, 732, + 795, 864, 0, 576, 580, 586, 625, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | + DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK), }, /* 55 - 720(1440)x576i@200Hz */ - { DRM_MODE("720x576i", 54000, 720, 732, - 795, 864, 0, 576, 580, 586, 625, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | - DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK), + { + DRM_MODE("720x576i", 54000, 720, 732, + 795, 864, 0, 576, 580, 586, 625, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | + DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK), }, /* 56 - 720x480@240Hz */ - { DRM_MODE("720x480", 108000, 720, 736, - 798, 858, 0, 480, 489, 495, 525, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), + { + DRM_MODE("720x480", 108000, 720, 736, + 798, 858, 0, 480, 489, 495, 525, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), }, /* 57 - 720x480@240Hz */ - { DRM_MODE("720x480", 108000, 720, 736, - 798, 858, 0, 480, 489, 495, 525, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), + { + DRM_MODE("720x480", 108000, 720, 736, + 798, 858, 0, 480, 489, 495, 525, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), }, /* 58 - 720(1440)x480i@240 */ - { DRM_MODE("720x480i", 54000, 720, 739, - 801, 858, 0, 480, 488, 494, 525, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | - DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK), + { + DRM_MODE("720x480i", 54000, 720, 739, + 801, 858, 0, 480, 488, 494, 525, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | + DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK), }, /* 59 - 720(1440)x480i@240 */ - { DRM_MODE("720x480i", 54000, 720, 739, - 801, 858, 0, 480, 488, 494, 525, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | - DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK), + { + DRM_MODE("720x480i", 54000, 720, 739, + 801, 858, 0, 480, 488, 494, 525, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | + DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK), }, /* 60 - 1280x720@24Hz */ - { DRM_MODE("1280x720", 59400, 1280, 3040, - 3080, 3300, 0, 720, 725, 730, 750, 0, - DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC), + { + DRM_MODE("1280x720", 59400, 1280, 3040, + 3080, 3300, 0, 720, 725, 730, 750, 0, + DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC), }, /* 61 - 1280x720@25Hz */ - { DRM_MODE("1280x720", 74250, 1280, 3700, - 3740, 3960, 0, 720, 725, 730, 750, 0, - DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC), + { + DRM_MODE("1280x720", 74250, 1280, 3700, + 3740, 3960, 0, 720, 725, 730, 750, 0, + DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC), }, /* 62 - 1280x720@30Hz */ - { DRM_MODE("1280x720", 74250, 1280, 3040, - 3080, 3300, 0, 720, 725, 730, 750, 0, - DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC), + { + DRM_MODE("1280x720", 74250, 1280, 3040, + 3080, 3300, 0, 720, 725, 730, 750, 0, + DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC), }, /* 63 - 1920x1080@120Hz */ - { DRM_MODE("1920x1080", 297000, 1920, 2008, - 2052, 2200, 0, 1080, 1084, 1089, 1125, 0, - DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC), + { + DRM_MODE("1920x1080", 297000, 1920, 2008, + 2052, 2200, 0, 1080, 1084, 1089, 1125, 0, + DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC), }, /* 64 - 1920x1080@100Hz */ - { DRM_MODE("1920x1080", 297000, 1920, 2448, - 2492, 2640, 0, 1080, 1084, 1094, 1125, 0, - DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC), + { + DRM_MODE("1920x1080", 297000, 1920, 2448, + 2492, 2640, 0, 1080, 1084, 1094, 1125, 0, + DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC), }, /* TERMINATOR */ - { }, + {}, }; -} +} // namespace kms diff --git a/kms++/src/modedb_dmt.cpp b/kms++/src/modedb_dmt.cpp index 7dee6b1..21fe1c2 100644 --- a/kms++/src/modedb_dmt.cpp +++ b/kms++/src/modedb_dmt.cpp @@ -6,18 +6,17 @@ namespace kms { - #define DIV_ROUND(n, d) (((n) + (d) / 2) / (d)) // hd, hss, hse, ht, vd, vss, vse, vt -#define DRM_MODE(nm, c, hact, hfp, hsw, hbp, vact, vfp, vsw, vbp, f) \ - { \ - .name = nm, .clock = c, \ - .hdisplay = (hact), .hsync_start = (hact) + (hfp), .hsync_end = (hact) + (hfp) + (hsw), .htotal = (hact) + (hfp) + (hsw) + (hbp), .hskew = 0, \ - .vdisplay = (vact), .vsync_start = (vact) + (vfp), .vsync_end = (vact) + (vfp) + (vsw), .vtotal = (vact) + (vfp) + (vsw) + (vbp), .vscan = 0, \ - .vrefresh = DIV_ROUND(c * 1000, ((hact) + (hfp) + (hsw) + (hbp)) * ((vact) + (vfp) + (vsw) + (vbp))) * (((f) & DRM_MODE_FLAG_INTERLACE) ? 2 : 1), \ - .flags = (f), .type = 0 \ +#define DRM_MODE(nm, c, hact, hfp, hsw, hbp, vact, vfp, vsw, vbp, f) \ + { \ + .name = nm, .clock = c, \ + .hdisplay = (hact), .hsync_start = (hact) + (hfp), .hsync_end = (hact) + (hfp) + (hsw), .htotal = (hact) + (hfp) + (hsw) + (hbp), .hskew = 0, \ + .vdisplay = (vact), .vsync_start = (vact) + (vfp), .vsync_end = (vact) + (vfp) + (vsw), .vtotal = (vact) + (vfp) + (vsw) + (vbp), .vscan = 0, \ + .vrefresh = DIV_ROUND(c * 1000, ((hact) + (hfp) + (hsw) + (hbp)) * ((vact) + (vfp) + (vsw) + (vbp))) * (((f)&DRM_MODE_FLAG_INTERLACE) ? 2 : 1), \ + .flags = (f), .type = 0 \ } const Videomode dmt_modes[] = { @@ -198,7 +197,7 @@ const Videomode dmt_modes[] = { // 0x58 - 4096 x 2160 @ 59.94 Hz CVT (Reduced Blanking v2) DRM_MODE("4096 x 2160 @ 59.94 Hz CVT (Reduced Blanking v2)", 556188, 4096, 8, 32, 40, 2160, 48, 8, 6, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC), /* TERMINATOR */ - { }, + {}, }; -} +} // namespace kms diff --git a/kms++/src/omap/omapcard.cpp b/kms++/src/omap/omapcard.cpp index 5e21c75..500bb72 100644 --- a/kms++/src/omap/omapcard.cpp +++ b/kms++/src/omap/omapcard.cpp @@ -9,7 +9,6 @@ using namespace std; namespace kms { - OmapCard::OmapCard(const string& device) : Card(device) { @@ -21,4 +20,4 @@ OmapCard::~OmapCard() omap_device_del(m_omap_dev); } -} +} // namespace kms diff --git a/kms++/src/omap/omapframebuffer.cpp b/kms++/src/omap/omapframebuffer.cpp index f33a286..eac45e2 100644 --- a/kms++/src/omap/omapframebuffer.cpp +++ b/kms++/src/omap/omapframebuffer.cpp @@ -18,21 +18,20 @@ extern "C" { } #define __round_mask(x, y) ((__typeof__(x))((y)-1)) -#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1) +#define round_up(x, y) ((((x)-1) | __round_mask(x, y)) + 1) #define PAGE_SIZE 4096 using namespace std; namespace kms { - OmapFramebuffer::OmapFramebuffer(OmapCard& card, uint32_t width, uint32_t height, const string& fourcc, Flags flags) : OmapFramebuffer(card, width, height, FourCCToPixelFormat(fourcc), flags) { } OmapFramebuffer::OmapFramebuffer(OmapCard& card, uint32_t width, uint32_t height, PixelFormat format, Flags flags) - :Framebuffer(card, width, height), m_omap_card(card), m_format(format) + : Framebuffer(card, width, height), m_omap_card(card), m_format(format) { Create(flags); } @@ -80,23 +79,33 @@ void OmapFramebuffer::Create(Flags buffer_flags) switch (m_format) { case PixelFormat::NV12: - bitspertiler = i == 0 ? 8 : 16; break; + bitspertiler = i == 0 ? 8 : 16; + break; case PixelFormat::YUYV: case PixelFormat::UYVY: - bitspertiler = 32; break; + bitspertiler = 32; + break; case PixelFormat::ARGB8888: case PixelFormat::XRGB8888: - bitspertiler = 32; break; + bitspertiler = 32; + break; case PixelFormat::RGB565: - bitspertiler = 16; break; + bitspertiler = 16; + break; default: throw invalid_argument("unimplemented format"); } switch (bitspertiler) { - case 8: flags |= OMAP_BO_TILED_8; break; - case 16: flags |= OMAP_BO_TILED_16; break; - case 32: flags |= OMAP_BO_TILED_32; break; + case 8: + flags |= OMAP_BO_TILED_8; + break; + case 16: + flags |= OMAP_BO_TILED_16; + break; + case 32: + flags |= OMAP_BO_TILED_32; + break; default: throw invalid_argument("bad bitspertiler"); } @@ -125,7 +134,7 @@ void OmapFramebuffer::Create(Flags buffer_flags) uint32_t offsets[4] = { m_planes[0].offset, m_planes[1].offset }; uint32_t id; int r = drmModeAddFB2(card().fd(), width(), height(), (uint32_t)format(), - bo_handles, pitches, offsets, &id, 0); + bo_handles, pitches, offsets, &id, 0); if (r) throw invalid_argument(string("drmModeAddFB2 failed: ") + strerror(errno)); @@ -181,4 +190,4 @@ int OmapFramebuffer::prime_fd(unsigned int plane) return fd; } -} +} // namespace kms diff --git a/kms++/src/pixelformats.cpp b/kms++/src/pixelformats.cpp index 2c60c1e..d739efd 100644 --- a/kms++/src/pixelformats.cpp +++ b/kms++/src/pixelformats.cpp @@ -8,54 +8,266 @@ namespace kms { static const map<PixelFormat, PixelFormatInfo> format_info_array = { /* YUV packed */ - { PixelFormat::UYVY, { PixelColorType::YUV, 1, { { 16, 2, 1 } }, } }, - { PixelFormat::YUYV, { PixelColorType::YUV, 1, { { 16, 2, 1 } }, } }, - { PixelFormat::YVYU, { PixelColorType::YUV, 1, { { 16, 2, 1 } }, } }, - { PixelFormat::VYUY, { PixelColorType::YUV, 1, { { 16, 2, 1 } }, } }, + { PixelFormat::UYVY, { + PixelColorType::YUV, + 1, + { { 16, 2, 1 } }, + } }, + { PixelFormat::YUYV, { + PixelColorType::YUV, + 1, + { { 16, 2, 1 } }, + } }, + { PixelFormat::YVYU, { + PixelColorType::YUV, + 1, + { { 16, 2, 1 } }, + } }, + { PixelFormat::VYUY, { + PixelColorType::YUV, + 1, + { { 16, 2, 1 } }, + } }, /* YUV semi-planar */ - { PixelFormat::NV12, { PixelColorType::YUV, 2, { { 8, 1, 1, }, { 8, 2, 2 } }, } }, - { PixelFormat::NV21, { PixelColorType::YUV, 2, { { 8, 1, 1, }, { 8, 2, 2 } }, } }, - { PixelFormat::NV16, { PixelColorType::YUV, 2, { { 8, 1, 1, }, { 8, 2, 1 } }, } }, - { PixelFormat::NV61, { PixelColorType::YUV, 2, { { 8, 1, 1, }, { 8, 2, 1 } }, } }, + { PixelFormat::NV12, { + PixelColorType::YUV, + 2, + { { + 8, + 1, + 1, + }, + { 8, 2, 2 } }, + } }, + { PixelFormat::NV21, { + PixelColorType::YUV, + 2, + { { + 8, + 1, + 1, + }, + { 8, 2, 2 } }, + } }, + { PixelFormat::NV16, { + PixelColorType::YUV, + 2, + { { + 8, + 1, + 1, + }, + { 8, 2, 1 } }, + } }, + { PixelFormat::NV61, { + PixelColorType::YUV, + 2, + { { + 8, + 1, + 1, + }, + { 8, 2, 1 } }, + } }, /* YUV planar */ - { PixelFormat::YUV420, { PixelColorType::YUV, 3, { { 8, 1, 1, }, { 8, 2, 2 }, { 8, 2, 2 } }, } }, - { PixelFormat::YVU420, { PixelColorType::YUV, 3, { { 8, 1, 1, }, { 8, 2, 2 }, { 8, 2, 2 } }, } }, - { PixelFormat::YUV422, { PixelColorType::YUV, 3, { { 8, 1, 1, }, { 8, 2, 1 }, { 8, 2, 1 } }, } }, - { PixelFormat::YVU422, { PixelColorType::YUV, 3, { { 8, 1, 1, }, { 8, 2, 1 }, { 8, 2, 1 } }, } }, - { PixelFormat::YUV444, { PixelColorType::YUV, 3, { { 8, 1, 1, }, { 8, 1, 1 }, { 8, 1, 1 } }, } }, - { PixelFormat::YVU444, { PixelColorType::YUV, 3, { { 8, 1, 1, }, { 8, 1, 1 }, { 8, 1, 1 } }, } }, + { PixelFormat::YUV420, { + PixelColorType::YUV, + 3, + { { + 8, + 1, + 1, + }, + { 8, 2, 2 }, + { 8, 2, 2 } }, + } }, + { PixelFormat::YVU420, { + PixelColorType::YUV, + 3, + { { + 8, + 1, + 1, + }, + { 8, 2, 2 }, + { 8, 2, 2 } }, + } }, + { PixelFormat::YUV422, { + PixelColorType::YUV, + 3, + { { + 8, + 1, + 1, + }, + { 8, 2, 1 }, + { 8, 2, 1 } }, + } }, + { PixelFormat::YVU422, { + PixelColorType::YUV, + 3, + { { + 8, + 1, + 1, + }, + { 8, 2, 1 }, + { 8, 2, 1 } }, + } }, + { PixelFormat::YUV444, { + PixelColorType::YUV, + 3, + { { + 8, + 1, + 1, + }, + { 8, 1, 1 }, + { 8, 1, 1 } }, + } }, + { PixelFormat::YVU444, { + PixelColorType::YUV, + 3, + { { + 8, + 1, + 1, + }, + { 8, 1, 1 }, + { 8, 1, 1 } }, + } }, /* RGB8 */ - { PixelFormat::RGB332, { PixelColorType::RGB, 1, { { 8, 1, 1 } }, } }, + { PixelFormat::RGB332, { + PixelColorType::RGB, + 1, + { { 8, 1, 1 } }, + } }, /* RGB16 */ - { PixelFormat::RGB565, { PixelColorType::RGB, 1, { { 16, 1, 1 } }, } }, - { PixelFormat::BGR565, { PixelColorType::RGB, 1, { { 16, 1, 1 } }, } }, - { PixelFormat::XRGB4444, { PixelColorType::RGB, 1, { { 16, 1, 1 } }, } }, - { PixelFormat::XRGB1555, { PixelColorType::RGB, 1, { { 16, 1, 1 } }, } }, - { PixelFormat::ARGB4444, { PixelColorType::RGB, 1, { { 16, 1, 1 } }, } }, - { PixelFormat::ARGB1555, { PixelColorType::RGB, 1, { { 16, 1, 1 } }, } }, + { PixelFormat::RGB565, { + PixelColorType::RGB, + 1, + { { 16, 1, 1 } }, + } }, + { PixelFormat::BGR565, { + PixelColorType::RGB, + 1, + { { 16, 1, 1 } }, + } }, + { PixelFormat::XRGB4444, { + PixelColorType::RGB, + 1, + { { 16, 1, 1 } }, + } }, + { PixelFormat::XRGB1555, { + PixelColorType::RGB, + 1, + { { 16, 1, 1 } }, + } }, + { PixelFormat::ARGB4444, { + PixelColorType::RGB, + 1, + { { 16, 1, 1 } }, + } }, + { PixelFormat::ARGB1555, { + PixelColorType::RGB, + 1, + { { 16, 1, 1 } }, + } }, /* RGB24 */ - { PixelFormat::RGB888, { PixelColorType::RGB, 1, { { 24, 1, 1 } }, } }, - { PixelFormat::BGR888, { PixelColorType::RGB, 1, { { 24, 1, 1 } }, } }, + { PixelFormat::RGB888, { + PixelColorType::RGB, + 1, + { { 24, 1, 1 } }, + } }, + { PixelFormat::BGR888, { + PixelColorType::RGB, + 1, + { { 24, 1, 1 } }, + } }, /* RGB32 */ - { PixelFormat::XRGB8888, { PixelColorType::RGB, 1, { { 32, 1, 1 } }, } }, - { PixelFormat::XBGR8888, { PixelColorType::RGB, 1, { { 32, 1, 1 } }, } }, - { PixelFormat::RGBX8888, { PixelColorType::RGB, 1, { { 32, 1, 1 } }, } }, - { PixelFormat::BGRX8888, { PixelColorType::RGB, 1, { { 32, 1, 1 } }, } }, + { PixelFormat::XRGB8888, { + PixelColorType::RGB, + 1, + { { 32, 1, 1 } }, + } }, + { PixelFormat::XBGR8888, { + PixelColorType::RGB, + 1, + { { 32, 1, 1 } }, + } }, + { PixelFormat::RGBX8888, { + PixelColorType::RGB, + 1, + { { 32, 1, 1 } }, + } }, + { PixelFormat::BGRX8888, { + PixelColorType::RGB, + 1, + { { 32, 1, 1 } }, + } }, - { PixelFormat::ARGB8888, { PixelColorType::RGB, 1, { { 32, 1, 1 } }, } }, - { PixelFormat::ABGR8888, { PixelColorType::RGB, 1, { { 32, 1, 1 } }, } }, - { PixelFormat::RGBA8888, { PixelColorType::RGB, 1, { { 32, 1, 1 } }, } }, - { PixelFormat::BGRA8888, { PixelColorType::RGB, 1, { { 32, 1, 1 } }, } }, + { PixelFormat::ARGB8888, { + PixelColorType::RGB, + 1, + { { 32, 1, 1 } }, + } }, + { PixelFormat::ABGR8888, { + PixelColorType::RGB, + 1, + { { 32, 1, 1 } }, + } }, + { PixelFormat::RGBA8888, { + PixelColorType::RGB, + 1, + { { 32, 1, 1 } }, + } }, + { PixelFormat::BGRA8888, { + PixelColorType::RGB, + 1, + { { 32, 1, 1 } }, + } }, - { PixelFormat::XRGB2101010, { PixelColorType::RGB, 1, { { 32, 1, 1 } }, } }, - { PixelFormat::XBGR2101010, { PixelColorType::RGB, 1, { { 32, 1, 1 } }, } }, - { PixelFormat::RGBX1010102, { PixelColorType::RGB, 1, { { 32, 1, 1 } }, } }, - { PixelFormat::BGRX1010102, { PixelColorType::RGB, 1, { { 32, 1, 1 } }, } }, + { PixelFormat::XRGB2101010, { + PixelColorType::RGB, + 1, + { { 32, 1, 1 } }, + } }, + { PixelFormat::XBGR2101010, { + PixelColorType::RGB, + 1, + { { 32, 1, 1 } }, + } }, + { PixelFormat::RGBX1010102, { + PixelColorType::RGB, + 1, + { { 32, 1, 1 } }, + } }, + { PixelFormat::BGRX1010102, { + PixelColorType::RGB, + 1, + { { 32, 1, 1 } }, + } }, - { PixelFormat::ARGB2101010, { PixelColorType::RGB, 1, { { 32, 1, 1 } }, } }, - { PixelFormat::ABGR2101010, { PixelColorType::RGB, 1, { { 32, 1, 1 } }, } }, - { PixelFormat::RGBA1010102, { PixelColorType::RGB, 1, { { 32, 1, 1 } }, } }, - { PixelFormat::BGRA1010102, { PixelColorType::RGB, 1, { { 32, 1, 1 } }, } }, + { PixelFormat::ARGB2101010, { + PixelColorType::RGB, + 1, + { { 32, 1, 1 } }, + } }, + { PixelFormat::ABGR2101010, { + PixelColorType::RGB, + 1, + { { 32, 1, 1 } }, + } }, + { PixelFormat::RGBA1010102, { + PixelColorType::RGB, + 1, + { { 32, 1, 1 } }, + } }, + { PixelFormat::BGRA1010102, { + PixelColorType::RGB, + 1, + { { 32, 1, 1 } }, + } }, }; const struct PixelFormatInfo& get_pixel_format_info(PixelFormat format) @@ -66,4 +278,4 @@ const struct PixelFormatInfo& get_pixel_format_info(PixelFormat format) return format_info_array.at(format); } -} +} // namespace kms diff --git a/kms++/src/plane.cpp b/kms++/src/plane.cpp index ffab3b5..bd426dd 100644 --- a/kms++/src/plane.cpp +++ b/kms++/src/plane.cpp @@ -13,14 +13,12 @@ using namespace std; namespace kms { - -struct PlanePriv -{ +struct PlanePriv { drmModePlanePtr drm_plane; }; -Plane::Plane(Card &card, uint32_t id, uint32_t idx) - :DrmPropObject(card, id, DRM_MODE_OBJECT_PLANE, idx) +Plane::Plane(Card& card, uint32_t id, uint32_t idx) + : DrmPropObject(card, id, DRM_MODE_OBJECT_PLANE, idx) { m_priv = new PlanePriv(); m_priv->drm_plane = drmModeGetPlane(this->card().fd(), this->id()); @@ -76,7 +74,6 @@ vector<Crtc*> Plane::get_possible_crtcs() const for (uint32_t crtc_mask = m_priv->drm_plane->possible_crtcs; crtc_mask; idx++, crtc_mask >>= 1) { - if ((crtc_mask & 1) == 0) continue; @@ -97,7 +94,7 @@ vector<PixelFormat> Plane::get_formats() const vector<PixelFormat> r; for (unsigned i = 0; i < p->count_formats; ++i) - r.push_back((PixelFormat) p->formats[i]); + r.push_back((PixelFormat)p->formats[i]); return r; } @@ -137,4 +134,4 @@ uint32_t Plane::gamma_size() const return m_priv->drm_plane->gamma_size; } -} +} // namespace kms diff --git a/kms++/src/property.cpp b/kms++/src/property.cpp index ee79922..0484f0e 100644 --- a/kms++/src/property.cpp +++ b/kms++/src/property.cpp @@ -7,9 +7,7 @@ using namespace std; namespace kms { - -struct PropertyPriv -{ +struct PropertyPriv { drmModePropertyPtr drm_prop; }; @@ -84,4 +82,4 @@ vector<uint32_t> Property::get_blob_ids() const drmModePropertyPtr p = m_priv->drm_prop; return vector<uint32_t>(p->blob_ids, p->blob_ids + p->count_blobs); } -} +} // namespace kms diff --git a/kms++/src/videomode.cpp b/kms++/src/videomode.cpp index 066896f..b039059 100644 --- a/kms++/src/videomode.cpp +++ b/kms++/src/videomode.cpp @@ -11,7 +11,6 @@ using namespace std; namespace kms { - bool Videomode::valid() const { return !!clock; @@ -147,7 +146,7 @@ Videomode videomode_from_timings(uint32_t clock_khz, uint16_t hact, uint16_t hfp, uint16_t hsw, uint16_t hbp, uint16_t vact, uint16_t vfp, uint16_t vsw, uint16_t vbp) { - Videomode m { }; + Videomode m{}; m.clock = clock_khz; m.hdisplay = hact; @@ -163,4 +162,4 @@ Videomode videomode_from_timings(uint32_t clock_khz, return m; } -} +} // namespace kms diff --git a/kms++util/inc/kms++util/color.h b/kms++util/inc/kms++util/color.h index fa05fbc..5232b37 100644 --- a/kms++util/inc/kms++util/color.h +++ b/kms++util/inc/kms++util/color.h @@ -14,8 +14,7 @@ enum class YUVType { MAX, }; -struct RGB -{ +struct RGB { RGB(); RGB(uint8_t r, uint8_t g, uint8_t b); RGB(uint8_t a, uint8_t r, uint8_t g, uint8_t b); @@ -47,8 +46,7 @@ struct RGB uint8_t a; }; -struct YUV -{ +struct YUV { YUV(); YUV(uint8_t y, uint8_t u, uint8_t v); YUV(const RGB& rgb, YUVType type = YUVType::BT601_Lim); @@ -58,4 +56,4 @@ struct YUV uint8_t y; uint8_t a; }; -} +} // namespace kms diff --git a/kms++util/inc/kms++util/cpuframebuffer.h b/kms++util/inc/kms++util/cpuframebuffer.h index 4273e0d..e4de150 100644 --- a/kms++util/inc/kms++util/cpuframebuffer.h +++ b/kms++util/inc/kms++util/cpuframebuffer.h @@ -4,8 +4,8 @@ namespace kms { - -class CPUFramebuffer : public IFramebuffer { +class CPUFramebuffer : public IFramebuffer +{ public: CPUFramebuffer(uint32_t width, uint32_t height, PixelFormat format); @@ -30,7 +30,7 @@ private: uint32_t size; uint32_t stride; uint32_t offset; - uint8_t *map; + uint8_t* map; }; uint32_t m_width; @@ -41,4 +41,4 @@ private: struct FramebufferPlane m_planes[4]; }; -} +} // namespace kms diff --git a/kms++util/inc/kms++util/extcpuframebuffer.h b/kms++util/inc/kms++util/extcpuframebuffer.h index 92ca43a..29a06c0 100644 --- a/kms++util/inc/kms++util/extcpuframebuffer.h +++ b/kms++util/inc/kms++util/extcpuframebuffer.h @@ -4,7 +4,6 @@ namespace kms { - class ExtCPUFramebuffer : public IFramebuffer { public: @@ -30,7 +29,7 @@ private: uint32_t size; uint32_t stride; uint32_t offset; - uint8_t *map; + uint8_t* map; }; uint32_t m_width; @@ -40,4 +39,4 @@ private: unsigned m_num_planes; struct FramebufferPlane m_planes[4]; }; -} +} // namespace kms diff --git a/kms++util/inc/kms++util/kms++util.h b/kms++util/inc/kms++util/kms++util.h index 8fc6c8b..52b6ce9 100644 --- a/kms++util/inc/kms++util/kms++util.h +++ b/kms++util/inc/kms++util/kms++util.h @@ -21,15 +21,15 @@ void draw_rgb_pixel(IFramebuffer& buf, unsigned x, unsigned y, RGB color); void draw_yuv444_pixel(IFramebuffer& buf, unsigned x, unsigned y, YUV yuv); void draw_yuv422_macropixel(IFramebuffer& buf, unsigned x, unsigned y, YUV yuv1, YUV yuv2); void draw_yuv420_macropixel(IFramebuffer& buf, unsigned x, unsigned y, - YUV yuv1, YUV yuv2, YUV yuv3, YUV yuv4); -void draw_rect(IFramebuffer &fb, uint32_t x, uint32_t y, uint32_t w, uint32_t h, RGB color); + YUV yuv1, YUV yuv2, YUV yuv3, YUV yuv4); +void draw_rect(IFramebuffer& fb, uint32_t x, uint32_t y, uint32_t w, uint32_t h, RGB color); void draw_circle(IFramebuffer& fb, int32_t xCenter, int32_t yCenter, int32_t radius, RGB color); void draw_text(IFramebuffer& buf, uint32_t x, uint32_t y, const std::string& str, RGB color); void draw_color_bar(IFramebuffer& buf, int old_xpos, int xpos, int width); -void draw_test_pattern(IFramebuffer &fb, YUVType yuvt = YUVType::BT601_Lim); -} +void draw_test_pattern(IFramebuffer& fb, YUVType yuvt = YUVType::BT601_Lim); +} // namespace kms #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) @@ -42,32 +42,32 @@ void draw_test_pattern(IFramebuffer &fb, YUVType yuvt = YUVType::BT601_Lim); #define __STRING(x) #x #endif -#define ASSERT(x) \ - if (unlikely(!(x))) { \ +#define ASSERT(x) \ + if (unlikely(!(x))) { \ fprintf(stderr, "%s:%d: %s: ASSERT(%s) failed\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, __STRING(x)); \ - abort(); \ + abort(); \ } -#define FAIL(fmt, ...) \ - do { \ +#define FAIL(fmt, ...) \ + do { \ fprintf(stderr, "%s:%d: %s:\n" fmt "\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, ##__VA_ARGS__); \ - abort(); \ - } while(0) + abort(); \ + } while (0) -#define FAIL_IF(x, fmt, ...) \ - if (unlikely(x)) { \ +#define FAIL_IF(x, fmt, ...) \ + if (unlikely(x)) { \ fprintf(stderr, "%s:%d: %s:\n" fmt "\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, ##__VA_ARGS__); \ - abort(); \ + abort(); \ } -#define EXIT(fmt, ...) \ - do { \ +#define EXIT(fmt, ...) \ + do { \ fprintf(stderr, fmt "\n", ##__VA_ARGS__); \ - exit(-1); \ - } while(0) + exit(-1); \ + } while (0) -#define EXIT_IF(x, fmt, ...) \ - if (unlikely(x)) { \ +#define EXIT_IF(x, fmt, ...) \ + if (unlikely(x)) { \ fprintf(stderr, fmt "\n", ##__VA_ARGS__); \ - exit(-1); \ + exit(-1); \ } diff --git a/kms++util/inc/kms++util/opts.h b/kms++util/inc/kms++util/opts.h index 1b0fd22..6058b27 100644 --- a/kms++util/inc/kms++util/opts.h +++ b/kms++util/inc/kms++util/opts.h @@ -7,6 +7,7 @@ class Option { friend class OptionSet; + public: Option(const std::string& str, std::function<void()> func); Option(const std::string& str, std::function<void(const std::string)> func); diff --git a/kms++util/inc/kms++util/resourcemanager.h b/kms++util/inc/kms++util/resourcemanager.h index 3301da2..11c11b3 100644 --- a/kms++util/inc/kms++util/resourcemanager.h +++ b/kms++util/inc/kms++util/resourcemanager.h @@ -2,8 +2,8 @@ #include <set> #include <string> -namespace kms { - +namespace kms +{ class ResourceManager { public: @@ -32,4 +32,4 @@ private: std::set<Plane*> m_reserved_planes; }; -} +} // namespace kms diff --git a/kms++util/inc/kms++util/strhelpers.h b/kms++util/inc/kms++util/strhelpers.h index 2d35e93..c4032d7 100644 --- a/kms++util/inc/kms++util/strhelpers.h +++ b/kms++util/inc/kms++util/strhelpers.h @@ -5,7 +5,7 @@ std::string to_lower(const std::string& str); -template <typename T> +template<typename T> std::string join(const T& values, const std::string& delim) { std::ostringstream ss; @@ -17,7 +17,7 @@ std::string join(const T& values, const std::string& delim) return ss.str(); } -template <typename T> +template<typename T> std::string join(const std::vector<T>& values, const std::string& delim, std::function<std::string(T)> func) { std::ostringstream ss; diff --git a/kms++util/inc/kms++util/videodevice.h b/kms++util/inc/kms++util/videodevice.h index 0aaa103..3bce4a9 100644 --- a/kms++util/inc/kms++util/videodevice.h +++ b/kms++util/inc/kms++util/videodevice.h @@ -9,8 +9,7 @@ class VideoStreamer; class VideoDevice { public: - struct VideoFrameSize - { + struct VideoFrameSize { uint32_t min_w, max_w, step_w; uint32_t min_h, max_h, step_h; }; diff --git a/kms++util/src/color.cpp b/kms++util/src/color.cpp index 2d45eff..74ff8c9 100644 --- a/kms++util/src/color.cpp +++ b/kms++util/src/color.cpp @@ -9,7 +9,7 @@ RGB::RGB() } RGB::RGB(uint8_t r, uint8_t g, uint8_t b) - :RGB(255, r, g, b) + : RGB(255, r, g, b) { } @@ -110,33 +110,27 @@ YUV RGB::yuv(YUVType type) const } #define CF_ONE (256) -#define CF(a, b, c) { ((int) ((a) * CF_ONE)), ((int) ((b) * CF_ONE)), ((int) ((c) * CF_ONE)) } -#define CLAMP(a) ((a) > (CF_ONE-1) ? (CF_ONE-1) : (a) < 0 ? 0 : (a)) +#define CF(a, b, c) \ + { \ + ((int)((a)*CF_ONE)), ((int)((b)*CF_ONE)), ((int)((c)*CF_ONE)) \ + } +#define CLAMP(a) ((a) > (CF_ONE - 1) ? (CF_ONE - 1) : (a) < 0 ? 0 : (a)) const int YUVcoef[static_cast<unsigned>(YUVType::MAX)][3][3] = { [static_cast<unsigned>(YUVType::BT601_Lim)] = { - CF( 0.257, 0.504, 0.098), - CF(-0.148, -0.291, 0.439), - CF( 0.439, -0.368, -0.071) }, - [static_cast<unsigned>(YUVType::BT601_Full)] = { - CF( 0.299, 0.587, 0.114), - CF(-0.169, -0.331, 0.500), - CF( 0.500, -0.419, -0.081) }, - [static_cast<unsigned>(YUVType::BT709_Lim)] = { - CF( 0.1826, 0.6142, 0.0620), - CF(-0.1006, -0.3386, 0.4392), - CF( 0.4392, -0.3989, -0.0403) }, - [static_cast<unsigned>(YUVType::BT709_Full)] = { - CF( 0.2126, 0.7152, 0.0722), - CF(-0.1146, -0.3854, 0.5000), - CF( 0.5000, -0.4542, -0.0468) }, + CF(0.257, 0.504, 0.098), + CF(-0.148, -0.291, 0.439), + CF(0.439, -0.368, -0.071) }, + [static_cast<unsigned>(YUVType::BT601_Full)] = { CF(0.299, 0.587, 0.114), CF(-0.169, -0.331, 0.500), CF(0.500, -0.419, -0.081) }, + [static_cast<unsigned>(YUVType::BT709_Lim)] = { CF(0.1826, 0.6142, 0.0620), CF(-0.1006, -0.3386, 0.4392), CF(0.4392, -0.3989, -0.0403) }, + [static_cast<unsigned>(YUVType::BT709_Full)] = { CF(0.2126, 0.7152, 0.0722), CF(-0.1146, -0.3854, 0.5000), CF(0.5000, -0.4542, -0.0468) }, }; const int YUVoffset[static_cast<unsigned>(YUVType::MAX)][3] = { - [static_cast<unsigned>(YUVType::BT601_Lim)] = CF(0.0625, 0.5, 0.5), - [static_cast<unsigned>(YUVType::BT601_Full)] = CF( 0, 0.5, 0.5), - [static_cast<unsigned>(YUVType::BT709_Lim)] = CF(0.0625, 0.5, 0.5), - [static_cast<unsigned>(YUVType::BT709_Full)] = CF( 0, 0.5, 0.5), + [static_cast<unsigned>(YUVType::BT601_Lim)] = CF(0.0625, 0.5, 0.5), + [static_cast<unsigned>(YUVType::BT601_Full)] = CF(0, 0.5, 0.5), + [static_cast<unsigned>(YUVType::BT709_Lim)] = CF(0.0625, 0.5, 0.5), + [static_cast<unsigned>(YUVType::BT709_Full)] = CF(0, 0.5, 0.5), }; YUV::YUV() @@ -152,33 +146,33 @@ YUV::YUV(uint8_t y, uint8_t u, uint8_t v) this->a = 0; } -static inline -uint8_t MAKE_YUV_Y(uint8_t r, uint8_t g, uint8_t b, YUVType type) +static inline uint8_t MAKE_YUV_Y(uint8_t r, uint8_t g, uint8_t b, YUVType type) { unsigned tidx = static_cast<unsigned>(type); return CLAMP(((YUVcoef[tidx][0][0] * r + YUVcoef[tidx][0][1] * g + - YUVcoef[tidx][0][2] * b + CF_ONE/2) / CF_ONE) + + YUVcoef[tidx][0][2] * b + CF_ONE / 2) / + CF_ONE) + YUVoffset[tidx][0]); } -static inline -uint8_t MAKE_YUV_U(uint8_t r, uint8_t g, uint8_t b, YUVType type) +static inline uint8_t MAKE_YUV_U(uint8_t r, uint8_t g, uint8_t b, YUVType type) { unsigned tidx = static_cast<unsigned>(type); return CLAMP(((YUVcoef[tidx][1][0] * r + YUVcoef[tidx][1][1] * g + - YUVcoef[tidx][1][2] * b + CF_ONE/2) / CF_ONE) + + YUVcoef[tidx][1][2] * b + CF_ONE / 2) / + CF_ONE) + YUVoffset[tidx][1]); } -static inline -uint8_t MAKE_YUV_V(uint8_t r, uint8_t g, uint8_t b, YUVType type) +static inline uint8_t MAKE_YUV_V(uint8_t r, uint8_t g, uint8_t b, YUVType type) { unsigned tidx = static_cast<unsigned>(type); return CLAMP(((YUVcoef[tidx][2][0] * r + YUVcoef[tidx][2][1] * g + - YUVcoef[tidx][2][2] * b + CF_ONE/2) / CF_ONE) + + YUVcoef[tidx][2][2] * b + CF_ONE / 2) / + CF_ONE) + YUVoffset[tidx][2]); } @@ -189,4 +183,4 @@ YUV::YUV(const RGB& rgb, YUVType type) this->v = MAKE_YUV_V(rgb.r, rgb.g, rgb.b, type); this->a = rgb.a; } -} +} // namespace kms diff --git a/kms++util/src/colorbar.cpp b/kms++util/src/colorbar.cpp index c08ed9d..cd0b978 100644 --- a/kms++util/src/colorbar.cpp +++ b/kms++util/src/colorbar.cpp @@ -39,7 +39,7 @@ static void drm_draw_color_bar_rgb888(IFramebuffer& buf, int old_xpos, int xpos, { for (unsigned y = 0; y < buf.height(); ++y) { RGB bcol = colors32[y * ARRAY_SIZE(colors32) / buf.height()]; - uint32_t *line = (uint32_t*)(buf.map(0) + buf.stride(0) * y); + uint32_t* line = (uint32_t*)(buf.map(0) + buf.stride(0) * y); if (old_xpos >= 0) { for (int x = old_xpos; x < old_xpos + width; ++x) @@ -57,7 +57,7 @@ static void drm_draw_color_bar_rgb565(IFramebuffer& buf, int old_xpos, int xpos, for (unsigned y = 0; y < buf.height(); ++y) { uint16_t bcol = colors16[y * ARRAY_SIZE(colors16) / buf.height()]; - uint16_t *line = (uint16_t*)(buf.map(0) + buf.stride(0) * y); + uint16_t* line = (uint16_t*)(buf.map(0) + buf.stride(0) * y); if (old_xpos >= 0) { for (int x = old_xpos; x < old_xpos + width; ++x) @@ -85,7 +85,7 @@ static void drm_draw_color_bar_semiplanar_yuv(IFramebuffer& buf, int old_xpos, i for (unsigned y = 0; y < buf.height(); ++y) { unsigned int bcol = colors[y * ARRAY_SIZE(colors) / buf.height()]; - uint8_t *line = (uint8_t*)(buf.map(0) + buf.stride(0) * y); + uint8_t* line = (uint8_t*)(buf.map(0) + buf.stride(0) * y); if (old_xpos >= 0) { for (int x = old_xpos; x < old_xpos + width; ++x) @@ -129,4 +129,4 @@ void draw_color_bar(IFramebuffer& buf, int old_xpos, int xpos, int width) ASSERT(false); } } -} +} // namespace kms diff --git a/kms++util/src/cpuframebuffer.cpp b/kms++util/src/cpuframebuffer.cpp index 33f8f97..c3bc248 100644 --- a/kms++util/src/cpuframebuffer.cpp +++ b/kms++util/src/cpuframebuffer.cpp @@ -4,8 +4,8 @@ using namespace std; -namespace kms { - +namespace kms +{ CPUFramebuffer::CPUFramebuffer(uint32_t width, uint32_t height, PixelFormat format) : m_width(width), m_height(height), m_format(format) { @@ -18,7 +18,7 @@ CPUFramebuffer::CPUFramebuffer(uint32_t width, uint32_t height, PixelFormat form FramebufferPlane& plane = m_planes[i]; plane.stride = width * pi.bitspp / 8; - plane.size = plane.stride * height/ pi.ysub; + plane.size = plane.stride * height / pi.ysub; plane.offset = 0; plane.map = new uint8_t[plane.size]; } @@ -29,8 +29,8 @@ CPUFramebuffer::~CPUFramebuffer() for (unsigned i = 0; i < m_num_planes; ++i) { FramebufferPlane& plane = m_planes[i]; - delete [] plane.map; + delete[] plane.map; } } -} +} // namespace kms diff --git a/kms++util/src/drawing.cpp b/kms++util/src/drawing.cpp index 3752f94..79e0d90 100644 --- a/kms++util/src/drawing.cpp +++ b/kms++util/src/drawing.cpp @@ -15,106 +15,91 @@ void draw_rgb_pixel(IFramebuffer& buf, unsigned x, unsigned y, RGB color) switch (buf.format()) { case PixelFormat::XRGB8888: - case PixelFormat::ARGB8888: - { - uint32_t *p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4); + case PixelFormat::ARGB8888: { + uint32_t* p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4); *p = color.argb8888(); break; } case PixelFormat::XBGR8888: - case PixelFormat::ABGR8888: - { - uint32_t *p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4); + case PixelFormat::ABGR8888: { + uint32_t* p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4); *p = color.abgr8888(); break; } case PixelFormat::RGBX8888: - case PixelFormat::RGBA8888: - { - uint32_t *p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4); + case PixelFormat::RGBA8888: { + uint32_t* p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4); *p = color.rgba8888(); break; } case PixelFormat::BGRX8888: - case PixelFormat::BGRA8888: - { - uint32_t *p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4); + case PixelFormat::BGRA8888: { + uint32_t* p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4); *p = color.bgra8888(); break; } case PixelFormat::XRGB2101010: - case PixelFormat::ARGB2101010: - { - uint32_t *p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4); + case PixelFormat::ARGB2101010: { + uint32_t* p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4); *p = color.argb2101010(); break; } case PixelFormat::XBGR2101010: - case PixelFormat::ABGR2101010: - { - uint32_t *p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4); + case PixelFormat::ABGR2101010: { + uint32_t* p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4); *p = color.abgr2101010(); break; } case PixelFormat::RGBX1010102: - case PixelFormat::RGBA1010102: - { - uint32_t *p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4); + case PixelFormat::RGBA1010102: { + uint32_t* p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4); *p = color.rgba1010102(); break; } case PixelFormat::BGRX1010102: - case PixelFormat::BGRA1010102: - { - uint32_t *p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4); + case PixelFormat::BGRA1010102: { + uint32_t* p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4); *p = color.bgra1010102(); break; } - case PixelFormat::RGB888: - { - uint8_t *p = buf.map(0) + buf.stride(0) * y + x * 3; + case PixelFormat::RGB888: { + uint8_t* p = buf.map(0) + buf.stride(0) * y + x * 3; p[0] = color.b; p[1] = color.g; p[2] = color.r; break; } - case PixelFormat::BGR888: - { - uint8_t *p = buf.map(0) + buf.stride(0) * y + x * 3; + case PixelFormat::BGR888: { + uint8_t* p = buf.map(0) + buf.stride(0) * y + x * 3; p[0] = color.r; p[1] = color.g; p[2] = color.b; break; } - case PixelFormat::RGB332: - { - uint8_t *p = (uint8_t*)(buf.map(0) + buf.stride(0) * y + x); + case PixelFormat::RGB332: { + uint8_t* p = (uint8_t*)(buf.map(0) + buf.stride(0) * y + x); *p = color.rgb332(); break; } - case PixelFormat::RGB565: - { - uint16_t *p = (uint16_t*)(buf.map(0) + buf.stride(0) * y + x * 2); + case PixelFormat::RGB565: { + uint16_t* p = (uint16_t*)(buf.map(0) + buf.stride(0) * y + x * 2); *p = color.rgb565(); break; } - case PixelFormat::BGR565: - { - uint16_t *p = (uint16_t*)(buf.map(0) + buf.stride(0) * y + x * 2); + case PixelFormat::BGR565: { + uint16_t* p = (uint16_t*)(buf.map(0) + buf.stride(0) * y + x * 2); *p = color.bgr565(); break; } case PixelFormat::XRGB4444: - case PixelFormat::ARGB4444: - { - uint16_t *p = (uint16_t*)(buf.map(0) + buf.stride(0) * y + x * 2); + case PixelFormat::ARGB4444: { + uint16_t* p = (uint16_t*)(buf.map(0) + buf.stride(0) * y + x * 2); *p = color.argb4444(); break; } case PixelFormat::XRGB1555: - case PixelFormat::ARGB1555: - { - uint16_t *p = (uint16_t*)(buf.map(0) + buf.stride(0) * y + x * 2); + case PixelFormat::ARGB1555: { + uint16_t* p = (uint16_t*)(buf.map(0) + buf.stride(0) * y + x * 2); *p = color.argb1555(); break; } @@ -128,9 +113,9 @@ void draw_yuv444_pixel(IFramebuffer& buf, unsigned x, unsigned y, YUV yuv) if (x >= buf.width() || y >= buf.height()) throw runtime_error("attempt to draw outside the buffer"); - uint8_t *py = (uint8_t*)(buf.map(0) + buf.stride(0) * y + x); - uint8_t *pu = (uint8_t*)(buf.map(1) + buf.stride(1) * y + x); - uint8_t *pv = (uint8_t*)(buf.map(2) + buf.stride(2) * y + x); + uint8_t* py = (uint8_t*)(buf.map(0) + buf.stride(0) * y + x); + uint8_t* pu = (uint8_t*)(buf.map(1) + buf.stride(1) * y + x); + uint8_t* pv = (uint8_t*)(buf.map(2) + buf.stride(2) * y + x); switch (buf.format()) { case PixelFormat::YUV444: @@ -153,7 +138,7 @@ void draw_yuv444_pixel(IFramebuffer& buf, unsigned x, unsigned y, YUV yuv) static void draw_yuv422_packed_macropixel(IFramebuffer& buf, unsigned x, unsigned y, YUV yuv1, YUV yuv2) { - uint8_t *p = (uint8_t*)(buf.map(0) + buf.stride(0) * y + x * 2); + uint8_t* p = (uint8_t*)(buf.map(0) + buf.stride(0) * y + x * 2); uint8_t y0 = yuv1.y; uint8_t y1 = yuv2.y; @@ -197,8 +182,8 @@ static void draw_yuv422_packed_macropixel(IFramebuffer& buf, unsigned x, unsigne static void draw_yuv422_semiplanar_macropixel(IFramebuffer& buf, unsigned x, unsigned y, YUV yuv1, YUV yuv2) { - uint8_t *py = (uint8_t*)(buf.map(0) + buf.stride(0) * y + x); - uint8_t *puv = (uint8_t*)(buf.map(1) + buf.stride(1) * y + x); + uint8_t* py = (uint8_t*)(buf.map(0) + buf.stride(0) * y + x); + uint8_t* puv = (uint8_t*)(buf.map(1) + buf.stride(1) * y + x); uint8_t y0 = yuv1.y; uint8_t y1 = yuv2.y; @@ -228,9 +213,9 @@ static void draw_yuv422_semiplanar_macropixel(IFramebuffer& buf, unsigned x, uns static void draw_yuv422_planar_macropixel(IFramebuffer& buf, unsigned x, unsigned y, YUV yuv1, YUV yuv2) { - uint8_t *py = (uint8_t*)(buf.map(0) + buf.stride(0) * y + x); - uint8_t *pu = (uint8_t*)(buf.map(1) + buf.stride(1) * y + x / 2); - uint8_t *pv = (uint8_t*)(buf.map(2) + buf.stride(2) * y + x / 2); + uint8_t* py = (uint8_t*)(buf.map(0) + buf.stride(0) * y + x); + uint8_t* pu = (uint8_t*)(buf.map(1) + buf.stride(1) * y + x / 2); + uint8_t* pv = (uint8_t*)(buf.map(2) + buf.stride(2) * y + x / 2); uint8_t y0 = yuv1.y; uint8_t y1 = yuv2.y; @@ -290,10 +275,10 @@ void draw_yuv422_macropixel(IFramebuffer& buf, unsigned x, unsigned y, YUV yuv1, static void draw_yuv420_semiplanar_macropixel(IFramebuffer& buf, unsigned x, unsigned y, YUV yuv1, YUV yuv2, YUV yuv3, YUV yuv4) { - uint8_t *py1 = (uint8_t*)(buf.map(0) + buf.stride(0) * (y + 0) + x); - uint8_t *py2 = (uint8_t*)(buf.map(0) + buf.stride(0) * (y + 1) + x); + uint8_t* py1 = (uint8_t*)(buf.map(0) + buf.stride(0) * (y + 0) + x); + uint8_t* py2 = (uint8_t*)(buf.map(0) + buf.stride(0) * (y + 1) + x); - uint8_t *puv = (uint8_t*)(buf.map(1) + buf.stride(1) * (y / 2) + x); + uint8_t* puv = (uint8_t*)(buf.map(1) + buf.stride(1) * (y / 2) + x); uint8_t y0 = yuv1.y; uint8_t y1 = yuv2.y; @@ -329,11 +314,11 @@ static void draw_yuv420_semiplanar_macropixel(IFramebuffer& buf, unsigned x, uns static void draw_yuv420_planar_macropixel(IFramebuffer& buf, unsigned x, unsigned y, YUV yuv1, YUV yuv2, YUV yuv3, YUV yuv4) { - uint8_t *py1 = (uint8_t*)(buf.map(0) + buf.stride(0) * (y + 0) + x); - uint8_t *py2 = (uint8_t*)(buf.map(0) + buf.stride(0) * (y + 1) + x); + uint8_t* py1 = (uint8_t*)(buf.map(0) + buf.stride(0) * (y + 0) + x); + uint8_t* py2 = (uint8_t*)(buf.map(0) + buf.stride(0) * (y + 1) + x); - uint8_t *pu = (uint8_t*)(buf.map(1) + buf.stride(1) * (y / 2) + x / 2); - uint8_t *pv = (uint8_t*)(buf.map(2) + buf.stride(2) * (y / 2) + x / 2); + uint8_t* pu = (uint8_t*)(buf.map(1) + buf.stride(1) * (y / 2) + x / 2); + uint8_t* pv = (uint8_t*)(buf.map(2) + buf.stride(2) * (y / 2) + x / 2); uint8_t y0 = yuv1.y; uint8_t y1 = yuv2.y; @@ -391,7 +376,7 @@ void draw_yuv420_macropixel(IFramebuffer& buf, unsigned x, unsigned y, } } -void draw_rect(IFramebuffer &fb, uint32_t x, uint32_t y, uint32_t w, uint32_t h, RGB color) +void draw_rect(IFramebuffer& fb, uint32_t x, uint32_t y, uint32_t w, uint32_t h, RGB color) { unsigned i, j; YUV yuvcolor = color.yuv(); @@ -565,8 +550,8 @@ static void draw_char(IFramebuffer& buf, uint32_t xpos, uint32_t ypos, char c, R void draw_text(IFramebuffer& buf, uint32_t x, uint32_t y, const string& str, RGB color) { - for(unsigned i = 0; i < str.size(); i++) + for (unsigned i = 0; i < str.size(); i++) draw_char(buf, (x + 8 * i), y, str[i], color); } -} +} // namespace kms diff --git a/kms++util/src/extcpuframebuffer.cpp b/kms++util/src/extcpuframebuffer.cpp index feb3add..0ee79ee 100644 --- a/kms++util/src/extcpuframebuffer.cpp +++ b/kms++util/src/extcpuframebuffer.cpp @@ -5,7 +5,6 @@ using namespace std; namespace kms { - ExtCPUFramebuffer::ExtCPUFramebuffer(uint32_t width, uint32_t height, PixelFormat format, uint8_t* buffer, uint32_t size, uint32_t pitch, uint32_t offset) : m_width(width), m_height(height), m_format(format) @@ -46,4 +45,4 @@ ExtCPUFramebuffer::~ExtCPUFramebuffer() { } -} +} // namespace kms diff --git a/kms++util/src/font_8x8.h b/kms++util/src/font_8x8.h index 2a2a1ea..ed9bf3f 100644 --- a/kms++util/src/font_8x8.h +++ b/kms++util/src/font_8x8.h @@ -2567,4 +2567,3 @@ const uint8_t fontdata_8x8[] = { 0x00, /* 00000000 */ }; - diff --git a/kms++util/src/opts.cpp b/kms++util/src/opts.cpp index 5a14b84..ba49995 100644 --- a/kms++util/src/opts.cpp +++ b/kms++util/src/opts.cpp @@ -75,7 +75,7 @@ void OptionSet::parse(int argc, char** argv) } } - longopts.push_back(option {}); + longopts.push_back(option{}); while (1) { int long_idx = 0; diff --git a/kms++util/src/testpat.cpp b/kms++util/src/testpat.cpp index ac38673..78c9d19 100644 --- a/kms++util/src/testpat.cpp +++ b/kms++util/src/testpat.cpp @@ -15,7 +15,6 @@ using namespace std; namespace kms { - static RGB get_test_pattern_pixel(IFramebuffer& fb, unsigned x, unsigned y) { const unsigned w = fb.width(); @@ -198,7 +197,7 @@ static void draw_test_pattern_impl(IFramebuffer& fb, YUVType yuvt) #endif } -void draw_test_pattern(IFramebuffer &fb, YUVType yuvt) +void draw_test_pattern(IFramebuffer& fb, YUVType yuvt) { #ifdef DRAW_PERF_PRINT Stopwatch sw; @@ -213,4 +212,4 @@ void draw_test_pattern(IFramebuffer &fb, YUVType yuvt) #endif } -} +} // namespace kms diff --git a/kms++util/src/videodevice.cpp b/kms++util/src/videodevice.cpp index 0121c7c..9530d60 100644 --- a/kms++util/src/videodevice.cpp +++ b/kms++util/src/videodevice.cpp @@ -32,7 +32,7 @@ static vector<PixelFormat> v4l2_get_formats(int fd, uint32_t buf_type) { vector<PixelFormat> v; - v4l2_fmtdesc desc { }; + v4l2_fmtdesc desc{}; desc.type = buf_type; while (ioctl(fd, VIDIOC_ENUM_FMT, &desc) == 0) { @@ -51,7 +51,7 @@ static void v4l2_set_format(int fd, PixelFormat fmt, uint32_t width, uint32_t he { int r; - v4l2_format v4lfmt { }; + v4l2_format v4lfmt{}; v4lfmt.type = buf_type; r = ioctl(fd, VIDIOC_G_FMT, &v4lfmt); @@ -177,7 +177,7 @@ static void v4l2_set_selection(int fd, uint32_t& left, uint32_t& top, uint32_t& static void v4l2_request_bufs(int fd, uint32_t queue_size, uint32_t buf_type) { - v4l2_requestbuffers v4lreqbuf { }; + v4l2_requestbuffers v4lreqbuf{}; v4lreqbuf.type = buf_type; v4lreqbuf.memory = V4L2_MEMORY_DMABUF; v4lreqbuf.count = queue_size; @@ -188,7 +188,7 @@ static void v4l2_request_bufs(int fd, uint32_t queue_size, uint32_t buf_type) static void v4l2_queue_dmabuf(int fd, uint32_t index, DumbFramebuffer* fb, uint32_t buf_type) { - v4l2_buffer buf { }; + v4l2_buffer buf{}; buf.type = buf_type; buf.memory = V4L2_MEMORY_DMABUF; buf.index = index; @@ -200,7 +200,7 @@ static void v4l2_queue_dmabuf(int fd, uint32_t index, DumbFramebuffer* fb, uint3 if (mplane) { buf.length = pfi.num_planes; - v4l2_plane planes[4] { }; + v4l2_plane planes[4]{}; buf.m.planes = planes; for (unsigned i = 0; i < pfi.num_planes; ++i) { @@ -221,12 +221,12 @@ static void v4l2_queue_dmabuf(int fd, uint32_t index, DumbFramebuffer* fb, uint3 static uint32_t v4l2_dequeue(int fd, uint32_t buf_type) { - v4l2_buffer buf { }; + v4l2_buffer buf{}; buf.type = buf_type; buf.memory = V4L2_MEMORY_DMABUF; // V4L2 crashes if planes are not set - v4l2_plane planes[4] { }; + v4l2_plane planes[4]{}; buf.m.planes = planes; buf.length = 4; @@ -237,11 +237,8 @@ static uint32_t v4l2_dequeue(int fd, uint32_t buf_type) return buf.index; } - - - VideoDevice::VideoDevice(const string& dev) - :VideoDevice(::open(dev.c_str(), O_RDWR | O_NONBLOCK)) + : VideoDevice(::open(dev.c_str(), O_RDWR | O_NONBLOCK)) { } @@ -251,7 +248,7 @@ VideoDevice::VideoDevice(int fd) if (fd < 0) throw runtime_error("bad fd"); - struct v4l2_capability cap = { }; + struct v4l2_capability cap = {}; int r = ioctl(fd, VIDIOC_QUERYCAP, &cap); ASSERT(r == 0); @@ -321,7 +318,7 @@ vector<tuple<uint32_t, uint32_t>> VideoDevice::get_discrete_frame_sizes(PixelFor { vector<tuple<uint32_t, uint32_t>> v; - v4l2_frmsizeenum v4lfrms { }; + v4l2_frmsizeenum v4lfrms{}; v4lfrms.pixel_format = (uint32_t)fmt; int r = ioctl(m_fd, VIDIOC_ENUM_FRAMESIZES, &v4lfrms); @@ -339,7 +336,7 @@ vector<tuple<uint32_t, uint32_t>> VideoDevice::get_discrete_frame_sizes(PixelFor VideoDevice::VideoFrameSize VideoDevice::get_frame_sizes(PixelFormat fmt) { - v4l2_frmsizeenum v4lfrms { }; + v4l2_frmsizeenum v4lfrms{}; v4lfrms.pixel_format = (uint32_t)fmt; int r = ioctl(m_fd, VIDIOC_ENUM_FRAMESIZES, &v4lfrms); @@ -406,11 +403,9 @@ vector<string> VideoDevice::get_m2m_devices() return v; } - VideoStreamer::VideoStreamer(int fd, StreamerType type) : m_fd(fd), m_type(type) { - } std::vector<string> VideoStreamer::get_ports() @@ -419,9 +414,9 @@ std::vector<string> VideoStreamer::get_ports() switch (m_type) { case StreamerType::CaptureSingle: - case StreamerType::CaptureMulti: - { - struct v4l2_input input { }; + case StreamerType::CaptureMulti: { + struct v4l2_input input { + }; while (ioctl(m_fd, VIDIOC_ENUMINPUT, &input) == 0) { v.push_back(string((char*)&input.name)); @@ -432,9 +427,9 @@ std::vector<string> VideoStreamer::get_ports() } case StreamerType::OutputSingle: - case StreamerType::OutputMulti: - { - struct v4l2_output output { }; + case StreamerType::OutputMulti: { + struct v4l2_output output { + }; while (ioctl(m_fd, VIDIOC_ENUMOUTPUT, &output) == 0) { v.push_back(string((char*)&output.name)); diff --git a/kmscube/cube-egl.cpp b/kmscube/cube-egl.cpp index 81b3107..5f23c4e 100644 --- a/kmscube/cube-egl.cpp +++ b/kmscube/cube-egl.cpp @@ -22,7 +22,7 @@ static void print_egl_config(EGLDisplay dpy, EGLConfig cfg) getconf(EGL_NATIVE_VISUAL_TYPE)); } -EglState::EglState(void *native_display) +EglState::EglState(void* native_display) { EGLBoolean b; EGLint major, minor, n; @@ -60,7 +60,6 @@ EglState::EglState(void *native_display) b = eglBindAPI(EGL_OPENGL_ES_API); FAIL_IF(!b, "failed to bind api EGL_OPENGL_ES_API"); - if (s_verbose) { EGLint numConfigs; b = eglGetConfigs(m_display, nullptr, 0, &numConfigs); @@ -96,7 +95,7 @@ EglState::~EglState() eglTerminate(m_display); } -EglSurface::EglSurface(const EglState &egl, void *native_window) +EglSurface::EglSurface(const EglState& egl, void* native_window) : egl(egl) { esurface = eglCreateWindowSurface(egl.display(), egl.config(), (EGLNativeWindowType)native_window, NULL); diff --git a/kmscube/cube-egl.h b/kmscube/cube-egl.h index a7de103..f492d07 100644 --- a/kmscube/cube-egl.h +++ b/kmscube/cube-egl.h @@ -5,7 +5,7 @@ class EglState { public: - EglState(void *native_display); + EglState(void* native_display); ~EglState(); EGLDisplay display() const { return m_display; } @@ -21,7 +21,7 @@ private: class EglSurface { public: - EglSurface(const EglState& egl, void *native_window); + EglSurface(const EglState& egl, void* native_window); ~EglSurface(); void make_current(); diff --git a/kmscube/cube-gbm.cpp b/kmscube/cube-gbm.cpp index e239a0c..d998f0b 100644 --- a/kmscube/cube-gbm.cpp +++ b/kmscube/cube-gbm.cpp @@ -74,7 +74,7 @@ public: return gbm_surface_lock_front_buffer(m_surface); } - void release_buffer(gbm_bo *bo) + void release_buffer(gbm_bo* bo) { gbm_surface_release_buffer(m_surface, bo); } @@ -116,13 +116,13 @@ public: eglSwapBuffers(egl.display(), esurface); } - static void drm_fb_destroy_callback(struct gbm_bo *bo, void *data) + static void drm_fb_destroy_callback(struct gbm_bo* bo, void* data) { auto fb = reinterpret_cast<Framebuffer*>(data); delete fb; } - static Framebuffer* drm_fb_get_from_bo(struct gbm_bo *bo, Card& card) + static Framebuffer* drm_fb_get_from_bo(struct gbm_bo* bo, Card& card) { auto fb = reinterpret_cast<Framebuffer*>(gbm_bo_get_user_data(bo)); if (fb) @@ -134,9 +134,9 @@ public: uint32_t handle = gbm_bo_get_handle(bo).u32; PixelFormat format = (PixelFormat)gbm_bo_get_format(bo); - vector<uint32_t> handles { handle }; - vector<uint32_t> strides { stride }; - vector<uint32_t> offsets { 0 }; + vector<uint32_t> handles{ handle }; + vector<uint32_t> strides{ stride }; + vector<uint32_t> offsets{ 0 }; fb = new ExtFramebuffer(card, width, height, format, handles, strides, offsets); @@ -237,7 +237,7 @@ private: { ++m_frame_num; - if (m_frame_num % 100 == 0) { + if (m_frame_num % 100 == 0) { auto t2 = chrono::steady_clock::now(); chrono::duration<float> fsec = t2 - m_t1; printf("fps: %f\n", 100.0 / fsec.count()); @@ -351,11 +351,11 @@ void main_gbm() for (auto& out : outputs) out->start_flipping(); - struct pollfd fds[2] = { }; + struct pollfd fds[2] = {}; fds[0].fd = 0; - fds[0].events = POLLIN; + fds[0].events = POLLIN; fds[1].fd = card.fd(); - fds[1].events = POLLIN; + fds[1].events = POLLIN; while (!s_need_exit || s_flip_pending) { int r = poll(fds, ARRAY_SIZE(fds), -1); diff --git a/kmscube/cube-gles2.cpp b/kmscube/cube-gles2.cpp index 05567ea..854c90e 100644 --- a/kmscube/cube-gles2.cpp +++ b/kmscube/cube-gles2.cpp @@ -41,40 +41,40 @@ GlScene::GlScene() -1.0f, -1.0f, -1.0f, // point black +1.0f, -1.0f, -1.0f, // point red -1.0f, -1.0f, +1.0f, // point blue - +1.0f, -1.0f, +1.0f // point magenta + +1.0f, -1.0f, +1.0f // point magenta }; static const GLfloat vColors[] = { // front - 0.0f, 0.0f, 1.0f, // blue - 1.0f, 0.0f, 1.0f, // magenta - 0.0f, 1.0f, 1.0f, // cyan - 1.0f, 1.0f, 1.0f, // white + 0.0f, 0.0f, 1.0f, // blue + 1.0f, 0.0f, 1.0f, // magenta + 0.0f, 1.0f, 1.0f, // cyan + 1.0f, 1.0f, 1.0f, // white // back - 1.0f, 0.0f, 0.0f, // red - 0.0f, 0.0f, 0.0f, // black - 1.0f, 1.0f, 0.0f, // yellow - 0.0f, 1.0f, 0.0f, // green + 1.0f, 0.0f, 0.0f, // red + 0.0f, 0.0f, 0.0f, // black + 1.0f, 1.0f, 0.0f, // yellow + 0.0f, 1.0f, 0.0f, // green // right - 1.0f, 0.0f, 1.0f, // magenta - 1.0f, 0.0f, 0.0f, // red - 1.0f, 1.0f, 1.0f, // white - 1.0f, 1.0f, 0.0f, // yellow + 1.0f, 0.0f, 1.0f, // magenta + 1.0f, 0.0f, 0.0f, // red + 1.0f, 1.0f, 1.0f, // white + 1.0f, 1.0f, 0.0f, // yellow // left - 0.0f, 0.0f, 0.0f, // black - 0.0f, 0.0f, 1.0f, // blue - 0.0f, 1.0f, 0.0f, // green - 0.0f, 1.0f, 1.0f, // cyan + 0.0f, 0.0f, 0.0f, // black + 0.0f, 0.0f, 1.0f, // blue + 0.0f, 1.0f, 0.0f, // green + 0.0f, 1.0f, 1.0f, // cyan // top - 0.0f, 1.0f, 1.0f, // cyan - 1.0f, 1.0f, 1.0f, // white - 0.0f, 1.0f, 0.0f, // green - 1.0f, 1.0f, 0.0f, // yellow + 0.0f, 1.0f, 1.0f, // cyan + 1.0f, 1.0f, 1.0f, // white + 0.0f, 1.0f, 0.0f, // green + 1.0f, 1.0f, 0.0f, // yellow // bottom - 0.0f, 0.0f, 0.0f, // black - 1.0f, 0.0f, 0.0f, // red - 0.0f, 0.0f, 1.0f, // blue - 1.0f, 0.0f, 1.0f // magenta + 0.0f, 0.0f, 0.0f, // black + 1.0f, 0.0f, 0.0f, // red + 0.0f, 0.0f, 1.0f, // blue + 1.0f, 0.0f, 1.0f // magenta }; static const GLfloat vNormals[] = { @@ -107,43 +107,42 @@ GlScene::GlScene() +0.0f, -1.0f, +0.0f, // down +0.0f, -1.0f, +0.0f, // down +0.0f, -1.0f, +0.0f, // down - +0.0f, -1.0f, +0.0f // down + +0.0f, -1.0f, +0.0f // down }; - static const char *vertex_shader_source = - "uniform mat4 modelviewMatrix; \n" - "uniform mat4 modelviewprojectionMatrix;\n" - "uniform mat3 normalMatrix; \n" - " \n" - "attribute vec4 in_position; \n" - "attribute vec3 in_normal; \n" - "attribute vec4 in_color; \n" - "\n" - "vec4 lightSource = vec4(2.0, 2.0, 20.0, 0.0);\n" - " \n" - "varying vec4 vVaryingColor; \n" - " \n" - "void main() \n" - "{ \n" - " gl_Position = modelviewprojectionMatrix * in_position;\n" - " vec3 vEyeNormal = normalMatrix * in_normal;\n" - " vec4 vPosition4 = modelviewMatrix * in_position;\n" - " vec3 vPosition3 = vPosition4.xyz / vPosition4.w;\n" - " vec3 vLightDir = normalize(lightSource.xyz - vPosition3);\n" - " float diff = max(0.0, dot(vEyeNormal, vLightDir));\n" - " vVaryingColor = vec4(diff * in_color.rgb, 1.0);\n" - "} \n"; - - static const char *fragment_shader_source = - "precision mediump float; \n" - " \n" - "varying vec4 vVaryingColor; \n" - " \n" - "void main() \n" - "{ \n" - " gl_FragColor = vVaryingColor; \n" - "} \n"; - + static const char* vertex_shader_source = + "uniform mat4 modelviewMatrix; \n" + "uniform mat4 modelviewprojectionMatrix;\n" + "uniform mat3 normalMatrix; \n" + " \n" + "attribute vec4 in_position; \n" + "attribute vec3 in_normal; \n" + "attribute vec4 in_color; \n" + "\n" + "vec4 lightSource = vec4(2.0, 2.0, 20.0, 0.0);\n" + " \n" + "varying vec4 vVaryingColor; \n" + " \n" + "void main() \n" + "{ \n" + " gl_Position = modelviewprojectionMatrix * in_position;\n" + " vec3 vEyeNormal = normalMatrix * in_normal;\n" + " vec4 vPosition4 = modelviewMatrix * in_position;\n" + " vec3 vPosition3 = vPosition4.xyz / vPosition4.w;\n" + " vec3 vLightDir = normalize(lightSource.xyz - vPosition3);\n" + " float diff = max(0.0, dot(vEyeNormal, vLightDir));\n" + " vVaryingColor = vec4(diff * in_color.rgb, 1.0);\n" + "} \n"; + + static const char* fragment_shader_source = + "precision mediump float; \n" + " \n" + "varying vec4 vVaryingColor; \n" + " \n" + "void main() \n" + "{ \n" + " gl_FragColor = vVaryingColor; \n" + "} \n"; if (s_verbose) { printf("GL_VENDOR: %s\n", glGetString(GL_VENDOR)); diff --git a/kmscube/cube-null.cpp b/kmscube/cube-null.cpp index f8f2091..1fba1db 100644 --- a/kmscube/cube-null.cpp +++ b/kmscube/cube-null.cpp @@ -18,9 +18,9 @@ void main_null() int framenum = 0; - struct pollfd fds[1] = { }; + struct pollfd fds[1] = {}; fds[0].fd = 0; - fds[0].events = POLLIN; + fds[0].events = POLLIN; while (true) { int r = poll(fds, ARRAY_SIZE(fds), 0); diff --git a/kmscube/cube-wl.cpp b/kmscube/cube-wl.cpp index de75f88..136a4ed 100644 --- a/kmscube/cube-wl.cpp +++ b/kmscube/cube-wl.cpp @@ -9,18 +9,18 @@ #include "cube-egl.h" #include "cube-gles2.h" -static struct wl_compositor *s_compositor = NULL; -static struct wl_shell *s_shell = NULL; +static struct wl_compositor* s_compositor = NULL; +static struct wl_shell* s_shell = NULL; static char s_running = 1; struct window { - struct wl_surface *surface; - struct wl_shell_surface *shell_surface; - struct wl_egl_window *egl_window; + struct wl_surface* surface; + struct wl_shell_surface* shell_surface; + struct wl_egl_window* egl_window; }; // listeners -static void registry_add_object(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) +static void registry_add_object(void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t version) { if (!strcmp(interface, "wl_compositor")) s_compositor = (struct wl_compositor*)wl_registry_bind(registry, name, &wl_compositor_interface, 0); @@ -28,35 +28,33 @@ static void registry_add_object(void *data, struct wl_registry *registry, uint32 s_shell = (struct wl_shell*)wl_registry_bind(registry, name, &wl_shell_interface, 0); } -static void registry_remove_object(void *data, struct wl_registry *registry, uint32_t name) +static void registry_remove_object(void* data, struct wl_registry* registry, uint32_t name) { - } static struct wl_registry_listener registry_listener = { ®istry_add_object, ®istry_remove_object }; -static void shell_surface_ping(void *data, struct wl_shell_surface *shell_surface, uint32_t serial) +static void shell_surface_ping(void* data, struct wl_shell_surface* shell_surface, uint32_t serial) { wl_shell_surface_pong(shell_surface, serial); } -static void shell_surface_configure(void *data, struct wl_shell_surface *shell_surface, uint32_t edges, int32_t width, int32_t height) +static void shell_surface_configure(void* data, struct wl_shell_surface* shell_surface, uint32_t edges, int32_t width, int32_t height) { - struct window *window = (struct window*)data; + struct window* window = (struct window*)data; wl_egl_window_resize(window->egl_window, width, height, 0, 0); } -static void shell_surface_popup_done(void *data, struct wl_shell_surface *shell_surface) +static void shell_surface_popup_done(void* data, struct wl_shell_surface* shell_surface) { - } static struct wl_shell_surface_listener shell_surface_listener = { &shell_surface_ping, &shell_surface_configure, &shell_surface_popup_done }; -static void create_window(struct window *window, int32_t width, int32_t height) +static void create_window(struct window* window, int32_t width, int32_t height) { window->surface = wl_compositor_create_surface(s_compositor); window->shell_surface = wl_shell_get_shell_surface(s_shell, window->surface); @@ -65,7 +63,7 @@ static void create_window(struct window *window, int32_t width, int32_t height) window->egl_window = wl_egl_window_create(window->surface, width, height); } -static void delete_window(struct window *window) +static void delete_window(struct window* window) { wl_egl_window_destroy(window->egl_window); wl_shell_surface_destroy(window->shell_surface); @@ -74,8 +72,8 @@ static void delete_window(struct window *window) void main_wl() { - struct wl_display *display = wl_display_connect(NULL); - struct wl_registry *registry = wl_display_get_registry(display); + struct wl_display* display = wl_display_connect(NULL); + struct wl_registry* registry = wl_display_get_registry(display); wl_registry_add_listener(registry, ®istry_listener, NULL); wl_display_roundtrip(display); diff --git a/kmscube/cube-x11.cpp b/kmscube/cube-x11.cpp index 47a1d2b..ae018ea 100644 --- a/kmscube/cube-x11.cpp +++ b/kmscube/cube-x11.cpp @@ -10,7 +10,7 @@ using namespace std; -static void main_loop(Display* dpy, xcb_connection_t *c, xcb_window_t window, uint32_t width, uint32_t height) +static void main_loop(Display* dpy, xcb_connection_t* c, xcb_window_t window, uint32_t width, uint32_t height) { EglState egl(dpy); EglSurface surface(egl, (void*)(uintptr_t)window); @@ -25,10 +25,9 @@ static void main_loop(Display* dpy, xcb_connection_t *c, xcb_window_t window, ui bool need_exit = false; - xcb_generic_event_t *event; + xcb_generic_event_t* event; while (true) { - - while ((event = xcb_poll_for_event (c))) { + while ((event = xcb_poll_for_event(c))) { bool handled = false; uint8_t response_type = event->response_type & ~0x80; @@ -40,7 +39,7 @@ static void main_loop(Display* dpy, xcb_connection_t *c, xcb_window_t window, ui case XCB_KEY_PRESS: { handled = true; - xcb_key_press_event_t *kp = (xcb_key_press_event_t *)event; + xcb_key_press_event_t* kp = (xcb_key_press_event_t*)event; if (kp->detail == 24 || kp->detail == 9) { printf("Exit due to keypress\n"); need_exit = true; @@ -85,14 +84,14 @@ void main_x11() Display* dpy = XOpenDisplay(NULL); FAIL_IF(!dpy, "Failed to connect to the X server"); - xcb_connection_t *c = XGetXCBConnection(dpy); + xcb_connection_t* c = XGetXCBConnection(dpy); /* Acquire event queue ownership */ XSetEventQueueOwner(dpy, XCBOwnsEventQueue); /* Get the first screen */ - const xcb_setup_t *setup = xcb_get_setup (c); - xcb_screen_t *screen = xcb_setup_roots_iterator (setup).data; + const xcb_setup_t* setup = xcb_get_setup(c); + xcb_screen_t* screen = xcb_setup_roots_iterator(setup).data; /* Create the window */ @@ -115,23 +114,22 @@ void main_x11() XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_KEY_PRESS, }; - xcb_window_t window = xcb_generate_id (c); - xcb_create_window (c, /* Connection */ - XCB_COPY_FROM_PARENT, /* depth (same as root)*/ - window, /* window Id */ - screen->root, /* parent window */ - 0, 0, /* x, y */ - width, height, /* width, height */ - 0, /* border_width */ - XCB_WINDOW_CLASS_INPUT_OUTPUT, /* class */ - screen->root_visual, /* visual */ - xcb_window_attrib_mask, - xcb_window_attrib_list); - - if (s_fullscreen) - { - const char *net_wm_state = "_NET_WM_STATE"; - const char *net_wm_state_fullscreen = "_NET_WM_STATE_FULLSCREEN"; + xcb_window_t window = xcb_generate_id(c); + xcb_create_window(c, /* Connection */ + XCB_COPY_FROM_PARENT, /* depth (same as root)*/ + window, /* window Id */ + screen->root, /* parent window */ + 0, 0, /* x, y */ + width, height, /* width, height */ + 0, /* border_width */ + XCB_WINDOW_CLASS_INPUT_OUTPUT, /* class */ + screen->root_visual, /* visual */ + xcb_window_attrib_mask, + xcb_window_attrib_list); + + if (s_fullscreen) { + const char* net_wm_state = "_NET_WM_STATE"; + const char* net_wm_state_fullscreen = "_NET_WM_STATE_FULLSCREEN"; xcb_intern_atom_cookie_t cookie = xcb_intern_atom(c, 0, strlen(net_wm_state), net_wm_state); xcb_intern_atom_reply_t* reply = xcb_intern_atom_reply(c, cookie, 0); @@ -139,11 +137,11 @@ void main_x11() xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(c, 0, strlen(net_wm_state_fullscreen), net_wm_state_fullscreen); xcb_intern_atom_reply_t* reply2 = xcb_intern_atom_reply(c, cookie2, 0); - xcb_change_property(c, XCB_PROP_MODE_REPLACE, window, reply->atom, XCB_ATOM_ATOM , 32, 1, (void*)&reply2->atom); + xcb_change_property(c, XCB_PROP_MODE_REPLACE, window, reply->atom, XCB_ATOM_ATOM, 32, 1, (void*)&reply2->atom); } - xcb_map_window (c, window); - xcb_flush (c); + xcb_map_window(c, window); + xcb_flush(c); main_loop(dpy, c, window, width, height); diff --git a/kmscube/cube.cpp b/kmscube/cube.cpp index 4129554..406bb8d 100644 --- a/kmscube/cube.cpp +++ b/kmscube/cube.cpp @@ -34,24 +34,21 @@ bool s_verbose; bool s_fullscreen; unsigned s_num_frames; -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { OptionSet optionset = { Option("v|verbose", - [&]() - { - s_verbose = true; - }), + [&]() { + s_verbose = true; + }), Option("f|fullscreen", - [&]() - { - s_fullscreen = true; - }), + [&]() { + s_fullscreen = true; + }), Option("n|numframes=", - [&](string s) - { - s_num_frames = stoi(s); - }), + [&](string s) { + s_num_frames = stoi(s); + }), }; optionset.parse(argc, argv); diff --git a/kmscube/cube.h b/kmscube/cube.h index 6368162..18ab0e0 100644 --- a/kmscube/cube.h +++ b/kmscube/cube.h @@ -8,4 +8,3 @@ void main_null(); void main_gbm(); void main_x11(); void main_wl(); - diff --git a/kmscube/esTransform.cpp b/kmscube/esTransform.cpp index 899c038..daa28ac 100644 --- a/kmscube/esTransform.cpp +++ b/kmscube/esTransform.cpp @@ -46,8 +46,7 @@ #define PI 3.1415926535897932384626433832795f -void -esScale(ESMatrix *result, GLfloat sx, GLfloat sy, GLfloat sz) +void esScale(ESMatrix* result, GLfloat sx, GLfloat sy, GLfloat sz) { result->m[0][0] *= sx; result->m[0][1] *= sx; @@ -65,8 +64,7 @@ esScale(ESMatrix *result, GLfloat sx, GLfloat sy, GLfloat sz) result->m[2][3] *= sz; } -void -esTranslate(ESMatrix *result, GLfloat tx, GLfloat ty, GLfloat tz) +void esTranslate(ESMatrix* result, GLfloat tx, GLfloat ty, GLfloat tz) { result->m[3][0] += (result->m[0][0] * tx + result->m[1][0] * ty + result->m[2][0] * tz); result->m[3][1] += (result->m[0][1] * tx + result->m[1][1] * ty + result->m[2][1] * tz); @@ -74,16 +72,14 @@ esTranslate(ESMatrix *result, GLfloat tx, GLfloat ty, GLfloat tz) result->m[3][3] += (result->m[0][3] * tx + result->m[1][3] * ty + result->m[2][3] * tz); } -void -esRotate(ESMatrix *result, GLfloat angle, GLfloat x, GLfloat y, GLfloat z) +void esRotate(ESMatrix* result, GLfloat angle, GLfloat x, GLfloat y, GLfloat z) { GLfloat sinAngle, cosAngle; GLfloat mag = sqrtf(x * x + y * y + z * z); - sinAngle = sinf ( angle * PI / 180.0f ); - cosAngle = cosf ( angle * PI / 180.0f ); - if ( mag > 0.0f ) - { + sinAngle = sinf(angle * PI / 180.0f); + cosAngle = cosf(angle * PI / 180.0f); + if (mag > 0.0f) { GLfloat xx, yy, zz, xy, yz, zx, xs, ys, zs; GLfloat oneMinusCos; ESMatrix rotMat; @@ -123,20 +119,19 @@ esRotate(ESMatrix *result, GLfloat angle, GLfloat x, GLfloat y, GLfloat z) rotMat.m[3][2] = 0.0F; rotMat.m[3][3] = 1.0F; - esMatrixMultiply( result, &rotMat, result ); + esMatrixMultiply(result, &rotMat, result); } } -void -esFrustum(ESMatrix *result, float left, float right, float bottom, float top, float nearZ, float farZ) +void esFrustum(ESMatrix* result, float left, float right, float bottom, float top, float nearZ, float farZ) { - float deltaX = right - left; - float deltaY = top - bottom; - float deltaZ = farZ - nearZ; - ESMatrix frust; + float deltaX = right - left; + float deltaY = top - bottom; + float deltaZ = farZ - nearZ; + ESMatrix frust; - if ( (nearZ <= 0.0f) || (farZ <= 0.0f) || - (deltaX <= 0.0f) || (deltaY <= 0.0f) || (deltaZ <= 0.0f) ) + if ((nearZ <= 0.0f) || (farZ <= 0.0f) || + (deltaX <= 0.0f) || (deltaY <= 0.0f) || (deltaZ <= 0.0f)) return; frust.m[0][0] = 2.0f * nearZ / deltaX; @@ -156,27 +151,24 @@ esFrustum(ESMatrix *result, float left, float right, float bottom, float top, fl esMatrixMultiply(result, &frust, result); } - -void -esPerspective(ESMatrix *result, float fovy, float aspect, float nearZ, float farZ) +void esPerspective(ESMatrix* result, float fovy, float aspect, float nearZ, float farZ) { GLfloat frustumW, frustumH; - frustumH = tanf( fovy / 360.0f * PI ) * nearZ; + frustumH = tanf(fovy / 360.0f * PI) * nearZ; frustumW = frustumH * aspect; - esFrustum( result, -frustumW, frustumW, -frustumH, frustumH, nearZ, farZ ); + esFrustum(result, -frustumW, frustumW, -frustumH, frustumH, nearZ, farZ); } -void -esOrtho(ESMatrix *result, float left, float right, float bottom, float top, float nearZ, float farZ) +void esOrtho(ESMatrix* result, float left, float right, float bottom, float top, float nearZ, float farZ) { - float deltaX = right - left; - float deltaY = top - bottom; - float deltaZ = farZ - nearZ; - ESMatrix ortho; + float deltaX = right - left; + float deltaY = top - bottom; + float deltaZ = farZ - nearZ; + ESMatrix ortho; - if ( (deltaX == 0.0f) || (deltaY == 0.0f) || (deltaZ == 0.0f) ) + if ((deltaX == 0.0f) || (deltaY == 0.0f) || (deltaZ == 0.0f)) return; esMatrixLoadIdentity(&ortho); @@ -190,41 +182,36 @@ esOrtho(ESMatrix *result, float left, float right, float bottom, float top, floa esMatrixMultiply(result, &ortho, result); } - -void -esMatrixMultiply(ESMatrix *result, ESMatrix *srcA, ESMatrix *srcB) +void esMatrixMultiply(ESMatrix* result, ESMatrix* srcA, ESMatrix* srcB) { - ESMatrix tmp; - int i; - - for (i=0; i<4; i++) - { - tmp.m[i][0] = (srcA->m[i][0] * srcB->m[0][0]) + - (srcA->m[i][1] * srcB->m[1][0]) + - (srcA->m[i][2] * srcB->m[2][0]) + - (srcA->m[i][3] * srcB->m[3][0]) ; - - tmp.m[i][1] = (srcA->m[i][0] * srcB->m[0][1]) + - (srcA->m[i][1] * srcB->m[1][1]) + - (srcA->m[i][2] * srcB->m[2][1]) + - (srcA->m[i][3] * srcB->m[3][1]) ; - - tmp.m[i][2] = (srcA->m[i][0] * srcB->m[0][2]) + - (srcA->m[i][1] * srcB->m[1][2]) + - (srcA->m[i][2] * srcB->m[2][2]) + - (srcA->m[i][3] * srcB->m[3][2]) ; - - tmp.m[i][3] = (srcA->m[i][0] * srcB->m[0][3]) + - (srcA->m[i][1] * srcB->m[1][3]) + - (srcA->m[i][2] * srcB->m[2][3]) + - (srcA->m[i][3] * srcB->m[3][3]) ; + ESMatrix tmp; + int i; + + for (i = 0; i < 4; i++) { + tmp.m[i][0] = (srcA->m[i][0] * srcB->m[0][0]) + + (srcA->m[i][1] * srcB->m[1][0]) + + (srcA->m[i][2] * srcB->m[2][0]) + + (srcA->m[i][3] * srcB->m[3][0]); + + tmp.m[i][1] = (srcA->m[i][0] * srcB->m[0][1]) + + (srcA->m[i][1] * srcB->m[1][1]) + + (srcA->m[i][2] * srcB->m[2][1]) + + (srcA->m[i][3] * srcB->m[3][1]); + + tmp.m[i][2] = (srcA->m[i][0] * srcB->m[0][2]) + + (srcA->m[i][1] * srcB->m[1][2]) + + (srcA->m[i][2] * srcB->m[2][2]) + + (srcA->m[i][3] * srcB->m[3][2]); + + tmp.m[i][3] = (srcA->m[i][0] * srcB->m[0][3]) + + (srcA->m[i][1] * srcB->m[1][3]) + + (srcA->m[i][2] * srcB->m[2][3]) + + (srcA->m[i][3] * srcB->m[3][3]); } memcpy(result, &tmp, sizeof(ESMatrix)); } - -void -esMatrixLoadIdentity(ESMatrix *result) +void esMatrixLoadIdentity(ESMatrix* result) { memset(result, 0x0, sizeof(ESMatrix)); result->m[0][0] = 1.0f; @@ -232,4 +219,3 @@ esMatrixLoadIdentity(ESMatrix *result) result->m[2][2] = 1.0f; result->m[3][3] = 1.0f; } - diff --git a/kmscube/esTransform.h b/kmscube/esTransform.h index c0383ab..f89e7b4 100644 --- a/kmscube/esTransform.h +++ b/kmscube/esTransform.h @@ -52,7 +52,7 @@ extern "C" { typedef struct { - GLfloat m[4][4]; + GLfloat m[4][4]; } ESMatrix; // @@ -60,14 +60,14 @@ typedef struct /// \param result Specifies the input matrix. Scaled matrix is returned in result. /// \param sx, sy, sz Scale factors along the x, y and z axes respectively // -void esScale(ESMatrix *result, GLfloat sx, GLfloat sy, GLfloat sz); +void esScale(ESMatrix* result, GLfloat sx, GLfloat sy, GLfloat sz); // /// \brief multiply matrix specified by result with a translation matrix and return new matrix in result /// \param result Specifies the input matrix. Translated matrix is returned in result. /// \param tx, ty, tz Scale factors along the x, y and z axes respectively // -void esTranslate(ESMatrix *result, GLfloat tx, GLfloat ty, GLfloat tz); +void esTranslate(ESMatrix* result, GLfloat tx, GLfloat ty, GLfloat tz); // /// \brief multiply matrix specified by result with a rotation matrix and return new matrix in result @@ -75,7 +75,7 @@ void esTranslate(ESMatrix *result, GLfloat tx, GLfloat ty, GLfloat tz); /// \param angle Specifies the angle of rotation, in degrees. /// \param x, y, z Specify the x, y and z coordinates of a vector, respectively // -void esRotate(ESMatrix *result, GLfloat angle, GLfloat x, GLfloat y, GLfloat z); +void esRotate(ESMatrix* result, GLfloat angle, GLfloat x, GLfloat y, GLfloat z); // // \brief multiply matrix specified by result with a perspective matrix and return new matrix in result @@ -84,7 +84,7 @@ void esRotate(ESMatrix *result, GLfloat angle, GLfloat x, GLfloat y, GLfloat z); /// \param bottom, top Coordinates for the bottom and top horizontal clipping planes /// \param nearZ, farZ Distances to the near and far depth clipping planes. Both distances must be positive. // -void esFrustum(ESMatrix *result, float left, float right, float bottom, float top, float nearZ, float farZ); +void esFrustum(ESMatrix* result, float left, float right, float bottom, float top, float nearZ, float farZ); // /// \brief multiply matrix specified by result with a perspective matrix and return new matrix in result @@ -94,7 +94,7 @@ void esFrustum(ESMatrix *result, float left, float right, float bottom, float to /// \param nearZ Near plane distance /// \param farZ Far plane distance // -void esPerspective(ESMatrix *result, float fovy, float aspect, float nearZ, float farZ); +void esPerspective(ESMatrix* result, float fovy, float aspect, float nearZ, float farZ); // /// \brief multiply matrix specified by result with a perspective matrix and return new matrix in result @@ -103,20 +103,20 @@ void esPerspective(ESMatrix *result, float fovy, float aspect, float nearZ, floa /// \param bottom, top Coordinates for the bottom and top horizontal clipping planes /// \param nearZ, farZ Distances to the near and far depth clipping planes. These values are negative if plane is behind the viewer // -void esOrtho(ESMatrix *result, float left, float right, float bottom, float top, float nearZ, float farZ); +void esOrtho(ESMatrix* result, float left, float right, float bottom, float top, float nearZ, float farZ); // /// \brief perform the following operation - result matrix = srcA matrix * srcB matrix /// \param result Returns multiplied matrix /// \param srcA, srcB Input matrices to be multiplied // -void esMatrixMultiply(ESMatrix *result, ESMatrix *srcA, ESMatrix *srcB); +void esMatrixMultiply(ESMatrix* result, ESMatrix* srcA, ESMatrix* srcB); // //// \brief return an indentity matrix //// \param result returns identity matrix // -void esMatrixLoadIdentity(ESMatrix *result); +void esMatrixLoadIdentity(ESMatrix* result); #ifdef __cplusplus } diff --git a/py/pykms/pykms.cpp b/py/pykms/pykms.cpp index fec8417..b91a1a9 100644 --- a/py/pykms/pykms.cpp +++ b/py/pykms/pykms.cpp @@ -7,15 +7,16 @@ namespace py = pybind11; using namespace kms; using namespace std; -void init_pykmstest(py::module &m); -void init_pykmsbase(py::module &m); -void init_pyvid(py::module &m); +void init_pykmstest(py::module& m); +void init_pykmsbase(py::module& m); +void init_pyvid(py::module& m); #if HAS_LIBDRM_OMAP -void init_pykmsomap(py::module &m); +void init_pykmsomap(py::module& m); #endif -PYBIND11_MODULE(pykms, m) { +PYBIND11_MODULE(pykms, m) +{ init_pykmsbase(m); init_pykmstest(m); diff --git a/py/pykms/pykmsbase.cpp b/py/pykms/pykmsbase.cpp index 6ed82a0..43c2dfd 100644 --- a/py/pykms/pykmsbase.cpp +++ b/py/pykms/pykmsbase.cpp @@ -17,275 +17,262 @@ static vector<unique_ptr<T, py::nodelete>> convert_vector(const vector<T*>& sour return v; } -void init_pykmsbase(py::module &m) +void init_pykmsbase(py::module& m) { py::class_<Card>(m, "Card") - .def(py::init<>()) - .def(py::init<const string&>()) - .def(py::init<const string&, uint32_t>()) - .def_property_readonly("fd", &Card::fd) - .def_property_readonly("minor", &Card::dev_minor) - .def_property_readonly("get_first_connected_connector", &Card::get_first_connected_connector) - - // XXX pybind11 can't handle vector<T*> where T is non-copyable, and complains: - // RuntimeError: return_value_policy = move, but the object is neither movable nor copyable! - // So we do this manually. - .def_property_readonly("connectors", [](Card* self) { - return convert_vector(self->get_connectors()); - }) - - .def_property_readonly("crtcs", [](Card* self) { - return convert_vector(self->get_crtcs()); - }) - - .def_property_readonly("encoders", [](Card* self) { - return convert_vector(self->get_encoders()); - }) - - .def_property_readonly("planes", [](Card* self) { - return convert_vector(self->get_planes()); - }) - - .def_property_readonly("has_atomic", &Card::has_atomic) - .def("get_prop", (Property* (Card::*)(uint32_t) const)&Card::get_prop) - - .def_property_readonly("version_name", &Card::version_name); - ; + .def(py::init<>()) + .def(py::init<const string&>()) + .def(py::init<const string&, uint32_t>()) + .def_property_readonly("fd", &Card::fd) + .def_property_readonly("minor", &Card::dev_minor) + .def_property_readonly("get_first_connected_connector", &Card::get_first_connected_connector) + + // XXX pybind11 can't handle vector<T*> where T is non-copyable, and complains: + // RuntimeError: return_value_policy = move, but the object is neither movable nor copyable! + // So we do this manually. + .def_property_readonly("connectors", [](Card* self) { + return convert_vector(self->get_connectors()); + }) + + .def_property_readonly("crtcs", [](Card* self) { + return convert_vector(self->get_crtcs()); + }) + + .def_property_readonly("encoders", [](Card* self) { + return convert_vector(self->get_encoders()); + }) + + .def_property_readonly("planes", [](Card* self) { + return convert_vector(self->get_planes()); + }) + + .def_property_readonly("has_atomic", &Card::has_atomic) + .def("get_prop", (Property * (Card::*)(uint32_t) const) & Card::get_prop) + + .def_property_readonly("version_name", &Card::version_name); + ; py::class_<DrmObject, unique_ptr<DrmObject, py::nodelete>>(m, "DrmObject") - .def_property_readonly("id", &DrmObject::id) - .def_property_readonly("idx", &DrmObject::idx) - .def_property_readonly("card", &DrmObject::card) - ; + .def_property_readonly("id", &DrmObject::id) + .def_property_readonly("idx", &DrmObject::idx) + .def_property_readonly("card", &DrmObject::card); py::class_<DrmPropObject, DrmObject, unique_ptr<DrmPropObject, py::nodelete>>(m, "DrmPropObject") - .def("refresh_props", &DrmPropObject::refresh_props) - .def_property_readonly("prop_map", &DrmPropObject::get_prop_map) - .def("get_prop_value", (uint64_t (DrmPropObject::*)(const string&) const)&DrmPropObject::get_prop_value) - .def("set_prop_value",(int (DrmPropObject::*)(const string&, uint64_t)) &DrmPropObject::set_prop_value) - .def("get_prop_value_as_blob", &DrmPropObject::get_prop_value_as_blob) - .def("get_prop", &DrmPropObject::get_prop) - .def("has_prop", &DrmPropObject::has_prop) - ; + .def("refresh_props", &DrmPropObject::refresh_props) + .def_property_readonly("prop_map", &DrmPropObject::get_prop_map) + .def("get_prop_value", (uint64_t(DrmPropObject::*)(const string&) const) & DrmPropObject::get_prop_value) + .def("set_prop_value", (int (DrmPropObject::*)(const string&, uint64_t)) & DrmPropObject::set_prop_value) + .def("get_prop_value_as_blob", &DrmPropObject::get_prop_value_as_blob) + .def("get_prop", &DrmPropObject::get_prop) + .def("has_prop", &DrmPropObject::has_prop); py::class_<Connector, DrmPropObject, unique_ptr<Connector, py::nodelete>>(m, "Connector") - .def_property_readonly("fullname", &Connector::fullname) - .def("get_default_mode", &Connector::get_default_mode) - .def("get_current_crtc", &Connector::get_current_crtc) - .def("get_possible_crtcs", [](Connector* self) { - return convert_vector(self->get_possible_crtcs()); - }) - .def("get_modes", &Connector::get_modes) - .def("get_mode", (Videomode (Connector::*)(const string& mode) const)&Connector::get_mode) - .def("get_mode", (Videomode (Connector::*)(unsigned xres, unsigned yres, float refresh, bool ilace) const)&Connector::get_mode) - .def("connected", &Connector::connected) - .def("__repr__", [](const Connector& o) { return "<pykms.Connector " + to_string(o.id()) + ">"; }) - .def("refresh", &Connector::refresh) - ; + .def_property_readonly("fullname", &Connector::fullname) + .def("get_default_mode", &Connector::get_default_mode) + .def("get_current_crtc", &Connector::get_current_crtc) + .def("get_possible_crtcs", [](Connector* self) { + return convert_vector(self->get_possible_crtcs()); + }) + .def("get_modes", &Connector::get_modes) + .def("get_mode", (Videomode(Connector::*)(const string& mode) const) & Connector::get_mode) + .def("get_mode", (Videomode(Connector::*)(unsigned xres, unsigned yres, float refresh, bool ilace) const) & Connector::get_mode) + .def("connected", &Connector::connected) + .def("__repr__", [](const Connector& o) { return "<pykms.Connector " + to_string(o.id()) + ">"; }) + .def("refresh", &Connector::refresh); py::class_<Crtc, DrmPropObject, unique_ptr<Crtc, py::nodelete>>(m, "Crtc") - .def("set_mode", (int (Crtc::*)(Connector*, const Videomode&))&Crtc::set_mode) - .def("set_mode", (int (Crtc::*)(Connector*, Framebuffer&, const Videomode&))&Crtc::set_mode) - .def("disable_mode", &Crtc::disable_mode) - .def("page_flip", - [](Crtc* self, Framebuffer& fb, uint32_t data) - { - self->page_flip(fb, (void*)(intptr_t)data); - }, py::arg("fb"), py::arg("data") = 0) - .def("set_plane", &Crtc::set_plane) - .def_property_readonly("possible_planes", &Crtc::get_possible_planes) - .def_property_readonly("primary_plane", &Crtc::get_primary_plane) - .def_property_readonly("mode", &Crtc::mode) - .def_property_readonly("mode_valid", &Crtc::mode_valid) - .def("__repr__", [](const Crtc& o) { return "<pykms.Crtc " + to_string(o.id()) + ">"; }) - .def("refresh", &Crtc::refresh) - ; + .def("set_mode", (int (Crtc::*)(Connector*, const Videomode&)) & Crtc::set_mode) + .def("set_mode", (int (Crtc::*)(Connector*, Framebuffer&, const Videomode&)) & Crtc::set_mode) + .def("disable_mode", &Crtc::disable_mode) + .def( + "page_flip", + [](Crtc* self, Framebuffer& fb, uint32_t data) { + self->page_flip(fb, (void*)(intptr_t)data); + }, + py::arg("fb"), py::arg("data") = 0) + .def("set_plane", &Crtc::set_plane) + .def_property_readonly("possible_planes", &Crtc::get_possible_planes) + .def_property_readonly("primary_plane", &Crtc::get_primary_plane) + .def_property_readonly("mode", &Crtc::mode) + .def_property_readonly("mode_valid", &Crtc::mode_valid) + .def("__repr__", [](const Crtc& o) { return "<pykms.Crtc " + to_string(o.id()) + ">"; }) + .def("refresh", &Crtc::refresh); py::class_<Encoder, DrmPropObject, unique_ptr<Encoder, py::nodelete>>(m, "Encoder") - .def("refresh", &Encoder::refresh) - ; + .def("refresh", &Encoder::refresh); py::class_<Plane, DrmPropObject, unique_ptr<Plane, py::nodelete>>(m, "Plane") - .def("supports_crtc", &Plane::supports_crtc) - .def_property_readonly("formats", &Plane::get_formats) - .def_property_readonly("plane_type", &Plane::plane_type) - .def("__repr__", [](const Plane& o) { return "<pykms.Plane " + to_string(o.id()) + ">"; }) - ; + .def("supports_crtc", &Plane::supports_crtc) + .def_property_readonly("formats", &Plane::get_formats) + .def_property_readonly("plane_type", &Plane::plane_type) + .def("__repr__", [](const Plane& o) { return "<pykms.Plane " + to_string(o.id()) + ">"; }); py::enum_<PlaneType>(m, "PlaneType") - .value("Overlay", PlaneType::Overlay) - .value("Primary", PlaneType::Primary) - .value("Cursor", PlaneType::Cursor) - ; + .value("Overlay", PlaneType::Overlay) + .value("Primary", PlaneType::Primary) + .value("Cursor", PlaneType::Cursor); py::class_<Property, DrmObject, unique_ptr<Property, py::nodelete>>(m, "Property") - .def_property_readonly("name", &Property::name) - .def_property_readonly("enums", &Property::get_enums) - ; + .def_property_readonly("name", &Property::name) + .def_property_readonly("enums", &Property::get_enums); py::class_<Blob>(m, "Blob") - .def(py::init([](Card& card, py::buffer buf) { - py::buffer_info info = buf.request(); - if (info.ndim != 1) - throw std::runtime_error("Incompatible buffer dimension!"); - - return new Blob(card, info.ptr, info.size * info.itemsize); - }), - py::keep_alive<1, 2>()) // Keep Card alive until this is destructed - - .def_property_readonly("data", &Blob::data) - - // XXX pybind11 doesn't support a base object (DrmObject) with custom holder-type, - // and a subclass with standard holder-type. - // So we just copy the DrmObject members here. - // Note that this means that python thinks we don't derive from DrmObject - .def_property_readonly("id", &DrmObject::id) - .def_property_readonly("idx", &DrmObject::idx) - .def_property_readonly("card", &DrmObject::card) - ; + .def(py::init([](Card& card, py::buffer buf) { + py::buffer_info info = buf.request(); + if (info.ndim != 1) + throw std::runtime_error("Incompatible buffer dimension!"); + + return new Blob(card, info.ptr, info.size * info.itemsize); + }), + py::keep_alive<1, 2>()) // Keep Card alive until this is destructed + + .def_property_readonly("data", &Blob::data) + + // XXX pybind11 doesn't support a base object (DrmObject) with custom holder-type, + // and a subclass with standard holder-type. + // So we just copy the DrmObject members here. + // Note that this means that python thinks we don't derive from DrmObject + .def_property_readonly("id", &DrmObject::id) + .def_property_readonly("idx", &DrmObject::idx) + .def_property_readonly("card", &DrmObject::card); py::class_<Framebuffer>(m, "Framebuffer") - .def_property_readonly("width", &Framebuffer::width) - .def_property_readonly("height", &Framebuffer::height) - .def_property_readonly("format", &Framebuffer::format) - .def_property_readonly("num_planes", &Framebuffer::num_planes) - .def("stride", &Framebuffer::stride) - .def("size", &Framebuffer::size) - .def("offset", &Framebuffer::offset) - .def("fd", &Framebuffer::prime_fd) - - // XXX pybind11 doesn't support a base object (DrmObject) with custom holder-type, - // and a subclass with standard holder-type. - // So we just copy the DrmObject members here. - // Note that this means that python thinks we don't derive from DrmObject - .def_property_readonly("id", &DrmObject::id) - .def_property_readonly("idx", &DrmObject::idx) - .def_property_readonly("card", &DrmObject::card) - ; + .def_property_readonly("width", &Framebuffer::width) + .def_property_readonly("height", &Framebuffer::height) + .def_property_readonly("format", &Framebuffer::format) + .def_property_readonly("num_planes", &Framebuffer::num_planes) + .def("stride", &Framebuffer::stride) + .def("size", &Framebuffer::size) + .def("offset", &Framebuffer::offset) + .def("fd", &Framebuffer::prime_fd) + + // XXX pybind11 doesn't support a base object (DrmObject) with custom holder-type, + // and a subclass with standard holder-type. + // So we just copy the DrmObject members here. + // Note that this means that python thinks we don't derive from DrmObject + .def_property_readonly("id", &DrmObject::id) + .def_property_readonly("idx", &DrmObject::idx) + .def_property_readonly("card", &DrmObject::card); py::class_<DumbFramebuffer, Framebuffer>(m, "DumbFramebuffer") - .def(py::init<Card&, uint32_t, uint32_t, const string&>(), - py::keep_alive<1, 2>()) // Keep Card alive until this is destructed - .def(py::init<Card&, uint32_t, uint32_t, PixelFormat>(), - py::keep_alive<1, 2>()) // Keep Card alive until this is destructed - ; + .def(py::init<Card&, uint32_t, uint32_t, const string&>(), + py::keep_alive<1, 2>()) // Keep Card alive until this is destructed + .def(py::init<Card&, uint32_t, uint32_t, PixelFormat>(), + py::keep_alive<1, 2>()) // Keep Card alive until this is destructed + ; py::class_<DmabufFramebuffer, Framebuffer>(m, "DmabufFramebuffer") - .def(py::init<Card&, uint32_t, uint32_t, const string&, vector<int>, vector<uint32_t>, vector<uint32_t>>(), - py::keep_alive<1, 2>()) // Keep Card alive until this is destructed - .def(py::init<Card&, uint32_t, uint32_t, PixelFormat, vector<int>, vector<uint32_t>, vector<uint32_t>>(), - py::keep_alive<1, 2>()) // Keep Card alive until this is destructed - ; + .def(py::init<Card&, uint32_t, uint32_t, const string&, vector<int>, vector<uint32_t>, vector<uint32_t>>(), + py::keep_alive<1, 2>()) // Keep Card alive until this is destructed + .def(py::init<Card&, uint32_t, uint32_t, PixelFormat, vector<int>, vector<uint32_t>, vector<uint32_t>>(), + py::keep_alive<1, 2>()) // Keep Card alive until this is destructed + ; py::enum_<PixelFormat>(m, "PixelFormat") - .value("Undefined", PixelFormat::Undefined) + .value("Undefined", PixelFormat::Undefined) - .value("NV12", PixelFormat::NV12) - .value("NV21", PixelFormat::NV21) - .value("NV16", PixelFormat::NV16) - .value("NV61", PixelFormat::NV61) + .value("NV12", PixelFormat::NV12) + .value("NV21", PixelFormat::NV21) + .value("NV16", PixelFormat::NV16) + .value("NV61", PixelFormat::NV61) - .value("YUV420", PixelFormat::YUV420) - .value("YVU420", PixelFormat::YVU420) - .value("YUV422", PixelFormat::YUV422) - .value("YVU422", PixelFormat::YVU422) - .value("YUV444", PixelFormat::YUV444) - .value("YVU444", PixelFormat::YVU444) + .value("YUV420", PixelFormat::YUV420) + .value("YVU420", PixelFormat::YVU420) + .value("YUV422", PixelFormat::YUV422) + .value("YVU422", PixelFormat::YVU422) + .value("YUV444", PixelFormat::YUV444) + .value("YVU444", PixelFormat::YVU444) - .value("UYVY", PixelFormat::UYVY) - .value("YUYV", PixelFormat::YUYV) - .value("YVYU", PixelFormat::YVYU) - .value("VYUY", PixelFormat::VYUY) + .value("UYVY", PixelFormat::UYVY) + .value("YUYV", PixelFormat::YUYV) + .value("YVYU", PixelFormat::YVYU) + .value("VYUY", PixelFormat::VYUY) - .value("XRGB8888", PixelFormat::XRGB8888) - .value("XBGR8888", PixelFormat::XBGR8888) - .value("RGBX8888", PixelFormat::RGBX8888) - .value("BGRX8888", PixelFormat::BGRX8888) + .value("XRGB8888", PixelFormat::XRGB8888) + .value("XBGR8888", PixelFormat::XBGR8888) + .value("RGBX8888", PixelFormat::RGBX8888) + .value("BGRX8888", PixelFormat::BGRX8888) - .value("ARGB8888", PixelFormat::ARGB8888) - .value("ABGR8888", PixelFormat::ABGR8888) - .value("RGBA8888", PixelFormat::RGBA8888) - .value("BGRA8888", PixelFormat::BGRA8888) + .value("ARGB8888", PixelFormat::ARGB8888) + .value("ABGR8888", PixelFormat::ABGR8888) + .value("RGBA8888", PixelFormat::RGBA8888) + .value("BGRA8888", PixelFormat::BGRA8888) - .value("RGB888", PixelFormat::RGB888) - .value("BGR888", PixelFormat::BGR888) + .value("RGB888", PixelFormat::RGB888) + .value("BGR888", PixelFormat::BGR888) - .value("RGB332", PixelFormat::RGB332) + .value("RGB332", PixelFormat::RGB332) - .value("RGB565", PixelFormat::RGB565) - .value("BGR565", PixelFormat::BGR565) + .value("RGB565", PixelFormat::RGB565) + .value("BGR565", PixelFormat::BGR565) - .value("XRGB4444", PixelFormat::XRGB4444) - .value("XRGB1555", PixelFormat::XRGB1555) + .value("XRGB4444", PixelFormat::XRGB4444) + .value("XRGB1555", PixelFormat::XRGB1555) - .value("ARGB4444", PixelFormat::ARGB4444) - .value("ARGB1555", PixelFormat::ARGB1555) + .value("ARGB4444", PixelFormat::ARGB4444) + .value("ARGB1555", PixelFormat::ARGB1555) - .value("XRGB2101010", PixelFormat::XRGB2101010) - .value("XBGR2101010", PixelFormat::XBGR2101010) - .value("RGBX1010102", PixelFormat::RGBX1010102) - .value("BGRX1010102", PixelFormat::BGRX1010102) + .value("XRGB2101010", PixelFormat::XRGB2101010) + .value("XBGR2101010", PixelFormat::XBGR2101010) + .value("RGBX1010102", PixelFormat::RGBX1010102) + .value("BGRX1010102", PixelFormat::BGRX1010102) - .value("ARGB2101010", PixelFormat::ARGB2101010) - .value("ABGR2101010", PixelFormat::ABGR2101010) - .value("RGBA1010102", PixelFormat::RGBA1010102) - .value("BGRA1010102", PixelFormat::BGRA1010102) - ; + .value("ARGB2101010", PixelFormat::ARGB2101010) + .value("ABGR2101010", PixelFormat::ABGR2101010) + .value("RGBA1010102", PixelFormat::RGBA1010102) + .value("BGRA1010102", PixelFormat::BGRA1010102); py::enum_<SyncPolarity>(m, "SyncPolarity") - .value("Undefined", SyncPolarity::Undefined) - .value("Positive", SyncPolarity::Positive) - .value("Negative", SyncPolarity::Negative) - ; + .value("Undefined", SyncPolarity::Undefined) + .value("Positive", SyncPolarity::Positive) + .value("Negative", SyncPolarity::Negative); py::class_<Videomode>(m, "Videomode") - .def(py::init<>()) - - .def_readwrite("name", &Videomode::name) + .def(py::init<>()) - .def_readwrite("clock", &Videomode::clock) + .def_readwrite("name", &Videomode::name) - .def_readwrite("hdisplay", &Videomode::hdisplay) - .def_readwrite("hsync_start", &Videomode::hsync_start) - .def_readwrite("hsync_end", &Videomode::hsync_end) - .def_readwrite("htotal", &Videomode::htotal) + .def_readwrite("clock", &Videomode::clock) - .def_readwrite("vdisplay", &Videomode::vdisplay) - .def_readwrite("vsync_start", &Videomode::vsync_start) - .def_readwrite("vsync_end", &Videomode::vsync_end) - .def_readwrite("vtotal", &Videomode::vtotal) + .def_readwrite("hdisplay", &Videomode::hdisplay) + .def_readwrite("hsync_start", &Videomode::hsync_start) + .def_readwrite("hsync_end", &Videomode::hsync_end) + .def_readwrite("htotal", &Videomode::htotal) - .def_readwrite("vrefresh", &Videomode::vrefresh) + .def_readwrite("vdisplay", &Videomode::vdisplay) + .def_readwrite("vsync_start", &Videomode::vsync_start) + .def_readwrite("vsync_end", &Videomode::vsync_end) + .def_readwrite("vtotal", &Videomode::vtotal) - .def_readwrite("flags", &Videomode::flags) - .def_readwrite("type", &Videomode::type) + .def_readwrite("vrefresh", &Videomode::vrefresh) - .def("__repr__", [](const Videomode& vm) { return "<pykms.Videomode " + to_string(vm.hdisplay) + "x" + to_string(vm.vdisplay) + ">"; }) + .def_readwrite("flags", &Videomode::flags) + .def_readwrite("type", &Videomode::type) - .def("to_blob", &Videomode::to_blob) + .def("__repr__", [](const Videomode& vm) { return "<pykms.Videomode " + to_string(vm.hdisplay) + "x" + to_string(vm.vdisplay) + ">"; }) - .def_property("hsync", &Videomode::hsync, &Videomode::set_hsync) - .def_property("vsync", &Videomode::vsync, &Videomode::set_vsync) + .def("to_blob", &Videomode::to_blob) - .def("to_string_short", &Videomode::to_string_short) - .def("to_string_long", &Videomode::to_string_long) - ; + .def_property("hsync", &Videomode::hsync, &Videomode::set_hsync) + .def_property("vsync", &Videomode::vsync, &Videomode::set_vsync) + .def("to_string_short", &Videomode::to_string_short) + .def("to_string_long", &Videomode::to_string_long); m.def("videomode_from_timings", &videomode_from_timings); py::class_<AtomicReq>(m, "AtomicReq") - .def(py::init<Card&>(), - py::keep_alive<1, 2>()) // Keep Card alive until this is destructed - .def("add", (void (AtomicReq::*)(DrmPropObject*, const string&, uint64_t)) &AtomicReq::add) - .def("add", (void (AtomicReq::*)(DrmPropObject*, Property*, uint64_t)) &AtomicReq::add) - .def("add", (void (AtomicReq::*)(DrmPropObject*, const map<string, uint64_t>&)) &AtomicReq::add) - .def("test", &AtomicReq::test, py::arg("allow_modeset") = false) - .def("commit", - [](AtomicReq* self, uint32_t data, bool allow) - { - return self->commit((void*)(intptr_t)data, allow); - }, py::arg("data") = 0, py::arg("allow_modeset") = false) - .def("commit_sync", &AtomicReq::commit_sync, py::arg("allow_modeset") = false) - ; + .def(py::init<Card&>(), + py::keep_alive<1, 2>()) // Keep Card alive until this is destructed + .def("add", (void (AtomicReq::*)(DrmPropObject*, const string&, uint64_t)) & AtomicReq::add) + .def("add", (void (AtomicReq::*)(DrmPropObject*, Property*, uint64_t)) & AtomicReq::add) + .def("add", (void (AtomicReq::*)(DrmPropObject*, const map<string, uint64_t>&)) & AtomicReq::add) + .def("test", &AtomicReq::test, py::arg("allow_modeset") = false) + .def( + "commit", + [](AtomicReq* self, uint32_t data, bool allow) { + return self->commit((void*)(intptr_t)data, allow); + }, + py::arg("data") = 0, py::arg("allow_modeset") = false) + .def("commit_sync", &AtomicReq::commit_sync, py::arg("allow_modeset") = false); } diff --git a/py/pykms/pykmsomap.cpp b/py/pykms/pykmsomap.cpp index 4fc7084..eb01f47 100644 --- a/py/pykms/pykmsomap.cpp +++ b/py/pykms/pykmsomap.cpp @@ -8,35 +8,32 @@ namespace py = pybind11; using namespace kms; using namespace std; -void init_pykmsomap(py::module &m) +void init_pykmsomap(py::module& m) { py::class_<OmapCard, Card>(m, "OmapCard") - .def(py::init<>()) - ; + .def(py::init<>()); py::class_<OmapFramebuffer, Framebuffer> omapfb(m, "OmapFramebuffer"); // XXX we should use py::arithmetic() here to support or and and operators, but it's not supported in the pybind11 we use py::enum_<OmapFramebuffer::Flags>(omapfb, "Flags") - .value("None", OmapFramebuffer::Flags::None) - .value("Tiled", OmapFramebuffer::Flags::Tiled) - .value("MemContig", OmapFramebuffer::Flags::MemContig) - .value("MemTiler", OmapFramebuffer::Flags::MemTiler) - .value("MemPin", OmapFramebuffer::Flags::MemPin) - .export_values() - ; + .value("None", OmapFramebuffer::Flags::None) + .value("Tiled", OmapFramebuffer::Flags::Tiled) + .value("MemContig", OmapFramebuffer::Flags::MemContig) + .value("MemTiler", OmapFramebuffer::Flags::MemTiler) + .value("MemPin", OmapFramebuffer::Flags::MemPin) + .export_values(); omapfb - .def(py::init<OmapCard&, uint32_t, uint32_t, const string&, OmapFramebuffer::Flags>(), - py::keep_alive<1, 2>(), // Keep Card alive until this is destructed - py::arg("card"), py::arg("width"), py::arg("height"), py::arg("fourcc"), py::arg("flags") = OmapFramebuffer::None) - .def(py::init<OmapCard&, uint32_t, uint32_t, PixelFormat, OmapFramebuffer::Flags>(), - py::keep_alive<1, 2>(), // Keep OmapCard alive until this is destructed - py::arg("card"), py::arg("width"), py::arg("height"), py::arg("pixfmt"), py::arg("flags") = OmapFramebuffer::None) - .def_property_readonly("format", &OmapFramebuffer::format) - .def_property_readonly("num_planes", &OmapFramebuffer::num_planes) - .def("fd", &OmapFramebuffer::prime_fd) - .def("stride", &OmapFramebuffer::stride) - .def("offset", &OmapFramebuffer::offset) - ; + .def(py::init<OmapCard&, uint32_t, uint32_t, const string&, OmapFramebuffer::Flags>(), + py::keep_alive<1, 2>(), // Keep Card alive until this is destructed + py::arg("card"), py::arg("width"), py::arg("height"), py::arg("fourcc"), py::arg("flags") = OmapFramebuffer::None) + .def(py::init<OmapCard&, uint32_t, uint32_t, PixelFormat, OmapFramebuffer::Flags>(), + py::keep_alive<1, 2>(), // Keep OmapCard alive until this is destructed + py::arg("card"), py::arg("width"), py::arg("height"), py::arg("pixfmt"), py::arg("flags") = OmapFramebuffer::None) + .def_property_readonly("format", &OmapFramebuffer::format) + .def_property_readonly("num_planes", &OmapFramebuffer::num_planes) + .def("fd", &OmapFramebuffer::prime_fd) + .def("stride", &OmapFramebuffer::stride) + .def("offset", &OmapFramebuffer::offset); } diff --git a/py/pykms/pykmsutil.cpp b/py/pykms/pykmsutil.cpp index d5d7fde..666cbdc 100644 --- a/py/pykms/pykmsutil.cpp +++ b/py/pykms/pykmsutil.cpp @@ -8,58 +8,55 @@ namespace py = pybind11; using namespace kms; using namespace std; -void init_pykmstest(py::module &m) +void init_pykmstest(py::module& m) { py::class_<RGB>(m, "RGB") - .def(py::init<>()) - .def(py::init<uint8_t, uint8_t, uint8_t&>()) - .def(py::init<uint8_t, uint8_t, uint8_t, uint8_t&>()) - .def_property_readonly("rgb888", &RGB::rgb888) - .def_property_readonly("argb8888", &RGB::argb8888) - .def_property_readonly("abgr8888", &RGB::abgr8888) - .def_property_readonly("rgb565", &RGB::rgb565) - ; + .def(py::init<>()) + .def(py::init<uint8_t, uint8_t, uint8_t&>()) + .def(py::init<uint8_t, uint8_t, uint8_t, uint8_t&>()) + .def_property_readonly("rgb888", &RGB::rgb888) + .def_property_readonly("argb8888", &RGB::argb8888) + .def_property_readonly("abgr8888", &RGB::abgr8888) + .def_property_readonly("rgb565", &RGB::rgb565); py::class_<ResourceManager>(m, "ResourceManager") - .def(py::init<Card&>()) - .def("reset", &ResourceManager::reset) - .def("reserve_connector", (Connector* (ResourceManager::*)(const string& name))&ResourceManager::reserve_connector, - py::arg("name") = string()) - .def("reserve_crtc", (Crtc* (ResourceManager::*)(Connector*))&ResourceManager::reserve_crtc) - .def("reserve_plane", (Plane* (ResourceManager::*)(Crtc*, PlaneType, PixelFormat))&ResourceManager::reserve_plane, - py::arg("crtc"), - py::arg("type"), - py::arg("format") = PixelFormat::Undefined) - .def("reserve_generic_plane", &ResourceManager::reserve_generic_plane, - py::arg("crtc"), - py::arg("format") = PixelFormat::Undefined) - .def("reserve_primary_plane", &ResourceManager::reserve_primary_plane, - py::arg("crtc"), - py::arg("format") = PixelFormat::Undefined) - .def("reserve_overlay_plane", &ResourceManager::reserve_overlay_plane, - py::arg("crtc"), - py::arg("format") = PixelFormat::Undefined) - ; + .def(py::init<Card&>()) + .def("reset", &ResourceManager::reset) + .def("reserve_connector", (Connector * (ResourceManager::*)(const string& name)) & ResourceManager::reserve_connector, + py::arg("name") = string()) + .def("reserve_crtc", (Crtc * (ResourceManager::*)(Connector*)) & ResourceManager::reserve_crtc) + .def("reserve_plane", (Plane * (ResourceManager::*)(Crtc*, PlaneType, PixelFormat)) & ResourceManager::reserve_plane, + py::arg("crtc"), + py::arg("type"), + py::arg("format") = PixelFormat::Undefined) + .def("reserve_generic_plane", &ResourceManager::reserve_generic_plane, + py::arg("crtc"), + py::arg("format") = PixelFormat::Undefined) + .def("reserve_primary_plane", &ResourceManager::reserve_primary_plane, + py::arg("crtc"), + py::arg("format") = PixelFormat::Undefined) + .def("reserve_overlay_plane", &ResourceManager::reserve_overlay_plane, + py::arg("crtc"), + py::arg("format") = PixelFormat::Undefined); py::enum_<YUVType>(m, "YUVType") - .value("BT601_Lim", YUVType::BT601_Lim) - .value("BT601_Full", YUVType::BT601_Full) - .value("BT709_Lim", YUVType::BT709_Lim) - .value("BT709_Full", YUVType::BT709_Full) - ; + .value("BT601_Lim", YUVType::BT601_Lim) + .value("BT601_Full", YUVType::BT601_Full) + .value("BT709_Lim", YUVType::BT709_Lim) + .value("BT709_Full", YUVType::BT709_Full); // Use lambdas to handle IFramebuffer - m.def("draw_test_pattern", [](Framebuffer& fb, YUVType yuvt) { draw_test_pattern(fb, yuvt); }, - py::arg("fb"), - py::arg("yuvt") = YUVType::BT601_Lim); + m.def( + "draw_test_pattern", [](Framebuffer& fb, YUVType yuvt) { draw_test_pattern(fb, yuvt); }, + py::arg("fb"), + py::arg("yuvt") = YUVType::BT601_Lim); m.def("draw_color_bar", [](Framebuffer& fb, int old_xpos, int xpos, int width) { draw_color_bar(fb, old_xpos, xpos, width); - } ); + }); m.def("draw_rect", [](Framebuffer& fb, uint32_t x, uint32_t y, uint32_t w, uint32_t h, RGB color) { draw_rect(fb, x, y, w, h, color); - } ); + }); m.def("draw_circle", [](Framebuffer& fb, int32_t xCenter, int32_t yCenter, int32_t radius, RGB color) { draw_circle(fb, xCenter, yCenter, radius, color); - } ); - m.def("draw_text", [](Framebuffer& fb, uint32_t x, uint32_t y, const string& str, RGB color) { - draw_text(fb, x, y, str, color); } ); + }); + m.def("draw_text", [](Framebuffer& fb, uint32_t x, uint32_t y, const string& str, RGB color) { draw_text(fb, x, y, str, color); }); } diff --git a/py/pykms/pyvid.cpp b/py/pykms/pyvid.cpp index 8b0450a..54ad480 100644 --- a/py/pykms/pyvid.cpp +++ b/py/pykms/pyvid.cpp @@ -9,40 +9,38 @@ namespace py = pybind11; using namespace kms; using namespace std; -void init_pyvid(py::module &m) +void init_pyvid(py::module& m) { py::class_<VideoDevice>(m, "VideoDevice") - .def(py::init<const string&>()) - .def_property_readonly("fd", &VideoDevice::fd) - .def_property_readonly("has_capture", &VideoDevice::has_capture) - .def_property_readonly("has_output", &VideoDevice::has_output) - .def_property_readonly("has_m2m", &VideoDevice::has_m2m) - .def_property_readonly("capture_streamer", &VideoDevice::get_capture_streamer) - .def_property_readonly("output_streamer", &VideoDevice::get_output_streamer) - .def_property_readonly("discrete_frame_sizes", &VideoDevice::get_discrete_frame_sizes) - .def_property_readonly("frame_sizes", &VideoDevice::get_frame_sizes) - .def("get_capture_devices", &VideoDevice::get_capture_devices) - ; + .def(py::init<const string&>()) + .def_property_readonly("fd", &VideoDevice::fd) + .def_property_readonly("has_capture", &VideoDevice::has_capture) + .def_property_readonly("has_output", &VideoDevice::has_output) + .def_property_readonly("has_m2m", &VideoDevice::has_m2m) + .def_property_readonly("capture_streamer", &VideoDevice::get_capture_streamer) + .def_property_readonly("output_streamer", &VideoDevice::get_output_streamer) + .def_property_readonly("discrete_frame_sizes", &VideoDevice::get_discrete_frame_sizes) + .def_property_readonly("frame_sizes", &VideoDevice::get_frame_sizes) + .def("get_capture_devices", &VideoDevice::get_capture_devices); py::class_<VideoStreamer>(m, "VideoStreamer") - .def_property_readonly("fd", &VideoStreamer::fd) - .def_property_readonly("ports", &VideoStreamer::get_ports) - .def("set_port", &VideoStreamer::set_port) - .def_property_readonly("formats", &VideoStreamer::get_formats) - .def("set_format", &VideoStreamer::set_format) - .def("get_selection", [](VideoStreamer *self) { - uint32_t left, top, width, height; - self->get_selection(left, top, width, height); - return make_tuple(left, top, width, height); - } ) - .def("set_selection", [](VideoStreamer *self, uint32_t left, uint32_t top, uint32_t width, uint32_t height) { - self->set_selection(left, top, width, height); - return make_tuple(left, top, width, height); - } ) - .def("set_queue_size", &VideoStreamer::set_queue_size) - .def("queue", &VideoStreamer::queue) - .def("dequeue", &VideoStreamer::dequeue) - .def("stream_on", &VideoStreamer::stream_on) - .def("stream_off", &VideoStreamer::stream_off) - ; + .def_property_readonly("fd", &VideoStreamer::fd) + .def_property_readonly("ports", &VideoStreamer::get_ports) + .def("set_port", &VideoStreamer::set_port) + .def_property_readonly("formats", &VideoStreamer::get_formats) + .def("set_format", &VideoStreamer::set_format) + .def("get_selection", [](VideoStreamer* self) { + uint32_t left, top, width, height; + self->get_selection(left, top, width, height); + return make_tuple(left, top, width, height); + }) + .def("set_selection", [](VideoStreamer* self, uint32_t left, uint32_t top, uint32_t width, uint32_t height) { + self->set_selection(left, top, width, height); + return make_tuple(left, top, width, height); + }) + .def("set_queue_size", &VideoStreamer::set_queue_size) + .def("queue", &VideoStreamer::queue) + .def("dequeue", &VideoStreamer::dequeue) + .def("stream_on", &VideoStreamer::stream_on) + .def("stream_off", &VideoStreamer::stream_off); } diff --git a/utils/fbtest.cpp b/utils/fbtest.cpp index 1c9a5f1..fba7ba7 100644 --- a/utils/fbtest.cpp +++ b/utils/fbtest.cpp @@ -34,9 +34,9 @@ int main(int argc, char** argv) FAIL_IF(r, "FBIOGET_FSCREENINFO failed"); uint8_t* ptr = (uint8_t*)mmap(NULL, - var.yres_virtual * fix.line_length, - PROT_WRITE | PROT_READ, - MAP_SHARED, fd, 0); + var.yres_virtual * fix.line_length, + PROT_WRITE | PROT_READ, + MAP_SHARED, fd, 0); FAIL_IF(ptr == MAP_FAILED, "mmap failed"); diff --git a/utils/kmsblank.cpp b/utils/kmsblank.cpp index 286c7f7..d9a3460 100644 --- a/utils/kmsblank.cpp +++ b/utils/kmsblank.cpp @@ -9,23 +9,22 @@ using namespace std; using namespace kms; static const char* usage_str = - "Usage: kmsblank [OPTION]...\n\n" - "Blank screen(s)\n\n" - "Options:\n" - " --device=DEVICE DEVICE is the path to DRM card to open\n" - " -c, --connector=CONN CONN is <connector>\n" - " -t, --time=TIME blank/unblank in TIME intervals\n" - "\n" - "<connector> can be given by index (<idx>) or id (@<id>).\n" - "<connector> can also be given by name.\n" - ; + "Usage: kmsblank [OPTION]...\n\n" + "Blank screen(s)\n\n" + "Options:\n" + " --device=DEVICE DEVICE is the path to DRM card to open\n" + " -c, --connector=CONN CONN is <connector>\n" + " -t, --time=TIME blank/unblank in TIME intervals\n" + "\n" + "<connector> can be given by index (<idx>) or id (@<id>).\n" + "<connector> can also be given by name.\n"; static void usage() { puts(usage_str); } -int main(int argc, char **argv) +int main(int argc, char** argv) { string dev_path; @@ -33,20 +32,16 @@ int main(int argc, char **argv) uint32_t time = 0; OptionSet optionset = { - Option("|device=", [&dev_path](string s) - { + Option("|device=", [&dev_path](string s) { dev_path = s; }), - Option("c|connector=", [&conn_strs](string str) - { + Option("c|connector=", [&conn_strs](string str) { conn_strs.push_back(str); }), - Option("t|time=", [&time](string str) - { + Option("t|time=", [&time](string str) { time = stoul(str); }), - Option("h|help", []() - { + Option("h|help", []() { usage(); exit(-1); }), diff --git a/utils/kmscapture.cpp b/utils/kmscapture.cpp index a36b355..099d40f 100644 --- a/utils/kmscapture.cpp +++ b/utils/kmscapture.cpp @@ -11,8 +11,8 @@ #include <kms++/kms++.h> #include <kms++util/kms++util.h> -#define CAMERA_BUF_QUEUE_SIZE 3 -#define MAX_CAMERA 9 +#define CAMERA_BUF_QUEUE_SIZE 3 +#define MAX_CAMERA 9 using namespace std; using namespace kms; @@ -33,12 +33,13 @@ public: CameraPipeline(const CameraPipeline& other) = delete; CameraPipeline& operator=(const CameraPipeline& other) = delete; - void show_next_frame(AtomicReq &req); + void show_next_frame(AtomicReq& req); int fd() const { return m_fd; } void start_streaming(); + private: DmabufFramebuffer* GetDmabufFrameBuffer(Card& card, uint32_t i, PixelFormat pixfmt); - int m_fd; /* camera file descriptor */ + int m_fd; /* camera file descriptor */ Crtc* m_crtc; Plane* m_plane; BufferProvider m_buffer_provider; @@ -50,7 +51,7 @@ private: uint32_t m_out_x, m_out_y; }; -static int buffer_export(int v4lfd, enum v4l2_buf_type bt, uint32_t index, int *dmafd) +static int buffer_export(int v4lfd, enum v4l2_buf_type bt, uint32_t index, int* dmafd) { struct v4l2_exportbuffer expbuf; @@ -77,12 +78,12 @@ DmabufFramebuffer* CameraPipeline::GetDmabufFrameBuffer(Card& card, uint32_t i, const PixelFormatInfo& format_info = get_pixel_format_info(pixfmt); ASSERT(format_info.num_planes == 1); - vector<int> fds { dmafd }; - vector<uint32_t> pitches { m_in_width * (format_info.planes[0].bitspp / 8) }; - vector<uint32_t> offsets { 0 }; + vector<int> fds{ dmafd }; + vector<uint32_t> pitches{ m_in_width * (format_info.planes[0].bitspp / 8) }; + vector<uint32_t> offsets{ 0 }; return new DmabufFramebuffer(card, m_in_width, m_in_height, pixfmt, - fds, pitches, offsets); + fds, pitches, offsets); } bool inline better_size(struct v4l2_frmsize_discrete* v4ldisc, @@ -96,17 +97,16 @@ bool inline better_size(struct v4l2_frmsize_discrete* v4ldisc, return false; } -CameraPipeline::CameraPipeline(int cam_fd, Card& card, Crtc *crtc, Plane* plane, uint32_t x, uint32_t y, +CameraPipeline::CameraPipeline(int cam_fd, Card& card, Crtc* crtc, Plane* plane, uint32_t x, uint32_t y, uint32_t iw, uint32_t ih, PixelFormat pixfmt, BufferProvider buffer_provider) : m_fd(cam_fd), m_crtc(crtc), m_buffer_provider(buffer_provider), m_prev_fb_index(-1) { - int r; uint32_t best_w = 320; uint32_t best_h = 240; - struct v4l2_frmsizeenum v4lfrms = { }; + struct v4l2_frmsizeenum v4lfrms = {}; v4lfrms.pixel_format = (uint32_t)pixfmt; while (ioctl(m_fd, VIDIOC_ENUM_FRAMESIZES, &v4lfrms) == 0) { if (v4lfrms.type != V4L2_FRMSIZE_TYPE_DISCRETE) { @@ -137,7 +137,7 @@ CameraPipeline::CameraPipeline(int cam_fd, Card& card, Crtc *crtc, Plane* plane, printf("Capture: %ux%u\n", best_w, best_h); - struct v4l2_format v4lfmt = { }; + struct v4l2_format v4lfmt = {}; v4lfmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; r = ioctl(m_fd, VIDIOC_G_FMT, &v4lfmt); ASSERT(r == 0); @@ -156,7 +156,7 @@ CameraPipeline::CameraPipeline(int cam_fd, Card& card, Crtc *crtc, Plane* plane, else v4l_mem = V4L2_MEMORY_DMABUF; - struct v4l2_requestbuffers v4lreqbuf = { }; + struct v4l2_requestbuffers v4lreqbuf = {}; v4lreqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; v4lreqbuf.memory = v4l_mem; v4lreqbuf.count = CAMERA_BUF_QUEUE_SIZE; @@ -164,12 +164,12 @@ CameraPipeline::CameraPipeline(int cam_fd, Card& card, Crtc *crtc, Plane* plane, ASSERT(r == 0); ASSERT(v4lreqbuf.count == CAMERA_BUF_QUEUE_SIZE); - struct v4l2_buffer v4lbuf = { }; + struct v4l2_buffer v4lbuf = {}; v4lbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; v4lbuf.memory = v4l_mem; for (unsigned i = 0; i < CAMERA_BUF_QUEUE_SIZE; i++) { - Framebuffer *fb; + Framebuffer* fb; if (m_buffer_provider == BufferProvider::V4L2) fb = GetDmabufFrameBuffer(card, i, pixfmt); @@ -192,7 +192,7 @@ CameraPipeline::CameraPipeline(int cam_fd, Card& card, Crtc *crtc, Plane* plane, // set the FB when page flipping AtomicReq req(card); - Framebuffer *fb = m_fb[0]; + Framebuffer* fb = m_fb[0]; req.add(m_plane, "CRTC_ID", m_crtc->id()); req.add(m_plane, "FB_ID", fb->id()); @@ -237,7 +237,7 @@ void CameraPipeline::show_next_frame(AtomicReq& req) else v4l_mem = V4L2_MEMORY_DMABUF; - struct v4l2_buffer v4l2buf = { }; + struct v4l2_buffer v4l2buf = {}; v4l2buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; v4l2buf.memory = v4l_mem; r = ioctl(m_fd, VIDIOC_DQBUF, &v4l2buf); @@ -248,7 +248,7 @@ void CameraPipeline::show_next_frame(AtomicReq& req) unsigned fb_index = v4l2buf.index; - Framebuffer *fb = m_fb[fb_index]; + Framebuffer* fb = m_fb[fb_index]; req.add(m_plane, "FB_ID", fb->id()); @@ -261,7 +261,6 @@ void CameraPipeline::show_next_frame(AtomicReq& req) v4l2buf.m.fd = m_fb[m_prev_fb_index]->prime_fd(0); r = ioctl(m_fd, VIDIOC_QBUF, &v4l2buf); ASSERT(r == 0); - } m_prev_fb_index = fb_index; @@ -269,7 +268,7 @@ void CameraPipeline::show_next_frame(AtomicReq& req) static bool is_capture_dev(int fd) { - struct v4l2_capability cap = { }; + struct v4l2_capability cap = {}; int r = ioctl(fd, VIDIOC_QUERYCAP, &cap); ASSERT(r == 0); return cap.capabilities & V4L2_CAP_VIDEO_CAPTURE; @@ -280,19 +279,18 @@ std::vector<std::string> glob(const std::string& pat) glob_t glob_result; glob(pat.c_str(), 0, NULL, &glob_result); vector<string> ret; - for(unsigned i = 0; i < glob_result.gl_pathc; ++i) + for (unsigned i = 0; i < glob_result.gl_pathc; ++i) ret.push_back(string(glob_result.gl_pathv[i])); globfree(&glob_result); return ret; } static const char* usage_str = - "Usage: kmscapture [OPTIONS]\n\n" - "Options:\n" - " -s, --single Single camera mode. Open only /dev/video0\n" - " --buffer-type=<drm|v4l> Use DRM or V4L provided buffers. Default: DRM\n" - " -h, --help Print this help\n" - ; + "Usage: kmscapture [OPTIONS]\n\n" + "Options:\n" + " -s, --single Single camera mode. Open only /dev/video0\n" + " --buffer-type=<drm|v4l> Use DRM or V4L provided buffers. Default: DRM\n" + " -h, --help Print this help\n"; int main(int argc, char** argv) { @@ -300,12 +298,10 @@ int main(int argc, char** argv) bool single_cam = false; OptionSet optionset = { - Option("s|single", [&]() - { + Option("s|single", [&]() { single_cam = true; }), - Option("|buffer-type=", [&](string s) - { + Option("|buffer-type=", [&](string s) { if (s == "v4l") buffer_provider = BufferProvider::V4L2; else if (s == "drm") @@ -313,8 +309,7 @@ int main(int argc, char** argv) else FAIL("Invalid buffer provider: %s", s.c_str()); }), - Option("h|help", [&]() - { + Option("h|help", [&]() { puts(usage_str); exit(-1); }), @@ -334,7 +329,7 @@ int main(int argc, char** argv) auto conn = card.get_first_connected_connector(); auto crtc = conn->get_current_crtc(); printf("Display: %dx%d\n", crtc->width(), crtc->height()); - printf("Buffer provider: %s\n", buffer_provider == BufferProvider::V4L2? "V4L" : "DRM"); + printf("Buffer provider: %s\n", buffer_provider == BufferProvider::V4L2 ? "V4L" : "DRM"); vector<int> camera_fds; @@ -389,10 +384,10 @@ int main(int argc, char** argv) for (unsigned i = 0; i < nr_cameras; i++) { fds[i].fd = cameras[i]->fd(); - fds[i].events = POLLIN; + fds[i].events = POLLIN; } fds[nr_cameras].fd = 0; - fds[nr_cameras].events = POLLIN; + fds[nr_cameras].events = POLLIN; for (auto cam : cameras) cam->start_streaming(); diff --git a/utils/kmsprint.cpp b/utils/kmsprint.cpp index 9d3d7cc..7469b47 100644 --- a/utils/kmsprint.cpp +++ b/utils/kmsprint.cpp @@ -27,13 +27,13 @@ static string format_mode(const Videomode& m, unsigned idx) if (s_opts.x_modeline) { str += fmt::format("{:12} {:6} {:4} {:4} {:4} {:4} {:4} {:4} {:4} {:4} {:3} {:#x} {:#x}", - m.name, - m.clock, - m.hdisplay, m.hsync_start, m.hsync_end, m.htotal, - m.vdisplay, m.vsync_start, m.vsync_end, m.vtotal, - m.vrefresh, - m.flags, - m.type); + m.name, + m.clock, + m.hdisplay, m.hsync_start, m.hsync_end, m.htotal, + m.vdisplay, m.vsync_start, m.vsync_end, m.vtotal, + m.vrefresh, + m.flags, + m.type); } else { str += m.to_string_long_padded(); } @@ -51,7 +51,7 @@ static string format_connector(Connector& c) string str; str = fmt::format("Connector {} ({}) {}", - c.idx(), c.id(), c.fullname()); + c.idx(), c.id(), c.fullname()); switch (c.connector_status()) { case ConnectorStatus::Connected: @@ -71,7 +71,7 @@ static string format_connector(Connector& c) static string format_encoder(Encoder& e) { return fmt::format("Encoder {} ({}) {}", - e.idx(), e.id(), e.get_encoder_type()); + e.idx(), e.id(), e.get_encoder_type()); } static string format_crtc(Crtc& c) @@ -101,14 +101,14 @@ static string format_plane(Plane& p) if (p.card().has_atomic()) { str += fmt::format(" {},{} {}x{} -> {},{} {}x{}", - (uint32_t)p.get_prop_value("SRC_X") >> 16, - (uint32_t)p.get_prop_value("SRC_Y") >> 16, - (uint32_t)p.get_prop_value("SRC_W") >> 16, - (uint32_t)p.get_prop_value("SRC_H") >> 16, - (uint32_t)p.get_prop_value("CRTC_X"), - (uint32_t)p.get_prop_value("CRTC_Y"), - (uint32_t)p.get_prop_value("CRTC_W"), - (uint32_t)p.get_prop_value("CRTC_H")); + (uint32_t)p.get_prop_value("SRC_X") >> 16, + (uint32_t)p.get_prop_value("SRC_Y") >> 16, + (uint32_t)p.get_prop_value("SRC_W") >> 16, + (uint32_t)p.get_prop_value("SRC_H") >> 16, + (uint32_t)p.get_prop_value("CRTC_X"), + (uint32_t)p.get_prop_value("CRTC_Y"), + (uint32_t)p.get_prop_value("CRTC_W"), + (uint32_t)p.get_prop_value("CRTC_H")); } string fmts = join<PixelFormat>(p.get_formats(), " ", [](PixelFormat fmt) { return PixelFormatToFourCC(fmt); }); @@ -121,7 +121,7 @@ static string format_plane(Plane& p) static string format_fb(Framebuffer& fb) { return fmt::format("FB {} {}x{}", - fb.id(), fb.width(), fb.height()); + fb.id(), fb.width(), fb.height()); } static string format_property(const Property* prop, uint64_t val) @@ -129,8 +129,7 @@ static string format_property(const Property* prop, uint64_t val) string ret = fmt::format("{} ({}) = ", prop->name(), prop->id()); switch (prop->type()) { - case PropertyType::Bitmask: - { + case PropertyType::Bitmask: { vector<string> v, vall; for (auto kvp : prop->get_enums()) { @@ -145,8 +144,7 @@ static string format_property(const Property* prop, uint64_t val) break; } - case PropertyType::Blob: - { + case PropertyType::Blob: { uint32_t blob_id = (uint32_t)val; if (blob_id) { @@ -161,8 +159,7 @@ static string format_property(const Property* prop, uint64_t val) break; } - case PropertyType::Enum: - { + case PropertyType::Enum: { string cur; vector<string> vall; @@ -177,32 +174,28 @@ static string format_property(const Property* prop, uint64_t val) break; } - case PropertyType::Object: - { + case PropertyType::Object: { ret += fmt::format("object id {}", val); break; } - case PropertyType::Range: - { + case PropertyType::Range: { auto values = prop->get_values(); ret += fmt::format("{} [{} - {}]", - val, values[0], values[1]); + val, values[0], values[1]); break; } - case PropertyType::SignedRange: - { + case PropertyType::SignedRange: { auto values = prop->get_values(); ret += fmt::format("{} [{} - {}]", - (int64_t)val, (int64_t)values[0], (int64_t)values[1]); + (int64_t)val, (int64_t)values[0], (int64_t)values[1]); break; } - } if (prop->is_pending()) @@ -247,15 +240,14 @@ vector<T> filter(const vector<T>& sequence, function<bool(T)> predicate) { vector<T> result; - for(auto it = sequence.begin(); it != sequence.end(); ++it) - if(predicate(*it)) + for (auto it = sequence.begin(); it != sequence.end(); ++it) + if (predicate(*it)) result.push_back(*it); return result; } -struct Entry -{ +struct Entry { string title; vector<string> lines; vector<Entry> children; @@ -345,7 +337,7 @@ static void print_entry(const Entry& e, const string& prefix, bool is_child, boo static void print_entries(const vector<Entry>& entries, const string& prefix) { - for (const Entry& e: entries) { + for (const Entry& e : entries) { print_entry(e, "", false, false); } } @@ -356,7 +348,6 @@ static void append(vector<DrmObject*>& dst, const vector<T*>& src) dst.insert(dst.end(), src.begin(), src.end()); } - static void print_as_list(Card& card) { vector<DrmPropObject*> obs; @@ -386,7 +377,7 @@ static void print_as_list(Card& card) } } - for (DrmPropObject* ob: obs) { + for (DrmPropObject* ob : obs) { fmt::print("{}\n", format_ob(ob)); if (s_opts.print_props) { @@ -395,7 +386,7 @@ static void print_as_list(Card& card) } } - for (Framebuffer* fb: fbs) { + for (Framebuffer* fb : fbs) { fmt::print("{}\n", format_ob(fb)); } } @@ -411,7 +402,6 @@ static void print_as_tree(Card& card) e1.lines = format_props(conn); for (Encoder* enc : conn->get_encoders()) { - Entry& e2 = add_entry(e1.children); e2.title = format_ob(enc); if (s_opts.print_props) @@ -470,46 +460,40 @@ static void print_modes(Card& card) } static const char* usage_str = - "Usage: kmsprint [OPTIONS]\n\n" - "Options:\n" - " --device=DEVICE DEVICE is the path to DRM card to open\n" - " -l, --list Print list instead of tree\n" - " -m, --modes Print modes\n" - " --xmode Print modes using X modeline\n" - " -p, --props Print properties\n" - ; + "Usage: kmsprint [OPTIONS]\n\n" + "Options:\n" + " --device=DEVICE DEVICE is the path to DRM card to open\n" + " -l, --list Print list instead of tree\n" + " -m, --modes Print modes\n" + " --xmode Print modes using X modeline\n" + " -p, --props Print properties\n"; static void usage() { puts(usage_str); } -int main(int argc, char **argv) +int main(int argc, char** argv) { string dev_path; OptionSet optionset = { - Option("|device=", [&dev_path](string s) - { + Option("|device=", [&dev_path](string s) { dev_path = s; }), - Option("l|list", []() - { + Option("l|list", []() { s_opts.print_list = true; }), - Option("m|modes", []() - { + Option("m|modes", []() { s_opts.print_modes = true; }), - Option("p|props", []() - { + Option("p|props", []() { s_opts.print_props = true; }), Option("|xmode", []() { s_opts.x_modeline = true; }), - Option("h|help", []() - { + Option("h|help", []() { usage(); exit(-1); }), diff --git a/utils/kmstest.cpp b/utils/kmstest.cpp index b4bf24b..981a2fd 100644 --- a/utils/kmstest.cpp +++ b/utils/kmstest.cpp @@ -21,15 +21,15 @@ using namespace std; using namespace kms; struct PropInfo { - PropInfo(string n, uint64_t v) : prop(NULL), name(n), val(v) {} + PropInfo(string n, uint64_t v) + : prop(NULL), name(n), val(v) {} - Property *prop; + Property* prop; string name; uint64_t val; }; -struct PlaneInfo -{ +struct PlaneInfo { Plane* plane; unsigned x; @@ -47,8 +47,7 @@ struct PlaneInfo vector<PropInfo> props; }; -struct OutputInfo -{ +struct OutputInfo { Connector* connector; Crtc* crtc; @@ -72,8 +71,7 @@ static bool s_cvt_vid_opt; static unsigned s_max_flips; static bool s_print_crc; -__attribute__ ((unused)) -static void print_regex_match(smatch sm) +__attribute__((unused)) static void print_regex_match(smatch sm) { for (unsigned i = 0; i < sm.size(); ++i) { string str = sm[i].str(); @@ -100,11 +98,10 @@ static void get_default_crtc(ResourceManager& resman, OutputInfo& output) EXIT("Could not find available crtc"); } - -static PlaneInfo *add_default_planeinfo(OutputInfo* output) +static PlaneInfo* add_default_planeinfo(OutputInfo* output) { - output->planes.push_back(PlaneInfo { }); - PlaneInfo *ret = &output->planes.back(); + output->planes.push_back(PlaneInfo{}); + PlaneInfo* ret = &output->planes.back(); ret->w = output->mode.hdisplay; ret->h = output->mode.vdisplay; return ret; @@ -115,16 +112,16 @@ static void parse_crtc(ResourceManager& resman, Card& card, const string& crtc_s // @12:1920x1200i@60 // @12:33000000,800/210/30/16/-,480/22/13/10/-,i - const regex modename_re("(?:(@?)(\\d+):)?" // @12: - "(?:(\\d+)x(\\d+)(i)?)" // 1920x1200i - "(?:@([\\d\\.]+))?"); // @60 + const regex modename_re("(?:(@?)(\\d+):)?" // @12: + "(?:(\\d+)x(\\d+)(i)?)" // 1920x1200i + "(?:@([\\d\\.]+))?"); // @60 - const regex modeline_re("(?:(@?)(\\d+):)?" // @12: - "(\\d+)," // 33000000, - "(\\d+)/(\\d+)/(\\d+)/(\\d+)/([+-])," // 800/210/30/16/-, - "(\\d+)/(\\d+)/(\\d+)/(\\d+)/([+-])" // 480/22/13/10/- - "(?:,([i]+))?" // ,i - ); + const regex modeline_re("(?:(@?)(\\d+):)?" // @12: + "(\\d+)," // 33000000, + "(\\d+)/(\\d+)/(\\d+)/(\\d+)/([+-])," // 800/210/30/16/-, + "(\\d+)/(\\d+)/(\\d+)/(\\d+)/([+-])" // 480/22/13/10/- + "(?:,([i]+))?" // ,i + ); smatch sm; if (regex_match(crtc_str, sm, modename_re)) { @@ -246,9 +243,9 @@ static void parse_crtc(ResourceManager& resman, Card& card, const string& crtc_s static void parse_plane(ResourceManager& resman, Card& card, const string& plane_str, const OutputInfo& output, PlaneInfo& pinfo) { // 3:400,400-400x400 - const regex plane_re("(?:(@?)(\\d+):)?" // 3: - "(?:(\\d+),(\\d+)-)?" // 400,400- - "(\\d+)x(\\d+)"); // 400x400 + const regex plane_re("(?:(@?)(\\d+):)?" // 3: + "(?:(\\d+),(\\d+)-)?" // 400,400- + "(\\d+)x(\\d+)"); // 400x400 smatch sm; if (!regex_match(plane_str, sm, plane_re)) @@ -292,7 +289,7 @@ static void parse_plane(ResourceManager& resman, Card& card, const string& plane pinfo.y = output.mode.vdisplay / 2 - pinfo.h / 2; } -static void parse_prop(const string& prop_str, vector<PropInfo> &props) +static void parse_prop(const string& prop_str, vector<PropInfo>& props) { string name, val; @@ -302,12 +299,12 @@ static void parse_prop(const string& prop_str, vector<PropInfo> &props) EXIT("Equal sign ('=') not found in %s", prop_str.c_str()); name = prop_str.substr(0, split); - val = prop_str.substr(split+1); + val = prop_str.substr(split + 1); props.push_back(PropInfo(name, stoull(val, 0, 0))); } -static void get_props(Card& card, vector<PropInfo> &props, const DrmPropObject* propobj) +static void get_props(Card& card, vector<PropInfo>& props, const DrmPropObject* propobj) { for (auto& pi : props) pi.prop = propobj->get_prop(pi.name); @@ -339,9 +336,9 @@ static void parse_fb(Card& card, const string& fb_str, OutputInfo* output, Plane if (!fb_str.empty()) { // XXX the regexp is not quite correct // 400x400-NV12 - const regex fb_re("(?:(\\d+)x(\\d+))?" // 400x400 - "(?:-)?" // - - "(\\w\\w\\w\\w)?"); // NV12 + const regex fb_re("(?:(\\d+)x(\\d+))?" // 400x400 + "(?:-)?" // - + "(\\w\\w\\w\\w)?"); // NV12 smatch sm; if (!regex_match(fb_str, sm, fb_re)) @@ -368,7 +365,7 @@ static void parse_fb(Card& card, const string& fb_str, OutputInfo* output, Plane static void parse_view(const string& view_str, PlaneInfo& pinfo) { - const regex view_re("(\\d+),(\\d+)-(\\d+)x(\\d+)"); // 400,400-400x400 + const regex view_re("(\\d+),(\\d+)-(\\d+)x(\\d+)"); // 400,400-400x400 smatch sm; if (!regex_match(view_str, sm, view_re)) @@ -381,56 +378,54 @@ static void parse_view(const string& view_str, PlaneInfo& pinfo) } static const char* usage_str = - "Usage: kmstest [OPTION]...\n\n" - "Show a test pattern on a display or plane\n\n" - "Options:\n" - " --device=DEVICE DEVICE is the path to DRM card to open\n" - " -c, --connector=CONN CONN is <connector>\n" - " -r, --crtc=CRTC CRTC is [<crtc>:]<w>x<h>[@<Hz>]\n" - " or\n" - " [<crtc>:]<pclk>,<hact>/<hfp>/<hsw>/<hbp>/<hsp>,<vact>/<vfp>/<vsw>/<vbp>/<vsp>[,i]\n" - " -p, --plane=PLANE PLANE is [<plane>:][<x>,<y>-]<w>x<h>\n" - " -f, --fb=FB FB is [<w>x<h>][-][<4cc>]\n" - " -v, --view=VIEW VIEW is <x>,<y>-<w>x<h>\n" - " -P, --property=PROP=VAL Set PROP to VAL in the previous DRM object\n" - " --dmt Search for the given mode from DMT tables\n" - " --cea Search for the given mode from CEA tables\n" - " --cvt=CVT Create videomode with CVT. CVT is 'v1', 'v2' or 'v2o'\n" - " --flip[=max] Do page flipping for each output with an optional maximum flips count\n" - " --sync Synchronize page flipping\n" - " --crc Print CRC16 for framebuffer contents\n" - "\n" - "<connector>, <crtc> and <plane> can be given by index (<idx>) or id (@<id>).\n" - "<connector> can also be given by name.\n" - "\n" - "Options can be given multiple times to set up multiple displays or planes.\n" - "Options may apply to previous options, e.g. a plane will be set on a crtc set in\n" - "an earlier option.\n" - "If you omit parameters, kmstest tries to guess what you mean\n" - "\n" - "Examples:\n" - "\n" - "Set eDP-1 mode to 1920x1080@60, show XR24 framebuffer on the crtc, and a 400x400 XB24 plane:\n" - " kmstest -c eDP-1 -r 1920x1080@60 -f XR24 -p 400x400 -f XB24\n\n" - "XR24 framebuffer on first connected connector in the default mode:\n" - " kmstest -f XR24\n\n" - "XR24 framebuffer on a 400x400 plane on the first connected connector in the default mode:\n" - " kmstest -p 400x400 -f XR24\n\n" - "Test pattern on the second connector with default mode:\n" - " kmstest -c 1\n" - "\n" - "Environmental variables:\n" - " KMSXX_DISABLE_UNIVERSAL_PLANES Don't enable universal planes even if available\n" - " KMSXX_DISABLE_ATOMIC Don't enable atomic modesetting even if available\n" - ; + "Usage: kmstest [OPTION]...\n\n" + "Show a test pattern on a display or plane\n\n" + "Options:\n" + " --device=DEVICE DEVICE is the path to DRM card to open\n" + " -c, --connector=CONN CONN is <connector>\n" + " -r, --crtc=CRTC CRTC is [<crtc>:]<w>x<h>[@<Hz>]\n" + " or\n" + " [<crtc>:]<pclk>,<hact>/<hfp>/<hsw>/<hbp>/<hsp>,<vact>/<vfp>/<vsw>/<vbp>/<vsp>[,i]\n" + " -p, --plane=PLANE PLANE is [<plane>:][<x>,<y>-]<w>x<h>\n" + " -f, --fb=FB FB is [<w>x<h>][-][<4cc>]\n" + " -v, --view=VIEW VIEW is <x>,<y>-<w>x<h>\n" + " -P, --property=PROP=VAL Set PROP to VAL in the previous DRM object\n" + " --dmt Search for the given mode from DMT tables\n" + " --cea Search for the given mode from CEA tables\n" + " --cvt=CVT Create videomode with CVT. CVT is 'v1', 'v2' or 'v2o'\n" + " --flip[=max] Do page flipping for each output with an optional maximum flips count\n" + " --sync Synchronize page flipping\n" + " --crc Print CRC16 for framebuffer contents\n" + "\n" + "<connector>, <crtc> and <plane> can be given by index (<idx>) or id (@<id>).\n" + "<connector> can also be given by name.\n" + "\n" + "Options can be given multiple times to set up multiple displays or planes.\n" + "Options may apply to previous options, e.g. a plane will be set on a crtc set in\n" + "an earlier option.\n" + "If you omit parameters, kmstest tries to guess what you mean\n" + "\n" + "Examples:\n" + "\n" + "Set eDP-1 mode to 1920x1080@60, show XR24 framebuffer on the crtc, and a 400x400 XB24 plane:\n" + " kmstest -c eDP-1 -r 1920x1080@60 -f XR24 -p 400x400 -f XB24\n\n" + "XR24 framebuffer on first connected connector in the default mode:\n" + " kmstest -f XR24\n\n" + "XR24 framebuffer on a 400x400 plane on the first connected connector in the default mode:\n" + " kmstest -p 400x400 -f XR24\n\n" + "Test pattern on the second connector with default mode:\n" + " kmstest -c 1\n" + "\n" + "Environmental variables:\n" + " KMSXX_DISABLE_UNIVERSAL_PLANES Don't enable universal planes even if available\n" + " KMSXX_DISABLE_ATOMIC Don't enable atomic modesetting even if available\n"; static void usage() { puts(usage_str); } -enum class ArgType -{ +enum class ArgType { Connector, Crtc, Plane, @@ -439,70 +434,57 @@ enum class ArgType Property, }; -struct Arg -{ +struct Arg { ArgType type; string arg; }; static string s_device_path; -static vector<Arg> parse_cmdline(int argc, char **argv) +static vector<Arg> parse_cmdline(int argc, char** argv) { vector<Arg> args; OptionSet optionset = { Option("|device=", - [&](string s) - { - s_device_path = s; - }), + [&](string s) { + s_device_path = s; + }), Option("c|connector=", - [&](string s) - { - args.push_back(Arg { ArgType::Connector, s }); - }), - Option("r|crtc=", [&](string s) - { - args.push_back(Arg { ArgType::Crtc, s }); + [&](string s) { + args.push_back(Arg{ ArgType::Connector, s }); + }), + Option("r|crtc=", [&](string s) { + args.push_back(Arg{ ArgType::Crtc, s }); }), - Option("p|plane=", [&](string s) - { - args.push_back(Arg { ArgType::Plane, s }); + Option("p|plane=", [&](string s) { + args.push_back(Arg{ ArgType::Plane, s }); }), - Option("f|fb=", [&](string s) - { - args.push_back(Arg { ArgType::Framebuffer, s }); + Option("f|fb=", [&](string s) { + args.push_back(Arg{ ArgType::Framebuffer, s }); }), - Option("v|view=", [&](string s) - { - args.push_back(Arg { ArgType::View, s }); + Option("v|view=", [&](string s) { + args.push_back(Arg{ ArgType::View, s }); }), - Option("P|property=", [&](string s) - { - args.push_back(Arg { ArgType::Property, s }); + Option("P|property=", [&](string s) { + args.push_back(Arg{ ArgType::Property, s }); }), - Option("|dmt", []() - { + Option("|dmt", []() { s_use_dmt = true; }), - Option("|cea", []() - { + Option("|cea", []() { s_use_cea = true; }), - Option("|flip?", [&](string s) - { + Option("|flip?", [&](string s) { s_flip_mode = true; s_num_buffers = 2; if (!s.empty()) s_max_flips = stoi(s); }), - Option("|sync", []() - { + Option("|sync", []() { s_flip_sync = true; }), - Option("|cvt=", [&](string s) - { + Option("|cvt=", [&](string s) { if (s == "v1") s_cvt = true; else if (s == "v2") @@ -517,8 +499,7 @@ static vector<Arg> parse_cmdline(int argc, char **argv) Option("|crc", []() { s_print_crc = true; }), - Option("h|help", [&]() - { + Option("h|help", [&]() { usage(); exit(-1); }), @@ -543,9 +524,8 @@ static vector<OutputInfo> setups_to_outputs(Card& card, ResourceManager& resman, for (auto& arg : output_args) { switch (arg.type) { - case ArgType::Connector: - { - outputs.push_back(OutputInfo { }); + case ArgType::Connector: { + outputs.push_back(OutputInfo{}); current_output = &outputs.back(); get_connector(resman, *current_output, arg.arg); @@ -554,10 +534,9 @@ static vector<OutputInfo> setups_to_outputs(Card& card, ResourceManager& resman, break; } - case ArgType::Crtc: - { + case ArgType::Crtc: { if (!current_output) { - outputs.push_back(OutputInfo { }); + outputs.push_back(OutputInfo{}); current_output = &outputs.back(); } @@ -571,10 +550,9 @@ static vector<OutputInfo> setups_to_outputs(Card& card, ResourceManager& resman, break; } - case ArgType::Plane: - { + case ArgType::Plane: { if (!current_output) { - outputs.push_back(OutputInfo { }); + outputs.push_back(OutputInfo{}); current_output = &outputs.back(); } @@ -591,10 +569,9 @@ static vector<OutputInfo> setups_to_outputs(Card& card, ResourceManager& resman, break; } - case ArgType::Framebuffer: - { + case ArgType::Framebuffer: { if (!current_output) { - outputs.push_back(OutputInfo { }); + outputs.push_back(OutputInfo{}); current_output = &outputs.back(); } @@ -612,8 +589,7 @@ static vector<OutputInfo> setups_to_outputs(Card& card, ResourceManager& resman, break; } - case ArgType::View: - { + case ArgType::View: { if (!current_plane || current_plane->fbs.empty()) EXIT("'view' parameter requires a plane and a fb"); @@ -621,8 +597,7 @@ static vector<OutputInfo> setups_to_outputs(Card& card, ResourceManager& resman, break; } - case ArgType::Property: - { + case ArgType::Property: { if (!current_output) EXIT("No object to which set the property"); @@ -646,7 +621,7 @@ static vector<OutputInfo> setups_to_outputs(Card& card, ResourceManager& resman, if (!conn->connected()) continue; - OutputInfo output = { }; + OutputInfo output = {}; output.connector = resman.reserve_connector(conn); EXIT_IF(!output.connector, "Failed to reserve connector %s", conn->fullname().c_str()); output.crtc = resman.reserve_crtc(conn); @@ -676,7 +651,7 @@ static vector<OutputInfo> setups_to_outputs(Card& card, ResourceManager& resman, o.legacy_fbs = get_default_fb(card, o.mode.hdisplay, o.mode.vdisplay); } - for (PlaneInfo &p : o.planes) { + for (PlaneInfo& p : o.planes) { if (p.fbs.empty()) p.fbs = get_default_fb(card, p.w, p.h); } @@ -704,7 +679,7 @@ static uint16_t crc16(uint16_t crc, uint8_t data) for (uint8_t i = 0; i < 8; i++) { if (((crc & 0x8000) >> 8) ^ (data & 0x80)) - crc = (crc << 1) ^ CRC16_IBM; + crc = (crc << 1) ^ CRC16_IBM; else crc = (crc << 1); @@ -714,16 +689,16 @@ static uint16_t crc16(uint16_t crc, uint8_t data) return crc; } -static string fb_crc(IFramebuffer *fb) +static string fb_crc(IFramebuffer* fb) { - uint8_t *p = fb->map(0); + uint8_t* p = fb->map(0); uint16_t r, g, b; r = g = b = 0; for (unsigned y = 0; y < fb->height(); ++y) { for (unsigned x = 0; x < fb->width(); ++x) { - uint32_t *p32 = (uint32_t*)(p + fb->stride(0) * y + x * 4); + uint32_t* p32 = (uint32_t*)(p + fb->stride(0) * y + x * 4); RGB rgb(*p32); r = crc16(r, rgb.r); @@ -748,12 +723,12 @@ static void print_outputs(const vector<OutputInfo>& outputs) fmt::print("Connector {}/@{}: {}", o.connector->idx(), o.connector->id(), o.connector->fullname()); - for (const PropInfo &prop: o.conn_props) + for (const PropInfo& prop : o.conn_props) fmt::print(" {}={}", prop.prop->name(), prop.val); fmt::print("\n Crtc {}/@{}", o.crtc->idx(), o.crtc->id()); - for (const PropInfo &prop: o.crtc_props) + for (const PropInfo& prop : o.crtc_props) fmt::print(" {}={}", prop.prop->name(), prop.val); fmt::print(": {}\n", o.mode.to_string_long()); @@ -768,7 +743,7 @@ static void print_outputs(const vector<OutputInfo>& outputs) auto fb = p.fbs[0]; fmt::print(" Plane {}/@{}: {},{}-{}x{}", p.plane->idx(), p.plane->id(), p.x, p.y, p.w, p.h); - for (const PropInfo &prop: p.props) + for (const PropInfo& prop : p.props) fmt::print(" {}={}", prop.prop->name(), prop.val); fmt::print("\n"); @@ -833,8 +808,8 @@ static void set_crtcs_n_planes_legacy(Card& card, const vector<OutputInfo>& outp auto fb = p.fbs[0]; r = crtc->set_plane(p.plane, *fb, - p.x, p.y, p.w, p.h, - 0, 0, fb->width(), fb->height()); + p.x, p.y, p.w, p.h, + 0, 0, fb->width(), fb->height()); if (r) fmt::print(stderr, "crtc->set_plane() failed for plane {}: {}\n", p.plane->id(), strerror(-r)); @@ -858,22 +833,21 @@ static void set_crtcs_n_planes_atomic(Card& card, const vector<OutputInfo>& outp // continue; disable_req.add(crtc, { - { "ACTIVE", 0 }, - }); + { "ACTIVE", 0 }, + }); } // Disable unused planes for (Plane* plane : card.get_planes()) disable_req.add(plane, { - { "FB_ID", 0 }, - { "CRTC_ID", 0 }, - }); + { "FB_ID", 0 }, + { "CRTC_ID", 0 }, + }); r = disable_req.commit_sync(true); if (r) EXIT("Atomic commit failed when disabling: %d\n", r); - // Keep blobs here so that we keep ref to them until we have committed the req vector<unique_ptr<Blob>> blobs; @@ -887,37 +861,37 @@ static void set_crtcs_n_planes_atomic(Card& card, const vector<OutputInfo>& outp Blob* mode_blob = blobs.back().get(); req.add(conn, { - { "CRTC_ID", crtc->id() }, - }); + { "CRTC_ID", crtc->id() }, + }); - for (const PropInfo &prop: o.conn_props) + for (const PropInfo& prop : o.conn_props) req.add(conn, prop.prop, prop.val); req.add(crtc, { - { "ACTIVE", 1 }, - { "MODE_ID", mode_blob->id() }, - }); + { "ACTIVE", 1 }, + { "MODE_ID", mode_blob->id() }, + }); - for (const PropInfo &prop: o.crtc_props) + for (const PropInfo& prop : o.crtc_props) req.add(crtc, prop.prop, prop.val); for (const PlaneInfo& p : o.planes) { auto fb = p.fbs[0]; req.add(p.plane, { - { "FB_ID", fb->id() }, - { "CRTC_ID", crtc->id() }, - { "SRC_X", (p.view_x ?: 0) << 16 }, - { "SRC_Y", (p.view_y ?: 0) << 16 }, - { "SRC_W", (p.view_w ?: fb->width()) << 16 }, - { "SRC_H", (p.view_h ?: fb->height()) << 16 }, - { "CRTC_X", p.x }, - { "CRTC_Y", p.y }, - { "CRTC_W", p.w }, - { "CRTC_H", p.h }, - }); - - for (const PropInfo &prop: p.props) + { "FB_ID", fb->id() }, + { "CRTC_ID", crtc->id() }, + { "SRC_X", (p.view_x ?: 0) << 16 }, + { "SRC_Y", (p.view_y ?: 0) << 16 }, + { "SRC_W", (p.view_w ?: fb->width()) << 16 }, + { "SRC_H", (p.view_h ?: fb->height()) << 16 }, + { "CRTC_X", p.x }, + { "CRTC_Y", p.y }, + { "CRTC_W", p.w }, + { "CRTC_H", p.h }, + }); + + for (const PropInfo& prop : p.props) req.add(p.plane, prop.prop, prop.val); } } @@ -977,7 +951,7 @@ private: if (diff > m_slowest_frame) m_slowest_frame = diff; - if (m_frame_num % 100 == 0) { + if (m_frame_num % 100 == 0) { std::chrono::duration<float> fsec = now - m_prev_print; fmt::print("Connector {}: fps {:.2f}, slowest {:.2f} ms\n", m_name.c_str(), @@ -1016,8 +990,8 @@ private: draw_bar(fb, frame_num); req.add(p.plane, { - { "FB_ID", fb->id() }, - }); + { "FB_ID", fb->id() }, + }); } } @@ -1129,7 +1103,7 @@ static void main_flip(Card& card, const vector<OutputInfo>& outputs) } } -int main(int argc, char **argv) +int main(int argc, char** argv) { vector<Arg> output_args = parse_cmdline(argc, argv); diff --git a/utils/kmstouch.cpp b/utils/kmstouch.cpp index b7ac420..fbe0f3d 100644 --- a/utils/kmstouch.cpp +++ b/utils/kmstouch.cpp @@ -16,14 +16,13 @@ using namespace std; using namespace kms; static const char* usage_str = - "Usage: kmstouch [OPTION]...\n\n" - "Simple touchscreen tester\n\n" - "Options:\n" - " --input=DEVICE DEVICE is the path to input device to open\n" - " --device=DEVICE DEVICE is the path to DRM card to open\n" - " -c, --connector=CONN CONN is <connector>\n" - "\n" - ; + "Usage: kmstouch [OPTION]...\n\n" + "Simple touchscreen tester\n\n" + "Options:\n" + " --input=DEVICE DEVICE is the path to input device to open\n" + " --device=DEVICE DEVICE is the path to DRM card to open\n" + " -c, --connector=CONN CONN is <connector>\n" + "\n"; static void usage() { @@ -39,9 +38,9 @@ static map<int, pair<int32_t, int32_t>> s_abs_map; // axis -> value static map<int, int32_t> s_abs_vals; -static void print_abs_bits(struct libevdev *dev, int axis) +static void print_abs_bits(struct libevdev* dev, int axis) { - const struct input_absinfo *abs; + const struct input_absinfo* abs; if (!libevdev_has_event_code(dev, EV_ABS, axis)) return; @@ -59,7 +58,7 @@ static void print_abs_bits(struct libevdev *dev, int axis) printf(" Resolution %6d\n", abs->resolution); } -static void print_code_bits(struct libevdev *dev, unsigned int type, unsigned int max) +static void print_code_bits(struct libevdev* dev, unsigned int type, unsigned int max) { for (uint32_t i = 0; i <= max; i++) { if (!libevdev_has_event_code(dev, type, i)) @@ -71,7 +70,7 @@ static void print_code_bits(struct libevdev *dev, unsigned int type, unsigned in } } -static void print_bits(struct libevdev *dev) +static void print_bits(struct libevdev* dev) { printf("Supported events:\n"); @@ -81,7 +80,7 @@ static void print_bits(struct libevdev *dev) printf(" Event type %d (%s)\n", i, libevdev_event_type_get_name(i)); - switch(i) { + switch (i) { case EV_KEY: print_code_bits(dev, EV_KEY, KEY_MAX); break; @@ -104,7 +103,7 @@ static void collect_current(struct libevdev* dev) if (!libevdev_has_event_code(dev, EV_ABS, i)) continue; - const struct input_absinfo *abs; + const struct input_absinfo* abs; abs = libevdev_get_abs_info(dev, i); @@ -113,7 +112,7 @@ static void collect_current(struct libevdev* dev) } } -static void print_props(struct libevdev *dev) +static void print_props(struct libevdev* dev) { printf("Properties:\n"); @@ -194,27 +193,23 @@ static void handle_event(struct input_event& ev, DumbFramebuffer* fb) } } -int main(int argc, char **argv) +int main(int argc, char** argv) { string drm_dev_path = "/dev/dri/card0"; string input_dev_path = "/dev/input/event0"; string conn_name; OptionSet optionset = { - Option("i|input=", [&input_dev_path](string s) - { + Option("i|input=", [&input_dev_path](string s) { input_dev_path = s; }), - Option("|device=", [&drm_dev_path](string s) - { + Option("|device=", [&drm_dev_path](string s) { drm_dev_path = s; }), - Option("c|connector=", [&conn_name](string s) - { + Option("c|connector=", [&conn_name](string s) { conn_name = s; }), - Option("h|help", []() - { + Option("h|help", []() { usage(); exit(-1); }), @@ -227,8 +222,7 @@ int main(int argc, char **argv) exit(-1); } - - struct libevdev *dev = nullptr; + struct libevdev* dev = nullptr; int fd = open(input_dev_path.c_str(), O_RDONLY | O_NONBLOCK); FAIL_IF(fd < 0, "Failed to open input device %s: %s\n", input_dev_path.c_str(), strerror(errno)); @@ -252,7 +246,6 @@ int main(int argc, char **argv) collect_current(dev); - Card card(drm_dev_path); ResourceManager resman(card); @@ -288,7 +281,8 @@ int main(int argc, char **argv) FAIL_IF(r, "initial plane setup failed"); do { - struct input_event ev {}; + struct input_event ev { + }; rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); if (rc == 0) handle_event(ev, fb); diff --git a/utils/kmsview.cpp b/utils/kmsview.cpp index eea9dde..952c643 100644 --- a/utils/kmsview.cpp +++ b/utils/kmsview.cpp @@ -24,11 +24,10 @@ static void read_frame(ifstream& is, DumbFramebuffer* fb, Crtc* crtc, Plane* pla } static const char* usage_str = - "Usage: kmsview [options] <file> <width> <height> <fourcc>\n\n" - "Options:\n" - " -c, --connector <name> Output connector\n" - " -t, --time <ms> Milliseconds to sleep between frames\n" - ; + "Usage: kmsview [options] <file> <width> <height> <fourcc>\n\n" + "Options:\n" + " -c, --connector <name> Output connector\n" + " -t, --time <ms> Milliseconds to sleep between frames\n"; static void usage() { @@ -42,20 +41,16 @@ int main(int argc, char** argv) string conn_name; OptionSet optionset = { - Option("c|connector=", [&conn_name](string s) - { + Option("c|connector=", [&conn_name](string s) { conn_name = s; }), - Option("|device=", [&dev_path](string s) - { + Option("|device=", [&dev_path](string s) { dev_path = s; }), - Option("t|time=", [&time](const string& str) - { + Option("t|time=", [&time](const string& str) { time = stoul(str); }), - Option("h|help", []() - { + Option("h|help", []() { usage(); exit(-1); }), @@ -83,7 +78,6 @@ int main(int argc, char** argv) unsigned fsize = is.tellg(); is.seekg(0); - Card card(dev_path); ResourceManager res(card); @@ -102,7 +96,8 @@ int main(int argc, char** argv) printf("file size %u, frame size %u, frames %u\n", fsize, frame_size, num_frames); for (unsigned i = 0; i < num_frames; ++i) { - printf("frame %d", i); fflush(stdout); + printf("frame %d", i); + fflush(stdout); read_frame(is, fb, crtc, plane); if (!time) { getchar(); diff --git a/utils/wbcap.cpp b/utils/wbcap.cpp index 886fe36..8033869 100644 --- a/utils/wbcap.cpp +++ b/utils/wbcap.cpp @@ -213,19 +213,19 @@ private: draw_bar(fb, m_frame_num); req.add(m_plane, { - { "CRTC_ID", m_crtc->id() }, - { "FB_ID", fb->id() }, + { "CRTC_ID", m_crtc->id() }, + { "FB_ID", fb->id() }, - { "CRTC_X", 0 }, - { "CRTC_Y", 0 }, - { "CRTC_W", min((uint32_t)m_crtc->mode().hdisplay, fb->width()) }, - { "CRTC_H", min((uint32_t)m_crtc->mode().vdisplay, fb->height()) }, + { "CRTC_X", 0 }, + { "CRTC_Y", 0 }, + { "CRTC_W", min((uint32_t)m_crtc->mode().hdisplay, fb->width()) }, + { "CRTC_H", min((uint32_t)m_crtc->mode().vdisplay, fb->height()) }, - { "SRC_X", 0 }, - { "SRC_Y", 0 }, - { "SRC_W", fb->width() << 16 }, - { "SRC_H", fb->height() << 16 }, - }); + { "SRC_X", 0 }, + { "SRC_Y", 0 }, + { "SRC_W", fb->width() << 16 }, + { "SRC_H", fb->height() << 16 }, + }); int r = req.commit(this); if (r) @@ -247,16 +247,15 @@ private: }; static const char* usage_str = - "Usage: wbcap [OPTIONS]\n\n" - "Options:\n" - " -s, --src=CONN Source connector\n" - " -d, --dst=CONN Destination connector\n" - " -m, --smode=MODE Source connector videomode\n" - " -M, --dmode=MODE Destination connector videomode\n" - " -f, --format=4CC Format\n" - " -w, --write Write captured frames to wbcap.raw file\n" - " -h, --help Print this help\n" - ; + "Usage: wbcap [OPTIONS]\n\n" + "Options:\n" + " -s, --src=CONN Source connector\n" + " -d, --dst=CONN Destination connector\n" + " -m, --smode=MODE Source connector videomode\n" + " -M, --dmode=MODE Destination connector videomode\n" + " -f, --format=4CC Format\n" + " -w, --write Write captured frames to wbcap.raw file\n" + " -h, --help Print this help\n"; int main(int argc, char** argv) { @@ -268,32 +267,25 @@ int main(int argc, char** argv) bool write_file = false; OptionSet optionset = { - Option("s|src=", [&](string s) - { + Option("s|src=", [&](string s) { src_conn_name = s; }), - Option("m|smode=", [&](string s) - { + Option("m|smode=", [&](string s) { src_mode_name = s; }), - Option("d|dst=", [&](string s) - { + Option("d|dst=", [&](string s) { dst_conn_name = s; }), - Option("M|dmode=", [&](string s) - { + Option("M|dmode=", [&](string s) { dst_mode_name = s; }), - Option("f|format=", [&](string s) - { + Option("f|format=", [&](string s) { pixfmt = FourCCToPixelFormat(s); }), - Option("w|write", [&]() - { + Option("w|write", [&]() { write_file = true; }), - Option("h|help", [&]() - { + Option("h|help", [&]() { puts(usage_str); exit(-1); }), @@ -326,7 +318,6 @@ int main(int argc, char** argv) Videomode src_mode = src_mode_name.empty() ? src_conn->get_default_mode() : src_conn->get_mode(src_mode_name); src_crtc->set_mode(src_conn, src_mode); - auto dst_conn = resman.reserve_connector(dst_conn_name); auto dst_crtc = resman.reserve_crtc(dst_conn); auto dst_plane = resman.reserve_overlay_plane(dst_crtc, pixfmt); @@ -371,11 +362,11 @@ int main(int argc, char** argv) vector<pollfd> fds(3); fds[0].fd = 0; - fds[0].events = POLLIN; + fds[0].events = POLLIN; fds[1].fd = wb.fd(); - fds[1].events = POLLIN; + fds[1].events = POLLIN; fds[2].fd = card.fd(); - fds[2].events = POLLIN; + fds[2].events = POLLIN; uint32_t dst_frame_num = 0; diff --git a/utils/wbm2m.cpp b/utils/wbm2m.cpp index 71a26a5..a00fab2 100644 --- a/utils/wbm2m.cpp +++ b/utils/wbm2m.cpp @@ -12,19 +12,18 @@ #include <kms++util/kms++util.h> #include <kms++util/videodevice.h> -const uint32_t NUM_SRC_BUFS=2; -const uint32_t NUM_DST_BUFS=2; +const uint32_t NUM_SRC_BUFS = 2; +const uint32_t NUM_DST_BUFS = 2; using namespace std; using namespace kms; static const char* usage_str = - "Usage: wbm2m [OPTIONS]\n\n" - "Options:\n" - " -f, --format=4CC Output format\n" - " -c, --crop=CROP CROP is <x>,<y>-<w>x<h>\n" - " -h, --help Print this help\n" - ; + "Usage: wbm2m [OPTIONS]\n\n" + "Options:\n" + " -f, --format=4CC Output format\n" + " -c, --crop=CROP CROP is <x>,<y>-<w>x<h>\n" + " -h, --help Print this help\n"; const int bar_speed = 4; const int bar_width = 10; @@ -51,7 +50,7 @@ static void read_frame(DumbFramebuffer* fb, unsigned frame_num) static void parse_crop(const string& crop_str, uint32_t& c_left, uint32_t& c_top, uint32_t& c_width, uint32_t& c_height) { - const regex crop_re("(\\d+),(\\d+)-(\\d+)x(\\d+)"); // 400,400-400x400 + const regex crop_re("(\\d+),(\\d+)-(\\d+)x(\\d+)"); // 400,400-400x400 smatch sm; if (!regex_match(crop_str, sm, crop_re)) @@ -79,17 +78,14 @@ int main(int argc, char** argv) bool use_selection = false; OptionSet optionset = { - Option("f|format=", [&](string s) - { + Option("f|format=", [&](string s) { dst_fmt = FourCCToPixelFormat(s); }), - Option("c|crop=", [&](string s) - { + Option("c|crop=", [&](string s) { parse_crop(s, c_left, c_top, c_width, c_height); use_selection = true; }), - Option("h|help", [&]() - { + Option("h|help", [&]() { puts(usage_str); exit(-1); }), @@ -106,7 +102,7 @@ int main(int argc, char** argv) dst_width, dst_height, PixelFormatToFourCC(dst_fmt).c_str()); const string filename = fmt::format("wb-out-{}x{}-{}.raw", dst_width, dst_height, - PixelFormatToFourCC(dst_fmt)); + PixelFormatToFourCC(dst_fmt)); printf("writing to %s\n", filename.c_str()); @@ -131,7 +127,6 @@ int main(int argc, char** argv) out->set_queue_size(NUM_SRC_BUFS); in->set_queue_size(NUM_DST_BUFS); - for (unsigned i = 0; i < min(NUM_SRC_BUFS, num_src_frames); ++i) { auto fb = new DumbFramebuffer(card, src_width, src_height, src_fmt); @@ -148,11 +143,11 @@ int main(int argc, char** argv) vector<pollfd> fds(3); fds[0].fd = 0; - fds[0].events = POLLIN; + fds[0].events = POLLIN; fds[1].fd = vid.fd(); - fds[1].events = POLLIN; + fds[1].events = POLLIN; fds[2].fd = card.fd(); - fds[2].events = POLLIN; + fds[2].events = POLLIN; ofstream os(filename, ofstream::binary); @@ -169,9 +164,8 @@ int main(int argc, char** argv) if (fds[1].revents) { fds[1].revents = 0; - try { - DumbFramebuffer *dst_fb = in->dequeue(); + DumbFramebuffer* dst_fb = in->dequeue(); printf("Writing frame %u\n", dst_frame_num); for (unsigned i = 0; i < dst_fb->num_planes(); ++i) os.write((char*)dst_fb->map(i), dst_fb->size(i)); @@ -189,7 +183,7 @@ int main(int argc, char** argv) break; } - DumbFramebuffer *src_fb = out->dequeue(); + DumbFramebuffer* src_fb = out->dequeue(); if (src_frame_num < num_src_frames) { read_frame(src_fb, src_frame_num++); |