blob: 3414656f4cb5b67aab81681a62caad6843601ddf [file] [log] [blame]
daniel@transgaming.com95a758f2012-07-12 15:17:06 +00001//
Nicolas Capens3501c162014-05-21 13:27:15 -04002// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.com95a758f2012-07-12 15:17:06 +00003// 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 Graham86f601c2013-09-17 13:28:00 -070013#include <algorithm>
14
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000015#include "libEGL/Surface.h"
16
17#include "common/debug.h"
18#include "libGLESv2/Texture.h"
daniel@transgaming.com3c720782012-10-31 18:42:34 +000019#include "libGLESv2/renderer/SwapChain.h"
daniel@transgaming.comcfa8efd2012-11-28 19:30:55 +000020#include "libGLESv2/main.h"
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000021
22#include "libEGL/main.h"
23#include "libEGL/Display.h"
24
Cooper Partineeb1f532014-09-23 10:25:02 -070025#include "common/NativeWindow.h"
26
Jamie Madill93e13fb2014-11-06 15:27:25 -050027//TODO(jmadill): phase this out
28#include "libGLESv2/renderer/d3d/RendererD3D.h"
29
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000030namespace egl
31{
32
Cooper Partineeb1f532014-09-23 10:25:02 -070033Surface::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.com95a758f2012-07-12 15:17:06 +000035{
Jamie Madill93e13fb2014-11-06 15:27:25 -050036 //TODO(jmadill): MANGLE refactor. (note, can't call makeRendererD3D because of dll export issues)
37 mRenderer = static_cast<rx::RendererD3D*>(mDisplay->getRenderer());
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000038 mSwapChain = NULL;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000039 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 Bauman3dc300a2014-01-28 15:30:35 -080048 mWidth = width;
49 mHeight = height;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000050 setSwapInterval(1);
John Bauman3dc300a2014-01-28 15:30:35 -080051 mFixedSize = fixedSize;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000052
53 subclassWindow();
54}
55
56Surface::Surface(Display *display, const Config *config, HANDLE shareHandle, EGLint width, EGLint height, EGLenum textureFormat, EGLenum textureType)
Cooper Partineeb1f532014-09-23 10:25:02 -070057 : mDisplay(display), mNativeWindow(NULL), mConfig(config), mShareHandle(shareHandle), mWidth(width), mHeight(height), mPostSubBufferSupported(EGL_FALSE)
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000058{
Jamie Madill93e13fb2014-11-06 15:27:25 -050059 //TODO(jmadill): MANGLE refactor. (note, can't call makeRendererD3D because of dll export issues)
60 mRenderer = static_cast<rx::RendererD3D*>(mDisplay->getRenderer());
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000061 mSwapChain = NULL;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000062 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 Bauman3dc300a2014-01-28 15:30:35 -080072 // This constructor is for offscreen surfaces, which are always fixed-size.
73 mFixedSize = EGL_TRUE;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000074}
75
76Surface::~Surface()
77{
78 unsubclassWindow();
79 release();
80}
81
Geoff Lang6b0cf992014-10-06 10:28:07 -040082Error Surface::initialize()
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000083{
Cooper Partineeb1f532014-09-23 10:25:02 -070084 if (mNativeWindow.getNativeWindow())
85 {
86 if (!mNativeWindow.initialize())
87 {
Geoff Lang6b0cf992014-10-06 10:28:07 -040088 return Error(EGL_BAD_SURFACE);
Cooper Partineeb1f532014-09-23 10:25:02 -070089 }
90 }
91
Geoff Lang6b0cf992014-10-06 10:28:07 -040092 Error error = resetSwapChain();
93 if (error.isError())
94 {
95 return error;
96 }
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000097
Geoff Lang6b0cf992014-10-06 10:28:07 -040098 return Error(EGL_SUCCESS);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000099}
100
101void Surface::release()
102{
daniel@transgaming.comb9bb2792012-11-28 19:36:49 +0000103 delete mSwapChain;
daniel@transgaming.com3c720782012-10-31 18:42:34 +0000104 mSwapChain = NULL;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000105
106 if (mTexture)
107 {
108 mTexture->releaseTexImage();
109 mTexture = NULL;
110 }
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000111}
112
Geoff Lang6b0cf992014-10-06 10:28:07 -0400113Error Surface::resetSwapChain()
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000114{
daniel@transgaming.com3c720782012-10-31 18:42:34 +0000115 ASSERT(!mSwapChain);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000116
daniel@transgaming.com3c720782012-10-31 18:42:34 +0000117 int width;
118 int height;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000119
John Bauman3dc300a2014-01-28 15:30:35 -0800120 if (!mFixedSize)
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000121 {
daniel@transgaming.com3c720782012-10-31 18:42:34 +0000122 RECT windowRect;
Cooper Partineeb1f532014-09-23 10:25:02 -0700123 if (!mNativeWindow.getClientRect(&windowRect))
apatrick@chromium.org85e44192012-08-17 20:58:01 +0000124 {
daniel@transgaming.com3c720782012-10-31 18:42:34 +0000125 ASSERT(false);
126
Geoff Lang6b0cf992014-10-06 10:28:07 -0400127 return Error(EGL_BAD_SURFACE, "Could not retrieve the window dimensions");
apatrick@chromium.org85e44192012-08-17 20:58:01 +0000128 }
apatrick@chromium.org0c71fd42012-08-10 18:08:47 +0000129
daniel@transgaming.com3c720782012-10-31 18:42:34 +0000130 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.com95a758f2012-07-12 15:17:06 +0000138 }
139
Cooper Partineeb1f532014-09-23 10:25:02 -0700140 mSwapChain = mRenderer->createSwapChain(mNativeWindow, mShareHandle,
daniel@transgaming.comb9bb2792012-11-28 19:36:49 +0000141 mConfig->mRenderTargetFormat,
142 mConfig->mDepthStencilFormat);
daniel@transgaming.com3c720782012-10-31 18:42:34 +0000143 if (!mSwapChain)
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000144 {
Geoff Lang6b0cf992014-10-06 10:28:07 -0400145 return Error(EGL_BAD_ALLOC);
daniel@transgaming.com3c720782012-10-31 18:42:34 +0000146 }
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000147
Geoff Lang6b0cf992014-10-06 10:28:07 -0400148 Error error = resetSwapChain(width, height);
149 if (error.isError())
daniel@transgaming.com3c720782012-10-31 18:42:34 +0000150 {
Geoff Lang6b0cf992014-10-06 10:28:07 -0400151 SafeDelete(mSwapChain);
152 return error;
daniel@transgaming.com3c720782012-10-31 18:42:34 +0000153 }
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000154
Geoff Lang6b0cf992014-10-06 10:28:07 -0400155 return Error(EGL_SUCCESS);
daniel@transgaming.com3c720782012-10-31 18:42:34 +0000156}
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000157
Geoff Lang6b0cf992014-10-06 10:28:07 -0400158Error Surface::resizeSwapChain(int backbufferWidth, int backbufferHeight)
shannon.woods@transgaming.comc71ca752013-02-28 23:06:50 +0000159{
160 ASSERT(backbufferWidth >= 0 && backbufferHeight >= 0);
161 ASSERT(mSwapChain);
162
John Bauman3dc300a2014-01-28 15:30:35 -0800163 EGLint status = mSwapChain->resize(std::max(1, backbufferWidth), std::max(1, backbufferHeight));
shannon.woods@transgaming.comc71ca752013-02-28 23:06:50 +0000164
165 if (status == EGL_CONTEXT_LOST)
166 {
167 mDisplay->notifyDeviceLost();
Geoff Lang6b0cf992014-10-06 10:28:07 -0400168 return Error(status);
shannon.woods@transgaming.comc71ca752013-02-28 23:06:50 +0000169 }
170 else if (status != EGL_SUCCESS)
171 {
Geoff Lang6b0cf992014-10-06 10:28:07 -0400172 return Error(status);
shannon.woods@transgaming.comc71ca752013-02-28 23:06:50 +0000173 }
174
175 mWidth = backbufferWidth;
176 mHeight = backbufferHeight;
177
Geoff Lang6b0cf992014-10-06 10:28:07 -0400178 return Error(EGL_SUCCESS);
shannon.woods@transgaming.comc71ca752013-02-28 23:06:50 +0000179}
180
Geoff Lang6b0cf992014-10-06 10:28:07 -0400181Error Surface::resetSwapChain(int backbufferWidth, int backbufferHeight)
daniel@transgaming.com3c720782012-10-31 18:42:34 +0000182{
183 ASSERT(backbufferWidth >= 0 && backbufferHeight >= 0);
184 ASSERT(mSwapChain);
185
John Bauman3dc300a2014-01-28 15:30:35 -0800186 EGLint status = mSwapChain->reset(std::max(1, backbufferWidth), std::max(1, backbufferHeight), mSwapInterval);
daniel@transgaming.com3c720782012-10-31 18:42:34 +0000187
188 if (status == EGL_CONTEXT_LOST)
189 {
shannon.woods@transgaming.comeb049e22013-02-28 23:04:49 +0000190 mRenderer->notifyDeviceLost();
Geoff Lang6b0cf992014-10-06 10:28:07 -0400191 return Error(status);
daniel@transgaming.com3c720782012-10-31 18:42:34 +0000192 }
193 else if (status != EGL_SUCCESS)
194 {
Geoff Lang6b0cf992014-10-06 10:28:07 -0400195 return Error(status);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000196 }
197
apatrick@chromium.org0c71fd42012-08-10 18:08:47 +0000198 mWidth = backbufferWidth;
199 mHeight = backbufferHeight;
daniel@transgaming.com3c720782012-10-31 18:42:34 +0000200 mSwapIntervalDirty = false;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000201
Geoff Lang6b0cf992014-10-06 10:28:07 -0400202 return Error(EGL_SUCCESS);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000203}
204
Geoff Lang6b0cf992014-10-06 10:28:07 -0400205Error Surface::swapRect(EGLint x, EGLint y, EGLint width, EGLint height)
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000206{
207 if (!mSwapChain)
208 {
Geoff Lang6b0cf992014-10-06 10:28:07 -0400209 return Error(EGL_SUCCESS);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000210 }
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 Lang6b0cf992014-10-06 10:28:07 -0400224 return Error(EGL_SUCCESS);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000225 }
226
daniel@transgaming.com3c720782012-10-31 18:42:34 +0000227 EGLint status = mSwapChain->swapRect(x, y, width, height);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000228
daniel@transgaming.com3c720782012-10-31 18:42:34 +0000229 if (status == EGL_CONTEXT_LOST)
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000230 {
shannon.woods@transgaming.comeb049e22013-02-28 23:04:49 +0000231 mRenderer->notifyDeviceLost();
Geoff Lang6b0cf992014-10-06 10:28:07 -0400232 return Error(status);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000233 }
daniel@transgaming.com3c720782012-10-31 18:42:34 +0000234 else if (status != EGL_SUCCESS)
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000235 {
Geoff Lang6b0cf992014-10-06 10:28:07 -0400236 return Error(status);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000237 }
238
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000239 checkForOutOfDateSwapChain();
240
Geoff Lang6b0cf992014-10-06 10:28:07 -0400241 return Error(EGL_SUCCESS);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000242}
243
Cooper Partineeb1f532014-09-23 10:25:02 -0700244EGLNativeWindowType Surface::getWindowHandle()
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000245{
Cooper Partineeb1f532014-09-23 10:25:02 -0700246 return mNativeWindow.getNativeWindow();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000247}
248
Cooper Partin88d3b8c2014-10-08 10:41:56 -0700249#if !defined(ANGLE_ENABLE_WINDOWS_STORE)
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000250#define kSurfaceProperty _TEXT("Egl::SurfaceOwner")
251#define kParentWndProc _TEXT("Egl::SurfaceParentWndProc")
252
253static 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 Partin88d3b8c2014-10-08 10:41:56 -0700266#endif
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000267
268void Surface::subclassWindow()
269{
Cooper Partin88d3b8c2014-10-08 10:41:56 -0700270#if !defined(ANGLE_ENABLE_WINDOWS_STORE)
Cooper Partineeb1f532014-09-23 10:25:02 -0700271 HWND window = mNativeWindow.getNativeWindow();
272 if (!window)
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000273 {
274 return;
275 }
276
277 DWORD processId;
Cooper Partineeb1f532014-09-23 10:25:02 -0700278 DWORD threadId = GetWindowThreadProcessId(window, &processId);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000279 if (processId != GetCurrentProcessId() || threadId != GetCurrentThreadId())
280 {
281 return;
282 }
283
284 SetLastError(0);
Cooper Partineeb1f532014-09-23 10:25:02 -0700285 LONG_PTR oldWndProc = SetWindowLongPtr(window, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(SurfaceWindowProc));
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000286 if(oldWndProc == 0 && GetLastError() != ERROR_SUCCESS)
287 {
288 mWindowSubclassed = false;
289 return;
290 }
291
Cooper Partineeb1f532014-09-23 10:25:02 -0700292 SetProp(window, kSurfaceProperty, reinterpret_cast<HANDLE>(this));
293 SetProp(window, kParentWndProc, reinterpret_cast<HANDLE>(oldWndProc));
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000294 mWindowSubclassed = true;
Cooper Partin88d3b8c2014-10-08 10:41:56 -0700295#endif
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000296}
297
298void Surface::unsubclassWindow()
299{
300 if(!mWindowSubclassed)
301 {
302 return;
303 }
304
Cooper Partin88d3b8c2014-10-08 10:41:56 -0700305#if !defined(ANGLE_ENABLE_WINDOWS_STORE)
Cooper Partineeb1f532014-09-23 10:25:02 -0700306 HWND window = mNativeWindow.getNativeWindow();
307 if (!window)
308 {
309 return;
310 }
311
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000312 // un-subclass
Cooper Partineeb1f532014-09-23 10:25:02 -0700313 LONG_PTR parentWndFunc = reinterpret_cast<LONG_PTR>(GetProp(window, kParentWndProc));
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000314
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 Partineeb1f532014-09-23 10:25:02 -0700322 LONG_PTR prevWndFunc = SetWindowLongPtr(window, GWLP_WNDPROC, parentWndFunc);
Geoff Lang9cd19152014-05-28 15:54:34 -0400323 UNUSED_ASSERTION_VARIABLE(prevWndFunc);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000324 ASSERT(prevWndFunc == reinterpret_cast<LONG_PTR>(SurfaceWindowProc));
325 }
326
Cooper Partineeb1f532014-09-23 10:25:02 -0700327 RemoveProp(window, kSurfaceProperty);
328 RemoveProp(window, kParentWndProc);
Cooper Partin88d3b8c2014-10-08 10:41:56 -0700329#endif
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000330 mWindowSubclassed = false;
331}
332
333bool Surface::checkForOutOfDateSwapChain()
334{
335 RECT client;
John Bauman3dc300a2014-01-28 15:30:35 -0800336 int clientWidth = getWidth();
337 int clientHeight = getHeight();
338 bool sizeDirty = false;
Cooper Partineeb1f532014-09-23 10:25:02 -0700339 if (!mFixedSize && !mNativeWindow.isIconic())
John Bauman827a4712013-10-29 16:03:11 -0700340 {
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 Partineeb1f532014-09-23 10:25:02 -0700343 if (!mNativeWindow.getClientRect(&client))
John Bauman3dc300a2014-01-28 15:30:35 -0800344 {
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 Bauman827a4712013-10-29 16:03:11 -0700353 }
354
Jamie Madill58e60322013-12-02 11:09:36 -0500355 bool wasDirty = (mSwapIntervalDirty || sizeDirty);
356
shannon.woods@transgaming.comc71ca752013-02-28 23:06:50 +0000357 if (mSwapIntervalDirty)
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000358 {
359 resetSwapChain(clientWidth, clientHeight);
shannon.woods@transgaming.comc71ca752013-02-28 23:06:50 +0000360 }
361 else if (sizeDirty)
362 {
363 resizeSwapChain(clientWidth, clientHeight);
364 }
365
Jamie Madill58e60322013-12-02 11:09:36 -0500366 if (wasDirty)
shannon.woods@transgaming.comc71ca752013-02-28 23:06:50 +0000367 {
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000368 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.comc71ca752013-02-28 23:06:50 +0000375
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000376 return false;
377}
378
Geoff Lang6b0cf992014-10-06 10:28:07 -0400379Error Surface::swap()
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000380{
381 return swapRect(0, 0, mWidth, mHeight);
382}
383
Geoff Lang6b0cf992014-10-06 10:28:07 -0400384Error Surface::postSubBuffer(EGLint x, EGLint y, EGLint width, EGLint height)
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000385{
386 if (!mPostSubBufferSupported)
387 {
388 // Spec is not clear about how this should be handled.
Geoff Lang6b0cf992014-10-06 10:28:07 -0400389 return Error(EGL_SUCCESS);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000390 }
Nicolas Capens3501c162014-05-21 13:27:15 -0400391
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000392 return swapRect(x, y, width, height);
393}
394
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000395EGLint Surface::isPostSubBufferSupported() const
396{
397 return mPostSubBufferSupported;
398}
399
daniel@transgaming.com76d3e6e2012-10-31 19:55:33 +0000400rx::SwapChain *Surface::getSwapChain() const
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000401{
daniel@transgaming.com3c720782012-10-31 18:42:34 +0000402 return mSwapChain;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000403}
404
405void Surface::setSwapInterval(EGLint interval)
406{
407 if (mSwapInterval == interval)
408 {
409 return;
410 }
Nicolas Capens3501c162014-05-21 13:27:15 -0400411
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000412 mSwapInterval = interval;
daniel@transgaming.com114bd462012-10-31 18:42:47 +0000413 mSwapInterval = std::max(mSwapInterval, mRenderer->getMinSwapInterval());
414 mSwapInterval = std::min(mSwapInterval, mRenderer->getMaxSwapInterval());
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000415
daniel@transgaming.com3c720782012-10-31 18:42:34 +0000416 mSwapIntervalDirty = true;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000417}
418
Nicolas Capens3501c162014-05-21 13:27:15 -0400419EGLint Surface::getConfigID() const
420{
421 return mConfig->mConfigID;
422}
423
424EGLint Surface::getWidth() const
425{
426 return mWidth;
427}
428
429EGLint Surface::getHeight() const
430{
431 return mHeight;
432}
433
434EGLint Surface::getPixelAspectRatio() const
435{
436 return mPixelAspectRatio;
437}
438
439EGLenum Surface::getRenderBuffer() const
440{
441 return mRenderBuffer;
442}
443
444EGLenum Surface::getSwapBehavior() const
445{
446 return mSwapBehavior;
447}
448
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000449EGLenum Surface::getTextureFormat() const
450{
451 return mTextureFormat;
452}
453
454EGLenum Surface::getTextureTarget() const
455{
456 return mTextureTarget;
457}
458
459void Surface::setBoundTexture(gl::Texture2D *texture)
460{
461 mTexture = texture;
462}
463
464gl::Texture2D *Surface::getBoundTexture() const
465{
466 return mTexture;
467}
468
John Bauman3dc300a2014-01-28 15:30:35 -0800469EGLint Surface::isFixedSize() const
470{
471 return mFixedSize;
472}
473
daniel@transgaming.com106e1f72012-10-31 18:38:36 +0000474EGLenum Surface::getFormat() const
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000475{
476 return mConfig->mRenderTargetFormat;
477}
478}