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