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
Thread()23 Thread::Thread()
24 : mLabel(nullptr),
25 mError(EGL_SUCCESS),
26 mAPI(EGL_OPENGL_ES_API),
27 mContext(static_cast<gl::Context *>(EGL_NO_CONTEXT))
28 {}
29
setLabel(EGLLabelKHR label)30 void Thread::setLabel(EGLLabelKHR label)
31 {
32 mLabel = label;
33 }
34
getLabel() const35 EGLLabelKHR Thread::getLabel() const
36 {
37 return mLabel;
38 }
39
setSuccess()40 void Thread::setSuccess()
41 {
42 mError = EGL_SUCCESS;
43 }
44
setError(const Error & error,const Debug * debug,const char * command,const LabeledObject * object)45 void Thread::setError(const Error &error,
46 const Debug *debug,
47 const char *command,
48 const LabeledObject *object)
49 {
50 ASSERT(debug != nullptr);
51
52 mError = error.getCode();
53 if (error.isError() && !error.getMessage().empty())
54 {
55 debug->insertMessage(error.getCode(), command, ErrorCodeToMessageType(error.getCode()),
56 getLabel(), object ? object->getLabel() : nullptr, error.getMessage());
57 }
58 }
59
getError() const60 EGLint Thread::getError() const
61 {
62 return mError;
63 }
64
setAPI(EGLenum api)65 void Thread::setAPI(EGLenum api)
66 {
67 mAPI = api;
68 }
69
getAPI() const70 EGLenum Thread::getAPI() const
71 {
72 return mAPI;
73 }
74
setCurrent(gl::Context * context)75 void Thread::setCurrent(gl::Context *context)
76 {
77 mContext = context;
78 }
79
getCurrentDrawSurface() const80 Surface *Thread::getCurrentDrawSurface() const
81 {
82 if (mContext)
83 {
84 return mContext->getCurrentDrawSurface();
85 }
86 return nullptr;
87 }
88
getCurrentReadSurface() const89 Surface *Thread::getCurrentReadSurface() const
90 {
91 if (mContext)
92 {
93 return mContext->getCurrentReadSurface();
94 }
95 return nullptr;
96 }
97
getContext() const98 gl::Context *Thread::getContext() const
99 {
100 return mContext;
101 }
102
getDisplay() const103 Display *Thread::getDisplay() const
104 {
105 if (mContext)
106 {
107 return mContext->getDisplay();
108 }
109 return nullptr;
110 }
111 } // namespace egl
112