OSDN Git Service

resolve merge conflicts of 42ca6159e52c5a2217825da02a26cf504998301b to stage-aosp...
[android-x86/external-minigbm.git] / cros_gralloc / cros_gralloc_driver.cc
index e324bce..ab7c654 100644 (file)
@@ -55,7 +55,7 @@ int32_t cros_gralloc_driver::init()
                        if (asprintf(&node, str, DRM_DIR_NAME, j) < 0)
                                continue;
 
-                       fd = open(node, O_RDWR, 0);
+                       fd = open(node, O_RDWR | O_CLOEXEC);
                        free(node);
 
                        if (fd < 0)
@@ -96,10 +96,10 @@ bool cros_gralloc_driver::is_supported(const struct cros_gralloc_buffer_descript
 
 int32_t create_reserved_region(const std::string &buffer_name, uint64_t reserved_region_size)
 {
-       int32_t reserved_region_fd;
        std::string reserved_region_name = buffer_name + " reserved region";
 
-       reserved_region_fd = memfd_create(reserved_region_name.c_str(), FD_CLOEXEC);
+#ifdef __NR_memfd_create
+       int32_t reserved_region_fd = memfd_create(reserved_region_name.c_str(), FD_CLOEXEC);
        if (reserved_region_fd == -1) {
                drv_log("Failed to create reserved region fd: %s.\n", strerror(errno));
                return -errno;
@@ -111,6 +111,11 @@ int32_t create_reserved_region(const std::string &buffer_name, uint64_t reserved
        }
 
        return reserved_region_fd;
+#else
+       drv_log("Failed to create reserved region '%s': memfd_create not available.",
+               reserved_region_name.c_str());
+       return -1;
+#endif
 }
 
 int32_t cros_gralloc_driver::allocate(const struct cros_gralloc_buffer_descriptor *descriptor,
@@ -191,7 +196,7 @@ int32_t cros_gralloc_driver::allocate(const struct cros_gralloc_buffer_descripto
        num_bytes = ALIGN(num_bytes, sizeof(int));
        num_ints = num_bytes - sizeof(native_handle_t) - num_fds;
        /*
-        * Malloc is used as handles are ultimetly destroyed via free in
+        * Malloc is used as handles are ultimately destroyed via free in
         * native_handle_delete().
         */
        hnd = static_cast<struct cros_gralloc_handle *>(malloc(num_bytes));
@@ -212,6 +217,7 @@ int32_t cros_gralloc_driver::allocate(const struct cros_gralloc_buffer_descripto
        hnd->width = drv_bo_get_width(bo);
        hnd->height = drv_bo_get_height(bo);
        hnd->format = drv_bo_get_format(bo);
+       hnd->tiling = bo->meta.tiling;
        hnd->format_modifier = drv_bo_get_plane_format_modifier(bo, 0);
        hnd->use_flags = descriptor->use_flags;
        bytes_per_pixel = drv_bytes_per_pixel_from_format(hnd->format, 0);
@@ -266,6 +272,7 @@ int32_t cros_gralloc_driver::retain(buffer_handle_t handle)
                struct bo *bo;
                struct drv_import_fd_data data;
                data.format = hnd->format;
+               data.tiling = hnd->tiling;
 
                data.width = hnd->width;
                data.height = hnd->height;
@@ -498,4 +505,4 @@ void cros_gralloc_driver::for_each_handle(
        for (const auto &pair : handles_) {
                function(pair.first);
        }
-}
\ No newline at end of file
+}