1 #pragma once 2 3 #include <cstdint> 4 #include <vector> 5 #include <map> 6 #include <memory> 7 #include <string> 8 9 #include "decls.h" 10 #include "pipeline.h" 11 12 namespace kms 13 { 14 struct CardVersion { 15 int major; 16 int minor; 17 int patchlevel; 18 std::string name; 19 std::string date; 20 std::string desc; 21 }; 22 23 class Card 24 { 25 friend class Framebuffer; 26 27 public: 28 static std::unique_ptr<Card> open_named_card(const std::string& name); 29 30 Card(const std::string& dev_path = ""); 31 Card(const std::string& driver, uint32_t idx); 32 Card(int fd, bool take_ownership); 33 virtual ~Card(); 34 35 Card(const Card& other) = delete; 36 Card& operator=(const Card& other) = delete; 37 fd()38 int fd() const { return m_fd; } dev_minor()39 unsigned int dev_minor() const { return m_minor; } 40 41 void drop_master(); 42 43 Connector* get_first_connected_connector() const; 44 45 DrmObject* get_object(uint32_t id) const; 46 Connector* get_connector(uint32_t id) const; 47 Crtc* get_crtc(uint32_t id) const; 48 Encoder* get_encoder(uint32_t id) const; 49 Plane* get_plane(uint32_t id) const; 50 Property* get_prop(uint32_t id) const; 51 is_master()52 bool is_master() const { return m_is_master; } has_atomic()53 bool has_atomic() const { return m_has_atomic; } has_universal_planes()54 bool has_universal_planes() const { return m_has_universal_planes; } has_dumb_buffers()55 bool has_dumb_buffers() const { return m_has_dumb; } 56 bool has_kms() const; 57 get_connectors()58 std::vector<Connector*> get_connectors() const { return m_connectors; } get_encoders()59 std::vector<Encoder*> get_encoders() const { return m_encoders; } get_crtcs()60 std::vector<Crtc*> get_crtcs() const { return m_crtcs; } get_planes()61 std::vector<Plane*> get_planes() const { return m_planes; } get_properties()62 std::vector<Property*> get_properties() const { return m_properties; } 63 64 std::vector<DrmObject*> get_objects() const; 65 66 std::vector<Pipeline> get_connected_pipelines(); 67 68 void call_page_flip_handlers(); 69 70 int disable_all(); 71 version_name()72 const std::string& version_name() const { return m_version.name; } version()73 const CardVersion& version() const { return m_version; } 74 75 private: 76 void setup(); 77 void restore_modes(); 78 79 std::map<uint32_t, DrmObject*> m_obmap; 80 81 std::vector<Connector*> m_connectors; 82 std::vector<Encoder*> m_encoders; 83 std::vector<Crtc*> m_crtcs; 84 std::vector<Plane*> m_planes; 85 std::vector<Property*> m_properties; 86 std::vector<Framebuffer*> m_framebuffers; 87 88 int m_fd; 89 unsigned int m_minor; 90 bool m_is_master; 91 92 bool m_has_atomic; 93 bool m_has_universal_planes; 94 bool m_has_dumb; 95 96 CardVersion m_version; 97 }; 98 } // namespace kms 99