1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <cstdint> 20 #include <map> 21 #include <optional> 22 #include <tuple> 23 24 #include "DrmConnector.h" 25 #include "DrmCrtc.h" 26 #include "DrmEncoder.h" 27 #include "bufferinfo/BufferInfo.h" 28 #include "utils/fd.h" 29 30 namespace android { 31 32 class DrmFbImporter; 33 class DrmPlane; 34 class ResourceManager; 35 36 class DrmDevice { 37 public: 38 ~DrmDevice() = default; 39 40 static auto CreateInstance(std::string const &path, ResourceManager *res_man, 41 uint32_t index) -> std::unique_ptr<DrmDevice>; 42 GetFd()43 auto &GetFd() const { 44 return fd_; 45 } 46 GetIndexInDevArray()47 auto GetIndexInDevArray() const { 48 return index_in_dev_array_; 49 } 50 GetResMan()51 auto &GetResMan() { 52 return *res_man_; 53 } 54 55 auto GetConnectors() -> const std::vector<std::unique_ptr<DrmConnector>> &; 56 auto GetWritebackConnectors() 57 -> const std::vector<std::unique_ptr<DrmConnector>> &; 58 auto GetPlanes() -> const std::vector<std::unique_ptr<DrmPlane>> &; 59 auto GetCrtcs() -> const std::vector<std::unique_ptr<DrmCrtc>> &; 60 auto GetEncoders() -> const std::vector<std::unique_ptr<DrmEncoder>> &; 61 GetMinResolution()62 auto GetMinResolution() const { 63 return min_resolution_; 64 } 65 GetMaxResolution()66 auto GetMaxResolution() const { 67 return max_resolution_; 68 } 69 70 std::string GetName() const; 71 72 auto RegisterUserPropertyBlob(void *data, size_t length) const 73 -> DrmModeUserPropertyBlobUnique; 74 HasAddFb2ModifiersSupport()75 auto HasAddFb2ModifiersSupport() const { 76 return HasAddFb2ModifiersSupport_; 77 } 78 79 auto CreateBufferForModeset(uint32_t width, uint32_t height) 80 -> std::optional<BufferInfo>; 81 GetDrmFbImporter()82 auto &GetDrmFbImporter() { 83 return *drm_fb_importer_; 84 } 85 86 auto FindCrtcById(uint32_t id) const -> DrmCrtc * { 87 for (const auto &crtc : crtcs_) { 88 if (crtc->GetId() == id) { 89 return crtc.get(); 90 } 91 }; 92 93 return nullptr; 94 } 95 96 auto FindEncoderById(uint32_t id) const -> DrmEncoder * { 97 for (const auto &enc : encoders_) { 98 if (enc->GetId() == id) { 99 return enc.get(); 100 } 101 }; 102 103 return nullptr; 104 } 105 106 int GetProperty(uint32_t obj_id, uint32_t obj_type, const char *prop_name, 107 DrmProperty *property) const; 108 GetCapCursorSize()109 const std::optional<std::pair<uint64_t, uint64_t>> &GetCapCursorSize() const { 110 return cap_cursor_size_; 111 } 112 113 private: 114 explicit DrmDevice(ResourceManager *res_man, uint32_t index); 115 auto Init(const char *path) -> int; 116 117 static auto IsKMSDev(const char *path) -> bool; 118 119 SharedFd fd_; 120 const uint32_t index_in_dev_array_; 121 122 std::vector<std::unique_ptr<DrmConnector>> connectors_; 123 std::vector<std::unique_ptr<DrmConnector>> writeback_connectors_; 124 std::vector<std::unique_ptr<DrmEncoder>> encoders_; 125 std::vector<std::unique_ptr<DrmCrtc>> crtcs_; 126 std::vector<std::unique_ptr<DrmPlane>> planes_; 127 128 std::pair<uint32_t, uint32_t> min_resolution_; 129 std::pair<uint32_t, uint32_t> max_resolution_; 130 std::optional<std::pair<uint64_t, uint64_t>> cap_cursor_size_; 131 132 bool HasAddFb2ModifiersSupport_{}; 133 134 std::unique_ptr<DrmFbImporter> drm_fb_importer_; 135 136 ResourceManager *const res_man_; 137 }; 138 139 } // namespace android 140