1 /* 2 * Copyright (c) 2021 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 #ifndef UPDATER_UI_FRAME_H 16 #define UPDATER_UI_FRAME_H 17 18 #include <list> 19 #include <map> 20 #include <thread> 21 #include "surface_dev.h" 22 #include "view.h" 23 24 namespace updater { 25 struct CmpByStartY { operatorCmpByStartY26 bool operator()(const View *v1, const View *v2) const 27 { 28 return v1->startY_ < v2->startY_; 29 } 30 }; 31 32 class Frame : public View { 33 public: 34 Frame(unsigned int w, unsigned int h, View::PixelFormat pixType, SurfaceDev *sfDev); 35 36 ~Frame() override; 37 38 void OnDraw() override; 39 40 void ViewRegister(View *view); 41 42 void DispatchKeyEvent(int key); 43 44 void DispatchKeyEvent(int id, int event); 45 private: 46 void FlushThreadLoop(); 47 48 void DownFoucs(); 49 50 void UpFoucs(); 51 52 void SendKey(int key); 53 54 void ProcessKeyLoop(); 55 56 void DoEvent(int key); 57 58 void ReleaseEvent(); 59 60 void PressEvent(); 61 62 int currentActionIndex_ = 0; 63 int maxActionIndex_ = 0; 64 int listIndex_ = 0; 65 int frameViewId = 0; 66 bool flushFlag_ = false; 67 bool needStop_ = false; 68 bool keyEventNotify_ = false; 69 SurfaceDev *sfDev_ = nullptr; 70 std::thread flushLoop_; 71 std::thread keyProcessLoop_; 72 std::mutex frameMutex_; 73 std::mutex keyMutex_; 74 std::condition_variable_any mCondFlush_; 75 std::condition_variable_any mCondKey_; 76 std::list<int> keyFifo_; 77 std::map<View*, int, CmpByStartY> viewMapList_; 78 int keyEvent_ = -1; 79 int btnId_ = -1; 80 }; 81 } // namespace updater 82 #endif // UPDATER_UI_FRAME_H 83