Skip to content

Commit

Permalink
Apply modernize-make-unique to gpu/
Browse files Browse the repository at this point in the history
This is a large-scale change: go/chromium-modernize-make-unique

Bug: 1194272
Change-Id: Iaa2496e140eb0e9a3f540ea09bb2890781bee7d8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2802823
Commit-Queue: Peter Boström <pbos@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Owners-Override: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#869035}
  • Loading branch information
pbos authored and Chromium LUCI CQ committed Apr 3, 2021
1 parent c3a922f commit 1aa21c1
Show file tree
Hide file tree
Showing 43 changed files with 228 additions and 184 deletions.
10 changes: 5 additions & 5 deletions gpu/command_buffer/client/buffer_tracker_unittest.cc
Expand Up @@ -57,12 +57,12 @@ class BufferTrackerTest : public testing::Test {
kNumCommandEntries * sizeof(CommandBufferEntry);

void SetUp() override {
command_buffer_.reset(new MockClientCommandBufferImpl());
helper_.reset(new GLES2CmdHelper(command_buffer_.get()));
command_buffer_ = std::make_unique<MockClientCommandBufferImpl>();
helper_ = std::make_unique<GLES2CmdHelper>(command_buffer_.get());
helper_->Initialize(kCommandBufferSizeBytes);
mapped_memory_.reset(
new MappedMemoryManager(helper_.get(), MappedMemoryManager::kNoLimit));
buffer_tracker_.reset(new BufferTracker(mapped_memory_.get()));
mapped_memory_ = std::make_unique<MappedMemoryManager>(
helper_.get(), MappedMemoryManager::kNoLimit);
buffer_tracker_ = std::make_unique<BufferTracker>(mapped_memory_.get());
}

void TearDown() override {
Expand Down
7 changes: 4 additions & 3 deletions gpu/command_buffer/client/cmd_buffer_helper_test.cc
Expand Up @@ -41,16 +41,17 @@ const int32_t kUnusedCommandId = 5; // we use 0 and 2 currently.
class CommandBufferHelperTest : public testing::Test {
protected:
void SetUp() override {
command_buffer_.reset(new CommandBufferDirectLocked());
api_mock_.reset(new AsyncAPIMock(true, command_buffer_->service()));
command_buffer_ = std::make_unique<CommandBufferDirectLocked>();
api_mock_ =
std::make_unique<AsyncAPIMock>(true, command_buffer_->service());
command_buffer_->set_handler(api_mock_.get());

// ignore noops in the mock - we don't want to inspect the internals of the
// helper.
EXPECT_CALL(*api_mock_, DoCommand(cmd::kNoop, _, _))
.WillRepeatedly(Return(error::kNoError));

helper_.reset(new CommandBufferHelper(command_buffer_.get()));
helper_ = std::make_unique<CommandBufferHelper>(command_buffer_.get());
helper_->Initialize(kCommandBufferSizeBytes);

test_command_next_id_ = kUnusedCommandId;
Expand Down
14 changes: 7 additions & 7 deletions gpu/command_buffer/client/fenced_allocator_test.cc
Expand Up @@ -36,8 +36,9 @@ class BaseFencedAllocatorTest : public testing::Test {
static const int kAllocAlignment = 16;

void SetUp() override {
command_buffer_.reset(new CommandBufferDirect());
api_mock_.reset(new AsyncAPIMock(true, command_buffer_->service()));
command_buffer_ = std::make_unique<CommandBufferDirect>();
api_mock_ =
std::make_unique<AsyncAPIMock>(true, command_buffer_->service());
command_buffer_->set_handler(api_mock_.get());

// ignore noops in the mock - we don't want to inspect the internals of the
Expand All @@ -49,7 +50,7 @@ class BaseFencedAllocatorTest : public testing::Test {
.WillRepeatedly(DoAll(Invoke(api_mock_.get(), &AsyncAPIMock::SetToken),
Return(error::kNoError)));

helper_.reset(new CommandBufferHelper(command_buffer_.get()));
helper_ = std::make_unique<CommandBufferHelper>(command_buffer_.get());
helper_->Initialize(kBufferSize);
}

Expand All @@ -73,7 +74,7 @@ class FencedAllocatorTest : public BaseFencedAllocatorTest {
protected:
void SetUp() override {
BaseFencedAllocatorTest::SetUp();
allocator_.reset(new FencedAllocator(kBufferSize, helper_.get()));
allocator_ = std::make_unique<FencedAllocator>(kBufferSize, helper_.get());
}

void TearDown() override {
Expand Down Expand Up @@ -383,9 +384,8 @@ class FencedAllocatorWrapperTest : public BaseFencedAllocatorTest {
// something.
buffer_.reset(static_cast<char*>(base::AlignedAlloc(
kBufferSize, kAllocAlignment)));
allocator_.reset(new FencedAllocatorWrapper(kBufferSize,
helper_.get(),
buffer_.get()));
allocator_ = std::make_unique<FencedAllocatorWrapper>(
kBufferSize, helper_.get(), buffer_.get());
}

void TearDown() override {
Expand Down
7 changes: 4 additions & 3 deletions gpu/command_buffer/client/gl_helper.cc
Expand Up @@ -7,6 +7,7 @@
#include <stddef.h>
#include <stdint.h>

#include <memory>
#include <string>
#include <utility>

Expand Down Expand Up @@ -500,14 +501,14 @@ void GLHelper::ReadbackTextureAsync(GLuint texture,
void GLHelper::InitCopyTextToImpl() {
// Lazily initialize |copy_texture_to_impl_|
if (!copy_texture_to_impl_)
copy_texture_to_impl_.reset(
new CopyTextureToImpl(gl_, context_support_, this));
copy_texture_to_impl_ =
std::make_unique<CopyTextureToImpl>(gl_, context_support_, this);
}

void GLHelper::InitScalerImpl() {
// Lazily initialize |scaler_impl_|
if (!scaler_impl_)
scaler_impl_.reset(new GLHelperScaling(gl_, this));
scaler_impl_ = std::make_unique<GLHelperScaling>(gl_, this);
}

GLint GLHelper::MaxDrawBuffers() {
Expand Down
7 changes: 4 additions & 3 deletions gpu/command_buffer/client/gles2_implementation.cc
Expand Up @@ -16,6 +16,7 @@

#include <algorithm>
#include <map>
#include <memory>
#include <set>
#include <sstream>
#include <string>
Expand Down Expand Up @@ -290,17 +291,17 @@ gpu::ContextResult GLES2Implementation::Initialize(
helper_);

for (int i = 0; i < static_cast<int>(IdNamespaces::kNumIdNamespaces); ++i)
id_allocators_[i].reset(new IdAllocator());
id_allocators_[i] = std::make_unique<IdAllocator>();

if (support_client_side_arrays_) {
GetIdHandler(SharedIdNamespaces::kBuffers)
->MakeIds(this, kClientSideArrayId, base::size(reserved_ids_),
&reserved_ids_[0]);
}

vertex_array_object_manager_.reset(new VertexArrayObjectManager(
vertex_array_object_manager_ = std::make_unique<VertexArrayObjectManager>(
capabilities_.max_vertex_attribs, reserved_ids_[0], reserved_ids_[1],
support_client_side_arrays_));
support_client_side_arrays_);

// GL_BIND_GENERATES_RESOURCE_CHROMIUM state must be the same
// on Client & Service.
Expand Down
19 changes: 10 additions & 9 deletions gpu/command_buffer/client/mapped_memory_unittest.cc
Expand Up @@ -33,8 +33,9 @@ class MappedMemoryTestBase : public testing::Test {
static const unsigned int kBufferSize = 1024;

void SetUp() override {
command_buffer_.reset(new CommandBufferDirectLocked());
api_mock_.reset(new AsyncAPIMock(true, command_buffer_->service()));
command_buffer_ = std::make_unique<CommandBufferDirectLocked>();
api_mock_ =
std::make_unique<AsyncAPIMock>(true, command_buffer_->service());
command_buffer_->set_handler(api_mock_.get());

// ignore noops in the mock - we don't want to inspect the internals of the
Expand All @@ -46,7 +47,7 @@ class MappedMemoryTestBase : public testing::Test {
.WillRepeatedly(DoAll(Invoke(api_mock_.get(), &AsyncAPIMock::SetToken),
Return(error::kNoError)));

helper_.reset(new CommandBufferHelper(command_buffer_.get()));
helper_ = std::make_unique<CommandBufferHelper>(command_buffer_.get());
helper_->Initialize(kBufferSize);
}

Expand Down Expand Up @@ -77,7 +78,7 @@ class MemoryChunkTest : public MappedMemoryTestBase {
shared_memory_region.Map();
buffer_ = MakeBufferFromSharedMemory(std::move(shared_memory_region),
std::move(shared_memory_mapping));
chunk_.reset(new MemoryChunk(kShmId, buffer_, helper_.get()));
chunk_ = std::make_unique<MemoryChunk>(kShmId, buffer_, helper_.get());
}

void TearDown() override {
Expand Down Expand Up @@ -136,8 +137,8 @@ class MappedMemoryManagerTest : public MappedMemoryTestBase {
protected:
void SetUp() override {
MappedMemoryTestBase::SetUp();
manager_.reset(
new MappedMemoryManager(helper_.get(), MappedMemoryManager::kNoLimit));
manager_ = std::make_unique<MappedMemoryManager>(
helper_.get(), MappedMemoryManager::kNoLimit);
}

void TearDown() override {
Expand Down Expand Up @@ -328,7 +329,7 @@ TEST_F(MappedMemoryManagerTest, ChunkSizeMultiple) {
TEST_F(MappedMemoryManagerTest, UnusedMemoryLimit) {
const unsigned int kChunkSize = 2048;
// Reset the manager with a memory limit.
manager_.reset(new MappedMemoryManager(helper_.get(), kChunkSize));
manager_ = std::make_unique<MappedMemoryManager>(helper_.get(), kChunkSize);
manager_->set_chunk_size_multiple(kChunkSize);

// Allocate one chunk worth of memory.
Expand Down Expand Up @@ -359,7 +360,7 @@ TEST_F(MappedMemoryManagerTest, UnusedMemoryLimit) {
TEST_F(MappedMemoryManagerTest, MemoryLimitWithReuse) {
const unsigned int kSize = 1024;
// Reset the manager with a memory limit.
manager_.reset(new MappedMemoryManager(helper_.get(), kSize));
manager_ = std::make_unique<MappedMemoryManager>(helper_.get(), kSize);
const unsigned int kChunkSize = 2 * 1024;
manager_->set_chunk_size_multiple(kChunkSize);

Expand Down Expand Up @@ -411,7 +412,7 @@ TEST_F(MappedMemoryManagerTest, MemoryLimitWithReuse) {
TEST_F(MappedMemoryManagerTest, MaxAllocationTest) {
const unsigned int kSize = 1024;
// Reset the manager with a memory limit.
manager_.reset(new MappedMemoryManager(helper_.get(), kSize));
manager_ = std::make_unique<MappedMemoryManager>(helper_.get(), kSize);

const size_t kLimit = 512;
manager_->set_chunk_size_multiple(kLimit);
Expand Down
2 changes: 1 addition & 1 deletion gpu/command_buffer/client/program_info_manager_unittest.cc
Expand Up @@ -65,7 +65,7 @@ class ProgramInfoManagerTest : public testing::Test {
};

void SetUp() override {
program_info_manager_.reset(new ProgramInfoManager);
program_info_manager_ = std::make_unique<ProgramInfoManager>();
program_info_manager_->CreateInfo(kClientProgramId);
{
base::AutoLock auto_lock(program_info_manager_->lock_);
Expand Down
20 changes: 10 additions & 10 deletions gpu/command_buffer/client/query_tracker_unittest.cc
Expand Up @@ -34,12 +34,12 @@ class QuerySyncManagerTest : public testing::Test {
kNumCommandEntries * sizeof(CommandBufferEntry);

void SetUp() override {
command_buffer_.reset(new MockClientCommandBuffer());
helper_.reset(new GLES2CmdHelper(command_buffer_.get()));
command_buffer_ = std::make_unique<MockClientCommandBuffer>();
helper_ = std::make_unique<GLES2CmdHelper>(command_buffer_.get());
helper_->Initialize(kCommandBufferSizeBytes);
mapped_memory_.reset(
new MappedMemoryManager(helper_.get(), MappedMemoryManager::kNoLimit));
sync_manager_.reset(new QuerySyncManager(mapped_memory_.get()));
mapped_memory_ = std::make_unique<MappedMemoryManager>(
helper_.get(), MappedMemoryManager::kNoLimit);
sync_manager_ = std::make_unique<QuerySyncManager>(mapped_memory_.get());
}

void TearDown() override {
Expand Down Expand Up @@ -209,12 +209,12 @@ class QueryTrackerTest : public testing::Test {
kNumCommandEntries * sizeof(CommandBufferEntry);

void SetUp() override {
command_buffer_.reset(new MockClientCommandBuffer());
helper_.reset(new GLES2CmdHelper(command_buffer_.get()));
command_buffer_ = std::make_unique<MockClientCommandBuffer>();
helper_ = std::make_unique<GLES2CmdHelper>(command_buffer_.get());
helper_->Initialize(kCommandBufferSizeBytes);
mapped_memory_.reset(
new MappedMemoryManager(helper_.get(), MappedMemoryManager::kNoLimit));
query_tracker_.reset(new QueryTracker(mapped_memory_.get()));
mapped_memory_ = std::make_unique<MappedMemoryManager>(
helper_.get(), MappedMemoryManager::kNoLimit);
query_tracker_ = std::make_unique<QueryTracker>(mapped_memory_.get());
}

void TearDown() override {
Expand Down
13 changes: 7 additions & 6 deletions gpu/command_buffer/client/share_group.cc
Expand Up @@ -6,6 +6,7 @@

#include <stdint.h>

#include <memory>
#include <vector>

#include "base/containers/stack.h"
Expand Down Expand Up @@ -369,25 +370,25 @@ ShareGroup::ShareGroup(bool bind_generates_resource, uint64_t tracing_guid)
i < static_cast<int>(SharedIdNamespaces::kNumSharedIdNamespaces);
++i) {
if (i == static_cast<int>(SharedIdNamespaces::kProgramsAndShaders)) {
id_handlers_[i].reset(new NonReusedIdHandler());
id_handlers_[i] = std::make_unique<NonReusedIdHandler>();
} else {
id_handlers_[i].reset(new IdHandler());
id_handlers_[i] = std::make_unique<IdHandler>();
}
}
} else {
for (int i = 0;
i < static_cast<int>(SharedIdNamespaces::kNumSharedIdNamespaces);
++i) {
if (i == static_cast<int>(SharedIdNamespaces::kProgramsAndShaders)) {
id_handlers_[i].reset(new NonReusedIdHandler());
id_handlers_[i] = std::make_unique<NonReusedIdHandler>();
} else {
id_handlers_[i].reset(new StrictIdHandler(i));
id_handlers_[i] = std::make_unique<StrictIdHandler>(i);
}
}
}
program_info_manager_.reset(new ProgramInfoManager);
program_info_manager_ = std::make_unique<ProgramInfoManager>();
for (auto& range_id_handler : range_id_handlers_) {
range_id_handler.reset(new RangeIdHandler());
range_id_handler = std::make_unique<RangeIdHandler>();
}
}

Expand Down
14 changes: 8 additions & 6 deletions gpu/command_buffer/client/transfer_buffer_unittest.cc
Expand Up @@ -63,15 +63,16 @@ class TransferBufferTest : public testing::Test {
};

void TransferBufferTest::SetUp() {
command_buffer_.reset(new StrictMock<MockClientCommandBufferMockFlush>());
command_buffer_ =
std::make_unique<StrictMock<MockClientCommandBufferMockFlush>>();

helper_.reset(new CommandBufferHelper(command_buffer()));
helper_ = std::make_unique<CommandBufferHelper>(command_buffer());
ASSERT_EQ(helper_->Initialize(kCommandBufferSizeBytes),
gpu::ContextResult::kSuccess);

transfer_buffer_id_ = command_buffer()->GetNextFreeTransferBufferId();

transfer_buffer_.reset(new TransferBuffer(helper_.get()));
transfer_buffer_ = std::make_unique<TransferBuffer>(helper_.get());
}

void TransferBufferTest::TearDown() {
Expand Down Expand Up @@ -275,7 +276,8 @@ class TransferBufferExpandContractTest : public testing::Test {
};

void TransferBufferExpandContractTest::SetUp() {
command_buffer_.reset(new StrictMock<MockClientCommandBufferCanFail>());
command_buffer_ =
std::make_unique<StrictMock<MockClientCommandBufferCanFail>>();
command_buffer_->SetTokenForSetGetBuffer(0);

EXPECT_CALL(*command_buffer(),
Expand All @@ -285,7 +287,7 @@ void TransferBufferExpandContractTest::SetUp() {
&MockClientCommandBufferCanFail::RealCreateTransferBuffer))
.RetiresOnSaturation();

helper_.reset(new CommandBufferHelper(command_buffer()));
helper_ = std::make_unique<CommandBufferHelper>(command_buffer());
ASSERT_EQ(helper_->Initialize(kCommandBufferSizeBytes),
gpu::ContextResult::kSuccess);

Expand All @@ -298,7 +300,7 @@ void TransferBufferExpandContractTest::SetUp() {
&MockClientCommandBufferCanFail::RealCreateTransferBuffer))
.RetiresOnSaturation();

transfer_buffer_.reset(new TransferBuffer(helper_.get()));
transfer_buffer_ = std::make_unique<TransferBuffer>(helper_.get());
ASSERT_TRUE(transfer_buffer_->Initialize(
kStartTransferBufferSize, kStartingOffset, kMinTransferBufferSize,
kMaxTransferBufferSize, kAlignment));
Expand Down
20 changes: 11 additions & 9 deletions gpu/command_buffer/client/webgpu_implementation_unittest.cc
Expand Up @@ -6,6 +6,8 @@

#include "gpu/command_buffer/client/webgpu_implementation.h"

#include <memory>

#include "gpu/command_buffer/client/client_test_helper.h"
#include "gpu/command_buffer/client/mock_transfer_buffer.h"
#include "gpu/command_buffer/client/shared_memory_limits.h"
Expand Down Expand Up @@ -45,25 +47,25 @@ class WebGPUImplementationTest : public testing::Test {

bool Initialize() {
SharedMemoryLimits limits = SharedMemoryLimitsForTesting();
command_buffer_.reset(new StrictMock<MockClientCommandBuffer>());
command_buffer_ = std::make_unique<StrictMock<MockClientCommandBuffer>>();

transfer_buffer_.reset(
new MockTransferBuffer(command_buffer_.get(), kTransferBufferSize,
ImplementationBase::kStartingOffset,
ImplementationBase::kAlignment, false));
transfer_buffer_ = std::make_unique<MockTransferBuffer>(
command_buffer_.get(), kTransferBufferSize,
ImplementationBase::kStartingOffset, ImplementationBase::kAlignment,
false);

helper_.reset(new WebGPUCmdHelper(command_buffer_.get()));
helper_ = std::make_unique<WebGPUCmdHelper>(command_buffer_.get());
helper_->Initialize(limits.command_buffer_size);
gpu_control_.reset(new StrictMock<MockClientGpuControl>());
gpu_control_ = std::make_unique<StrictMock<MockClientGpuControl>>();

EXPECT_CALL(*gpu_control_, GetCapabilities())
.WillOnce(ReturnRef(capabilities_));

{
InSequence sequence;

gl_.reset(new WebGPUImplementation(helper_.get(), transfer_buffer_.get(),
gpu_control_.get()));
gl_ = std::make_unique<WebGPUImplementation>(
helper_.get(), transfer_buffer_.get(), gpu_control_.get());
}

// The client should be set to something non-null.
Expand Down
2 changes: 1 addition & 1 deletion gpu/command_buffer/common/command_buffer_shared_test.cc
Expand Up @@ -21,7 +21,7 @@ namespace gpu {
class CommandBufferSharedTest : public testing::Test {
protected:
void SetUp() override {
shared_state_.reset(new CommandBufferSharedState());
shared_state_ = std::make_unique<CommandBufferSharedState>();
shared_state_->Initialize();
}

Expand Down

0 comments on commit 1aa21c1

Please sign in to comment.