summaryrefslogtreecommitdiff
path: root/graphics/composer/aidl/vts/GraphicsComposerCallback.h
blob: e54da346f5fb0402bc2d77ce7d1e2927f0c5368c (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
/**
 * Copyright (c) 2021, 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.
 */
#pragma once

#include <aidl/android/hardware/graphics/composer3/BnComposerCallback.h>
#include <android-base/thread_annotations.h>
#include <mutex>
#include <vector>

namespace aidl::android::hardware::graphics::composer3::vts {

class GraphicsComposerCallback : public BnComposerCallback {
  public:
    void setVsyncAllowed(bool allowed);

    std::vector<int64_t> getDisplays() const;

    int32_t getInvalidHotplugCount() const;

    int32_t getInvalidRefreshCount() const;

    int32_t getInvalidVsyncCount() const;

    int32_t getInvalidVsyncPeriodChangeCount() const;

    int32_t getInvalidSeamlessPossibleCount() const;

    int32_t getVsyncIdleCount() const;

    int64_t getVsyncIdleTime() const;

    std::optional<VsyncPeriodChangeTimeline> takeLastVsyncPeriodChangeTimeline();

  private:
    virtual ::ndk::ScopedAStatus onHotplug(int64_t in_display, bool in_connected) override;
    virtual ::ndk::ScopedAStatus onRefresh(int64_t in_display) override;
    virtual ::ndk::ScopedAStatus onSeamlessPossible(int64_t in_display) override;
    virtual ::ndk::ScopedAStatus onVsync(int64_t in_display, int64_t in_timestamp,
                                         int32_t in_vsyncPeriodNanos) override;
    virtual ::ndk::ScopedAStatus onVsyncPeriodTimingChanged(
            int64_t in_display,
            const ::aidl::android::hardware::graphics::composer3::VsyncPeriodChangeTimeline&
                    in_updatedTimeline) override;
    virtual ::ndk::ScopedAStatus onVsyncIdle(int64_t in_display) override;

    mutable std::mutex mMutex;
    // the set of all currently connected displays
    std::vector<int64_t> mDisplays GUARDED_BY(mMutex);
    // true only when vsync is enabled
    bool mVsyncAllowed GUARDED_BY(mMutex) = true;

    std::optional<VsyncPeriodChangeTimeline> mTimeline GUARDED_BY(mMutex);

    int32_t mVsyncIdleCount GUARDED_BY(mMutex) = 0;
    int64_t mVsyncIdleTime GUARDED_BY(mMutex) = 0;

    // track invalid callbacks
    int32_t mInvalidHotplugCount GUARDED_BY(mMutex) = 0;
    int32_t mInvalidRefreshCount GUARDED_BY(mMutex) = 0;
    int32_t mInvalidVsyncCount GUARDED_BY(mMutex) = 0;
    int32_t mInvalidVsyncPeriodChangeCount GUARDED_BY(mMutex) = 0;
    int32_t mInvalidSeamlessPossibleCount GUARDED_BY(mMutex) = 0;
};

}  // namespace aidl::android::hardware::graphics::composer3::vts