Index: gpu/gles2_conform_support/egl/thread_state.h |
diff --git a/gpu/gles2_conform_support/egl/thread_state.h b/gpu/gles2_conform_support/egl/thread_state.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6a11a29b9e3d94a8742456a6df7ab9d3aee65e07 |
--- /dev/null |
+++ b/gpu/gles2_conform_support/egl/thread_state.h |
@@ -0,0 +1,67 @@ |
+// Copyright (c) 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef GPU_GLES2_CONFORM_SUPPORT_EGL_STATE_H_ |
+#define GPU_GLES2_CONFORM_SUPPORT_EGL_STATE_H_ |
+ |
+#include "base/macros.h" |
+#include "base/memory/ref_counted.h" |
+#include <EGL/egl.h> |
+ |
+namespace egl { |
+ |
+class Context; |
+class Display; |
+class Surface; |
+ |
+// Thread-local API state of EGL. |
+class ThreadState { |
+ public: |
+ // Factory getter for the class. Should only be called by the API layer, and |
+ // then passed through Display in order to avoid lock issues. |
+ static ThreadState* Get(); |
+ static void ReleaseThread(); |
+ |
+ ThreadState(); |
+ ~ThreadState(); |
Sami Väisänen
2016/02/19 14:10:15
If lifetime management happens through Get and Rel
Kimmo Kinnunen
2016/02/22 06:43:08
Done.
|
+ |
+ Surface* current_surface() const { return current_surface_.get(); } |
+ Context* current_context() const { return current_context_.get(); } |
Sami Väisänen
2016/02/19 14:10:15
return value is not const Context*, so I'm not sur
Kimmo Kinnunen
2016/02/22 06:43:08
So the returned objects are not part of the logica
|
+ |
+ template <typename T> |
+ T ReturnError(EGLint error, T return_value) { |
+ error_code_ = error; |
+ return return_value; |
+ } |
+ template <typename T> |
+ T ReturnSuccess(T return_value) { |
+ error_code_ = EGL_SUCCESS; |
+ return return_value; |
+ } |
+ EGLint ConsumeErrorCode(); |
+ |
+ Display* GetDefaultDisplay(); |
+ Display* GetDisplay(EGLDisplay); |
+ void SetCurrent(Surface*, Context*); |
+ void ApplyCurrentContext(); |
+ |
+ class AutoApplyCurrentContext { |
+ public: |
+ AutoApplyCurrentContext(ThreadState*); |
+ ~AutoApplyCurrentContext(); |
+ |
+ private: |
+ ThreadState* thread_state_; |
+ }; |
Sami Väisänen
2016/02/19 14:10:15
if this is a RAII type, maybe disallow copyctor an
Kimmo Kinnunen
2016/02/22 06:43:08
Done.
|
+ |
+ private: |
+ EGLint error_code_; |
+ scoped_refptr<Surface> current_surface_; |
+ scoped_refptr<Context> current_context_; |
+ DISALLOW_COPY_AND_ASSIGN(ThreadState); |
+}; |
+ |
+} // namespace egl |
+ |
+#endif |