forked from youtube/cobalt_sandbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
window.h
228 lines (194 loc) · 9.46 KB
/
window.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
// Copyright 2015 The Cobalt Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Module Overview: Starboard Window module
//
// Provides functionality to handle Window creation and management.
#ifndef STARBOARD_WINDOW_H_
#define STARBOARD_WINDOW_H_
#include "starboard/export.h"
#include "starboard/types.h"
#ifdef __cplusplus
extern "C" {
#endif
// Private structure representing a system window.
typedef struct SbWindowPrivate SbWindowPrivate;
// A handle to a window.
typedef SbWindowPrivate* SbWindow;
// The size of a window in graphics rendering coordinates. The width and height
// of a window should correspond to the size of the graphics surface used for
// drawing that would be created to back that window.
typedef struct SbWindowSize {
// The width of the window in graphics pixels.
int width;
// The height of the window in graphics pixels.
int height;
// The ratio of video pixels to graphics pixels. This ratio must be applied
// equally to width and height, meaning the aspect ratio is maintained.
//
// A value of 1.0f means the video resolution is the same as the graphics
// resolution. This is the most common case.
//
// Values greater than 1.0f mean that the video resolution is higher (denser,
// larger) than the graphics resolution. This is a common case as devices
// often have more video decoding capabilities than graphics rendering
// capabilities (or memory, etc...).
//
// Values less than 1.0f mean that the maximum video resolution is smaller
// than the graphics resolution.
//
// A value of 0.0f means the ratio could not be determined, it should be
// assumed to be the same as the graphics resolution (i.e. 1.0f).
float video_pixel_ratio;
} SbWindowSize;
// Options that can be requested at window creation time.
typedef struct SbWindowOptions {
// The requested size of the new window. The value of |video_pixel_ratio| will
// not be used or looked at.
SbWindowSize size;
// Whether the new window should be windowed or not. If not, the requested
// size is really the requested resolution.
bool windowed;
// The name of the window to create.
const char* name;
} SbWindowOptions;
// Well-defined value for an invalid window handle.
#define kSbWindowInvalid ((SbWindow)NULL)
// Returns whether the given window handle is valid.
static SB_C_INLINE bool SbWindowIsValid(SbWindow window) {
return window != kSbWindowInvalid;
}
// Creates and returns a new system window with the given |options|, which may
// be |NULL|. The function returns |kSbWindowInvalid| if it cannot create the
// requested |SbWindow| due to policy, unsatisfiable options, or any other
// reason.
//
// If |options| are not specified, this function uses all defaults, which must
// work on every platform. In general, it defaults to creating a fullscreen
// window at the highest 16:9 resolution possible. If the platform does not
// support fullscreen windows, then it creates a normal, windowed window.
//
// Some devices are fullscreen-only, including many production targets for
// Starboard. In those cases, only one SbWindow may be created, and it must be
// fullscreen. Additionally, in those cases, the requested size will actually
// be the requested resolution.
//
// An SbWindow must be created to receive window-based events, like input
// events, even on fullscreen-only devices. These events are dispatched to
// the Starboard entry point.
//
// |options|: Options that specify parameters for the window being created.
SB_EXPORT SbWindow SbWindowCreate(const SbWindowOptions* options);
// Gets the size of the diagonal between two opposing screen corners.
//
// A return value of 0 means that starboard does not know what the
// screen diagonal is.
SB_EXPORT float SbWindowGetDiagonalSizeInInches(SbWindow window);
// Sets the default options for system windows.
//
// |options|: The option values to use as default values. This object must not
// be |NULL|.
SB_EXPORT void SbWindowSetDefaultOptions(SbWindowOptions* options);
// Destroys |window|, reclaiming associated resources.
//
// |window|: The |SbWindow| to destroy.
SB_EXPORT bool SbWindowDestroy(SbWindow window);
// Retrieves the dimensions of |window| and sets |size| accordingly. This
// function returns |true| if it completes successfully. If the function
// returns |false|, then |size| will not have been modified.
//
// |window|: The SbWindow to retrieve the size of.
// |size|: The retrieved size.
SB_EXPORT bool SbWindowGetSize(SbWindow window, SbWindowSize* size);
// Gets the platform-specific handle for |window|, which can be passed as an
// EGLNativeWindowType to initialize EGL/GLES. This return value is entirely
// platform-specific, so there are no constraints about expected ranges.
//
// |window|: The SbWindow to retrieve the platform handle for.
SB_EXPORT void* SbWindowGetPlatformHandle(SbWindow window);
// System-triggered OnScreenKeyboard events have ticket value
// kSbEventOnScreenKeyboardInvalidTicket.
#define kSbEventOnScreenKeyboardInvalidTicket (-1)
// Defines a rectangle via a point |(x, y)| and a size |(width, height)|. This
// structure is used as output for SbWindowGetOnScreenKeyboardBoundingRect.
typedef struct SbWindowRect {
float x;
float y;
float width;
float height;
} SbWindowRect;
// Return whether the current platform supports an on screen keyboard
SB_EXPORT bool SbWindowOnScreenKeyboardIsSupported();
// Determine if the on screen keyboard is shown.
SB_EXPORT bool SbWindowIsOnScreenKeyboardShown(SbWindow window);
// Get the rectangle of the on screen keyboard in screen pixel coordinates.
// Return |true| if successful. Return |false| if the on screen keyboard is not
// showing. If the function returns |false|, then |rect| will not have been
// modified.
SB_EXPORT
bool SbWindowGetOnScreenKeyboardBoundingRect(SbWindow window,
SbWindowRect* bounding_rect);
// Notify the system that |keepFocus| has been set for the OnScreenKeyboard.
// |keepFocus| true indicates that the user may not navigate focus off of the
// OnScreenKeyboard via input; focus may only be moved via events sent by the
// app. |keepFocus| false indicates that the user may navigate focus off of the
// OnScreenKeyboard via input. |keepFocus| is initialized to false in the
// OnScreenKeyboard constructor.
SB_EXPORT void SbWindowSetOnScreenKeyboardKeepFocus(SbWindow window,
bool keep_focus);
// Show the on screen keyboard and populate the input with text |input_text|.
// Fire kSbEventTypeWindowSizeChange and kSbEventTypeOnScreenKeyboardShown if
// necessary. kSbEventTypeOnScreenKeyboardShown has data |ticket|. The passed
// in |input_text| will never be NULL, but may be an empty string. Calling
// SbWindowShowOnScreenKeyboard() when the keyboard is already shown is
// permitted, and the input will be replaced with |input_text|. Showing the on
// screen keyboard does not give it focus.
SB_EXPORT void SbWindowShowOnScreenKeyboard(SbWindow window,
const char* input_text,
int ticket);
// Hide the on screen keyboard. Fire kSbEventTypeWindowSizeChange and
// kSbEventTypeOnScreenKeyboardHidden if necessary.
// kSbEventTypeOnScreenKeyboardHidden has data |ticket|. Calling
// SbWindowHideOnScreenKeyboard() when the keyboard is already hidden is
// permitted.
SB_EXPORT void SbWindowHideOnScreenKeyboard(SbWindow window, int ticket);
// Focus the on screen keyboard. Fire kSbEventTypeOnScreenKeyboardFocused.
// kSbEventTypeOnScreenKeyboardFocused has data |ticket|. Calling
// SbWindowFocusOnScreenKeyboard() when the keyboard is already focused is
// permitted. Calling SbWindowFocusOnScreenKeyboard while the on screen keyboard
// is not showing does nothing and does not fire any event.
SB_EXPORT void SbWindowFocusOnScreenKeyboard(SbWindow window, int ticket);
// Blur the on screen keyboard. Fire kSbEventTypeOnScreenKeyboardBlurred.
// kSbEventTypeOnScreenKeyboardBlurred has data |ticket|. Calling
// SbWindowBlurOnScreenKeyboard() when the keyboard is already blurred is
// permitted. Calling SbWindowBlurOnScreenKeyboard while the on screen keyboard
// is not showing does nothing and does not fire any event.
SB_EXPORT void SbWindowBlurOnScreenKeyboard(SbWindow window, int ticket);
// Update the on screen keyboard custom suggestions. Fire
// kSbEventTypeOnScreenKeyboardSuggestionsUpdated.
// kSbEventTypeOnScreenKeyboardSuggestionsUpdated has data |ticket|. The
// suggestions should remain up-to-date when the keyboard is shown after being
// hidden.
SB_EXPORT void SbWindowUpdateOnScreenKeyboardSuggestions(
SbWindow window,
const char* suggestions[],
int num_suggestions,
int ticket);
// Determine if the on screen keyboard has suggestions implemented. If this
// returns false, then calling SbWindowUpdateOnScreenKeyboardSuggestions() will
// be undefined.
SB_EXPORT bool SbWindowOnScreenKeyboardSuggestionsSupported(SbWindow window);
#ifdef __cplusplus
} // extern "C"
#endif
#endif // STARBOARD_WINDOW_H_