caryclark | 936b734 | 2014-07-11 12:14:51 -0700 | [diff] [blame] | 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" |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 11 | #include "SkApplication.h" |
caryclark | 936b734 | 2014-07-11 12:14:51 -0700 | [diff] [blame] | 12 | #include "SkCanvas.h" |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 13 | #include "SkCommonFlags.h" |
caryclark | 936b734 | 2014-07-11 12:14:51 -0700 | [diff] [blame] | 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 | |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 56 | DEFINE_bool(dm, false, "run dm"); |
| 57 | DEFINE_bool(nanobench, false, "run nanobench"); |
caryclark | 936b734 | 2014-07-11 12:14:51 -0700 | [diff] [blame] | 58 | |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 59 | int nanobench_main(); |
| 60 | int dm_main(); |
| 61 | |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 62 | IOS_launch_type set_cmd_line_args(int argc, char *argv[], const char* resourceDir) { |
| 63 | SkCommandLineFlags::Parse(argc, argv); |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 64 | if (FLAGS_nanobench) { |
| 65 | return nanobench_main() ? kError_iOSLaunchType : kTool_iOSLaunchType; |
caryclark | 936b734 | 2014-07-11 12:14:51 -0700 | [diff] [blame] | 66 | } |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 67 | if (FLAGS_dm) { |
| 68 | return dm_main() ? kError_iOSLaunchType : kTool_iOSLaunchType; |
| 69 | } |
| 70 | return kError_iOSLaunchType; |
caryclark | 936b734 | 2014-07-11 12:14:51 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | // FIXME: this should be in a header |
| 74 | SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv); |
| 75 | SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) { |
| 76 | return new ShellWindow(hwnd, argc, argv); |
| 77 | } |
| 78 | |
| 79 | // FIXME: this should be in a header |
caryclark | 936b734 | 2014-07-11 12:14:51 -0700 | [diff] [blame] | 80 | void application_init(); |
| 81 | void application_init() { |
| 82 | SkGraphics::Init(); |
| 83 | SkEvent::Init(); |
| 84 | } |
| 85 | |
| 86 | // FIXME: this should be in a header |
| 87 | void application_term(); |
| 88 | void application_term() { |
| 89 | SkEvent::Term(); |
caryclark | 936b734 | 2014-07-11 12:14:51 -0700 | [diff] [blame] | 90 | } |