Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 1 | /* |
Roman Stratiienko | b2e9fe2 | 2020-10-03 10:52:36 +0300 | [diff] [blame] | 2 | * Copyright (C) 2020 The Android Open Source Project |
Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 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 | |
Sean Paul | 5d8acfc | 2016-04-21 16:26:27 -0400 | [diff] [blame] | 17 | #ifndef ANDROID_PLATFORM_DRM_GENERIC_H_ |
| 18 | #define ANDROID_PLATFORM_DRM_GENERIC_H_ |
Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 19 | |
Roman Stratiienko | aa3cd54 | 2020-08-29 11:26:16 +0300 | [diff] [blame] | 20 | #include <drm/drm_fourcc.h> |
Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 21 | #include <hardware/gralloc.h> |
Roman Stratiienko | aa3cd54 | 2020-08-29 11:26:16 +0300 | [diff] [blame] | 22 | |
Vincent Donnefort | f67c365 | 2019-08-02 11:18:35 +0100 | [diff] [blame] | 23 | #include <map> |
Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 24 | |
Roman Stratiienko | 13cc366 | 2020-08-29 21:35:39 +0300 | [diff] [blame] | 25 | #include "drm/DrmDevice.h" |
Roman Stratiienko | b2e9fe2 | 2020-10-03 10:52:36 +0300 | [diff] [blame] | 26 | #include "drmhwcgralloc.h" |
Roman Stratiienko | 6f5e450 | 2019-11-27 19:23:03 +0200 | [diff] [blame] | 27 | |
| 28 | #ifndef DRM_FORMAT_INVALID |
| 29 | #define DRM_FORMAT_INVALID 0 |
| 30 | #endif |
| 31 | |
Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 32 | namespace android { |
| 33 | |
Roman Stratiienko | b2e9fe2 | 2020-10-03 10:52:36 +0300 | [diff] [blame] | 34 | class Importer { |
| 35 | public: |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 36 | virtual ~Importer() = default; |
Roman Stratiienko | b2e9fe2 | 2020-10-03 10:52:36 +0300 | [diff] [blame] | 37 | |
| 38 | // Imports the buffer referred to by handle into bo. |
| 39 | // |
| 40 | // Note: This can be called from a different thread than ReleaseBuffer. The |
| 41 | // implementation is responsible for ensuring thread safety. |
| 42 | virtual int ImportBuffer(hwc_drm_bo_t *bo) = 0; |
| 43 | |
| 44 | // Releases the buffer object (ie: does the inverse of ImportBuffer) |
| 45 | // |
| 46 | // Note: This can be called from a different thread than ImportBuffer. The |
| 47 | // implementation is responsible for ensuring thread safety. |
| 48 | virtual int ReleaseBuffer(hwc_drm_bo_t *bo) = 0; |
| 49 | }; |
| 50 | |
Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 51 | class DrmGenericImporter : public Importer { |
| 52 | public: |
Alexandru Gheorghe | 0f5abd7 | 2018-05-01 14:37:10 +0100 | [diff] [blame] | 53 | DrmGenericImporter(DrmDevice *drm); |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 54 | ~DrmGenericImporter() override = default; |
Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 55 | |
Roman Stratiienko | b2e9fe2 | 2020-10-03 10:52:36 +0300 | [diff] [blame] | 56 | int ImportBuffer(hwc_drm_bo_t *bo) override; |
Haixia Shi | 479412c | 2015-10-27 10:40:48 -0700 | [diff] [blame] | 57 | int ReleaseBuffer(hwc_drm_bo_t *bo) override; |
Vincent Donnefort | f67c365 | 2019-08-02 11:18:35 +0100 | [diff] [blame] | 58 | int ImportHandle(uint32_t gem_handle); |
| 59 | int ReleaseHandle(uint32_t gem_handle); |
Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 60 | |
Mykhailo Sopiha | ad43886 | 2019-06-06 14:45:27 +0300 | [diff] [blame] | 61 | protected: |
Alexandru Gheorghe | 0f5abd7 | 2018-05-01 14:37:10 +0100 | [diff] [blame] | 62 | DrmDevice *drm_; |
Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 63 | |
Mykhailo Sopiha | ad43886 | 2019-06-06 14:45:27 +0300 | [diff] [blame] | 64 | private: |
Vincent Donnefort | f67c365 | 2019-08-02 11:18:35 +0100 | [diff] [blame] | 65 | int CloseHandle(uint32_t gem_handle); |
| 66 | std::map<uint32_t, int> gem_refcount_; |
Dennis Tsiang | 3a5fb50 | 2020-10-30 08:43:33 +0000 | [diff] [blame] | 67 | bool has_modifier_support_; |
Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 68 | }; |
Roman Stratiienko | b2e9fe2 | 2020-10-03 10:52:36 +0300 | [diff] [blame] | 69 | |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 70 | } // namespace android |
Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 71 | |
| 72 | #endif |