1 /* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FOUNDATION_DMSERVER_ABSTRACT_DISPLAY_CONTROLLER_H 17 #define FOUNDATION_DMSERVER_ABSTRACT_DISPLAY_CONTROLLER_H 18 19 #include "abstract_screen_controller.h" 20 21 #include <map> 22 #include <pixel_map.h> 23 #include <surface.h> 24 #include <transaction/rs_interfaces.h> 25 26 #include "screen.h" 27 #include "abstract_display.h" 28 #include "display_change_listener.h" 29 #include "future.h" 30 31 namespace OHOS::Rosen { 32 class AbstractDisplayController : public RefBase { 33 using DisplayStateChangeListener = std::function<void(DisplayId, sptr<DisplayInfo>, 34 const std::map<DisplayId, sptr<DisplayInfo>>&, DisplayStateChangeType)>; 35 public: 36 AbstractDisplayController(std::recursive_mutex& mutex, DisplayStateChangeListener); 37 ~AbstractDisplayController(); 38 WM_DISALLOW_COPY_AND_MOVE(AbstractDisplayController); 39 40 void Init(sptr<AbstractScreenController> abstractScreenController); 41 ScreenId GetDefaultScreenId(); 42 RSScreenModeInfo GetScreenActiveMode(ScreenId id); 43 44 std::shared_ptr<Media::PixelMap> GetScreenSnapshot(DisplayId displayId); 45 sptr<AbstractDisplay> GetAbstractDisplay(DisplayId displayId) const; 46 sptr<AbstractDisplay> GetAbstractDisplayByScreen(ScreenId screenId) const; 47 std::vector<DisplayId> GetAllDisplayIds() const; 48 void SetFreeze(std::vector<DisplayId> displayIds, bool isFreeze); 49 50 private: 51 void OnAbstractScreenConnect(sptr<AbstractScreen> absScreen); 52 void OnAbstractScreenDisconnect(sptr<AbstractScreen> absScreen); 53 void OnAbstractScreenChange(sptr<AbstractScreen> absScreen, DisplayChangeEvent event); 54 void ProcessDisplayUpdateOrientation(sptr<AbstractScreen> absScreen, DisplayStateChangeType type); 55 void ProcessDisplaySizeChange(sptr<AbstractScreen> absScreen); 56 void ProcessVirtualPixelRatioChange(sptr<AbstractScreen> absScreen); 57 void ProcessDisplayRotationChange(sptr<AbstractScreen> absScreen, DisplayStateChangeType type); 58 void ProcessDisplayCompression(sptr<AbstractScreen> absScreen); 59 sptr<AbstractDisplay> GetAbstractDisplayByAbsScreen(sptr<AbstractScreen> absScreen); 60 void BindAloneScreenLocked(sptr<AbstractScreen> absScreen); 61 void AddScreenToMirrorLocked(sptr<AbstractScreen> absScreen); 62 void AddScreenToExpandLocked(sptr<AbstractScreen> absScreen); 63 std::map<DisplayId, sptr<DisplayInfo>> GetAllDisplayInfoOfGroup(sptr<DisplayInfo> info); 64 DisplayId ProcessNormalScreenDisconnected( 65 sptr<AbstractScreen> absScreen, sptr<AbstractScreenGroup> screenGroup, sptr<AbstractDisplay>& absDisplay); 66 DisplayId ProcessExpandScreenDisconnected( 67 sptr<AbstractScreen> absScreen, sptr<AbstractScreenGroup> screenGroup, sptr<AbstractDisplay>& absDisplay); 68 bool UpdateDisplaySize(sptr<AbstractDisplay> absDisplay, sptr<SupportedScreenModes> info, 69 Point offset = Point(0, 0)); 70 void SetDisplayStateChangeListener(sptr<AbstractDisplay> abstractDisplay, DisplayStateChangeType type); 71 DisplayId GetDefaultDisplayId(); 72 73 std::recursive_mutex& mutex_; 74 std::atomic<DisplayId> displayCount_ { 0 }; 75 sptr<AbstractDisplay> dummyDisplay_; 76 std::map<DisplayId, sptr<AbstractDisplay>> abstractDisplayMap_; 77 sptr<AbstractScreenController> abstractScreenController_; 78 sptr<AbstractScreenController::AbstractScreenCallback> abstractScreenCallback_; 79 OHOS::Rosen::RSInterfaces& rsInterface_; 80 DisplayStateChangeListener displayStateChangeListener_; 81 }; 82 } // namespace OHOS::Rosen 83 #endif // FOUNDATION_DMSERVER_ABSTRACT_DISPLAY_CONTROLLER_H