OSDN Git Service

minigbm: rockchip/mediatek: invalidate shadow buffers
[android-x86/external-minigbm.git] / mediatek.c
index ebc000f..7614004 100644 (file)
@@ -32,16 +32,11 @@ static const uint32_t texture_source_formats[] = { DRM_FORMAT_R8, DRM_FORMAT_YVU
 
 static int mediatek_init(struct driver *drv)
 {
-       int ret;
-       ret = drv_add_combinations(drv, render_target_formats, ARRAY_SIZE(render_target_formats),
-                                  &LINEAR_METADATA, BO_USE_RENDER_MASK);
-       if (ret)
-               return ret;
+       drv_add_combinations(drv, render_target_formats, ARRAY_SIZE(render_target_formats),
+                            &LINEAR_METADATA, BO_USE_RENDER_MASK);
 
-       ret = drv_add_combinations(drv, texture_source_formats, ARRAY_SIZE(texture_source_formats),
-                                  &LINEAR_METADATA, BO_USE_TEXTURE_MASK);
-       if (ret)
-               return ret;
+       drv_add_combinations(drv, texture_source_formats, ARRAY_SIZE(texture_source_formats),
+                            &LINEAR_METADATA, BO_USE_TEXTURE_MASK);
 
        return drv_modify_linear_combinations(drv);
 }
@@ -102,7 +97,6 @@ static void *mediatek_bo_map(struct bo *bo, struct vma *vma, size_t plane, uint3
                priv = calloc(1, sizeof(*priv));
                priv->cached_addr = calloc(1, bo->total_size);
                priv->gem_addr = addr;
-               memcpy(priv->cached_addr, priv->gem_addr, bo->total_size);
                vma->priv = priv;
                addr = priv->cached_addr;
        }
@@ -123,6 +117,16 @@ static int mediatek_bo_unmap(struct bo *bo, struct vma *vma)
        return munmap(vma->addr, vma->length);
 }
 
+static int mediatek_bo_invalidate(struct bo *bo, struct mapping *mapping)
+{
+       if (mapping->vma->priv) {
+               struct mediatek_private_map_data *priv = mapping->vma->priv;
+               memcpy(priv->cached_addr, priv->gem_addr, bo->total_size);
+       }
+
+       return 0;
+}
+
 static int mediatek_bo_flush(struct bo *bo, struct mapping *mapping)
 {
        struct mediatek_private_map_data *priv = mapping->vma->priv;
@@ -153,6 +157,7 @@ const struct backend backend_mediatek = {
        .bo_import = drv_prime_bo_import,
        .bo_map = mediatek_bo_map,
        .bo_unmap = mediatek_bo_unmap,
+       .bo_invalidate = mediatek_bo_invalidate,
        .bo_flush = mediatek_bo_flush,
        .resolve_format = mediatek_resolve_format,
 };