blob: d096160a567cbea3ec26603037a58e3720385e69 [file] [log] [blame]
Sean Pauled2ec4b2016-03-10 15:35:40 -05001/*
2 * Copyright (C) 2016 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
Matvii Zorin0ddc3292020-07-27 18:29:15 +030017#ifndef ANDROID_DRM_HWC_TWO_H_
18#define ANDROID_DRM_HWC_TWO_H_
19
Sean Pauled2ec4b2016-03-10 15:35:40 -050020#include <hardware/hwcomposer2.h>
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030021
Roman Stratiienko13cc3662020-08-29 21:35:39 +030022#include "drm/ResourceManager.h"
Roman Stratiienko3627beb2022-01-04 16:02:55 +020023#include "hwc2_device/HwcDisplay.h"
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030024
Sean Pauled2ec4b2016-03-10 15:35:40 -050025namespace android {
26
Roman Stratiienko26fd2b22022-01-04 12:59:29 +020027class DrmHwcTwo {
Sean Pauled2ec4b2016-03-10 15:35:40 -050028 public:
29 DrmHwcTwo();
30
Sean Paulac874152016-03-10 16:00:26 -050031 HWC2::Error Init();
32
Roman Stratiienko863a3c22021-09-29 13:00:29 +030033 std::pair<HWC2_PFN_HOTPLUG, hwc2_callback_data_t> hotplug_callback_{};
34 std::pair<HWC2_PFN_VSYNC, hwc2_callback_data_t> vsync_callback_{};
Roman Stratiienko11ef8c52021-09-29 13:01:39 +030035#if PLATFORM_SDK_VERSION > 29
36 std::pair<HWC2_PFN_VSYNC_2_4, hwc2_callback_data_t> vsync_2_4_callback_{};
37#endif
Roman Stratiienko863a3c22021-09-29 13:00:29 +030038 std::pair<HWC2_PFN_REFRESH, hwc2_callback_data_t> refresh_callback_{};
Roman Stratiienko23701092020-09-26 02:08:41 +030039
Roman Stratiienko863a3c22021-09-29 13:00:29 +030040 std::mutex callback_lock_;
Roman Stratiienko23701092020-09-26 02:08:41 +030041
Vincent Donnefort315444c2019-10-09 14:23:42 +010042 static HwcDisplay *GetDisplay(DrmHwcTwo *hwc, hwc2_display_t display_handle) {
43 auto it = hwc->displays_.find(display_handle);
44 if (it == hwc->displays_.end())
45 return nullptr;
46
47 return &it->second;
48 }
49
Sean Pauled2ec4b2016-03-10 15:35:40 -050050 // Device functions
51 HWC2::Error CreateVirtualDisplay(uint32_t width, uint32_t height,
Sean Paulf72cccd2018-08-27 13:59:08 -040052 int32_t *format, hwc2_display_t *display);
Sean Pauled2ec4b2016-03-10 15:35:40 -050053 HWC2::Error DestroyVirtualDisplay(hwc2_display_t display);
Roman Stratiienko0d1a2cd2019-11-28 17:51:16 +020054 void Dump(uint32_t *outSize, char *outBuffer);
Sean Pauled2ec4b2016-03-10 15:35:40 -050055 uint32_t GetMaxVirtualDisplayCount();
56 HWC2::Error RegisterCallback(int32_t descriptor, hwc2_callback_data_t data,
57 hwc2_function_pointer_t function);
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +030058 HWC2::Error CreateDisplay(hwc2_display_t displ, HWC2::DisplayType type);
Roman Stratiienko26fd2b22022-01-04 12:59:29 +020059
60 private:
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +030061 void HandleDisplayHotplug(hwc2_display_t displayid, int state);
62 void HandleInitialHotplugState(DrmDevice *drmDevice);
Sean Pauled2ec4b2016-03-10 15:35:40 -050063
Roman Stratiienko1e053b42021-10-25 22:54:20 +030064 void HandleHotplugUEvent();
65
Alexandru Gheorghec5463582018-03-27 15:52:02 +010066 ResourceManager resource_manager_;
Sean Pauled2ec4b2016-03-10 15:35:40 -050067 std::map<hwc2_display_t, HwcDisplay> displays_;
Roman Stratiienko0d1a2cd2019-11-28 17:51:16 +020068
69 std::string mDumpString;
Sean Pauled2ec4b2016-03-10 15:35:40 -050070};
Sean Paulf72cccd2018-08-27 13:59:08 -040071} // namespace android
Matvii Zorin0ddc3292020-07-27 18:29:15 +030072
73#endif