tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

Error.cpp (1587B)


      1 //
      2 // Copyright 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 
      7 // Error.cpp: Implements the egl::Error and gl::Error classes which encapsulate API errors
      8 // and optional error messages.
      9 
     10 #include "libANGLE/Error.h"
     11 
     12 #include "common/angleutils.h"
     13 #include "common/debug.h"
     14 #include "common/utilities.h"
     15 
     16 #include <cstdarg>
     17 
     18 namespace
     19 {
     20 std::unique_ptr<std::string> EmplaceErrorString(std::string &&message)
     21 {
     22    return message.empty() ? std::unique_ptr<std::string>()
     23                           : std::unique_ptr<std::string>(new std::string(std::move(message)));
     24 }
     25 }  // anonymous namespace
     26 
     27 namespace egl
     28 {
     29 
     30 Error::Error(EGLint errorCode, std::string &&message)
     31    : mCode(errorCode), mID(errorCode), mMessage(EmplaceErrorString(std::move(message)))
     32 {}
     33 
     34 Error::Error(EGLint errorCode, EGLint id, std::string &&message)
     35    : mCode(errorCode), mID(id), mMessage(EmplaceErrorString(std::move(message)))
     36 {}
     37 
     38 void Error::createMessageString() const
     39 {
     40    if (!mMessage)
     41    {
     42        mMessage.reset(new std::string(GetGenericErrorMessage(mCode)));
     43    }
     44 }
     45 
     46 const std::string &Error::getMessage() const
     47 {
     48    createMessageString();
     49    return *mMessage;
     50 }
     51 
     52 std::ostream &operator<<(std::ostream &os, const Error &err)
     53 {
     54    return gl::FmtHex(os, err.getCode());
     55 }
     56 }  // namespace egl
     57 
     58 namespace angle
     59 {
     60 egl::Error ResultToEGL(Result result)
     61 {
     62    if (result == Result::Continue)
     63        return egl::NoError();
     64 
     65    return egl::Error(EGL_BAD_ACCESS);
     66 }
     67 }  // namespace angle