keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 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" |
Yahan Zhou | b7f0908 | 2016-03-10 11:45:02 -0800 | [diff] [blame] | 21 | #include "ChecksumCalculator.h" |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 22 | |
Lingfeng Yang | 1883535 | 2016-05-23 12:16:04 -0700 | [diff] [blame] | 23 | #include <string> |
| 24 | |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 25 | class GLEncoder; |
Yahan Zhou | e8cf63d | 2016-09-22 12:33:50 -0700 | [diff] [blame^] | 26 | struct gl_client_context_t; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 27 | class GL2Encoder; |
Yahan Zhou | e8cf63d | 2016-09-22 12:33:50 -0700 | [diff] [blame^] | 28 | struct gl2_client_context_t; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 29 | |
Lingfeng Yang | 4f12b8d | 2016-07-13 16:26:10 -0700 | [diff] [blame] | 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. |
Lingfeng Yang | 2ce4c31 | 2016-08-31 14:46:11 -0700 | [diff] [blame] | 47 | // This string is always updated to require the _latest_ |
| 48 | // version of Android emulator native sync in this system image; |
| 49 | // otherwise, we do not use the feature. |
| 50 | static const char kRCNativeSync[] = "ANDROID_EMU_native_sync_v2"; |
Lingfeng Yang | 4f12b8d | 2016-07-13 16:26:10 -0700 | [diff] [blame] | 51 | |
| 52 | // ExtendedRCEncoderContext is an extended version of renderControl_encoder_context_t |
| 53 | // that will be used to track SyncImpl. |
| 54 | class ExtendedRCEncoderContext : public renderControl_encoder_context_t { |
| 55 | public: |
| 56 | ExtendedRCEncoderContext(IOStream *stream, ChecksumCalculator *checksumCalculator) |
| 57 | : renderControl_encoder_context_t(stream, checksumCalculator) { } |
| 58 | void setSyncImpl(SyncImpl syncImpl) { m_syncImpl = syncImpl; } |
| 59 | bool hasNativeSync() const { return m_syncImpl == SYNC_IMPL_NATIVE_SYNC; } |
| 60 | private: |
| 61 | SyncImpl m_syncImpl; |
| 62 | }; |
| 63 | |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 64 | class HostConnection |
| 65 | { |
| 66 | public: |
| 67 | static HostConnection *get(); |
Lingfeng Yang | 200c716 | 2016-06-13 08:39:28 -0700 | [diff] [blame] | 68 | static void exit(); |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 69 | ~HostConnection(); |
| 70 | |
| 71 | GLEncoder *glEncoder(); |
| 72 | GL2Encoder *gl2Encoder(); |
Lingfeng Yang | 4f12b8d | 2016-07-13 16:26:10 -0700 | [diff] [blame] | 73 | ExtendedRCEncoderContext *rcEncoder(); |
Yahan Zhou | b7f0908 | 2016-03-10 11:45:02 -0800 | [diff] [blame] | 74 | ChecksumCalculator *checksumHelper() { return &m_checksumHelper; } |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 75 | |
| 76 | void flush() { |
| 77 | if (m_stream) { |
| 78 | m_stream->flush(); |
| 79 | } |
| 80 | } |
| 81 | |
Lingfeng Yang | 200c716 | 2016-06-13 08:39:28 -0700 | [diff] [blame] | 82 | void setGrallocOnly(bool gralloc_only) { |
| 83 | m_grallocOnly = gralloc_only; |
| 84 | } |
| 85 | |
| 86 | bool isGrallocOnly() const { return m_grallocOnly; } |
| 87 | |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 88 | private: |
| 89 | HostConnection(); |
| 90 | static gl_client_context_t *s_getGLContext(); |
| 91 | static gl2_client_context_t *s_getGL2Context(); |
Lingfeng Yang | 1883535 | 2016-05-23 12:16:04 -0700 | [diff] [blame] | 92 | |
Lingfeng Yang | 4f12b8d | 2016-07-13 16:26:10 -0700 | [diff] [blame] | 93 | std::string queryGLExtensions(ExtendedRCEncoderContext *rcEnc); |
Yahan Zhou | b7f0908 | 2016-03-10 11:45:02 -0800 | [diff] [blame] | 94 | // setProtocol initilizes GL communication protocol for checksums |
| 95 | // should be called when m_rcEnc is created |
Lingfeng Yang | 4f12b8d | 2016-07-13 16:26:10 -0700 | [diff] [blame] | 96 | void setChecksumHelper(ExtendedRCEncoderContext *rcEnc); |
| 97 | void queryAndSetSyncImpl(ExtendedRCEncoderContext *rcEnc); |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 98 | |
| 99 | private: |
| 100 | IOStream *m_stream; |
| 101 | GLEncoder *m_glEnc; |
| 102 | GL2Encoder *m_gl2Enc; |
Lingfeng Yang | 4f12b8d | 2016-07-13 16:26:10 -0700 | [diff] [blame] | 103 | ExtendedRCEncoderContext *m_rcEnc; |
Yahan Zhou | b7f0908 | 2016-03-10 11:45:02 -0800 | [diff] [blame] | 104 | ChecksumCalculator m_checksumHelper; |
Lingfeng Yang | 4f12b8d | 2016-07-13 16:26:10 -0700 | [diff] [blame] | 105 | std::string m_glExtensions; |
Lingfeng Yang | 200c716 | 2016-06-13 08:39:28 -0700 | [diff] [blame] | 106 | bool m_grallocOnly; |
keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 107 | }; |
| 108 | |
| 109 | #endif |