blob: 2e4f0fdb5e3b1a07e00a62328c7d15f931a1a071 [file] [log] [blame]
caryclark936b7342014-07-11 12:14:51 -07001/*
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"
caryclark17f0b6d2014-07-22 10:15:34 -070011#include "SkApplication.h"
caryclark936b7342014-07-11 12:14:51 -070012#include "SkCanvas.h"
caryclark17f0b6d2014-07-22 10:15:34 -070013#include "SkCommonFlags.h"
caryclark936b7342014-07-11 12:14:51 -070014#include "SkGraphics.h"
15#include "SkWindow.h"
16#include "sk_tool_utils.h"
17
18//////////////////////////////////////////////////////////////////////////////
19
20static SkView* curr_view(SkWindow* wind) {
21 SkView::F2BIter iter(wind);
22 return iter.next();
23}
24
25ShellWindow::ShellWindow(void* hwnd, int argc, char** argv)
26 : INHERITED(hwnd) {
27 SkCommandLineFlags::Parse(argc, argv);
28}
29
30ShellWindow::~ShellWindow() {
31}
32
33///////////////////////////////////////////////////////////////////////////////
34
35bool 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
48void 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
caryclark17f0b6d2014-07-22 10:15:34 -070056DEFINE_bool(dm, false, "run dm");
57DEFINE_bool(nanobench, false, "run nanobench");
caryclark936b7342014-07-11 12:14:51 -070058
jcgregorio3b27ade2014-11-13 08:06:40 -080059int nanobench_main();
60int dm_main();
61
caryclark17f0b6d2014-07-22 10:15:34 -070062IOS_launch_type set_cmd_line_args(int argc, char *argv[], const char* resourceDir) {
63 SkCommandLineFlags::Parse(argc, argv);
caryclark17f0b6d2014-07-22 10:15:34 -070064 if (FLAGS_nanobench) {
65 return nanobench_main() ? kError_iOSLaunchType : kTool_iOSLaunchType;
caryclark936b7342014-07-11 12:14:51 -070066 }
caryclark17f0b6d2014-07-22 10:15:34 -070067 if (FLAGS_dm) {
68 return dm_main() ? kError_iOSLaunchType : kTool_iOSLaunchType;
69 }
70 return kError_iOSLaunchType;
caryclark936b7342014-07-11 12:14:51 -070071}
72
73// FIXME: this should be in a header
74SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv);
75SkOSWindow* 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
caryclark936b7342014-07-11 12:14:51 -070080void application_init();
81void application_init() {
82 SkGraphics::Init();
83 SkEvent::Init();
84}
85
86// FIXME: this should be in a header
87void application_term();
88void application_term() {
89 SkEvent::Term();
caryclark936b7342014-07-11 12:14:51 -070090}