Add libqemupipe.ranchu and libgralloc_cb.ranchu

Bug: 154151802
Test: presubmit
Signed-off-by: Roman Kiryanov <[email protected]>
Change-Id: I915fcb68e1efe8829635d66730dea4c908ad222b
diff --git a/shared/OpenglCodecCommon/goldfish_dma.cpp b/shared/OpenglCodecCommon/goldfish_dma.cpp
index dbb1f8d..4423f51 100644
--- a/shared/OpenglCodecCommon/goldfish_dma.cpp
+++ b/shared/OpenglCodecCommon/goldfish_dma.cpp
@@ -13,7 +13,9 @@
  */
 
 #include "goldfish_dma.h"
-#include "qemu_pipe.h"
+
+#define ALLOW_DEPRECATED_QEMU_PIPE_HEADERS
+#include <qemu_pipe.h>
 
 #if PLATFORM_SDK_VERSION < 26
 #include <cutils/log.h>
diff --git a/shared/OpenglCodecCommon/gralloc_cb.h b/shared/OpenglCodecCommon/gralloc_cb.h
index 26d6026..5d11882 100644
--- a/shared/OpenglCodecCommon/gralloc_cb.h
+++ b/shared/OpenglCodecCommon/gralloc_cb.h
@@ -14,6 +14,10 @@
 * limitations under the License.
 */
 
+#if !(defined(HOST_BUILD) || defined(ALLOW_DEPRECATED_QEMU_PIPE_HEADERS))
+#error include <gralloc_cb_bp.h> instead from libgralloc_cb.ranchu
+#endif
+
 #ifndef __GRALLOC_CB_H__
 #define __GRALLOC_CB_H__
 
diff --git a/shared/OpenglCodecCommon/qemu_pipe.h b/shared/OpenglCodecCommon/qemu_pipe.h
index b323a43..87014f1 100644
--- a/shared/OpenglCodecCommon/qemu_pipe.h
+++ b/shared/OpenglCodecCommon/qemu_pipe.h
@@ -13,6 +13,11 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
+#if !(defined(HOST_BUILD) || defined(ALLOW_DEPRECATED_QEMU_PIPE_HEADERS))
+#error include <qemu_pipe_bp.h> instead from libqemupipe.ranchu
+#endif
+
 #ifndef ANDROID_INCLUDE_HARDWARE_QEMU_PIPE_H
 #define ANDROID_INCLUDE_HARDWARE_QEMU_PIPE_H
 
diff --git a/shared/gralloc_cb/Android.bp b/shared/gralloc_cb/Android.bp
new file mode 100644
index 0000000..faea798
--- /dev/null
+++ b/shared/gralloc_cb/Android.bp
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+cc_library_headers {
+    name: "libgralloc_cb.ranchu",
+    vendor_available: true,
+    export_include_dirs: ["include"],
+    header_libs: [
+        "libcutils_headers",
+        "libqemupipe-types.ranchu",
+    ],
+    export_header_lib_headers: [
+        "libcutils_headers",
+        "libqemupipe-types.ranchu"
+    ],
+}
diff --git a/shared/gralloc_cb/include/gralloc_cb_bp.h b/shared/gralloc_cb/include/gralloc_cb_bp.h
new file mode 100644
index 0000000..259ed85
--- /dev/null
+++ b/shared/gralloc_cb/include/gralloc_cb_bp.h
@@ -0,0 +1,128 @@
+/*
+* Copyright 2011 The Android Open Source Project
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#ifndef __GRALLOC_CB_H__
+#define __GRALLOC_CB_H__
+
+#include <cutils/native_handle.h>
+#include <qemu_pipe_types_bp.h>
+
+const uint32_t CB_HANDLE_MAGIC_MASK = 0xFFFFFFF0;
+const uint32_t CB_HANDLE_MAGIC_BASE = 0xABFABFA0;
+
+#define CB_HANDLE_NUM_INTS(nfd) \
+    ((sizeof(*this)-sizeof(native_handle_t)-nfd*sizeof(int32_t))/sizeof(int32_t))
+
+struct cb_handle_t : public native_handle_t {
+    cb_handle_t(int32_t p_bufferFd,
+                QEMU_PIPE_HANDLE p_hostHandleRefCountFd,
+                uint32_t p_magic,
+                uint32_t p_hostHandle,
+                int32_t p_usage,
+                int32_t p_width,
+                int32_t p_height,
+                int32_t p_format,
+                int32_t p_glFormat,
+                int32_t p_glType,
+                uint32_t p_bufSize,
+                void* p_bufPtr,
+                uint64_t p_mmapedOffset)
+        : bufferFd(p_bufferFd),
+          hostHandleRefCountFd(p_hostHandleRefCountFd),
+          magic(p_magic),
+          hostHandle(p_hostHandle),
+          usage(p_usage),
+          width(p_width),
+          height(p_height),
+          format(p_format),
+          glFormat(p_glFormat),
+          glType(p_glType),
+          bufferSize(p_bufSize),
+          mmapedOffsetLo(static_cast<uint32_t>(p_mmapedOffset)),
+          mmapedOffsetHi(static_cast<uint32_t>(p_mmapedOffset >> 32)),
+          lockedLeft(0),
+          lockedTop(0),
+          lockedWidth(0),
+          lockedHeight(0) {
+        version = sizeof(native_handle);
+        numFds = ((bufferFd >= 0) ? 1 : 0) + (qemu_pipe_valid(hostHandleRefCountFd) ? 1 : 0);
+        numInts = 0; // has to be overwritten in children classes
+        setBufferPtr(p_bufPtr);
+    }
+
+    void* getBufferPtr() const {
+        const uint64_t addr = (uint64_t(bufferPtrHi) << 32) | bufferPtrLo;
+        return reinterpret_cast<void*>(static_cast<uintptr_t>(addr));
+    }
+
+    void setBufferPtr(void* ptr) {
+        const uint64_t addr = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(ptr));
+        bufferPtrLo = uint32_t(addr);
+        bufferPtrHi = uint32_t(addr >> 32);
+    }
+
+    uint64_t getMmapedOffset() const {
+        return (uint64_t(mmapedOffsetHi) << 32) | mmapedOffsetLo;
+    }
+
+    uint32_t allocatedSize() const {
+        return getBufferPtr() ? bufferSize : 0;
+    }
+
+    bool isValid() const {
+        return (version == sizeof(native_handle))
+               && (magic & CB_HANDLE_MAGIC_MASK) == CB_HANDLE_MAGIC_BASE;
+    }
+
+    static cb_handle_t* from(void* p) {
+        if (!p) { return NULL; }
+        cb_handle_t* cb = static_cast<cb_handle_t*>(p);
+        return cb->isValid() ? cb : NULL;
+    }
+
+    static const cb_handle_t* from(const void* p) {
+        return from(const_cast<void*>(p));
+    }
+
+    static cb_handle_t* from_unconst(const void* p) {
+        return from(const_cast<void*>(p));
+    }
+
+    // fds
+    int32_t bufferFd;       // underlying buffer file handle
+    QEMU_PIPE_HANDLE hostHandleRefCountFd; // guest side refcounter to hostHandle
+
+    // ints
+    uint32_t magic;         // magic number in order to validate a pointer
+    uint32_t hostHandle;    // the host reference to this buffer
+    int32_t  usage;         // usage bits the buffer was created with
+    int32_t  width;         // buffer width
+    int32_t  height;        // buffer height
+    int32_t  format;        // real internal pixel format format
+    int32_t  glFormat;      // OpenGL format enum used for host h/w color buffer
+    int32_t  glType;        // OpenGL type enum used when uploading to host
+    uint32_t bufferSize;    // buffer size and location
+    uint32_t bufferPtrLo;
+    uint32_t bufferPtrHi;
+    uint32_t mmapedOffsetLo;
+    uint32_t mmapedOffsetHi;
+    int32_t  lockedLeft;    // region of buffer locked for s/w write
+    int32_t  lockedTop;
+    int32_t  lockedWidth;
+    int32_t  lockedHeight;
+};
+
+#endif //__GRALLOC_CB_H__
diff --git a/shared/qemupipe/Android.bp b/shared/qemupipe/Android.bp
new file mode 100644
index 0000000..ba8de3b
--- /dev/null
+++ b/shared/qemupipe/Android.bp
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+cc_library_headers {
+    name: "libqemupipe-types.ranchu",
+    vendor_available: true,
+    export_include_dirs: ["include-types"],
+}
+
+cc_library {
+    name: "libqemupipe.ranchu",
+    vendor_available: true,
+    srcs: ["qemu_pipe.cpp"],
+    header_libs: ["libqemupipe-types.ranchu"],
+    export_header_lib_headers: ["libqemupipe-types.ranchu"],
+    shared_libs: ["liblog"],
+    export_include_dirs: ["include"],
+}
diff --git a/shared/qemupipe/include-types/qemu_pipe_types_bp.h b/shared/qemupipe/include-types/qemu_pipe_types_bp.h
new file mode 100644
index 0000000..d786fe5
--- /dev/null
+++ b/shared/qemupipe/include-types/qemu_pipe_types_bp.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+#include <stddef.h>
+#include <stdbool.h>
+
+#ifdef HOST_BUILD
+
+typedef void* QEMU_PIPE_HANDLE;
+#define QEMU_PIPE_INVALID_HANDLE NULL
+
+inline bool qemu_pipe_valid(QEMU_PIPE_HANDLE h) {
+    return h != QEMU_PIPE_INVALID_HANDLE;
+}
+
+#else  // ifdef HOST_BUILD
+
+typedef int QEMU_PIPE_HANDLE;
+#define QEMU_PIPE_INVALID_HANDLE (-1)
+
+inline bool qemu_pipe_valid(QEMU_PIPE_HANDLE h) {
+    return h > QEMU_PIPE_INVALID_HANDLE;
+}
+
+#endif // ifdef HOST_BUILD
diff --git a/shared/qemupipe/include/qemu_pipe_bp.h b/shared/qemupipe/include/qemu_pipe_bp.h
new file mode 100644
index 0000000..4338ee5
--- /dev/null
+++ b/shared/qemupipe/include/qemu_pipe_bp.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+#include <qemu_pipe_types_bp.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+QEMU_PIPE_HANDLE qemu_pipe_open_ns(const char* ns, const char* pipeName, int flags);
+QEMU_PIPE_HANDLE qemu_pipe_open(const char* pipeName);
+void qemu_pipe_close(QEMU_PIPE_HANDLE pipe);
+
+int qemu_pipe_read_fully(QEMU_PIPE_HANDLE pipe, void* buffer, int size);
+int qemu_pipe_write_fully(QEMU_PIPE_HANDLE pipe, const void* buffer, int size);
+int qemu_pipe_read(QEMU_PIPE_HANDLE pipe, void* buffer, int size);
+int qemu_pipe_write(QEMU_PIPE_HANDLE pipe, const void* buffer, int size);
+
+int qemu_pipe_try_again(int ret);
+void qemu_pipe_print_error(QEMU_PIPE_HANDLE pipe);
+
+#ifdef __cplusplus
+}  // extern "C"
+#endif
+
+#define QEMU_PIPE_RETRY(exp) ({ \
+    __typeof__(exp) _rc; \
+    do { \
+        _rc = (exp); \
+    } while (qemu_pipe_try_again(_rc)); \
+    _rc; })
diff --git a/shared/qemupipe/qemu_pipe.cpp b/shared/qemupipe/qemu_pipe.cpp
new file mode 100644
index 0000000..6a07796
--- /dev/null
+++ b/shared/qemupipe/qemu_pipe.cpp
@@ -0,0 +1,121 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <errno.h>
+#include <log/log.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <qemu_pipe_bp.h>
+
+namespace {
+int open_verbose(const char* name, int flags) {
+    const int fd = QEMU_PIPE_RETRY(open(name, flags));
+    if (fd < 0) {
+        ALOGE("%s:%d: Could not open '%s': %s",
+              __func__, __LINE__, name, strerror(errno));
+    }
+    return fd;
+}
+
+}  // namespace
+
+extern "C" {
+
+int qemu_pipe_open_ns(const char* ns, const char* pipeName, int flags) {
+    if (pipeName == NULL || pipeName[0] == '\0') {
+        errno = EINVAL;
+        return -1;
+    }
+
+    const int fd = open_verbose("/dev/goldfish_pipe", flags);
+    if (fd < 0) {
+        return fd;
+    }
+
+    char buf[256];
+    int bufLen;
+    if (ns) {
+        bufLen = snprintf(buf, sizeof(buf), "pipe:%s:%s", ns, pipeName);
+    } else {
+        bufLen = snprintf(buf, sizeof(buf), "pipe:%s", pipeName);
+    }
+
+    if (qemu_pipe_write_fully(fd, buf, bufLen + 1)) {
+        ALOGE("%s:%d: Could not connect to the '%s' service: %s",
+              __func__, __LINE__, buf, strerror(errno));
+        return -1;
+    }
+
+    return fd;
+}
+
+int qemu_pipe_open(const char* pipeName) {
+    return qemu_pipe_open_ns(NULL, pipeName, O_RDWR | O_NONBLOCK);
+}
+
+void qemu_pipe_close(int pipe) {
+    close(pipe);
+}
+
+int qemu_pipe_read_fully(int pipe, void* buffer, int size) {
+    char* p = (char*)buffer;
+
+    while (size > 0) {
+      int n = QEMU_PIPE_RETRY(qemu_pipe_read(pipe, p, size));
+      if (n < 0) return n;
+
+      p += n;
+      size -= n;
+    }
+
+    return 0;
+}
+
+int qemu_pipe_write_fully(int pipe, const void* buffer, int size) {
+    const char* p = (const char*)buffer;
+
+    while (size > 0) {
+      int n = QEMU_PIPE_RETRY(qemu_pipe_write(pipe, p, size));
+      if (n < 0) return n;
+
+      p += n;
+      size -= n;
+    }
+
+    return 0;
+}
+
+int qemu_pipe_read(int pipe, void* buffer, int size) {
+    return read(pipe, buffer, size);
+}
+
+int qemu_pipe_write(int pipe, const void* buffer, int size) {
+    return write(pipe, buffer, size);
+}
+
+int qemu_pipe_try_again(int ret) {
+    return (ret < 0) && (errno == EINTR || errno == EAGAIN);
+}
+
+void qemu_pipe_print_error(int pipe) {
+    ALOGE("pipe error: fd %d errno %d", pipe, errno);
+}
+
+}  // extern "C"
diff --git a/system/OpenglSystemCommon/ProcessPipe.cpp b/system/OpenglSystemCommon/ProcessPipe.cpp
index 40cb298..56f1e52 100644
--- a/system/OpenglSystemCommon/ProcessPipe.cpp
+++ b/system/OpenglSystemCommon/ProcessPipe.cpp
@@ -16,7 +16,9 @@
 
 #include "ProcessPipe.h"
 #include "renderControl_enc.h"
-#include "qemu_pipe.h"
+
+#define ALLOW_DEPRECATED_QEMU_PIPE_HEADERS
+#include <qemu_pipe.h>
 
 #if PLATFORM_SDK_VERSION < 26
 #include <cutils/log.h>
diff --git a/system/OpenglSystemCommon/QemuPipeStream.cpp b/system/OpenglSystemCommon/QemuPipeStream.cpp
index e71821f..254ebd2 100644
--- a/system/OpenglSystemCommon/QemuPipeStream.cpp
+++ b/system/OpenglSystemCommon/QemuPipeStream.cpp
@@ -14,6 +14,7 @@
 * limitations under the License.
 */
 #include "QemuPipeStream.h"
+#include <qemu_pipe.h>
 
 #if PLATFORM_SDK_VERSION < 26
 #include <cutils/log.h>
diff --git a/system/OpenglSystemCommon/QemuPipeStream.h b/system/OpenglSystemCommon/QemuPipeStream.h
index 87638af..9ca4459 100644
--- a/system/OpenglSystemCommon/QemuPipeStream.h
+++ b/system/OpenglSystemCommon/QemuPipeStream.h
@@ -23,7 +23,8 @@
 #include <stdlib.h>
 #include "IOStream.h"
 
-#include "qemu_pipe.h"
+#define ALLOW_DEPRECATED_QEMU_PIPE_HEADERS
+#include <qemu_pipe.h>
 
 #ifdef __Fuchsia__
 #include <fuchsia/hardware/goldfish/cpp/fidl.h>
diff --git a/system/codecs/omx/avcdec/Android.mk b/system/codecs/omx/avcdec/Android.mk
index 798255f..4ab6db3 100644
--- a/system/codecs/omx/avcdec/Android.mk
+++ b/system/codecs/omx/avcdec/Android.mk
@@ -49,6 +49,8 @@
 		[email protected] \
         libstagefright_foundation
 
+LOCAL_HEADER_LIBRARIES += libgralloc_cb.ranchu
+
 $(call emugl-export,C_INCLUDES,$(LOCAL_PATH))
 $(call emugl-import,libgoldfish_codecs_common)
 $(call emugl-import,libstagefrighthw)
diff --git a/system/codecs/omx/avcdec/GoldfishAVCDec.h b/system/codecs/omx/avcdec/GoldfishAVCDec.h
index dc9dc96..0fd52b0 100644
--- a/system/codecs/omx/avcdec/GoldfishAVCDec.h
+++ b/system/codecs/omx/avcdec/GoldfishAVCDec.h
@@ -25,7 +25,7 @@
 #include <vector>
 #include <map>
 
-#include "gralloc_cb.h"
+#include <gralloc_cb_bp.h>
 #include <utils/RefBase.h>
 #include <utils/threads.h>
 #include <utils/Vector.h>
diff --git a/system/codecs/omx/plugin/Android.mk b/system/codecs/omx/plugin/Android.mk
index 77a2091..4adfd8a 100644
--- a/system/codecs/omx/plugin/Android.mk
+++ b/system/codecs/omx/plugin/Android.mk
@@ -35,15 +35,13 @@
 $(call emugl-export,SHARED_LIBRARIES,libcutils libutils liblog)
 $(call emugl-export,C_INCLUDES,$(LOCAL_PATH))
 
-
-
-LOCAL_HEADER_LIBRARIES := media_plugin_headers \
+LOCAL_HEADER_LIBRARIES += media_plugin_headers \
 	                      libmedia_headers \
 	                      libbinder_headers \
 	                      libhidlbase_impl_internal \
 	                      libbase
 
-LOCAL_SHARED_LIBRARIES :=       \
+LOCAL_SHARED_LIBRARIES +=       \
         libbinder               \
         libutils                \
         liblog                  \
diff --git a/system/codecs/omx/vpxdec/Android.mk b/system/codecs/omx/vpxdec/Android.mk
index ce2ab89..e7ec2d4 100644
--- a/system/codecs/omx/vpxdec/Android.mk
+++ b/system/codecs/omx/vpxdec/Android.mk
@@ -40,7 +40,9 @@
                           libarect_headers \
                           libarect_headers_for_ndk
 
-LOCAL_SHARED_LIBRARIES :=       \
+LOCAL_HEADER_LIBRARIES += libgralloc_cb.ranchu
+
+LOCAL_SHARED_LIBRARIES +=       \
         libbinder               \
         libutils                \
         liblog                  \
diff --git a/system/codecs/omx/vpxdec/GoldfishVPX.h b/system/codecs/omx/vpxdec/GoldfishVPX.h
index 2eb762c..cb9321f 100644
--- a/system/codecs/omx/vpxdec/GoldfishVPX.h
+++ b/system/codecs/omx/vpxdec/GoldfishVPX.h
@@ -31,7 +31,7 @@
 #include <utils/RefBase.h>
 #include <utils/Vector.h>
 #include <utils/threads.h>
-#include "gralloc_cb.h"
+#include <gralloc_cb_bp.h>
 
 namespace android {
 
diff --git a/system/egl/egl.cpp b/system/egl/egl.cpp
index aaa763a..17506cd 100644
--- a/system/egl/egl.cpp
+++ b/system/egl/egl.cpp
@@ -33,7 +33,9 @@
 #include "ClientAPIExts.h"
 #include "EGLImage.h"
 #include "ProcessPipe.h"
-#include "qemu_pipe.h"
+
+#define ALLOW_DEPRECATED_QEMU_PIPE_HEADERS
+#include <qemu_pipe.h>
 
 #include "GLEncoder.h"
 #ifdef WITH_GLES2
diff --git a/system/hals/Android.mk b/system/hals/Android.mk
index b762a78..3b90bf0 100644
--- a/system/hals/Android.mk
+++ b/system/hals/Android.mk
@@ -34,6 +34,9 @@
     liblog \
     libutils
 
+LOCAL_STATIC_LIBRARIES += libqemupipe.ranchu
+LOCAL_HEADER_LIBRARIES += libgralloc_cb.ranchu
+
 LOCAL_C_INCLUDES += \
     device/generic/goldfish-opengl/system/include \
     device/generic/goldfish-opengl/system/OpenglSystemCommon \
@@ -63,6 +66,9 @@
     libutils \
     libsync
 
+LOCAL_STATIC_LIBRARIES += libqemupipe.ranchu
+LOCAL_HEADER_LIBRARIES += libgralloc_cb.ranchu
+
 LOCAL_C_INCLUDES += \
     device/generic/goldfish-opengl/system/include \
     device/generic/goldfish-opengl/system/OpenglSystemCommon \
diff --git a/system/hals/allocator3.cpp b/system/hals/allocator3.cpp
index 2e5c23e..8b433c2 100644
--- a/system/hals/allocator3.cpp
+++ b/system/hals/allocator3.cpp
@@ -17,6 +17,7 @@
 #include <android/hardware/graphics/allocator/3.0/IAllocator.h>
 #include <android/hardware/graphics/mapper/3.0/IMapper.h>
 #include <hidl/LegacySupport.h>
+#include <qemu_pipe_bp.h>
 
 #include "glUtils.h"
 #include "cb_handle_30.h"
diff --git a/system/hals/cb_handle_30.h b/system/hals/cb_handle_30.h
index 11ce322..374008e 100644
--- a/system/hals/cb_handle_30.h
+++ b/system/hals/cb_handle_30.h
@@ -17,7 +17,7 @@
 #ifndef SYSTEM_HALS_CB_HANDLE_30_H
 #define SYSTEM_HALS_CB_HANDLE_30_H
 
-#include "gralloc_cb.h"
+#include <gralloc_cb_bp.h>
 #include "goldfish_address_space.h"
 
 const uint32_t CB_HANDLE_MAGIC_30 = CB_HANDLE_MAGIC_BASE | 0x2;