1//
2// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5
6// Error.inl: Inline definitions of egl::Error and gl::Error classes which encapsulate API errors
7// and optional error messages.
8
9#include "common/angleutils.h"
10
11#include <cstdarg>
12
13namespace gl
14{
15
16Error::Error(GLenum errorCode)
17    : mCode(errorCode),
18      mID(errorCode)
19{
20}
21
22Error::Error(const Error &other)
23    : mCode(other.mCode),
24      mID(other.mID)
25{
26    if (other.mMessage)
27    {
28        createMessageString();
29        *mMessage = *(other.mMessage);
30    }
31}
32
33Error::Error(Error &&other)
34    : mCode(other.mCode),
35      mID(other.mID),
36      mMessage(std::move(other.mMessage))
37{
38}
39
40// automatic error type conversion
41Error::Error(egl::Error &&eglErr)
42    : mCode(GL_INVALID_OPERATION),
43      mID(0),
44      mMessage(std::move(eglErr.mMessage))
45{
46}
47
48Error::Error(egl::Error eglErr)
49    : mCode(GL_INVALID_OPERATION),
50      mID(0),
51      mMessage(std::move(eglErr.mMessage))
52{
53}
54
55Error &Error::operator=(const Error &other)
56{
57    mCode = other.mCode;
58    mID = other.mID;
59
60    if (other.mMessage)
61    {
62        createMessageString();
63        *mMessage = *(other.mMessage);
64    }
65    else
66    {
67        mMessage.release();
68    }
69
70    return *this;
71}
72
73Error &Error::operator=(Error &&other)
74{
75    if (this != &other)
76    {
77        mCode = other.mCode;
78        mID = other.mID;
79        mMessage = std::move(other.mMessage);
80    }
81
82    return *this;
83}
84
85GLenum Error::getCode() const
86{
87    return mCode;
88}
89
90GLuint Error::getID() const
91{
92    return mID;
93}
94
95bool Error::isError() const
96{
97    return (mCode != GL_NO_ERROR);
98}
99
100}  // namespace gl
101
102namespace egl
103{
104
105Error::Error(EGLint errorCode)
106    : mCode(errorCode),
107      mID(0)
108{
109}
110
111Error::Error(const Error &other)
112    : mCode(other.mCode),
113      mID(other.mID)
114{
115    if (other.mMessage)
116    {
117        createMessageString();
118        *mMessage = *(other.mMessage);
119    }
120}
121
122Error::Error(Error &&other)
123    : mCode(other.mCode),
124      mID(other.mID),
125      mMessage(std::move(other.mMessage))
126{
127}
128
129// automatic error type conversion
130Error::Error(gl::Error &&glErr)
131    : mCode(EGL_BAD_ACCESS),
132      mID(0),
133      mMessage(std::move(glErr.mMessage))
134{
135}
136
137Error::Error(gl::Error glErr)
138    : mCode(EGL_BAD_ACCESS),
139      mID(0),
140      mMessage(std::move(glErr.mMessage))
141{
142}
143
144Error &Error::operator=(const Error &other)
145{
146    mCode = other.mCode;
147    mID = other.mID;
148
149    if (other.mMessage)
150    {
151        createMessageString();
152        *mMessage = *(other.mMessage);
153    }
154    else
155    {
156        mMessage.release();
157    }
158
159    return *this;
160}
161
162Error &Error::operator=(Error &&other)
163{
164    if (this != &other)
165    {
166        mCode = other.mCode;
167        mID = other.mID;
168        mMessage = std::move(other.mMessage);
169    }
170
171    return *this;
172}
173
174EGLint Error::getCode() const
175{
176    return mCode;
177}
178
179EGLint Error::getID() const
180{
181    return mID;
182}
183
184bool Error::isError() const
185{
186    return (mCode != EGL_SUCCESS);
187}
188
189}
190