1 /* 2 * Copyright 2014 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #include "iOSShell.h" 9 10 #include "Resources.h" 11 #include "SkApplication.h" 12 #include "SkCanvas.h" 13 #include "SkCommonFlags.h" 14 #include "SkGraphics.h" 15 #include "SkWindow.h" 16 #include "sk_tool_utils.h" 17 18 ////////////////////////////////////////////////////////////////////////////// 19 20 static SkView* curr_view(SkWindow* wind) { 21 SkView::F2BIter iter(wind); 22 return iter.next(); 23 } 24 25 ShellWindow::ShellWindow(void* hwnd, int argc, char** argv) 26 : INHERITED(hwnd) { 27 SkCommandLineFlags::Parse(argc, argv); 28 } 29 30 ShellWindow::~ShellWindow() { 31 } 32 33 /////////////////////////////////////////////////////////////////////////////// 34 35 bool ShellWindow::onDispatchClick(int x, int y, Click::State state, 36 void* owner, unsigned modi) { 37 int w = SkScalarRoundToInt(this->width()); 38 int h = SkScalarRoundToInt(this->height()); 39 40 // check for the resize-box 41 if (w - x < 16 && h - y < 16) { 42 return false; // let the OS handle the click 43 } else { 44 return this->INHERITED::onDispatchClick(x, y, state, owner, modi); 45 } 46 } 47 48 void ShellWindow::onSizeChange() { 49 this->INHERITED::onSizeChange(); 50 51 SkView::F2BIter iter(this); 52 SkView* view = iter.next(); 53 view->setSize(this->width(), this->height()); 54 } 55 56 DEFINE_bool(dm, false, "run dm"); 57 DEFINE_bool(nanobench, false, "run nanobench"); 58 59 int nanobench_main(); 60 int dm_main(); 61 62 IOS_launch_type set_cmd_line_args(int argc, char *argv[], const char* resourceDir) { 63 SkCommandLineFlags::Parse(argc, argv); 64 SetResourcePath(resourceDir); 65 if (FLAGS_nanobench) { 66 return nanobench_main() ? kError_iOSLaunchType : kTool_iOSLaunchType; 67 } 68 if (FLAGS_dm) { 69 return dm_main() ? kError_iOSLaunchType : kTool_iOSLaunchType; 70 } 71 return kError_iOSLaunchType; 72 } 73 74 // FIXME: this should be in a header 75 SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv); 76 SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) { 77 return new ShellWindow(hwnd, argc, argv); 78 } 79 80 // FIXME: this should be in a header 81 void get_preferred_size(int* x, int* y, int* width, int* height); 82 void get_preferred_size(int* x, int* y, int* width, int* height) { 83 *x = 10; 84 *y = 50; 85 *width = 640; 86 *height = 480; 87 } 88 89 // FIXME: this should be in a header 90 void application_init(); 91 void application_init() { 92 SkGraphics::Init(); 93 SkEvent::Init(); 94 } 95 96 // FIXME: this should be in a header 97 void application_term(); 98 void application_term() { 99 SkEvent::Term(); 100 SkGraphics::Term(); 101 } 102