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 | |
Jamie Madill | 93e13fb | 2014-11-06 15:27:25 -0500 | [diff] [blame] | 23 | //TODO(jmadill): phase this out |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 24 | #include "libANGLE/renderer/d3d/RendererD3D.h" |
Jamie Madill | 93e13fb | 2014-11-06 15:27:25 -0500 | [diff] [blame] | 25 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 26 | namespace egl |
| 27 | { |
| 28 | |
Cooper Partin | eeb1f53 | 2014-09-23 10:25:02 -0700 | [diff] [blame] | 29 | Surface::Surface(Display *display, const Config *config, EGLNativeWindowType window, EGLint fixedSize, EGLint width, EGLint height, EGLint postSubBufferSupported) |
| 30 | : mDisplay(display), mConfig(config), mNativeWindow(window), mPostSubBufferSupported(postSubBufferSupported) |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 31 | { |
Jamie Madill | 93e13fb | 2014-11-06 15:27:25 -0500 | [diff] [blame] | 32 | //TODO(jmadill): MANGLE refactor. (note, can't call makeRendererD3D because of dll export issues) |
| 33 | mRenderer = static_cast<rx::RendererD3D*>(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 | { |
Jamie Madill | 93e13fb | 2014-11-06 15:27:25 -0500 | [diff] [blame] | 55 | //TODO(jmadill): MANGLE refactor. (note, can't call makeRendererD3D because of dll export issues) |
| 56 | mRenderer = static_cast<rx::RendererD3D*>(mDisplay->getRenderer()); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 57 | mSwapChain = NULL; |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 58 | mWindowSubclassed = false; |
| 59 | mTexture = NULL; |
| 60 | mTextureFormat = textureFormat; |
| 61 | mTextureTarget = textureType; |
| 62 | |
| 63 | mPixelAspectRatio = (EGLint)(1.0 * EGL_DISPLAY_SCALING); // FIXME: Determine actual pixel aspect ratio |
| 64 | mRenderBuffer = EGL_BACK_BUFFER; |
| 65 | mSwapBehavior = EGL_BUFFER_PRESERVED; |
| 66 | mSwapInterval = -1; |
| 67 | setSwapInterval(1); |
John Bauman | 3dc300a | 2014-01-28 15:30:35 -0800 | [diff] [blame] | 68 | // This constructor is for offscreen surfaces, which are always fixed-size. |
| 69 | mFixedSize = EGL_TRUE; |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | Surface::~Surface() |
| 73 | { |
| 74 | unsubclassWindow(); |
| 75 | release(); |
| 76 | } |
| 77 | |
Geoff Lang | 6b0cf99 | 2014-10-06 10:28:07 -0400 | [diff] [blame] | 78 | Error Surface::initialize() |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 79 | { |
Cooper Partin | eeb1f53 | 2014-09-23 10:25:02 -0700 | [diff] [blame] | 80 | if (mNativeWindow.getNativeWindow()) |
| 81 | { |
| 82 | if (!mNativeWindow.initialize()) |
| 83 | { |
Geoff Lang | 6b0cf99 | 2014-10-06 10:28:07 -0400 | [diff] [blame] | 84 | return Error(EGL_BAD_SURFACE); |
Cooper Partin | eeb1f53 | 2014-09-23 10:25:02 -0700 | [diff] [blame] | 85 | } |
| 86 | } |
| 87 | |
Geoff Lang | 6b0cf99 | 2014-10-06 10:28:07 -0400 | [diff] [blame] | 88 | Error error = resetSwapChain(); |
| 89 | if (error.isError()) |
| 90 | { |
| 91 | return error; |
| 92 | } |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 93 | |
Geoff Lang | 6b0cf99 | 2014-10-06 10:28:07 -0400 | [diff] [blame] | 94 | return Error(EGL_SUCCESS); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | void Surface::release() |
| 98 | { |
daniel@transgaming.com | b9bb279 | 2012-11-28 19:36:49 +0000 | [diff] [blame] | 99 | delete mSwapChain; |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 100 | mSwapChain = NULL; |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 101 | |
| 102 | if (mTexture) |
| 103 | { |
| 104 | mTexture->releaseTexImage(); |
| 105 | mTexture = NULL; |
| 106 | } |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 107 | } |
| 108 | |
Geoff Lang | 6b0cf99 | 2014-10-06 10:28:07 -0400 | [diff] [blame] | 109 | Error Surface::resetSwapChain() |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 110 | { |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 111 | ASSERT(!mSwapChain); |
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 | int width; |
| 114 | int height; |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 115 | |
John Bauman | 3dc300a | 2014-01-28 15:30:35 -0800 | [diff] [blame] | 116 | if (!mFixedSize) |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 117 | { |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 118 | RECT windowRect; |
Cooper Partin | eeb1f53 | 2014-09-23 10:25:02 -0700 | [diff] [blame] | 119 | if (!mNativeWindow.getClientRect(&windowRect)) |
apatrick@chromium.org | 85e4419 | 2012-08-17 20:58:01 +0000 | [diff] [blame] | 120 | { |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 121 | ASSERT(false); |
| 122 | |
Geoff Lang | 6b0cf99 | 2014-10-06 10:28:07 -0400 | [diff] [blame] | 123 | return Error(EGL_BAD_SURFACE, "Could not retrieve the window dimensions"); |
apatrick@chromium.org | 85e4419 | 2012-08-17 20:58:01 +0000 | [diff] [blame] | 124 | } |
apatrick@chromium.org | 0c71fd4 | 2012-08-10 18:08:47 +0000 | [diff] [blame] | 125 | |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 126 | width = windowRect.right - windowRect.left; |
| 127 | height = windowRect.bottom - windowRect.top; |
| 128 | } |
| 129 | else |
| 130 | { |
| 131 | // non-window surface - size is determined at creation |
| 132 | width = mWidth; |
| 133 | height = mHeight; |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 134 | } |
| 135 | |
Cooper Partin | eeb1f53 | 2014-09-23 10:25:02 -0700 | [diff] [blame] | 136 | mSwapChain = mRenderer->createSwapChain(mNativeWindow, mShareHandle, |
daniel@transgaming.com | b9bb279 | 2012-11-28 19:36:49 +0000 | [diff] [blame] | 137 | mConfig->mRenderTargetFormat, |
| 138 | mConfig->mDepthStencilFormat); |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 139 | if (!mSwapChain) |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 140 | { |
Geoff Lang | 6b0cf99 | 2014-10-06 10:28:07 -0400 | [diff] [blame] | 141 | return Error(EGL_BAD_ALLOC); |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 142 | } |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 143 | |
Geoff Lang | 6b0cf99 | 2014-10-06 10:28:07 -0400 | [diff] [blame] | 144 | Error error = resetSwapChain(width, height); |
| 145 | if (error.isError()) |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 146 | { |
Geoff Lang | 6b0cf99 | 2014-10-06 10:28:07 -0400 | [diff] [blame] | 147 | SafeDelete(mSwapChain); |
| 148 | return error; |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 149 | } |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 150 | |
Geoff Lang | 6b0cf99 | 2014-10-06 10:28:07 -0400 | [diff] [blame] | 151 | return Error(EGL_SUCCESS); |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 152 | } |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 153 | |
Geoff Lang | 6b0cf99 | 2014-10-06 10:28:07 -0400 | [diff] [blame] | 154 | Error Surface::resizeSwapChain(int backbufferWidth, int backbufferHeight) |
shannon.woods@transgaming.com | c71ca75 | 2013-02-28 23:06:50 +0000 | [diff] [blame] | 155 | { |
| 156 | ASSERT(backbufferWidth >= 0 && backbufferHeight >= 0); |
| 157 | ASSERT(mSwapChain); |
| 158 | |
John Bauman | 3dc300a | 2014-01-28 15:30:35 -0800 | [diff] [blame] | 159 | 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] | 160 | |
| 161 | if (status == EGL_CONTEXT_LOST) |
| 162 | { |
| 163 | mDisplay->notifyDeviceLost(); |
Geoff Lang | 6b0cf99 | 2014-10-06 10:28:07 -0400 | [diff] [blame] | 164 | return Error(status); |
shannon.woods@transgaming.com | c71ca75 | 2013-02-28 23:06:50 +0000 | [diff] [blame] | 165 | } |
| 166 | else if (status != EGL_SUCCESS) |
| 167 | { |
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 | |
| 171 | mWidth = backbufferWidth; |
| 172 | mHeight = backbufferHeight; |
| 173 | |
Geoff Lang | 6b0cf99 | 2014-10-06 10:28:07 -0400 | [diff] [blame] | 174 | return Error(EGL_SUCCESS); |
shannon.woods@transgaming.com | c71ca75 | 2013-02-28 23:06:50 +0000 | [diff] [blame] | 175 | } |
| 176 | |
Geoff Lang | 6b0cf99 | 2014-10-06 10:28:07 -0400 | [diff] [blame] | 177 | Error Surface::resetSwapChain(int backbufferWidth, int backbufferHeight) |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 178 | { |
| 179 | ASSERT(backbufferWidth >= 0 && backbufferHeight >= 0); |
| 180 | ASSERT(mSwapChain); |
| 181 | |
John Bauman | 3dc300a | 2014-01-28 15:30:35 -0800 | [diff] [blame] | 182 | 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] | 183 | |
| 184 | if (status == EGL_CONTEXT_LOST) |
| 185 | { |
Jamie Madill | 4c76fea | 2014-11-24 11:38:52 -0500 | [diff] [blame] | 186 | //TODO(jmadill): MANGLE refactor |
| 187 | rx::RendererD3D *rendererD3D = static_cast<rx::RendererD3D*>(mRenderer); |
| 188 | rendererD3D->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 | { |
Jamie Madill | 4c76fea | 2014-11-24 11:38:52 -0500 | [diff] [blame] | 229 | //TODO(jmadill): MANGLE refactor |
| 230 | rx::RendererD3D *rendererD3D = static_cast<rx::RendererD3D*>(mRenderer); |
| 231 | rendererD3D->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 | |
Geoff Lang | 6a1e6b9 | 2014-11-06 10:42:45 -0500 | [diff] [blame] | 366 | return wasDirty; |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 367 | } |
| 368 | |
Geoff Lang | 6b0cf99 | 2014-10-06 10:28:07 -0400 | [diff] [blame] | 369 | Error Surface::swap() |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 370 | { |
| 371 | return swapRect(0, 0, mWidth, mHeight); |
| 372 | } |
| 373 | |
Geoff Lang | 6b0cf99 | 2014-10-06 10:28:07 -0400 | [diff] [blame] | 374 | Error Surface::postSubBuffer(EGLint x, EGLint y, EGLint width, EGLint height) |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 375 | { |
| 376 | if (!mPostSubBufferSupported) |
| 377 | { |
| 378 | // Spec is not clear about how this should be handled. |
Geoff Lang | 6b0cf99 | 2014-10-06 10:28:07 -0400 | [diff] [blame] | 379 | return Error(EGL_SUCCESS); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 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 | return swapRect(x, y, width, height); |
| 383 | } |
| 384 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 385 | EGLint Surface::isPostSubBufferSupported() const |
| 386 | { |
| 387 | return mPostSubBufferSupported; |
| 388 | } |
| 389 | |
daniel@transgaming.com | 76d3e6e | 2012-10-31 19:55:33 +0000 | [diff] [blame] | 390 | rx::SwapChain *Surface::getSwapChain() const |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 391 | { |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 392 | return mSwapChain; |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | void Surface::setSwapInterval(EGLint interval) |
| 396 | { |
| 397 | if (mSwapInterval == interval) |
| 398 | { |
| 399 | return; |
| 400 | } |
Nicolas Capens | 3501c16 | 2014-05-21 13:27:15 -0400 | [diff] [blame] | 401 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 402 | mSwapInterval = interval; |
daniel@transgaming.com | 114bd46 | 2012-10-31 18:42:47 +0000 | [diff] [blame] | 403 | mSwapInterval = std::max(mSwapInterval, mRenderer->getMinSwapInterval()); |
| 404 | mSwapInterval = std::min(mSwapInterval, mRenderer->getMaxSwapInterval()); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 405 | |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 406 | mSwapIntervalDirty = true; |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 407 | } |
| 408 | |
Nicolas Capens | 3501c16 | 2014-05-21 13:27:15 -0400 | [diff] [blame] | 409 | EGLint Surface::getConfigID() const |
| 410 | { |
| 411 | return mConfig->mConfigID; |
| 412 | } |
| 413 | |
| 414 | EGLint Surface::getWidth() const |
| 415 | { |
| 416 | return mWidth; |
| 417 | } |
| 418 | |
| 419 | EGLint Surface::getHeight() const |
| 420 | { |
| 421 | return mHeight; |
| 422 | } |
| 423 | |
| 424 | EGLint Surface::getPixelAspectRatio() const |
| 425 | { |
| 426 | return mPixelAspectRatio; |
| 427 | } |
| 428 | |
| 429 | EGLenum Surface::getRenderBuffer() const |
| 430 | { |
| 431 | return mRenderBuffer; |
| 432 | } |
| 433 | |
| 434 | EGLenum Surface::getSwapBehavior() const |
| 435 | { |
| 436 | return mSwapBehavior; |
| 437 | } |
| 438 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 439 | EGLenum Surface::getTextureFormat() const |
| 440 | { |
| 441 | return mTextureFormat; |
| 442 | } |
| 443 | |
| 444 | EGLenum Surface::getTextureTarget() const |
| 445 | { |
| 446 | return mTextureTarget; |
| 447 | } |
| 448 | |
| 449 | void Surface::setBoundTexture(gl::Texture2D *texture) |
| 450 | { |
| 451 | mTexture = texture; |
| 452 | } |
| 453 | |
| 454 | gl::Texture2D *Surface::getBoundTexture() const |
| 455 | { |
| 456 | return mTexture; |
| 457 | } |
| 458 | |
John Bauman | 3dc300a | 2014-01-28 15:30:35 -0800 | [diff] [blame] | 459 | EGLint Surface::isFixedSize() const |
| 460 | { |
| 461 | return mFixedSize; |
| 462 | } |
| 463 | |
daniel@transgaming.com | 106e1f7 | 2012-10-31 18:38:36 +0000 | [diff] [blame] | 464 | EGLenum Surface::getFormat() const |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 465 | { |
| 466 | return mConfig->mRenderTargetFormat; |
| 467 | } |
| 468 | } |