1 /* 2 * Copyright (C) 2020 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 #ifndef ANDROID_PLATFORM_DRM_GENERIC_H_ 18 #define ANDROID_PLATFORM_DRM_GENERIC_H_ 19 20 #include <drm/drm_fourcc.h> 21 #include <hardware/gralloc.h> 22 23 #include <map> 24 25 #include "drm/DrmDevice.h" 26 #include "drmhwcgralloc.h" 27 28 #ifndef DRM_FORMAT_INVALID 29 #define DRM_FORMAT_INVALID 0 30 #endif 31 32 namespace android { 33 34 class Importer { 35 public: ~Importer()36 virtual ~Importer() { 37 } 38 39 // Imports the buffer referred to by handle into bo. 40 // 41 // Note: This can be called from a different thread than ReleaseBuffer. The 42 // implementation is responsible for ensuring thread safety. 43 virtual int ImportBuffer(hwc_drm_bo_t *bo) = 0; 44 45 // Releases the buffer object (ie: does the inverse of ImportBuffer) 46 // 47 // Note: This can be called from a different thread than ImportBuffer. The 48 // implementation is responsible for ensuring thread safety. 49 virtual int ReleaseBuffer(hwc_drm_bo_t *bo) = 0; 50 }; 51 52 class DrmGenericImporter : public Importer { 53 public: 54 DrmGenericImporter(DrmDevice *drm); 55 ~DrmGenericImporter() override; 56 57 int ImportBuffer(hwc_drm_bo_t *bo) override; 58 int ReleaseBuffer(hwc_drm_bo_t *bo) override; 59 int ImportHandle(uint32_t gem_handle); 60 int ReleaseHandle(uint32_t gem_handle); 61 62 protected: 63 DrmDevice *drm_; 64 65 private: 66 int CloseHandle(uint32_t gem_handle); 67 std::map<uint32_t, int> gem_refcount_; 68 bool has_modifier_support_; 69 }; 70 71 } // namespace android 72 73 #endif 74