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 void FastPreviewCallBack(const std::string& jsonStr); 32 void InitAll(std::string pipeName, std::string pipePort); 33 34 private: 35 VirtualScreenImpl(); 36 ~VirtualScreenImpl(); 37 void Send(const void* data, int32_t retWidth, int32_t retHeight); 38 bool SendPixmap(const void* data, size_t length, int32_t retWidth, int32_t retHeight); 39 void FreeJpgMemory(); 40 template<class T, class = typename std::enable_if<std::is_integral<T>::value>::type> WriteBuffer(const T data)41 void WriteBuffer(const T data) 42 { 43 T dataToSend = EndianUtil::ToNetworkEndian<T>(data); 44 unsigned char* startPos = reinterpret_cast<unsigned char*>(&dataToSend); 45 std::copy(startPos, startPos + sizeof(dataToSend), screenBuffer + currentPos); 46 currentPos += sizeof(dataToSend); 47 } 48 49 bool isFirstSend; 50 bool isFirstRender; 51 size_t writed; 52 uint8_t* wholeBuffer; 53 uint8_t* screenBuffer; 54 uint64_t bufferSize; 55 unsigned long long currentPos; 56 static constexpr int SEND_IMG_DURATION_MS = 300; 57 58 uint8_t* loadDocTempBuffer; 59 uint8_t* loadDocCopyBuffer; 60 size_t lengthTemp; 61 int32_t widthTemp; 62 int32_t heightTemp; 63 }; 64 65 #endif // VIRTUALSREENIMPL_H 66