• 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 _LIBRENDER_RENDER_CONTEXT_H
17 #define _LIBRENDER_RENDER_CONTEXT_H
18 
19 #include "base/Stream.h"
20 #include "GLDecoderContextData.h"
21 
22 #include <EGL/egl.h>
23 
24 #include <memory>
25 
26 // Type of handles, a.k.a. "object names" in the GL specification.
27 // These are integers used to uniquely identify a resource of a given type.
28 typedef uint32_t HandleType;
29 
30 // Tracks all the possible OpenGL ES API versions.
31 enum GLESApi {
32     GLESApi_CM = 1,
33     GLESApi_2 = 2,
34     GLESApi_3_0 = 3,
35     GLESApi_3_1 = 4,
36     GLESApi_3_2 = 5,
37 };
38 
39 // A class used to model a guest EGLContext. This simply wraps a host
40 // EGLContext, associated with an GLDecoderContextData instance that is
41 // used to store copies of guest-side arrays.
42 class RenderContext {
43 public:
44     // Create a new RenderContext instance.
45     // |display| is the host EGLDisplay handle.
46     // |config| is the host EGLConfig to use.
47     // |sharedContext| is either EGL_NO_CONTEXT of a host EGLContext handle.
48     // |version| specifies the GLES version as a GLESApi.
49     static RenderContext *create(EGLDisplay display,
50                                  EGLConfig config,
51                                  EGLContext sharedContext,
52                                  HandleType hndl,
53                                  GLESApi = GLESApi_CM);
54 
55     // Destructor.
56     ~RenderContext();
57 
58     // Retrieve host EGLContext value.
getEGLContext()59     EGLContext getEGLContext() const { return mContext; }
60 
61     // Return the GLES version it is trying to emulate in this context.
62     // This can be different from the underlying version when using
63     // GLES12Translator.
64     GLESApi clientVersion() const;
65 
66     // Retrieve GLDecoderContextData instance reference for this
67     // RenderContext instance.
decoderContextData()68     GLDecoderContextData& decoderContextData() { return mContextData; }
69 
getHndl()70     HandleType getHndl() const { return mHndl; }
71 
72     void onSave(android::base::Stream* stream);
73     static RenderContext *onLoad(android::base::Stream* stream,
74             EGLDisplay display);
75 private:
76     RenderContext(EGLDisplay display,
77                   EGLContext context,
78                   HandleType hndl,
79                   GLESApi version,
80                   void* emulatedGLES1Context);
81 
82     // Implementation of create
83     // |stream| is the stream to load from when restoring a snapshot,
84     // set |stream| to nullptr if it is not loading from a snapshot
85     static RenderContext *createImpl(EGLDisplay display,
86                                  EGLConfig config,
87                                  EGLContext sharedContext,
88                                  HandleType hndl,
89                                  GLESApi version,
90                                  android::base::Stream *stream);
91 private:
92     EGLDisplay mDisplay;
93     EGLContext mContext;
94     HandleType mHndl;
95     GLESApi mVersion;
96     GLDecoderContextData mContextData;
97 };
98 
99 typedef std::shared_ptr<RenderContext> RenderContextPtr;
100 
101 #endif  // _LIBRENDER_RENDER_CONTEXT_H
102