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 CPP_DISPLAYPROXY_INCLUDE_CARDISPLAYPROXYSERVICE_H_ 18 #define CPP_DISPLAYPROXY_INCLUDE_CARDISPLAYPROXYSERVICE_H_ 19 20 #include <aidl/android/frameworks/automotive/display/BnCarDisplayProxy.h> 21 #include <gui/Surface.h> 22 #include <gui/SurfaceControl.h> 23 #include <ui/DisplayMode.h> 24 #include <ui/DisplayState.h> 25 26 namespace aidl::android::frameworks::automotive::display::implementation { 27 28 struct DisplayRecord { 29 ::android::sp<::android::IBinder> token; 30 ::android::sp<::android::SurfaceControl> surfaceControl; 31 }; 32 33 class CarDisplayProxy : public ::aidl::android::frameworks::automotive::display::BnCarDisplayProxy { 34 public: ~CarDisplayProxy()35 ~CarDisplayProxy() { mSurfaceList.clear(); } 36 37 // Methods from ::aidl::android::frameworks::automotive::display::ICarDisplayProxy 38 ::ndk::ScopedAStatus getDisplayIdList(std::vector<int64_t>* _aidl_return) override; 39 ::ndk::ScopedAStatus getDisplayInfo( 40 int64_t id, 41 ::aidl::android::frameworks::automotive::display::DisplayDesc* _aidl_return) override; 42 ::ndk::ScopedAStatus getHGraphicBufferProducer( 43 int64_t id, ::aidl::android::hardware::common::NativeHandle* _aidl_return) override; 44 ::ndk::ScopedAStatus hideWindow(int64_t id) override; 45 ::ndk::ScopedAStatus showWindow(int64_t id) override; 46 ::ndk::ScopedAStatus getSurface(int64_t id, 47 ::aidl::android::view::Surface* _aidl_return) override; 48 49 private: getDisplayPort(uint64_t id)50 uint8_t getDisplayPort(uint64_t id) { return (id & 0xF); } 51 ::android::sp<::android::IBinder> getDisplayInfoFromSurfaceComposerClient( 52 int64_t id, ::android::ui::DisplayMode* displayMode, 53 ::android::ui::DisplayState* displayState); 54 ::ndk::ScopedAStatus getDisplayRecord( 55 int64_t id, ::android::sp<::android::IBinder>* outDisplayToken, 56 ::android::sp<::android::SurfaceControl>* outSurfaceControl); 57 58 // Bookkeeping display records and Surface objects. Because this service is 59 // single-threaded, these variables are not needed to be protected 60 // explicitly. 61 std::unordered_map<uint64_t, DisplayRecord> mDisplays; 62 std::unordered_map<uint64_t, ::android::sp<::android::Surface>> mSurfaceList; 63 }; 64 65 } // namespace aidl::android::frameworks::automotive::display::implementation 66 67 #endif // CPP_DISPLAYPROXY_INCLUDE_CARDISPLAYPROXYSERVICE_H_ 68