Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: platform_tools/android/launcher/skia_launcher.cpp

Issue 15855006: prepare skia for shared library build on android (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebasing Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « platform_tools/android/gyp/skia_android.gypi ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 10 matching lines...) Expand all
21 return true; 21 return true;
22 } 22 }
23 return false; 23 return false;
24 } 24 }
25 25
26 int launch_app(int (*app_main)(int, const char**), int argc, 26 int launch_app(int (*app_main)(int, const char**), int argc,
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** argv, const char* libraryName)
32 {
33 // attempt to lookup the location of the shared libraries
34 char libraryLocation[100];
35 sprintf(libraryLocation, "%s/lib/lib%s.so", argv[0], libraryName);
36 if (!file_exists(libraryLocation)) {
37 printf("ERROR: Unable to find the appropriate library in the Skia App.\n ");
38 printf("ERROR: Did you provide the correct program_name?\n");
39 usage(argv[0]);
40 return NULL;
41 }
42
43 // load the appropriate library
44 void* appLibrary = dlopen(libraryLocation, RTLD_LOCAL | RTLD_LAZY);
45 if (!appLibrary) {
46 printf("ERROR: Unable to open the shared library.\n");
47 printf("ERROR: %s", dlerror());
48 return NULL;
49 }
50
51 return appLibrary;
52 }
53
31 int main(int argc, const char** argv) { 54 int main(int argc, const char** argv) {
32 55
33 // check that the program name was specified 56 // check that the program name was specified
34 if (argc < 2) { 57 if (argc < 2) {
35 printf("ERROR: No program_name was specified\n"); 58 printf("ERROR: No program_name was specified\n");
36 usage(argv[0]); 59 usage(argv[0]);
37 return -1; 60 return -1;
38 } 61 }
39 62
40 // attempt to lookup the location of the skia app 63 // attempt to lookup the location of the skia app
41 const char* appLocation = "/data/data/com.skia"; 64 const char* appLocation = "/data/data/com.skia";
42 if (!file_exists(appLocation)) { 65 if (!file_exists(appLocation)) {
43 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");
44 return -1; 67 return -1;
45 } 68 }
46 69
47 // attempt to lookup the location of the shared libraries 70 // load the local skia shared library
48 char libraryLocation[100]; 71 void* skiaLibrary = load_library(argv, "libskia_android.so");
49 sprintf(libraryLocation, "%s/lib/lib%s.so", appLocation, argv[1]); 72 if (NULL == skiaLibrary)
50 if (!file_exists(libraryLocation)) { 73 {
51 printf("ERROR: Unable to find the appropriate library in the Skia App.\n ");
52 printf("ERROR: Did you provide the correct program_name?\n");
53 usage(argv[0]);
54 return -1; 74 return -1;
55 } 75 }
56 76
57 // load the appropriate library 77 // load the appropriate library
58 void* appLibrary = dlopen(libraryLocation, RTLD_LOCAL | RTLD_LAZY); 78 void* appLibrary = load_library(argv, argv[1]);
59 if (!appLibrary) { 79 if (NULL == appLibrary) {
60 printf("ERROR: Unable to open the shared library.\n");
61 printf("ERROR: %s", dlerror());
62 return -1; 80 return -1;
63 } 81 }
64 82
65 // find the address of the main function 83 // find the address of the main function
66 int (*app_main)(int, const char**); 84 int (*app_main)(int, const char**);
67 *(void **) (&app_main) = dlsym(appLibrary, "main"); 85 *(void **) (&app_main) = dlsym(appLibrary, "main");
68 86
69 if (!app_main) { 87 if (!app_main) {
70 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");
71 printf("ERROR: %s\n", dlerror()); 89 printf("ERROR: %s\n", dlerror());
72 return -1; 90 return -1;
73 } 91 }
74 92
75 // find the address of the SkPrintToConsole function 93 // find the address of the SkPrintToConsole function
76 void (*app_SkDebugToStdOut)(bool); 94 void (*app_SkDebugToStdOut)(bool);
77 *(void **) (&app_SkDebugToStdOut) = dlsym(appLibrary, "AndroidSkDebugToStdOu t"); 95 *(void **) (&app_SkDebugToStdOut) = dlsym(appLibrary, "AndroidSkDebugToStdOu t");
78 96
79 if (app_SkDebugToStdOut) { 97 if (app_SkDebugToStdOut) {
80 (*app_SkDebugToStdOut)(true); 98 (*app_SkDebugToStdOut)(true);
81 } else { 99 } else {
82 printf("WARNING: Unable to redirect output to the console.\n"); 100 printf("WARNING: Unable to redirect output to the console.\n");
83 printf("WARNING: %s\n", dlerror()); 101 printf("WARNING: %s\n", dlerror());
84 } 102 }
85 103
86 // pass all additional arguments to the main function 104 // pass all additional arguments to the main function
87 return launch_app(app_main, argc - 1, ++argv); 105 return launch_app(app_main, argc - 1, ++argv);
88 } 106 }
OLDNEW
« no previous file with comments | « platform_tools/android/gyp/skia_android.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698