Some iOS fixes to make SampleApp work better.

Changes:
- Rebuild argc and argv so we can process command line arguments
- Remove unnecessary SimpleiOSApp files
- Add support for reading files from the app bundle
- Add gpu flag so we can start up directly into OpenGL

Review URL: https://codereview.chromium.org/1382943004
diff --git a/experimental/iOSSampleApp/SkSampleUIView.mm b/experimental/iOSSampleApp/SkSampleUIView.mm
index f442f5a..3d82627 100644
--- a/experimental/iOSSampleApp/SkSampleUIView.mm
+++ b/experimental/iOSSampleApp/SkSampleUIView.mm
@@ -316,12 +316,27 @@
         fRasterLayer.actions = newActions;
         [newActions release];
         
+        // rebuild argc and argv from process info
+        NSArray* arguments = [[NSProcessInfo processInfo] arguments];
+        int argc = [arguments count];
+        char** argv = new char*[argc];
+        for (int i = 0; i < argc; ++i) {
+            NSString* arg = [arguments objectAtIndex:i];
+            int strlen = [arg lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
+            argv[i] = new char[strlen+1];
+            [arg getCString:argv[i] maxLength:strlen+1 encoding:NSUTF8StringEncoding];
+        }
+        
         fDevManager = new SkiOSDeviceManager(fGL.fFramebuffer);
-        static char* kDummyArgv = const_cast<char*>("dummyExecutableName");
-        fWind = new SampleWindow(self, 1, &kDummyArgv, fDevManager);
+        fWind = new SampleWindow(self, argc, argv, fDevManager);
 
         fWind->resize(self.frame.size.width, self.frame.size.height,
                       kN32_SkColorType);
+        
+        for (int i = 0; i < argc; ++i) {
+            delete [] argv[i];
+        }
+        delete [] argv;
     }
     return self;
 }
diff --git a/gyp/SampleApp.gyp b/gyp/SampleApp.gyp
index c2bdb3a..e73eb2d 100644
--- a/gyp/SampleApp.gyp
+++ b/gyp/SampleApp.gyp
@@ -4,9 +4,6 @@
 # found in the LICENSE file.
 #
 {
-  'includes': [
-    'apptype_console.gypi',
-  ],
   'targets': [
     {
       'target_name': 'SampleApp',
@@ -158,13 +155,20 @@
         'views_animated.gyp:views_animated',
         'xml.gyp:xml',
       ],
+      'msvs_settings': {
+        'VCLinkerTool': {
+          #Allows for creation / output to console.
+          #Console (/SUBSYSTEM:CONSOLE)
+          'SubSystem': '1',
+
+          #Console app, use main/wmain
+          'EntryPointSymbol': 'mainCRTStartup',
+        },
+      },
       'conditions' : [
         [ 'skia_os == "ios"', {
+          'mac_bundle' : 1,
           # TODO: This doesn't build properly yet, but it's getting there.
-          'sources!': [
-            '../samplecode/SampleDecode.cpp',
-            '../experimental/SimpleiOSApp/SimpleApp.mm',
-          ],
           'sources': [
             '../src/views/mac/SkEventNotifier.mm',
             '../experimental/iOSSampleApp/SkSampleUIView.mm',
@@ -182,12 +186,10 @@
             # iPad
             '../experimental/iOSSampleApp/iPad/AppDelegate_iPad.mm',
             '../experimental/iOSSampleApp/iPad/SkUISplitViewController.mm',
-            '../experimental/iOSSampleApp/iPad/MainWindow_iPad.xib',
 
             # iPhone
             '../experimental/iOSSampleApp/iPhone/AppDelegate_iPhone.mm',
             '../experimental/iOSSampleApp/iPhone/SkUINavigationController.mm',
-            '../experimental/iOSSampleApp/iPhone/MainWindow_iPhone.xib',
 
             '../src/views/ios/SkOSWindow_iOS.mm',
 
@@ -229,11 +231,20 @@
           'sources!': [
             '../samplecode/SampleAnimator.cpp',
           ],
+          'conditions': [
+            ['skia_android_framework == 0', {
+              'dependencies': [
+                'android_deps.gyp:Android_EntryPoint',
+                'skia_launcher.gyp:skia_launcher',
+              ],
+            }],
+          ],
           'dependencies!': [
             'animator.gyp:animator',
             'experimental.gyp:experimental',
           ],
           'dependencies': [
+            'android_output.gyp:android_output',
             'android_deps.gyp:Android_SampleApp',
           ],
         }],
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp
index 02c5e03..c891508 100644
--- a/samplecode/SampleApp.cpp
+++ b/samplecode/SampleApp.cpp
@@ -711,6 +711,7 @@
 DEFINE_string(picture, "", "Path to single picture.");
 DEFINE_bool(sort, false, "Sort samples by title.");
 DEFINE_bool(list, false, "List samples?");
+DEFINE_bool(gpu, false, "Start up with gpu?");
 DEFINE_string(key, "", "");  // dummy to enable gm tests that have platform-specific names
 #ifdef SAMPLE_PDF_FILE_VIEWER
 DEFINE_string(pdfPath, "", "Path to direcotry of pdf files.");
@@ -799,6 +800,9 @@
 #endif
 
     fDeviceType = kRaster_DeviceType;
+    if (FLAGS_gpu) {
+        fDeviceType = kGPU_DeviceType;
+    }
 
 #if DEFAULT_TO_GPU
     fDeviceType = kGPU_DeviceType;
diff --git a/src/ports/SkOSFile_stdio.cpp b/src/ports/SkOSFile_stdio.cpp
index 261d061..53a2bb4 100644
--- a/src/ports/SkOSFile_stdio.cpp
+++ b/src/ports/SkOSFile_stdio.cpp
@@ -17,6 +17,34 @@
 #include <io.h>
 #endif
 
+#ifdef SK_BUILD_FOR_IOS
+#import <CoreFoundation/CoreFoundation.h>
+
+static FILE* ios_open_from_bundle(const char path[], const char* perm) {
+    // Get a reference to the main bundle
+    CFBundleRef mainBundle = CFBundleGetMainBundle();
+    
+    // Get a reference to the file's URL
+    CFStringRef pathRef = CFStringCreateWithCString(NULL, path, kCFStringEncodingUTF8);
+    CFURLRef imageURL = CFBundleCopyResourceURL(mainBundle, pathRef, NULL, NULL);
+    if (!imageURL) {
+        return nullptr;
+    }
+    
+    // Convert the URL reference into a string reference
+    CFStringRef imagePath = CFURLCopyFileSystemPath(imageURL, kCFURLPOSIXPathStyle);
+    
+    // Get the system encoding method
+    CFStringEncoding encodingMethod = CFStringGetSystemEncoding();
+    
+    // Convert the string reference into a C string
+    const char *finalPath = CFStringGetCStringPtr(imagePath, encodingMethod);
+   
+    return fopen(finalPath, perm);
+}
+#endif
+
+
 SkFILE* sk_fopen(const char path[], SkFILE_Flags flags) {
     char    perm[4];
     char*   p = perm;
@@ -29,10 +57,22 @@
     }
     *p++ = 'b';
     *p = 0;
-
+    
     //TODO: on Windows fopen is just ASCII or the current code page,
     //convert to utf16 and use _wfopen
-    SkFILE* file = (SkFILE*)::fopen(path, perm);
+    SkFILE* file = nullptr;
+#ifdef SK_BUILD_FOR_IOS
+    // if read-only, try to open from bundle first
+    if (kRead_SkFILE_Flag == flags) {
+        file = (SkFILE*)ios_open_from_bundle(path, perm);
+    }
+    // otherwise just read from the Documents directory (default)
+    if (!file) {
+#endif
+        file = (SkFILE*)::fopen(path, perm);
+#ifdef SK_BUILD_FOR_IOS
+    }
+#endif
     if (nullptr == file && (flags & kWrite_SkFILE_Flag)) {
         SkDEBUGF(("sk_fopen: fopen(\"%s\", \"%s\") returned NULL (errno:%d): %s\n",
                   path, perm, errno, strerror(errno)));