1 /*
2  * Copyright (c) 2023-2023 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_PICTURE_IN_PICTURE_MANAGER_H
17 #define OHOS_PICTURE_IN_PICTURE_MANAGER_H
18 
19 #include <refbase.h>
20 #include "picture_in_picture_controller.h"
21 #include "window.h"
22 #include "wm_common.h"
23 
24 namespace OHOS {
25 namespace Rosen {
26 class PictureInPictureManager {
27 public:
28     PictureInPictureManager();
29     ~PictureInPictureManager();
30     static bool ShouldAbortPipStart();
31     static bool IsSupportPiP();
32     static void PutPipControllerInfo(int32_t windowId, sptr<PictureInPictureController> pipController);
33     static void RemovePipControllerInfo(int32_t windowId);
34     static void AttachActivePipController(sptr<PictureInPictureController> pipController);
35     static void DetachActivePipController(sptr<PictureInPictureController> pipController);
36     static sptr<PictureInPictureController> GetPipControllerInfo(int32_t windowId);
37 
38     static bool HasActiveController();
39     static bool IsActiveController(wptr<PictureInPictureController> pipController);
40     static void SetActiveController(sptr<PictureInPictureController> pipController);
41     static void RemoveActiveController(wptr<PictureInPictureController> pipController);
42     static void AttachAutoStartController(int32_t handleId, wptr<PictureInPictureController> pipController);
43     static void DetachAutoStartController(int32_t handleId, wptr<PictureInPictureController> pipController);
44     static bool IsAttachedToSameWindow(uint32_t windowId);
45     static sptr<Window> GetCurrentWindow();
46 
47     static void DoPreRestore();
48     static void DoRestore();
49     static void DoClose(bool destroyWindow, bool needAnim);
50     static void DoActionClose();
51     static void DoPrepareSource();
52     static void DoLocateSource();
53     static void DoActionEvent(const std::string& actionName, int32_t status);
54     static void DoControlEvent(PiPControlType controlType, PiPControlStatus status);
55     static void AutoStartPipWindow();
56     static void DoDestroy();
57     static std::shared_ptr<NativeReference> innerCallbackRef_;
58 private:
59     // controller in use
60     static sptr<PictureInPictureController> activeController_;
61     static wptr<PictureInPictureController> autoStartController_;
62     // controllers enable auto start
63     static std::map<int32_t, wptr<PictureInPictureController>> autoStartControllerMap_;
64 
65     static std::map<int32_t, sptr<PictureInPictureController>> windowToControllerMap_;
66 };
67 } // namespace Rosen
68 } // namespace OHOS
69 #endif // OHOS_PICTURE_IN_PICTURE_MANAGER_H