1 /*
2  * Copyright (C) 2021 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 <aidl/com/google/hardware/pixel/display/BnDisplay.h>
20 
21 #include "./histogram_mediator.h"
22 #include "ExynosDevice.h"
23 
24 namespace aidl {
25 namespace com {
26 namespace google {
27 namespace hardware {
28 namespace pixel {
29 namespace display {
30 
31 using aidl::android::hardware::common::NativeHandle;
32 using RoiRect = histogram::RoiRect;
33 using Weight = histogram::Weight;
34 using HistogramPos = histogram::HistogramPos;
35 using Priority = histogram::Priority;
36 using HistogramErrorCode = histogram::HistogramErrorCode;
37 
38 // Default implementation
39 class Display : public BnDisplay {
40 public:
Display(ExynosDisplay * display)41     Display(ExynosDisplay *display) : mDisplay(display), mMediator(display) {}
42 
43     ndk::ScopedAStatus isHbmSupported(bool *_aidl_return) override;
44     ndk::ScopedAStatus setHbmState(HbmState state) override;
45     ndk::ScopedAStatus getHbmState(HbmState *_aidl_return) override;
46     ndk::ScopedAStatus isLbeSupported(bool *_aidl_return) override;
47     ndk::ScopedAStatus setLbeState(LbeState state) override;
48     ndk::ScopedAStatus setLbeAmbientLight(int ambientLux) override;
49     ndk::ScopedAStatus getLbeState(LbeState *_aidl_return) override;
50     ndk::ScopedAStatus isLhbmSupported(bool *_aidl_return) override;
51     ndk::ScopedAStatus setLhbmState(bool enabled) override;
52     ndk::ScopedAStatus getLhbmState(bool *_aidl_return) override;
53     ndk::ScopedAStatus setCompensationImageHandle(const NativeHandle &native_handle,
54                                                   const std::string &imageName,
55                                                   int *_aidl_return) override;
56     ndk::ScopedAStatus setMinIdleRefreshRate(int fps, int *_aidl_return) override;
57     ndk::ScopedAStatus setRefreshRateThrottle(int delayMs, int *_aidl_return) override;
58     ndk::ScopedAStatus histogramSample(const RoiRect &roi, const Weight &weight, HistogramPos pos,
59                                        Priority pri, std::vector<char16_t> *histogrambuffer,
60                                        HistogramErrorCode *_aidl_return) override;
61     ndk::ScopedAStatus getPanelCalibrationStatus(PanelCalibrationStatus *_aidl_return) override;
62     ndk::ScopedAStatus isDbmSupported(bool *_aidl_return) override;
63     ndk::ScopedAStatus setDbmState(bool enabled) override;
64     ndk::ScopedAStatus setPeakRefreshRate(int rate) override;
65     ndk::ScopedAStatus setLowPowerMode(bool enabled) override;
66     ndk::ScopedAStatus isOperationRateSupported(bool *_aidl_return) override;
67     ndk::ScopedAStatus getHistogramCapability(HistogramCapability *_aidl_return) override;
68     ndk::ScopedAStatus registerHistogram(const ndk::SpAIBinder &token,
69                                          const HistogramConfig &histogramConfig,
70                                          HistogramErrorCode *_aidl_return) override;
71     ndk::ScopedAStatus queryHistogram(const ndk::SpAIBinder &token,
72                                       std::vector<char16_t> *histogramBuffer,
73                                       HistogramErrorCode *_aidl_return) override;
74     ndk::ScopedAStatus reconfigHistogram(const ndk::SpAIBinder &token,
75                                          const HistogramConfig &histogramConfig,
76                                          HistogramErrorCode *_aidl_return) override;
77     ndk::ScopedAStatus unregisterHistogram(const ndk::SpAIBinder &token,
78                                            HistogramErrorCode *_aidl_return) override;
79     ndk::ScopedAStatus setFixedTe2Rate(int rateHz, int* _aidl_return) override;
80     ndk::ScopedAStatus queryStats(DisplayStats::Tag tag,
81                                   std::optional<DisplayStats>* _aidl_return) override;
82     ndk::ScopedAStatus isProximitySensorStateCallbackSupported(bool* _aidl_return) override;
83     ndk::ScopedAStatus registerProximitySensorStateChangeCallback(
84             const std::shared_ptr<IDisplayProximitySensorCallback>& callback) override;
85 
86 private:
87     bool runMediator(const RoiRect &roi, const Weight &weight, const HistogramPos &pos,
88                        std::vector<char16_t> *histogrambuffer);
89     ExynosDisplay *mDisplay = nullptr;
90     histogram::HistogramMediator mMediator;
91 };
92 } // namespace display
93 } // namespace pixel
94 } // namespace hardware
95 } // namespace google
96 } // namespace com
97 } // namespace aidl
98