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 @@
'libEGL/Config.h',
'libEGL/Display.cpp',
'libEGL/Display.h',
'libEGL/Error.cpp',
'libEGL/Error.h',
'libEGL/Surface.cpp',
'libEGL/Surface.h',
'libEGL/libEGL.cpp',
......
......@@ -14,6 +14,7 @@
#include <set>
#include <vector>
#include "libEGL/Error.h"
#include "libEGL/Config.h"
namespace gl
......@@ -30,7 +31,7 @@ class Display
public:
~Display();
bool initialize();
Error initialize();
void terminate();
static egl::Display *getDisplay(EGLNativeDisplayType displayId, EGLint displayType);
......@@ -43,9 +44,10 @@ class Display
bool getConfigs(EGLConfig *configs, const EGLint *attribList, EGLint configSize, EGLint *numConfig);
bool getConfigAttrib(EGLConfig config, EGLint attribute, EGLint *value);
EGLSurface createWindowSurface(EGLNativeWindowType window, EGLConfig config, const EGLint *attribList);
EGLSurface createOffscreenSurface(EGLConfig config, HANDLE shareHandle, const EGLint *attribList);
EGLContext createContext(EGLConfig configHandle, EGLint clientVersion, const gl::Context *shareContext, bool notifyResets, bool robustAccess);
Error createWindowSurface(EGLNativeWindowType window, EGLConfig config, const EGLint *attribList, EGLSurface *outSurface);
Error createOffscreenSurface(EGLConfig config, HANDLE shareHandle, const EGLint *attribList, EGLSurface *outSurface);
Error createContext(EGLConfig configHandle, EGLint clientVersion, const gl::Context *shareContext, bool notifyResets,
bool robustAccess, EGLContext *outContext);
void destroySurface(egl::Surface *surface);
void destroyContext(gl::Context *context);
......@@ -70,7 +72,7 @@ class Display
Display(EGLNativeDisplayType displayId, EGLint displayType);
bool restoreLostDevice();
Error restoreLostDevice();
EGLNativeDisplayType mDisplayId;
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()
release();
}
bool Surface::initialize()
Error Surface::initialize()
{
if (mNativeWindow.getNativeWindow())
{
if (!mNativeWindow.initialize())
{
return false;
return Error(EGL_BAD_SURFACE);
}
}
if (!resetSwapChain())
return false;
Error error = resetSwapChain();
if (error.isError())
{
return error;
}
return true;
return Error(EGL_SUCCESS);
}
void Surface::release()
......@@ -102,7 +105,7 @@ void Surface::release()
}
}
bool Surface::resetSwapChain()
Error Surface::resetSwapChain()
{
ASSERT(!mSwapChain);
......@@ -116,8 +119,7 @@ bool Surface::resetSwapChain()
{
ASSERT(false);
ERR("Could not retrieve the window dimensions");
return error(EGL_BAD_SURFACE, false);
return Error(EGL_BAD_SURFACE, "Could not retrieve the window dimensions");
}
width = windowRect.right - windowRect.left;
......@@ -135,20 +137,20 @@ bool Surface::resetSwapChain()
mConfig->mDepthStencilFormat);
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;
mSwapChain = NULL;
return false;
SafeDelete(mSwapChain);
return error;
}
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(mSwapChain);
......@@ -158,20 +160,20 @@ bool Surface::resizeSwapChain(int backbufferWidth, int backbufferHeight)
if (status == EGL_CONTEXT_LOST)
{
mDisplay->notifyDeviceLost();
return false;
return Error(status);
}
else if (status != EGL_SUCCESS)
{
return error(status, false);
return Error(status);
}
mWidth = backbufferWidth;
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(mSwapChain);
......@@ -181,25 +183,25 @@ bool Surface::resetSwapChain(int backbufferWidth, int backbufferHeight)
if (status == EGL_CONTEXT_LOST)
{
mRenderer->notifyDeviceLost();
return false;
return Error(status);
}
else if (status != EGL_SUCCESS)
{
return error(status, false);
return Error(status);
}
mWidth = backbufferWidth;
mHeight = backbufferHeight;
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)
{
return true;
return Error(EGL_SUCCESS);
}
if (x + width > mWidth)
......@@ -214,7 +216,7 @@ bool Surface::swapRect(EGLint x, EGLint y, EGLint width, EGLint height)
if (width == 0 || height == 0)
{
return true;
return Error(EGL_SUCCESS);
}
EGLint status = mSwapChain->swapRect(x, y, width, height);
......@@ -222,16 +224,16 @@ bool Surface::swapRect(EGLint x, EGLint y, EGLint width, EGLint height)
if (status == EGL_CONTEXT_LOST)
{
mRenderer->notifyDeviceLost();
return false;
return Error(status);
}
else if (status != EGL_SUCCESS)
{
return error(status, false);
return Error(status);
}
checkForOutOfDateSwapChain();
return true;
return Error(EGL_SUCCESS);
}
EGLNativeWindowType Surface::getWindowHandle()
......@@ -369,17 +371,17 @@ bool Surface::checkForOutOfDateSwapChain()
return false;
}
bool Surface::swap()
Error Surface::swap()
{
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)
{
// Spec is not clear about how this should be handled.
return true;
return Error(EGL_SUCCESS);
}
return swapRect(x, y, width, height);
......
......@@ -11,6 +11,8 @@
#ifndef LIBEGL_SURFACE_H_
#define LIBEGL_SURFACE_H_
#include "libEGL/Error.h"
#include <EGL/egl.h>
#include "common/angleutils.h"
......@@ -39,13 +41,13 @@ class Surface
virtual ~Surface();
bool initialize();
Error initialize();
void release();
bool resetSwapChain();
Error resetSwapChain();
EGLNativeWindowType getWindowHandle();
bool swap();
bool postSubBuffer(EGLint x, EGLint y, EGLint width, EGLint height);
Error swap();
Error postSubBuffer(EGLint x, EGLint y, EGLint width, EGLint height);
virtual EGLint isPostSubBufferSupported() const;
......@@ -80,9 +82,9 @@ private:
void subclassWindow();
void unsubclassWindow();
bool resizeSwapChain(int backbufferWidth, int backbufferHeight);
bool resetSwapChain(int backbufferWidth, int backbufferHeight);
bool swapRect(EGLint x, EGLint y, EGLint width, EGLint height);
Error resizeSwapChain(int backbufferWidth, int backbufferHeight);
Error resetSwapChain(int backbufferWidth, int backbufferHeight);
Error swapRect(EGLint x, EGLint y, EGLint width, EGLint height);
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
......
......@@ -120,11 +120,11 @@ Current *GetCurrentData()
return (current ? current : AllocateCurrent());
}
void setCurrentError(EGLint error)
void recordError(const Error &error)
{
Current *current = GetCurrentData();
current->error = error;
current->error = error.getCode();
}
EGLint getCurrentError()
......@@ -190,9 +190,4 @@ EGLSurface getCurrentReadSurface()
return current->readSurface;
}
void error(EGLint errorCode)
{
egl::setCurrentError(errorCode);
}
}
......@@ -9,6 +9,8 @@
#ifndef LIBEGL_MAIN_H_
#define LIBEGL_MAIN_H_
#include "libEGL/Error.h"
#include <EGL/egl.h>
#include <EGL/eglext.h>
......@@ -23,7 +25,7 @@ struct Current
EGLSurface readSurface;
};
void setCurrentError(EGLint error);
void recordError(const Error &error);
EGLint getCurrentError();
void setCurrentAPI(EGLenum API);
......@@ -38,24 +40,6 @@ EGLSurface getCurrentDrawSurface();
void setCurrentReadSurface(EGLSurface surface);
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_
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