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 
curr_view(SkWindow * wind)20 static SkView* curr_view(SkWindow* wind) {
21     SkView::F2BIter iter(wind);
22     return iter.next();
23 }
24 
ShellWindow(void * hwnd,int argc,char ** argv)25 ShellWindow::ShellWindow(void* hwnd, int argc, char** argv)
26     : INHERITED(hwnd) {
27     SkCommandLineFlags::Parse(argc, argv);
28 }
29 
~ShellWindow()30 ShellWindow::~ShellWindow() {
31 }
32 
33 ///////////////////////////////////////////////////////////////////////////////
34 
onDispatchClick(int x,int y,Click::State state,void * owner,unsigned modi)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 
onSizeChange()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 
set_cmd_line_args(int argc,char * argv[],const char * resourceDir)62 IOS_launch_type set_cmd_line_args(int argc, char *argv[], const char* resourceDir) {
63     SkCommandLineFlags::Parse(argc, argv);
64     if (FLAGS_nanobench) {
65         return nanobench_main() ? kError_iOSLaunchType : kTool_iOSLaunchType;
66     }
67     if (FLAGS_dm) {
68         return dm_main() ? kError_iOSLaunchType : kTool_iOSLaunchType;
69     }
70     return kError_iOSLaunchType;
71 }
72 
73 // FIXME: this should be in a header
74 SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv);
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
80 void get_preferred_size(int* x, int* y, int* width, int* height);
get_preferred_size(int * x,int * y,int * width,int * height)81 void 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
89 void application_init();
application_init()90 void application_init() {
91     SkGraphics::Init();
92     SkEvent::Init();
93 }
94 
95 // FIXME: this should be in a header
96 void application_term();
application_term()97 void application_term() {
98     SkEvent::Term();
99 }
100