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