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 <tuple> 22 23 #include "DrmConnector.h" 24 #include "DrmCrtc.h" 25 #include "DrmEncoder.h" 26 #include "utils/fd.h" 27 28 namespace android { 29 30 class DrmFbImporter; 31 class DrmPlane; 32 class ResourceManager; 33 34 class DrmDevice { 35 public: 36 ~DrmDevice() = default; 37 38 static auto CreateInstance(std::string const &path, ResourceManager *res_man) 39 -> std::unique_ptr<DrmDevice>; 40 GetFd()41 auto &GetFd() const { 42 return fd_; 43 } 44 GetResMan()45 auto &GetResMan() { 46 return *res_man_; 47 } 48 49 auto GetConnectors() -> const std::vector<std::unique_ptr<DrmConnector>> &; 50 auto GetWritebackConnectors() 51 -> const std::vector<std::unique_ptr<DrmConnector>> &; 52 auto GetPlanes() -> const std::vector<std::unique_ptr<DrmPlane>> &; 53 auto GetCrtcs() -> const std::vector<std::unique_ptr<DrmCrtc>> &; 54 auto GetEncoders() -> const std::vector<std::unique_ptr<DrmEncoder>> &; 55 GetMinResolution()56 auto GetMinResolution() const { 57 return min_resolution_; 58 } 59 GetMaxResolution()60 auto GetMaxResolution() const { 61 return max_resolution_; 62 } 63 64 std::string GetName() const; 65 66 auto RegisterUserPropertyBlob(void *data, size_t length) const 67 -> DrmModeUserPropertyBlobUnique; 68 HasAddFb2ModifiersSupport()69 auto HasAddFb2ModifiersSupport() const { 70 return HasAddFb2ModifiersSupport_; 71 } 72 GetDrmFbImporter()73 auto &GetDrmFbImporter() { 74 return *drm_fb_importer_; 75 } 76 77 auto FindCrtcById(uint32_t id) const -> DrmCrtc * { 78 for (const auto &crtc : crtcs_) { 79 if (crtc->GetId() == id) { 80 return crtc.get(); 81 } 82 }; 83 84 return nullptr; 85 } 86 87 auto FindEncoderById(uint32_t id) const -> DrmEncoder * { 88 for (const auto &enc : encoders_) { 89 if (enc->GetId() == id) { 90 return enc.get(); 91 } 92 }; 93 94 return nullptr; 95 } 96 97 int GetProperty(uint32_t obj_id, uint32_t obj_type, const char *prop_name, 98 DrmProperty *property) const; 99 100 private: 101 explicit DrmDevice(ResourceManager *res_man); 102 auto Init(const char *path) -> int; 103 104 static auto IsKMSDev(const char *path) -> bool; 105 106 SharedFd fd_; 107 108 std::vector<std::unique_ptr<DrmConnector>> connectors_; 109 std::vector<std::unique_ptr<DrmConnector>> writeback_connectors_; 110 std::vector<std::unique_ptr<DrmEncoder>> encoders_; 111 std::vector<std::unique_ptr<DrmCrtc>> crtcs_; 112 std::vector<std::unique_ptr<DrmPlane>> planes_; 113 114 std::pair<uint32_t, uint32_t> min_resolution_; 115 std::pair<uint32_t, uint32_t> max_resolution_; 116 117 bool HasAddFb2ModifiersSupport_{}; 118 119 std::unique_ptr<DrmFbImporter> drm_fb_importer_; 120 121 ResourceManager *const res_man_; 122 }; 123 } // namespace android 124