2 * Copyright (C) 2016 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.
17 #include "renderControl_enc.h"
19 #include <cutils/log.h>
21 #if PLATFORM_SDK_VERSION > 24
22 #include <system/qemu_pipe.h>
23 #else // PLATFORM_SDK_VERSION
24 #include <hardware/qemu_pipe.h>
25 #endif //PLATFORM_SDK_VERSION
27 static int sProcPipe = 0;
28 static pthread_once_t sProcPipeOnce = PTHREAD_ONCE_INIT;
29 // sProcUID is a unique ID per process assigned by the host.
30 // It is different from getpid().
31 static uint64_t sProcUID = 0;
33 // processPipeInitOnce is used to generate a process unique ID (puid).
34 // processPipeInitOnce will only be called at most once per process.
35 // Use it with pthread_once for thread safety.
36 // The host associates resources with process unique ID (puid) for memory cleanup.
37 // It will fallback to the default path if the host does not support it.
38 // Processes are identified by acquiring a per-process 64bit unique ID from the
40 static void processPipeInitOnce() {
41 sProcPipe = qemu_pipe_open("GLProcessPipe");
44 ALOGW("Process pipe failed");
47 // Send a confirmation int to the host
48 int32_t confirmInt = 100;
51 stat = ::write(sProcPipe, (const char*)&confirmInt,
53 } while (stat < 0 && errno == EINTR);
55 if (stat != sizeof(confirmInt)) { // failed
58 ALOGW("Process pipe failed");
62 // Ask the host for per-process unique ID
64 stat = ::read(sProcPipe, (char*)&sProcUID,
66 } while (stat < 0 && errno == EINTR);
68 if (stat != sizeof(sProcUID)) {
72 ALOGW("Process pipe failed");
77 bool processPipeInit(renderControl_encoder_context_t *rcEnc) {
78 pthread_once(&sProcPipeOnce, processPipeInitOnce);
79 if (!sProcPipe) return false;
80 rcEnc->rcSetPuid(rcEnc, sProcUID);