Do not pass std::shared_ptr when not transfering ownership
This goes against Google's C++ primer [1] and the Core C++ guidelines [2]. It incurs additional runtime overhead to increase and subsequently decrease the reference count without providing value, since the parent function maintains the a reference to the object through the duration of the function. 1: go/cpp-primer#unique_ptr - "In general, if you find yourself wanting to use a pointer or reference to a unique_ptr, you're probably not transferring ownership, so you should usually just pass a raw pointer or reference to the underlying object, and keep unique_ptr out of it." 2: http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#f7-for-general-use-take-t-or-t-arguments-rather-than-smart-pointers Reviewed-by: Aaron Ruby <aruby@blackberry.com> Acked-by: Yonggang Luo <luoyonggang@gmail.com> Acked-by: Adam Jackson <ajax@redhat.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27246>
This commit is contained in:
@@ -112,7 +112,7 @@ AddressSpaceStream* createVirtioGpuAddressSpaceStream(enum VirtGpuCapset capset,
|
||||
exec.command = static_cast<void*>(&contextCreate);
|
||||
exec.command_size = sizeof(contextCreate);
|
||||
|
||||
ret = instance->execBuffer(exec, blob);
|
||||
ret = instance->execBuffer(exec, blob.get());
|
||||
if (ret)
|
||||
return nullptr;
|
||||
|
||||
|
||||
@@ -25,9 +25,9 @@ class FuchsiaVirtGpuBlob : public std::enable_shared_from_this<FuchsiaVirtGpuBlo
|
||||
uint64_t size);
|
||||
~FuchsiaVirtGpuBlob();
|
||||
|
||||
uint32_t getResourceHandle(void) override;
|
||||
uint32_t getBlobHandle(void) override;
|
||||
int wait(void) override;
|
||||
uint32_t getResourceHandle() const override;
|
||||
uint32_t getBlobHandle() const override;
|
||||
int wait() override;
|
||||
|
||||
int exportBlob(struct VirtGpuExternalHandle& handle) override;
|
||||
int transferFromHost(uint32_t offset, uint32_t size) override;
|
||||
@@ -57,5 +57,5 @@ class FuchsiaVirtGpuDevice : public VirtGpuDevice {
|
||||
VirtGpuBlobPtr createVirglBlob(uint32_t width, uint32_t height, uint32_t format) override;
|
||||
VirtGpuBlobPtr importBlob(const struct VirtGpuExternalHandle& handle) override;
|
||||
|
||||
int execBuffer(struct VirtGpuExecBuffer& execbuffer, VirtGpuBlobPtr blob) override;
|
||||
int execBuffer(struct VirtGpuExecBuffer& execbuffer, const VirtGpuBlob* blob) override;
|
||||
};
|
||||
|
||||
@@ -23,12 +23,12 @@ FuchsiaVirtGpuBlob::FuchsiaVirtGpuBlob(int64_t deviceHandle, uint32_t blobHandle
|
||||
|
||||
FuchsiaVirtGpuBlob::~FuchsiaVirtGpuBlob(void) {}
|
||||
|
||||
uint32_t FuchsiaVirtGpuBlob::getBlobHandle(void) {
|
||||
uint32_t FuchsiaVirtGpuBlob::getBlobHandle() const {
|
||||
ALOGE("%s: unimplemented", __func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t FuchsiaVirtGpuBlob::getResourceHandle(void) {
|
||||
uint32_t FuchsiaVirtGpuBlob::getResourceHandle() const {
|
||||
ALOGE("%s: unimplemented", __func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -43,7 +43,8 @@ VirtGpuBlobPtr FuchsiaVirtGpuDevice::importBlob(const struct VirtGpuExternalHand
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int FuchsiaVirtGpuDevice::execBuffer(struct VirtGpuExecBuffer& execbuffer, VirtGpuBlobPtr blob) {
|
||||
int FuchsiaVirtGpuDevice::execBuffer(struct VirtGpuExecBuffer& execbuffer,
|
||||
const VirtGpuBlob* blob) {
|
||||
ALOGE("%s: unimplemented", __func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -134,9 +134,9 @@ class VirtGpuBlob {
|
||||
public:
|
||||
virtual ~VirtGpuBlob() {}
|
||||
|
||||
virtual uint32_t getResourceHandle(void) = 0;
|
||||
virtual uint32_t getBlobHandle(void) = 0;
|
||||
virtual int wait(void) = 0;
|
||||
virtual uint32_t getResourceHandle() const = 0;
|
||||
virtual uint32_t getBlobHandle() const = 0;
|
||||
virtual int wait() = 0;
|
||||
|
||||
virtual VirtGpuBlobMappingPtr createMapping(void) = 0;
|
||||
virtual int exportBlob(struct VirtGpuExternalHandle& handle) = 0;
|
||||
@@ -172,9 +172,9 @@ class VirtGpuDevice {
|
||||
virtual VirtGpuBlobPtr createVirglBlob(uint32_t width, uint32_t height, uint32_t virglFormat) = 0;
|
||||
virtual VirtGpuBlobPtr importBlob(const struct VirtGpuExternalHandle& handle) = 0;
|
||||
|
||||
virtual int execBuffer(struct VirtGpuExecBuffer& execbuffer, VirtGpuBlobPtr blob) = 0;
|
||||
virtual int execBuffer(struct VirtGpuExecBuffer& execbuffer, const VirtGpuBlob* blob) = 0;
|
||||
|
||||
private:
|
||||
private:
|
||||
enum VirtGpuCapset mCapset;
|
||||
};
|
||||
|
||||
|
||||
@@ -24,9 +24,9 @@ class LinuxVirtGpuBlob : public std::enable_shared_from_this<LinuxVirtGpuBlob>,
|
||||
uint64_t size);
|
||||
~LinuxVirtGpuBlob();
|
||||
|
||||
uint32_t getResourceHandle(void) override;
|
||||
uint32_t getBlobHandle(void) override;
|
||||
int wait(void) override;
|
||||
uint32_t getResourceHandle() const override;
|
||||
uint32_t getBlobHandle() const override;
|
||||
int wait() override;
|
||||
|
||||
VirtGpuBlobMappingPtr createMapping(void) override;
|
||||
int exportBlob(struct VirtGpuExternalHandle& handle) override;
|
||||
@@ -70,7 +70,7 @@ class LinuxVirtGpuDevice : public VirtGpuDevice {
|
||||
VirtGpuBlobPtr createVirglBlob(uint32_t width, uint32_t height, uint32_t virglFormat) override;
|
||||
|
||||
virtual VirtGpuBlobPtr importBlob(const struct VirtGpuExternalHandle& handle);
|
||||
virtual int execBuffer(struct VirtGpuExecBuffer& execbuffer, VirtGpuBlobPtr blob);
|
||||
virtual int execBuffer(struct VirtGpuExecBuffer& execbuffer, const VirtGpuBlob* blob);
|
||||
|
||||
private:
|
||||
int64_t mDeviceHandle;
|
||||
|
||||
@@ -33,7 +33,7 @@ LinuxVirtGpuBlob::LinuxVirtGpuBlob(int64_t deviceHandle, uint32_t blobHandle,
|
||||
mResourceHandle(resourceHandle),
|
||||
mSize(size) {}
|
||||
|
||||
LinuxVirtGpuBlob::~LinuxVirtGpuBlob(void) {
|
||||
LinuxVirtGpuBlob::~LinuxVirtGpuBlob() {
|
||||
struct drm_gem_close gem_close {
|
||||
.handle = mBlobHandle, .pad = 0,
|
||||
};
|
||||
@@ -45,11 +45,11 @@ LinuxVirtGpuBlob::~LinuxVirtGpuBlob(void) {
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t LinuxVirtGpuBlob::getBlobHandle(void) { return mBlobHandle; }
|
||||
uint32_t LinuxVirtGpuBlob::getBlobHandle() const { return mBlobHandle; }
|
||||
|
||||
uint32_t LinuxVirtGpuBlob::getResourceHandle(void) { return mResourceHandle; }
|
||||
uint32_t LinuxVirtGpuBlob::getResourceHandle() const { return mResourceHandle; }
|
||||
|
||||
VirtGpuBlobMappingPtr LinuxVirtGpuBlob::createMapping(void) {
|
||||
VirtGpuBlobMappingPtr LinuxVirtGpuBlob::createMapping() {
|
||||
int ret;
|
||||
struct drm_virtgpu_map map {
|
||||
.handle = mBlobHandle, .pad = 0,
|
||||
|
||||
@@ -245,7 +245,7 @@ VirtGpuBlobPtr LinuxVirtGpuDevice::importBlob(const struct VirtGpuExternalHandle
|
||||
static_cast<uint64_t>(info.size));
|
||||
}
|
||||
|
||||
int LinuxVirtGpuDevice::execBuffer(struct VirtGpuExecBuffer& execbuffer, VirtGpuBlobPtr blob) {
|
||||
int LinuxVirtGpuDevice::execBuffer(struct VirtGpuExecBuffer& execbuffer, const VirtGpuBlob* blob) {
|
||||
int ret;
|
||||
struct drm_virtgpu_execbuffer exec = {0};
|
||||
uint32_t blobHandle;
|
||||
|
||||
@@ -3068,7 +3068,7 @@ VkResult ResourceTracker::allocateCoherentMemory(VkDevice device,
|
||||
exec.command_size = sizeof(placeholderCmd);
|
||||
exec.flags = kRingIdx;
|
||||
exec.ring_idx = 1;
|
||||
if (instance->execBuffer(exec, guestBlob)) {
|
||||
if (instance->execBuffer(exec, guestBlob.get())) {
|
||||
ALOGE("Failed to allocate coherent memory: failed to execbuffer for wait.");
|
||||
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user