1 //
2 // Copyright 2016 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 // Thread.cpp : Defines the Thread class which represents a global EGL thread.
8
9 #include "libANGLE/Thread.h"
10
11 #include "libANGLE/Context.h"
12 #include "libANGLE/Debug.h"
13 #include "libANGLE/Error.h"
14 #include "libANGLE/ErrorStrings.h"
15
16 namespace egl
17 {
18
Thread()19 Thread::Thread()
20 : mLabel(nullptr),
21 mError(EGL_SUCCESS),
22 mAPI(EGL_OPENGL_ES_API),
23 mContext(static_cast<gl::Context *>(EGL_NO_CONTEXT))
24 {}
25
setLabel(EGLLabelKHR label)26 void Thread::setLabel(EGLLabelKHR label)
27 {
28 mLabel = label;
29 }
30
getLabel() const31 EGLLabelKHR Thread::getLabel() const
32 {
33 return mLabel;
34 }
35
setSuccess()36 void Thread::setSuccess()
37 {
38 mError = EGL_SUCCESS;
39 }
40
setError(const Error & error,const Debug * debug,const char * command,const LabeledObject * object)41 void Thread::setError(const Error &error,
42 const Debug *debug,
43 const char *command,
44 const LabeledObject *object)
45 {
46 ASSERT(debug != nullptr);
47
48 mError = error.getCode();
49 if (error.isError() && !error.getMessage().empty())
50 {
51 debug->insertMessage(error.getCode(), command, ErrorCodeToMessageType(error.getCode()),
52 getLabel(), object ? object->getLabel() : nullptr, error.getMessage());
53 }
54 }
55
getError() const56 EGLint Thread::getError() const
57 {
58 return mError;
59 }
60
setAPI(EGLenum api)61 void Thread::setAPI(EGLenum api)
62 {
63 mAPI = api;
64 }
65
getAPI() const66 EGLenum Thread::getAPI() const
67 {
68 return mAPI;
69 }
70
setCurrent(gl::Context * context)71 void Thread::setCurrent(gl::Context *context)
72 {
73 mContext = context;
74 }
75
getCurrentDrawSurface() const76 Surface *Thread::getCurrentDrawSurface() const
77 {
78 if (mContext)
79 {
80 return mContext->getCurrentDrawSurface();
81 }
82 return nullptr;
83 }
84
getCurrentReadSurface() const85 Surface *Thread::getCurrentReadSurface() const
86 {
87 if (mContext)
88 {
89 return mContext->getCurrentReadSurface();
90 }
91 return nullptr;
92 }
93
getContext() const94 gl::Context *Thread::getContext() const
95 {
96 return mContext;
97 }
98
getValidContext() const99 gl::Context *Thread::getValidContext() const
100 {
101 if (mContext && mContext->isContextLost())
102 {
103 mContext->handleError(GL_OUT_OF_MEMORY, gl::err::kContextLost, __FILE__, ANGLE_FUNCTION,
104 __LINE__);
105 return nullptr;
106 }
107
108 return mContext;
109 }
110
getDisplay() const111 Display *Thread::getDisplay() const
112 {
113 if (mContext)
114 {
115 return mContext->getDisplay();
116 }
117 return nullptr;
118 }
119
120 } // namespace egl
121