diff options
author | senorblanco@chromium.org <senorblanco@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-06-28 19:44:03 +0000 |
---|---|---|
committer | senorblanco@chromium.org <senorblanco@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-06-28 19:44:03 +0000 |
commit | 78b8253c0a389a484e15439722e35a1658eb3b01 (patch) | |
tree | 732fb5f2f8655c841de93343a1a26417a1d79533 /src | |
parent | 4809fc862957010dad610c68bdff5058d8b16a4c (diff) |
Parse SampleApp command line for a test name. If an argument is passed to
SampleApp on the command line, interpret it as a test name. If it's a valid
test, open that test at startup.
Review URL: http://codereview.appspot.com/4661054/
git-svn-id: http://skia.googlecode.com/svn/trunk@1742 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r-- | src/utils/mac/skia_mac.cpp | 86 | ||||
-rw-r--r-- | src/utils/win/skia_win.cpp | 41 |
2 files changed, 77 insertions, 50 deletions
diff --git a/src/utils/mac/skia_mac.cpp b/src/utils/mac/skia_mac.cpp index a1345cf62c..653e663b16 100644 --- a/src/utils/mac/skia_mac.cpp +++ b/src/utils/mac/skia_mac.cpp @@ -1,43 +1,43 @@ -#include <Carbon/Carbon.h>
-#include "SkApplication.h"
-#include "SkWindow.h"
-
-int main(int argc, char* argv[])
-{
- WindowRef window;
- OSStatus err = noErr;
-
- Rect bounds = {100, 100, 500, 500};
- WindowAttributes attrs = kWindowStandardHandlerAttribute |
- kWindowLiveResizeAttribute |
- kWindowInWindowMenuAttribute |
- kWindowCompositingAttribute |
- kWindowAsyncDragAttribute |
- kWindowFullZoomAttribute |
- kWindowFrameworkScaledAttribute;
- //kWindowDoesNotCycleAttribute;
- CreateNewWindow(kDocumentWindowClass, attrs, &bounds, &window);
-
- MenuRef menu;
- CreateNewMenu(0, 0, &menu);
-
- // if we get here, we can start our normal Skia sequence
- {
- application_init();
- (void)create_sk_window(window);
- SizeWindow(window, 640, 480, false);
- }
-
- // The window was created hidden so show it.
- ShowWindow( window );
-
- // Call the event loop
- RunApplicationEventLoop();
-
- application_term();
-
-CantCreateWindow:
-CantGetNibRef:
- return err;
-}
-
+#include <Carbon/Carbon.h> +#include "SkApplication.h" +#include "SkWindow.h" + +int main(int argc, char* argv[]) +{ + WindowRef window; + OSStatus err = noErr; + + Rect bounds = {100, 100, 500, 500}; + WindowAttributes attrs = kWindowStandardHandlerAttribute | + kWindowLiveResizeAttribute | + kWindowInWindowMenuAttribute | + kWindowCompositingAttribute | + kWindowAsyncDragAttribute | + kWindowFullZoomAttribute | + kWindowFrameworkScaledAttribute; + //kWindowDoesNotCycleAttribute; + CreateNewWindow(kDocumentWindowClass, attrs, &bounds, &window); + + MenuRef menu; + CreateNewMenu(0, 0, &menu); + + // if we get here, we can start our normal Skia sequence + { + application_init(); + (void)create_sk_window(window, argc, argv); + SizeWindow(window, 640, 480, false); + } + + // The window was created hidden so show it. + ShowWindow( window ); + + // Call the event loop + RunApplicationEventLoop(); + + application_term(); + +CantCreateWindow: +CantGetNibRef: + return err; +} + diff --git a/src/utils/win/skia_win.cpp b/src/utils/win/skia_win.cpp index 5ef1f7a755..c7aa9fd2ff 100644 --- a/src/utils/win/skia_win.cpp +++ b/src/utils/win/skia_win.cpp @@ -9,7 +9,7 @@ TCHAR szWindowClass[] = _T("SAMPLEAPP"); // the main window class name // Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
-BOOL InitInstance(HINSTANCE, int);
+BOOL InitInstance(HINSTANCE, int, LPTSTR);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
@@ -19,7 +19,6 @@ int APIENTRY _tWinMain(HINSTANCE hInstance, int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
- UNREFERENCED_PARAMETER(lpCmdLine);
MSG msg;
@@ -27,7 +26,7 @@ int APIENTRY _tWinMain(HINSTANCE hInstance, MyRegisterClass(hInstance);
// Perform application initialization:
- if (!InitInstance (hInstance, nCmdShow))
+ if (!InitInstance (hInstance, nCmdShow, lpCmdLine))
{
return FALSE;
}
@@ -82,12 +81,24 @@ ATOM MyRegisterClass(HINSTANCE hInstance) }
#include "SkOSWindow_Win.h"
-extern SkOSWindow* create_sk_window(void* hwnd);
+extern SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv);
static SkOSWindow* gSkWind;
+char* tchar_to_utf8(const TCHAR* str) {
+#ifdef _UNICODE
+ int size = WideCharToMultiByte(CP_UTF8, 0, str, wcslen(str), NULL, 0, NULL, NULL);
+ char* str8 = (char*) malloc(size+1);
+ WideCharToMultiByte(CP_UTF8, 0, str, wcslen(str), str8, size, NULL, NULL);
+ str8[size] = '\0';
+ return str8;
+#else
+ return strdup(str);
+#endif
+}
+
//
-// FUNCTION: InitInstance(HINSTANCE, int)
+// FUNCTION: InitInstance(HINSTANCE, int, LPTSTR)
//
// PURPOSE: Saves instance handle and creates main window
//
@@ -96,7 +107,9 @@ static SkOSWindow* gSkWind; // In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
-BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
+
+
+BOOL InitInstance(HINSTANCE hInstance, int nCmdShow, LPTSTR lpCmdLine)
{
HWND hWnd;
@@ -110,7 +123,21 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) return FALSE;
}
- gSkWind = create_sk_window(hWnd);
+ char* argv[4096];
+ int argc = 0;
+ TCHAR exename[1024], *next;
+ int exenameLen = GetModuleFileName(NULL, exename, 1024);
+ argv[argc++] = tchar_to_utf8(exename);
+ TCHAR* arg = _tcstok_s(lpCmdLine, _T(" "), &next);
+ while (arg != NULL) {
+ argv[argc++] = tchar_to_utf8(arg);
+ arg = _tcstok_s(NULL, _T(" "), &next);
+ }
+
+ gSkWind = create_sk_window(hWnd, argc, argv);
+ for (int i = 0; i < argc; ++i) {
+ free(argv[i]);
+ }
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
|