2 * Copyright (C) 2011 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef __COMMON_HOST_CONNECTION_H
17 #define __COMMON_HOST_CONNECTION_H
20 #include "renderControl_enc.h"
21 #include "ChecksumCalculator.h"
22 #include "goldfish_dma.h"
27 struct gl_client_context_t;
29 struct gl2_client_context_t;
31 // SyncImpl determines the presence of host/guest OpenGL fence sync
32 // capabilities. It corresponds exactly to EGL_ANDROID_native_fence_sync
33 // capability, but for the emulator, we need to make sure that
34 // OpenGL pipe protocols match, so we use a special extension name
36 // SYNC_IMPL_NONE means that the native fence sync capability is
37 // not present, and we will end up using the equivalent of glFinish
38 // in order to preserve buffer swapping order.
39 // SYNC_IMPL_NATIVE_SYNC means that we do have native fence sync
40 // capability, and we will use a fence fd to synchronize buffer swaps.
43 SYNC_IMPL_NATIVE_SYNC = 1
47 // If this GL extension string shows up, we use
48 // SYNC_IMPL_NATIVE_SYNC, otherwise we use SYNC_IMPL_NONE.
49 // This string is always updated to require the _latest_
50 // version of Android emulator native sync in this system image;
51 // otherwise, we do not use the feature.
52 static const char kRCNativeSync[] = "ANDROID_EMU_native_sync_v2";
60 static const char kDmaExtStr_v1[] = "ANDROID_EMU_dma_v1";
62 // OpenGL ES max supported version
64 GLES_MAX_VERSION_2 = 0,
65 GLES_MAX_VERSION_3_0 = 1,
66 GLES_MAX_VERSION_3_1 = 2,
67 GLES_MAX_VERSION_3_2 = 3,
70 static const char kGLESMaxVersion_2[] = "ANDROID_EMU_gles_max_version_2";
71 static const char kGLESMaxVersion_3_0[] = "ANDROID_EMU_gles_max_version_3_0";
72 static const char kGLESMaxVersion_3_1[] = "ANDROID_EMU_gles_max_version_3_1";
73 static const char kGLESMaxVersion_3_2[] = "ANDROID_EMU_gles_max_version_3_2";
75 // ExtendedRCEncoderContext is an extended version of renderControl_encoder_context_t
76 // that will be used to track SyncImpl.
77 class ExtendedRCEncoderContext : public renderControl_encoder_context_t {
79 ExtendedRCEncoderContext(IOStream *stream, ChecksumCalculator *checksumCalculator)
80 : renderControl_encoder_context_t(stream, checksumCalculator) {
83 void setSyncImpl(SyncImpl syncImpl) { m_syncImpl = syncImpl; }
84 void setDmaImpl(DmaImpl dmaImpl) { m_dmaImpl = dmaImpl; }
85 bool hasNativeSync() const { return m_syncImpl == SYNC_IMPL_NATIVE_SYNC; }
86 DmaImpl getDmaVersion() const { return m_dmaImpl; }
87 void bindDmaContext(struct goldfish_dma_context* cxt) { m_dmaCxt = cxt; }
88 virtual uint64_t lockAndWriteDma(void* data, uint32_t size) {
89 ALOGV("%s: call", __FUNCTION__);
91 ALOGE("%s: ERROR: No DMA context bound!",
95 goldfish_dma_lock(m_dmaCxt);
96 goldfish_dma_write(m_dmaCxt, data, size);
97 uint64_t paddr = goldfish_dma_guest_paddr(m_dmaCxt);
98 ALOGV("%s: paddr=0x%llx", __FUNCTION__, paddr);
101 void setGLESMaxVersion(GLESMaxVersion ver) { m_glesMaxVersion = ver; }
102 GLESMaxVersion getGLESMaxVersion() const { return m_glesMaxVersion; }
106 struct goldfish_dma_context* m_dmaCxt;
107 GLESMaxVersion m_glesMaxVersion;
113 static HostConnection *get();
117 GLEncoder *glEncoder();
118 GL2Encoder *gl2Encoder();
119 ExtendedRCEncoderContext *rcEncoder();
120 ChecksumCalculator *checksumHelper() { return &m_checksumHelper; }
128 void setGrallocOnly(bool gralloc_only) {
129 m_grallocOnly = gralloc_only;
132 bool isGrallocOnly() const { return m_grallocOnly; }
134 int getPipeFd() const { return m_pipeFd; }
138 static gl_client_context_t *s_getGLContext();
139 static gl2_client_context_t *s_getGL2Context();
141 const std::string& queryGLExtensions(ExtendedRCEncoderContext *rcEnc);
142 // setProtocol initilizes GL communication protocol for checksums
143 // should be called when m_rcEnc is created
144 void setChecksumHelper(ExtendedRCEncoderContext *rcEnc);
145 void queryAndSetSyncImpl(ExtendedRCEncoderContext *rcEnc);
146 void queryAndSetDmaImpl(ExtendedRCEncoderContext *rcEnc);
147 void queryAndSetGLESMaxVersion(ExtendedRCEncoderContext *rcEnc);
152 GL2Encoder *m_gl2Enc;
153 ExtendedRCEncoderContext *m_rcEnc;
154 ChecksumCalculator m_checksumHelper;
155 std::string m_glExtensions;