| 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" | 
| 11 #include "SkError.h" | 11 #include "SkError.h" | 
| 12 #include "SkErrorInternals.h" | 12 #include "SkErrorInternals.h" | 
| 13 | 13 | 
| 14 #include <stdio.h> | 14 #include <stdio.h> | 
| 15 #include <stdarg.h> | 15 #include <stdarg.h> | 
| 16 | 16 | 
| 17 namespace { | 17 namespace { | 
| 18     void *CreateThreadError() { | 18 void *CreateThreadError() { return new SkError(kNoError_SkError); } | 
| 19         return SkNEW_ARGS(SkError, (kNoError_SkError)); | 19 void DeleteThreadError(void *v) { delete reinterpret_cast<SkError *>(v); } | 
| 20     } |  | 
| 21     void DeleteThreadError(void* v) { |  | 
| 22         SkDELETE(reinterpret_cast<SkError*>(v)); |  | 
| 23     } |  | 
| 24     #define THREAD_ERROR \ | 20     #define THREAD_ERROR \ | 
| 25         (*reinterpret_cast<SkError*>(SkTLS::Get(CreateThreadError, DeleteThreadE
     rror))) | 21         (*reinterpret_cast<SkError*>(SkTLS::Get(CreateThreadError, DeleteThreadE
     rror))) | 
| 26 | 22 | 
| 27     void *CreateThreadErrorCallback() { | 23     void *CreateThreadErrorCallback() { | 
| 28         return SkNEW_ARGS(SkErrorCallbackFunction, (SkErrorInternals::DefaultErr
     orCallback)); | 24         return new SkErrorCallbackFunction(SkErrorInternals::DefaultErrorCallbac
     k); | 
| 29     } | 25     } | 
| 30     void DeleteThreadErrorCallback(void* v) { | 26     void DeleteThreadErrorCallback(void* v) { | 
| 31         SkDELETE(reinterpret_cast<SkErrorCallbackFunction *>(v)); | 27         delete reinterpret_cast<SkErrorCallbackFunction *>(v); | 
| 32     } | 28     } | 
| 33 | 29 | 
| 34     #define THREAD_ERROR_CALLBACK                                               
                   \ | 30     #define THREAD_ERROR_CALLBACK                                               
                   \ | 
| 35         *(reinterpret_cast<SkErrorCallbackFunction *>(SkTLS::Get(CreateThreadErr
     orCallback,   \ | 31         *(reinterpret_cast<SkErrorCallbackFunction *>(SkTLS::Get(CreateThreadErr
     orCallback,   \ | 
| 36                                                                  DeleteThreadErr
     orCallback))) | 32                                                                  DeleteThreadErr
     orCallback))) | 
| 37 | 33 | 
| 38     void *CreateThreadErrorContext() { | 34     void *CreateThreadErrorContext() { return new void **(NULL); } | 
| 39         return SkNEW_ARGS(void **, (NULL)); | 35     void DeleteThreadErrorContext(void *v) { delete reinterpret_cast<void **>(v)
     ; } | 
| 40     } |  | 
| 41     void DeleteThreadErrorContext(void* v) { |  | 
| 42         SkDELETE(reinterpret_cast<void **>(v)); |  | 
| 43     } |  | 
| 44     #define THREAD_ERROR_CONTEXT \ | 36     #define THREAD_ERROR_CONTEXT \ | 
| 45         (*reinterpret_cast<void **>(SkTLS::Get(CreateThreadErrorContext, DeleteT
     hreadErrorContext))) | 37         (*reinterpret_cast<void **>(SkTLS::Get(CreateThreadErrorContext, DeleteT
     hreadErrorContext))) | 
| 46 | 38 | 
| 47     #define ERROR_STRING_LENGTH 2048 | 39     #define ERROR_STRING_LENGTH 2048 | 
| 48 | 40 | 
| 49     void *CreateThreadErrorString() { | 41     void *CreateThreadErrorString() { return new char[(ERROR_STRING_LENGTH)]; } | 
| 50         return SkNEW_ARRAY(char, (ERROR_STRING_LENGTH)); | 42     void DeleteThreadErrorString(void *v) { delete[] reinterpret_cast<char *>(v)
     ; } | 
| 51     } |  | 
| 52     void DeleteThreadErrorString(void* v) { |  | 
| 53         SkDELETE_ARRAY(reinterpret_cast<char *>(v)); |  | 
| 54     } |  | 
| 55     #define THREAD_ERROR_STRING \ | 43     #define THREAD_ERROR_STRING \ | 
| 56         (reinterpret_cast<char *>(SkTLS::Get(CreateThreadErrorString, DeleteThre
     adErrorString))) | 44         (reinterpret_cast<char *>(SkTLS::Get(CreateThreadErrorString, DeleteThre
     adErrorString))) | 
| 57 } | 45 } | 
| 58 | 46 | 
| 59 SkError SkGetLastError() { | 47 SkError SkGetLastError() { | 
| 60     return SkErrorInternals::GetLastError(); | 48     return SkErrorInternals::GetLastError(); | 
| 61 } | 49 } | 
| 62 void SkClearLastError() { | 50 void SkClearLastError() { | 
| 63     SkErrorInternals::ClearError(); | 51     SkErrorInternals::ClearError(); | 
| 64 } | 52 } | 
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 134     str += strlen(str); | 122     str += strlen(str); | 
| 135 | 123 | 
| 136     va_start( args, fmt ); | 124     va_start( args, fmt ); | 
| 137     vsnprintf( str, string_left, fmt, args ); | 125     vsnprintf( str, string_left, fmt, args ); | 
| 138     va_end( args ); | 126     va_end( args ); | 
| 139     SkErrorCallbackFunction fn = THREAD_ERROR_CALLBACK; | 127     SkErrorCallbackFunction fn = THREAD_ERROR_CALLBACK; | 
| 140     if (fn && code != kNoError_SkError) { | 128     if (fn && code != kNoError_SkError) { | 
| 141         fn(code, THREAD_ERROR_CONTEXT); | 129         fn(code, THREAD_ERROR_CONTEXT); | 
| 142     } | 130     } | 
| 143 } | 131 } | 
| OLD | NEW | 
|---|