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_DM_DISPLAY_MANAGER_H 17 #define FOUNDATION_DM_DISPLAY_MANAGER_H 18 19 #include <vector> 20 #include <mutex> 21 #include <pixel_map.h> 22 23 #include "display.h" 24 #include "dm_common.h" 25 #include "wm_single_instance.h" 26 #include "screenshot_info.h" 27 28 namespace OHOS::Rosen { 29 class DisplayManager { 30 WM_DECLARE_SINGLE_INSTANCE_BASE(DisplayManager); 31 friend class DMSDeathRecipient; 32 public: 33 class IDisplayListener : public virtual RefBase { 34 public: 35 virtual void OnCreate(DisplayId) = 0; 36 virtual void OnDestroy(DisplayId) = 0; 37 virtual void OnChange(DisplayId) = 0; 38 }; 39 40 class IScreenshotListener : public virtual RefBase { 41 public: OnScreenshot(const ScreenshotInfo info)42 virtual void OnScreenshot(const ScreenshotInfo info) {} 43 }; 44 45 std::vector<sptr<Display>> GetAllDisplays(); 46 DisplayId GetDefaultDisplayId(); 47 sptr<Display> GetDefaultDisplay(); 48 sptr<Display> GetDefaultDisplaySync(); 49 sptr<Display> GetDisplayById(DisplayId displayId); 50 sptr<Display> GetDisplayByScreen(ScreenId screenId); 51 std::vector<DisplayId> GetAllDisplayIds(); 52 DMError HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow); 53 54 std::shared_ptr<Media::PixelMap> GetScreenshot(DisplayId displayId); 55 std::shared_ptr<Media::PixelMap> GetScreenshot(DisplayId displayId, const Media::Rect &rect, 56 const Media::Size &size, int rotation); 57 bool WakeUpBegin(PowerStateChangeReason reason); 58 bool WakeUpEnd(); 59 bool SuspendBegin(PowerStateChangeReason reason); 60 bool SuspendEnd(); 61 bool SetDisplayState(DisplayState state, DisplayStateCallback callback); 62 DisplayState GetDisplayState(DisplayId displayId); 63 bool SetScreenBrightness(uint64_t screenId, uint32_t level); 64 uint32_t GetScreenBrightness(uint64_t screenId) const; 65 void NotifyDisplayEvent(DisplayEvent event); 66 bool Freeze(std::vector<DisplayId> displayIds); 67 bool Unfreeze(std::vector<DisplayId> displayIds); 68 69 bool RegisterDisplayListener(sptr<IDisplayListener> listener); 70 bool UnregisterDisplayListener(sptr<IDisplayListener> listener); 71 bool RegisterDisplayPowerEventListener(sptr<IDisplayPowerEventListener> listener); 72 bool UnregisterDisplayPowerEventListener(sptr<IDisplayPowerEventListener> listener); 73 bool RegisterScreenshotListener(sptr<IScreenshotListener> listener); 74 bool UnregisterScreenshotListener(sptr<IScreenshotListener> listener); 75 76 constexpr static int32_t MAX_RESOLUTION_SIZE_SCREENSHOT = 3840; // max resolution, 4K 77 78 private: 79 DisplayManager(); 80 ~DisplayManager(); 81 void OnRemoteDied(); 82 83 class Impl; 84 std::recursive_mutex mutex_; 85 bool destroyed_ = false; 86 sptr<Impl> pImpl_; 87 }; 88 } // namespace OHOS::Rosen 89 90 #endif // FOUNDATION_DM_DISPLAY_MANAGER_H