• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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_ACE_FRAMEWORKS_CORE_COMPONENTS_XCOMPONENT_XCOMPONENT_CONTROLLER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_XCOMPONENT_XCOMPONENT_CONTROLLER_H
18 
19 #include <algorithm>
20 #include <functional>
21 #include <list>
22 #include <string>
23 
24 #include "base/geometry/size.h"
25 #include "base/utils/utils.h"
26 #include "core/pipeline/base/element.h"
27 
28 namespace OHOS::Ace {
29 class XComponentController : public virtual AceType {
30     DECLARE_ACE_TYPE(XComponentController, AceType);
31 
32 public:
33     using ConfigSurfaceImpl = std::function<void(uint32_t, uint32_t)>;
34 
GetSurfaceId()35     std::string GetSurfaceId()
36     {
37         return surfaceId_;
38     }
39 
ConfigSurface(uint32_t surfaceWidth,uint32_t surfaceHeight)40     void ConfigSurface(uint32_t surfaceWidth, uint32_t surfaceHeight)
41     {
42         if (ConfigSurfaceImpl_) {
43             ConfigSurfaceImpl_(surfaceWidth, surfaceHeight);
44         }
45     }
46 
SetConfigSurfaceImpl(ConfigSurfaceImpl && ConfigSurfaceImpl)47     void SetConfigSurfaceImpl(ConfigSurfaceImpl&& ConfigSurfaceImpl)
48     {
49         ConfigSurfaceImpl_ = std::move(ConfigSurfaceImpl);
50     }
51 
AddXComponentController(const RefPtr<XComponentController> & xcomponentController)52     void AddXComponentController(const RefPtr<XComponentController>& xcomponentController)
53     {
54         auto it = std::find(controllers_.begin(), controllers_.end(), xcomponentController);
55         if (it != controllers_.end()) {
56             LOGW("Controller is already existed");
57             return;
58         }
59         controllers_.emplace_back(xcomponentController);
60     }
61 
RemoveXComponentController(const RefPtr<XComponentController> & xcomponentController)62     void RemoveXComponentController(const RefPtr<XComponentController>& xcomponentController)
63     {
64         if (xcomponentController) {
65             controllers_.remove(xcomponentController);
66         }
67     }
68 
Clear()69     void Clear()
70     {
71         controllers_.clear();
72     }
73 
74     std::string surfaceId_ = "";
75 
76 private:
77     std::list<RefPtr<XComponentController>> controllers_;
78     ConfigSurfaceImpl ConfigSurfaceImpl_;
79 };
80 } // namespace OHOS::Ace
81 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_XCOMPONENT_XCOMPONENT_CONTROLLER_H