• 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 
createDisplayMode(PhysicalDisplayId displayId,DisplayModeId modeId,Fps refreshRate)36 inline DisplayModePtr createDisplayMode(PhysicalDisplayId displayId, DisplayModeId modeId,
37                                         Fps refreshRate) {
38     return createDisplayMode(modeId, refreshRate, {}, {}, displayId);
39 }
40 
cloneForDisplay(PhysicalDisplayId displayId,const DisplayModePtr & modePtr)41 inline DisplayModePtr cloneForDisplay(PhysicalDisplayId displayId, const DisplayModePtr& modePtr) {
42     return DisplayMode::Builder(modePtr->getHwcId())
43             .setId(modePtr->getId())
44             .setPhysicalDisplayId(displayId)
45             .setVsyncPeriod(modePtr->getVsyncPeriod())
46             .setGroup(modePtr->getGroup())
47             .setResolution(modePtr->getResolution())
48             .build();
49 }
50 
cloneForDisplay(PhysicalDisplayId displayId,const DisplayModes & modes)51 inline DisplayModes cloneForDisplay(PhysicalDisplayId displayId, const DisplayModes& modes) {
52     DisplayModes clones;
53 
54     for (const auto& [id, modePtr] : modes) {
55         clones.try_emplace(id, cloneForDisplay(displayId, modePtr));
56     }
57 
58     return clones;
59 }
60 
61 } // namespace android::mock
62