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) | 10 #if defined(SK_BUILD_FOR_ANDROID) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 | 43 |
44 SkOSWindow* SkOSWindow::GetInstanceForWindowID(Uint32 windowID) { | 44 SkOSWindow* SkOSWindow::GetInstanceForWindowID(Uint32 windowID) { |
45 if (gCurrentWindow && | 45 if (gCurrentWindow && |
46 gCurrentWindow->fWindow && | 46 gCurrentWindow->fWindow && |
47 SDL_GetWindowID(gCurrentWindow->fWindow) == windowID) { | 47 SDL_GetWindowID(gCurrentWindow->fWindow) == windowID) { |
48 return gCurrentWindow; | 48 return gCurrentWindow; |
49 } | 49 } |
50 return nullptr; | 50 return nullptr; |
51 } | 51 } |
52 | 52 |
53 void SkOSWindow::detach() { | 53 void SkOSWindow::release() { |
54 if (fGLContext) { | 54 if (fGLContext) { |
55 SDL_GL_DeleteContext(fGLContext); | 55 SDL_GL_DeleteContext(fGLContext); |
56 fGLContext = nullptr; | 56 fGLContext = nullptr; |
57 } | 57 } |
58 } | 58 } |
59 | 59 |
60 bool SkOSWindow::attach(SkBackEndTypes attachType, int msaaSampleCount, Attachme
ntInfo* info) { | 60 bool SkOSWindow::attach(SkBackEndTypes attachType, int msaaSampleCount, Attachme
ntInfo* info) { |
61 this->createWindow(msaaSampleCount); | 61 this->createWindow(msaaSampleCount); |
62 if (!fWindow) { | 62 if (!fWindow) { |
63 return false; | 63 return false; |
64 } | 64 } |
65 if (!fGLContext) { | 65 if (!fGLContext) { |
66 fGLContext = SDL_GL_CreateContext(fWindow); | 66 fGLContext = SDL_GL_CreateContext(fWindow); |
67 if (!fGLContext) { | 67 if (!fGLContext) { |
68 report_sdl_error("Failed to create SDL GL context."); | 68 report_sdl_error("Failed to create SDL GL context."); |
69 return false; | 69 return false; |
70 } | 70 } |
71 glClearColor(0, 0, 0, 0); | 71 glClearColor(0, 0, 0, 0); |
72 glClearStencil(0); | 72 glClearStencil(0); |
73 glStencilMask(0xffffffff); | 73 glStencilMask(0xffffffff); |
74 glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); | 74 glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
75 } | 75 } |
76 | 76 |
77 if (SDL_GL_MakeCurrent(fWindow, fGLContext) != 0) { | 77 if (SDL_GL_MakeCurrent(fWindow, fGLContext) != 0) { |
78 report_sdl_error("Failed to make SDL GL context current."); | 78 report_sdl_error("Failed to make SDL GL context current."); |
79 this->detach(); | 79 this->release(); |
80 return false; | 80 return false; |
81 } | 81 } |
82 | 82 |
83 info->fSampleCount = msaaSampleCount; | 83 info->fSampleCount = msaaSampleCount; |
84 info->fStencilBits = 8; | 84 info->fStencilBits = 8; |
85 | 85 |
86 glViewport(0, 0, SkScalarRoundToInt(this->width()), SkScalarRoundToInt(this-
>height())); | 86 glViewport(0, 0, SkScalarRoundToInt(this->width()), SkScalarRoundToInt(this-
>height())); |
87 return true; | 87 return true; |
88 } | 88 } |
89 | 89 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 fWindow = SDL_CreateWindow(this->getTitle(), SDL_WINDOWPOS_CENTERED, SDL_WIN
DOWPOS_CENTERED, | 212 fWindow = SDL_CreateWindow(this->getTitle(), SDL_WINDOWPOS_CENTERED, SDL_WIN
DOWPOS_CENTERED, |
213 windowWidth, windowHeight, windowFlags); | 213 windowWidth, windowHeight, windowFlags); |
214 if (!fWindow) { | 214 if (!fWindow) { |
215 report_sdl_error("Failed to create SDL window."); | 215 report_sdl_error("Failed to create SDL window."); |
216 return; | 216 return; |
217 } | 217 } |
218 fWindowMSAASampleCount = msaaSampleCount; | 218 fWindowMSAASampleCount = msaaSampleCount; |
219 } | 219 } |
220 | 220 |
221 void SkOSWindow::destroyWindow() { | 221 void SkOSWindow::destroyWindow() { |
222 this->detach(); | 222 this->release(); |
223 if (fWindow) { | 223 if (fWindow) { |
224 SDL_DestroyWindow(fWindow); | 224 SDL_DestroyWindow(fWindow); |
225 fWindow = nullptr; | 225 fWindow = nullptr; |
226 fWindowMSAASampleCount = 0; | 226 fWindowMSAASampleCount = 0; |
227 } | 227 } |
228 } | 228 } |
229 | 229 |
230 bool SkOSWindow::HasDirtyWindows() { | 230 bool SkOSWindow::HasDirtyWindows() { |
231 if (gCurrentWindow && gCurrentWindow->fWindow) { | 231 if (gCurrentWindow && gCurrentWindow->fWindow) { |
232 return gCurrentWindow->isDirty(); | 232 return gCurrentWindow->isDirty(); |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 | 391 |
392 SkOSWindow::RunEventLoop(); | 392 SkOSWindow::RunEventLoop(); |
393 | 393 |
394 delete window; | 394 delete window; |
395 application_term(); | 395 application_term(); |
396 | 396 |
397 SDL_Quit(); | 397 SDL_Quit(); |
398 | 398 |
399 return 0; | 399 return 0; |
400 } | 400 } |
OLD | NEW |