Commit 6b0cf996 by Geoff Lang

Added an egl::Error class and updated libEGL to use it.

BUG=angle:520 Change-Id: I792c8ddd8e8b76184f566294196d089bc9d1902a Reviewed-on: https://chromium-review.googlesource.com/223270Reviewed-by: 's avatarBrandon Jones <bajones@chromium.org> Reviewed-by: 's avatarShannon Woods <shannonwoods@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 4de44cb6
...@@ -42,6 +42,8 @@ ...@@ -42,6 +42,8 @@
'libEGL/Config.h', 'libEGL/Config.h',
'libEGL/Display.cpp', 'libEGL/Display.cpp',
'libEGL/Display.h', 'libEGL/Display.h',
'libEGL/Error.cpp',
'libEGL/Error.h',
'libEGL/Surface.cpp', 'libEGL/Surface.cpp',
'libEGL/Surface.h', 'libEGL/Surface.h',
'libEGL/libEGL.cpp', 'libEGL/libEGL.cpp',
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <set> #include <set>
#include <vector> #include <vector>
#include "libEGL/Error.h"
#include "libEGL/Config.h" #include "libEGL/Config.h"
namespace gl namespace gl
...@@ -30,7 +31,7 @@ class Display ...@@ -30,7 +31,7 @@ class Display
public: public:
~Display(); ~Display();
bool initialize(); Error initialize();
void terminate(); void terminate();
static egl::Display *getDisplay(EGLNativeDisplayType displayId, EGLint displayType); static egl::Display *getDisplay(EGLNativeDisplayType displayId, EGLint displayType);
...@@ -43,9 +44,10 @@ class Display ...@@ -43,9 +44,10 @@ class Display
bool getConfigs(EGLConfig *configs, const EGLint *attribList, EGLint configSize, EGLint *numConfig); bool getConfigs(EGLConfig *configs, const EGLint *attribList, EGLint configSize, EGLint *numConfig);
bool getConfigAttrib(EGLConfig config, EGLint attribute, EGLint *value); bool getConfigAttrib(EGLConfig config, EGLint attribute, EGLint *value);
EGLSurface createWindowSurface(EGLNativeWindowType window, EGLConfig config, const EGLint *attribList); Error createWindowSurface(EGLNativeWindowType window, EGLConfig config, const EGLint *attribList, EGLSurface *outSurface);
EGLSurface createOffscreenSurface(EGLConfig config, HANDLE shareHandle, const EGLint *attribList); Error createOffscreenSurface(EGLConfig config, HANDLE shareHandle, const EGLint *attribList, EGLSurface *outSurface);
EGLContext createContext(EGLConfig configHandle, EGLint clientVersion, const gl::Context *shareContext, bool notifyResets, bool robustAccess); Error createContext(EGLConfig configHandle, EGLint clientVersion, const gl::Context *shareContext, bool notifyResets,
bool robustAccess, EGLContext *outContext);
void destroySurface(egl::Surface *surface); void destroySurface(egl::Surface *surface);
void destroyContext(gl::Context *context); void destroyContext(gl::Context *context);
...@@ -70,7 +72,7 @@ class Display ...@@ -70,7 +72,7 @@ class Display
Display(EGLNativeDisplayType displayId, EGLint displayType); Display(EGLNativeDisplayType displayId, EGLint displayType);
bool restoreLostDevice(); Error restoreLostDevice();
EGLNativeDisplayType mDisplayId; EGLNativeDisplayType mDisplayId;
EGLint mRequestedDisplayType; EGLint mRequestedDisplayType;
......
//
// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Error.cpp: Implements the egl::Error class which encapsulates an EGL error
// and optional error message.
#include "libEGL/Error.h"
#include "common/angleutils.h"
#include <cstdarg>
namespace egl
{
Error::Error(EGLint errorCode)
: mCode(errorCode),
mMessage()
{
}
Error::Error(EGLint errorCode, const char *msg, ...)
: mCode(errorCode),
mMessage()
{
va_list vararg;
va_start(vararg, msg);
mMessage = FormatString(msg, vararg);
va_end(vararg);
}
Error::Error(const Error &other)
: mCode(other.mCode),
mMessage(other.mMessage)
{
}
Error &Error::operator=(const Error &other)
{
mCode = other.mCode;
mMessage = other.mMessage;
return *this;
}
}
//
// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Error.h: Defines the egl::Error class which encapsulates an EGL error
// and optional error message.
#ifndef LIBEGL_ERROR_H_
#define LIBEGL_ERROR_H_
#include <EGL/egl.h>
#include <string>
namespace egl
{
class Error
{
public:
explicit Error(EGLint errorCode);
Error(EGLint errorCode, const char *msg, ...);
Error(const Error &other);
Error &operator=(const Error &other);
EGLint getCode() const { return mCode; }
bool isError() const { return (mCode != EGL_SUCCESS); }
const std::string &getMessage() const { return mMessage; }
private:
EGLint mCode;
std::string mMessage;
};
}
#endif // LIBEGL_ERROR_H_
...@@ -74,20 +74,23 @@ Surface::~Surface() ...@@ -74,20 +74,23 @@ Surface::~Surface()
release(); release();
} }
bool Surface::initialize() Error Surface::initialize()
{ {
if (mNativeWindow.getNativeWindow()) if (mNativeWindow.getNativeWindow())
{ {
if (!mNativeWindow.initialize()) if (!mNativeWindow.initialize())
{ {
return false; return Error(EGL_BAD_SURFACE);
} }
} }
if (!resetSwapChain()) Error error = resetSwapChain();
return false; if (error.isError())
{
return error;
}
return true; return Error(EGL_SUCCESS);
} }
void Surface::release() void Surface::release()
...@@ -102,7 +105,7 @@ void Surface::release() ...@@ -102,7 +105,7 @@ void Surface::release()
} }
} }
bool Surface::resetSwapChain() Error Surface::resetSwapChain()
{ {
ASSERT(!mSwapChain); ASSERT(!mSwapChain);
...@@ -116,8 +119,7 @@ bool Surface::resetSwapChain() ...@@ -116,8 +119,7 @@ bool Surface::resetSwapChain()
{ {
ASSERT(false); ASSERT(false);
ERR("Could not retrieve the window dimensions"); return Error(EGL_BAD_SURFACE, "Could not retrieve the window dimensions");
return error(EGL_BAD_SURFACE, false);
} }
width = windowRect.right - windowRect.left; width = windowRect.right - windowRect.left;
...@@ -135,20 +137,20 @@ bool Surface::resetSwapChain() ...@@ -135,20 +137,20 @@ bool Surface::resetSwapChain()
mConfig->mDepthStencilFormat); mConfig->mDepthStencilFormat);
if (!mSwapChain) if (!mSwapChain)
{ {
return error(EGL_BAD_ALLOC, false); return Error(EGL_BAD_ALLOC);
} }
if (!resetSwapChain(width, height)) Error error = resetSwapChain(width, height);
if (error.isError())
{ {
delete mSwapChain; SafeDelete(mSwapChain);
mSwapChain = NULL; return error;
return false;
} }
return true; return Error(EGL_SUCCESS);
} }
bool Surface::resizeSwapChain(int backbufferWidth, int backbufferHeight) Error Surface::resizeSwapChain(int backbufferWidth, int backbufferHeight)
{ {
ASSERT(backbufferWidth >= 0 && backbufferHeight >= 0); ASSERT(backbufferWidth >= 0 && backbufferHeight >= 0);
ASSERT(mSwapChain); ASSERT(mSwapChain);
...@@ -158,20 +160,20 @@ bool Surface::resizeSwapChain(int backbufferWidth, int backbufferHeight) ...@@ -158,20 +160,20 @@ bool Surface::resizeSwapChain(int backbufferWidth, int backbufferHeight)
if (status == EGL_CONTEXT_LOST) if (status == EGL_CONTEXT_LOST)
{ {
mDisplay->notifyDeviceLost(); mDisplay->notifyDeviceLost();
return false; return Error(status);
} }
else if (status != EGL_SUCCESS) else if (status != EGL_SUCCESS)
{ {
return error(status, false); return Error(status);
} }
mWidth = backbufferWidth; mWidth = backbufferWidth;
mHeight = backbufferHeight; mHeight = backbufferHeight;
return true; return Error(EGL_SUCCESS);
} }
bool Surface::resetSwapChain(int backbufferWidth, int backbufferHeight) Error Surface::resetSwapChain(int backbufferWidth, int backbufferHeight)
{ {
ASSERT(backbufferWidth >= 0 && backbufferHeight >= 0); ASSERT(backbufferWidth >= 0 && backbufferHeight >= 0);
ASSERT(mSwapChain); ASSERT(mSwapChain);
...@@ -181,25 +183,25 @@ bool Surface::resetSwapChain(int backbufferWidth, int backbufferHeight) ...@@ -181,25 +183,25 @@ bool Surface::resetSwapChain(int backbufferWidth, int backbufferHeight)
if (status == EGL_CONTEXT_LOST) if (status == EGL_CONTEXT_LOST)
{ {
mRenderer->notifyDeviceLost(); mRenderer->notifyDeviceLost();
return false; return Error(status);
} }
else if (status != EGL_SUCCESS) else if (status != EGL_SUCCESS)
{ {
return error(status, false); return Error(status);
} }
mWidth = backbufferWidth; mWidth = backbufferWidth;
mHeight = backbufferHeight; mHeight = backbufferHeight;
mSwapIntervalDirty = false; mSwapIntervalDirty = false;
return true; return Error(EGL_SUCCESS);
} }
bool Surface::swapRect(EGLint x, EGLint y, EGLint width, EGLint height) Error Surface::swapRect(EGLint x, EGLint y, EGLint width, EGLint height)
{ {
if (!mSwapChain) if (!mSwapChain)
{ {
return true; return Error(EGL_SUCCESS);
} }
if (x + width > mWidth) if (x + width > mWidth)
...@@ -214,7 +216,7 @@ bool Surface::swapRect(EGLint x, EGLint y, EGLint width, EGLint height) ...@@ -214,7 +216,7 @@ bool Surface::swapRect(EGLint x, EGLint y, EGLint width, EGLint height)
if (width == 0 || height == 0) if (width == 0 || height == 0)
{ {
return true; return Error(EGL_SUCCESS);
} }
EGLint status = mSwapChain->swapRect(x, y, width, height); EGLint status = mSwapChain->swapRect(x, y, width, height);
...@@ -222,16 +224,16 @@ bool Surface::swapRect(EGLint x, EGLint y, EGLint width, EGLint height) ...@@ -222,16 +224,16 @@ bool Surface::swapRect(EGLint x, EGLint y, EGLint width, EGLint height)
if (status == EGL_CONTEXT_LOST) if (status == EGL_CONTEXT_LOST)
{ {
mRenderer->notifyDeviceLost(); mRenderer->notifyDeviceLost();
return false; return Error(status);
} }
else if (status != EGL_SUCCESS) else if (status != EGL_SUCCESS)
{ {
return error(status, false); return Error(status);
} }
checkForOutOfDateSwapChain(); checkForOutOfDateSwapChain();
return true; return Error(EGL_SUCCESS);
} }
EGLNativeWindowType Surface::getWindowHandle() EGLNativeWindowType Surface::getWindowHandle()
...@@ -369,17 +371,17 @@ bool Surface::checkForOutOfDateSwapChain() ...@@ -369,17 +371,17 @@ bool Surface::checkForOutOfDateSwapChain()
return false; return false;
} }
bool Surface::swap() Error Surface::swap()
{ {
return swapRect(0, 0, mWidth, mHeight); return swapRect(0, 0, mWidth, mHeight);
} }
bool Surface::postSubBuffer(EGLint x, EGLint y, EGLint width, EGLint height) Error Surface::postSubBuffer(EGLint x, EGLint y, EGLint width, EGLint height)
{ {
if (!mPostSubBufferSupported) if (!mPostSubBufferSupported)
{ {
// Spec is not clear about how this should be handled. // Spec is not clear about how this should be handled.
return true; return Error(EGL_SUCCESS);
} }
return swapRect(x, y, width, height); return swapRect(x, y, width, height);
......
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
#ifndef LIBEGL_SURFACE_H_ #ifndef LIBEGL_SURFACE_H_
#define LIBEGL_SURFACE_H_ #define LIBEGL_SURFACE_H_
#include "libEGL/Error.h"
#include <EGL/egl.h> #include <EGL/egl.h>
#include "common/angleutils.h" #include "common/angleutils.h"
...@@ -39,13 +41,13 @@ class Surface ...@@ -39,13 +41,13 @@ class Surface
virtual ~Surface(); virtual ~Surface();
bool initialize(); Error initialize();
void release(); void release();
bool resetSwapChain(); Error resetSwapChain();
EGLNativeWindowType getWindowHandle(); EGLNativeWindowType getWindowHandle();
bool swap(); Error swap();
bool postSubBuffer(EGLint x, EGLint y, EGLint width, EGLint height); Error postSubBuffer(EGLint x, EGLint y, EGLint width, EGLint height);
virtual EGLint isPostSubBufferSupported() const; virtual EGLint isPostSubBufferSupported() const;
...@@ -80,9 +82,9 @@ private: ...@@ -80,9 +82,9 @@ private:
void subclassWindow(); void subclassWindow();
void unsubclassWindow(); void unsubclassWindow();
bool resizeSwapChain(int backbufferWidth, int backbufferHeight); Error resizeSwapChain(int backbufferWidth, int backbufferHeight);
bool resetSwapChain(int backbufferWidth, int backbufferHeight); Error resetSwapChain(int backbufferWidth, int backbufferHeight);
bool swapRect(EGLint x, EGLint y, EGLint width, EGLint height); Error swapRect(EGLint x, EGLint y, EGLint width, EGLint height);
rx::NativeWindow mNativeWindow; // Handler for the Window that the surface is created for. rx::NativeWindow mNativeWindow; // Handler for the Window that the surface is created for.
bool mWindowSubclassed; // Indicates whether we successfully subclassed mWindow for WM_RESIZE hooking bool mWindowSubclassed; // Indicates whether we successfully subclassed mWindow for WM_RESIZE hooking
......
...@@ -120,11 +120,11 @@ Current *GetCurrentData() ...@@ -120,11 +120,11 @@ Current *GetCurrentData()
return (current ? current : AllocateCurrent()); return (current ? current : AllocateCurrent());
} }
void setCurrentError(EGLint error) void recordError(const Error &error)
{ {
Current *current = GetCurrentData(); Current *current = GetCurrentData();
current->error = error; current->error = error.getCode();
} }
EGLint getCurrentError() EGLint getCurrentError()
...@@ -190,9 +190,4 @@ EGLSurface getCurrentReadSurface() ...@@ -190,9 +190,4 @@ EGLSurface getCurrentReadSurface()
return current->readSurface; return current->readSurface;
} }
void error(EGLint errorCode)
{
egl::setCurrentError(errorCode);
}
} }
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#ifndef LIBEGL_MAIN_H_ #ifndef LIBEGL_MAIN_H_
#define LIBEGL_MAIN_H_ #define LIBEGL_MAIN_H_
#include "libEGL/Error.h"
#include <EGL/egl.h> #include <EGL/egl.h>
#include <EGL/eglext.h> #include <EGL/eglext.h>
...@@ -23,7 +25,7 @@ struct Current ...@@ -23,7 +25,7 @@ struct Current
EGLSurface readSurface; EGLSurface readSurface;
}; };
void setCurrentError(EGLint error); void recordError(const Error &error);
EGLint getCurrentError(); EGLint getCurrentError();
void setCurrentAPI(EGLenum API); void setCurrentAPI(EGLenum API);
...@@ -38,24 +40,6 @@ EGLSurface getCurrentDrawSurface(); ...@@ -38,24 +40,6 @@ EGLSurface getCurrentDrawSurface();
void setCurrentReadSurface(EGLSurface surface); void setCurrentReadSurface(EGLSurface surface);
EGLSurface getCurrentReadSurface(); EGLSurface getCurrentReadSurface();
void error(EGLint errorCode);
template<class T>
const T &error(EGLint errorCode, const T &returnValue)
{
error(errorCode);
return returnValue;
}
template<class T>
const T &success(const T &returnValue)
{
egl::setCurrentError(EGL_SUCCESS);
return returnValue;
}
} }
#endif // LIBEGL_MAIN_H_ #endif // LIBEGL_MAIN_H_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment