blob: 49be34d65b3865274d2899166465d7c9452cdc38 [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"
caryclark17f0b6d2014-07-22 10:15:34 -070015#include "SkThreadPool.h"
caryclark936b7342014-07-11 12:14:51 -070016#include "SkWindow.h"
17#include "sk_tool_utils.h"
18
19//////////////////////////////////////////////////////////////////////////////
20
21static SkView* curr_view(SkWindow* wind) {
22 SkView::F2BIter iter(wind);
23 return iter.next();
24}
25
26ShellWindow::ShellWindow(void* hwnd, int argc, char** argv)
27 : INHERITED(hwnd) {
28 SkCommandLineFlags::Parse(argc, argv);
29}
30
31ShellWindow::~ShellWindow() {
32}
33
34///////////////////////////////////////////////////////////////////////////////
35
36bool ShellWindow::onDispatchClick(int x, int y, Click::State state,
37 void* owner, unsigned modi) {
38 int w = SkScalarRoundToInt(this->width());
39 int h = SkScalarRoundToInt(this->height());
40
41 // check for the resize-box
42 if (w - x < 16 && h - y < 16) {
43 return false; // let the OS handle the click
44 } else {
45 return this->INHERITED::onDispatchClick(x, y, state, owner, modi);
46 }
47}
48
49void ShellWindow::onSizeChange() {
50 this->INHERITED::onSizeChange();
51
52 SkView::F2BIter iter(this);
53 SkView* view = iter.next();
54 view->setSize(this->width(), this->height());
55}
56
caryclark17f0b6d2014-07-22 10:15:34 -070057DEFINE_bool(dm, false, "run dm");
58DEFINE_bool(nanobench, false, "run nanobench");
caryclark936b7342014-07-11 12:14:51 -070059
caryclark17f0b6d2014-07-22 10:15:34 -070060int nanobench_main();
61int dm_main();
62
63IOS_launch_type set_cmd_line_args(int argc, char *argv[], const char* resourceDir) {
64 SkCommandLineFlags::Parse(argc, argv);
65 SetResourcePath(resourceDir);
66 if (FLAGS_nanobench) {
67 return nanobench_main() ? kError_iOSLaunchType : kTool_iOSLaunchType;
caryclark936b7342014-07-11 12:14:51 -070068 }
caryclark17f0b6d2014-07-22 10:15:34 -070069 if (FLAGS_dm) {
70 return dm_main() ? kError_iOSLaunchType : kTool_iOSLaunchType;
71 }
72 return kError_iOSLaunchType;
caryclark936b7342014-07-11 12:14:51 -070073}
74
75// FIXME: this should be in a header
76SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv);
77SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) {
78 return new ShellWindow(hwnd, argc, argv);
79}
80
81// FIXME: this should be in a header
82void get_preferred_size(int* x, int* y, int* width, int* height);
83void get_preferred_size(int* x, int* y, int* width, int* height) {
84 *x = 10;
85 *y = 50;
86 *width = 640;
87 *height = 480;
88}
89
90// FIXME: this should be in a header
91void application_init();
92void application_init() {
93 SkGraphics::Init();
94 SkEvent::Init();
95}
96
97// FIXME: this should be in a header
98void application_term();
99void application_term() {
100 SkEvent::Term();
101 SkGraphics::Term();
102}