1*8975f5c5SAndroid Build Coastguard Worker //
2*8975f5c5SAndroid Build Coastguard Worker // Copyright 2014 The ANGLE Project Authors. All rights reserved.
3*8975f5c5SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
4*8975f5c5SAndroid Build Coastguard Worker // found in the LICENSE file.
5*8975f5c5SAndroid Build Coastguard Worker //
6*8975f5c5SAndroid Build Coastguard Worker
7*8975f5c5SAndroid Build Coastguard Worker // Error.cpp: Implements the egl::Error and gl::Error classes which encapsulate API errors
8*8975f5c5SAndroid Build Coastguard Worker // and optional error messages.
9*8975f5c5SAndroid Build Coastguard Worker
10*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/Error.h"
11*8975f5c5SAndroid Build Coastguard Worker
12*8975f5c5SAndroid Build Coastguard Worker #include "common/angleutils.h"
13*8975f5c5SAndroid Build Coastguard Worker #include "common/debug.h"
14*8975f5c5SAndroid Build Coastguard Worker #include "common/utilities.h"
15*8975f5c5SAndroid Build Coastguard Worker
16*8975f5c5SAndroid Build Coastguard Worker #include <cstdarg>
17*8975f5c5SAndroid Build Coastguard Worker
18*8975f5c5SAndroid Build Coastguard Worker namespace
19*8975f5c5SAndroid Build Coastguard Worker {
EmplaceErrorString(std::string && message)20*8975f5c5SAndroid Build Coastguard Worker std::unique_ptr<std::string> EmplaceErrorString(std::string &&message)
21*8975f5c5SAndroid Build Coastguard Worker {
22*8975f5c5SAndroid Build Coastguard Worker return message.empty() ? std::unique_ptr<std::string>()
23*8975f5c5SAndroid Build Coastguard Worker : std::unique_ptr<std::string>(new std::string(std::move(message)));
24*8975f5c5SAndroid Build Coastguard Worker }
25*8975f5c5SAndroid Build Coastguard Worker } // anonymous namespace
26*8975f5c5SAndroid Build Coastguard Worker
27*8975f5c5SAndroid Build Coastguard Worker namespace egl
28*8975f5c5SAndroid Build Coastguard Worker {
29*8975f5c5SAndroid Build Coastguard Worker
Error(EGLint errorCode,std::string && message)30*8975f5c5SAndroid Build Coastguard Worker Error::Error(EGLint errorCode, std::string &&message)
31*8975f5c5SAndroid Build Coastguard Worker : mCode(errorCode), mID(errorCode), mMessage(EmplaceErrorString(std::move(message)))
32*8975f5c5SAndroid Build Coastguard Worker {}
33*8975f5c5SAndroid Build Coastguard Worker
Error(EGLint errorCode,EGLint id,std::string && message)34*8975f5c5SAndroid Build Coastguard Worker Error::Error(EGLint errorCode, EGLint id, std::string &&message)
35*8975f5c5SAndroid Build Coastguard Worker : mCode(errorCode), mID(id), mMessage(EmplaceErrorString(std::move(message)))
36*8975f5c5SAndroid Build Coastguard Worker {}
37*8975f5c5SAndroid Build Coastguard Worker
createMessageString() const38*8975f5c5SAndroid Build Coastguard Worker void Error::createMessageString() const
39*8975f5c5SAndroid Build Coastguard Worker {
40*8975f5c5SAndroid Build Coastguard Worker if (!mMessage)
41*8975f5c5SAndroid Build Coastguard Worker {
42*8975f5c5SAndroid Build Coastguard Worker mMessage.reset(new std::string(GetGenericErrorMessage(mCode)));
43*8975f5c5SAndroid Build Coastguard Worker }
44*8975f5c5SAndroid Build Coastguard Worker }
45*8975f5c5SAndroid Build Coastguard Worker
getMessage() const46*8975f5c5SAndroid Build Coastguard Worker const std::string &Error::getMessage() const
47*8975f5c5SAndroid Build Coastguard Worker {
48*8975f5c5SAndroid Build Coastguard Worker createMessageString();
49*8975f5c5SAndroid Build Coastguard Worker return *mMessage;
50*8975f5c5SAndroid Build Coastguard Worker }
51*8975f5c5SAndroid Build Coastguard Worker
operator <<(std::ostream & os,const Error & err)52*8975f5c5SAndroid Build Coastguard Worker std::ostream &operator<<(std::ostream &os, const Error &err)
53*8975f5c5SAndroid Build Coastguard Worker {
54*8975f5c5SAndroid Build Coastguard Worker return gl::FmtHex(os, err.getCode());
55*8975f5c5SAndroid Build Coastguard Worker }
56*8975f5c5SAndroid Build Coastguard Worker } // namespace egl
57*8975f5c5SAndroid Build Coastguard Worker
58*8975f5c5SAndroid Build Coastguard Worker namespace angle
59*8975f5c5SAndroid Build Coastguard Worker {
ResultToEGL(Result result)60*8975f5c5SAndroid Build Coastguard Worker egl::Error ResultToEGL(Result result)
61*8975f5c5SAndroid Build Coastguard Worker {
62*8975f5c5SAndroid Build Coastguard Worker if (result == Result::Continue)
63*8975f5c5SAndroid Build Coastguard Worker return egl::NoError();
64*8975f5c5SAndroid Build Coastguard Worker
65*8975f5c5SAndroid Build Coastguard Worker return egl::Error(EGL_BAD_ACCESS);
66*8975f5c5SAndroid Build Coastguard Worker }
67*8975f5c5SAndroid Build Coastguard Worker } // namespace angle
68