• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef _RENDERER_H_
17 #define _RENDERER_H_
18 #include <map>
19 #include "RendererSurface.h"
20 #include "RendererContext.h"
21 #include "NativeWindowing.h"
22 #include <utils/threads.h>
23 
24 class RenderingThread;
25 
26 class Renderer {
27 public:
28 
29     class ClientHandle {
30     public:
31         unsigned int pid;
32         unsigned int handle;
ClientHandle(unsigned int _pid,unsigned int _handle)33         ClientHandle(unsigned int _pid, unsigned int _handle) : pid(_pid), handle(_handle) {}
34 
35         bool operator< (const ClientHandle & p) const {
36             bool val = (pid == p.pid) ? handle < p.handle : pid < p.pid;
37             return val;
38         }
39     };
40 
41     static Renderer *instance();
42     int createSurface(RenderingThread *thread, const ClientHandle & handle);
43     int destroySurface(RenderingThread *thread, const ClientHandle &handle);
44     int createContext(RenderingThread *thread, const ClientHandle & ctx, const ClientHandle shareCtx, int version);
45     int destroyContext(RenderingThread *thread,const ClientHandle & ctx);
46     int makeCurrent(RenderingThread *thread,
47                     const ClientHandle & drawSurface, const ClientHandle & readSurface, const ClientHandle & ctx);
48     int swapBuffers(RenderingThread *thread, const ClientHandle & surface);
49 
50 private:
51     typedef std::map<ClientHandle, RendererSurface *> SurfaceMap;
52     typedef std::map<ClientHandle, RendererContext *> ContextMap;
53     static Renderer *m_instance;
54     Renderer();
55     SurfaceMap m_surfaces;
56     ContextMap m_ctxs;
57     NativeWindowing *m_nw;
58     EGLDisplay m_dpy;
59 
60     android::Mutex m_mutex; // single global mutex for the renderer class;
61 };
62 #endif
63