blob: fa131709cad4eb411cf93866dcb357d53dea1da8 [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
Sean Pauled2ec4b2016-03-10 15:35:40 -050040 // Device functions
41 HWC2::Error CreateVirtualDisplay(uint32_t width, uint32_t height,
Sean Paulf72cccd2018-08-27 13:59:08 -040042 int32_t *format, hwc2_display_t *display);
Sean Pauled2ec4b2016-03-10 15:35:40 -050043 HWC2::Error DestroyVirtualDisplay(hwc2_display_t display);
Roman Stratiienko0d1a2cd2019-11-28 17:51:16 +020044 void Dump(uint32_t *outSize, char *outBuffer);
Sean Pauled2ec4b2016-03-10 15:35:40 -050045 uint32_t GetMaxVirtualDisplayCount();
46 HWC2::Error RegisterCallback(int32_t descriptor, hwc2_callback_data_t data,
47 hwc2_function_pointer_t function);
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +030048 HWC2::Error CreateDisplay(hwc2_display_t displ, HWC2::DisplayType type);
Roman Stratiienko26fd2b22022-01-04 12:59:29 +020049
Roman Stratiienko938a7422022-01-29 00:10:07 +020050 auto GetDisplay(hwc2_display_t display_handle) {
51 return displays_.count(display_handle) != 0 ? &displays_.at(display_handle)
52 : nullptr;
53 }
54
Roman Stratiienko74923582022-01-17 11:24:21 +020055 auto &GetResMan() {
56 return resource_manager_;
57 }
58
Roman Stratiienko26fd2b22022-01-04 12:59:29 +020059 private:
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +030060 void HandleDisplayHotplug(hwc2_display_t displayid, int state);
61 void HandleInitialHotplugState(DrmDevice *drmDevice);
Sean Pauled2ec4b2016-03-10 15:35:40 -050062
Roman Stratiienko1e053b42021-10-25 22:54:20 +030063 void HandleHotplugUEvent();
64
Alexandru Gheorghec5463582018-03-27 15:52:02 +010065 ResourceManager resource_manager_;
Sean Pauled2ec4b2016-03-10 15:35:40 -050066 std::map<hwc2_display_t, HwcDisplay> displays_;
Roman Stratiienko0d1a2cd2019-11-28 17:51:16 +020067
68 std::string mDumpString;
Sean Pauled2ec4b2016-03-10 15:35:40 -050069};
Sean Paulf72cccd2018-08-27 13:59:08 -040070} // namespace android
Matvii Zorin0ddc3292020-07-27 18:29:15 +030071
72#endif