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