1 /* 2 * Copyright (c) 2023 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 VIRTUALSREENIMPL_H 17 #define VIRTUALSREENIMPL_H 18 19 #include "VirtualScreen.h" 20 21 class VirtualScreenImpl : public VirtualScreen { 22 public: 23 VirtualScreenImpl(const VirtualScreenImpl&) = delete; 24 VirtualScreenImpl& operator=(const VirtualScreenImpl&) = delete; 25 static VirtualScreenImpl& GetInstance(); 26 static void StartTimer(); 27 static bool LoadDocCallback(const void* data, const size_t length, 28 const int32_t width, const int32_t height); 29 static bool CallBack(const void* data, const size_t length, const int32_t width, const int32_t height); 30 static bool PageCallBack(const std::string currentRouterPath); 31 static bool LoadContentCallBack(const std::string currentRouterPath); 32 static void FastPreviewCallBack(const std::string& jsonStr); 33 void InitAll(std::string pipeName, std::string pipePort); 34 35 private: 36 VirtualScreenImpl(); 37 ~VirtualScreenImpl(); 38 void Send(const void* data, int32_t retWidth, int32_t retHeight); 39 bool SendPixmap(const void* data, size_t length, int32_t retWidth, int32_t retHeight); 40 void FreeJpgMemory(); 41 template<class T, class = typename std::enable_if<std::is_integral<T>::value>::type> WriteBuffer(const T data)42 void WriteBuffer(const T data) 43 { 44 T dataToSend = EndianUtil::ToNetworkEndian<T>(data); 45 unsigned char* startPos = reinterpret_cast<unsigned char*>(&dataToSend); 46 std::copy(startPos, startPos + sizeof(dataToSend), screenBuffer + currentPos); 47 currentPos += sizeof(dataToSend); 48 } 49 50 bool isFirstSend; 51 bool isFirstRender; 52 size_t writed; 53 uint8_t* wholeBuffer; 54 uint8_t* screenBuffer; 55 uint64_t bufferSize; 56 unsigned long long currentPos; 57 static constexpr int SEND_IMG_DURATION_MS = 300; 58 static constexpr int STOP_SEND_CARD_DURATION_MS = 10000; 59 60 uint8_t* loadDocTempBuffer; 61 uint8_t* loadDocCopyBuffer; 62 size_t lengthTemp; 63 int32_t widthTemp; 64 int32_t heightTemp; 65 }; 66 67 #endif // VIRTUALSREENIMPL_H 68