1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved.
2 //
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 // debug.cpp: Debugging utilities.
16 
17 #include "common/debug.h"
18 
19 #ifdef  __ANDROID__
20 #include <utils/String8.h>
21 #if ANDROID_PLATFORM_SDK_VERSION < 27
22 #include <cutils/log.h>
23 #elif ANDROID_PLATFORM_SDK_VERSION >= 27
24 #include <log/log.h>
25 #else
26 #error "ANDROID_PLATFORM_SDK_VERSION is not defined"
27 #endif
28 #endif
29 
30 #include <stdio.h>
31 #include <stdarg.h>
32 
33 namespace es
34 {
35 #if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD)
output(const char * format,va_list vararg)36 	static void output(const char *format, va_list vararg)
37 	{
38 		ALOGI("%s", android::String8::formatV(format, vararg).string());
39 	}
40 #else
41 	static void output(const char *format, va_list vararg)
42 	{
43 		if(false)
44 		{
45 			static FILE* file = nullptr;
46 			if(!file)
47 			{
48 				file = fopen(TRACE_OUTPUT_FILE, "w");
49 			}
50 
51 			if(file)
52 			{
53 				vfprintf(file, format, vararg);
54 			//	fflush(file);
55 			}
56 		}
57 	}
58 #endif
59 
trace(const char * format,...)60 	void trace(const char *format, ...)
61 	{
62 		va_list vararg;
63 		va_start(vararg, format);
64 		output(format, vararg);
65 		va_end(vararg);
66 	}
67 }
68