OSDN Git Service

Merge changes from topic 'emu-glsync-guest-v2'
[android-x86/device-generic-goldfish-opengl.git] / system / OpenglSystemCommon / HostConnection.h
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 __COMMON_HOST_CONNECTION_H
17 #define __COMMON_HOST_CONNECTION_H
18
19 #include "IOStream.h"
20 #include "renderControl_enc.h"
21 #include "ChecksumCalculator.h"
22
23 #include <string>
24
25 class GLEncoder;
26 class gl_client_context_t;
27 class GL2Encoder;
28 class gl2_client_context_t;
29
30 // SyncImpl determines the presence of host/guest OpenGL fence sync
31 // capabilities. It corresponds exactly to EGL_ANDROID_native_fence_sync
32 // capability, but for the emulator, we need to make sure that
33 // OpenGL pipe protocols match, so we use a special extension name
34 // here.
35 // SYNC_IMPL_NONE means that the native fence sync capability is
36 // not present, and we will end up using the equivalent of glFinish
37 // in order to preserve buffer swapping order.
38 // SYNC_IMPL_NATIVE_SYNC means that we do have native fence sync
39 // capability, and we will use a fence fd to synchronize buffer swaps.
40 enum SyncImpl {
41     SYNC_IMPL_NONE = 0,
42     SYNC_IMPL_NATIVE_SYNC = 1
43 };
44 // Interface:
45 // If this GL extension string shows up, we use
46 // SYNC_IMPL_NATIVE_SYNC, otherwise we use SYNC_IMPL_NONE.
47 static const char kRCNativeSync[] = "ANDROID_EMU_NATIVE_SYNC";
48
49 // ExtendedRCEncoderContext is an extended version of renderControl_encoder_context_t
50 // that will be used to track SyncImpl.
51 class ExtendedRCEncoderContext : public renderControl_encoder_context_t {
52 public:
53     ExtendedRCEncoderContext(IOStream *stream, ChecksumCalculator *checksumCalculator)
54         : renderControl_encoder_context_t(stream, checksumCalculator) { }
55     void setSyncImpl(SyncImpl syncImpl) { m_syncImpl = syncImpl; }
56     bool hasNativeSync() const { return m_syncImpl == SYNC_IMPL_NATIVE_SYNC; }
57 private:
58     SyncImpl m_syncImpl;
59 };
60
61 class HostConnection
62 {
63 public:
64     static HostConnection *get();
65     static void exit();
66     ~HostConnection();
67
68     GLEncoder *glEncoder();
69     GL2Encoder *gl2Encoder();
70     ExtendedRCEncoderContext *rcEncoder();
71     ChecksumCalculator *checksumHelper() { return &m_checksumHelper; }
72
73     void flush() {
74         if (m_stream) {
75             m_stream->flush();
76         }
77     }
78
79     void setGrallocOnly(bool gralloc_only) {
80         m_grallocOnly = gralloc_only;
81     }
82
83     bool isGrallocOnly() const { return m_grallocOnly; }
84
85 private:
86     HostConnection();
87     static gl_client_context_t  *s_getGLContext();
88     static gl2_client_context_t *s_getGL2Context();
89
90     std::string queryGLExtensions(ExtendedRCEncoderContext *rcEnc);
91     // setProtocol initilizes GL communication protocol for checksums
92     // should be called when m_rcEnc is created
93     void setChecksumHelper(ExtendedRCEncoderContext *rcEnc);
94     void queryAndSetSyncImpl(ExtendedRCEncoderContext *rcEnc);
95
96 private:
97     IOStream *m_stream;
98     GLEncoder   *m_glEnc;
99     GL2Encoder  *m_gl2Enc;
100     ExtendedRCEncoderContext *m_rcEnc;
101     ChecksumCalculator m_checksumHelper;
102     std::string m_glExtensions;
103     bool m_grallocOnly;
104 };
105
106 #endif