chromium/media/gpu/vaapi/test/fake_libva_driver/scoped_bo_mapping_factory.h

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MEDIA_GPU_VAAPI_TEST_FAKE_LIBVA_DRIVER_SCOPED_BO_MAPPING_FACTORY_H_
#define MEDIA_GPU_VAAPI_TEST_FAKE_LIBVA_DRIVER_SCOPED_BO_MAPPING_FACTORY_H_

#include <gbm.h>

#include <memory>

#include "base/files/scoped_file.h"
#include "base/memory/raw_ref.h"
#include "base/synchronization/lock.h"
#include "ui/gfx/linux/scoped_gbm_device.h"

namespace media::internal {

class ScopedBOMappingFactory;

// ScopedBOMapping tracks the CPU mapping of a minigbm Buffer Object (BO).
// Upon destruction, it unmaps and destroys the Buffer Object.
//
// Notes:
//
// - Only a ScopedBOMappingFactory can create valid ScopedBOMapping instances.
//   Upon destruction, the ScopedBOMapping requests the ScopedBOMappingFactory
//   to unmap and destroy the Buffer Object. This is done to ensure that the GBM
//   device is protected from concurrent operations on multiple threads.
//   Therefore, the ScopedBOMappingFactory that creates a ScopedBOMapping must
//   outlive it.
//
// - ScopedBOMapping instances can be used from any thread, but they are NOT
//   thread-safe, i.e., access to them must be synchronized externally.
//   Additionally, access to different ScopedBOMappings that refer to the same
//   dma-buf must also be synchronized externally.
class ScopedBOMapping {};

// A ScopedBOMappingFactory provides thread-safe access to minigbm in order to
// import dma-bufs and map them for CPU access.
//
// ScopedBOMappingFactory instances are thread-safe.
class ScopedBOMappingFactory {};

}  // namespace media::internal

#endif  // MEDIA_GPU_VAAPI_TEST_FAKE_LIBVA_DRIVER_SCOPED_BO_MAPPING_FACTORY_H_