blob: 0e72251669545c95da929cb2eaf021775c8e5834 [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 Stratiienko3dacd472022-01-11 19:18:34 +020027class DrmHwcTwo : public PipelineToFrontendBindingInterface {
Sean Pauled2ec4b2016-03-10 15:35:40 -050028 public:
29 DrmHwcTwo();
Roman Stratiienko3dacd472022-01-11 19:18:34 +020030 ~DrmHwcTwo() override = default;
Sean Paulac874152016-03-10 16:00:26 -050031
Roman Stratiienko863a3c22021-09-29 13:00:29 +030032 std::pair<HWC2_PFN_HOTPLUG, hwc2_callback_data_t> hotplug_callback_{};
33 std::pair<HWC2_PFN_VSYNC, hwc2_callback_data_t> vsync_callback_{};
Roman Stratiienko11ef8c52021-09-29 13:01:39 +030034#if PLATFORM_SDK_VERSION > 29
35 std::pair<HWC2_PFN_VSYNC_2_4, hwc2_callback_data_t> vsync_2_4_callback_{};
Roman Stratiienkod0c035b2022-01-21 15:12:56 +020036 std::pair<HWC2_PFN_VSYNC_PERIOD_TIMING_CHANGED, hwc2_callback_data_t>
37 period_timing_changed_callback_{};
Roman Stratiienko11ef8c52021-09-29 13:01:39 +030038#endif
Roman Stratiienko863a3c22021-09-29 13:00:29 +030039 std::pair<HWC2_PFN_REFRESH, hwc2_callback_data_t> refresh_callback_{};
Roman Stratiienko23701092020-09-26 02:08:41 +030040
Sean Pauled2ec4b2016-03-10 15:35:40 -050041 // Device functions
42 HWC2::Error CreateVirtualDisplay(uint32_t width, uint32_t height,
Sean Paulf72cccd2018-08-27 13:59:08 -040043 int32_t *format, hwc2_display_t *display);
Sean Pauled2ec4b2016-03-10 15:35:40 -050044 HWC2::Error DestroyVirtualDisplay(hwc2_display_t display);
Roman Stratiienko0d1a2cd2019-11-28 17:51:16 +020045 void Dump(uint32_t *outSize, char *outBuffer);
Sean Pauled2ec4b2016-03-10 15:35:40 -050046 uint32_t GetMaxVirtualDisplayCount();
47 HWC2::Error RegisterCallback(int32_t descriptor, hwc2_callback_data_t data,
48 hwc2_function_pointer_t function);
Roman Stratiienko26fd2b22022-01-04 12:59:29 +020049
Roman Stratiienko938a7422022-01-29 00:10:07 +020050 auto GetDisplay(hwc2_display_t display_handle) {
Roman Stratiienko3dacd472022-01-11 19:18:34 +020051 return displays_.count(display_handle) != 0
52 ? displays_[display_handle].get()
53 : nullptr;
Roman Stratiienko938a7422022-01-29 00:10:07 +020054 }
55
Roman Stratiienko74923582022-01-17 11:24:21 +020056 auto &GetResMan() {
57 return resource_manager_;
58 }
59
Roman Stratiienko3dacd472022-01-11 19:18:34 +020060 void ScheduleHotplugEvent(hwc2_display_t displayid, bool connected) {
61 deferred_hotplug_events_[displayid] = connected;
62 }
Sean Pauled2ec4b2016-03-10 15:35:40 -050063
Roman Stratiienko3dacd472022-01-11 19:18:34 +020064 // PipelineToFrontendBindingInterface
65 bool BindDisplay(DrmDisplayPipeline *pipeline) override;
66 bool UnbindDisplay(DrmDisplayPipeline *pipeline) override;
67 void FinalizeDisplayBinding() override;
68
Roman Stratiienko099c3112022-01-20 11:50:54 +020069 void SendVsyncEventToClient(hwc2_display_t displayid, int64_t timestamp,
70 uint32_t vsync_period) const;
Roman Stratiienkod0c035b2022-01-21 15:12:56 +020071 void SendVsyncPeriodTimingChangedEventToClient(hwc2_display_t displayid,
72 int64_t timestamp) const;
Roman Stratiienko099c3112022-01-20 11:50:54 +020073
Roman Stratiienko3dacd472022-01-11 19:18:34 +020074 private:
75 void SendHotplugEventToClient(hwc2_display_t displayid, bool connected);
Roman Stratiienko1e053b42021-10-25 22:54:20 +030076
Alexandru Gheorghec5463582018-03-27 15:52:02 +010077 ResourceManager resource_manager_;
Roman Stratiienko3dacd472022-01-11 19:18:34 +020078 std::map<hwc2_display_t, std::unique_ptr<HwcDisplay>> displays_;
79 std::map<DrmDisplayPipeline *, hwc2_display_t> display_handles_;
Roman Stratiienko0d1a2cd2019-11-28 17:51:16 +020080
81 std::string mDumpString;
Roman Stratiienko3dacd472022-01-11 19:18:34 +020082
83 std::map<hwc2_display_t, bool> deferred_hotplug_events_;
84
85 uint32_t last_display_handle_ = kPrimaryDisplay;
Sean Pauled2ec4b2016-03-10 15:35:40 -050086};
Sean Paulf72cccd2018-08-27 13:59:08 -040087} // namespace android
Matvii Zorin0ddc3292020-07-27 18:29:15 +030088
89#endif