17c804472Sopenharmony_ci/* 27c804472Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 37c804472Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 47c804472Sopenharmony_ci * you may not use this file except in compliance with the License. 57c804472Sopenharmony_ci * You may obtain a copy of the License at 67c804472Sopenharmony_ci * 77c804472Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 87c804472Sopenharmony_ci * 97c804472Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 107c804472Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 117c804472Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 127c804472Sopenharmony_ci * See the License for the specific language governing permissions and 137c804472Sopenharmony_ci * limitations under the License. 147c804472Sopenharmony_ci */ 157c804472Sopenharmony_ci 167c804472Sopenharmony_ci#ifndef VIRTUALSREENIMPL_H 177c804472Sopenharmony_ci#define VIRTUALSREENIMPL_H 187c804472Sopenharmony_ci 197c804472Sopenharmony_ci#include "VirtualScreen.h" 207c804472Sopenharmony_ci 217c804472Sopenharmony_ciclass ScreenInfo { 227c804472Sopenharmony_cipublic: 237c804472Sopenharmony_ci int32_t orignalResolutionWidth; 247c804472Sopenharmony_ci int32_t orignalResolutionHeight; 257c804472Sopenharmony_ci int32_t compressionResolutionWidth; 267c804472Sopenharmony_ci int32_t compressionResolutionHeight; 277c804472Sopenharmony_ci std::string foldStatus; 287c804472Sopenharmony_ci bool foldable; 297c804472Sopenharmony_ci int32_t foldWidth; 307c804472Sopenharmony_ci int32_t foldHeight; 317c804472Sopenharmony_ci}; 327c804472Sopenharmony_ci 337c804472Sopenharmony_ciclass VirtualScreenImpl : public VirtualScreen { 347c804472Sopenharmony_cipublic: 357c804472Sopenharmony_ci VirtualScreenImpl(const VirtualScreenImpl&) = delete; 367c804472Sopenharmony_ci VirtualScreenImpl& operator=(const VirtualScreenImpl&) = delete; 377c804472Sopenharmony_ci static VirtualScreenImpl& GetInstance(); 387c804472Sopenharmony_ci static void StartTimer(); 397c804472Sopenharmony_ci static bool FlushEmptyFunc(std::chrono::system_clock::time_point endTime, int64_t timePassed); 407c804472Sopenharmony_ci static bool NoFlushEmptyFunc(int64_t timePassed); 417c804472Sopenharmony_ci static void PrintLoadDocFinishedLog(const std::string& logStr); 427c804472Sopenharmony_ci static void SendBufferOnTimer(); 437c804472Sopenharmony_ci static bool LoadDocCallback(const void* data, const size_t length, 447c804472Sopenharmony_ci const int32_t width, const int32_t height, const uint64_t timeStamp); 457c804472Sopenharmony_ci static bool Callback(const void* data, const size_t length, const int32_t width, const int32_t height, 467c804472Sopenharmony_ci const uint64_t timeStamp); 477c804472Sopenharmony_ci static bool FlushEmptyCallback(const uint64_t timeStamp); 487c804472Sopenharmony_ci void InitFlushEmptyTime() override; 497c804472Sopenharmony_ci static bool PageCallback(const std::string currentRouterPath); 507c804472Sopenharmony_ci static bool LoadContentCallback(const std::string currentRouterPath); 517c804472Sopenharmony_ci static void FastPreviewCallback(const std::string& jsonStr); 527c804472Sopenharmony_ci void InitAll(std::string pipeName, std::string pipePort); 537c804472Sopenharmony_ci ScreenInfo GetScreenInfo(); 547c804472Sopenharmony_ci void InitFoldParams(); 557c804472Sopenharmony_ciprivate: 567c804472Sopenharmony_ci VirtualScreenImpl(); 577c804472Sopenharmony_ci ~VirtualScreenImpl(); 587c804472Sopenharmony_ci void Send(const void* data, int32_t retWidth, int32_t retHeight); 597c804472Sopenharmony_ci bool SendPixmap(const void* data, size_t length, int32_t retWidth, int32_t retHeight); 607c804472Sopenharmony_ci void FreeJpgMemory(); 617c804472Sopenharmony_ci template<class T, class = typename std::enable_if<std::is_integral<T>::value>::type> 627c804472Sopenharmony_ci void WriteBuffer(const T data) 637c804472Sopenharmony_ci { 647c804472Sopenharmony_ci T dataToSend = EndianUtil::ToNetworkEndian<T>(data); 657c804472Sopenharmony_ci unsigned char* startPos = reinterpret_cast<unsigned char*>(&dataToSend); 667c804472Sopenharmony_ci std::copy(startPos, startPos + sizeof(dataToSend), screenBuffer + currentPos); 677c804472Sopenharmony_ci currentPos += sizeof(dataToSend); 687c804472Sopenharmony_ci } 697c804472Sopenharmony_ci 707c804472Sopenharmony_ci bool isFirstSend; 717c804472Sopenharmony_ci bool isFirstRender; 727c804472Sopenharmony_ci size_t writed; 737c804472Sopenharmony_ci uint8_t* wholeBuffer; 747c804472Sopenharmony_ci uint8_t* screenBuffer; 757c804472Sopenharmony_ci uint64_t bufferSize; 767c804472Sopenharmony_ci unsigned long long currentPos; 777c804472Sopenharmony_ci static constexpr int SEND_IMG_DURATION_MS = 300; 787c804472Sopenharmony_ci static constexpr int STOP_SEND_CARD_DURATION_MS = 10000; 797c804472Sopenharmony_ci 807c804472Sopenharmony_ci uint8_t* loadDocTempBuffer; 817c804472Sopenharmony_ci uint8_t* loadDocCopyBuffer; 827c804472Sopenharmony_ci size_t lengthTemp; 837c804472Sopenharmony_ci int32_t widthTemp; 847c804472Sopenharmony_ci int32_t heightTemp; 857c804472Sopenharmony_ci uint64_t timeStampTemp; 867c804472Sopenharmony_ci 877c804472Sopenharmony_ci static constexpr int TIMEOUT_ONRENDER_DURATION_MS = 100; 887c804472Sopenharmony_ci static constexpr int TIMEOUT_NINE_S = 9000; 897c804472Sopenharmony_ci static constexpr int64_t SEC_TO_NANOSEC = 1000000000; 907c804472Sopenharmony_ci bool isFlushEmpty = false; 917c804472Sopenharmony_ci uint64_t loadDocTimeStamp = 0; 927c804472Sopenharmony_ci uint64_t flushEmptyTimeStamp = 0; 937c804472Sopenharmony_ci std::chrono::system_clock::time_point flushEmptyTime = std::chrono::system_clock::time_point::min(); 947c804472Sopenharmony_ci std::chrono::system_clock::time_point onRenderTime = std::chrono::system_clock::time_point::min(); 957c804472Sopenharmony_ci}; 967c804472Sopenharmony_ci 977c804472Sopenharmony_ci#endif // VIRTUALSREENIMPL_H 98