OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 #include "SkOSWindow_SDL.h" | 7 #include "SkOSWindow_SDL.h" |
8 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 | 9 |
10 #if defined(SK_BUILD_FOR_ANDROID) | |
11 #include <GLES/gl.h> | |
12 #else | |
13 #include <GL/gl.h> | 10 #include <GL/gl.h> |
14 #endif | |
15 | 11 |
16 const int SCREEN_WIDTH = 640; | 12 const int SCREEN_WIDTH = 640; |
17 const int SCREEN_HEIGHT = 480; | 13 const int SCREEN_HEIGHT = 480; |
18 | 14 |
19 static void handle_error() { | 15 static void handle_error() { |
20 const char* error = SDL_GetError(); | 16 const char* error = SDL_GetError(); |
21 SkDebugf("SDL Error: %s\n", error); | 17 SkDebugf("SDL Error: %s\n", error); |
22 SDL_ClearError(); | 18 SDL_ClearError(); |
23 } | 19 } |
24 | 20 |
25 SkOSWindow::SkOSWindow(void* screen) : fQuit(false) , fGLContext(nullptr) { | 21 SkOSWindow::SkOSWindow(void* screen) : fQuit(false) , fGLContext(nullptr) { |
26 #if defined(SK_BUILD_FOR_ANDROID) | 22 //Create window |
27 // TODO we should try and get a 3.0 context first | 23 SDL_Init(SDL_INIT_VIDEO|SDL_INIT_GAMECONTROLLER|SDL_INIT_EVENTS); |
28 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); | 24 fWindow = SDL_CreateWindow("SDL Window", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOW
POS_UNDEFINED, |
29 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); | 25 SCREEN_WIDTH, SCREEN_HEIGHT, |
30 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); | 26 SDL_WINDOW_OPENGL|SDL_WINDOW_SHOWN ); |
31 fWindowFlags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | | |
32 SDL_WINDOW_BORDERLESS | SDL_WINDOW_FULLSCREEN_DESKTOP | | |
33 SDL_WINDOW_ALLOW_HIGHDPI; | |
34 #else | |
35 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); | |
36 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); | |
37 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE
); | |
38 SDL_StartTextInput(); | |
39 | |
40 fWindowFlags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE; | |
41 #endif | |
42 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); | |
43 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5); | |
44 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); | |
45 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); | |
46 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); | |
47 SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); | |
48 | |
49 SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); | |
50 | |
51 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) != 0) { | |
52 handle_error(); | |
53 return; | |
54 } | |
55 | |
56 SDL_DisplayMode dm; | |
57 if (SDL_GetDesktopDisplayMode(0, &dm) != 0) { | |
58 handle_error(); | |
59 return; | |
60 } | |
61 | |
62 fWindow = SDL_CreateWindow("SDL Window", SDL_WINDOWPOS_CENTERED, SDL_WINDOWP
OS_CENTERED, | |
63 dm.w, dm.h, fWindowFlags); | |
64 | |
65 if (!fWindow) { | 27 if (!fWindow) { |
66 handle_error(); | 28 handle_error(); |
67 return; | 29 return; |
68 } | 30 } |
69 this->resize(SkIntToScalar(dm.w), SkIntToScalar(dm.h)); | 31 SDL_StartTextInput(); |
| 32 this->resize(SCREEN_WIDTH, SCREEN_HEIGHT); |
70 } | 33 } |
71 | 34 |
72 SkOSWindow::~SkOSWindow() { | 35 SkOSWindow::~SkOSWindow() { |
73 if (fGLContext) { | 36 if (fGLContext) { |
74 SDL_GL_DeleteContext(fGLContext); | 37 SDL_GL_DeleteContext(fGLContext); |
75 } | 38 } |
76 | 39 |
77 //Destroy window | 40 //Destroy window |
78 SDL_DestroyWindow(fWindow); | 41 SDL_DestroyWindow(fWindow); |
79 | 42 |
80 //Quit SDL subsystems | 43 //Quit SDL subsystems |
81 SDL_Quit(); | 44 SDL_Quit(); |
82 } | 45 } |
83 | 46 |
84 void SkOSWindow::detach() { | 47 void SkOSWindow::detach() { |
85 if (fGLContext) { | 48 if (fGLContext) { |
86 SDL_GL_DeleteContext(fGLContext); | 49 SDL_GL_DeleteContext(fGLContext); |
87 fGLContext = nullptr; | 50 fGLContext = nullptr; |
88 } | 51 } |
89 | |
90 #if defined(SK_BUILD_FOR_ANDROID) | |
91 if (fWindow) { | |
92 // Destroy window | |
93 // Not totally sure why, but we have to do this or swapbuffers will hang | |
94 SDL_DestroyWindow(fWindow); | |
95 fWindow = nullptr; | |
96 } | |
97 #endif | |
98 } | 52 } |
99 | 53 |
100 bool SkOSWindow::attach(SkBackEndTypes attachType, int msaaSampleCount, Attachme
ntInfo* info) { | 54 bool SkOSWindow::attach(SkBackEndTypes attachType, int msaaSampleCount, Attachme
ntInfo*) { |
101 if (!fWindow) { | 55 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); |
102 fWindow = SDL_CreateWindow("SDL Window", SDL_WINDOWPOS_CENTERED, SDL_WIN
DOWPOS_CENTERED, | 56 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); |
103 SCREEN_WIDTH, SCREEN_HEIGHT, | 57 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE
); |
104 fWindowFlags); | 58 |
105 } | 59 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); |
| 60 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); |
| 61 SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); |
106 | 62 |
107 if (msaaSampleCount > 0) { | 63 if (msaaSampleCount > 0) { |
108 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); | 64 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); |
109 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, msaaSampleCount); | 65 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, msaaSampleCount); |
110 } | 66 } |
111 | 67 |
112 info->fSampleCount = msaaSampleCount; | |
113 info->fStencilBits = 8; | |
114 | |
115 fGLContext = SDL_GL_CreateContext(fWindow); | 68 fGLContext = SDL_GL_CreateContext(fWindow); |
116 if (!fGLContext) { | 69 if (!fGLContext) { |
117 handle_error(); | 70 handle_error(); |
118 return false; | 71 return false; |
119 } | 72 } |
120 | 73 |
121 int success = SDL_GL_MakeCurrent(fWindow, fGLContext); | 74 int success = SDL_GL_MakeCurrent(fWindow, fGLContext); |
122 if (success != 0) { | 75 if (success != 0) { |
123 handle_error(); | 76 handle_error(); |
124 return false; | 77 return false; |
125 } | 78 } |
126 | 79 |
127 glViewport(0, 0, SkScalarFloorToInt(this->width()), SkScalarFloorToInt(this-
>height())); | 80 glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); |
128 glClearColor(1, 1, 1, 1); | 81 glClearColor(1, 1, 1, 1); |
129 glClearStencil(0); | 82 glClearStencil(0); |
130 glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); | 83 glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
131 | 84 |
132 return true; | 85 return true; |
133 } | 86 } |
134 | 87 |
135 void SkOSWindow::present() { | 88 void SkOSWindow::present() { |
136 SDL_GL_SwapWindow(fWindow); | 89 SDL_GL_SwapWindow(fWindow); |
137 } | 90 } |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 ////////////////////////////////////////////////////////////////////////////////
/////// | 202 ////////////////////////////////////////////////////////////////////////////////
/////// |
250 | 203 |
251 void SkEvent::SignalNonEmptyQueue() { | 204 void SkEvent::SignalNonEmptyQueue() { |
252 // nothing to do, since we spin on our event-queue | 205 // nothing to do, since we spin on our event-queue |
253 } | 206 } |
254 | 207 |
255 void SkEvent::SignalQueueTimer(SkMSec delay) { | 208 void SkEvent::SignalQueueTimer(SkMSec delay) { |
256 // just need to record the delay time. We handle waking up for it in | 209 // just need to record the delay time. We handle waking up for it in |
257 } | 210 } |
258 | 211 |
259 void SkOSWindow::onHandleInval(const SkIRect& rect) { | 212 ////////////////////////////////////////////////////////////////////////////////
////////////// |
260 } | |
261 | 213 |
262 void SkOSWindow::onPDFSaved(const char title[], const char desc[], const char pa
th[]) { | |
263 } | |
264 | |
265 ////////////////////////////////////////////////////////////////////////////////
////////////// | |
266 | 214 |
267 #include "SkApplication.h" | 215 #include "SkApplication.h" |
268 #include "SkEvent.h" | 216 #include "SkEvent.h" |
269 #include "SkWindow.h" | 217 #include "SkWindow.h" |
270 | 218 |
271 #if defined(SK_BUILD_FOR_ANDROID) | 219 int main(int argc, char** argv){ |
272 int SDL_main(int argc, char** argv) { | |
273 #else | |
274 int main(int argc, char** argv) { | |
275 #endif | |
276 SkOSWindow* window = create_sk_window(nullptr, argc, argv); | 220 SkOSWindow* window = create_sk_window(nullptr, argc, argv); |
277 | 221 |
278 // drain any events that occurred before |window| was assigned. | 222 // drain any events that occurred before |window| was assigned. |
279 while (SkEvent::ProcessEvent()); | 223 while (SkEvent::ProcessEvent()); |
280 | 224 |
281 // Start normal Skia sequence | 225 // Start normal Skia sequence |
282 application_init(); | 226 application_init(); |
283 | 227 |
284 window->loop(); | 228 window->loop(); |
285 | 229 |
286 delete window; | 230 delete window; |
287 application_term(); | 231 application_term(); |
288 return 0; | 232 return 0; |
289 } | 233 } |
OLD | NEW |