• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 OHOS_ROSEN_WINDOW_INNER_MANAGER_H
17 #define OHOS_ROSEN_WINDOW_INNER_MANAGER_H
18 
19 #include <condition_variable>
20 #include <mutex>
21 #include <string>
22 #include <thread>
23 #include <vector>
24 #include "include/core/SkBitmap.h"
25 #ifdef ACE_ENABLE_GL
26 #include "render_context/render_context.h"
27 #endif
28 #include "transaction/rs_transaction.h"
29 #include "ui/rs_surface_extractor.h"
30 #include "wm_single_instance.h"
31 #include "singleton_delegator.h"
32 #include "window.h"
33 #include "wm_common.h"
34 
35 namespace OHOS {
36 namespace Rosen {
37 enum InnerWMCmd : uint32_t {
38     INNER_WM_CREATE_DIVIDER,
39     INNER_WM_DESTROY_DIVIDER,
40     INNER_WM_DESTROY_THREAD,
41 };
42 
43 struct WindowMessage {
44     InnerWMCmd cmdType;
45     DisplayId displayId;
46     Rect dividerRect;
47 };
48 
49 class WindowInnerManager {
50 WM_DECLARE_SINGLE_INSTANCE(WindowInnerManager);
51 public:
52     void Init();
53     void SendMessage(InnerWMCmd cmdType, DisplayId displayId = 0);
54 private:
55     static inline SingletonDelegator<WindowInnerManager> delegator;
56 
57     void HandleMessage();
58     sptr<Window> CreateWindow(DisplayId displayId, const WindowType& type, const Rect& rect);
59     void CreateAndShowDivider(std::unique_ptr<WindowMessage> msg);
60     void HideAndDestroyDivider(std::unique_ptr<WindowMessage> msg);
61     void DestroyThread(std::unique_ptr<WindowMessage> msg);
62     void DrawSurface(const sptr<Window>& window);
63     void DrawColor(std::shared_ptr<RSSurface>& rsSurface, uint32_t width, uint32_t height);
64     void DrawBitmap(std::shared_ptr<RSSurface>& rsSurface, uint32_t width, uint32_t height);
65     sptr<Window> GetDividerWindow(DisplayId displayId) const;
66     bool DecodeImageFile(const char* filename, SkBitmap& bitmap);
67 
68     std::mutex mutex_;
69     std::condition_variable conVar_;
70     bool ready_ = false;
71 #ifdef ACE_ENABLE_GL
72     RenderContext* rc_ = nullptr;
73 #endif
74     std::map<uint32_t, sptr<Window>> dividerMap_;
75     std::vector<std::unique_ptr<WindowMessage>> messages_;
76     bool hasInitThread_ = false;
77     bool needDestroyThread_ = false;
78     bool isDividerImageLoaded_ = false;
79     const char *splitIconPath_ = "/etc/window/resources/bg_split_handle.png";
80     uint32_t DIVIDER_HANDLE_COLOR = 0xff808080; // gray
81     SkBitmap dividerBitmap_;
82 };
83 }
84 }
85 #endif // OHOS_ROSEN_WINDOW_INNER_MANAGER_H
86