OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "SkTLS.h" | 9 #include "SkTLS.h" |
10 #include "SkTypes.h" | 10 #include "SkTypes.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 return new SkErrorCallbackFunction(SkErrorInternals::DefaultErrorCallbac
k); | 24 return new SkErrorCallbackFunction(SkErrorInternals::DefaultErrorCallbac
k); |
25 } | 25 } |
26 void DeleteThreadErrorCallback(void* v) { | 26 void DeleteThreadErrorCallback(void* v) { |
27 delete reinterpret_cast<SkErrorCallbackFunction *>(v); | 27 delete reinterpret_cast<SkErrorCallbackFunction *>(v); |
28 } | 28 } |
29 | 29 |
30 #define THREAD_ERROR_CALLBACK
\ | 30 #define THREAD_ERROR_CALLBACK
\ |
31 *(reinterpret_cast<SkErrorCallbackFunction *>(SkTLS::Get(CreateThreadErr
orCallback, \ | 31 *(reinterpret_cast<SkErrorCallbackFunction *>(SkTLS::Get(CreateThreadErr
orCallback, \ |
32 DeleteThreadErr
orCallback))) | 32 DeleteThreadErr
orCallback))) |
33 | 33 |
34 void *CreateThreadErrorContext() { return new void **(NULL); } | 34 void *CreateThreadErrorContext() { return new void **(nullptr); } |
35 void DeleteThreadErrorContext(void *v) { delete reinterpret_cast<void **>(v)
; } | 35 void DeleteThreadErrorContext(void *v) { delete reinterpret_cast<void **>(v)
; } |
36 #define THREAD_ERROR_CONTEXT \ | 36 #define THREAD_ERROR_CONTEXT \ |
37 (*reinterpret_cast<void **>(SkTLS::Get(CreateThreadErrorContext, DeleteT
hreadErrorContext))) | 37 (*reinterpret_cast<void **>(SkTLS::Get(CreateThreadErrorContext, DeleteT
hreadErrorContext))) |
38 | 38 |
39 #define ERROR_STRING_LENGTH 2048 | 39 #define ERROR_STRING_LENGTH 2048 |
40 | 40 |
41 void *CreateThreadErrorString() { return new char[(ERROR_STRING_LENGTH)]; } | 41 void *CreateThreadErrorString() { return new char[(ERROR_STRING_LENGTH)]; } |
42 void DeleteThreadErrorString(void *v) { delete[] reinterpret_cast<char *>(v)
; } | 42 void DeleteThreadErrorString(void *v) { delete[] reinterpret_cast<char *>(v)
; } |
43 #define THREAD_ERROR_STRING \ | 43 #define THREAD_ERROR_STRING \ |
44 (reinterpret_cast<char *>(SkTLS::Get(CreateThreadErrorString, DeleteThre
adErrorString))) | 44 (reinterpret_cast<char *>(SkTLS::Get(CreateThreadErrorString, DeleteThre
adErrorString))) |
45 } | 45 } |
46 | 46 |
47 SkError SkGetLastError() { | 47 SkError SkGetLastError() { |
48 return SkErrorInternals::GetLastError(); | 48 return SkErrorInternals::GetLastError(); |
49 } | 49 } |
50 void SkClearLastError() { | 50 void SkClearLastError() { |
51 SkErrorInternals::ClearError(); | 51 SkErrorInternals::ClearError(); |
52 } | 52 } |
53 void SkSetErrorCallback(SkErrorCallbackFunction cb, void *context) { | 53 void SkSetErrorCallback(SkErrorCallbackFunction cb, void *context) { |
54 SkErrorInternals::SetErrorCallback(cb, context); | 54 SkErrorInternals::SetErrorCallback(cb, context); |
55 } | 55 } |
56 const char *SkGetLastErrorString() { | 56 const char *SkGetLastErrorString() { |
57 return SkErrorInternals::GetLastErrorString(); | 57 return SkErrorInternals::GetLastErrorString(); |
58 } | 58 } |
59 | 59 |
60 // ------------ Private Error functions --------- | 60 // ------------ Private Error functions --------- |
61 | 61 |
62 void SkErrorInternals::SetErrorCallback(SkErrorCallbackFunction cb, void *contex
t) { | 62 void SkErrorInternals::SetErrorCallback(SkErrorCallbackFunction cb, void *contex
t) { |
63 if (cb == NULL) { | 63 if (cb == nullptr) { |
64 THREAD_ERROR_CALLBACK = SkErrorInternals::DefaultErrorCallback; | 64 THREAD_ERROR_CALLBACK = SkErrorInternals::DefaultErrorCallback; |
65 } else { | 65 } else { |
66 THREAD_ERROR_CALLBACK = cb; | 66 THREAD_ERROR_CALLBACK = cb; |
67 } | 67 } |
68 THREAD_ERROR_CONTEXT = context; | 68 THREAD_ERROR_CONTEXT = context; |
69 } | 69 } |
70 | 70 |
71 void SkErrorInternals::DefaultErrorCallback(SkError code, void *context) { | 71 void SkErrorInternals::DefaultErrorCallback(SkError code, void *context) { |
72 SkDebugf("Skia Error: %s\n", SkGetLastErrorString()); | 72 SkDebugf("Skia Error: %s\n", SkGetLastErrorString()); |
73 } | 73 } |
74 | 74 |
75 void SkErrorInternals::ClearError() { | 75 void SkErrorInternals::ClearError() { |
76 SkErrorInternals::SetError( kNoError_SkError, "All is well" ); | 76 SkErrorInternals::SetError( kNoError_SkError, "All is well" ); |
77 } | 77 } |
78 | 78 |
79 SkError SkErrorInternals::GetLastError() { | 79 SkError SkErrorInternals::GetLastError() { |
80 return THREAD_ERROR; | 80 return THREAD_ERROR; |
81 } | 81 } |
82 | 82 |
83 const char *SkErrorInternals::GetLastErrorString() { | 83 const char *SkErrorInternals::GetLastErrorString() { |
84 return THREAD_ERROR_STRING; | 84 return THREAD_ERROR_STRING; |
85 } | 85 } |
86 | 86 |
87 void SkErrorInternals::SetError(SkError code, const char *fmt, ...) { | 87 void SkErrorInternals::SetError(SkError code, const char *fmt, ...) { |
88 THREAD_ERROR = code; | 88 THREAD_ERROR = code; |
89 va_list args; | 89 va_list args; |
90 | 90 |
91 char *str = THREAD_ERROR_STRING; | 91 char *str = THREAD_ERROR_STRING; |
92 const char *error_name = NULL; | 92 const char *error_name = nullptr; |
93 switch( code ) { | 93 switch( code ) { |
94 case kNoError_SkError: | 94 case kNoError_SkError: |
95 error_name = "No Error"; | 95 error_name = "No Error"; |
96 break; | 96 break; |
97 case kInvalidArgument_SkError: | 97 case kInvalidArgument_SkError: |
98 error_name = "Invalid Argument"; | 98 error_name = "Invalid Argument"; |
99 break; | 99 break; |
100 case kInvalidOperation_SkError: | 100 case kInvalidOperation_SkError: |
101 error_name = "Invalid Operation"; | 101 error_name = "Invalid Operation"; |
102 break; | 102 break; |
(...skipping 19 matching lines...) Expand all Loading... |
122 str += strlen(str); | 122 str += strlen(str); |
123 | 123 |
124 va_start( args, fmt ); | 124 va_start( args, fmt ); |
125 vsnprintf( str, string_left, fmt, args ); | 125 vsnprintf( str, string_left, fmt, args ); |
126 va_end( args ); | 126 va_end( args ); |
127 SkErrorCallbackFunction fn = THREAD_ERROR_CALLBACK; | 127 SkErrorCallbackFunction fn = THREAD_ERROR_CALLBACK; |
128 if (fn && code != kNoError_SkError) { | 128 if (fn && code != kNoError_SkError) { |
129 fn(code, THREAD_ERROR_CONTEXT); | 129 fn(code, THREAD_ERROR_CONTEXT); |
130 } | 130 } |
131 } | 131 } |
OLD | NEW |