1 /* 2 * Copyright (C) 2023 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 #ifndef ANDROID_HWC_DRMSWAPCHAIN_H 17 #define ANDROID_HWC_DRMSWAPCHAIN_H 18 19 #include <android-base/unique_fd.h> 20 21 #include "Common.h" 22 #include "DrmClient.h" 23 24 namespace aidl::android::hardware::graphics::composer3::impl { 25 26 class DrmSwapchain { 27 public: 28 class Image { 29 public: 30 Image() = delete; 31 ~Image(); 32 int wait(); 33 void markAsInUse(::android::base::unique_fd useCompleteFenceFd); 34 const native_handle_t* getBuffer(); 35 const std::shared_ptr<DrmBuffer> getDrmBuffer(); 36 Image(Image&& other); 37 38 private: 39 Image(const native_handle_t*, std::shared_ptr<DrmBuffer>); 40 const native_handle_t* mBuffer = nullptr; 41 std::shared_ptr<DrmBuffer> mDrmBuffer; 42 ::android::base::unique_fd mLastUseFenceFd; 43 44 friend class DrmSwapchain; 45 }; 46 47 static std::unique_ptr<DrmSwapchain> create(uint32_t width, uint32_t height, uint32_t usage, 48 DrmClient* client, uint32_t numImages = 3); 49 Image* getNextImage(); 50 51 private: 52 DrmSwapchain(std::vector<Image> images); 53 std::vector<Image> mImages; 54 std::size_t mLastUsedIndex = 0; 55 }; 56 57 } // namespace aidl::android::hardware::graphics::composer3::impl 58 59 #endif