summaryrefslogtreecommitdiff
path: root/libhwc2.1/histogram_mediator.h
blob: fa81e0ba794f641238940b168f2a60ca34a54380 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef HISTOGRAM_MEDIATOR_H_
#define HISTOGRAM_MEDIATOR_H_

#include <aidl/android/hardware/graphics/common/Rect.h>
#include <aidl/com/google/hardware/pixel/display/BnDisplay.h>
#include <aidl/com/google/hardware/pixel/display/HistogramErrorCode.h>
#include <aidl/com/google/hardware/pixel/display/HistogramPos.h>
#include <aidl/com/google/hardware/pixel/display/Priority.h>
#include <aidl/com/google/hardware/pixel/display/Weight.h>
#include <xf86drm.h>
#include <xf86drmMode.h>

#include <condition_variable>
#include <mutex>
#include <vector>

#define HWC2_INCLUDE_STRINGIFICATION
#define HWC2_USE_CPP11
#include <hardware/hwcomposer2.h>
#undef HWC2_INCLUDE_STRINGIFICATION
#undef HWC2_USE_CPP11
#include "ExynosDevice.h"
#include "ExynosDisplay.h"
#include "ExynosDisplayDrmInterfaceModule.h"
#include "ExynosDisplayInterface.h"
#include "ExynosLayer.h"

namespace histogram {
using RoiRect = ::aidl::android::hardware::graphics::common::Rect;
using Weight = ::aidl::com::google::hardware::pixel::display::Weight;
using HistogramPos = ::aidl::com::google::hardware::pixel::display::HistogramPos;
using Priority = ::aidl::com::google::hardware::pixel::display::Priority;
using HistogramErrorCode = ::aidl::com::google::hardware::pixel::display::HistogramErrorCode;

constexpr size_t HISTOGRAM_BINS_SIZE = 256;
constexpr size_t WEIGHT_SUM = 1024;

class HistogramMediator {
public:
    HistogramMediator() = default;
    HistogramMediator(ExynosDisplay *display);
    ~HistogramMediator() {}

    bool isDisplayPowerOff();
    bool isSecureContentPresenting();
    HistogramErrorCode requestHist();
    HistogramErrorCode cancelHistRequest();
    HistogramErrorCode collectRoiLuma(std::vector<char16_t> *buf);
    HistogramErrorCode setRoiWeightThreshold(const RoiRect &roi, const Weight &weight,
                                             const HistogramPos &pos);
    RoiRect calRoi(const RoiRect &roi);
    struct HistogramReceiver : public IDLHistogram {
        HistogramReceiver() : mHistData(){};
        void callbackHistogram(char16_t *bin) override;
        uint16_t mHistData[HISTOGRAM_BINS_SIZE]; // luma buffer
        std::condition_variable mHistData_cv;    // for pullback data sync ctrl
        bool mHistReq_pending = false;
        std::mutex mDataCollectingMutex; // for data collecting operations
    };
    uint32_t getFrameCount();
    void setSampleFrameCounter(int32_t id) { mSampledFrameCounter = id; }
    uint32_t getSampleFrameCounter() { return mSampledFrameCounter; }
    bool histRequested() { return mIDLHistogram->mHistReq_pending; }

private:
    int calculateThreshold(const RoiRect &roi);
    std::shared_ptr<HistogramReceiver> mIDLHistogram;
    ExynosDisplay *mDisplay = nullptr;
    uint32_t mSampledFrameCounter = 0;
};

} // namespace histogram

#endif // HISTOGRAM_MEDIATOR_H_