Delete guest/hals/gralloc but not /legacy

Credit to natsu@ for pointing out that /legacy is still needed.

Bug: 144111429
Test: Run with -vm_manager=qemu_cli
Change-Id: Ic5e3b4bd50b65da3f989902476a735604f98148c
diff --git a/guest/hals/gralloc/Android.mk b/guest/hals/gralloc/Android.mk
deleted file mode 100644
index 68ffffa..0000000
--- a/guest/hals/gralloc/Android.mk
+++ /dev/null
@@ -1,63 +0,0 @@
-# Copyright (C) 2017 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.
-
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := gralloc.cutf_ivsh-future
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_SRC_FILES := \
-    gralloc.cpp \
-    mapper.cpp
-
-LOCAL_C_INCLUDES += \
-    device/google/cuttlefish_common \
-    device/google/cuttlefish_kernel \
-    hardware/libhardware/include \
-    system/core/base/include
-
-LOCAL_CFLAGS := \
-    -DLOG_TAG=\"gralloc_vsoc\" \
-    -Wno-missing-field-initializers \
-    -Wall -Werror \
-    $(VSOC_VERSION_CFLAGS)
-
-LOCAL_SHARED_LIBRARIES := \
-    libbase \
-    libcutils \
-    cuttlefish_auto_resources \
-    libcuttlefish_fs \
-    liblog \
-    vsoc_lib
-
-LOCAL_HEADER_LIBRARIES := \
-    libhardware_headers
-
-ifeq (0, $(shell test $(PLATFORM_SDK_VERSION) -ge 21; echo $$?))
-LOCAL_MODULE_RELATIVE_PATH := hw
-else
-LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
-endif
-
-LOCAL_VENDOR_MODULE := true
-
-# See b/67109557
-ifeq (true, $(TARGET_TRANSLATE_2ND_ARCH))
-LOCAL_MULTILIB := first
-endif
-include $(BUILD_SHARED_LIBRARY)
-
-include $(call first-makefiles-under,$(LOCAL_PATH))
diff --git a/guest/hals/gralloc/gralloc.cpp b/guest/hals/gralloc/gralloc.cpp
deleted file mode 100644
index d21d918..0000000
--- a/guest/hals/gralloc/gralloc.cpp
+++ /dev/null
@@ -1,320 +0,0 @@
-/*
- * Copyright (C) 2017 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 <hardware/gralloc.h>
-#include <hardware/hardware.h>
-#include <log/log.h>
-#include <stdlib.h>
-
-#include "guest/hals/gralloc/gralloc_vsoc_priv.h"
-#include "guest/vsoc/lib/gralloc_region_view.h"
-
-using vsoc::gralloc::GrallocRegionView;
-
-namespace {
-
-static const int kSwiftShaderPadding = 4;
-
-inline void formatToYcbcr(
-    int format, int width, int height, void* base_v, android_ycbcr* ycbcr) {
-  uintptr_t it = reinterpret_cast<uintptr_t>(base_v);
-  // Clear reserved fields;
-  memset(ycbcr, 0, sizeof(*ycbcr));
-  switch (format) {
-    case HAL_PIXEL_FORMAT_YV12:
-    case HAL_PIXEL_FORMAT_YCbCr_420_888:
-      ycbcr->ystride = align(width, 16);
-      ycbcr->cstride = align(ycbcr->ystride / 2, 16);
-      ycbcr->chroma_step = 1;
-      ycbcr->y = reinterpret_cast<void*>(it);
-      it += ycbcr->ystride * height;
-      ycbcr->cr = reinterpret_cast<void*>(it);
-      it += ycbcr->cstride * height / 2;
-      ycbcr->cb = reinterpret_cast<void*>(it);
-      break;
-    default:
-      ALOGE("%s: can't deal with format=0x%x", __FUNCTION__, format);
-  }
-}
-
-inline int formatToBytesPerPixel(int format) {
-  switch (format) {
-    case HAL_PIXEL_FORMAT_RGBA_FP16:
-      return 8;
-    case HAL_PIXEL_FORMAT_RGBA_8888:
-    case HAL_PIXEL_FORMAT_RGBX_8888:
-    case HAL_PIXEL_FORMAT_BGRA_8888:
-    // The camera 3.0 implementation assumes that IMPLEMENTATION_DEFINED
-    // means HAL_PIXEL_FORMAT_RGBA_8888
-    case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
-      return 4;
-    case HAL_PIXEL_FORMAT_RGB_888:
-      return 3;
-    case HAL_PIXEL_FORMAT_RGB_565:
-    case HAL_PIXEL_FORMAT_YV12:
-    case HAL_PIXEL_FORMAT_YCbCr_420_888:
-      return 2;
-    case HAL_PIXEL_FORMAT_BLOB:
-      return 1;
-    default:
-      ALOGE("%s: unknown format=%d", __FUNCTION__, format);
-      return 8;
-  }
-}
-
-inline int formatToBytesPerFrame(int format, int w, int h) {
-  int bytes_per_pixel = formatToBytesPerPixel(format);
-  int w16, h16;
-  int y_size, c_size;
-
-  switch (format) {
-    // BLOB is used to allocate buffers for JPEG formatted data. Bytes per pixel
-    // is 1, the desired buffer size is in w, and h should be 1. We refrain from
-    // adding additional padding, although the caller is likely to round
-    // up to a page size.
-    case HAL_PIXEL_FORMAT_BLOB:
-      return bytes_per_pixel * w * h;
-    case HAL_PIXEL_FORMAT_YV12:
-    case HAL_PIXEL_FORMAT_YCbCr_420_888:
-      android_ycbcr strides;
-      formatToYcbcr(format, w, h, NULL, &strides);
-      y_size = strides.ystride * h;
-      c_size = strides.cstride * h / 2;
-      return (y_size + 2 * c_size + kSwiftShaderPadding);
-    /*case HAL_PIXEL_FORMAT_RGBA_8888:
-    case HAL_PIXEL_FORMAT_RGBX_8888:
-    case HAL_PIXEL_FORMAT_BGRA_8888:
-    case HAL_PIXEL_FORMAT_RGB_888:
-    case HAL_PIXEL_FORMAT_RGB_565:*/
-    default:
-      w16 = align(w, 16);
-      h16 = align(h, 16);
-      return bytes_per_pixel * w16 * h16 + kSwiftShaderPadding;
-  }
-}
-
-}
-
-/******************************************************************************/
-
-void dump(struct alloc_device_t */*dev*/, char */*buff*/, int /*buff_len*/) {}
-
-/******************************************************************************/
-
-int lock(struct gralloc_module_t const* /*module*/,
-         buffer_handle_t handle,
-         int /*usage*/,
-         int /*l*/,
-         int /*t*/,
-         int /*w*/,
-         int /*h*/,
-         void** vaddr) {
-  if (!vaddr || vsoc_buffer_handle_t::validate(handle)) {
-    return -EINVAL;
-  }
-  // TODO(jemoreira): Check allocation usage flags against requested usage.
-  const vsoc_buffer_handle_t* hnd =
-      reinterpret_cast<const vsoc_buffer_handle_t*>(handle);
-  void* mapped = reference_buffer(hnd);
-  if (mapped == NULL) {
-    ALOGE("Unable to reference buffer, %s", __FUNCTION__);
-    return -1;
-  }
-  *vaddr = mapped;
-  return 0;
-}
-
-int unlock(struct gralloc_module_t const* /*module*/, buffer_handle_t handle) {
-  if (vsoc_buffer_handle_t::validate(handle)) {
-    return -EINVAL;
-  }
-  return unreference_buffer(
-      reinterpret_cast<const vsoc_buffer_handle_t*>(handle));
-}
-
-int lock_ycbcr(struct gralloc_module_t const* module,
-               buffer_handle_t handle,
-               int usage,
-               int l,
-               int t,
-               int w,
-               int h,
-               struct android_ycbcr* ycbcr) {
-  void* mapped;
-  int retval = lock(module, handle, usage, l, t, w, h, &mapped);
-  if (retval) {
-    return retval;
-  }
-  const vsoc_buffer_handle_t* hnd =
-      reinterpret_cast<const vsoc_buffer_handle_t*>(handle);
-  formatToYcbcr(hnd->format, w, h, mapped, ycbcr);
-  return 0;
-}
-
-/******************************************************************************/
-
-static int gralloc_alloc(alloc_device_t* /*dev*/,
-                         int w,
-                         int h,
-                         int format,
-                         int /*usage*/,
-                         buffer_handle_t* pHandle,
-                         int* pStrideInPixels) {
-  int fd = -1;
-
-  int bytes_per_pixel = formatToBytesPerPixel(format);
-  int bytes_per_line;
-  int stride_in_pixels;
-  int size = 0;
-  uint32_t offset = 0;
-  // SwiftShader can't handle RGB_888, so fail fast and hard if we try to create
-  // a gralloc buffer in this format.
-  ALOG_ASSERT(format != HAL_PIXEL_FORMAT_RGB_888);
-  if (format == HAL_PIXEL_FORMAT_YV12) {
-    bytes_per_line = align(bytes_per_pixel * w, 16);
-  } else {
-    bytes_per_line = align(bytes_per_pixel * w, 8);
-  }
-  size = align(size + formatToBytesPerFrame(format, w, h), PAGE_SIZE);
-  size += PAGE_SIZE;
-  fd = GrallocRegionView::GetInstance()->AllocateBuffer(size, &offset);
-  if (fd < 0) {
-    ALOGE("Unable to allocate buffer (%s)", strerror(-fd));
-    return fd;
-  }
-
-  stride_in_pixels = bytes_per_line / bytes_per_pixel;
-  vsoc_buffer_handle_t* hnd = new vsoc_buffer_handle_t(fd,
-                                                       offset,
-                                                       size,
-                                                       format,
-                                                       w, h,
-                                                       stride_in_pixels);
-  void* addr =
-      reference_buffer(reinterpret_cast<const vsoc_buffer_handle_t*>(hnd));
-  if (!addr) {
-    ALOGE("Unable to reference buffer, %s", __FUNCTION__);
-    return -EIO;
-  }
-
-  *pHandle = hnd;
-  *pStrideInPixels = stride_in_pixels;
-
-  return 0;
-}
-
-static int gralloc_free(alloc_device_t* /*dev*/, buffer_handle_t handle) {
-  // No need to do anything else, the buffer will be atomatically deallocated
-  // when the handle is closed.
-  return unreference_buffer(
-      reinterpret_cast<const vsoc_buffer_handle_t*>(handle));
-}
-
-static int register_buffer(struct gralloc_module_t const* /*module*/,
-                          buffer_handle_t handle) {
-  if (vsoc_buffer_handle_t::validate(handle)) {
-    return -EINVAL;
-  }
-  void* addr =
-      reference_buffer(reinterpret_cast<const vsoc_buffer_handle_t*>(handle));
-  if (!addr) {
-    ALOGE("Unable to reference buffer, %s", __FUNCTION__);
-    return -EIO;
-  }
-  return 0;
-}
-
-int unregister_buffer(struct gralloc_module_t const* /*module*/,
-                     buffer_handle_t handle) {
-  if (vsoc_buffer_handle_t::validate(handle)) {
-    return -EINVAL;
-  }
-  return unreference_buffer(
-      reinterpret_cast<const vsoc_buffer_handle_t*>(handle));
-}
-
-/******************************************************************************/
-
-static int gralloc_device_close(struct hw_device_t *dev) {
-  vsoc_alloc_device_t* pdev = reinterpret_cast<vsoc_alloc_device_t*>(dev);
-  if (pdev) {
-    free(pdev);
-  }
-  return 0;
-}
-
-static int gralloc_device_open(
-    const hw_module_t* module, const char* name, hw_device_t** device) {
-    int status = -EINVAL;
-  if (!strcmp(name, GRALLOC_HARDWARE_GPU0)) {
-    vsoc_alloc_device_t *dev;
-    dev = (vsoc_alloc_device_t*) malloc(sizeof(*dev));
-    LOG_FATAL_IF(!dev, "%s: malloc returned NULL.", __FUNCTION__);
-
-    /* initialize our state here */
-    memset(dev, 0, sizeof(*dev));
-
-    /* initialize the procs */
-    dev->device.common.tag = HARDWARE_DEVICE_TAG;
-    dev->device.common.version = 0; // TODO(jemoreira): Bump to 0_2 when stable
-    dev->device.common.module = const_cast<hw_module_t*>(module);
-    dev->device.common.close = gralloc_device_close;
-
-    dev->device.alloc   = gralloc_alloc;
-    dev->device.free    = gralloc_free;
-
-    if (!GrallocRegionView::GetInstance()) {
-      LOG_FATAL("Unable to instantiate the gralloc region");
-      free(dev);
-      return -EIO;
-    }
-
-    *device = &dev->device.common;
-    status = 0;
-  }
-  // TODO(jemoreira): Consider opening other type of devices (framebuffer)
-  return status;
-}
-
-/******************************************************************************/
-
-static struct hw_module_methods_t gralloc_module_methods = {
-  .open = gralloc_device_open
-};
-
-struct vsoc_gralloc_module_t HAL_MODULE_INFO_SYM = {
-  .base = {
-    .common = {
-      .tag = HARDWARE_MODULE_TAG,
-      .version_major = GRALLOC_MODULE_API_VERSION_0_2,
-      .version_minor = 0,
-      .id = GRALLOC_HARDWARE_MODULE_ID,
-      .name = "VSoC X86 Graphics Memory Allocator Module",
-      .author = "The Android Open Source Project",
-      .methods = &gralloc_module_methods,
-      .dso = NULL,
-      .reserved = {0},
-    },
-    .registerBuffer = register_buffer,
-    .unregisterBuffer = unregister_buffer,
-    .lock = lock,
-    .unlock = unlock,
-    .perform = NULL,
-    .lock_ycbcr = lock_ycbcr,
-    .getTransportSize = NULL,
-    .validateBufferSize = NULL,
-  },
-};
diff --git a/guest/hals/gralloc/gralloc_vsoc_priv.h b/guest/hals/gralloc/gralloc_vsoc_priv.h
deleted file mode 100644
index 1ec5659..0000000
--- a/guest/hals/gralloc/gralloc_vsoc_priv.h
+++ /dev/null
@@ -1,100 +0,0 @@
-#pragma once
-/*
- * Copyright (C) 2017 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 <cutils/native_handle.h>
-#include <hardware/gralloc.h>
-#include <log/log.h>
-
-struct vsoc_alloc_device_t {
-  alloc_device_t device;
-};
-
-struct vsoc_gralloc_module_t {
-  gralloc_module_t base;
-};
-
-static_assert(sizeof(int) >= 4, "At least 4 bytes are needed for offsets");
-
-struct vsoc_buffer_handle_t : public native_handle {
-  // File descriptors
-  int fd;
-  // ints
-  int magic;
-  int format;
-  int x_res;
-  int y_res;
-  int stride_in_pixels;
-  int size;
-  // buffer offset in bytes divided by PAGE_SIZE
-  int offset;
-
-  static inline int sNumInts() {
-    return ((sizeof(vsoc_buffer_handle_t) - sizeof(native_handle_t)) /
-                sizeof(int) -
-            sNumFds);
-  }
-  static const int sNumFds = 1;
-  static const int sMagic = 0xc63752f4;
-
-  vsoc_buffer_handle_t(int fd,
-                       int offset,
-                       int size,
-                       int format,
-                       int x_res,
-                       int y_res,
-                       int stride_in_pixels)
-      : fd(fd),
-        magic(sMagic),
-        format(format),
-        x_res(x_res),
-        y_res(y_res),
-        stride_in_pixels(stride_in_pixels),
-        size(size),
-        offset(offset) {
-    version = sizeof(native_handle);
-    numInts = sNumInts();
-    numFds = sNumFds;
-  }
-
-  ~vsoc_buffer_handle_t() {
-    magic = 0;
-  }
-
-  static int validate(const native_handle* handle) {
-    const vsoc_buffer_handle_t* hnd =
-        reinterpret_cast<const vsoc_buffer_handle_t*>(handle);
-    if (!hnd || hnd->version != sizeof(native_handle) ||
-        hnd->numInts != sNumInts() || hnd->numFds != sNumFds ||
-        hnd->magic != sMagic) {
-      ALOGE("Invalid gralloc handle (at %p)", handle);
-      return -EINVAL;
-    }
-    return 0;
-  }
-};
-
-// These functions are to be used to map/unmap gralloc buffers. They are thread
-// safe and ensure that the same buffer never gets mapped twice.
-void* reference_buffer(const vsoc_buffer_handle_t* hnd);
-int unreference_buffer(const vsoc_buffer_handle_t* hnd);
-
-// TODO(jemoreira): Move this to a place where it can be used by the gralloc
-// region as well.
-inline int align(int input, int alignment) {
-  return (input + alignment - 1) & -alignment;
-}
diff --git a/guest/hals/gralloc/legacy/Android.mk b/guest/hals/gralloc/legacy/Android.mk
index 4bbc9c0..ac789fb 100644
--- a/guest/hals/gralloc/legacy/Android.mk
+++ b/guest/hals/gralloc/legacy/Android.mk
@@ -18,7 +18,6 @@
 
 VSOC_GRALLOC_COMMON_SRC_FILES := \
     gralloc.cpp \
-    framebuffer.cpp \
     mapper.cpp \
     region_registry.cpp
 
@@ -47,8 +46,7 @@
     libbase \
     liblog \
     libutils \
-    libcutils \
-    vsoc_lib
+    libcutils
 
 LOCAL_VENDOR_MODULE := true
 
diff --git a/guest/hals/gralloc/legacy/framebuffer.cpp b/guest/hals/gralloc/legacy/framebuffer.cpp
deleted file mode 100644
index 5a2b7f0..0000000
--- a/guest/hals/gralloc/legacy/framebuffer.cpp
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Copyright (C) 2016 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 <sys/mman.h>
-
-#include <dlfcn.h>
-
-#include <cutils/ashmem.h>
-#include <log/log.h>
-#include <cutils/properties.h>
-
-#include <sys/system_properties.h>
-
-#include <hardware/hardware.h>
-#include <hardware/gralloc.h>
-
-#include <fcntl.h>
-#include <errno.h>
-#include <sys/ioctl.h>
-#include <string.h>
-#include <stdlib.h>
-
-#include <cutils/atomic.h>
-
-#if defined(__ANDROID__)
-#include <linux/fb.h>
-#endif
-
-#include "gralloc_vsoc_priv.h"
-#include "region_registry.h"
-
-#include "common/libs/auto_resources/auto_resources.h"
-#include "common/libs/threads/cuttlefish_thread.h"
-#include "common/vsoc/lib/screen_region_view.h"
-
-using vsoc::screen::ScreenRegionView;
-
-/*****************************************************************************/
-
-struct fb_context_t {
-  framebuffer_device_t  device;
-};
-
-/*****************************************************************************/
-
-static int fb_setSwapInterval(struct framebuffer_device_t* dev, int interval) {
-  if (interval < dev->minSwapInterval || interval > dev->maxSwapInterval) {
-    return -EINVAL;
-  }
-  // FIXME: implement fb_setSwapInterval
-  return 0;
-}
-
-/*
- * These functions (and probably the entire framebuffer device) are most likely
- * not used when the hardware composer device is present, however is hard to be
- * 100% sure.
- */
-static int fb_setUpdateRect(
-    struct framebuffer_device_t* dev __unused, int l, int t, int w, int h) {
-  if (((w|h) <= 0) || ((l|t)<0)) {
-    return -EINVAL;
-  }
-  // TODO(jemoreira): Find a way to broadcast this with the framebuffer control.
-  return 0;
-}
-
-static int fb_post(struct framebuffer_device_t* dev __unused,
-                   buffer_handle_t buffer_handle) {
-  static int frame_buffer_idx = 0;
-
-  auto screen_view = ScreenRegionView::GetInstance();
-
-  void* frame_buffer = screen_view->GetBuffer(frame_buffer_idx);
-  const private_handle_t* p_handle =
-      reinterpret_cast<const private_handle_t*>(buffer_handle);
-  void* buffer;
-  int retval =
-      reinterpret_cast<gralloc_module_t*>(dev->common.module)
-          ->lock(reinterpret_cast<const gralloc_module_t*>(dev->common.module),
-                 buffer_handle, GRALLOC_USAGE_SW_READ_OFTEN, 0, 0,
-                 p_handle->x_res, p_handle->y_res, &buffer);
-  if (retval != 0) {
-    ALOGE("Got error code %d from lock function", retval);
-    return -1;
-  }
-  memcpy(frame_buffer, buffer, screen_view->buffer_size());
-  screen_view->BroadcastNewFrame(frame_buffer_idx);
-
-  frame_buffer_idx = (frame_buffer_idx + 1) % screen_view->number_of_buffers();
-
-  return 0;
-}
-
-/*****************************************************************************/
-
-static int fb_close(struct hw_device_t *dev) {
-  fb_context_t* ctx = (fb_context_t*)dev;
-  if (ctx) {
-    free(ctx);
-  }
-  return 0;
-}
-
-int fb_device_open(
-    hw_module_t const* module, const char* name, hw_device_t** device) {
-  if (strcmp(name, GRALLOC_HARDWARE_FB0) != 0) {
-    return -EINVAL;
-  }
-  /* initialize our state here */
-  fb_context_t* dev = (fb_context_t*) malloc(sizeof(*dev));
-  LOG_FATAL_IF(!dev, "%s: malloc returned NULL.", __FUNCTION__);
-  memset(dev, 0, sizeof(*dev));
-
-  /* initialize the procs */
-  dev->device.common.tag = HARDWARE_DEVICE_TAG;
-  dev->device.common.version = 0;
-  dev->device.common.module = const_cast<hw_module_t*>(module);
-  dev->device.common.close = fb_close;
-  dev->device.setSwapInterval = fb_setSwapInterval;
-  dev->device.post            = fb_post;
-  dev->device.setUpdateRect   = fb_setUpdateRect;
-
-  auto screen_view = ScreenRegionView::GetInstance();
-
-  int stride =
-    screen_view->line_length() / screen_view->bytes_per_pixel();
-  int format = HAL_PIXEL_FORMAT_RGBX_8888;
-  const_cast<uint32_t&>(dev->device.flags) = 0;
-  const_cast<uint32_t&>(dev->device.width) = screen_view->x_res();
-  const_cast<uint32_t&>(dev->device.height) = screen_view->y_res();
-  const_cast<int&>(dev->device.stride) = stride;
-  const_cast<int&>(dev->device.format) = format;
-  const_cast<float&>(dev->device.xdpi) = screen_view->dpi();
-  const_cast<float&>(dev->device.ydpi) = screen_view->dpi();
-  const_cast<float&>(dev->device.fps) =
-    (screen_view->refresh_rate_hz() * 1000) / 1000.0f;
-  const_cast<int&>(dev->device.minSwapInterval) = 1;
-  const_cast<int&>(dev->device.maxSwapInterval) = 1;
-  *device = &dev->device.common;
-
-  return 0;
-}
diff --git a/guest/hals/gralloc/legacy/gralloc.cpp b/guest/hals/gralloc/legacy/gralloc.cpp
index 8a0cbd2..dbe2838 100644
--- a/guest/hals/gralloc/legacy/gralloc.cpp
+++ b/guest/hals/gralloc/legacy/gralloc.cpp
@@ -36,7 +36,6 @@
 #include <hardware/gralloc.h>
 
 #include "common/libs/auto_resources/auto_resources.h"
-#include "common/vsoc/lib/screen_region_view.h"
 #include "gralloc_vsoc_priv.h"
 #include "region_registry.h"
 
@@ -162,7 +161,7 @@
     *device = &dev->device.common;
     status = 0;
   } else {
-    status = fb_device_open(module, name, device);
+    ALOGE("Need to create framebuffer, but it is unsupported");
   }
   return status;
 }
diff --git a/guest/hals/gralloc/legacy/gralloc_vsoc_priv.h b/guest/hals/gralloc/legacy/gralloc_vsoc_priv.h
index 2544b5a..390c654 100644
--- a/guest/hals/gralloc/legacy/gralloc_vsoc_priv.h
+++ b/guest/hals/gralloc/legacy/gralloc_vsoc_priv.h
@@ -29,8 +29,6 @@
 
 #include <linux/fb.h>
 
-#include "common/vsoc/lib/screen_region_view.h"
-
 #ifndef GRALLOC_MODULE_API_VERSION_0_2
 // This structure will be defined in later releases of Android. Declare it
 // here to allow us to structure the code well.
@@ -45,6 +43,20 @@
 };
 #endif
 
+namespace vsoc {
+namespace screen {
+
+struct ScreenRegionView {
+  static int align(int input) {
+    auto constexpr alignment = 16;
+    return (input + alignment - 1) & -alignment;
+  }
+  static constexpr int kSwiftShaderPadding = 4;
+};
+
+}
+}
+
 /*****************************************************************************/
 
 struct private_handle_t;
@@ -297,9 +309,6 @@
   }
 }
 
-int fb_device_open(
-    const hw_module_t* module, const char* name, hw_device_t** device);
-
 int gralloc_lock(
     gralloc_module_t const* module,
     buffer_handle_t handle, int usage,
diff --git a/guest/hals/gralloc/mapper.cpp b/guest/hals/gralloc/mapper.cpp
deleted file mode 100644
index e9ba2eb..0000000
--- a/guest/hals/gralloc/mapper.cpp
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Copyright (C) 2017 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 "gralloc_vsoc_priv.h"
-
-#include <unistd.h>
-#include <string.h>
-#include <sys/mman.h>
-
-#include <cutils/hashmap.h>
-#include <hardware/gralloc.h>
-#include <hardware/hardware.h>
-#include <log/log.h>
-
-namespace {
-
-const size_t g_page_size = sysconf(_SC_PAGESIZE);
-
-struct HmLockGuard {
-  HmLockGuard(Hashmap* map) : map_(map) {
-    hashmapLock(map_);
-  }
-  ~HmLockGuard() {
-    hashmapUnlock(map_);
-  }
- private:
-  Hashmap* map_;
-};
-
-int offset_hash(void* key) {
-  return *reinterpret_cast<int*>(key);
-}
-
-bool offset_equals(void* key1, void* key2) {
-  return *reinterpret_cast<int*>(key1) ==
-         *reinterpret_cast<int*>(key2);
-}
-
-// Keeps track of how many times a buffer is locked in the current process.
-struct GrallocBuffer {
-  void* vaddr;
-  int ref_count;
-  GrallocBuffer() : vaddr(NULL), ref_count(0) {}
-
-  static Hashmap* mapped_buffers() {
-    static Hashmap* mapped_buffers =
-        hashmapCreate(19, offset_hash, offset_equals);
-    return mapped_buffers;
-  }
-};
-
-}
-
-void* reference_buffer(const vsoc_buffer_handle_t* hnd) {
-  Hashmap* map = GrallocBuffer::mapped_buffers();
-  HmLockGuard lock_guard(map);
-  GrallocBuffer* buffer = reinterpret_cast<GrallocBuffer*>(
-      hashmapGet(map, const_cast<int*>(&hnd->offset)));
-  if (!buffer) {
-    buffer = new GrallocBuffer();
-    hashmapPut(map, const_cast<int*>(&hnd->offset), buffer);
-  }
-
-  if (!buffer->vaddr) {
-    void* mapped =
-      mmap(NULL, hnd->size, PROT_READ | PROT_WRITE, MAP_SHARED, hnd->fd, 0);
-    if (mapped == MAP_FAILED) {
-      ALOGE("Unable to map buffer (offset: %d, size: %d): %s",
-            hnd->offset,
-            hnd->size,
-            strerror(errno));
-      return NULL;
-    }
-    // Set up the guard pages. The last page is always a guard
-    uintptr_t base = uintptr_t(mapped);
-    uintptr_t addr = base + hnd->size - g_page_size;
-    if (mprotect((void*)addr, g_page_size, PROT_NONE) == -1) {
-      ALOGW("Unable to protect last page of buffer (offset: %d, size: %d): %s",
-            hnd->offset,
-            hnd->size,
-            strerror(errno));
-    }
-    buffer->vaddr = mapped;
-  }
-  buffer->ref_count++;
-  return buffer->vaddr;
-}
-
-int unreference_buffer(const vsoc_buffer_handle_t* hnd) {
-  int result = 0;
-  Hashmap* map = GrallocBuffer::mapped_buffers();
-  HmLockGuard lock_guard(map);
-  GrallocBuffer* buffer = reinterpret_cast<GrallocBuffer*>(
-      hashmapGet(map, const_cast<int*>(&hnd->offset)));
-  if (!buffer) {
-    ALOGE("Unreferencing an unknown buffer (offset: %d, size: %d)",
-          hnd->offset,
-          hnd->size);
-    return -EINVAL;
-  }
-  if (buffer->ref_count == 0) {
-    ALOGE("Unbalanced reference/unreference on buffer (offset: %d, size: %d)",
-          hnd->offset,
-          hnd->size);
-    return -EINVAL;
-  }
-  buffer->ref_count--;
-  if (buffer->ref_count == 0) {
-    result = munmap(buffer->vaddr, hnd->size);
-    if (result) {
-      ALOGE("Unable to unmap buffer (offset: %d, size: %d): %s",
-            hnd->offset,
-            hnd->size,
-            strerror(errno));
-    }
-    buffer->vaddr = NULL;
-  }
-  return result;
-}