1 /* 2 * Copyright 2020 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 #pragma once 17 18 #include <android/hardware/graphics/composer/2.4/IComposerCallback.h> 19 20 #include <mutex> 21 #include <vector> 22 23 namespace android::hardware::graphics::composer::V2_4::vts { 24 25 using Display = V2_1::Display; 26 27 // IComposerCallback to be installed with IComposerClient::registerCallback. 28 class GraphicsComposerCallback : public IComposerCallback { 29 public: 30 void setVsyncAllowed(bool allowed); 31 32 std::vector<Display> getDisplays() const; 33 34 int32_t getInvalidHotplugCount() const; 35 36 int32_t getInvalidRefreshCount() const; 37 38 int32_t getInvalidVsyncCount() const; 39 40 int32_t getInvalidVsync_2_4Count() const; 41 42 int32_t getInvalidVsyncPeriodChangeCount() const; 43 44 int32_t getInvalidSeamlessPossibleCount() const; 45 46 std::optional<VsyncPeriodChangeTimeline> takeLastVsyncPeriodChangeTimeline(); 47 48 private: 49 Return<void> onHotplug(Display display, Connection connection) override; 50 Return<void> onRefresh(Display display) override; 51 Return<void> onVsync(Display display, int64_t) override; 52 Return<void> onVsync_2_4(Display display, int64_t, VsyncPeriodNanos vsyncPeriodNanos) override; 53 Return<void> onVsyncPeriodTimingChanged( 54 Display display, const VsyncPeriodChangeTimeline& updatedTimeline) override; 55 Return<void> onSeamlessPossible(Display display) override; 56 57 mutable std::mutex mMutex; 58 // the set of all currently connected displays 59 std::vector<Display> mDisplays; 60 // true only when vsync is enabled 61 bool mVsyncAllowed = true; 62 63 std::optional<VsyncPeriodChangeTimeline> mTimeline; 64 65 // track invalid callbacks 66 int32_t mInvalidHotplugCount = 0; 67 int32_t mInvalidRefreshCount = 0; 68 int32_t mInvalidVsyncCount = 0; 69 int32_t mInvalidVsync_2_4Count = 0; 70 int32_t mInvalidVsyncPeriodChangeCount = 0; 71 int32_t mInvalidSeamlessPossibleCount = 0; 72 }; 73 74 } // namespace android::hardware::graphics::composer::V2_4::vts 75