mirror of
https://github.com/openharmony/windowmanager.git
synced 2026-07-19 17:08:11 -04:00
fix issue
Signed-off-by: Grady <yangguangwei4@huawei.com> Change-Id: Iebdb5219cee4184f32e6f6eb9dac67bdfb9bae17
This commit is contained in:
@@ -287,6 +287,7 @@ bool AbstractScreenGroup::GetRSDisplayNodeConfig(sptr<AbstractScreen>& dmsScreen
|
||||
}
|
||||
switch (combination_) {
|
||||
case ScreenCombination::SCREEN_ALONE:
|
||||
[[fallthrough]];
|
||||
case ScreenCombination::SCREEN_EXPAND:
|
||||
config = { dmsScreen->rsId_ };
|
||||
break;
|
||||
|
||||
@@ -217,6 +217,10 @@ napi_value MainFunc(napi_env env, napi_callback_info info)
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
|
||||
|
||||
auto param = std::make_unique<Param>();
|
||||
if (param == nullptr) {
|
||||
WLOGFE("Create param failed.");
|
||||
return nullptr;
|
||||
}
|
||||
param->option.displayId = DisplayManager::GetInstance().GetDefaultDisplayId();
|
||||
napi_ref ref = nullptr;
|
||||
if (argc == 0) {
|
||||
|
||||
@@ -32,12 +32,12 @@ int main(int argc, char *argv[])
|
||||
|
||||
auto display = DisplayManager::GetInstance().GetDisplayById(cmdArgments.displayId);
|
||||
if (display == nullptr) {
|
||||
printf("error: GetDisplayById %" PRIu64 " error!\n", cmdArgments.displayId);
|
||||
std::cout << "error: GetDisplayById " << cmdArgments.displayId << " error!" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("process: display %" PRIu64 ": width %d, height %d\n",
|
||||
cmdArgments.displayId, display->GetWidth(), display->GetHeight());
|
||||
std::cout << "process: display " << cmdArgments.displayId <<
|
||||
": width " << display->GetWidth() << ", height " << display->GetHeight() << std::endl;
|
||||
|
||||
// get PixelMap from DisplayManager API
|
||||
std::shared_ptr<OHOS::Media::PixelMap> pixelMap = nullptr;
|
||||
@@ -46,14 +46,15 @@ int main(int argc, char *argv[])
|
||||
} else {
|
||||
if (!cmdArgments.isWidthSet) {
|
||||
cmdArgments.width = display->GetWidth();
|
||||
printf("process: reset to display's width %d\n", cmdArgments.width);
|
||||
std::cout << "process: reset to display's width " << cmdArgments.width << std::endl;
|
||||
}
|
||||
if (!cmdArgments.isHeightSet) {
|
||||
cmdArgments.height = display->GetHeight();
|
||||
printf("process: reset to display's height %d\n", cmdArgments.height);
|
||||
std::cout << "process: reset to display's height " << cmdArgments.height << std::endl;
|
||||
}
|
||||
if (!SnapShotUtils::CheckWidthAndHeightValid(cmdArgments)) {
|
||||
printf("error: width %d, height %d invalid!\n", cmdArgments.width, cmdArgments.height);
|
||||
std::cout << "error: width " << cmdArgments.width << " height " <<
|
||||
cmdArgments.height << " invalid!" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
const Media::Rect rect = {0, 0, display->GetWidth(), display->GetHeight()};
|
||||
@@ -67,12 +68,13 @@ int main(int argc, char *argv[])
|
||||
ret = SnapShotUtils::WriteToPngWithPixelMap(cmdArgments.fileName, *pixelMap);
|
||||
}
|
||||
if (!ret) {
|
||||
printf("\nerror: snapshot display %" PRIu64 ", write to %s as png failed!\n",
|
||||
cmdArgments.displayId, cmdArgments.fileName.c_str());
|
||||
std::cout << "\nerror: snapshot display " << cmdArgments.displayId <<
|
||||
", write to " << cmdArgments.fileName.c_str() << " as png failed!" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("\nsuccess: snapshot display %" PRIu64 ", write to %s as png, width %d, height %d\n",
|
||||
cmdArgments.displayId, cmdArgments.fileName.c_str(), pixelMap->GetWidth(), pixelMap->GetHeight());
|
||||
std::cout << "\nsuccess: snapshot display " << cmdArgments.displayId << " , write to " <<
|
||||
cmdArgments.fileName.c_str() << " as png, width " << pixelMap->GetWidth() <<
|
||||
", height " << pixelMap->GetHeight() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
+16
-14
@@ -37,7 +37,8 @@ const char *VALID_SNAPSHOT_SUFFIX = ".png";
|
||||
|
||||
void SnapShotUtils::PrintUsage(const std::string &cmdLine)
|
||||
{
|
||||
printf("usage: %s [-i displayId] [-f output_file] [-w width] [-h height] [-m]\n", cmdLine.c_str());
|
||||
std::cout << "usage: " << cmdLine.c_str() <<
|
||||
" [-i displayId] [-f output_file] [-w width] [-h height] [-m]" << std::endl;
|
||||
}
|
||||
|
||||
std::string SnapShotUtils::GenerateFileName(int offset)
|
||||
@@ -66,7 +67,7 @@ bool SnapShotUtils::CheckFileNameValid(const std::string &fileName)
|
||||
{
|
||||
WM_SCOPED_TRACE("snapshot:CheckFileNameValid(%s)", fileName.c_str());
|
||||
if (fileName.length() <= strlen(VALID_SNAPSHOT_SUFFIX)) {
|
||||
printf("error: fileName %s invalid, file length too short!\n", fileName.c_str());
|
||||
std::cout << "error: fileName " << fileName.c_str() << " invalid, file length too short!" << std::endl;
|
||||
return false;
|
||||
}
|
||||
// check file path
|
||||
@@ -80,12 +81,12 @@ bool SnapShotUtils::CheckFileNameValid(const std::string &fileName)
|
||||
char resolvedPath[PATH_MAX] = { 0 };
|
||||
char *realPath = realpath(fileDir.c_str(), resolvedPath);
|
||||
if (realPath == nullptr) {
|
||||
printf("error: fileName %s invalid, realpath nullptr!\n", fileName.c_str());
|
||||
std::cout << "error: fileName " << fileName.c_str() << " invalid, realpath nullptr!" << std::endl;
|
||||
return false;
|
||||
}
|
||||
if (strncmp(realPath, VALID_SNAPSHOT_PATH, strlen(VALID_SNAPSHOT_PATH)) != 0) {
|
||||
printf("error: fileName %s invalid, realpath %s must dump at dir: %s \n",
|
||||
fileName.c_str(), realPath, VALID_SNAPSHOT_PATH);
|
||||
std::cout << "error: fileName " << fileName.c_str() << " invalid, realpath "
|
||||
<< realPath << " must dump at dir: " << VALID_SNAPSHOT_PATH << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -95,7 +96,8 @@ bool SnapShotUtils::CheckFileNameValid(const std::string &fileName)
|
||||
return true; // valid suffix
|
||||
}
|
||||
|
||||
printf("error: fileName %s invalid, suffix must be %s\n", fileName.c_str(), VALID_SNAPSHOT_SUFFIX);
|
||||
std::cout << "error: fileName " << fileName.c_str() <<
|
||||
" invalid, suffix must be " << VALID_SNAPSHOT_SUFFIX << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -145,18 +147,18 @@ bool SnapShotUtils::WriteToPng(const std::string &fileName, const WriteToPngPara
|
||||
|
||||
png_structp pngStruct = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
|
||||
if (pngStruct == nullptr) {
|
||||
printf("error: png_create_write_struct nullptr!\n");
|
||||
std::cout << "error: png_create_write_struct nullptr!" << std::endl;
|
||||
return false;
|
||||
}
|
||||
png_infop pngInfo = png_create_info_struct(pngStruct);
|
||||
if (pngInfo == nullptr) {
|
||||
printf("error: png_create_info_struct error nullptr!\n");
|
||||
std::cout << "error: png_create_info_struct error nullptr!" << std::endl;
|
||||
png_destroy_write_struct(&pngStruct, nullptr);
|
||||
return false;
|
||||
}
|
||||
FILE *fp = fopen(fileName.c_str(), "wb");
|
||||
if (fp == nullptr) {
|
||||
printf("error: open file [%s] error, %d!\n", fileName.c_str(), errno);
|
||||
std::cout << "error: open file [" << fileName.c_str() << "] error, " << errno << "!" << std::endl;
|
||||
png_destroy_write_struct(&pngStruct, &pngInfo);
|
||||
return false;
|
||||
}
|
||||
@@ -213,10 +215,10 @@ static bool ProcessDisplayId(DisplayId &displayId, bool isDisplayIdSet)
|
||||
}
|
||||
}
|
||||
if (!validFlag) {
|
||||
printf("error: displayId %" PRId64 " invalid!\n", static_cast<int64_t>(displayId));
|
||||
printf("tips: supported displayIds:\n");
|
||||
std::cout << "error: displayId " << static_cast<int64_t>(displayId) << " invalid!" << std::endl;
|
||||
std::cout << "tips: supported displayIds:" << std::endl;
|
||||
for (auto dispId: displayIds) {
|
||||
printf("\t%" PRIu64 "\n", dispId);
|
||||
std::cout << "\t" << dispId << std::endl;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -265,12 +267,12 @@ bool SnapShotUtils::ProcessArgs(int argc, char * const argv[], CmdArgments &cmdA
|
||||
|
||||
if (cmdArgments.fileName == "") {
|
||||
cmdArgments.fileName = GenerateFileName();
|
||||
printf("process: set filename to %s\n", cmdArgments.fileName.c_str());
|
||||
std::cout << "process: set filename to " << cmdArgments.fileName.c_str() << std::endl;
|
||||
}
|
||||
|
||||
// check fileName
|
||||
if (!SnapShotUtils::CheckFileNameValid(cmdArgments.fileName)) {
|
||||
printf("error: filename %s invalid!\n", cmdArgments.fileName.c_str());
|
||||
std::cout << "error: filename " << cmdArgments.fileName.c_str() << " invalid!" << std::endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#define SNAPSHOT_UTILS_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <pixel_map.h>
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ int main(int argc, char *argv[])
|
||||
SurfaceReader surfaceReader;
|
||||
sptr<SurfaceReaderHandlerImpl> surfaceReaderHandler = new SurfaceReaderHandlerImpl();
|
||||
if (!surfaceReader.Init()) {
|
||||
printf("surfaceReader init failed!\n");
|
||||
std::cout << "surfaceReader init failed!" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
surfaceReader.SetHandler(surfaceReaderHandler);
|
||||
@@ -71,7 +71,7 @@ int main(int argc, char *argv[])
|
||||
while (!surfaceReaderHandler->IsImageOk()) {
|
||||
waitCount++;
|
||||
if (waitCount >= MAX_WAIT_COUNT) {
|
||||
printf("wait image overtime\n");
|
||||
std::cout << "wait image overtime" << std::endl;
|
||||
break;
|
||||
}
|
||||
usleep(SLEEP_US);
|
||||
@@ -82,16 +82,16 @@ int main(int argc, char *argv[])
|
||||
auto pixelMap = surfaceReaderHandler->GetPixelMap();
|
||||
bool ret = SnapShotUtils::WriteToPngWithPixelMap(FILE_NAME + std::to_string(fileIndex) + ".png", *pixelMap);
|
||||
if (ret) {
|
||||
printf("snapshot %" PRIu64 ", write to %s as png\n",
|
||||
mainId, (FILE_NAME + std::to_string(fileIndex)).c_str());
|
||||
std::cout << "snapshot "<< mainId << " write to " <<
|
||||
(FILE_NAME + std::to_string(fileIndex)).c_str() << " as png" << std::endl;
|
||||
} else {
|
||||
printf("snapshot %" PRIu64 " write to %s failed!\n",
|
||||
mainId, (FILE_NAME + std::to_string(fileIndex)).c_str());
|
||||
std::cout << "snapshot "<< mainId << " write to " <<
|
||||
(FILE_NAME + std::to_string(fileIndex)).c_str() << " failed!" << std::endl;
|
||||
}
|
||||
surfaceReaderHandler->ResetFlag();
|
||||
fileIndex++;
|
||||
}
|
||||
ScreenManager::GetInstance().DestroyVirtualScreen(virtualScreenId);
|
||||
printf("DestroyVirtualScreen %" PRIu64 "\n", virtualScreenId);
|
||||
std::cout << "DestroyVirtualScreen " << virtualScreenId << std::endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user