| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include <dlfcn.h> | 8 #include <dlfcn.h> |
| 9 #include <stdio.h> | 9 #include <stdio.h> |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 const char** argv) { | 27 const char** argv) { |
| 28 return (*app_main)(argc, argv); | 28 return (*app_main)(argc, argv); |
| 29 } | 29 } |
| 30 | 30 |
| 31 void* load_library(const char* appLocation, const char* libraryName) | 31 void* load_library(const char* appLocation, const char* libraryName) |
| 32 { | 32 { |
| 33 // attempt to lookup the location of the shared libraries | 33 // attempt to lookup the location of the shared libraries |
| 34 char libraryLocation[100]; | 34 char libraryLocation[100]; |
| 35 sprintf(libraryLocation, "%s/lib/lib%s.so", appLocation, libraryName); | 35 sprintf(libraryLocation, "%s/lib/lib%s.so", appLocation, libraryName); |
| 36 if (!file_exists(libraryLocation)) { | 36 if (!file_exists(libraryLocation)) { |
| 37 printf("ERROR: Unable to find the appropriate library in the Skia App.\n
"); | 37 printf("ERROR: Unable to find the '%s' library in the Skia App.\n", libr
aryName); |
| 38 printf("ERROR: Did you provide the correct program_name?\n"); | 38 printf("ERROR: Did you provide the correct program_name?\n"); |
| 39 usage(); | 39 usage(); |
| 40 return NULL; | 40 return NULL; |
| 41 } | 41 } |
| 42 | 42 |
| 43 // load the appropriate library | 43 // load the appropriate library |
| 44 void* appLibrary = dlopen(libraryLocation, RTLD_LOCAL | RTLD_LAZY); | 44 void* appLibrary = dlopen(libraryLocation, RTLD_LOCAL | RTLD_LAZY); |
| 45 if (!appLibrary) { | 45 if (!appLibrary) { |
| 46 printf("ERROR: Unable to open the shared library.\n"); | 46 printf("ERROR: Unable to open the shared library.\n"); |
| 47 printf("ERROR: %s", dlerror()); | 47 printf("ERROR: %s", dlerror()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 61 } | 61 } |
| 62 | 62 |
| 63 // attempt to lookup the location of the skia app | 63 // attempt to lookup the location of the skia app |
| 64 const char* appLocation = "/data/data/com.skia"; | 64 const char* appLocation = "/data/data/com.skia"; |
| 65 if (!file_exists(appLocation)) { | 65 if (!file_exists(appLocation)) { |
| 66 printf("ERROR: Unable to find the com.skia app on the device.\n"); | 66 printf("ERROR: Unable to find the com.skia app on the device.\n"); |
| 67 return -1; | 67 return -1; |
| 68 } | 68 } |
| 69 | 69 |
| 70 // load the local skia shared library | 70 // load the local skia shared library |
| 71 void* skiaLibrary = load_library(appLocation, "libskia_android.so"); | 71 void* skiaLibrary = load_library(appLocation, "skia_android"); |
| 72 if (NULL == skiaLibrary) | 72 if (NULL == skiaLibrary) |
| 73 { | 73 { |
| 74 return -1; | 74 return -1; |
| 75 } | 75 } |
| 76 | 76 |
| 77 // load the appropriate library | 77 // load the appropriate library |
| 78 void* appLibrary = load_library(appLocation, argv[1]); | 78 void* appLibrary = load_library(appLocation, argv[1]); |
| 79 if (NULL == appLibrary) { | 79 if (NULL == appLibrary) { |
| 80 return -1; | 80 return -1; |
| 81 } | 81 } |
| 82 | 82 |
| 83 // find the address of the main function | 83 // find the address of the main function |
| 84 int (*app_main)(int, const char**); | 84 int (*app_main)(int, const char**); |
| 85 *(void **) (&app_main) = dlsym(appLibrary, "main"); | 85 *(void **) (&app_main) = dlsym(appLibrary, "main"); |
| 86 | 86 |
| 87 if (!app_main) { | 87 if (!app_main) { |
| 88 printf("ERROR: Unable to load the main function of the selected program.
\n"); | 88 printf("ERROR: Unable to load the main function of the selected program.
\n"); |
| 89 printf("ERROR: %s\n", dlerror()); | 89 printf("ERROR: %s\n", dlerror()); |
| 90 return -1; | 90 return -1; |
| 91 } | 91 } |
| 92 | 92 |
| 93 // find the address of the SkPrintToConsole function | 93 // find the address of the SkPrintToConsole function |
| 94 void (*app_SkDebugToStdOut)(bool); | 94 void (*app_SkDebugToStdOut)(bool); |
| 95 *(void **) (&app_SkDebugToStdOut) = dlsym(appLibrary, "AndroidSkDebugToStdOu
t"); | 95 *(void **) (&app_SkDebugToStdOut) = dlsym(skiaLibrary, "AndroidSkDebugToStdO
ut"); |
| 96 | 96 |
| 97 if (app_SkDebugToStdOut) { | 97 if (app_SkDebugToStdOut) { |
| 98 (*app_SkDebugToStdOut)(true); | 98 (*app_SkDebugToStdOut)(true); |
| 99 } else { | 99 } else { |
| 100 printf("WARNING: Unable to redirect output to the console.\n"); | 100 printf("WARNING: Unable to redirect output to the console.\n"); |
| 101 printf("WARNING: %s\n", dlerror()); | 101 printf("WARNING: %s\n", dlerror()); |
| 102 } | 102 } |
| 103 | 103 |
| 104 // pass all additional arguments to the main function | 104 // pass all additional arguments to the main function |
| 105 return launch_app(app_main, argc - 1, ++argv); | 105 return launch_app(app_main, argc - 1, ++argv); |
| 106 } | 106 } |
| OLD | NEW |