• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #if !defined(ANDROID_NDK_BUILD)
21 #include <utils/String8.h>
22 #if ANDROID_PLATFORM_SDK_VERSION < 27
23 #include <cutils/log.h>
24 #elif ANDROID_PLATFORM_SDK_VERSION >= 27
25 #include <log/log.h>
26 #else
27 #error "ANDROID_PLATFORM_SDK_VERSION is not defined"
28 #endif
29 #endif
30 #endif
31 
32 #include <stdio.h>
33 #include <stdarg.h>
34 
35 namespace es
36 {
37 #if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD) && !defined(ANDROID_NDK_BUILD)
output(const char * format,va_list vararg)38 	static void output(const char *format, va_list vararg)
39 	{
40 		ALOGI("%s", android::String8::formatV(format, vararg).string());
41 	}
42 #else
43 	static void output(const char *format, va_list vararg)
44 	{
45 		if(false)
46 		{
47 			static FILE* file = nullptr;
48 			if(!file)
49 			{
50 				file = fopen(TRACE_OUTPUT_FILE, "w");
51 			}
52 
53 			if(file)
54 			{
55 				vfprintf(file, format, vararg);
56 			//	fflush(file);
57 			}
58 		}
59 	}
60 #endif
61 
trace(const char * format,...)62 	void trace(const char *format, ...)
63 	{
64 		va_list vararg;
65 		va_start(vararg, format);
66 		output(format, vararg);
67 		va_end(vararg);
68 	}
69 }
70