blob: 02884c8e119cd0181841d1bb813bd54c3a162fa8 [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
80void get_preferred_size(int* x, int* y, int* width, int* height);
81void get_preferred_size(int* x, int* y, int* width, int* height) {
82 *x = 10;
83 *y = 50;
84 *width = 640;
85 *height = 480;
86}
87
88// FIXME: this should be in a header
89void application_init();
90void application_init() {
91 SkGraphics::Init();
92 SkEvent::Init();
93}
94
95// FIXME: this should be in a header
96void application_term();
97void application_term() {
98 SkEvent::Term();
caryclark936b7342014-07-11 12:14:51 -070099}