blob: ca537620d16cf5f4481be5fb4fee29d34c4946dc [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:
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
Sean Paulda6270d2015-06-01 14:11:52 -040052class DrmGenericImporter : public Importer {
53 public:
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +010054 DrmGenericImporter(DrmDevice *drm);
Haixia Shi479412c2015-10-27 10:40:48 -070055 ~DrmGenericImporter() override;
Sean Paulda6270d2015-06-01 14:11:52 -040056
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030057 int ImportBuffer(hwc_drm_bo_t *bo) override;
Haixia Shi479412c2015-10-27 10:40:48 -070058 int ReleaseBuffer(hwc_drm_bo_t *bo) override;
Vincent Donnefortf67c3652019-08-02 11:18:35 +010059 int ImportHandle(uint32_t gem_handle);
60 int ReleaseHandle(uint32_t gem_handle);
Sean Paulda6270d2015-06-01 14:11:52 -040061
Mykhailo Sopihaad438862019-06-06 14:45:27 +030062 protected:
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +010063 DrmDevice *drm_;
Sean Paulda6270d2015-06-01 14:11:52 -040064
Mykhailo Sopihaad438862019-06-06 14:45:27 +030065 private:
Vincent Donnefortf67c3652019-08-02 11:18:35 +010066 int CloseHandle(uint32_t gem_handle);
67 std::map<uint32_t, int> gem_refcount_;
Dennis Tsiang3a5fb502020-10-30 08:43:33 +000068 bool has_modifier_support_;
Sean Paulda6270d2015-06-01 14:11:52 -040069};
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030070
Sean Paulf72cccd2018-08-27 13:59:08 -040071} // namespace android
Sean Paulda6270d2015-06-01 14:11:52 -040072
73#endif