• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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_NATIVE_PIP_WINDOW_LISTENER_H
17 #define OHOS_NATIVE_PIP_WINDOW_LISTENER_H
18 
19 #include "picture_in_picture_interface.h"
20 #include "refbase.h"
21 
22 namespace OHOS {
23 namespace Rosen {
24 typedef void (*NativePipLifeCycleCallback)(uint32_t controllerId, PiPState state, int32_t errcode);
25 typedef void (*NativePipControlEventCallback)(uint32_t controllerId, PiPControlType controlType,
26     PiPControlStatus status);
27 typedef void (*NativePipResizeCallback)(uint32_t controllerId, uint32_t width, uint32_t height, double scale);
28 typedef void (*NativePipStartPipCallback)(uint32_t controllerId, uint8_t requestId, uint64_t surfaceId);
29 
30 class NativePiPWindowListener : public IPiPLifeCycle,
31                             public IPiPControlObserver,
32                             public IPiPWindowSize,
33                             public IPiPStartObserver {
34 public:
NativePiPWindowListener(NativePipLifeCycleCallback callback)35     explicit NativePiPWindowListener(NativePipLifeCycleCallback callback) : lifeCycleCallBack_(callback) {}
NativePiPWindowListener(NativePipControlEventCallback callback)36     explicit NativePiPWindowListener(NativePipControlEventCallback callback) : controlEventCallBack_(callback) {}
NativePiPWindowListener(NativePipResizeCallback callback)37     explicit NativePiPWindowListener(NativePipResizeCallback callback) : windowSizeCallBack_(callback) {}
NativePiPWindowListener(NativePipStartPipCallback callback)38     explicit NativePiPWindowListener(NativePipStartPipCallback callback) : pipStartCallback_(callback) {}
39     ~NativePiPWindowListener();
GetLifeCycleCallbackRef()40     NativePipLifeCycleCallback GetLifeCycleCallbackRef() const { return lifeCycleCallBack_; }
GetControlEventCallbackRef()41     NativePipControlEventCallback GetControlEventCallbackRef() const { return controlEventCallBack_; }
GetResizeCallbackRef()42     NativePipResizeCallback GetResizeCallbackRef() const { return windowSizeCallBack_; }
GetStartPipCallbackRef()43     NativePipStartPipCallback GetStartPipCallbackRef() const { return pipStartCallback_; }
44     void OnPreparePictureInPictureStart(uint32_t controllerId) override;
45     void OnPictureInPictureStart(uint32_t controllerId) override;
46     void OnPreparePictureInPictureStop(uint32_t controllerId) override;
47     void OnPictureInPictureStop(uint32_t controllerId) override;
48     void OnPictureInPictureOperationError(uint32_t controllerId, int32_t errorCode) override;
49     void OnRestoreUserInterface(uint32_t controllerId) override;
50     void OnControlEvent(uint32_t controllerId, PiPControlType controlType, PiPControlStatus statusCode) override;
51     void OnPipSizeChange(uint32_t controllerId, const PiPWindowSize& size) override;
52     void OnPipStart(uint32_t controllerId, uint8_t requestId, uint64_t surfaceId) override;
53 
54 private:
55     void OnPipListenerCallback(uint32_t controllerId, PiPState state, int32_t errorCode);
56     NativePipLifeCycleCallback lifeCycleCallBack_ = nullptr;
57     NativePipControlEventCallback controlEventCallBack_ = nullptr;
58     NativePipResizeCallback windowSizeCallBack_ = nullptr;
59     NativePipStartPipCallback pipStartCallback_ = nullptr;
60 };
61 }  // namespace Rosen
62 }  // namespace OHOS
63 #endif /* OHOS_NATIVE_PIP_WINDOW_LISTENER_H */