1 // Copyright (C) 2015 The Android Open Source Project
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
15 #ifndef _LIBRENDER_FB_CONFIG_H
16 #define _LIBRENDER_FB_CONFIG_H
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
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.
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 {
40 // Retrieve host EGLConfig.
41 EGLConfig getEglConfig() const { return mEglConfig; }
43 // Get depth size in bits.
44 GLuint getDepthSize() const { return getAttribValue(0); }
46 // Get stencil size in bits.
47 GLuint getStencilSize() const { return getAttribValue(1); }
49 // Get renderable type mask.
50 GLuint getRenderableType() const { return getAttribValue(2); }
52 // Get surface type mask.
53 GLuint getSurfaceType() const { return getAttribValue(3); }
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)); }
61 RendererConfig(RendererConfig& other);
63 explicit RendererConfig(EGLConfig hostConfig, EGLDisplay hostDisplay);
65 friend class RendererConfigList;
67 GLuint getAttribValue(int n) const {
68 return mAttribValues ? mAttribValues[n] : 0U;
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).
80 // Usage is the following:
82 // 1) Create new instance by passing host EGLDisplay value.
84 // 2) Call empty() to check that the list is not empty, which would indicate
85 // an error during creation.
87 // 3) FbConfig instances are identified by numbers in 0..(N-1) range, where
88 // N is the result of the size() method.
90 // 4) Convert an FbConfig id into an FbConfig instance with get().
92 // 5) Use getPackInfo() and packConfigs() to retrieve information about
93 // available configs to the guest.
94 class RendererConfigList {
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.
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);
105 ~RendererConfigList();
107 // Return true iff the list is empty. true means there was an error
108 // during construction.
109 bool empty() const { return mCount == 0; }
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); }
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];
127 // Use |attribs| a list of EGL attribute name/values terminated by
128 // EGL_NONE, to select a set of matching FbConfig instances.
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.
134 // |configsSize| is the number of entries in the |configs| array. The
135 // function will never write more than |configsSize| entries into
137 EGLint chooseConfig(const EGLint* attribs, EGLint* configs,
138 EGLint configsSize) const;
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;
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;
154 RendererConfigList();
155 RendererConfigList(const RendererConfigList& other);
158 RendererConfig** mConfigs;
162 #endif // _LIBRENDER_FB_CONFIG_H