summaryrefslogtreecommitdiff
path: root/stream-servers/RenderContext.h
blob: 2675982738e37c698bfbf1dea309382e206f32b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _LIBRENDER_RENDER_CONTEXT_H
#define _LIBRENDER_RENDER_CONTEXT_H

#include "base/Stream.h"
#include "GLDecoderContextData.h"

#include <EGL/egl.h>

#include <memory>

// Type of handles, a.k.a. "object names" in the GL specification.
// These are integers used to uniquely identify a resource of a given type.
typedef uint32_t HandleType;

// Tracks all the possible OpenGL ES API versions.
enum GLESApi {
    GLESApi_CM = 1,
    GLESApi_2 = 2,
    GLESApi_3_0 = 3,
    GLESApi_3_1 = 4,
    GLESApi_3_2 = 5,
};

// A class used to model a guest EGLContext. This simply wraps a host
// EGLContext, associated with an GLDecoderContextData instance that is
// used to store copies of guest-side arrays.
class RenderContext {
public:
    // Create a new RenderContext instance.
    // |display| is the host EGLDisplay handle.
    // |config| is the host EGLConfig to use.
    // |sharedContext| is either EGL_NO_CONTEXT of a host EGLContext handle.
    // |version| specifies the GLES version as a GLESApi.
    static RenderContext *create(EGLDisplay display,
                                 EGLConfig config,
                                 EGLContext sharedContext,
                                 HandleType hndl,
                                 GLESApi = GLESApi_CM);

    // Destructor.
    ~RenderContext();

    // Retrieve host EGLContext value.
    EGLContext getEGLContext() const { return mContext; }

    // Return the GLES version it is trying to emulate in this context.
    // This can be different from the underlying version when using
    // GLES12Translator.
    GLESApi clientVersion() const;

    // Retrieve GLDecoderContextData instance reference for this
    // RenderContext instance.
    GLDecoderContextData& decoderContextData() { return mContextData; }

    HandleType getHndl() const { return mHndl; }

    void onSave(android::base::Stream* stream);
    static RenderContext *onLoad(android::base::Stream* stream,
            EGLDisplay display);
private:
    RenderContext(EGLDisplay display,
                  EGLContext context,
                  HandleType hndl,
                  GLESApi version,
                  void* emulatedGLES1Context);

    // Implementation of create
    // |stream| is the stream to load from when restoring a snapshot,
    // set |stream| to nullptr if it is not loading from a snapshot
    static RenderContext *createImpl(EGLDisplay display,
                                 EGLConfig config,
                                 EGLContext sharedContext,
                                 HandleType hndl,
                                 GLESApi version,
                                 android::base::Stream *stream);
private:
    EGLDisplay mDisplay;
    EGLContext mContext;
    HandleType mHndl;
    GLESApi mVersion;
    GLDecoderContextData mContextData;
};

typedef std::shared_ptr<RenderContext> RenderContextPtr;

#endif  // _LIBRENDER_RENDER_CONTEXT_H