Commit 197e2514 by Ben Clayton

Device: Use std::unique_ptr instead of raw pointers

Instead of using raw pointers, use `std::unique_ptr`. Bug: b/126126820 Change-Id: Ia095f6aec1448c2153a0b0159f25a2946054e64b Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/43813Tested-by: 's avatarBen Clayton <bclayton@google.com> Kokoro-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarChris Forbes <chrisforbes@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 78ec0ea4
......@@ -50,16 +50,9 @@ bool PixelProcessor::State::operator==(const State &state) const
PixelProcessor::PixelProcessor()
{
routineCache = nullptr;
setRoutineCacheSize(1024);
}
PixelProcessor::~PixelProcessor()
{
delete routineCache;
routineCache = nullptr;
}
void PixelProcessor::setBlendConstant(const float4 &blendConstant)
{
// TODO(b/140935644): Check if clamp is required
......@@ -86,8 +79,7 @@ void PixelProcessor::setBlendConstant(const float4 &blendConstant)
void PixelProcessor::setRoutineCacheSize(int cacheSize)
{
delete routineCache;
routineCache = new RoutineCacheType(clamp(cacheSize, 1, 65536));
routineCache = std::make_unique<RoutineCacheType>(clamp(cacheSize, 1, 65536));
}
const PixelProcessor::State PixelProcessor::update(const Context *context) const
......
......@@ -19,6 +19,8 @@
#include "Memset.hpp"
#include "RoutineCache.hpp"
#include <memory>
namespace sw {
class PixelShader;
......@@ -146,8 +148,6 @@ public:
PixelProcessor();
virtual ~PixelProcessor();
void setBlendConstant(const float4 &blendConstant);
const State update(const Context *context) const;
......@@ -160,7 +160,7 @@ public:
private:
using RoutineCacheType = RoutineCache<State, RasterizerFunction::CFunctionType>;
RoutineCacheType *routineCache;
std::unique_ptr<RoutineCacheType> routineCache;
};
} // namespace sw
......
......@@ -52,16 +52,9 @@ bool SetupProcessor::State::operator==(const State &state) const
SetupProcessor::SetupProcessor()
{
routineCache = nullptr;
setRoutineCacheSize(1024);
}
SetupProcessor::~SetupProcessor()
{
delete routineCache;
routineCache = nullptr;
}
SetupProcessor::State SetupProcessor::update(const sw::Context *context) const
{
State state;
......@@ -117,8 +110,7 @@ SetupProcessor::RoutineType SetupProcessor::routine(const State &state)
void SetupProcessor::setRoutineCacheSize(int cacheSize)
{
delete routineCache;
routineCache = new RoutineCacheType(clamp(cacheSize, 1, 65536));
routineCache = std::make_unique<RoutineCacheType>(clamp(cacheSize, 1, 65536));
}
} // namespace sw
......@@ -21,6 +21,8 @@
#include "System/Types.hpp"
#include <Pipeline/SpirvShader.hpp>
#include <memory>
namespace sw {
struct Primitive;
......@@ -71,8 +73,6 @@ public:
SetupProcessor();
~SetupProcessor();
State update(const sw::Context *context) const;
RoutineType routine(const State &state);
......@@ -80,7 +80,7 @@ public:
private:
using RoutineCacheType = RoutineCache<State, SetupFunction::CFunctionType>;
RoutineCacheType *routineCache;
std::unique_ptr<RoutineCacheType> routineCache;
};
} // namespace sw
......
......@@ -57,20 +57,12 @@ bool VertexProcessor::State::operator==(const State &state) const
VertexProcessor::VertexProcessor()
{
routineCache = nullptr;
setRoutineCacheSize(1024);
}
VertexProcessor::~VertexProcessor()
{
delete routineCache;
routineCache = nullptr;
}
void VertexProcessor::setRoutineCacheSize(int cacheSize)
{
delete routineCache;
routineCache = new RoutineCacheType(clamp(cacheSize, 1, 65536));
routineCache = std::make_unique<RoutineCacheType>(clamp(cacheSize, 1, 65536));
}
const VertexProcessor::State VertexProcessor::update(const sw::Context *context)
......
......@@ -21,6 +21,8 @@
#include "Vertex.hpp"
#include "Pipeline/SpirvShader.hpp"
#include <memory>
namespace sw {
struct DrawData;
......@@ -92,8 +94,6 @@ public:
VertexProcessor();
virtual ~VertexProcessor();
const State update(const sw::Context *context);
RoutineType routine(const State &state, vk::PipelineLayout const *pipelineLayout,
SpirvShader const *vertexShader, const vk::DescriptorSet::Bindings &descriptorSets);
......@@ -102,7 +102,7 @@ public:
private:
using RoutineCacheType = RoutineCache<State, VertexRoutineFunction::CFunctionType>;
RoutineCacheType *routineCache;
std::unique_ptr<RoutineCacheType> routineCache;
};
} // namespace sw
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment