daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 1 | // |
Nicolas Capens | 3501c16 | 2014-05-21 13:27:15 -0400 | [diff] [blame] | 2 | // Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved. |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 7 | // Surface.cpp: Implements the egl::Surface class, representing a drawing surface |
| 8 | // such as the client area of a window, including any back buffers. |
| 9 | // Implements EGLSurface and related functionality. [EGL 1.4] section 2.2 page 3. |
| 10 | |
| 11 | #include <tchar.h> |
| 12 | |
Scott Graham | 86f601c | 2013-09-17 13:28:00 -0700 | [diff] [blame] | 13 | #include <algorithm> |
| 14 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 15 | #include "libEGL/Surface.h" |
| 16 | |
| 17 | #include "common/debug.h" |
| 18 | #include "libGLESv2/Texture.h" |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 19 | #include "libGLESv2/renderer/SwapChain.h" |
daniel@transgaming.com | cfa8efd | 2012-11-28 19:30:55 +0000 | [diff] [blame] | 20 | #include "libGLESv2/main.h" |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 21 | |
| 22 | #include "libEGL/main.h" |
| 23 | #include "libEGL/Display.h" |
| 24 | |
Cooper Partin | eeb1f53 | 2014-09-23 10:25:02 -0700 | [diff] [blame^] | 25 | #include "common/NativeWindow.h" |
| 26 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 27 | namespace egl |
| 28 | { |
| 29 | |
Cooper Partin | eeb1f53 | 2014-09-23 10:25:02 -0700 | [diff] [blame^] | 30 | Surface::Surface(Display *display, const Config *config, EGLNativeWindowType window, EGLint fixedSize, EGLint width, EGLint height, EGLint postSubBufferSupported) |
| 31 | : mDisplay(display), mConfig(config), mNativeWindow(window), mPostSubBufferSupported(postSubBufferSupported) |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 32 | { |
daniel@transgaming.com | b9bb279 | 2012-11-28 19:36:49 +0000 | [diff] [blame] | 33 | mRenderer = mDisplay->getRenderer(); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 34 | mSwapChain = NULL; |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 35 | mShareHandle = NULL; |
| 36 | mTexture = NULL; |
| 37 | mTextureFormat = EGL_NO_TEXTURE; |
| 38 | mTextureTarget = EGL_NO_TEXTURE; |
| 39 | |
| 40 | mPixelAspectRatio = (EGLint)(1.0 * EGL_DISPLAY_SCALING); // FIXME: Determine actual pixel aspect ratio |
| 41 | mRenderBuffer = EGL_BACK_BUFFER; |
| 42 | mSwapBehavior = EGL_BUFFER_PRESERVED; |
| 43 | mSwapInterval = -1; |
John Bauman | 3dc300a | 2014-01-28 15:30:35 -0800 | [diff] [blame] | 44 | mWidth = width; |
| 45 | mHeight = height; |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 46 | setSwapInterval(1); |
John Bauman | 3dc300a | 2014-01-28 15:30:35 -0800 | [diff] [blame] | 47 | mFixedSize = fixedSize; |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 48 | |
| 49 | subclassWindow(); |
| 50 | } |
| 51 | |
| 52 | Surface::Surface(Display *display, const Config *config, HANDLE shareHandle, EGLint width, EGLint height, EGLenum textureFormat, EGLenum textureType) |
Cooper Partin | eeb1f53 | 2014-09-23 10:25:02 -0700 | [diff] [blame^] | 53 | : mDisplay(display), mNativeWindow(NULL), mConfig(config), mShareHandle(shareHandle), mWidth(width), mHeight(height), mPostSubBufferSupported(EGL_FALSE) |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 54 | { |
daniel@transgaming.com | 28e3692 | 2012-11-28 21:02:47 +0000 | [diff] [blame] | 55 | mRenderer = mDisplay->getRenderer(); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 56 | mSwapChain = NULL; |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 57 | mWindowSubclassed = false; |
| 58 | mTexture = NULL; |
| 59 | mTextureFormat = textureFormat; |
| 60 | mTextureTarget = textureType; |
| 61 | |
| 62 | mPixelAspectRatio = (EGLint)(1.0 * EGL_DISPLAY_SCALING); // FIXME: Determine actual pixel aspect ratio |
| 63 | mRenderBuffer = EGL_BACK_BUFFER; |
| 64 | mSwapBehavior = EGL_BUFFER_PRESERVED; |
| 65 | mSwapInterval = -1; |
| 66 | setSwapInterval(1); |
John Bauman | 3dc300a | 2014-01-28 15:30:35 -0800 | [diff] [blame] | 67 | // This constructor is for offscreen surfaces, which are always fixed-size. |
| 68 | mFixedSize = EGL_TRUE; |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | Surface::~Surface() |
| 72 | { |
| 73 | unsubclassWindow(); |
| 74 | release(); |
| 75 | } |
| 76 | |
| 77 | bool Surface::initialize() |
| 78 | { |
Cooper Partin | eeb1f53 | 2014-09-23 10:25:02 -0700 | [diff] [blame^] | 79 | if (mNativeWindow.getNativeWindow()) |
| 80 | { |
| 81 | if (!mNativeWindow.initialize()) |
| 82 | { |
| 83 | return false; |
| 84 | } |
| 85 | } |
| 86 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 87 | if (!resetSwapChain()) |
| 88 | return false; |
| 89 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 90 | return true; |
| 91 | } |
| 92 | |
| 93 | void Surface::release() |
| 94 | { |
daniel@transgaming.com | b9bb279 | 2012-11-28 19:36:49 +0000 | [diff] [blame] | 95 | delete mSwapChain; |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 96 | mSwapChain = NULL; |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 97 | |
| 98 | if (mTexture) |
| 99 | { |
| 100 | mTexture->releaseTexImage(); |
| 101 | mTexture = NULL; |
| 102 | } |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | bool Surface::resetSwapChain() |
| 106 | { |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 107 | ASSERT(!mSwapChain); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 108 | |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 109 | int width; |
| 110 | int height; |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 111 | |
John Bauman | 3dc300a | 2014-01-28 15:30:35 -0800 | [diff] [blame] | 112 | if (!mFixedSize) |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 113 | { |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 114 | RECT windowRect; |
Cooper Partin | eeb1f53 | 2014-09-23 10:25:02 -0700 | [diff] [blame^] | 115 | if (!mNativeWindow.getClientRect(&windowRect)) |
apatrick@chromium.org | 85e4419 | 2012-08-17 20:58:01 +0000 | [diff] [blame] | 116 | { |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 117 | ASSERT(false); |
| 118 | |
| 119 | ERR("Could not retrieve the window dimensions"); |
| 120 | return error(EGL_BAD_SURFACE, false); |
apatrick@chromium.org | 85e4419 | 2012-08-17 20:58:01 +0000 | [diff] [blame] | 121 | } |
apatrick@chromium.org | 0c71fd4 | 2012-08-10 18:08:47 +0000 | [diff] [blame] | 122 | |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 123 | width = windowRect.right - windowRect.left; |
| 124 | height = windowRect.bottom - windowRect.top; |
| 125 | } |
| 126 | else |
| 127 | { |
| 128 | // non-window surface - size is determined at creation |
| 129 | width = mWidth; |
| 130 | height = mHeight; |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 131 | } |
| 132 | |
Cooper Partin | eeb1f53 | 2014-09-23 10:25:02 -0700 | [diff] [blame^] | 133 | mSwapChain = mRenderer->createSwapChain(mNativeWindow, mShareHandle, |
daniel@transgaming.com | b9bb279 | 2012-11-28 19:36:49 +0000 | [diff] [blame] | 134 | mConfig->mRenderTargetFormat, |
| 135 | mConfig->mDepthStencilFormat); |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 136 | if (!mSwapChain) |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 137 | { |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 138 | return error(EGL_BAD_ALLOC, false); |
| 139 | } |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 140 | |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 141 | if (!resetSwapChain(width, height)) |
| 142 | { |
daniel@transgaming.com | b9bb279 | 2012-11-28 19:36:49 +0000 | [diff] [blame] | 143 | delete mSwapChain; |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 144 | mSwapChain = NULL; |
daniel@transgaming.com | 2a99bfa | 2012-10-31 19:55:50 +0000 | [diff] [blame] | 145 | return false; |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 146 | } |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 147 | |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 148 | return true; |
| 149 | } |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 150 | |
shannon.woods@transgaming.com | c71ca75 | 2013-02-28 23:06:50 +0000 | [diff] [blame] | 151 | bool Surface::resizeSwapChain(int backbufferWidth, int backbufferHeight) |
| 152 | { |
| 153 | ASSERT(backbufferWidth >= 0 && backbufferHeight >= 0); |
| 154 | ASSERT(mSwapChain); |
| 155 | |
John Bauman | 3dc300a | 2014-01-28 15:30:35 -0800 | [diff] [blame] | 156 | EGLint status = mSwapChain->resize(std::max(1, backbufferWidth), std::max(1, backbufferHeight)); |
shannon.woods@transgaming.com | c71ca75 | 2013-02-28 23:06:50 +0000 | [diff] [blame] | 157 | |
| 158 | if (status == EGL_CONTEXT_LOST) |
| 159 | { |
| 160 | mDisplay->notifyDeviceLost(); |
| 161 | return false; |
| 162 | } |
| 163 | else if (status != EGL_SUCCESS) |
| 164 | { |
| 165 | return error(status, false); |
| 166 | } |
| 167 | |
| 168 | mWidth = backbufferWidth; |
| 169 | mHeight = backbufferHeight; |
| 170 | |
| 171 | return true; |
| 172 | } |
| 173 | |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 174 | bool Surface::resetSwapChain(int backbufferWidth, int backbufferHeight) |
| 175 | { |
| 176 | ASSERT(backbufferWidth >= 0 && backbufferHeight >= 0); |
| 177 | ASSERT(mSwapChain); |
| 178 | |
John Bauman | 3dc300a | 2014-01-28 15:30:35 -0800 | [diff] [blame] | 179 | EGLint status = mSwapChain->reset(std::max(1, backbufferWidth), std::max(1, backbufferHeight), mSwapInterval); |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 180 | |
| 181 | if (status == EGL_CONTEXT_LOST) |
| 182 | { |
shannon.woods@transgaming.com | eb049e2 | 2013-02-28 23:04:49 +0000 | [diff] [blame] | 183 | mRenderer->notifyDeviceLost(); |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 184 | return false; |
| 185 | } |
| 186 | else if (status != EGL_SUCCESS) |
| 187 | { |
| 188 | return error(status, false); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 189 | } |
| 190 | |
apatrick@chromium.org | 0c71fd4 | 2012-08-10 18:08:47 +0000 | [diff] [blame] | 191 | mWidth = backbufferWidth; |
| 192 | mHeight = backbufferHeight; |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 193 | mSwapIntervalDirty = false; |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 194 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 195 | return true; |
| 196 | } |
| 197 | |
| 198 | bool Surface::swapRect(EGLint x, EGLint y, EGLint width, EGLint height) |
| 199 | { |
| 200 | if (!mSwapChain) |
| 201 | { |
| 202 | return true; |
| 203 | } |
| 204 | |
| 205 | if (x + width > mWidth) |
| 206 | { |
| 207 | width = mWidth - x; |
| 208 | } |
| 209 | |
| 210 | if (y + height > mHeight) |
| 211 | { |
| 212 | height = mHeight - y; |
| 213 | } |
| 214 | |
| 215 | if (width == 0 || height == 0) |
| 216 | { |
| 217 | return true; |
| 218 | } |
| 219 | |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 220 | EGLint status = mSwapChain->swapRect(x, y, width, height); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 221 | |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 222 | if (status == EGL_CONTEXT_LOST) |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 223 | { |
shannon.woods@transgaming.com | eb049e2 | 2013-02-28 23:04:49 +0000 | [diff] [blame] | 224 | mRenderer->notifyDeviceLost(); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 225 | return false; |
| 226 | } |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 227 | else if (status != EGL_SUCCESS) |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 228 | { |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 229 | return error(status, false); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 230 | } |
| 231 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 232 | checkForOutOfDateSwapChain(); |
| 233 | |
| 234 | return true; |
| 235 | } |
| 236 | |
Cooper Partin | eeb1f53 | 2014-09-23 10:25:02 -0700 | [diff] [blame^] | 237 | EGLNativeWindowType Surface::getWindowHandle() |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 238 | { |
Cooper Partin | eeb1f53 | 2014-09-23 10:25:02 -0700 | [diff] [blame^] | 239 | return mNativeWindow.getNativeWindow(); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | |
| 243 | #define kSurfaceProperty _TEXT("Egl::SurfaceOwner") |
| 244 | #define kParentWndProc _TEXT("Egl::SurfaceParentWndProc") |
| 245 | |
| 246 | static LRESULT CALLBACK SurfaceWindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) |
| 247 | { |
| 248 | if (message == WM_SIZE) |
| 249 | { |
| 250 | Surface* surf = reinterpret_cast<Surface*>(GetProp(hwnd, kSurfaceProperty)); |
| 251 | if(surf) |
| 252 | { |
| 253 | surf->checkForOutOfDateSwapChain(); |
| 254 | } |
| 255 | } |
| 256 | WNDPROC prevWndFunc = reinterpret_cast<WNDPROC >(GetProp(hwnd, kParentWndProc)); |
| 257 | return CallWindowProc(prevWndFunc, hwnd, message, wparam, lparam); |
| 258 | } |
| 259 | |
| 260 | void Surface::subclassWindow() |
| 261 | { |
Cooper Partin | eeb1f53 | 2014-09-23 10:25:02 -0700 | [diff] [blame^] | 262 | HWND window = mNativeWindow.getNativeWindow(); |
| 263 | if (!window) |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 264 | { |
| 265 | return; |
| 266 | } |
| 267 | |
| 268 | DWORD processId; |
Cooper Partin | eeb1f53 | 2014-09-23 10:25:02 -0700 | [diff] [blame^] | 269 | DWORD threadId = GetWindowThreadProcessId(window, &processId); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 270 | if (processId != GetCurrentProcessId() || threadId != GetCurrentThreadId()) |
| 271 | { |
| 272 | return; |
| 273 | } |
| 274 | |
| 275 | SetLastError(0); |
Cooper Partin | eeb1f53 | 2014-09-23 10:25:02 -0700 | [diff] [blame^] | 276 | LONG_PTR oldWndProc = SetWindowLongPtr(window, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(SurfaceWindowProc)); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 277 | if(oldWndProc == 0 && GetLastError() != ERROR_SUCCESS) |
| 278 | { |
| 279 | mWindowSubclassed = false; |
| 280 | return; |
| 281 | } |
| 282 | |
Cooper Partin | eeb1f53 | 2014-09-23 10:25:02 -0700 | [diff] [blame^] | 283 | SetProp(window, kSurfaceProperty, reinterpret_cast<HANDLE>(this)); |
| 284 | SetProp(window, kParentWndProc, reinterpret_cast<HANDLE>(oldWndProc)); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 285 | mWindowSubclassed = true; |
| 286 | } |
| 287 | |
| 288 | void Surface::unsubclassWindow() |
| 289 | { |
| 290 | if(!mWindowSubclassed) |
| 291 | { |
| 292 | return; |
| 293 | } |
| 294 | |
Cooper Partin | eeb1f53 | 2014-09-23 10:25:02 -0700 | [diff] [blame^] | 295 | HWND window = mNativeWindow.getNativeWindow(); |
| 296 | if (!window) |
| 297 | { |
| 298 | return; |
| 299 | } |
| 300 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 301 | // un-subclass |
Cooper Partin | eeb1f53 | 2014-09-23 10:25:02 -0700 | [diff] [blame^] | 302 | LONG_PTR parentWndFunc = reinterpret_cast<LONG_PTR>(GetProp(window, kParentWndProc)); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 303 | |
| 304 | // Check the windowproc is still SurfaceWindowProc. |
| 305 | // If this assert fails, then it is likely the application has subclassed the |
| 306 | // hwnd as well and did not unsubclass before destroying its EGL context. The |
| 307 | // application should be modified to either subclass before initializing the |
| 308 | // EGL context, or to unsubclass before destroying the EGL context. |
| 309 | if(parentWndFunc) |
| 310 | { |
Cooper Partin | eeb1f53 | 2014-09-23 10:25:02 -0700 | [diff] [blame^] | 311 | LONG_PTR prevWndFunc = SetWindowLongPtr(window, GWLP_WNDPROC, parentWndFunc); |
Geoff Lang | 9cd1915 | 2014-05-28 15:54:34 -0400 | [diff] [blame] | 312 | UNUSED_ASSERTION_VARIABLE(prevWndFunc); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 313 | ASSERT(prevWndFunc == reinterpret_cast<LONG_PTR>(SurfaceWindowProc)); |
| 314 | } |
| 315 | |
Cooper Partin | eeb1f53 | 2014-09-23 10:25:02 -0700 | [diff] [blame^] | 316 | RemoveProp(window, kSurfaceProperty); |
| 317 | RemoveProp(window, kParentWndProc); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 318 | mWindowSubclassed = false; |
| 319 | } |
| 320 | |
| 321 | bool Surface::checkForOutOfDateSwapChain() |
| 322 | { |
| 323 | RECT client; |
John Bauman | 3dc300a | 2014-01-28 15:30:35 -0800 | [diff] [blame] | 324 | int clientWidth = getWidth(); |
| 325 | int clientHeight = getHeight(); |
| 326 | bool sizeDirty = false; |
Cooper Partin | eeb1f53 | 2014-09-23 10:25:02 -0700 | [diff] [blame^] | 327 | if (!mFixedSize && !mNativeWindow.isIconic()) |
John Bauman | 827a471 | 2013-10-29 16:03:11 -0700 | [diff] [blame] | 328 | { |
| 329 | // The window is automatically resized to 150x22 when it's minimized, but the swapchain shouldn't be resized |
| 330 | // because that's not a useful size to render to. |
Cooper Partin | eeb1f53 | 2014-09-23 10:25:02 -0700 | [diff] [blame^] | 331 | if (!mNativeWindow.getClientRect(&client)) |
John Bauman | 3dc300a | 2014-01-28 15:30:35 -0800 | [diff] [blame] | 332 | { |
| 333 | ASSERT(false); |
| 334 | return false; |
| 335 | } |
| 336 | |
| 337 | // Grow the buffer now, if the window has grown. We need to grow now to avoid losing information. |
| 338 | clientWidth = client.right - client.left; |
| 339 | clientHeight = client.bottom - client.top; |
| 340 | sizeDirty = clientWidth != getWidth() || clientHeight != getHeight(); |
John Bauman | 827a471 | 2013-10-29 16:03:11 -0700 | [diff] [blame] | 341 | } |
| 342 | |
Jamie Madill | 58e6032 | 2013-12-02 11:09:36 -0500 | [diff] [blame] | 343 | bool wasDirty = (mSwapIntervalDirty || sizeDirty); |
| 344 | |
shannon.woods@transgaming.com | c71ca75 | 2013-02-28 23:06:50 +0000 | [diff] [blame] | 345 | if (mSwapIntervalDirty) |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 346 | { |
| 347 | resetSwapChain(clientWidth, clientHeight); |
shannon.woods@transgaming.com | c71ca75 | 2013-02-28 23:06:50 +0000 | [diff] [blame] | 348 | } |
| 349 | else if (sizeDirty) |
| 350 | { |
| 351 | resizeSwapChain(clientWidth, clientHeight); |
| 352 | } |
| 353 | |
Jamie Madill | 58e6032 | 2013-12-02 11:09:36 -0500 | [diff] [blame] | 354 | if (wasDirty) |
shannon.woods@transgaming.com | c71ca75 | 2013-02-28 23:06:50 +0000 | [diff] [blame] | 355 | { |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 356 | if (static_cast<egl::Surface*>(getCurrentDrawSurface()) == this) |
| 357 | { |
| 358 | glMakeCurrent(glGetCurrentContext(), static_cast<egl::Display*>(getCurrentDisplay()), this); |
| 359 | } |
| 360 | |
| 361 | return true; |
| 362 | } |
shannon.woods@transgaming.com | c71ca75 | 2013-02-28 23:06:50 +0000 | [diff] [blame] | 363 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 364 | return false; |
| 365 | } |
| 366 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 367 | bool Surface::swap() |
| 368 | { |
| 369 | return swapRect(0, 0, mWidth, mHeight); |
| 370 | } |
| 371 | |
| 372 | bool Surface::postSubBuffer(EGLint x, EGLint y, EGLint width, EGLint height) |
| 373 | { |
| 374 | if (!mPostSubBufferSupported) |
| 375 | { |
| 376 | // Spec is not clear about how this should be handled. |
| 377 | return true; |
| 378 | } |
Nicolas Capens | 3501c16 | 2014-05-21 13:27:15 -0400 | [diff] [blame] | 379 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 380 | return swapRect(x, y, width, height); |
| 381 | } |
| 382 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 383 | EGLint Surface::isPostSubBufferSupported() const |
| 384 | { |
| 385 | return mPostSubBufferSupported; |
| 386 | } |
| 387 | |
daniel@transgaming.com | 76d3e6e | 2012-10-31 19:55:33 +0000 | [diff] [blame] | 388 | rx::SwapChain *Surface::getSwapChain() const |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 389 | { |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 390 | return mSwapChain; |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | void Surface::setSwapInterval(EGLint interval) |
| 394 | { |
| 395 | if (mSwapInterval == interval) |
| 396 | { |
| 397 | return; |
| 398 | } |
Nicolas Capens | 3501c16 | 2014-05-21 13:27:15 -0400 | [diff] [blame] | 399 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 400 | mSwapInterval = interval; |
daniel@transgaming.com | 114bd46 | 2012-10-31 18:42:47 +0000 | [diff] [blame] | 401 | mSwapInterval = std::max(mSwapInterval, mRenderer->getMinSwapInterval()); |
| 402 | mSwapInterval = std::min(mSwapInterval, mRenderer->getMaxSwapInterval()); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 403 | |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 404 | mSwapIntervalDirty = true; |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 405 | } |
| 406 | |
Nicolas Capens | 3501c16 | 2014-05-21 13:27:15 -0400 | [diff] [blame] | 407 | EGLint Surface::getConfigID() const |
| 408 | { |
| 409 | return mConfig->mConfigID; |
| 410 | } |
| 411 | |
| 412 | EGLint Surface::getWidth() const |
| 413 | { |
| 414 | return mWidth; |
| 415 | } |
| 416 | |
| 417 | EGLint Surface::getHeight() const |
| 418 | { |
| 419 | return mHeight; |
| 420 | } |
| 421 | |
| 422 | EGLint Surface::getPixelAspectRatio() const |
| 423 | { |
| 424 | return mPixelAspectRatio; |
| 425 | } |
| 426 | |
| 427 | EGLenum Surface::getRenderBuffer() const |
| 428 | { |
| 429 | return mRenderBuffer; |
| 430 | } |
| 431 | |
| 432 | EGLenum Surface::getSwapBehavior() const |
| 433 | { |
| 434 | return mSwapBehavior; |
| 435 | } |
| 436 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 437 | EGLenum Surface::getTextureFormat() const |
| 438 | { |
| 439 | return mTextureFormat; |
| 440 | } |
| 441 | |
| 442 | EGLenum Surface::getTextureTarget() const |
| 443 | { |
| 444 | return mTextureTarget; |
| 445 | } |
| 446 | |
| 447 | void Surface::setBoundTexture(gl::Texture2D *texture) |
| 448 | { |
| 449 | mTexture = texture; |
| 450 | } |
| 451 | |
| 452 | gl::Texture2D *Surface::getBoundTexture() const |
| 453 | { |
| 454 | return mTexture; |
| 455 | } |
| 456 | |
John Bauman | 3dc300a | 2014-01-28 15:30:35 -0800 | [diff] [blame] | 457 | EGLint Surface::isFixedSize() const |
| 458 | { |
| 459 | return mFixedSize; |
| 460 | } |
| 461 | |
daniel@transgaming.com | 106e1f7 | 2012-10-31 18:38:36 +0000 | [diff] [blame] | 462 | EGLenum Surface::getFormat() const |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 463 | { |
| 464 | return mConfig->mRenderTargetFormat; |
| 465 | } |
| 466 | } |