Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | // |
michael@0 | 2 | // Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved. |
michael@0 | 3 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 4 | // found in the LICENSE file. |
michael@0 | 5 | // |
michael@0 | 6 | |
michael@0 | 7 | // Surface.cpp: Implements the egl::Surface class, representing a drawing surface |
michael@0 | 8 | // such as the client area of a window, including any back buffers. |
michael@0 | 9 | // Implements EGLSurface and related functionality. [EGL 1.4] section 2.2 page 3. |
michael@0 | 10 | |
michael@0 | 11 | #include <tchar.h> |
michael@0 | 12 | |
michael@0 | 13 | #include "libEGL/Surface.h" |
michael@0 | 14 | |
michael@0 | 15 | #include "common/debug.h" |
michael@0 | 16 | #include "libGLESv2/Texture.h" |
michael@0 | 17 | #include "libGLESv2/renderer/SwapChain.h" |
michael@0 | 18 | #include "libGLESv2/main.h" |
michael@0 | 19 | |
michael@0 | 20 | #include "libEGL/main.h" |
michael@0 | 21 | #include "libEGL/Display.h" |
michael@0 | 22 | |
michael@0 | 23 | #include <algorithm> |
michael@0 | 24 | |
michael@0 | 25 | namespace egl |
michael@0 | 26 | { |
michael@0 | 27 | |
michael@0 | 28 | Surface::Surface(Display *display, const Config *config, HWND window, EGLint postSubBufferSupported) |
michael@0 | 29 | : mDisplay(display), mConfig(config), mWindow(window), mPostSubBufferSupported(postSubBufferSupported) |
michael@0 | 30 | { |
michael@0 | 31 | mRenderer = mDisplay->getRenderer(); |
michael@0 | 32 | mSwapChain = NULL; |
michael@0 | 33 | mShareHandle = NULL; |
michael@0 | 34 | mTexture = NULL; |
michael@0 | 35 | mTextureFormat = EGL_NO_TEXTURE; |
michael@0 | 36 | mTextureTarget = EGL_NO_TEXTURE; |
michael@0 | 37 | |
michael@0 | 38 | mPixelAspectRatio = (EGLint)(1.0 * EGL_DISPLAY_SCALING); // FIXME: Determine actual pixel aspect ratio |
michael@0 | 39 | mRenderBuffer = EGL_BACK_BUFFER; |
michael@0 | 40 | mSwapBehavior = EGL_BUFFER_PRESERVED; |
michael@0 | 41 | mSwapInterval = -1; |
michael@0 | 42 | mWidth = -1; |
michael@0 | 43 | mHeight = -1; |
michael@0 | 44 | setSwapInterval(1); |
michael@0 | 45 | |
michael@0 | 46 | subclassWindow(); |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | Surface::Surface(Display *display, const Config *config, HANDLE shareHandle, EGLint width, EGLint height, EGLenum textureFormat, EGLenum textureType) |
michael@0 | 50 | : mDisplay(display), mWindow(NULL), mConfig(config), mShareHandle(shareHandle), mWidth(width), mHeight(height), mPostSubBufferSupported(EGL_FALSE) |
michael@0 | 51 | { |
michael@0 | 52 | mRenderer = mDisplay->getRenderer(); |
michael@0 | 53 | mSwapChain = NULL; |
michael@0 | 54 | mWindowSubclassed = false; |
michael@0 | 55 | mTexture = NULL; |
michael@0 | 56 | mTextureFormat = textureFormat; |
michael@0 | 57 | mTextureTarget = textureType; |
michael@0 | 58 | |
michael@0 | 59 | mPixelAspectRatio = (EGLint)(1.0 * EGL_DISPLAY_SCALING); // FIXME: Determine actual pixel aspect ratio |
michael@0 | 60 | mRenderBuffer = EGL_BACK_BUFFER; |
michael@0 | 61 | mSwapBehavior = EGL_BUFFER_PRESERVED; |
michael@0 | 62 | mSwapInterval = -1; |
michael@0 | 63 | setSwapInterval(1); |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | Surface::~Surface() |
michael@0 | 67 | { |
michael@0 | 68 | unsubclassWindow(); |
michael@0 | 69 | release(); |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | bool Surface::initialize() |
michael@0 | 73 | { |
michael@0 | 74 | if (!resetSwapChain()) |
michael@0 | 75 | return false; |
michael@0 | 76 | |
michael@0 | 77 | return true; |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | void Surface::release() |
michael@0 | 81 | { |
michael@0 | 82 | delete mSwapChain; |
michael@0 | 83 | mSwapChain = NULL; |
michael@0 | 84 | |
michael@0 | 85 | if (mTexture) |
michael@0 | 86 | { |
michael@0 | 87 | mTexture->releaseTexImage(); |
michael@0 | 88 | mTexture = NULL; |
michael@0 | 89 | } |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | bool Surface::resetSwapChain() |
michael@0 | 93 | { |
michael@0 | 94 | ASSERT(!mSwapChain); |
michael@0 | 95 | |
michael@0 | 96 | int width; |
michael@0 | 97 | int height; |
michael@0 | 98 | |
michael@0 | 99 | if (mWindow) |
michael@0 | 100 | { |
michael@0 | 101 | RECT windowRect; |
michael@0 | 102 | if (!GetClientRect(getWindowHandle(), &windowRect)) |
michael@0 | 103 | { |
michael@0 | 104 | ASSERT(false); |
michael@0 | 105 | |
michael@0 | 106 | ERR("Could not retrieve the window dimensions"); |
michael@0 | 107 | return error(EGL_BAD_SURFACE, false); |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | width = windowRect.right - windowRect.left; |
michael@0 | 111 | height = windowRect.bottom - windowRect.top; |
michael@0 | 112 | } |
michael@0 | 113 | else |
michael@0 | 114 | { |
michael@0 | 115 | // non-window surface - size is determined at creation |
michael@0 | 116 | width = mWidth; |
michael@0 | 117 | height = mHeight; |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | mSwapChain = mRenderer->createSwapChain(mWindow, mShareHandle, |
michael@0 | 121 | mConfig->mRenderTargetFormat, |
michael@0 | 122 | mConfig->mDepthStencilFormat); |
michael@0 | 123 | if (!mSwapChain) |
michael@0 | 124 | { |
michael@0 | 125 | return error(EGL_BAD_ALLOC, false); |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | if (!resetSwapChain(width, height)) |
michael@0 | 129 | { |
michael@0 | 130 | delete mSwapChain; |
michael@0 | 131 | mSwapChain = NULL; |
michael@0 | 132 | return false; |
michael@0 | 133 | } |
michael@0 | 134 | |
michael@0 | 135 | return true; |
michael@0 | 136 | } |
michael@0 | 137 | |
michael@0 | 138 | bool Surface::resizeSwapChain(int backbufferWidth, int backbufferHeight) |
michael@0 | 139 | { |
michael@0 | 140 | ASSERT(backbufferWidth >= 0 && backbufferHeight >= 0); |
michael@0 | 141 | ASSERT(mSwapChain); |
michael@0 | 142 | |
michael@0 | 143 | EGLint status = mSwapChain->resize(backbufferWidth, backbufferHeight); |
michael@0 | 144 | |
michael@0 | 145 | if (status == EGL_CONTEXT_LOST) |
michael@0 | 146 | { |
michael@0 | 147 | mDisplay->notifyDeviceLost(); |
michael@0 | 148 | return false; |
michael@0 | 149 | } |
michael@0 | 150 | else if (status != EGL_SUCCESS) |
michael@0 | 151 | { |
michael@0 | 152 | return error(status, false); |
michael@0 | 153 | } |
michael@0 | 154 | |
michael@0 | 155 | mWidth = backbufferWidth; |
michael@0 | 156 | mHeight = backbufferHeight; |
michael@0 | 157 | |
michael@0 | 158 | return true; |
michael@0 | 159 | } |
michael@0 | 160 | |
michael@0 | 161 | bool Surface::resetSwapChain(int backbufferWidth, int backbufferHeight) |
michael@0 | 162 | { |
michael@0 | 163 | ASSERT(backbufferWidth >= 0 && backbufferHeight >= 0); |
michael@0 | 164 | ASSERT(mSwapChain); |
michael@0 | 165 | |
michael@0 | 166 | EGLint status = mSwapChain->reset(backbufferWidth, backbufferHeight, mSwapInterval); |
michael@0 | 167 | |
michael@0 | 168 | if (status == EGL_CONTEXT_LOST) |
michael@0 | 169 | { |
michael@0 | 170 | mRenderer->notifyDeviceLost(); |
michael@0 | 171 | return false; |
michael@0 | 172 | } |
michael@0 | 173 | else if (status != EGL_SUCCESS) |
michael@0 | 174 | { |
michael@0 | 175 | return error(status, false); |
michael@0 | 176 | } |
michael@0 | 177 | |
michael@0 | 178 | mWidth = backbufferWidth; |
michael@0 | 179 | mHeight = backbufferHeight; |
michael@0 | 180 | mSwapIntervalDirty = false; |
michael@0 | 181 | |
michael@0 | 182 | return true; |
michael@0 | 183 | } |
michael@0 | 184 | |
michael@0 | 185 | bool Surface::swapRect(EGLint x, EGLint y, EGLint width, EGLint height) |
michael@0 | 186 | { |
michael@0 | 187 | if (!mSwapChain) |
michael@0 | 188 | { |
michael@0 | 189 | return true; |
michael@0 | 190 | } |
michael@0 | 191 | |
michael@0 | 192 | if (x + width > mWidth) |
michael@0 | 193 | { |
michael@0 | 194 | width = mWidth - x; |
michael@0 | 195 | } |
michael@0 | 196 | |
michael@0 | 197 | if (y + height > mHeight) |
michael@0 | 198 | { |
michael@0 | 199 | height = mHeight - y; |
michael@0 | 200 | } |
michael@0 | 201 | |
michael@0 | 202 | if (width == 0 || height == 0) |
michael@0 | 203 | { |
michael@0 | 204 | return true; |
michael@0 | 205 | } |
michael@0 | 206 | |
michael@0 | 207 | EGLint status = mSwapChain->swapRect(x, y, width, height); |
michael@0 | 208 | |
michael@0 | 209 | if (status == EGL_CONTEXT_LOST) |
michael@0 | 210 | { |
michael@0 | 211 | mRenderer->notifyDeviceLost(); |
michael@0 | 212 | return false; |
michael@0 | 213 | } |
michael@0 | 214 | else if (status != EGL_SUCCESS) |
michael@0 | 215 | { |
michael@0 | 216 | return error(status, false); |
michael@0 | 217 | } |
michael@0 | 218 | |
michael@0 | 219 | checkForOutOfDateSwapChain(); |
michael@0 | 220 | |
michael@0 | 221 | return true; |
michael@0 | 222 | } |
michael@0 | 223 | |
michael@0 | 224 | HWND Surface::getWindowHandle() |
michael@0 | 225 | { |
michael@0 | 226 | return mWindow; |
michael@0 | 227 | } |
michael@0 | 228 | |
michael@0 | 229 | |
michael@0 | 230 | #define kSurfaceProperty _TEXT("Egl::SurfaceOwner") |
michael@0 | 231 | #define kParentWndProc _TEXT("Egl::SurfaceParentWndProc") |
michael@0 | 232 | |
michael@0 | 233 | static LRESULT CALLBACK SurfaceWindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) |
michael@0 | 234 | { |
michael@0 | 235 | if (message == WM_SIZE) |
michael@0 | 236 | { |
michael@0 | 237 | Surface* surf = reinterpret_cast<Surface*>(GetProp(hwnd, kSurfaceProperty)); |
michael@0 | 238 | if(surf) |
michael@0 | 239 | { |
michael@0 | 240 | surf->checkForOutOfDateSwapChain(); |
michael@0 | 241 | } |
michael@0 | 242 | } |
michael@0 | 243 | WNDPROC prevWndFunc = reinterpret_cast<WNDPROC >(GetProp(hwnd, kParentWndProc)); |
michael@0 | 244 | return CallWindowProc(prevWndFunc, hwnd, message, wparam, lparam); |
michael@0 | 245 | } |
michael@0 | 246 | |
michael@0 | 247 | void Surface::subclassWindow() |
michael@0 | 248 | { |
michael@0 | 249 | if (!mWindow) |
michael@0 | 250 | { |
michael@0 | 251 | return; |
michael@0 | 252 | } |
michael@0 | 253 | |
michael@0 | 254 | DWORD processId; |
michael@0 | 255 | DWORD threadId = GetWindowThreadProcessId(mWindow, &processId); |
michael@0 | 256 | if (processId != GetCurrentProcessId() || threadId != GetCurrentThreadId()) |
michael@0 | 257 | { |
michael@0 | 258 | return; |
michael@0 | 259 | } |
michael@0 | 260 | |
michael@0 | 261 | SetLastError(0); |
michael@0 | 262 | LONG_PTR oldWndProc = SetWindowLongPtr(mWindow, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(SurfaceWindowProc)); |
michael@0 | 263 | if(oldWndProc == 0 && GetLastError() != ERROR_SUCCESS) |
michael@0 | 264 | { |
michael@0 | 265 | mWindowSubclassed = false; |
michael@0 | 266 | return; |
michael@0 | 267 | } |
michael@0 | 268 | |
michael@0 | 269 | SetProp(mWindow, kSurfaceProperty, reinterpret_cast<HANDLE>(this)); |
michael@0 | 270 | SetProp(mWindow, kParentWndProc, reinterpret_cast<HANDLE>(oldWndProc)); |
michael@0 | 271 | mWindowSubclassed = true; |
michael@0 | 272 | } |
michael@0 | 273 | |
michael@0 | 274 | void Surface::unsubclassWindow() |
michael@0 | 275 | { |
michael@0 | 276 | if(!mWindowSubclassed) |
michael@0 | 277 | { |
michael@0 | 278 | return; |
michael@0 | 279 | } |
michael@0 | 280 | |
michael@0 | 281 | // un-subclass |
michael@0 | 282 | LONG_PTR parentWndFunc = reinterpret_cast<LONG_PTR>(GetProp(mWindow, kParentWndProc)); |
michael@0 | 283 | |
michael@0 | 284 | // Check the windowproc is still SurfaceWindowProc. |
michael@0 | 285 | // If this assert fails, then it is likely the application has subclassed the |
michael@0 | 286 | // hwnd as well and did not unsubclass before destroying its EGL context. The |
michael@0 | 287 | // application should be modified to either subclass before initializing the |
michael@0 | 288 | // EGL context, or to unsubclass before destroying the EGL context. |
michael@0 | 289 | if(parentWndFunc) |
michael@0 | 290 | { |
michael@0 | 291 | LONG_PTR prevWndFunc = SetWindowLongPtr(mWindow, GWLP_WNDPROC, parentWndFunc); |
michael@0 | 292 | ASSERT(prevWndFunc == reinterpret_cast<LONG_PTR>(SurfaceWindowProc)); |
michael@0 | 293 | } |
michael@0 | 294 | |
michael@0 | 295 | RemoveProp(mWindow, kSurfaceProperty); |
michael@0 | 296 | RemoveProp(mWindow, kParentWndProc); |
michael@0 | 297 | mWindowSubclassed = false; |
michael@0 | 298 | } |
michael@0 | 299 | |
michael@0 | 300 | bool Surface::checkForOutOfDateSwapChain() |
michael@0 | 301 | { |
michael@0 | 302 | RECT client; |
michael@0 | 303 | if (!GetClientRect(getWindowHandle(), &client)) |
michael@0 | 304 | { |
michael@0 | 305 | ASSERT(false); |
michael@0 | 306 | return false; |
michael@0 | 307 | } |
michael@0 | 308 | |
michael@0 | 309 | // Grow the buffer now, if the window has grown. We need to grow now to avoid losing information. |
michael@0 | 310 | int clientWidth = client.right - client.left; |
michael@0 | 311 | int clientHeight = client.bottom - client.top; |
michael@0 | 312 | bool sizeDirty = clientWidth != getWidth() || clientHeight != getHeight(); |
michael@0 | 313 | |
michael@0 | 314 | if (mSwapIntervalDirty) |
michael@0 | 315 | { |
michael@0 | 316 | resetSwapChain(clientWidth, clientHeight); |
michael@0 | 317 | } |
michael@0 | 318 | else if (sizeDirty) |
michael@0 | 319 | { |
michael@0 | 320 | resizeSwapChain(clientWidth, clientHeight); |
michael@0 | 321 | } |
michael@0 | 322 | |
michael@0 | 323 | if (mSwapIntervalDirty || sizeDirty) |
michael@0 | 324 | { |
michael@0 | 325 | if (static_cast<egl::Surface*>(getCurrentDrawSurface()) == this) |
michael@0 | 326 | { |
michael@0 | 327 | glMakeCurrent(glGetCurrentContext(), static_cast<egl::Display*>(getCurrentDisplay()), this); |
michael@0 | 328 | } |
michael@0 | 329 | |
michael@0 | 330 | return true; |
michael@0 | 331 | } |
michael@0 | 332 | |
michael@0 | 333 | return false; |
michael@0 | 334 | } |
michael@0 | 335 | |
michael@0 | 336 | bool Surface::swap() |
michael@0 | 337 | { |
michael@0 | 338 | return swapRect(0, 0, mWidth, mHeight); |
michael@0 | 339 | } |
michael@0 | 340 | |
michael@0 | 341 | bool Surface::postSubBuffer(EGLint x, EGLint y, EGLint width, EGLint height) |
michael@0 | 342 | { |
michael@0 | 343 | if (!mPostSubBufferSupported) |
michael@0 | 344 | { |
michael@0 | 345 | // Spec is not clear about how this should be handled. |
michael@0 | 346 | return true; |
michael@0 | 347 | } |
michael@0 | 348 | |
michael@0 | 349 | return swapRect(x, y, width, height); |
michael@0 | 350 | } |
michael@0 | 351 | |
michael@0 | 352 | EGLint Surface::getWidth() const |
michael@0 | 353 | { |
michael@0 | 354 | return mWidth; |
michael@0 | 355 | } |
michael@0 | 356 | |
michael@0 | 357 | EGLint Surface::getHeight() const |
michael@0 | 358 | { |
michael@0 | 359 | return mHeight; |
michael@0 | 360 | } |
michael@0 | 361 | |
michael@0 | 362 | EGLint Surface::isPostSubBufferSupported() const |
michael@0 | 363 | { |
michael@0 | 364 | return mPostSubBufferSupported; |
michael@0 | 365 | } |
michael@0 | 366 | |
michael@0 | 367 | rx::SwapChain *Surface::getSwapChain() const |
michael@0 | 368 | { |
michael@0 | 369 | return mSwapChain; |
michael@0 | 370 | } |
michael@0 | 371 | |
michael@0 | 372 | void Surface::setSwapInterval(EGLint interval) |
michael@0 | 373 | { |
michael@0 | 374 | if (mSwapInterval == interval) |
michael@0 | 375 | { |
michael@0 | 376 | return; |
michael@0 | 377 | } |
michael@0 | 378 | |
michael@0 | 379 | mSwapInterval = interval; |
michael@0 | 380 | mSwapInterval = std::max(mSwapInterval, mRenderer->getMinSwapInterval()); |
michael@0 | 381 | mSwapInterval = std::min(mSwapInterval, mRenderer->getMaxSwapInterval()); |
michael@0 | 382 | |
michael@0 | 383 | mSwapIntervalDirty = true; |
michael@0 | 384 | } |
michael@0 | 385 | |
michael@0 | 386 | EGLenum Surface::getTextureFormat() const |
michael@0 | 387 | { |
michael@0 | 388 | return mTextureFormat; |
michael@0 | 389 | } |
michael@0 | 390 | |
michael@0 | 391 | EGLenum Surface::getTextureTarget() const |
michael@0 | 392 | { |
michael@0 | 393 | return mTextureTarget; |
michael@0 | 394 | } |
michael@0 | 395 | |
michael@0 | 396 | void Surface::setBoundTexture(gl::Texture2D *texture) |
michael@0 | 397 | { |
michael@0 | 398 | mTexture = texture; |
michael@0 | 399 | } |
michael@0 | 400 | |
michael@0 | 401 | gl::Texture2D *Surface::getBoundTexture() const |
michael@0 | 402 | { |
michael@0 | 403 | return mTexture; |
michael@0 | 404 | } |
michael@0 | 405 | |
michael@0 | 406 | EGLenum Surface::getFormat() const |
michael@0 | 407 | { |
michael@0 | 408 | return mConfig->mRenderTargetFormat; |
michael@0 | 409 | } |
michael@0 | 410 | } |