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
|
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef GPU_COMMAND_BUFFER_CLIENT_INTERNAL_MAPPABLE_BUFFER_NATIVE_PIXMAP_H_
#define GPU_COMMAND_BUFFER_CLIENT_INTERNAL_MAPPABLE_BUFFER_NATIVE_PIXMAP_H_
#include <stddef.h>
#include <memory>
#include <vector>
#include "base/functional/callback_helpers.h"
#include "components/viz/common/resources/shared_image_format.h"
#include "gpu/command_buffer/client/gpu_command_buffer_client_export.h"
#include "gpu/command_buffer/client/internal/mappable_buffer.h"
namespace gfx {
class ClientNativePixmap;
class ClientNativePixmapFactory;
} // namespace gfx
namespace gpu {
class ClientSharedImage;
// Implementation of MappableBuffer based on Ozone native pixmap.
class GPU_COMMAND_BUFFER_CLIENT_EXPORT MappableBufferNativePixmap
: public MappableBuffer {
public:
MappableBufferNativePixmap(const MappableBufferNativePixmap&) = delete;
MappableBufferNativePixmap& operator=(const MappableBufferNativePixmap&) =
delete;
~MappableBufferNativePixmap() override;
static constexpr gfx::GpuMemoryBufferType kBufferType = gfx::NATIVE_PIXMAP;
static std::unique_ptr<MappableBufferNativePixmap> CreateFromHandleForTesting(
gfx::ClientNativePixmapFactory* client_native_pixmap_factory,
gfx::GpuMemoryBufferHandle handle,
const gfx::Size& size,
viz::SharedImageFormat format,
gfx::BufferUsage usage) {
return CreateFromHandle(client_native_pixmap_factory, std::move(handle),
size, format, usage);
}
static base::OnceClosure AllocateForTesting(
const gfx::Size& size,
viz::SharedImageFormat format,
gfx::BufferUsage usage,
gfx::GpuMemoryBufferHandle* handle);
// Overridden from MappableBuffer:
bool Map() override;
void MapAsync(base::OnceCallback<void(bool)> callback) override;
bool AsyncMappingIsNonBlocking() const override;
void* memory(size_t plane) override;
void Unmap() override;
int stride(size_t plane) const override;
gfx::GpuMemoryBufferType GetType() const override;
gfx::GpuMemoryBufferHandle CloneHandle() const override;
private:
friend class ClientSharedImage;
static std::unique_ptr<MappableBufferNativePixmap> CreateFromHandle(
gfx::ClientNativePixmapFactory* client_native_pixmap_factory,
gfx::GpuMemoryBufferHandle handle,
const gfx::Size& size,
viz::SharedImageFormat format,
gfx::BufferUsage usage);
MappableBufferNativePixmap(
const gfx::Size& size,
viz::SharedImageFormat format,
std::unique_ptr<gfx::ClientNativePixmap> native_pixmap);
void AssertMapped();
const gfx::Size size_;
const viz::SharedImageFormat format_;
const std::unique_ptr<gfx::ClientNativePixmap> pixmap_;
// Note: This lock must be held throughout the entirety of the Map() and
// Unmap() operations to avoid corrupt mutation across multiple threads.
base::Lock map_lock_;
uint32_t map_count_ GUARDED_BY(map_lock_) = 0u;
};
} // namespace gpu
#endif // GPU_COMMAND_BUFFER_CLIENT_INTERNAL_MAPPABLE_BUFFER_NATIVE_PIXMAP_H_
|