1 /*
2 * Copyright (c) 2024 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 #include "future_callback.h"
17 #include "window_manager_hilog.h"
18
19 namespace OHOS {
20 namespace Rosen {
21
OnUpdateSessionRect(const Rect & rect,WindowSizeChangeReason reason,int32_t persistentId)22 WSError FutureCallback::OnUpdateSessionRect(const Rect& rect, WindowSizeChangeReason reason,
23 int32_t persistentId)
24 {
25 TLOGI(WmsLogTag::WMS_LAYOUT, "Id:%{public}d, rect:%{public}s, reason:%{public}u",
26 persistentId, rect.ToString().c_str(), reason);
27 switch (reason) {
28 case WindowSizeChangeReason::MOVE:
29 moveToFuture_.SetValue(rect);
30 return WSError::WS_OK;
31 case WindowSizeChangeReason::RESIZE:
32 resizeFuture_.SetValue(rect);
33 return WSError::WS_OK;
34 default:
35 TLOGW(WmsLogTag::WMS_LAYOUT, "Id:%{public}d, reason:%{public}u is not move or resize",
36 persistentId, reason);
37 }
38 return WSError::WS_DO_NOTHING;
39 }
40
41 // LCOV_EXCL_START
OnUpdateGlobalDisplayRect(const Rect & rect,WindowSizeChangeReason reason,int32_t persistentId)42 WSError FutureCallback::OnUpdateGlobalDisplayRect(
43 const Rect& rect, WindowSizeChangeReason reason, int32_t persistentId)
44 {
45 TLOGD(WmsLogTag::WMS_LAYOUT, "windowId: %{public}d, rect: %{public}s, reason: %{public}u",
46 persistentId, rect.ToString().c_str(), reason);
47 switch (reason) {
48 case WindowSizeChangeReason::MOVE:
49 moveWindowToGlobalDisplayFuture_.SetValue(rect);
50 return WSError::WS_OK;
51 default:
52 TLOGD(WmsLogTag::WMS_LAYOUT, "Unmatched reason: %{public}u", reason);
53 }
54 return WSError::WS_DO_NOTHING;
55 }
56
OnUpdateTargetOrientationInfo(OrientationInfo & info)57 WSError FutureCallback::OnUpdateTargetOrientationInfo(OrientationInfo& info)
58 {
59 TLOGI(WmsLogTag::WMS_ROTATION, "update the target orientation info");
60 getTargetRotationFuture_.SetValue(info);
61 return WSError::WS_DO_NOTHING;
62 }
63
OnUpdateRotationResult(RotationChangeResult rotationChangeResult)64 void FutureCallback::OnUpdateRotationResult(RotationChangeResult rotationChangeResult)
65 {
66 TLOGI(WmsLogTag::WMS_ROTATION, "update the rotation change result");
67 getRotationResultFuture_.SetValue(rotationChangeResult);
68 }
69
GetResizeAsyncResult(long timeoutMs)70 Rect FutureCallback::GetResizeAsyncResult(long timeoutMs)
71 {
72 return resizeFuture_.GetResult(timeoutMs);
73 }
74
GetMoveToAsyncResult(long timeoutMs)75 Rect FutureCallback::GetMoveToAsyncResult(long timeoutMs)
76 {
77 return moveToFuture_.GetResult(timeoutMs);
78 }
79
GetMoveWindowToGlobalDisplayAsyncResult(long timeoutMs)80 Rect FutureCallback::GetMoveWindowToGlobalDisplayAsyncResult(long timeoutMs)
81 {
82 return moveWindowToGlobalDisplayFuture_.GetResult(timeoutMs);
83 }
84 // LCOV_EXCL_STOP
85
GetTargetOrientationResult(long timeoutMs)86 OrientationInfo FutureCallback::GetTargetOrientationResult(long timeoutMs)
87 {
88 return getTargetRotationFuture_.GetResult(timeoutMs);
89 }
90
GetRotationResult(long timeoutMs)91 RotationChangeResult FutureCallback::GetRotationResult(long timeoutMs)
92 {
93 return getRotationResultFuture_.GetResult(timeoutMs);
94 }
95
96 // LCOV_EXCL_START
ResetResizeLock()97 void FutureCallback::ResetResizeLock()
98 {
99 resizeFuture_.ResetLock({});
100 }
101
ResetMoveToLock()102 void FutureCallback::ResetMoveToLock()
103 {
104 moveToFuture_.ResetLock({});
105 }
106
ResetMoveWindowToGlobalDisplayLock()107 void FutureCallback::ResetMoveWindowToGlobalDisplayLock()
108 {
109 moveWindowToGlobalDisplayFuture_.ResetLock({});
110 }
111
ResetGetTargetRotationLock()112 void FutureCallback::ResetGetTargetRotationLock()
113 {
114 getTargetRotationFuture_.ResetLock({});
115 }
116
ResetRotationResultLock()117 void FutureCallback::ResetRotationResultLock()
118 {
119 getRotationResultFuture_.ResetLock({});
120 }
121 // LCOV_EXCL_STOP
122
GetUpdateRectResult(long timeoutMs)123 int32_t FutureCallback::GetUpdateRectResult(long timeoutMs)
124 {
125 return updateRectFuture_.GetResult(timeoutMs);
126 }
127
OnFirstValidRectUpdate(int32_t persistentId)128 void FutureCallback::OnFirstValidRectUpdate(int32_t persistentId)
129 {
130 updateRectFuture_.SetValue(persistentId);
131 }
132 } // namespace Rosen
133 } // namespace OHOS