TYPE3
[iec.git] / src / type3_AndroidCloud / anbox-master / src / anbox / graphics / emugl / RendererConfig.h
1 // Copyright (C) 2015 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #ifndef _LIBRENDER_FB_CONFIG_H
16 #define _LIBRENDER_FB_CONFIG_H
17
18 #include <EGL/egl.h>
19 #include <GLES/gl.h>
20
21 #include <stddef.h>
22
23 // A class used to model a guest EGL config.
24 // This really wraps a host EGLConfig handle, and provides a few cached
25 // attributes that can be retrieved through direct accessors, like
26 // getDepthSize().
27 //
28 // Each FbConfig is identified by a unique id which is its index in
29 // an FbConfigList instance (as declared below). It is not related to
30 // the host EGLConfig value or its EGL_CONFIG_ID.
31 //
32 // One doesn't create an FbConfig instance. Instead, create and initialize
33 // an FbConfigList from the host EGLDisplay, and use its size() and get()
34 // methods to access it.
35 class RendererConfig {
36  public:
37   // Destructor
38   ~RendererConfig();
39
40   // Retrieve host EGLConfig.
41   EGLConfig getEglConfig() const { return mEglConfig; }
42
43   // Get depth size in bits.
44   GLuint getDepthSize() const { return getAttribValue(0); }
45
46   // Get stencil size in bits.
47   GLuint getStencilSize() const { return getAttribValue(1); }
48
49   // Get renderable type mask.
50   GLuint getRenderableType() const { return getAttribValue(2); }
51
52   // Get surface type mask.
53   GLuint getSurfaceType() const { return getAttribValue(3); }
54
55   // Get the EGL_CONFIG_ID value. This is the same as the one of the
56   // underlying host EGLConfig handle.
57   GLint getConfigId() const { return static_cast<GLint>(getAttribValue(4)); }
58
59  private:
60   RendererConfig();
61   RendererConfig(RendererConfig& other);
62
63   explicit RendererConfig(EGLConfig hostConfig, EGLDisplay hostDisplay);
64
65   friend class RendererConfigList;
66
67   GLuint getAttribValue(int n) const {
68     return mAttribValues ? mAttribValues[n] : 0U;
69   }
70
71   EGLConfig mEglConfig;
72   GLint* mAttribValues;
73 };
74
75 // A class to model the list of FbConfig for a given EGLDisplay, this is
76 // built from the list of host EGLConfig handles, filtered to only accept
77 // configs that are useful by the rendering library (e.g. they must support
78 // PBuffers and RGB pixel values).
79 //
80 // Usage is the following:
81 //
82 // 1) Create new instance by passing host EGLDisplay value.
83 //
84 // 2) Call empty() to check that the list is not empty, which would indicate
85 //    an error during creation.
86 //
87 // 3) FbConfig instances are identified by numbers in 0..(N-1) range, where
88 //    N is the result of the size() method.
89 //
90 // 4) Convert an FbConfig id into an FbConfig instance with get().
91 //
92 // 5) Use getPackInfo() and packConfigs() to retrieve information about
93 //    available configs to the guest.
94 class RendererConfigList {
95  public:
96   // Create a new list of FbConfig instance, by querying all compatible
97   // host configs from |display|. A compatible config is one that supports
98   // Pbuffers and RGB pixel values.
99   //
100   // After construction, call empty() to check if there are items.
101   // An empty list means there was an error during construction.
102   explicit RendererConfigList(EGLDisplay display);
103
104   // Destructor.
105   ~RendererConfigList();
106
107   // Return true iff the list is empty. true means there was an error
108   // during construction.
109   bool empty() const { return mCount == 0; }
110
111   // Return the number of FbConfig instances in the list.
112   // Each instance is identified by a number from 0 to N-1,
113   // where N is the result of this function.
114   size_t size() const { return static_cast<size_t>(mCount); }
115
116   // Retrieve the FbConfig instance associated with |guestId|,
117   // which must be an integer between 0 and |size() - 1|. Returns
118   // NULL in case of failure.
119   const RendererConfig* get(int guestId) const {
120     if (guestId >= 0 && guestId < mCount) {
121       return mConfigs[guestId];
122     } else {
123       return NULL;
124     }
125   }
126
127   // Use |attribs| a list of EGL attribute name/values terminated by
128   // EGL_NONE, to select a set of matching FbConfig instances.
129   //
130   // On success, returns the number of matching instances.
131   // If |configs| is not NULL, it will be populated with the guest IDs
132   // of the matched FbConfig instances.
133   //
134   // |configsSize| is the number of entries in the |configs| array. The
135   // function will never write more than |configsSize| entries into
136   // |configsSize|.
137   EGLint chooseConfig(const EGLint* attribs, EGLint* configs,
138                       EGLint configsSize) const;
139
140   // Retrieve information that can be sent to the guest before packed
141   // config list information. If |numConfigs| is NULL, then |*numConfigs|
142   // will be set on return to the number of config instances.
143   // If |numAttribs| is not NULL, then |*numAttribs| will be set on return
144   // to the number of attribute values cached by each FbConfig instance.
145   void getPackInfo(EGLint* mumConfigs, EGLint* numAttribs) const;
146
147   // Write the full list information into an array of EGLuint items.
148   // |buffer| is the output buffer that will receive the data.
149   // |bufferByteSize| is teh buffer size in bytes.
150   // On success, this returns
151   EGLint packConfigs(GLuint bufferByteSize, GLuint* buffer) const;
152
153  private:
154   RendererConfigList();
155   RendererConfigList(const RendererConfigList& other);
156
157   int mCount;
158   RendererConfig** mConfigs;
159   EGLDisplay mDisplay;
160 };
161
162 #endif  // _LIBRENDER_FB_CONFIG_H