• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2006 The Android Open Source Project
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  * 2023.4.26 log adapt ohos.
7  * Copyright (c) 2023 Huawei Device Co., Ltd. All rights reserved.
8  */
9 
10 #include "include/core/SkTypes.h"
11 #include <stdio.h>
12 #include <string>
13 
14 #ifdef SKIA_OHOS_SHADER_REDUCE
15 #include <parameters.h>
16 #endif
17 
18 #define LOG_TAG "skia"
19 #include "hilog/log.h"
20 
21 #ifdef SKIA_OHOS_SINGLE_OWNER
22 #include "backtrace_local.h"
23 #include "include/core/SkLog.h"
24 #include <sstream>
25 #include <thread>
26 #include <fstream>
27 #endif
28 
29 extern "C" {
30     int HiLogPrintArgs(LogType type, LogLevel level, unsigned int domain, const char* tag, const char* fmt, va_list ap);
31 }
32 
33 // Print debug output to stdout as well.  This is useful for command line
34 // applications (e.g. skia_launcher).
35 bool gSkDebugToStdOut = false;
36 
SkDebugf(const char format[],...)37 void SkDebugf(const char format[], ...) {
38     va_list args1, args2;
39     va_start(args1, format);
40 
41     if (gSkDebugToStdOut) {
42         va_copy(args2, args1);
43         vprintf(format, args2);
44         va_end(args2);
45     }
46 
47     HiLogPrintArgs(LOG_CORE, LogLevel::LOG_DEBUG, 0xD001406, LOG_TAG, format, args1);
48 
49     va_end(args1);
50 }
51 
52 #ifdef SKIA_OHOS_SHADER_REDUCE
SkShaderReduceProperty()53 bool SkShaderReduceProperty()
54 {
55     static bool debugProp = std::atoi(OHOS::system::GetParameter("persist.sys.skia.shader.reduce", "1").c_str()) != 0;
56     return debugProp;
57 }
58 #endif
59 
60 #ifdef SKIA_OHOS_SINGLE_OWNER
IsRenderService()61 bool IsRenderService()
62 {
63     std::ifstream procfile("/proc/self/cmdline");
64     if (!procfile.is_open()) {
65         SK_LOGE("IsRenderService open failed");
66         return false;
67     }
68     std::string processName;
69     std::getline(procfile, processName);
70     procfile.close();
71     static const std::string target = "/system/bin/render_service";
72     bool result = processName.compare(0, target.size(), target) == 0;
73     return result;
74 }
75 
IsBeta()76 static bool IsBeta()
77 {
78     static const bool isBeta = OHOS::system::GetParameter("const.logsystem.versiontype", "unknown") == "beta";
79     return isBeta;
80 }
81 
GetEnableSkiaSingleOwner()82 bool GetEnableSkiaSingleOwner()
83 {
84     static const bool gIsEnableSingleOwner = IsRenderService() && IsBeta();
85     return gIsEnableSingleOwner;
86 }
87 
PrintBackTrace(uint32_t tid)88 void PrintBackTrace(uint32_t tid)
89 {
90     std::string msg = "";
91     OHOS::HiviewDFX::GetBacktraceStringByTid(msg, tid, 0, false);
92     if (!msg.empty()) {
93         std::vector<std::string> out;
94         std::stringstream ss(msg);
95         std::string s;
96         while (std::getline(ss, s , '\n')) {
97             out.push_back(s);
98         }
99         SK_LOGE(" ======== tid:%{public}d", tid);
100         for (auto const& line: out) {
101             SK_LOGE(" callstack %{public}s", line.c_str());
102         }
103     }
104 }
105 #endif