TYPE3
[iec.git] / src / type3_AndroidCloud / anbox-master / src / anbox / graphics / emugl / RenderThread.h
1 /*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef _LIB_OPENGL_RENDER_RENDER_THREAD_H
18 #define _LIB_OPENGL_RENDER_RENDER_THREAD_H
19
20 #include "external/android-emugl/host/include/libOpenglRender/IOStream.h"
21
22 #include "emugl/common/thread.h"
23
24 #include <memory>
25 #include <mutex>
26
27 class Renderer;
28
29 // A class used to model a thread of the RenderServer. Each one of them
30 // handles a single guest client / protocol byte stream.
31 class RenderThread : public emugl::Thread {
32  public:
33   // Create a new RenderThread instance.
34   // |stream| is an input stream that will be read from the thread,
35   // and deleted by it when it exits.
36   // |mutex| is a pointer to a shared mutex used to serialize
37   // decoding operations between all threads.
38   // TODO(digit): Why is this needed here? Shouldn't this be handled
39   //              by the decoders themselves or at a lower-level?
40   static RenderThread* create(const std::shared_ptr<Renderer>& renderer, IOStream* stream, std::mutex &m);
41
42   // Destructor.
43   virtual ~RenderThread();
44
45   // Returns true iff the thread has finished.
46   // Note that this also means that the thread's stack has been
47   bool isFinished() { return tryWait(NULL); }
48
49   // Force a thread to stop.
50   void forceStop();
51
52  private:
53   RenderThread();  // No default constructor
54
55   RenderThread(const std::shared_ptr<Renderer>& renderer, IOStream* stream, std::mutex &m);
56
57   virtual intptr_t main();
58
59   std::shared_ptr<Renderer> renderer_;
60   std::mutex &m_lock;
61   IOStream* m_stream;
62 };
63
64 #endif