• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 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 
17 #pragma once
18 
19 #include "DisplayHardware/DisplayMode.h"
20 
21 namespace android::mock {
22 
23 inline DisplayModePtr createDisplayMode(
24         DisplayModeId modeId, Fps refreshRate, int32_t group = 0,
25         ui::Size resolution = ui::Size(1920, 1080),
26         PhysicalDisplayId displayId = PhysicalDisplayId::fromPort(0)) {
27     return DisplayMode::Builder(hal::HWConfigId(modeId.value()))
28             .setId(modeId)
29             .setPhysicalDisplayId(displayId)
30             .setVsyncPeriod(refreshRate.getPeriodNsecs())
31             .setGroup(group)
32             .setResolution(resolution)
33             .build();
34 }
35 
cloneForDisplay(PhysicalDisplayId displayId,const DisplayModePtr & modePtr)36 inline DisplayModePtr cloneForDisplay(PhysicalDisplayId displayId, const DisplayModePtr& modePtr) {
37     return DisplayMode::Builder(modePtr->getHwcId())
38             .setId(modePtr->getId())
39             .setPhysicalDisplayId(displayId)
40             .setVsyncPeriod(modePtr->getVsyncPeriod())
41             .setGroup(modePtr->getGroup())
42             .setResolution(modePtr->getResolution())
43             .build();
44 }
45 
cloneForDisplay(PhysicalDisplayId displayId,const DisplayModes & modes)46 inline DisplayModes cloneForDisplay(PhysicalDisplayId displayId, const DisplayModes& modes) {
47     DisplayModes clones;
48 
49     for (const auto& [id, modePtr] : modes) {
50         clones.try_emplace(id, cloneForDisplay(displayId, modePtr));
51     }
52 
53     return clones;
54 }
55 
56 } // namespace android::mock
57