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 <xf86drmMode.h> 20 21 #include <cstdint> 22 #include <vector> 23 24 #include "DrmCrtc.h" 25 #include "DrmProperty.h" 26 #include "compositor/LayerData.h" 27 28 namespace android { 29 30 class DrmDevice; 31 struct LayerData; 32 33 // NOLINTNEXTLINE(readability-identifier-naming) 34 struct drm_plane_size_hint_local { 35 __u16 width; 36 __u16 height; 37 }; 38 39 class DrmPlane : public PipelineBindable<DrmPlane> { 40 public: 41 DrmPlane(const DrmPlane &) = delete; 42 DrmPlane &operator=(const DrmPlane &) = delete; 43 44 static auto CreateInstance(DrmDevice &dev, uint32_t plane_id) 45 -> std::unique_ptr<DrmPlane>; 46 47 bool IsCrtcSupported(const DrmCrtc &crtc) const; 48 bool IsValidForLayer(LayerData *layer); 49 GetType()50 auto GetType() const { 51 return type_; 52 } 53 54 bool IsFormatSupported(uint32_t format) const; 55 bool HasNonRgbFormat() const; 56 57 auto AtomicSetState(drmModeAtomicReq &pset, LayerData &layer, uint32_t zpos, 58 uint32_t crtc_id, DstRectInfo &whole_display_rect) -> int; 59 auto AtomicDisablePlane(drmModeAtomicReq &pset) -> int; GetZPosProperty()60 auto &GetZPosProperty() const { 61 return zpos_property_; 62 } 63 GetId()64 auto GetId() const { 65 return plane_->plane_id; 66 } 67 68 bool HasCursorSizeConstraints() const; 69 70 private: DrmPlane(DrmDevice & dev,DrmModePlaneUnique plane)71 DrmPlane(DrmDevice &dev, DrmModePlaneUnique plane) 72 : drm_(&dev), plane_(std::move(plane)){}; 73 DrmDevice *const drm_; 74 DrmModePlaneUnique plane_; 75 76 enum class Presence { kOptional, kMandatory }; 77 78 auto Init() -> int; 79 auto GetPlaneProperty(const char *prop_name, DrmProperty &property, 80 Presence presence = Presence::kMandatory) -> bool; 81 bool IsBufferValidForCursorPlane(const BufferInfo &bi) const; 82 83 uint32_t type_{}; 84 85 std::vector<uint32_t> formats_; 86 87 DrmProperty crtc_property_; 88 DrmProperty fb_property_; 89 DrmProperty crtc_x_property_; 90 DrmProperty crtc_y_property_; 91 DrmProperty crtc_w_property_; 92 DrmProperty crtc_h_property_; 93 DrmProperty src_x_property_; 94 DrmProperty src_y_property_; 95 DrmProperty src_w_property_; 96 DrmProperty src_h_property_; 97 DrmProperty zpos_property_; 98 DrmProperty rotation_property_; 99 DrmProperty alpha_property_; 100 DrmProperty blend_property_; 101 DrmProperty in_fence_fd_property_; 102 DrmProperty color_encoding_property_; 103 DrmProperty color_range_property_; 104 DrmProperty size_hints_property_; 105 106 std::map<BufferBlendMode, uint64_t> blending_enum_map_; 107 std::map<BufferColorSpace, uint64_t> color_encoding_enum_map_; 108 std::map<BufferSampleRange, uint64_t> color_range_enum_map_; 109 uint64_t transform_enum_mask_ = DRM_MODE_ROTATE_0; 110 std::vector<drm_plane_size_hint_local> size_hints_; 111 }; 112 } // namespace android 113