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 #include <surface.h> 23 24 #include "display.h" 25 #include "dm_common.h" 26 #include "wm_single_instance.h" 27 28 namespace OHOS::Rosen { 29 class DisplayManager { 30 WM_DECLARE_SINGLE_INSTANCE_BASE(DisplayManager); 31 public: 32 class IDisplayListener : public virtual RefBase { 33 public: 34 virtual void OnCreate(DisplayId) = 0; 35 virtual void OnDestroy(DisplayId) = 0; 36 virtual void OnChange(DisplayId) = 0; 37 }; 38 39 std::vector<sptr<Display>> GetAllDisplays(); 40 DisplayId GetDefaultDisplayId(); 41 sptr<Display> GetDefaultDisplay(); 42 sptr<Display> GetDisplayById(DisplayId displayId); 43 sptr<Display> GetDisplayByScreen(ScreenId screenId); 44 std::vector<DisplayId> GetAllDisplayIds(); 45 bool RegisterDisplayListener(sptr<IDisplayListener> listener); 46 bool UnregisterDisplayListener(sptr<IDisplayListener> listener); 47 48 std::shared_ptr<Media::PixelMap> GetScreenshot(DisplayId displayId); 49 std::shared_ptr<Media::PixelMap> GetScreenshot(DisplayId displayId, const Media::Rect &rect, 50 const Media::Size &size, int rotation); 51 52 bool RegisterDisplayPowerEventListener(sptr<IDisplayPowerEventListener> listener); 53 bool UnregisterDisplayPowerEventListener(sptr<IDisplayPowerEventListener> listener); 54 bool WakeUpBegin(PowerStateChangeReason reason); 55 bool WakeUpEnd(); 56 bool SuspendBegin(PowerStateChangeReason reason); 57 bool SuspendEnd(); 58 bool SetDisplayState(DisplayState state, DisplayStateCallback callback); 59 DisplayState GetDisplayState(DisplayId displayId); 60 bool SetScreenBrightness(uint64_t screenId, uint32_t level); 61 uint32_t GetScreenBrightness(uint64_t screenId) const; 62 void NotifyDisplayEvent(DisplayEvent event); 63 bool Freeze(std::vector<DisplayId> displayIds); 64 bool Unfreeze(std::vector<DisplayId> displayIds); 65 constexpr static int32_t MAX_RESOLUTION_SIZE_SCREENSHOT = 3840; // max resolution, 4K 66 67 private: 68 DisplayManager(); 69 ~DisplayManager(); 70 71 class Impl; 72 sptr<Impl> pImpl_; 73 }; 74 } // namespace OHOS::Rosen 75 76 #endif // FOUNDATION_DM_DISPLAY_MANAGER_H