1 /* 2 * Copyright (C) 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 #ifndef HISTOGRAM_MEDIATOR_H_ 18 #define HISTOGRAM_MEDIATOR_H_ 19 20 #include <aidl/android/hardware/graphics/common/Rect.h> 21 #include <aidl/com/google/hardware/pixel/display/BnDisplay.h> 22 #include <aidl/com/google/hardware/pixel/display/HistogramErrorCode.h> 23 #include <aidl/com/google/hardware/pixel/display/HistogramPos.h> 24 #include <aidl/com/google/hardware/pixel/display/Priority.h> 25 #include <aidl/com/google/hardware/pixel/display/Weight.h> 26 #include <xf86drm.h> 27 #include <xf86drmMode.h> 28 29 #include <condition_variable> 30 #include <mutex> 31 #include <vector> 32 33 #define HWC2_INCLUDE_STRINGIFICATION 34 #define HWC2_USE_CPP11 35 #include <hardware/hwcomposer2.h> 36 #undef HWC2_INCLUDE_STRINGIFICATION 37 #undef HWC2_USE_CPP11 38 #include "ExynosDevice.h" 39 #include "ExynosDisplay.h" 40 #include "ExynosDisplayDrmInterfaceModule.h" 41 #include "ExynosDisplayInterface.h" 42 #include "ExynosLayer.h" 43 44 namespace histogram { 45 using RoiRect = ::aidl::android::hardware::graphics::common::Rect; 46 using Weight = ::aidl::com::google::hardware::pixel::display::Weight; 47 using HistogramPos = ::aidl::com::google::hardware::pixel::display::HistogramPos; 48 using Priority = ::aidl::com::google::hardware::pixel::display::Priority; 49 using HistogramErrorCode = ::aidl::com::google::hardware::pixel::display::HistogramErrorCode; 50 51 constexpr size_t HISTOGRAM_BINS_SIZE = 256; 52 constexpr size_t WEIGHT_SUM = 1024; 53 54 class HistogramMediator { 55 public: 56 HistogramMediator() = default; 57 HistogramMediator(ExynosDisplay *display); ~HistogramMediator()58 ~HistogramMediator() {} 59 60 bool isDisplayPowerOff(); 61 bool isSecureContentPresenting(); 62 HistogramErrorCode requestHist(); 63 HistogramErrorCode cancelHistRequest(); 64 HistogramErrorCode collectRoiLuma(std::vector<char16_t> *buf); 65 HistogramErrorCode setRoiWeightThreshold(const RoiRect roi, const Weight weight, 66 const HistogramPos pos); 67 RoiRect calRoi(RoiRect roi); 68 struct HistogramReceiver : public IDLHistogram { HistogramReceiverHistogramReceiver69 HistogramReceiver() : mHistData(){}; 70 void callbackHistogram(char16_t *bin) override; 71 uint16_t mHistData[HISTOGRAM_BINS_SIZE]; // luma buffer 72 std::condition_variable mHistData_cv; // for pullback data sync ctrl 73 bool mHistReq_pending = false; 74 std::mutex mDataCollectingMutex; // for data collecting operations 75 }; 76 uint32_t getFrameCount(); setSampleFrameCounter(int32_t id)77 void setSampleFrameCounter(int32_t id) { mSampledFrameCounter = id; } getSampleFrameCounter()78 uint32_t getSampleFrameCounter() { return mSampledFrameCounter; } histRequested()79 bool histRequested() { return mIDLHistogram->mHistReq_pending; } 80 81 private: 82 int calculateThreshold(const RoiRect &roi); 83 std::shared_ptr<HistogramReceiver> mIDLHistogram; 84 ExynosDisplay *mDisplay = nullptr; 85 uint32_t mSampledFrameCounter = 0; 86 }; 87 88 } // namespace histogram 89 90 #endif // HISTOGRAM_MEDIATOR_H_ 91