blob: 27cfc3b0890c00d20b88a5a95d48371fefe92d05 [file] [log] [blame]
Sean Paulda6270d2015-06-01 14:11:52 -04001/*
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +03002 * Copyright (C) 2020 The Android Open Source Project
Sean Paulda6270d2015-06-01 14:11:52 -04003 *
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 Paul5d8acfc2016-04-21 16:26:27 -040017#ifndef ANDROID_PLATFORM_DRM_GENERIC_H_
18#define ANDROID_PLATFORM_DRM_GENERIC_H_
Sean Paulda6270d2015-06-01 14:11:52 -040019
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030020#include <drm/drm_fourcc.h>
Sean Paulda6270d2015-06-01 14:11:52 -040021#include <hardware/gralloc.h>
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030022
Vincent Donnefortf67c3652019-08-02 11:18:35 +010023#include <map>
Sean Paulda6270d2015-06-01 14:11:52 -040024
Roman Stratiienko13cc3662020-08-29 21:35:39 +030025#include "drm/DrmDevice.h"
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030026#include "drmhwcgralloc.h"
Roman Stratiienko6f5e4502019-11-27 19:23:03 +020027
28#ifndef DRM_FORMAT_INVALID
29#define DRM_FORMAT_INVALID 0
30#endif
31
Sean Paulda6270d2015-06-01 14:11:52 -040032namespace android {
33
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030034class Importer {
35 public:
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +020036 virtual ~Importer() = default;
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030037
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 Paulda6270d2015-06-01 14:11:52 -040051class DrmGenericImporter : public Importer {
52 public:
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +010053 DrmGenericImporter(DrmDevice *drm);
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +020054 ~DrmGenericImporter() override = default;
Sean Paulda6270d2015-06-01 14:11:52 -040055
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030056 int ImportBuffer(hwc_drm_bo_t *bo) override;
Haixia Shi479412c2015-10-27 10:40:48 -070057 int ReleaseBuffer(hwc_drm_bo_t *bo) override;
Vincent Donnefortf67c3652019-08-02 11:18:35 +010058 int ImportHandle(uint32_t gem_handle);
59 int ReleaseHandle(uint32_t gem_handle);
Sean Paulda6270d2015-06-01 14:11:52 -040060
Mykhailo Sopihaad438862019-06-06 14:45:27 +030061 protected:
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +010062 DrmDevice *drm_;
Sean Paulda6270d2015-06-01 14:11:52 -040063
Mykhailo Sopihaad438862019-06-06 14:45:27 +030064 private:
Vincent Donnefortf67c3652019-08-02 11:18:35 +010065 int CloseHandle(uint32_t gem_handle);
66 std::map<uint32_t, int> gem_refcount_;
Dennis Tsiang3a5fb502020-10-30 08:43:33 +000067 bool has_modifier_support_;
Sean Paulda6270d2015-06-01 14:11:52 -040068};
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030069
Sean Paulf72cccd2018-08-27 13:59:08 -040070} // namespace android
Sean Paulda6270d2015-06-01 14:11:52 -040071
72#endif