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.
18 #include "ServerConnection.h"
19 #include "TcpStream.h"
20 #include "QemuPipeStream.h"
21 #include <cutils/log.h>
22 #include "ThreadInfo.h"
24 gl_client_context_t *ServerConnection::s_getGlContext()
26 EGLThreadInfo *ti = getEGLThreadInfo();
28 return ti->serverConn->m_glEnc;
33 gl2_client_context_t *ServerConnection::s_getGl2Context()
35 EGLThreadInfo *ti = getEGLThreadInfo();
37 return ti->serverConn->m_gl2Enc;
42 ServerConnection *ServerConnection::s_getServerConnection()
44 EGLThreadInfo *ti = getEGLThreadInfo();
47 ti->serverConn = new ServerConnection();
48 if (ti->serverConn->create() < 0) {
49 delete ti->serverConn;
50 ti->serverConn = NULL;
54 return ti->serverConn;
58 ServerConnection::ServerConnection() :
65 ServerConnection::~ServerConnection()
74 int ServerConnection::create(size_t bufsize,
75 const char *defaultServer)
77 /* XXX: Make configurable through system property */
80 if (m_stream != NULL) delete(m_stream);
83 QemuPipeStream* pipeStream = new QemuPipeStream(bufsize);
85 if (pipeStream->connect() < 0) {
86 ALOGE("couldn't connect to host server\n");
90 m_stream = pipeStream;
92 else /* !useQemuPipe */
94 TcpStream* tcpStream = new TcpStream(bufsize);
96 char *s = getenv(ENV_RGL_SERVER);
99 hostname = strdup(defaultServer);
101 hostname = strdup(s);
104 if (tcpStream->connect(hostname, CODEC_SERVER_PORT) < 0) {
105 ALOGE("couldn't connect to %s\n", hostname);
110 LOGI("connecting to server %s\n", hostname);
113 m_stream = tcpStream;
116 m_glEnc = new GLEncoder(m_stream);
117 m_glEnc->setContextAccessor(s_getGlContext);
119 m_gl2Enc = new GL2Encoder(m_stream);
120 m_gl2Enc->setContextAccessor(s_getGl2Context);
122 m_ut_enc = new ut_rendercontrol_encoder_context_t(m_stream);