2 * Copyright (c) 2022 CompanyNameMagicTag.
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
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include "hals/lite_input_distributer.h"
17 #include "hals/display_dev.h"
18 #include "gfx_utils/graphic_log.h"
19 #include "dfx/dfx_record.h"
20 #include "common/low_power_manager.h"
21 #ifdef CONFIG_SUPPORTED_POWERMGR
22 #include "power_mgr_policy.h"
23 #include "power_mgr_service.h"
24 #include "samgr_lite.h"
25 #include "commu_feature.h"
28 static DeviceData g_lastData = {0};
29 LiteInputDistributer::LiteInputDistributer()
32 LiteInputDistributer::~LiteInputDistributer() {}
34 void LiteInputDistributer::SendRawEvent(const RawEvent& rawEvent)
36 RawEvent event = rawEvent;
37 DisplayDev* displayDev = DisplayDev::GetInstance();
38 if ((event.type == InputDevType::INDEV_TYPE_TOUCH) &&
39 (displayDev->GetLayerRotateType(LAYER_0) == LayerRotateType::LAYER_ROTATE_90)) {
40 LayerBuffer* buffer = displayDev->GetCurrentBuffer(LAYER_0);
41 if (buffer == nullptr) {
45 int16_t tmp = buffer->height - event.x;
49 #ifdef CONFIG_SUPPORTED_POWERMGR
55 void LiteInputDistributer::GetEventData(DeviceData& data, InputDevType type)
59 if (type == InputDevType::INDEV_TYPE_ENCODER) {
60 if (encoderDataList_.IsEmpty()) {
65 DeviceData* tmp = encoderDataList_.Front();
66 encoderDataList_.PopFront();
67 data.rotate = tmp->rotate;
68 data.state = tmp->state;
69 data.timestamp = tmp->timestamp;
72 }else if (type == InputDevType::INDEV_TYPE_TOUCH) {
73 g_lastData = deviceData_;
74 if (IsShowPoint() && (deviceData_.timestamp != g_lastData.timestamp)) {
77 data.point.x = deviceData_.point.x;
78 data.point.y = deviceData_.point.y;
79 data.state = deviceData_.state;
80 data.timestamp = deviceData_.timestamp;
81 }else if (type == InputDevType::INDEV_TYPE_KEY) {
82 if (keyList_.IsEmpty()) {
83 data.keyId = INVALID_KEY_ID;
87 DeviceData* tmp = keyList_.Front();
89 data.keyId = tmp->keyId;
90 data.state = tmp->state;
91 data.timestamp = tmp->timestamp;
98 void LiteInputDistributer::SetEventData(const RawEvent& event)
100 LowPowerManager::GetInstance()->ExitLowPower();
103 if (event.type == InputDevType::INDEV_TYPE_TOUCH) {
105 DfxTPSetEvent(event.timestamp - deviceData_.timestamp);
107 deviceData_.point.x = event.x;
108 deviceData_.point.y = event.y;
109 deviceData_.state = event.state;
110 deviceData_.timestamp = event.timestamp;
112 }else if (event.type == InputDevType::INDEV_TYPE_ENCODER) {
113 // if (IsShowPoint()) {
114 // DfxTPSetEvent(event.timestamp - encoderDataList_.timestamp);
116 DeviceData* data = new DeviceData();
117 data->rotate = event.rotate;
118 data->state = event.state;
119 data->timestamp = event.timestamp;
120 if (encoderDataList_.Size() >= MAX_ENCODER_DATA_LIST_SIZE) {
121 DeviceData* tmp = encoderDataList_.Front();
122 encoderDataList_.PopFront();
126 encoderDataList_.PushBack(data);
128 }else if (event.type == InputDevType::INDEV_TYPE_KEY) {
129 DeviceData* data = new DeviceData();
130 data->keyId = event.keyId;
131 data->state = event.state;
132 data->timestamp = event.timestamp;
133 if (keyList_.Size() >= MAX_KEY_LIST_SIZE) {
134 DeviceData* tmp = keyList_.Front();
139 keyList_.PushBack(data);
144 bool LiteInputDistributer::IsEventEmpty(InputDevType type)
146 if (type == InputDevType::INDEV_TYPE_TOUCH) {
147 return ((g_lastData.state == 0) && (deviceData_.state == 0));
148 } else if (type == InputDevType::INDEV_TYPE_KEY) {
149 return keyList_.IsEmpty();
150 } else if (type == InputDevType::INDEV_TYPE_ENCODER){
151 return encoderDataList_.IsEmpty();
156 #ifdef CONFIG_SUPPORTED_POWERMGR
157 void LiteInputDistributer::SendEventToPM(const RawEvent& event)
159 IUnknown *api = SAMGR_GetInstance()->GetDefaultFeatureApiById(POWER_SVR_ID);
160 if (api == nullptr) {
164 uint16_t msgId = POWERMSG_USER_EVENT;
166 if (event.type == InputDevType::INDEV_TYPE_TOUCH) {
167 userEvent = USER_EVENT_TOUCH;
169 if (event.type == InputDevType::INDEV_TYPE_KEY) {
170 userEvent = USER_EVENT_KEY;
172 uint32_t msgValue = (POWER_DISPLAY_POLICY << EVENT_TYPE_BITS_SIZE) | userEvent;
174 Request *request = nullptr;
175 request = SAMGR_AllocRequestMsg(0, CORES_APPLICATION_CORE, POWER_SVR_ID, 0);
176 if (request == nullptr) {
179 request->serviceId = UI_SVR_ID;
180 request->msgId = msgId;
181 request->msgValue = msgValue;
183 CommuFeature *feature = GET_OBJECT(api, CommuFeature, iUnknown);
184 Identity identity = feature->id;
185 identity.featureId = -1;
186 int32 ret = SAMGR_SendRequest(&identity, request, nullptr);
188 SAMGR_FreeRequestMsg(request);