• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
15 namespace angle
16 {
17 bool gUseAndroidOpenGLTlsSlot;
18 }  // namespace angle
19 
20 namespace egl
21 {
22 namespace
23 {
24 Debug *sDebug = nullptr;
25 }  // namespace
26 
Thread()27 Thread::Thread()
28     : mLabel(nullptr),
29       mError(EGL_SUCCESS),
30       mAPI(EGL_OPENGL_ES_API),
31       mContext(static_cast<gl::Context *>(EGL_NO_CONTEXT))
32 {}
33 
setLabel(EGLLabelKHR label)34 void Thread::setLabel(EGLLabelKHR label)
35 {
36     mLabel = label;
37 }
38 
getLabel() const39 EGLLabelKHR Thread::getLabel() const
40 {
41     return mLabel;
42 }
43 
setSuccess()44 void Thread::setSuccess()
45 {
46     mError = EGL_SUCCESS;
47 }
48 
setError(EGLint error,const char * command,const LabeledObject * object,const char * message)49 void Thread::setError(EGLint error,
50                       const char *command,
51                       const LabeledObject *object,
52                       const char *message)
53 {
54     mError = error;
55     if (error != EGL_SUCCESS && message)
56     {
57         EnsureDebugAllocated();
58         sDebug->insertMessage(error, command, ErrorCodeToMessageType(error), getLabel(),
59                               object ? object->getLabel() : nullptr, message);
60     }
61 }
62 
setError(const Error & error,const char * command,const LabeledObject * object)63 void Thread::setError(const Error &error, const char *command, const LabeledObject *object)
64 {
65     mError = error.getCode();
66     if (error.isError() && !error.getMessage().empty())
67     {
68         EnsureDebugAllocated();
69         sDebug->insertMessage(error.getCode(), command, ErrorCodeToMessageType(error.getCode()),
70                               getLabel(), object ? object->getLabel() : nullptr,
71                               error.getMessage());
72     }
73 }
74 
getError() const75 EGLint Thread::getError() const
76 {
77     return mError;
78 }
79 
setAPI(EGLenum api)80 void Thread::setAPI(EGLenum api)
81 {
82     mAPI = api;
83 }
84 
getAPI() const85 EGLenum Thread::getAPI() const
86 {
87     return mAPI;
88 }
89 
setCurrent(gl::Context * context)90 void Thread::setCurrent(gl::Context *context)
91 {
92     mContext = context;
93 }
94 
getCurrentDrawSurface() const95 Surface *Thread::getCurrentDrawSurface() const
96 {
97     if (mContext)
98     {
99         return mContext->getCurrentDrawSurface();
100     }
101     return nullptr;
102 }
103 
getCurrentReadSurface() const104 Surface *Thread::getCurrentReadSurface() const
105 {
106     if (mContext)
107     {
108         return mContext->getCurrentReadSurface();
109     }
110     return nullptr;
111 }
112 
getContext() const113 gl::Context *Thread::getContext() const
114 {
115     return mContext;
116 }
117 
getDisplay() const118 Display *Thread::getDisplay() const
119 {
120     if (mContext)
121     {
122         return mContext->getDisplay();
123     }
124     return nullptr;
125 }
126 
EnsureDebugAllocated()127 void EnsureDebugAllocated()
128 {
129     // All EGL calls use a global lock, this is thread safe
130     if (sDebug == nullptr)
131     {
132         sDebug = new Debug();
133     }
134 }
135 
DeallocateDebug()136 void DeallocateDebug()
137 {
138     SafeDelete(sDebug);
139 }
140 
GetDebug()141 Debug *GetDebug()
142 {
143     EnsureDebugAllocated();
144     return sDebug;
145 }
146 }  // namespace egl
147