1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_OZONE_PLATFORM_FLATLAND_FLATLAND_SYSMEM_BUFFER_MANAGER_H_
#define UI_OZONE_PLATFORM_FLATLAND_FLATLAND_SYSMEM_BUFFER_MANAGER_H_
#include <fuchsia/sysmem/cpp/fidl.h>
#include <fuchsia/ui/composition/cpp/fidl.h>
#include <lib/zx/channel.h>
#include <lib/zx/eventpair.h>
#include <vulkan/vulkan_core.h>
#include <unordered_map>
#include "base/containers/small_map.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/synchronization/lock.h"
#include "base/unguessable_token.h"
#include "gpu/vulkan/vulkan_implementation.h"
#include "ui/gfx/buffer_types.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/native_pixmap.h"
namespace ui {
class FlatlandSysmemBufferCollection;
class FlatlandSurfaceFactory;
class FlatlandSysmemBufferManager {
public:
explicit FlatlandSysmemBufferManager(
FlatlandSurfaceFactory* flatland_surface_factory);
~FlatlandSysmemBufferManager();
FlatlandSysmemBufferManager(const FlatlandSysmemBufferManager&) = delete;
FlatlandSysmemBufferManager& operator=(const FlatlandSysmemBufferManager&) =
delete;
// Initializes the buffer manager with a connection to the Sysmem service and
// Flatland Allocator.
void Initialize(fuchsia::sysmem2::AllocatorHandle sysmem_allocator,
fuchsia::ui::composition::AllocatorHandle flatland_allocator);
// Disconnects from the sysmem service. After disconnecting, it's safe to call
// Initialize() again.
void Shutdown();
scoped_refptr<gfx::NativePixmap> CreateNativePixmap(VkDevice vk_device,
gfx::Size size,
gfx::BufferFormat format,
gfx::BufferUsage usage);
// TODO(crbug.com/42050538): Instead of an additional
// |register_with_flatland_allocator| bool, we can rely on |usage| to decide
// if the buffers should be registered with Flatland or not.
scoped_refptr<FlatlandSysmemBufferCollection> ImportSysmemBufferCollection(
VkDevice vk_device,
zx::eventpair service_handle,
zx::channel sysmem_token,
gfx::Size size,
gfx::BufferFormat format,
gfx::BufferUsage usage,
size_t min_buffer_count,
bool register_with_flatland_allocator);
// Returns `SysmemBufferCollection` that corresponds to the specified
// buffer collection `handle`, which should be the other end of the eventpair
// passed to `ImportSysmemBufferCollection()`.
scoped_refptr<FlatlandSysmemBufferCollection> GetCollectionByHandle(
const zx::eventpair& handle);
fuchsia::sysmem2::Allocator_Sync* sysmem_allocator() {
return sysmem_allocator_.get();
}
fuchsia::ui::composition::Allocator* flatland_allocator() {
return flatland_allocator_.get();
}
private:
void RegisterCollection(
scoped_refptr<FlatlandSysmemBufferCollection> collection);
void OnCollectionReleased(zx_koid_t id);
const raw_ptr<FlatlandSurfaceFactory> flatland_surface_factory_;
fuchsia::sysmem2::AllocatorSyncPtr sysmem_allocator_;
fuchsia::ui::composition::AllocatorPtr flatland_allocator_;
base::small_map<
std::unordered_map<zx_koid_t,
scoped_refptr<FlatlandSysmemBufferCollection>>>
collections_ GUARDED_BY(collections_lock_);
base::Lock collections_lock_;
};
} // namespace ui
#endif // UI_OZONE_PLATFORM_FLATLAND_FLATLAND_SYSMEM_BUFFER_MANAGER_H_
|