diff options
author | r.kuznetsov <r.kuznetsov@corp.mail.ru> | 2015-04-16 14:48:30 +0300 |
---|---|---|
committer | r.kuznetsov <r.kuznetsov@corp.mail.ru> | 2015-11-30 16:04:17 +0300 |
commit | 734b0a10b024dac63a26710522683fdb0209a0b5 (patch) | |
tree | 96554add69ea14b6d9e2ed13eb17fdeb3a763eb4 /drape | |
parent | 4d6dcfc596953ef570d1d51f11416cdd5298999c (diff) |
Pointers refactoring
Diffstat (limited to 'drape')
50 files changed, 609 insertions, 1071 deletions
diff --git a/drape/attribute_buffer_mutator.hpp b/drape/attribute_buffer_mutator.hpp index d5846c849c..36235b9e79 100644 --- a/drape/attribute_buffer_mutator.hpp +++ b/drape/attribute_buffer_mutator.hpp @@ -23,7 +23,7 @@ struct MutateRegion struct MutateNode { MutateRegion m_region; - RefPointer<void> m_data; + ref_ptr<void> m_data; }; class AttributeBufferMutator diff --git a/drape/attribute_provider.cpp b/drape/attribute_provider.cpp index ef0655b136..95144450e2 100644 --- a/drape/attribute_provider.cpp +++ b/drape/attribute_provider.cpp @@ -43,7 +43,7 @@ void const * AttributeProvider::GetRawPointer(uint8_t streamIndex) { ASSERT_LESS(streamIndex, GetStreamCount(), ()); CHECK_STREAMS; - return m_streams[streamIndex].m_data.GetRaw(); + return m_streams[streamIndex].m_data; } BindingInfo const & AttributeProvider::GetBindingInfo(uint8_t streamIndex) const @@ -64,8 +64,8 @@ void AttributeProvider::Advance(uint16_t vertexCount) { BindingInfo const & info = m_streams[i].m_binding; uint32_t offset = vertexCount * info.GetElementSize(); - void * rawPointer = m_streams[i].m_data.GetRaw(); - m_streams[i].m_data = MakeStackRefPointer((void *)(((uint8_t *)rawPointer) + offset)); + void * rawPointer = m_streams[i].m_data; + m_streams[i].m_data = make_ref((void *)(((uint8_t *)rawPointer) + offset)); } } @@ -74,7 +74,7 @@ void AttributeProvider::Advance(uint16_t vertexCount) void AttributeProvider::InitStream(uint8_t streamIndex, BindingInfo const & bindingInfo, - RefPointer<void> data) + ref_ptr<void> data) { ASSERT_LESS(streamIndex, GetStreamCount(), ()); AttributeStream s; diff --git a/drape/attribute_provider.hpp b/drape/attribute_provider.hpp index 8aa473d334..ab6980d85c 100644 --- a/drape/attribute_provider.hpp +++ b/drape/attribute_provider.hpp @@ -25,7 +25,7 @@ public: void InitStream(uint8_t streamIndex, BindingInfo const & bindingInfo, - RefPointer<void> data); + ref_ptr<void> data); private: int32_t m_vertexCount; @@ -33,7 +33,7 @@ private: struct AttributeStream { BindingInfo m_binding; - RefPointer<void> m_data; + ref_ptr<void> m_data; }; vector<AttributeStream> m_streams; #ifdef DEBUG diff --git a/drape/batcher.cpp b/drape/batcher.cpp index 4a588e0d2a..93a6ff8ebd 100644 --- a/drape/batcher.cpp +++ b/drape/batcher.cpp @@ -14,14 +14,14 @@ namespace dp class Batcher::CallbacksWrapper { public: - CallbacksWrapper(GLState const & state, RefPointer<OverlayHandle> overlay) + CallbacksWrapper(GLState const & state, ref_ptr<OverlayHandle> overlay) : m_state(state) , m_overlay(overlay) , m_vaoChanged(false) { } - void SetVAO(RefPointer<VertexArrayBuffer> buffer) + void SetVAO(ref_ptr<VertexArrayBuffer> buffer) { // invocation with non-null VAO will cause to invalid range of indices. // It means that VAO has been changed during batching @@ -39,7 +39,7 @@ public: void FlushData(BindingInfo const & info, void const * data, uint16_t count) { - if (!m_overlay.IsNull() && info.IsDynamic()) + if (m_overlay != nullptr && info.IsDynamic()) { uint16_t offset = m_buffer->GetDynamicBufferOffset(info); m_overlay->AddDynamicAttribute(info, offset, count); @@ -50,7 +50,7 @@ public: uint16_t * GetIndexStorage(uint16_t size, uint16_t & startIndex) { startIndex = m_buffer->GetStartIndexValue(); - if (m_overlay.IsNull() || !m_overlay->IndexesRequired()) + if (m_overlay == nullptr || !m_overlay->IndexesRequired()) { m_indexStorage.resize(size); return &m_indexStorage[0]; @@ -61,7 +61,7 @@ public: void SubmitIndexes() { - if (m_overlay.IsNull() || !m_overlay->IndexesRequired()) + if (m_overlay == nullptr || !m_overlay->IndexesRequired()) m_buffer->UploadIndexes(&m_indexStorage[0], m_indexStorage.size()); } @@ -92,8 +92,8 @@ public: private: GLState const & m_state; - RefPointer<VertexArrayBuffer> m_buffer; - RefPointer<OverlayHandle> m_overlay; + ref_ptr<VertexArrayBuffer> m_buffer; + ref_ptr<OverlayHandle> m_overlay; vector<uint16_t> m_indexStorage; IndicesRange m_indicesRange; bool m_vaoChanged; @@ -109,52 +109,52 @@ Batcher::Batcher(uint32_t indexBufferSize, uint32_t vertexBufferSize) Batcher::~Batcher() { - DeleteRange(m_buckets, MasterPointerDeleter()); + m_buckets.clear(); } -void Batcher::InsertTriangleList(GLState const & state, RefPointer<AttributeProvider> params) +IndicesRange Batcher::InsertTriangleList(GLState const & state, ref_ptr<AttributeProvider> params) { - InsertTriangleList(state, params, MovePointer<OverlayHandle>(NULL)); + return InsertTriangleList(state, params, drape_ptr<OverlayHandle>(nullptr)); } -IndicesRange Batcher::InsertTriangleList(GLState const & state, RefPointer<AttributeProvider> params, - TransferPointer<OverlayHandle> handle) +IndicesRange Batcher::InsertTriangleList(GLState const & state, ref_ptr<AttributeProvider> params, + drape_ptr<OverlayHandle> && handle) { - return InsertTriangles<TriangleListBatch>(state, params, handle); + return InsertTriangles<TriangleListBatch>(state, params, move(handle)); } -void Batcher::InsertTriangleStrip(GLState const & state, RefPointer<AttributeProvider> params) +IndicesRange Batcher::InsertTriangleStrip(GLState const & state, ref_ptr<AttributeProvider> params) { - InsertTriangleStrip(state, params, MovePointer<OverlayHandle>(NULL)); + return InsertTriangleStrip(state, params, drape_ptr<OverlayHandle>(nullptr)); } -IndicesRange Batcher::InsertTriangleStrip(GLState const & state, RefPointer<AttributeProvider> params, - TransferPointer<OverlayHandle> handle) +IndicesRange Batcher::InsertTriangleStrip(GLState const & state, ref_ptr<AttributeProvider> params, + drape_ptr<OverlayHandle> && handle) { - return InsertTriangles<TriangleStripBatch>(state, params, handle); + return InsertTriangles<TriangleStripBatch>(state, params, move(handle)); } -void Batcher::InsertTriangleFan(GLState const & state, RefPointer<AttributeProvider> params) +IndicesRange Batcher::InsertTriangleFan(GLState const & state, ref_ptr<AttributeProvider> params) { - InsertTriangleFan(state, params, MovePointer<OverlayHandle>(NULL)); + return InsertTriangleFan(state, params, drape_ptr<OverlayHandle>(nullptr)); } -IndicesRange Batcher::InsertTriangleFan(GLState const & state, RefPointer<AttributeProvider> params, - TransferPointer<OverlayHandle> handle) +IndicesRange Batcher::InsertTriangleFan(GLState const & state, ref_ptr<AttributeProvider> params, + drape_ptr<OverlayHandle> && handle) { - return InsertTriangles<TriangleFanBatch>(state, params, handle); + return InsertTriangles<TriangleFanBatch>(state, params, move(handle)); } -void Batcher::InsertListOfStrip(GLState const & state, RefPointer<AttributeProvider> params, - uint8_t vertexStride) +IndicesRange Batcher::InsertListOfStrip(GLState const & state, ref_ptr<AttributeProvider> params, + uint8_t vertexStride) { - InsertListOfStrip(state, params, MovePointer<OverlayHandle>(NULL), vertexStride); + return InsertListOfStrip(state, params, drape_ptr<OverlayHandle>(nullptr), vertexStride); } -IndicesRange Batcher::InsertListOfStrip(GLState const & state, RefPointer<AttributeProvider> params, - TransferPointer<OverlayHandle> handle, uint8_t vertexStride) +IndicesRange Batcher::InsertListOfStrip(GLState const & state, ref_ptr<AttributeProvider> params, + drape_ptr<OverlayHandle> && handle, uint8_t vertexStride) { - return InsertTriangles<TriangleListOfStripBatch>(state, params, handle, vertexStride); + return InsertTriangles<TriangleListOfStripBatch>(state, params, move(handle), vertexStride); } void Batcher::StartSession(TFlushFn const & flusher) @@ -168,37 +168,40 @@ void Batcher::EndSession() m_flushInterface = TFlushFn(); } -void Batcher::ChangeBuffer(RefPointer<CallbacksWrapper> wrapper, bool checkFilledBuffer) +void Batcher::ChangeBuffer(ref_ptr<CallbacksWrapper> wrapper, bool checkFilledBuffer) { if (wrapper->IsVAOFilled() || checkFilledBuffer == false) { GLState const & state = wrapper->GetState(); FinalizeBucket(state); - RefPointer<RenderBucket> bucket = GetBucket(state); + ref_ptr<RenderBucket> bucket = GetBucket(state); wrapper->SetVAO(bucket->GetBuffer()); } } -RefPointer<RenderBucket> Batcher::GetBucket(GLState const & state) +ref_ptr<RenderBucket> Batcher::GetBucket(GLState const & state) { TBuckets::iterator it = m_buckets.find(state); if (it != m_buckets.end()) - return it->second.GetRefPointer(); + return make_ref<RenderBucket>(it->second); + + drape_ptr<VertexArrayBuffer> vao = make_unique_dp<VertexArrayBuffer>(m_indexBufferSize, m_vertexBufferSize); + drape_ptr<RenderBucket> buffer = make_unique_dp<RenderBucket>(move(vao)); + ref_ptr<RenderBucket> result = make_ref<RenderBucket>(buffer); + m_buckets.emplace(state, move(buffer)); - MasterPointer<VertexArrayBuffer> vao(new VertexArrayBuffer(m_indexBufferSize, m_vertexBufferSize)); - MasterPointer<RenderBucket> buffer(new RenderBucket(vao.Move())); - m_buckets.insert(make_pair(state, buffer)); - return buffer.GetRefPointer(); + return result; } void Batcher::FinalizeBucket(GLState const & state) { - ASSERT(m_buckets.find(state) != m_buckets.end(), ("Have no bucket for finalize with given state")); - MasterPointer<RenderBucket> bucket = m_buckets[state]; + TBuckets::iterator it = m_buckets.find(state); + ASSERT(it != m_buckets.end(), ("Have no bucket for finalize with given state")); + drape_ptr<RenderBucket> bucket = move(it->second); m_buckets.erase(state); bucket->GetBuffer()->Preflush(); - m_flushInterface(state, bucket.Move()); + m_flushInterface(state, move(bucket)); } void Batcher::Flush() @@ -206,26 +209,26 @@ void Batcher::Flush() ASSERT(m_flushInterface != NULL, ()); for_each(m_buckets.begin(), m_buckets.end(), [this](TBuckets::value_type & bucket) { - ASSERT(!bucket.second.IsNull(), ()); + ASSERT(bucket.second != nullptr, ()); bucket.second->GetBuffer()->Preflush(); - m_flushInterface(bucket.first, bucket.second.Move()); + m_flushInterface(bucket.first, move(bucket.second)); }); m_buckets.clear(); } template <typename TBatcher> -IndicesRange Batcher::InsertTriangles(GLState const & state, RefPointer<AttributeProvider> params, - TransferPointer<OverlayHandle> transferHandle, uint8_t vertexStride) +IndicesRange Batcher::InsertTriangles(GLState const & state, ref_ptr<AttributeProvider> params, + drape_ptr<OverlayHandle> && transferHandle, uint8_t vertexStride) { - RefPointer<RenderBucket> bucket = GetBucket(state); - RefPointer<VertexArrayBuffer> vao = bucket->GetBuffer(); + ref_ptr<RenderBucket> bucket = GetBucket(state); + ref_ptr<VertexArrayBuffer> vao = bucket->GetBuffer(); IndicesRange range; - MasterPointer<OverlayHandle> handle(transferHandle); + drape_ptr<OverlayHandle> handle = move(transferHandle); { - Batcher::CallbacksWrapper wrapper(state, handle.GetRefPointer()); + Batcher::CallbacksWrapper wrapper(state, make_ref<OverlayHandle>(handle)); wrapper.SetVAO(vao); BatchCallbacks callbacks; @@ -234,18 +237,18 @@ IndicesRange Batcher::InsertTriangles(GLState const & state, RefPointer<Attribut callbacks.m_submitIndex = bind(&CallbacksWrapper::SubmitIndexes, &wrapper); callbacks.m_getAvailableVertex = bind(&CallbacksWrapper::GetAvailableVertexCount, &wrapper); callbacks.m_getAvailableIndex = bind(&CallbacksWrapper::GetAvailableIndexCount, &wrapper); - callbacks.m_changeBuffer = bind(&Batcher::ChangeBuffer, this, MakeStackRefPointer(&wrapper), _1); + callbacks.m_changeBuffer = bind(&Batcher::ChangeBuffer, this, make_ref(&wrapper), _1); TBatcher batch(callbacks); - batch.SetIsCanDevideStreams(handle.IsNull()); + batch.SetIsCanDevideStreams(handle == nullptr); batch.SetVertexStride(vertexStride); batch.BatchData(params); range = wrapper.Finish(); } - if (!handle.IsNull()) - bucket->AddOverlayHandle(handle.Move()); + if (handle != nullptr) + bucket->AddOverlayHandle(move(handle)); return range; } diff --git a/drape/batcher.hpp b/drape/batcher.hpp index 0069293860..34334f1be4 100644 --- a/drape/batcher.hpp +++ b/drape/batcher.hpp @@ -34,34 +34,34 @@ public: void SetIndexBufferSize(uint32_t indexBufferSize) { m_indexBufferSize = indexBufferSize; } void SetVertexBufferSize(uint32_t vertexBufferSize) { m_vertexBufferSize = vertexBufferSize; } - void InsertTriangleList(GLState const & state, RefPointer<AttributeProvider> params); - IndicesRange InsertTriangleList(GLState const & state, RefPointer<AttributeProvider> params, - TransferPointer<OverlayHandle> handle); + IndicesRange InsertTriangleList(GLState const & state, ref_ptr<AttributeProvider> params); + IndicesRange InsertTriangleList(GLState const & state, ref_ptr<AttributeProvider> params, + drape_ptr<OverlayHandle> && handle); - void InsertTriangleStrip(GLState const & state, RefPointer<AttributeProvider> params); - IndicesRange InsertTriangleStrip(GLState const & state, RefPointer<AttributeProvider> params, - TransferPointer<OverlayHandle> handle); + IndicesRange InsertTriangleStrip(GLState const & state, ref_ptr<AttributeProvider> params); + IndicesRange InsertTriangleStrip(GLState const & state, ref_ptr<AttributeProvider> params, + drape_ptr<OverlayHandle> && handle); - void InsertTriangleFan(GLState const & state, RefPointer<AttributeProvider> params); - IndicesRange InsertTriangleFan(GLState const & state, RefPointer<AttributeProvider> params, - TransferPointer<OverlayHandle> handle); + IndicesRange InsertTriangleFan(GLState const & state, ref_ptr<AttributeProvider> params); + IndicesRange InsertTriangleFan(GLState const & state, ref_ptr<AttributeProvider> params, + drape_ptr<OverlayHandle> && handle); - void InsertListOfStrip(GLState const & state, RefPointer<AttributeProvider> params, uint8_t vertexStride); - IndicesRange InsertListOfStrip(GLState const & state, RefPointer<AttributeProvider> params, - TransferPointer<OverlayHandle> handle, uint8_t vertexStride); + IndicesRange InsertListOfStrip(GLState const & state, ref_ptr<AttributeProvider> params, uint8_t vertexStride); + IndicesRange InsertListOfStrip(GLState const & state, ref_ptr<AttributeProvider> params, + drape_ptr<OverlayHandle> && handle, uint8_t vertexStride); - typedef function<void (GLState const &, TransferPointer<RenderBucket> )> TFlushFn; + typedef function<void (GLState const &, drape_ptr<RenderBucket> &&)> TFlushFn; void StartSession(TFlushFn const & flusher); void EndSession(); private: template<typename TBacher> - IndicesRange InsertTriangles(GLState const & state, RefPointer<AttributeProvider> params, - TransferPointer<OverlayHandle> handle, uint8_t vertexStride = 0); + IndicesRange InsertTriangles(GLState const & state, ref_ptr<AttributeProvider> params, + drape_ptr<OverlayHandle> && handle, uint8_t vertexStride = 0); class CallbacksWrapper; - void ChangeBuffer(RefPointer<CallbacksWrapper> wrapper, bool checkFilledBuffer); - RefPointer<RenderBucket> GetBucket(GLState const & state); + void ChangeBuffer(ref_ptr<CallbacksWrapper> wrapper, bool checkFilledBuffer); + ref_ptr<RenderBucket> GetBucket(GLState const & state); void FinalizeBucket(GLState const & state); void Flush(); @@ -70,7 +70,7 @@ private: TFlushFn m_flushInterface; private: - using TBuckets = map<GLState, MasterPointer<RenderBucket>>; + using TBuckets = map<GLState, drape_ptr<RenderBucket>>; TBuckets m_buckets; uint32_t m_indexBufferSize; diff --git a/drape/batcher_helpers.cpp b/drape/batcher_helpers.cpp index f53485903f..7e1485250d 100644 --- a/drape/batcher_helpers.cpp +++ b/drape/batcher_helpers.cpp @@ -140,7 +140,7 @@ void TriangleBatch::SetVertexStride(uint8_t vertexStride) m_vertexStride = vertexStride; } -void TriangleBatch::FlushData(RefPointer<AttributeProvider> streams, uint16_t vertexVount) const +void TriangleBatch::FlushData(ref_ptr<AttributeProvider> streams, uint16_t vertexVount) const { for (uint8_t i = 0; i < streams->GetStreamCount(); ++i) FlushData(streams->GetBindingInfo(i), streams->GetRawPointer(i), vertexVount); @@ -189,7 +189,7 @@ uint8_t TriangleBatch::GetVertexStride() const TriangleListBatch::TriangleListBatch(BatchCallbacks const & callbacks) : TBase(callbacks) {} -void TriangleListBatch::BatchData(RefPointer<AttributeProvider> streams) +void TriangleListBatch::BatchData(ref_ptr<AttributeProvider> streams) { while (streams->IsDataExists()) { @@ -314,7 +314,7 @@ TriangleStripBatch::TriangleStripBatch(BatchCallbacks const & callbacks) { } -void TriangleStripBatch::BatchData(RefPointer<AttributeProvider> streams) +void TriangleStripBatch::BatchData(ref_ptr<AttributeProvider> streams) { while (streams->IsDataExists()) { @@ -354,7 +354,7 @@ TriangleFanBatch::TriangleFanBatch(BatchCallbacks const & callbacks) : TBase(cal * second part of data. But to avoid 2 separate call of glBufferSubData we at first do a copy of * data from params to cpuBuffer and than copy continuous block of memory from cpuBuffer */ -void TriangleFanBatch::BatchData(RefPointer<AttributeProvider> streams) +void TriangleFanBatch::BatchData(ref_ptr<AttributeProvider> streams) { vector<CPUBuffer> cpuBuffers; while (streams->IsDataExists()) @@ -443,7 +443,7 @@ TriangleListOfStripBatch::TriangleListOfStripBatch(BatchCallbacks const & callba { } -void TriangleListOfStripBatch::BatchData(RefPointer<AttributeProvider> streams) +void TriangleListOfStripBatch::BatchData(ref_ptr<AttributeProvider> streams) { while (streams->IsDataExists()) { diff --git a/drape/batcher_helpers.hpp b/drape/batcher_helpers.hpp index b5644f2994..783d3313d3 100644 --- a/drape/batcher_helpers.hpp +++ b/drape/batcher_helpers.hpp @@ -32,13 +32,13 @@ class TriangleBatch public: TriangleBatch(BatchCallbacks const & callbacks); - virtual void BatchData(RefPointer<AttributeProvider> streams) = 0; + virtual void BatchData(ref_ptr<AttributeProvider> streams) = 0; void SetIsCanDevideStreams(bool canDevide); bool IsCanDevideStreams() const; void SetVertexStride(uint8_t vertexStride); protected: - void FlushData(RefPointer<AttributeProvider> streams, uint16_t vertexVount) const; + void FlushData(ref_ptr<AttributeProvider> streams, uint16_t vertexVount) const; void FlushData(BindingInfo const & info, void const * data, uint16_t elementCount) const; uint16_t * GetIndexStorage(uint16_t indexCount, uint16_t & startIndex); void SubmitIndex(); @@ -61,7 +61,7 @@ class TriangleListBatch : public TriangleBatch public: TriangleListBatch(BatchCallbacks const & callbacks); - virtual void BatchData(RefPointer<AttributeProvider> streams); + virtual void BatchData(ref_ptr<AttributeProvider> streams); }; class FanStripHelper : public TriangleBatch @@ -94,7 +94,7 @@ class TriangleStripBatch : public FanStripHelper public: TriangleStripBatch(BatchCallbacks const & callbacks); - virtual void BatchData(RefPointer<AttributeProvider> streams); + virtual void BatchData(ref_ptr<AttributeProvider> streams); protected: virtual void GenerateIndexes(uint16_t * indexStorage, uint16_t count, uint16_t startIndex) const; }; @@ -106,7 +106,7 @@ class TriangleFanBatch : public FanStripHelper public: TriangleFanBatch(BatchCallbacks const & callbacks); - virtual void BatchData(RefPointer<AttributeProvider> streams); + virtual void BatchData(ref_ptr<AttributeProvider> streams); protected: virtual void GenerateIndexes(uint16_t * indexStorage, uint16_t count, uint16_t startIndex) const; }; @@ -118,7 +118,7 @@ class TriangleListOfStripBatch : public FanStripHelper public: TriangleListOfStripBatch(BatchCallbacks const & callbacks); - virtual void BatchData(RefPointer<AttributeProvider> streams); + virtual void BatchData(ref_ptr<AttributeProvider> streams); protected: virtual uint16_t VtoICount(uint16_t vCount) const; diff --git a/drape/data_buffer.cpp b/drape/data_buffer.cpp index ac123dc91d..3caca0de8e 100644 --- a/drape/data_buffer.cpp +++ b/drape/data_buffer.cpp @@ -5,38 +5,44 @@ namespace dp { DataBuffer::DataBuffer(uint8_t elementSize, uint16_t capacity) + : m_impl(make_unique_dp<CpuBufferImpl>(elementSize, capacity)) { - m_impl.Reset(new CpuBufferImpl(elementSize, capacity)); } DataBuffer::~DataBuffer() { - m_impl.Destroy(); } -dp::RefPointer<DataBufferBase> DataBuffer::GetBuffer() const +ref_ptr<DataBufferBase> DataBuffer::GetBuffer() const { - ASSERT(!m_impl.IsNull(), ()); - return m_impl.GetRefPointer(); + ASSERT(m_impl != nullptr, ()); + return make_ref<DataBufferBase>(m_impl); } void DataBuffer::MoveToGPU(GPUBuffer::Target target) { - dp::MasterPointer<DataBufferBase> newImpl; - // if currentSize is 0 buffer hasn't been filled on preparation stage, let it be filled further uint16_t const currentSize = m_impl->GetCurrentSize(); if (currentSize != 0) - newImpl.Reset(new GpuBufferImpl(target, m_impl->Data(), m_impl->GetElementSize(), currentSize)); + { + drape_ptr<DataBufferBase> newImpl = make_unique_dp<GpuBufferImpl>(target, m_impl->Data(), + m_impl->GetElementSize(), + currentSize); + m_impl.reset(); + m_impl = move(newImpl); + } else - newImpl.Reset(new GpuBufferImpl(target, nullptr, m_impl->GetElementSize(), m_impl->GetAvailableSize())); - - m_impl.Destroy(); - m_impl = newImpl; + { + drape_ptr<DataBufferBase> newImpl = make_unique_dp<GpuBufferImpl>(target, nullptr, + m_impl->GetElementSize(), + m_impl->GetAvailableSize()); + m_impl.reset(); + m_impl = move(newImpl); + } } -DataBufferMapper::DataBufferMapper(RefPointer<DataBuffer> buffer) +DataBufferMapper::DataBufferMapper(ref_ptr<DataBuffer> buffer) : m_buffer(buffer) { m_buffer->GetBuffer()->Bind(); diff --git a/drape/data_buffer.hpp b/drape/data_buffer.hpp index fe254ce40b..724cd33eb4 100644 --- a/drape/data_buffer.hpp +++ b/drape/data_buffer.hpp @@ -33,24 +33,24 @@ public: DataBuffer(uint8_t elementSize, uint16_t capacity); virtual ~DataBuffer(); - dp::RefPointer<DataBufferBase> GetBuffer() const; + ref_ptr<DataBufferBase> GetBuffer() const; void MoveToGPU(GPUBuffer::Target target); private: - dp::MasterPointer<DataBufferBase> m_impl; + drape_ptr<DataBufferBase> m_impl; }; class DataBufferMapper { public: - DataBufferMapper(RefPointer<DataBuffer> buffer); + DataBufferMapper(ref_ptr<DataBuffer> buffer); ~DataBufferMapper(); void UpdateData(void const * data, uint16_t elementOffset, uint16_t elementCount); private: - RefPointer<DataBuffer> m_buffer; + ref_ptr<DataBuffer> m_buffer; void * m_ptr; }; diff --git a/drape/data_buffer_impl.hpp b/drape/data_buffer_impl.hpp index 23b8496764..818b86e4d9 100644 --- a/drape/data_buffer_impl.hpp +++ b/drape/data_buffer_impl.hpp @@ -3,7 +3,6 @@ #include "data_buffer.hpp" #include "cpu_buffer.hpp" #include "gpu_buffer.hpp" - #include "std/utility.hpp" namespace dp @@ -15,13 +14,8 @@ class DataBufferImpl : public DataBufferBase { public: template<typename... Args> DataBufferImpl(Args&&... params) + : m_buffer(make_unique_dp<TBuffer>(forward<Args>(params)...)) { - m_buffer.Reset(new TBuffer(forward<Args>(params)...)); - } - - ~DataBufferImpl() override - { - m_buffer.Destroy(); } uint16_t GetCapacity() const override @@ -50,7 +44,7 @@ public: } protected: - dp::MasterPointer<TBuffer> m_buffer; + drape_ptr<TBuffer> m_buffer; }; /// CPU implementation of data buffer diff --git a/drape/drape_tests/attribute_provides_tests.cpp b/drape/drape_tests/attribute_provides_tests.cpp index abacefdb1e..8b3b7ffb9f 100644 --- a/drape/drape_tests/attribute_provides_tests.cpp +++ b/drape/drape_tests/attribute_provides_tests.cpp @@ -31,7 +31,7 @@ UNIT_TEST(InitStreamsTest) decl.m_componentType = gl_const::GLFloatType; decl.m_offset = 0; decl.m_stride = 0; - provider.InitStream(0, zeroStreamBinding, MakeStackRefPointer(positions)); + provider.InitStream(0, zeroStreamBinding, make_ref(positions)); } { @@ -42,7 +42,7 @@ UNIT_TEST(InitStreamsTest) decl.m_componentType = gl_const::GLFloatType; decl.m_offset = 0; decl.m_stride = 0; - provider.InitStream(1, firstStreamBinding, MakeStackRefPointer(depth)); + provider.InitStream(1, firstStreamBinding, make_ref(depth)); } { @@ -53,7 +53,7 @@ UNIT_TEST(InitStreamsTest) decl.m_componentType = gl_const::GLFloatType; decl.m_offset = 0; decl.m_stride = 0; - provider.InitStream(2, secondStreamBinding, MakeStackRefPointer(normals)); + provider.InitStream(2, secondStreamBinding, make_ref(normals)); } TEST_EQUAL(provider.IsDataExists(), true, ()); @@ -116,7 +116,7 @@ UNIT_TEST(InterleavedStreamTest) decl.m_stride = 5 * sizeof(float); } - provider.InitStream(0, binding, MakeStackRefPointer(data)); + provider.InitStream(0, binding, make_ref(data)); TEST_EQUAL(provider.IsDataExists(), true, ()); TEST_EQUAL(provider.GetVertexCount(), 10, ()); @@ -169,7 +169,7 @@ UNIT_TEST(MixedStreamsTest) decl.m_stride = 3 * sizeof(float); } - provider.InitStream(0, binding, MakeStackRefPointer(position)); + provider.InitStream(0, binding, make_ref(position)); } { @@ -180,7 +180,7 @@ UNIT_TEST(MixedStreamsTest) decl.m_componentType = gl_const::GLFloatType; decl.m_offset = 0; decl.m_stride = 0; - provider.InitStream(1, binding, MakeStackRefPointer(normal)); + provider.InitStream(1, binding, make_ref(normal)); } TEST_EQUAL(provider.IsDataExists(), true, ()); diff --git a/drape/drape_tests/batcher_tests.cpp b/drape/drape_tests/batcher_tests.cpp index e91cdb69b7..de72a84054 100644 --- a/drape/drape_tests/batcher_tests.cpp +++ b/drape/drape_tests/batcher_tests.cpp @@ -31,12 +31,12 @@ namespace struct VAOAcceptor { - virtual void FlushFullBucket(GLState const & /*state*/, TransferPointer<RenderBucket> bucket) + virtual void FlushFullBucket(GLState const & /*state*/, drape_ptr<RenderBucket> && bucket) { - m_vao.push_back(MasterPointer<RenderBucket>(bucket)); + m_vao.push_back(move(bucket)); } - vector<MasterPointer<RenderBucket> > m_vao; + vector<drape_ptr<RenderBucket> > m_vao; }; class BatcherExpectations @@ -70,18 +70,18 @@ public: decl.m_stride = 0; AttributeProvider provider(1, vertexCount); - provider.InitStream(0, binding, MakeStackRefPointer(vertexes)); + provider.InitStream(0, binding, make_ref(vertexes)); VAOAcceptor vaoAcceptor; Batcher batcher; batcher.StartSession(bind(&VAOAcceptor::FlushFullBucket, &vaoAcceptor, _1, _2)); - fn(&batcher, state, MakeStackRefPointer(&provider)); + fn(&batcher, state, make_ref(&provider)); batcher.EndSession(); ExpectBufferDeletion(); for (size_t i = 0; i < vaoAcceptor.m_vao.size(); ++i) - vaoAcceptor.m_vao[i].Destroy(); + vaoAcceptor.m_vao[i].reset(); } void ExpectBufferCreation(uint16_t vertexCount, uint16_t indexCount, @@ -134,7 +134,7 @@ UNIT_TEST(BatchLists_Test) indexes[i] = i; BatcherExpectations expectations; - auto fn = [](Batcher * batcher, GLState const & state, RefPointer<AttributeProvider> p) + auto fn = [](Batcher * batcher, GLState const & state, ref_ptr<AttributeProvider> p) { batcher->InsertTriangleList(state, p); }; @@ -154,7 +154,7 @@ UNIT_TEST(BatchListOfStript_4stride) { 0, 1, 2, 1, 3, 2, 4, 5, 6, 5, 7, 6, 8, 9, 10, 9, 11, 10}; BatcherExpectations expectations; - auto fn = [](Batcher * batcher, GLState const & state, RefPointer<AttributeProvider> p) + auto fn = [](Batcher * batcher, GLState const & state, ref_ptr<AttributeProvider> p) { batcher->InsertListOfStrip(state, p, dp::Batcher::VertexPerQuad); }; @@ -183,7 +183,7 @@ UNIT_TEST(BatchListOfStript_5stride) 12, 13, 14 }; BatcherExpectations expectations; - auto fn = [](Batcher * batcher, GLState const & state, RefPointer<AttributeProvider> p) + auto fn = [](Batcher * batcher, GLState const & state, ref_ptr<AttributeProvider> p) { batcher->InsertListOfStrip(state, p, 5); }; @@ -214,7 +214,7 @@ UNIT_TEST(BatchListOfStript_6stride) 15, 17, 16}; BatcherExpectations expectations; - auto fn = [](Batcher * batcher, GLState const & state, RefPointer<AttributeProvider> p) + auto fn = [](Batcher * batcher, GLState const & state, ref_ptr<AttributeProvider> p) { batcher->InsertListOfStrip(state, p, 6); }; @@ -368,15 +368,15 @@ UNIT_TEST(BatchListOfStript_partial) decl.m_stride = 0; AttributeProvider provider(1, VertexCount); - provider.InitStream(0, binding, MakeStackRefPointer(vertexData)); + provider.InitStream(0, binding, make_ref(vertexData)); VAOAcceptor vaoAcceptor; Batcher batcher(srcData[i].first, srcData[i].second); batcher.StartSession(bind(&VAOAcceptor::FlushFullBucket, &vaoAcceptor, _1, _2)); - batcher.InsertListOfStrip(state, MakeStackRefPointer(&provider), 4); + batcher.InsertListOfStrip(state, make_ref(&provider), 4); batcher.EndSession(); for (size_t i = 0; i < vaoAcceptor.m_vao.size(); ++i) - vaoAcceptor.m_vao[i].Destroy(); + vaoAcceptor.m_vao[i].reset(); } } diff --git a/drape/drape_tests/drape_tests.pro b/drape/drape_tests/drape_tests.pro index f8c85faecb..ac83f3ca15 100644 --- a/drape/drape_tests/drape_tests.pro +++ b/drape/drape_tests/drape_tests.pro @@ -28,7 +28,6 @@ SOURCES += \ attribute_provides_tests.cpp \ compile_shaders_test.cpp \ batcher_tests.cpp \ - pointers_tests.cpp \ bingind_info_tests.cpp \ stipple_pen_tests.cpp \ texture_of_colors_tests.cpp \ diff --git a/drape/drape_tests/dummy_texture.hpp b/drape/drape_tests/dummy_texture.hpp index bff89c075c..0b659c8cf2 100644 --- a/drape/drape_tests/dummy_texture.hpp +++ b/drape/drape_tests/dummy_texture.hpp @@ -6,14 +6,14 @@ class DummyTexture : public dp::Texture { public: - dp::RefPointer<ResourceInfo> FindResource(Key const & key) + ref_ptr<ResourceInfo> FindResource(Key const & key) { bool dummy = false; return FindResource(key, dummy); } - virtual dp::RefPointer<ResourceInfo> FindResource(Key const & /*key*/, bool & /*newResource*/) + virtual ref_ptr<ResourceInfo> FindResource(Key const & /*key*/, bool & /*newResource*/) { - return dp::RefPointer<ResourceInfo>(); + return make_ref<ResourceInfo>(nullptr); } }; diff --git a/drape/drape_tests/font_texture_tests.cpp b/drape/drape_tests/font_texture_tests.cpp index 8b93366832..415d52049f 100644 --- a/drape/drape_tests/font_texture_tests.cpp +++ b/drape/drape_tests/font_texture_tests.cpp @@ -63,12 +63,12 @@ namespace { typedef GlyphIndex TBase; public: - DummyGlyphIndex(m2::PointU size, RefPointer<GlyphManager> mng) + DummyGlyphIndex(m2::PointU size, ref_ptr<GlyphManager> mng) : TBase(size, mng) { } - RefPointer<Texture::ResourceInfo> MapResource(GlyphKey const & key) + ref_ptr<Texture::ResourceInfo> MapResource(GlyphKey const & key) { bool dummy = false; return TBase::MapResource(key, dummy); @@ -93,15 +93,15 @@ UNIT_TEST(UploadingGlyphs) GetPlatform().GetFontNames(args.m_fonts); GlyphManager mng(args); - DummyGlyphIndex index(m2::PointU(64, 64), MakeStackRefPointer(&mng)); + DummyGlyphIndex index(m2::PointU(64, 64), make_ref(&mng)); index.MapResource(GlyphKey(0x58)); index.MapResource(GlyphKey(0x59)); index.MapResource(GlyphKey(0x61)); DummyTexture tex; - tex.Create(64, 64, dp::ALPHA, MakeStackRefPointer<void>(nullptr)); + tex.Create(64, 64, dp::ALPHA, make_ref<void>(nullptr)); EXPECTGL(glTexSubImage2D(_, _, _, _, _, _, _)).WillOnce(Invoke(&r, &UploadedRender::glMemoryToQImage)); - index.UploadResources(MakeStackRefPointer<Texture>(&tex)); + index.UploadResources(make_ref<Texture>(&tex)); index.MapResource(GlyphKey(0x68)); index.MapResource(GlyphKey(0x30)); @@ -111,7 +111,7 @@ UNIT_TEST(UploadingGlyphs) index.MapResource(GlyphKey(0x401)); EXPECTGL(glTexSubImage2D(_, _, _, _, _, _, _)).WillOnce(Invoke(&r, &UploadedRender::glMemoryToQImage)) .WillOnce(Invoke(&r, &UploadedRender::glMemoryToQImage)); - index.UploadResources(MakeStackRefPointer<Texture>(&tex)); + index.UploadResources(make_ref<Texture>(&tex)); RunTestLoop("UploadingGlyphs", bind(&UploadedRender::Render, &r, _1)); } diff --git a/drape/drape_tests/pointers_tests.cpp b/drape/drape_tests/pointers_tests.cpp deleted file mode 100644 index 6fe1b527ff..0000000000 --- a/drape/drape_tests/pointers_tests.cpp +++ /dev/null @@ -1,367 +0,0 @@ -#include "testing/testing.hpp" - -#include "drape/pointers.hpp" - -#include "base/assert.hpp" - -#include "std/string.hpp" -#include "std/shared_ptr.hpp" - -#include <gmock/gmock.h> - -using ::testing::_; -using ::testing::MatcherInterface; -using ::testing::MatchResultListener; -using ::testing::Matcher; - -using my::SrcPoint; -using namespace dp; - -namespace -{ - -template<typename T> -void EmptyFunction(RefPointer<T> p){} - -template<typename T, typename ToDo> -void EmptyFunction(TransferPointer<T> p, ToDo & toDo) -{ - toDo(p); -} - -template<typename T> -void PointerDeleter(TransferPointer<T> p) -{ - p.Destroy(); -} - -#ifdef DEBUG -#ifdef CHECK_POINTERS -class MockAssertExpector -{ -public: - MOCK_CONST_METHOD2(Assert, void(SrcPoint const &, string const &)); -}; - -MockAssertExpector * g_asserter; -my::AssertFailedFn m_defaultAssertFn; -void MyOnAssertFailed(SrcPoint const & src, string const & msg) -{ - g_asserter->Assert(src, msg); -} - -MockAssertExpector * InitAsserter() -{ - if (g_asserter != NULL) - delete g_asserter; - - g_asserter = new MockAssertExpector(); - - m_defaultAssertFn = my::SetAssertFunction(&MyOnAssertFailed); - - return g_asserter; -} - -void DestroyAsserter() -{ - my::SetAssertFunction(m_defaultAssertFn); - delete g_asserter; - g_asserter = NULL; -} -#endif - -SrcPoint ConstructSrcPoint(char const * fileName, char const * function) -{ -#ifndef __OBJC__ - return SrcPoint(fileName, 0, function, "()"); -#else - return SrcPoint(fileName, 0, function); -#endif -} -#endif - -} // namespace - -#ifdef DEBUG - -class SrcPointMatcher : public MatcherInterface<SrcPoint const &> -{ -public: - SrcPointMatcher(char const * fileName, char const * function) - : m_srcPoint(ConstructSrcPoint(fileName, function)) - { - } - - virtual bool MatchAndExplain(SrcPoint const & x, MatchResultListener * listener) const - { - bool res = strcmp(x.FileName(), m_srcPoint.FileName()) == 0 && - strcmp(x.Function(), m_srcPoint.Function()) == 0; - - if (res == false) - (*listener) << "Actual parameter : " << DebugPrint(x); - - return res; - } - - virtual void DescribeTo(::std::ostream * os) const - { - *os << "Expected assert : " << DebugPrint(m_srcPoint); - } - - virtual void DescribeNegationTo(::std::ostream * os) const - { - *os << "Unexpected assert. Expect this : " << DebugPrint(m_srcPoint); - } - -private: - SrcPoint m_srcPoint; -}; - -inline Matcher<SrcPoint const &> SrcPointEq(char const * fileName, char const * function) -{ - return ::testing::MakeMatcher(new SrcPointMatcher(fileName, function)); -} - -#endif - -UNIT_TEST(RefPointer_Positive) -{ - MasterPointer<int> p(new int); - RefPointer<int> refP = p.GetRefPointer(); - - TEST_EQUAL(p.IsNull(), false, ()); - TEST_EQUAL(p.GetRaw(), refP.GetRaw(), ()); - - RefPointer<int> refP2(refP); - - TEST_EQUAL(p.IsNull(), false, ()); - TEST_EQUAL(p.GetRaw(), refP.GetRaw(), ()); - TEST_EQUAL(refP2.GetRaw(), refP.GetRaw(), ()); - - *refP.GetRaw() = 10; - - EmptyFunction(refP); - TEST_EQUAL(p.IsNull(), false, ()); - TEST_EQUAL(p.GetRaw(), refP.GetRaw(), ()); - TEST_EQUAL(refP2.GetRaw(), refP.GetRaw(), ()); - - EmptyFunction(refP2); - TEST_EQUAL(p.IsNull(), false, ()); - TEST_EQUAL(p.GetRaw(), refP.GetRaw(), ()); - TEST_EQUAL(refP2.GetRaw(), refP.GetRaw(), ()); - - refP2 = refP = RefPointer<int>(); - - TEST_EQUAL(p.IsNull(), false, ()); - TEST_EQUAL(refP.IsNull(), true, ()); - TEST_EQUAL(refP2.GetRaw(), refP.GetRaw(), ()); - - p.Destroy(); - TEST_EQUAL(p.IsNull(), true, ()); -} - -#if defined(CHECK_POINTERS) - UNIT_TEST(MasterPointerDestroy_Negative) - { - MockAssertExpector * asserter = InitAsserter(); - - EXPECT_CALL(*asserter, Assert(SrcPointEq("drape/pointers.cpp", "Destroy"), _)).Times(1); - - MasterPointer<int> p(new int); - RefPointer<int> refP(p.GetRefPointer()); - p.Destroy(); - - DestroyAsserter(); - } - - UNIT_TEST(MasterPointer_Leak) - { - MockAssertExpector * asserter = InitAsserter(); - - ::testing::InSequence s; - - EXPECT_CALL(*asserter, Assert(SrcPointEq("drape/pointers.cpp", "Deref"), _)); - - { - MasterPointer<int> p(new int); - } - - DestroyAsserter(); - } -#endif - -UNIT_TEST(TransferPointerConvertion_Positive) -{ - MasterPointer<int> p(new int); - TEST_EQUAL(p.IsNull(), false, ()); - - int * rawP = p.GetRaw(); - - TransferPointer<int> trP = p.Move(); - TEST_EQUAL(p.IsNull(), true, ()); - TEST_EQUAL(trP.IsNull(), false, ()); - - MasterPointer<int> p2(trP); - TEST_EQUAL(p.IsNull(), true, ()); - TEST_EQUAL(trP.IsNull(), true, ()); - TEST_EQUAL(p2.GetRaw(), rawP, ()); - - p2.Destroy(); -} - -UNIT_TEST(TransferPointer_Positive) -{ - MasterPointer<int> p(new int); - TEST_EQUAL(p.IsNull(), false, ()); - - TransferPointer<int> trP = p.Move(); - TEST_EQUAL(p.IsNull(), true, ()); - TEST_EQUAL(trP.IsNull(), false, ()); - PointerDeleter(trP); -} - -namespace -{ - -template <typename T> -struct MasterPointerAccum -{ -public: - MasterPointer<T> m_p; - - void operator() (TransferPointer<T> p) - { - TEST_EQUAL(p.IsNull(), false, ()); - m_p = MasterPointer<T>(p); - TEST_EQUAL(p.IsNull(), true, ()); - } -}; - -} // namespace - -UNIT_TEST(TransferPointerConvertion2_Positive) -{ - MasterPointer<int> p(new int); - TEST_EQUAL(p.IsNull(), false, ()); - - int * rawP = p.GetRaw(); - - MasterPointerAccum<int> accum; - EmptyFunction(p.Move(), accum); - TEST_EQUAL(p.IsNull(), true, ()); - TEST_EQUAL(accum.m_p.GetRaw(), rawP, ()); - - accum.m_p.Destroy(); -} - -#if defined(CHECK_POINTERS) - -namespace -{ - -template <typename T> -struct EmptyTransferAccepter -{ -public: - void operator() (TransferPointer<T> p) - { - TEST_EQUAL(p.IsNull(), false, ()); - TransferPointer<T> p2(p); - TEST_EQUAL(p.IsNull(), true, ()); - TEST_EQUAL(p2.IsNull(), false, ()); - } -}; - -} - -UNIT_TEST(TransferPointer_Leak) -{ - MockAssertExpector * asserter = InitAsserter(); - MasterPointer<int> p(new int); - TEST_EQUAL(p.IsNull(), false, ()); - - EXPECT_CALL(*asserter, Assert(SrcPointEq("drape/pointers.hpp", "~TransferPointer"), _)); - - EmptyTransferAccepter<int> toDo; - EmptyFunction(p.Move(), toDo); - TEST_EQUAL(p.IsNull(), true, ()); - - DestroyAsserter(); -} - -UNIT_TEST(PointerConversionAndLeak) -{ - MockAssertExpector * asserter = InitAsserter(); - - EXPECT_CALL(*asserter, Assert(SrcPointEq("drape/pointers.cpp", "Deref"), _)); - - { - MasterPointer<int> p(new int); - TEST_EQUAL(p.IsNull(), false, ()); - - int * rawP = p.GetRaw(); - - MasterPointerAccum<int> accum; - EmptyFunction(p.Move(), accum); - TEST_EQUAL(p.IsNull(), true, ()); - TEST_EQUAL(accum.m_p.GetRaw(), rawP, ()); - } - - DestroyAsserter(); -} - -#endif - -class Base -{ -public: - Base() {} - virtual ~Base() {} -}; - -class Derived : public Base -{ -public: - Derived() {} -}; - -UNIT_TEST(RefPointerCast) -{ - MasterPointer<Derived> p(new Derived()); - TEST_EQUAL(p.IsNull(), false, ()); - - { - RefPointer<Derived> refP(p.GetRefPointer()); - TEST_EQUAL(p.IsNull(), false, ()); - TEST_EQUAL(p.GetRaw(), refP.GetRaw(), ()); - - RefPointer<Base> refBaseP(refP); - TEST_EQUAL(p.IsNull(), false, ()); - TEST_EQUAL(p.GetRaw(), refP.GetRaw(), ()); - TEST_EQUAL(p.GetRaw(), refBaseP.GetRaw(), ()); - } - - p.Destroy(); -} - -UNIT_TEST(StackPointers) -{ - int data[10]; - { - RefPointer<int> p = MakeStackRefPointer(data); - TEST_EQUAL(p.GetRaw(), data, ()); - } -} - -UNIT_TEST(MoveFreePointers) -{ - int * data = new int; - TransferPointer<int> p = MovePointer(data); - TEST_EQUAL(p.IsNull(), false, ()); - - MasterPointer<int> mP(p); - TEST_EQUAL(p.IsNull(), true, ()); - TEST_EQUAL(mP.GetRaw(), data, ()); - - mP.Destroy(); -} diff --git a/drape/drape_tests/stipple_pen_tests.cpp b/drape/drape_tests/stipple_pen_tests.cpp index d682ce9f7c..26e9874715 100644 --- a/drape/drape_tests/stipple_pen_tests.cpp +++ b/drape/drape_tests/stipple_pen_tests.cpp @@ -45,7 +45,7 @@ namespace { } - RefPointer<Texture::ResourceInfo> MapResource(StipplePenKey const & key) + ref_ptr<Texture::ResourceInfo> MapResource(StipplePenKey const & key) { bool dummy = false; return TBase::MapResource(key, dummy); @@ -420,11 +420,11 @@ UNIT_TEST(StippleMappingTest) info.m_pattern.push_back(10); info.m_pattern.push_back(10); - RefPointer<Texture::ResourceInfo> r1 = index.MapResource(info); + ref_ptr<Texture::ResourceInfo> r1 = index.MapResource(info); TEST(IsRectsEqual(r1->GetTexRect(), m2::RectF(1.0f / width, 1.0f / height, 241.0f / width, 1.0f / height)), ()); - RefPointer<Texture::ResourceInfo> r2 = index.MapResource(info); + ref_ptr<Texture::ResourceInfo> r2 = index.MapResource(info); TEST(IsRectsEqual(r1->GetTexRect(), r2->GetTexRect()), ()); info.m_pattern.clear(); @@ -456,12 +456,12 @@ UNIT_TEST(StippleMappingTest) DummyTexture texture; texture.Create(width, height, dp::ALPHA); - index.UploadResources(MakeStackRefPointer<Texture>(&texture)); + index.UploadResources(make_ref<Texture>(&texture)); StipplePenKey secInfo; secInfo.m_pattern.push_back(20); secInfo.m_pattern.push_back(20); - RefPointer<Texture::ResourceInfo> r12 = index.MapResource(secInfo); + ref_ptr<Texture::ResourceInfo> r12 = index.MapResource(secInfo); TEST(IsRectsEqual(r12->GetTexRect(), m2::RectF(1.0f / width, 7.0f / height, 241.0f / width, 7.0f / height)), ()); @@ -478,6 +478,6 @@ UNIT_TEST(StippleMappingTest) MemoryComparer cmp22(secondUploadSecondPartEtalon, ARRAY_SIZE(secondUploadSecondPartEtalon)); EXPECTGL(glTexSubImage2D(256, 0, 256, 2, AnyOf(gl_const::GLAlpha, gl_const::GLAlpha8), gl_const::GL8BitOnChannel, _)) .WillOnce(Invoke(&cmp22, &MemoryComparer::cmpSubImage)); - index.UploadResources(MakeStackRefPointer<Texture>(&texture)); + index.UploadResources(make_ref<Texture>(&texture)); EXPECTGL(glDeleteTexture(1)); } diff --git a/drape/drape_tests/texture_of_colors_tests.cpp b/drape/drape_tests/texture_of_colors_tests.cpp index 173b5d9bba..318f44a8f1 100644 --- a/drape/drape_tests/texture_of_colors_tests.cpp +++ b/drape/drape_tests/texture_of_colors_tests.cpp @@ -52,7 +52,7 @@ public: { } - RefPointer<Texture::ResourceInfo> MapResource(ColorKey const & key) + ref_ptr<Texture::ResourceInfo> MapResource(ColorKey const & key) { bool dummy = false; return TBase::MapResource(key, dummy); @@ -65,12 +65,12 @@ UNIT_TEST(ColorPalleteMappingTests) { DummyColorPallete cp(m2::PointU(32, 16)); - RefPointer<Texture::ResourceInfo> info1 = cp.MapResource(dp::Color(0, 0, 0, 0)); - RefPointer<Texture::ResourceInfo> info2 = cp.MapResource(dp::Color(1, 1, 1, 1)); - RefPointer<Texture::ResourceInfo> info3 = cp.MapResource(dp::Color(0, 0, 0, 0)); + ref_ptr<Texture::ResourceInfo> info1 = cp.MapResource(dp::Color(0, 0, 0, 0)); + ref_ptr<Texture::ResourceInfo> info2 = cp.MapResource(dp::Color(1, 1, 1, 1)); + ref_ptr<Texture::ResourceInfo> info3 = cp.MapResource(dp::Color(0, 0, 0, 0)); - TEST_NOT_EQUAL(info1.GetRaw(), info2.GetRaw(), ()); - TEST_EQUAL(info1.GetRaw(), info3.GetRaw(), ()); + TEST_NOT_EQUAL(info1, info2, ()); + TEST_EQUAL(info1, info3, ()); TestRects(info1->GetTexRect(), m2::RectF(1.0f / 32.0f, 1.0f / 16, 1.0f / 32.0f, 1.0f / 16)); TestRects(info2->GetTexRect(), m2::RectF(3.0f / 32.0f, 1.0f / 16, @@ -94,7 +94,7 @@ UNIT_TEST(ColorPalleteUploadingSingleRow) DummyTexture texture; texture.Create(width, height, dp::RGBA8); DummyColorPallete cp(m2::PointU(width, height)); - cp.UploadResources(MakeStackRefPointer<Texture>(&texture)); + cp.UploadResources(make_ref<Texture>(&texture)); { cp.MapResource(dp::Color(0xFF, 0, 0, 0)); @@ -119,7 +119,7 @@ UNIT_TEST(ColorPalleteUploadingSingleRow) EXPECTGL(glTexSubImage2D(0, 0, 10, 2, AnyOf(gl_const::GLRGBA, gl_const::GLRGBA8), gl_const::GL8BitOnChannel, _)) .WillOnce(Invoke(&cmp, &MemoryComparer::cmpSubImage)); - cp.UploadResources(MakeStackRefPointer<Texture>(&texture)); + cp.UploadResources(make_ref<Texture>(&texture)); } { @@ -145,7 +145,7 @@ UNIT_TEST(ColorPalleteUploadingSingleRow) EXPECTGL(glTexSubImage2D(10, 0, 10, 2, AnyOf(gl_const::GLRGBA, gl_const::GLRGBA8), gl_const::GL8BitOnChannel, _)) .WillOnce(Invoke(&cmp, &MemoryComparer::cmpSubImage)); - cp.UploadResources(MakeStackRefPointer<Texture>(&texture)); + cp.UploadResources(make_ref<Texture>(&texture)); } EXPECTGL(glDeleteTexture(1)); @@ -186,7 +186,7 @@ UNIT_TEST(ColorPalleteUploadingPartialyRow) EXPECTGL(glTexSubImage2D(0, 0, 12, 2, AnyOf(gl_const::GLRGBA, gl_const::GLRGBA8), gl_const::GL8BitOnChannel, _)) .WillOnce(Invoke(&cmp, &MemoryComparer::cmpSubImage)); - cp.UploadResources(MakeStackRefPointer<Texture>(&texture)); + cp.UploadResources(make_ref<Texture>(&texture)); } { @@ -219,7 +219,7 @@ UNIT_TEST(ColorPalleteUploadingPartialyRow) EXPECTGL(glTexSubImage2D(0, 2, 4, 2, AnyOf(gl_const::GLRGBA, gl_const::GLRGBA8), gl_const::GL8BitOnChannel, _)) .WillOnce(Invoke(&cmp2, &MemoryComparer::cmpSubImage)); - cp.UploadResources(MakeStackRefPointer<Texture>(&texture)); + cp.UploadResources(make_ref<Texture>(&texture)); } @@ -253,7 +253,7 @@ UNIT_TEST(ColorPalleteUploadingMultipyRow) EXPECTGL(glTexSubImage2D(0, 0, 4, 2, AnyOf(gl_const::GLRGBA, gl_const::GLRGBA8), gl_const::GL8BitOnChannel, _)) .WillOnce(Invoke(&cmp, &MemoryComparer::cmpSubImage)); - cp.UploadResources(MakeStackRefPointer<Texture>(&texture)); + cp.UploadResources(make_ref<Texture>(&texture)); } { @@ -297,7 +297,7 @@ UNIT_TEST(ColorPalleteUploadingMultipyRow) EXPECTGL(glTexSubImage2D(0, 2, 8, 4, AnyOf(gl_const::GLRGBA, gl_const::GLRGBA8), gl_const::GL8BitOnChannel, _)) .WillOnce(Invoke(&cmp2, &MemoryComparer::cmpSubImage)); - cp.UploadResources(MakeStackRefPointer<Texture>(&texture)); + cp.UploadResources(make_ref<Texture>(&texture)); } EXPECTGL(glDeleteTexture(1)); diff --git a/drape/drape_tests/uniform_value_tests.cpp b/drape/drape_tests/uniform_value_tests.cpp index df8552fc05..9aba3d4334 100644 --- a/drape/drape_tests/uniform_value_tests.cpp +++ b/drape/drape_tests/uniform_value_tests.cpp @@ -162,8 +162,8 @@ UNIT_TEST(UniformValueTest) EXPECTGL(glDeleteShader(AnyOf(VertexShaderID, FragmentShaderID))).Times(2); } - GpuProgramManager * manager = new GpuProgramManager(); - RefPointer<GpuProgram> program = manager->GetProgram(gpu::TEXTURING_PROGRAM); + drape_ptr<GpuProgramManager> manager = make_unique_dp<GpuProgramManager>(); + ref_ptr<GpuProgram> program = manager->GetProgram(gpu::TEXTURING_PROGRAM); program->Bind(); @@ -211,7 +211,4 @@ UNIT_TEST(UniformValueTest) UniformValue v("viewModel", matrix); v.Apply(program); } - - program = RefPointer<GpuProgram>(); - delete manager; } diff --git a/drape/dynamic_texture.hpp b/drape/dynamic_texture.hpp index 80ba8fe4c8..c19479a707 100644 --- a/drape/dynamic_texture.hpp +++ b/drape/dynamic_texture.hpp @@ -12,23 +12,23 @@ class DynamicTexture : public Texture public: virtual ~DynamicTexture() { - ASSERT(m_indexer.IsNull(), ()); + ASSERT(m_indexer == nullptr, ()); } - virtual RefPointer<ResourceInfo> FindResource(Key const & key, bool & newResource) + virtual ref_ptr<ResourceInfo> FindResource(Key const & key, bool & newResource) { - ASSERT(!m_indexer.IsNull(), ()); + ASSERT(m_indexer != nullptr, ()); if (key.GetType() != TResourceType) - return RefPointer<ResourceInfo>(); + return ref_ptr<ResourceInfo>(); return m_indexer->MapResource(static_cast<TResourceKey const &>(key), newResource); } virtual void UpdateState() { - ASSERT(!m_indexer.IsNull(), ()); + ASSERT(m_indexer != nullptr, ()); Bind(); - m_indexer->UploadResources(MakeStackRefPointer<Texture>(this)); + m_indexer->UploadResources(make_ref<Texture>(this)); } protected: @@ -42,12 +42,12 @@ protected: glConst m_magFilter; }; - void Init(RefPointer<TIndexer> indexer, TextureParams const & params) + void Init(ref_ptr<TIndexer> indexer, TextureParams const & params) { - Init(indexer, params, MakeStackRefPointer<void>(nullptr)); + Init(indexer, params, make_ref<void>(nullptr)); } - void Init(RefPointer<TIndexer> indexer, TextureParams const & params, RefPointer<void> data) + void Init(ref_ptr<TIndexer> indexer, TextureParams const & params, ref_ptr<void> data) { m_indexer = indexer; Create(params.m_size.x, params.m_size.y, params.m_format, data); @@ -56,11 +56,11 @@ protected: void Reset() { - m_indexer = RefPointer<TIndexer>(); + m_indexer = ref_ptr<TIndexer>(); } private: - RefPointer<TIndexer> m_indexer; + ref_ptr<TIndexer> m_indexer; }; } diff --git a/drape/font_texture.cpp b/drape/font_texture.cpp index 41aaab9707..c3e154946a 100644 --- a/drape/font_texture.cpp +++ b/drape/font_texture.cpp @@ -76,7 +76,7 @@ m2::RectF GlyphPacker::MapTextureCoords(const m2::RectU & pixelRect) const bool GlyphPacker::IsFull() const { return m_isFull; } -GlyphIndex::GlyphIndex(m2::PointU size, RefPointer<GlyphManager> mng) +GlyphIndex::GlyphIndex(m2::PointU size, ref_ptr<GlyphManager> mng) : m_packer(size) , m_mng(mng) { @@ -94,13 +94,13 @@ GlyphIndex::~GlyphIndex() } } -RefPointer<Texture::ResourceInfo> GlyphIndex::MapResource(GlyphKey const & key, bool & newResource) +ref_ptr<Texture::ResourceInfo> GlyphIndex::MapResource(GlyphKey const & key, bool & newResource) { newResource = false; strings::UniChar uniChar = key.GetUnicodePoint(); auto it = m_index.find(uniChar); if (it != m_index.end()) - return MakeStackRefPointer<Texture::ResourceInfo>(&it->second); + return make_ref<Texture::ResourceInfo>(&it->second); newResource = true; @@ -109,7 +109,7 @@ RefPointer<Texture::ResourceInfo> GlyphIndex::MapResource(GlyphKey const & key, if (!m_packer.PackGlyph(glyph.m_image.m_width, glyph.m_image.m_height, r)) { glyph.m_image.Destroy(); - return RefPointer<GlyphInfo>(); + return make_ref<GlyphInfo>(nullptr); } { @@ -119,10 +119,10 @@ RefPointer<Texture::ResourceInfo> GlyphIndex::MapResource(GlyphKey const & key, auto res = m_index.emplace(uniChar, GlyphInfo(m_packer.MapTextureCoords(r), glyph.m_metrics)); ASSERT(res.second, ()); - return MakeStackRefPointer<GlyphInfo>(&res.first->second); + return make_ref<GlyphInfo>(&res.first->second); } -void GlyphIndex::UploadResources(RefPointer<Texture> texture) +void GlyphIndex::UploadResources(ref_ptr<Texture> texture) { if (m_pendingNodes.empty()) return; @@ -196,7 +196,7 @@ void GlyphIndex::UploadResources(RefPointer<Texture> texture) glyph.m_image.Destroy(); } - texture->UploadData(zeroPoint.x, zeroPoint.y, width, height, dp::ALPHA, MakeStackRefPointer<void>(dstMemory)); + texture->UploadData(zeroPoint.x, zeroPoint.y, width, height, dp::ALPHA, make_ref<void>(dstMemory)); SharedBufferManager::instance().freeSharedBuffer(byteCount, buffer); } } diff --git a/drape/font_texture.hpp b/drape/font_texture.hpp index 178e8fa33b..684af4b8ae 100644 --- a/drape/font_texture.hpp +++ b/drape/font_texture.hpp @@ -60,19 +60,19 @@ private: class GlyphIndex { public: - GlyphIndex(m2::PointU size, RefPointer<GlyphManager> mng); + GlyphIndex(m2::PointU size, ref_ptr<GlyphManager> mng); ~GlyphIndex(); /// can return nullptr - RefPointer<Texture::ResourceInfo> MapResource(GlyphKey const & key, bool & newResource); - void UploadResources(RefPointer<Texture> texture); + ref_ptr<Texture::ResourceInfo> MapResource(GlyphKey const & key, bool & newResource); + void UploadResources(ref_ptr<Texture> texture); glConst GetMinFilter() const { return gl_const::GLLinear; } glConst GetMagFilter() const { return gl_const::GLLinear; } private: GlyphPacker m_packer; - RefPointer<GlyphManager> m_mng; + ref_ptr<GlyphManager> m_mng; typedef map<strings::UniChar, GlyphInfo> TResourceMapping; typedef pair<m2::RectU, GlyphManager::Glyph> TPendingNode; @@ -87,7 +87,7 @@ class FontTexture : public DynamicTexture<GlyphIndex, GlyphKey, Texture::Glyph> { typedef DynamicTexture<GlyphIndex, GlyphKey, Texture::Glyph> TBase; public: - FontTexture(m2::PointU const & size, RefPointer<GlyphManager> glyphMng) + FontTexture(m2::PointU const & size, ref_ptr<GlyphManager> glyphMng) : m_index(size, glyphMng) { TBase::TextureParams params; @@ -97,7 +97,7 @@ public: params.m_magFilter = gl_const::GLLinear; vector<uint8_t> initData(params.m_size.x * params.m_size.y, 0); - TBase::Init(MakeStackRefPointer(&m_index), params, MakeStackRefPointer<void>(initData.data())); + TBase::Init(make_ref(&m_index), params, make_ref<void>(initData.data())); } ~FontTexture() { TBase::Reset(); } diff --git a/drape/glstate.cpp b/drape/glstate.cpp index 495cf9f193..a94f6d534f 100644 --- a/drape/glstate.cpp +++ b/drape/glstate.cpp @@ -52,6 +52,8 @@ bool Blending::operator == (Blending const & other) const GLState::GLState(uint32_t gpuProgramIndex, DepthLayer depthLayer) : m_gpuProgramIndex(gpuProgramIndex) , m_depthLayer(depthLayer) + , m_colorTexture(make_ref<Texture>(nullptr)) + , m_maskTexture(make_ref<Texture>(nullptr)) { } @@ -63,10 +65,10 @@ bool GLState::operator<(GLState const & other) const return m_blending < other.m_blending; if (m_gpuProgramIndex != other.m_gpuProgramIndex) return m_gpuProgramIndex < other.m_gpuProgramIndex; - if (m_colorTexture.GetRaw() != other.m_colorTexture.GetRaw()) - return m_colorTexture.GetRaw() < other.m_colorTexture.GetRaw(); + if (m_colorTexture != other.m_colorTexture) + return m_colorTexture < other.m_colorTexture; - return m_maskTexture.GetRaw() < other.m_maskTexture.GetRaw(); + return m_maskTexture < other.m_maskTexture; } bool GLState::operator==(GLState const & other) const @@ -80,21 +82,21 @@ bool GLState::operator==(GLState const & other) const namespace { - void ApplyUniformValue(UniformValue const & value, RefPointer<GpuProgram> program) + void ApplyUniformValue(UniformValue const & value, ref_ptr<GpuProgram> program) { value.Apply(program); } } -void ApplyUniforms(UniformValuesStorage const & uniforms, RefPointer<GpuProgram> program) +void ApplyUniforms(UniformValuesStorage const & uniforms, ref_ptr<GpuProgram> program) { uniforms.ForeachValue(bind(&ApplyUniformValue, _1, program)); } -void ApplyState(GLState state, RefPointer<GpuProgram> program) +void ApplyState(GLState state, ref_ptr<GpuProgram> program) { - RefPointer<Texture> tex = state.GetColorTexture(); - if (!tex.IsNull()) + ref_ptr<Texture> tex = state.GetColorTexture(); + if (tex != nullptr) { int8_t const colorTexLoc = program->GetUniformLocation("u_colorTex"); GLFunctions::glActiveTexture(gl_const::GLTexture0); @@ -103,7 +105,7 @@ void ApplyState(GLState state, RefPointer<GpuProgram> program) } tex = state.GetMaskTexture(); - if (!tex.IsNull()) + if (tex != nullptr) { int8_t const maskTexLoc = program->GetUniformLocation("u_maskTex"); GLFunctions::glActiveTexture(gl_const::GLTexture0 + 1); diff --git a/drape/glstate.hpp b/drape/glstate.hpp index 36326bfaff..931225ca68 100644 --- a/drape/glstate.hpp +++ b/drape/glstate.hpp @@ -40,11 +40,11 @@ public: DepthLayer const & GetDepthLayer() const { return m_depthLayer; } - void SetColorTexture(RefPointer<Texture> tex) { m_colorTexture = tex; } - RefPointer<Texture> GetColorTexture() const { return m_colorTexture; } + void SetColorTexture(ref_ptr<Texture> tex) { m_colorTexture = tex; } + ref_ptr<Texture> GetColorTexture() const { return m_colorTexture; } - void SetMaskTexture(RefPointer<Texture> tex) { m_maskTexture = tex; } - RefPointer<Texture> GetMaskTexture() const { return m_maskTexture; } + void SetMaskTexture(ref_ptr<Texture> tex) { m_maskTexture = tex; } + ref_ptr<Texture> GetMaskTexture() const { return m_maskTexture; } void SetBlending(Blending const & blending) { m_blending = blending; } Blending const & GetBlending() const { return m_blending; } @@ -59,11 +59,11 @@ private: DepthLayer m_depthLayer; Blending m_blending; - RefPointer<Texture> m_colorTexture; - RefPointer<Texture> m_maskTexture; + ref_ptr<Texture> m_colorTexture; + ref_ptr<Texture> m_maskTexture; }; -void ApplyUniforms(UniformValuesStorage const & uniforms, RefPointer<GpuProgram> program); -void ApplyState(GLState state, RefPointer<GpuProgram> program); +void ApplyUniforms(UniformValuesStorage const & uniforms, ref_ptr<GpuProgram> program); +void ApplyState(GLState state, ref_ptr<GpuProgram> program); } // namespace dp diff --git a/drape/gpu_program.cpp b/drape/gpu_program.cpp index 91e567da28..4390c30ec8 100644 --- a/drape/gpu_program.cpp +++ b/drape/gpu_program.cpp @@ -53,7 +53,7 @@ namespace dp #endif // UniformValidator -GpuProgram::GpuProgram(RefPointer<Shader> vertexShader, RefPointer<Shader> fragmentShader) +GpuProgram::GpuProgram(ref_ptr<Shader> vertexShader, ref_ptr<Shader> fragmentShader) { m_programID = GLFunctions::glCreateProgram(); GLFunctions::glAttachShader(m_programID, vertexShader->GetID()); diff --git a/drape/gpu_program.hpp b/drape/gpu_program.hpp index 1e47dbd073..844da3ac1b 100644 --- a/drape/gpu_program.hpp +++ b/drape/gpu_program.hpp @@ -22,8 +22,8 @@ namespace dp class GpuProgram { public: - GpuProgram(RefPointer<Shader> vertexShader, - RefPointer<Shader> fragmentShader); + GpuProgram(ref_ptr<Shader> vertexShader, + ref_ptr<Shader> fragmentShader); ~GpuProgram(); void Bind(); diff --git a/drape/gpu_program_manager.cpp b/drape/gpu_program_manager.cpp index b47b1cb1fa..c238575390 100644 --- a/drape/gpu_program_manager.cpp +++ b/drape/gpu_program_manager.cpp @@ -35,40 +35,42 @@ static ShaderMapper s_mapper; GpuProgramManager::~GpuProgramManager() { - (void)GetRangeDeletor(m_programs, MasterPointerDeleter())(); - (void)GetRangeDeletor(m_shaders, MasterPointerDeleter())(); + m_programs.clear(); + m_shaders.clear(); } -RefPointer<GpuProgram> GpuProgramManager::GetProgram(int index) +ref_ptr<GpuProgram> GpuProgramManager::GetProgram(int index) { program_map_t::iterator it = m_programs.find(index); if (it != m_programs.end()) - return it->second.GetRefPointer(); + return make_ref<GpuProgram>(it->second); gpu::ProgramInfo const & programInfo = s_mapper.GetShaders(index); - RefPointer<Shader> vertexShader = GetShader(programInfo.m_vertexIndex, - programInfo.m_vertexSource, - Shader::VertexShader); - RefPointer<Shader> fragmentShader = GetShader(programInfo.m_fragmentIndex, - programInfo.m_fragmentSource, - Shader::FragmentShader); + ref_ptr<Shader> vertexShader = GetShader(programInfo.m_vertexIndex, + programInfo.m_vertexSource, + Shader::VertexShader); + ref_ptr<Shader> fragmentShader = GetShader(programInfo.m_fragmentIndex, + programInfo.m_fragmentSource, + Shader::FragmentShader); - MasterPointer<GpuProgram> & result = m_programs[index]; - result.Reset(new GpuProgram(vertexShader, fragmentShader)); - return result.GetRefPointer(); + drape_ptr<GpuProgram> program = make_unique_dp<GpuProgram>(vertexShader, fragmentShader); + ref_ptr<GpuProgram> result = make_ref<GpuProgram>(program); + m_programs.emplace(index, move(program)); + + return result; } -RefPointer<Shader> GpuProgramManager::GetShader(int index, string const & source, Shader::Type t) +ref_ptr<Shader> GpuProgramManager::GetShader(int index, string const & source, Shader::Type t) { shader_map_t::iterator it = m_shaders.find(index); if (it == m_shaders.end()) { - MasterPointer<Shader> & shader = m_shaders[index]; - shader.Reset(new Shader(source, t)); - return shader.GetRefPointer(); + drape_ptr<Shader> shader = make_unique_dp<Shader>(source, t); + ref_ptr<Shader> result = make_ref<Shader>(shader); + m_shaders.emplace(index, move(shader)); + return result; } - else - return it->second.GetRefPointer(); + return make_ref<Shader>(it->second); } } // namespace dp diff --git a/drape/gpu_program_manager.hpp b/drape/gpu_program_manager.hpp index 5a7a5662d9..d8ad24ceb5 100644 --- a/drape/gpu_program_manager.hpp +++ b/drape/gpu_program_manager.hpp @@ -15,14 +15,14 @@ class GpuProgramManager : public noncopyable public: ~GpuProgramManager(); - RefPointer<GpuProgram> GetProgram(int index); + ref_ptr<GpuProgram> GetProgram(int index); private: - RefPointer<Shader> GetShader(int index, string const & source, Shader::Type t); + ref_ptr<Shader> GetShader(int index, string const & source, Shader::Type t); private: - typedef map<int, MasterPointer<GpuProgram> > program_map_t; - typedef map<int, MasterPointer<Shader> > shader_map_t; + typedef map<int, drape_ptr<GpuProgram> > program_map_t; + typedef map<int, drape_ptr<Shader> > shader_map_t; program_map_t m_programs; shader_map_t m_shaders; }; diff --git a/drape/overlay_handle.cpp b/drape/overlay_handle.cpp index 679bdf894d..41bbb9a444 100644 --- a/drape/overlay_handle.cpp +++ b/drape/overlay_handle.cpp @@ -44,13 +44,13 @@ void OverlayHandle::SetIsVisible(bool isVisible) m_isVisible = isVisible; } -bool OverlayHandle::IsIntersect(ScreenBase const & screen, OverlayHandle const & h) const +bool OverlayHandle::IsIntersect(ScreenBase const & screen, ref_ptr<OverlayHandle> const h) const { Rects ar1; Rects ar2; GetPixelShape(screen, ar1); - h.GetPixelShape(screen, ar2); + h->GetPixelShape(screen, ar2); for (size_t i = 0; i < ar1.size(); ++i) for (size_t j = 0; j < ar2.size(); ++j) @@ -66,13 +66,13 @@ uint16_t * OverlayHandle::IndexStorage(uint16_t size) return &m_indexes[0]; } -void OverlayHandle::GetElementIndexes(RefPointer<IndexBufferMutator> mutator) const +void OverlayHandle::GetElementIndexes(ref_ptr<IndexBufferMutator> mutator) const { ASSERT_EQUAL(m_isVisible, true, ()); mutator->AppendIndexes(&m_indexes[0], m_indexes.size()); } -void OverlayHandle::GetAttributeMutation(RefPointer<AttributeBufferMutator> mutator, ScreenBase const & screen) const +void OverlayHandle::GetAttributeMutation(ref_ptr<AttributeBufferMutator> mutator, ScreenBase const & screen) const { UNUSED_VALUE(mutator); UNUSED_VALUE(screen); diff --git a/drape/overlay_handle.hpp b/drape/overlay_handle.hpp index 142472ff1c..2ee3bec2f7 100644 --- a/drape/overlay_handle.hpp +++ b/drape/overlay_handle.hpp @@ -37,12 +37,12 @@ public: virtual void GetPixelShape(ScreenBase const & screen, Rects & rects) const = 0; - bool IsIntersect(ScreenBase const & screen, OverlayHandle const & h) const; + bool IsIntersect(ScreenBase const & screen, ref_ptr<OverlayHandle> const h) const; virtual bool IndexesRequired() const { return true; } uint16_t * IndexStorage(uint16_t size); - void GetElementIndexes(RefPointer<IndexBufferMutator> mutator) const; - virtual void GetAttributeMutation(RefPointer<AttributeBufferMutator> mutator, ScreenBase const & screen) const; + void GetElementIndexes(ref_ptr<IndexBufferMutator> mutator) const; + virtual void GetAttributeMutation(ref_ptr<AttributeBufferMutator> mutator, ScreenBase const & screen) const; bool HasDynamicAttributes() const; void AddDynamicAttribute(BindingInfo const & binding, uint16_t offset, uint16_t count); diff --git a/drape/overlay_tree.cpp b/drape/overlay_tree.cpp index 846025ce56..7fd5c2b9dc 100644 --- a/drape/overlay_tree.cpp +++ b/drape/overlay_tree.cpp @@ -12,7 +12,7 @@ void OverlayTree::StartOverlayPlacing(ScreenBase const & screen, bool canOverlap ASSERT(IsEmpty(), ()); } -void OverlayTree::Add(RefPointer<OverlayHandle> handle) +void OverlayTree::Add(ref_ptr<OverlayHandle> handle) { ScreenBase const & modelView = GetModelView(); @@ -29,15 +29,15 @@ void OverlayTree::Add(RefPointer<OverlayHandle> handle) return; } - typedef buffer_vector<RefPointer<OverlayHandle>, 8> OverlayContainerT; + typedef buffer_vector<ref_ptr<OverlayHandle>, 8> OverlayContainerT; OverlayContainerT elements; /* * Find elements that already on OverlayTree and it's pixel rect * intersect with handle pixel rect ("Intersected elements") */ - ForEachInRect(pixelRect, [&] (RefPointer<OverlayHandle> r) + ForEachInRect(pixelRect, [&] (ref_ptr<OverlayHandle> r) { - if (handle->IsIntersect(modelView, *r.GetRaw())) + if (handle->IsIntersect(modelView, r)) elements.push_back(r); }); @@ -60,7 +60,7 @@ void OverlayTree::Add(RefPointer<OverlayHandle> handle) void OverlayTree::EndOverlayPlacing() { - ForEach([] (RefPointer<OverlayHandle> handle) + ForEach([] (ref_ptr<OverlayHandle> handle) { handle->SetIsVisible(true); }); diff --git a/drape/overlay_tree.hpp b/drape/overlay_tree.hpp index 252c60dab4..b389c69eb6 100644 --- a/drape/overlay_tree.hpp +++ b/drape/overlay_tree.hpp @@ -16,7 +16,7 @@ struct OverlayTraits { ScreenBase m_modelView; - inline m2::RectD const LimitRect(RefPointer<OverlayHandle> handle) + inline m2::RectD const LimitRect(ref_ptr<OverlayHandle> handle) { return handle->GetPixelRect(m_modelView); } @@ -24,13 +24,13 @@ struct OverlayTraits } -class OverlayTree : public m4::Tree<RefPointer<OverlayHandle>, detail::OverlayTraits> +class OverlayTree : public m4::Tree<ref_ptr<OverlayHandle>, detail::OverlayTraits> { - typedef m4::Tree<RefPointer<OverlayHandle>, detail::OverlayTraits> BaseT; + typedef m4::Tree<ref_ptr<OverlayHandle>, detail::OverlayTraits> BaseT; public: void StartOverlayPlacing(ScreenBase const & screen, bool canOverlap = false); - void Add(RefPointer<OverlayHandle> handle); + void Add(ref_ptr<OverlayHandle> handle); void EndOverlayPlacing(); private: diff --git a/drape/pointers.cpp b/drape/pointers.cpp index fef3831d88..b157791747 100644 --- a/drape/pointers.cpp +++ b/drape/pointers.cpp @@ -1,46 +1,44 @@ #include "drape/pointers.hpp" +#include "base/logging.hpp" -namespace dp +DpPointerTracker & DpPointerTracker::Instance() { + static DpPointerTracker pointersTracker; + return pointersTracker; +} -PointerTracker::~PointerTracker() +DpPointerTracker::~DpPointerTracker() { - ASSERT(m_countMap.empty(), ()); + ASSERT(m_alivePointers.empty(), ()); } -void PointerTracker::Deref(void * p) +void DpPointerTracker::DestroyPtr(void * p) { - threads::MutexGuard g(m_mutex); - if (p == NULL) - return; - - map_t::iterator it = m_countMap.find(p); - ASSERT(it != m_countMap.end(), ()); - ASSERT(it->second.first > 0, ()); - - if (--it->second.first == 0) + lock_guard<mutex> lock(m_mutex); + ASSERT(p != nullptr, ()); + auto it = m_alivePointers.find(p); + if (it != m_alivePointers.end()) { - ASSERT(m_alivePointers.find(p) == m_alivePointers.end(), ("Pointer leak for type : ", it->second.second)); - m_countMap.erase(it); + if (it->second.first != 0) + { + LOG(LWARNING, ("Drape pointer [", it->second.second, p, + "] was destroyed, but had references, ref count = ", + it->second.first)); + } + m_alivePointers.erase(it); } } -void PointerTracker::Destroy(void * p) +void DpPointerTracker::DerefPtr(void * p) { - threads::MutexGuard g(m_mutex); - if (p == NULL) - return; - - map_t::iterator it = m_countMap.find(p); - if (it == m_countMap.end()) // suppress warning in release build - ASSERT(false, ()); - - ASSERT(it->second.first == 1, ("Delete memory with more than one user : ", it->second.second)); - ASSERT(m_alivePointers.erase(p) == 1, ()); + lock_guard<mutex> lock(m_mutex); + if (p != nullptr) + { + auto it = m_alivePointers.find(p); + if (it != m_alivePointers.end()) + { + ASSERT(it->second.first > 0, ()); + it->second.first--; + } + } } - -#if defined(CHECK_POINTERS) - PointerTracker g_tracker; -#endif - -} // namespace dp diff --git a/drape/pointers.hpp b/drape/pointers.hpp index 93548314d1..1ef1166f40 100644 --- a/drape/pointers.hpp +++ b/drape/pointers.hpp @@ -4,317 +4,214 @@ #include "base/mutex.hpp" #include "std/map.hpp" +#include "std/mutex.hpp" #include "std/typeinfo.hpp" -namespace dp -{ +//#define TRACK_POINTERS -class PointerTracker +/// This class tracks usage of drape_ptr's and ref_ptr's +class DpPointerTracker { public: - ~PointerTracker(); + static DpPointerTracker & Instance(); template <typename T> - void Ref(T * p, bool needDestroyCheck) + void RefPtr(T * refPtr) { - threads::MutexGuard g(m_mutex); - if (p == nullptr) - return; - - map_t::iterator it = m_countMap.find(p); - if (it == m_countMap.end()) + lock_guard<mutex> lock(m_mutex); + if (refPtr != nullptr) { - m_countMap.insert(make_pair((void *)p, make_pair(1, typeid(p).name()))); - if (needDestroyCheck) - m_alivePointers.insert(p); + auto it = m_alivePointers.find(refPtr); + if (it != m_alivePointers.end()) + it->second.first++; + else + m_alivePointers.insert(make_pair(refPtr, make_pair(1, typeid(refPtr).name()))); } - else - it->second.first++; } - void Deref(void * p); - void Destroy(void * p); + void DerefPtr(void * p); + + void DestroyPtr(void * p); private: - typedef map<void *, pair<int, string> > map_t; - map_t m_countMap; - typedef set<void *> alive_pointers_t; - alive_pointers_t m_alivePointers; - threads::Mutex m_mutex; -}; + DpPointerTracker() = default; + ~DpPointerTracker(); -#define DISABLE_DEBUG_PRT_TRACKING + typedef map<void *, pair<int, string> > TAlivePointers; + TAlivePointers m_alivePointers; + mutex m_mutex; +}; -#if defined(DEBUG) && !defined(DISABLE_DEBUG_PRT_TRACKING) - #define CHECK_POINTERS -#endif +// Custom deleter for unique_ptr +class DpPointerDeleter +{ +public: + template <typename T> + void operator()(T * p) + { + DpPointerTracker::Instance().DestroyPtr(p); + delete p; + } +}; -#if defined(CHECK_POINTERS) - extern PointerTracker g_tracker; +#if defined(TRACK_POINTERS) - #define REF_POINTER(p, c) g_tracker.Ref(p, c) - #define DEREF_POINTER(p) g_tracker.Deref(p) - #define DESTROY_POINTER(p) g_tracker.Destroy(p) +template<typename T> using drape_ptr = unique_ptr<T, DpPointerDeleter>; - #define DECLARE_CHECK bool m_checkOnDestroy - #define DECLARE_CHECK_GET bool IsCheckOnDestroy() const { return m_checkOnDestroy; } - #define DECLARE_CHECK_SET void SetCheckOnDestroy(bool doCheck) { m_checkOnDestroy = doCheck; } - #define SET_CHECK_FLAG(x) SetCheckOnDestroy(x) - #define GET_CHECK_FLAG(x) (x).IsCheckOnDestroy() - #define ASSERT_CHECK_FLAG(x) ASSERT(GET_CHECK_FLAG(x), ()) -#else - #define REF_POINTER(p, c) - #define DEREF_POINTER(p) - #define DESTROY_POINTER(p) - - #define DECLARE_CHECK - #define DECLARE_CHECK_GET - #define DECLARE_CHECK_SET - #define SET_CHECK_FLAG(x) - #define GET_CHECK_FLAG(x) false - #define ASSERT_CHECK_FLAG(x) -#endif +template <typename T, typename... Args> +drape_ptr<T> make_unique_dp(Args &&... args) +{ + return drape_ptr<T>(new T(std::forward<Args>(args)...)); +} -template <typename T> -class DrapePointer +template<typename T> +class ref_ptr { public: - DrapePointer() : m_p(nullptr) { SET_CHECK_FLAG(true); } + ref_ptr() + : m_ptr(nullptr), m_isOwnerUnique(false) + {} - bool operator==(DrapePointer<T> const & other) const + ref_ptr(T * ptr, bool isOwnerUnique = false) + : m_ptr(ptr), m_isOwnerUnique(isOwnerUnique) { - return m_p == other.m_p; + if (m_isOwnerUnique) + DpPointerTracker::Instance().RefPtr(m_ptr); } -protected: - DrapePointer(T * p, bool needDestroyedCheck = true) - : m_p(p) + ref_ptr(ref_ptr const & rhs) + : m_ptr(rhs.m_ptr), m_isOwnerUnique(rhs.m_isOwnerUnique) { - SET_CHECK_FLAG(needDestroyedCheck); - REF_POINTER(m_p, GET_CHECK_FLAG(*this)); + if (m_isOwnerUnique) + DpPointerTracker::Instance().RefPtr(m_ptr); } - DrapePointer(DrapePointer<T> const & other) : m_p(nullptr) + ref_ptr(ref_ptr && rhs) { - SET_CHECK_FLAG(GET_CHECK_FLAG(other)); - Reset(other.GetNonConstRaw()); - } + m_ptr = rhs.m_ptr; + rhs.m_ptr = nullptr; - DrapePointer<T> & operator=(DrapePointer<T> const & other) - { - SET_CHECK_FLAG(GET_CHECK_FLAG(other)); - Reset(other.GetNonConstRaw()); - return *this; + m_isOwnerUnique = rhs.m_isOwnerUnique; + rhs.m_isOwnerUnique = false; } - void Destroy() + ~ref_ptr() { - DESTROY_POINTER(m_p); - delete m_p; - DEREF_POINTER(m_p); - m_p = nullptr; + if (m_isOwnerUnique) + DpPointerTracker::Instance().DerefPtr(m_ptr); + m_ptr = nullptr; } - void Reset(T * p) - { - ResetImpl(p); - } + T * operator->() const { return m_ptr; } - T * GetRaw() { return m_p; } - T const * GetRaw() const { return m_p; } - T * GetNonConstRaw() const { return m_p; } + template<typename TResult> + operator TResult const *() const { return static_cast<TResult const *>(m_ptr); } - DECLARE_CHECK_GET; - DECLARE_CHECK_SET; + template<typename TResult> + operator TResult *() const { return static_cast<TResult *>(m_ptr); } - // Need to be const for copy constructor and assigment operator of TransfromPointer - void SetToNull() const + template<typename TResult> + operator ref_ptr<TResult>() const { - ResetImpl(nullptr); + return ref_ptr<TResult>(static_cast<TResult *>(m_ptr), m_isOwnerUnique); } -private: - void ResetImpl(T * p) const - { - DEREF_POINTER(m_p); - m_p = p; - REF_POINTER(m_p, GET_CHECK_FLAG(*this)); - } + operator bool() const { return m_ptr != nullptr; } -private: - // Mutable for Move method - mutable T * m_p; - DECLARE_CHECK; -}; + bool operator==(ref_ptr const & rhs) const { return m_ptr == rhs.m_ptr; } -template <typename T> class MasterPointer; + bool operator==(T * rhs) const { return m_ptr == rhs; } -template <typename T> -class TransferPointer : public DrapePointer<T> -{ - typedef DrapePointer<T> base_t; -public: - TransferPointer(TransferPointer<T> const & other) - : base_t(other) + bool operator!=(ref_ptr const & rhs) const { return !operator==(rhs); } + + bool operator!=(T * rhs) const { return !operator==(rhs); } + + bool operator<(ref_ptr const & rhs) const { return m_ptr < rhs.m_ptr; } + + template<typename TResult, class = typename enable_if<!is_void<TResult>::value>::type> + TResult & operator*() const { - ASSERT_CHECK_FLAG(other); - other.SetToNull(); + return *m_ptr; } - TransferPointer<T> & operator=(TransferPointer<T> const & other) + ref_ptr & operator=(ref_ptr const & rhs) { - ASSERT_CHECK_FLAG(other); - base_t::operator =(other); - other.SetToNull(); + if (this == &rhs) + return *this; + + if (m_isOwnerUnique) + DpPointerTracker::Instance().DerefPtr(m_ptr); + + m_ptr = rhs.m_ptr; + m_isOwnerUnique = rhs.m_isOwnerUnique; + + if (m_isOwnerUnique) + DpPointerTracker::Instance().RefPtr(m_ptr); + return *this; } - ~TransferPointer() + ref_ptr & operator=(ref_ptr && rhs) { - ASSERT(base_t::GetRaw() == nullptr, ()); - Destroy(); - } - void Destroy() { base_t::Destroy(); } - // IsNull need for test - bool IsNull() { return base_t::GetRaw() == nullptr; } + if (this == &rhs) + return *this; -private: - friend class MasterPointer<T>; - TransferPointer() {} - explicit TransferPointer(T * p) : base_t(p) {} -}; + if (m_isOwnerUnique) + DpPointerTracker::Instance().DerefPtr(m_ptr); -template <typename T> class RefPointer; -template <typename T> RefPointer<T> MakeStackRefPointer(T * p); + m_ptr = rhs.m_ptr; + rhs.m_ptr = nullptr; -template<typename T> -class RefPointer : public DrapePointer<T> -{ - typedef DrapePointer<T> base_t; -public: - RefPointer() : base_t() {} - ~RefPointer() { base_t::Reset(nullptr); } + m_isOwnerUnique = rhs.m_isOwnerUnique; + rhs.m_isOwnerUnique = false; - template <typename Y> - RefPointer(RefPointer<Y> const & p) : base_t(p.GetNonConstRaw(), GET_CHECK_FLAG(p)) {} - - bool IsContentLess(RefPointer<T> const & other) const { return *GetRaw() < *other.GetRaw(); } - bool IsNull() const { return base_t::GetRaw() == nullptr; } - T * operator->() { return base_t::GetRaw(); } - T const * operator->() const { return base_t::GetRaw(); } - T * GetRaw() { return base_t::GetRaw(); } - T const * GetRaw() const { return base_t::GetRaw(); } + return *this; + } private: - template <typename Y> friend class RefPointer; - friend class MasterPointer<T>; - friend RefPointer<T> MakeStackRefPointer<T>(T *); - explicit RefPointer(T * p, bool needDestroyedCheck = true) : base_t(p, needDestroyedCheck) {} + T* m_ptr; + bool m_isOwnerUnique; }; template <typename T> -RefPointer<T> MakeStackRefPointer(T * p) { return RefPointer<T>(p, false); } +inline string DebugPrint(ref_ptr<T> const & v) +{ + return DebugPrint(static_cast<T*>(v)); +} template <typename T> -RefPointer<void> StackVoidRef(T * p) +ref_ptr<T> make_ref(drape_ptr<T> const & drapePtr) { - return MakeStackRefPointer<void>(p); + return ref_ptr<T>(drapePtr.get(), true); } template <typename T> -class MasterPointer : public DrapePointer<T> +ref_ptr<T> make_ref(T* ptr) { - typedef DrapePointer<T> TBase; - -public: - MasterPointer() : TBase() {} - explicit MasterPointer(T * p) : TBase(p) {} - explicit MasterPointer(TransferPointer<T> & transferPointer) - { - Reset(transferPointer.GetRaw()); - transferPointer.Reset(nullptr); - } - - explicit MasterPointer(TransferPointer<T> && transferPointer) - { - Reset(transferPointer.GetRaw()); - transferPointer.Reset(nullptr); - } - - ~MasterPointer() - { - TBase::Reset(nullptr); - } - - RefPointer<T> GetRefPointer() const - { - return RefPointer<T>(TBase::GetNonConstRaw()); - } - - TransferPointer<T> Move() - { - TransferPointer<T> result(GetRaw()); - TBase::Reset(nullptr); - return result; - } - - void Destroy() - { - Reset(nullptr); - } - - void Reset(T * p) - { - TBase::Destroy(); - TBase::Reset(p); - } + return ref_ptr<T>(ptr, false); +} - T * Release() - { - T * result = GetRaw(); - TBase::Reset(nullptr); - return result; - } +#else - bool IsNull() const { return TBase::GetRaw() == nullptr; } - T * operator->() { return TBase::GetRaw(); } - T const * operator->() const { return TBase::GetRaw(); } - T * GetRaw() { return TBase::GetRaw(); } - T const * GetRaw() const { return TBase::GetRaw(); } -}; +template<typename T> using drape_ptr = unique_ptr<T>; +template<typename T> using ref_ptr = T*; -template<typename T> -TransferPointer<T> MovePointer(T * p) +template <typename T, typename... Args> +drape_ptr<T> make_unique_dp(Args &&... args) { - return MasterPointer<T>(p).Move(); + return make_unique<T>(std::forward<Args>(args)...); } template <typename T> -T * NonConstGetter(dp::MasterPointer<T> & p) +ref_ptr<T> make_ref(drape_ptr<T> const & drapePtr) { - return p.GetRaw(); + return ref_ptr<T>(drapePtr.get()); } -struct MasterPointerDeleter +template <typename T> +ref_ptr<T> make_ref(T * ptr) { - template <typename Y, typename T> - void operator() (pair<Y, MasterPointer<T> > & value) - { - Destroy(value.second); - } - - template <typename T> - void operator() (MasterPointer<T> & value) - { - Destroy(value); - } - -private: - template <typename T> - void Destroy(MasterPointer<T> & value) - { - value.Destroy(); - } -}; + return ref_ptr<T>(ptr); +} -} // namespace dp +#endif diff --git a/drape/render_bucket.cpp b/drape/render_bucket.cpp index 964b51019a..540126a195 100644 --- a/drape/render_bucket.cpp +++ b/drape/render_bucket.cpp @@ -11,25 +11,23 @@ namespace dp { -RenderBucket::RenderBucket(TransferPointer<VertexArrayBuffer> buffer) - : m_buffer(buffer) +RenderBucket::RenderBucket(drape_ptr<VertexArrayBuffer> && buffer) + : m_buffer(move(buffer)) { } RenderBucket::~RenderBucket() { - m_buffer.Destroy(); - (void)GetRangeDeletor(m_overlay, MasterPointerDeleter())(); } -RefPointer<VertexArrayBuffer> RenderBucket::GetBuffer() +ref_ptr<VertexArrayBuffer> RenderBucket::GetBuffer() { - return m_buffer.GetRefPointer(); + return make_ref<VertexArrayBuffer>(m_buffer); } -TransferPointer<VertexArrayBuffer> RenderBucket::MoveBuffer() +drape_ptr<VertexArrayBuffer> && RenderBucket::MoveBuffer() { - return m_buffer.Move(); + return move(m_buffer); } size_t RenderBucket::GetOverlayHandlesCount() const @@ -37,52 +35,51 @@ size_t RenderBucket::GetOverlayHandlesCount() const return m_overlay.size(); } -TransferPointer<OverlayHandle> RenderBucket::PopOverlayHandle() +drape_ptr<OverlayHandle> RenderBucket::PopOverlayHandle() { ASSERT(!m_overlay.empty(), ()); size_t lastElement = m_overlay.size() - 1; swap(m_overlay[0], m_overlay[lastElement]); - TransferPointer<OverlayHandle> h = m_overlay[lastElement].Move(); - m_overlay.resize(lastElement); + drape_ptr<OverlayHandle> h = move(m_overlay[lastElement]); + m_overlay.pop_back(); return h; } -RefPointer<OverlayHandle> RenderBucket::GetOverlayHandle(size_t index) +ref_ptr<OverlayHandle> RenderBucket::GetOverlayHandle(size_t index) { - return m_overlay[index].GetRefPointer(); + return make_ref<OverlayHandle>(m_overlay[index]); } -void RenderBucket::AddOverlayHandle(TransferPointer<OverlayHandle> handle) +void RenderBucket::AddOverlayHandle(drape_ptr<OverlayHandle> && handle) { - m_overlay.push_back(MasterPointer<OverlayHandle>(handle)); + m_overlay.push_back(move(handle)); } void RenderBucket::Update(ScreenBase const & modelView) { - for_each(m_overlay.begin(), m_overlay.end(), bind(&OverlayHandle::Update, - bind(&dp::NonConstGetter<OverlayHandle>, _1), - modelView)); + for (drape_ptr<OverlayHandle> const & overlayHandle : m_overlay) + overlayHandle->Update(modelView); } -void RenderBucket::CollectOverlayHandles(RefPointer<OverlayTree> tree) +void RenderBucket::CollectOverlayHandles(ref_ptr<OverlayTree> tree) { - for_each(m_overlay.begin(), m_overlay.end(), bind(&OverlayTree::Add, tree.GetRaw(), - bind(&MasterPointer<OverlayHandle>::GetRefPointer, _1))); + for (drape_ptr<OverlayHandle> const & overlayHandle : m_overlay) + tree->Add(make_ref<OverlayHandle>(overlayHandle)); } void RenderBucket::Render(ScreenBase const & screen) { - ASSERT(!m_buffer.IsNull(), ()); + ASSERT(m_buffer != nullptr, ()); if (!m_overlay.empty()) { // in simple case when overlay is symbol each element will be contains 6 indexes AttributeBufferMutator attributeMutator; IndexBufferMutator indexMutator(6 * m_overlay.size()); - RefPointer<IndexBufferMutator> rfpIndex = MakeStackRefPointer(&indexMutator); - RefPointer<AttributeBufferMutator> rfpAttrib = MakeStackRefPointer(&attributeMutator); + ref_ptr<IndexBufferMutator> rfpIndex = make_ref(&indexMutator); + ref_ptr<AttributeBufferMutator> rfpAttrib = make_ref(&attributeMutator); - for_each(m_overlay.begin(), m_overlay.end(), [&] (MasterPointer<OverlayHandle> handle) + for (drape_ptr<OverlayHandle> const & handle : m_overlay) { if (handle->IsValid() && handle->IsVisible()) { @@ -90,7 +87,7 @@ void RenderBucket::Render(ScreenBase const & screen) if (handle->HasDynamicAttributes()) handle->GetAttributeMutation(rfpAttrib, screen); } - }); + } m_buffer->ApplyMutation(rfpIndex, rfpAttrib); } diff --git a/drape/render_bucket.hpp b/drape/render_bucket.hpp index 071a07943e..7c0bc83bdb 100644 --- a/drape/render_bucket.hpp +++ b/drape/render_bucket.hpp @@ -14,32 +14,32 @@ class VertexArrayBuffer; class RenderBucket { public: - RenderBucket(TransferPointer<VertexArrayBuffer> buffer); + RenderBucket(drape_ptr<VertexArrayBuffer> && buffer); ~RenderBucket(); - RefPointer<VertexArrayBuffer> GetBuffer(); - TransferPointer<VertexArrayBuffer> MoveBuffer(); + ref_ptr<VertexArrayBuffer> GetBuffer(); + drape_ptr<VertexArrayBuffer> && MoveBuffer(); size_t GetOverlayHandlesCount() const; - TransferPointer<OverlayHandle> PopOverlayHandle(); - RefPointer<OverlayHandle> GetOverlayHandle(size_t index); - void AddOverlayHandle(TransferPointer<OverlayHandle> handle); + drape_ptr<OverlayHandle> PopOverlayHandle(); + ref_ptr<OverlayHandle> GetOverlayHandle(size_t index); + void AddOverlayHandle(drape_ptr<OverlayHandle> && handle); void Update(ScreenBase const & modelView); - void CollectOverlayHandles(RefPointer<OverlayTree> tree); + void CollectOverlayHandles(ref_ptr<OverlayTree> tree); void Render(ScreenBase const & screen); /// Only for testing! Don't use this function in production code! template <typename ToDo> void ForEachOverlay(ToDo const & todo) { - for (MasterPointer<OverlayHandle> & h : m_overlay) - todo(h.GetRaw()); + for (drape_ptr<OverlayHandle> const & h : m_overlay) + todo(h); } private: - vector<MasterPointer<OverlayHandle> > m_overlay; - MasterPointer<VertexArrayBuffer> m_buffer; + vector<drape_ptr<OverlayHandle> > m_overlay; + drape_ptr<VertexArrayBuffer> m_buffer; }; } // namespace dp diff --git a/drape/stipple_pen_resource.cpp b/drape/stipple_pen_resource.cpp index c2540aa084..140f81c1ef 100644 --- a/drape/stipple_pen_resource.cpp +++ b/drape/stipple_pen_resource.cpp @@ -138,13 +138,13 @@ void StipplePenRasterizator::Rasterize(void * buffer) memcpy(pixels + COLUMN_WIDTH, pixels, COLUMN_WIDTH); } -RefPointer<Texture::ResourceInfo> StipplePenIndex::MapResource(StipplePenKey const & key, bool & newResource) +ref_ptr<Texture::ResourceInfo> StipplePenIndex::MapResource(StipplePenKey const & key, bool & newResource) { newResource = false; StipplePenHandle handle(key); TResourceMapping::iterator it = m_resourceMapping.find(handle); if (it != m_resourceMapping.end()) - return MakeStackRefPointer<Texture::ResourceInfo>(&it->second); + return make_ref<Texture::ResourceInfo>(&it->second); newResource = true; @@ -159,10 +159,10 @@ RefPointer<Texture::ResourceInfo> StipplePenIndex::MapResource(StipplePenKey con resource.GetSize(), resource.GetPatternSize())); ASSERT(res.second, ()); - return MakeStackRefPointer<Texture::ResourceInfo>(&res.first->second); + return make_ref<Texture::ResourceInfo>(&res.first->second); } -void StipplePenIndex::UploadResources(RefPointer<Texture> texture) +void StipplePenIndex::UploadResources(ref_ptr<Texture> texture) { ASSERT(texture->GetFormat() == dp::ALPHA, ()); if (m_pendingNodes.empty()) @@ -227,7 +227,7 @@ void StipplePenIndex::UploadResources(RefPointer<Texture> texture) rawBuffer = SharedBufferManager::GetRawPointer(ptr); texture->UploadData(minX, minY, COLUMN_WIDTH, lineCount, - dp::ALPHA, MakeStackRefPointer<void>(rawBuffer)); + dp::ALPHA, make_ref<void>(rawBuffer)); mng.freeSharedBuffer(reserveBufferSize, ptr); } diff --git a/drape/stipple_pen_resource.hpp b/drape/stipple_pen_resource.hpp index 823b50838e..edc456cc6e 100644 --- a/drape/stipple_pen_resource.hpp +++ b/drape/stipple_pen_resource.hpp @@ -98,8 +98,8 @@ class StipplePenIndex { public: StipplePenIndex(m2::PointU const & canvasSize) : m_packer(canvasSize) {} - RefPointer<Texture::ResourceInfo> MapResource(StipplePenKey const & key, bool & newResource); - void UploadResources(RefPointer<Texture> texture); + ref_ptr<Texture::ResourceInfo> MapResource(StipplePenKey const & key, bool & newResource); + void UploadResources(ref_ptr<Texture> texture); glConst GetMinFilter() const; glConst GetMagFilter() const; @@ -125,7 +125,7 @@ public: : m_index(size) { TBase::TextureParams params{ size, TextureFormat::ALPHA, gl_const::GLNearest, gl_const::GLNearest }; - TBase::Init(MakeStackRefPointer(&m_index), params); + TBase::Init(make_ref(&m_index), params); } ~StipplePenTexture() { TBase::Reset(); } diff --git a/drape/symbols_texture.cpp b/drape/symbols_texture.cpp index 4056400781..60ed4164d2 100644 --- a/drape/symbols_texture.cpp +++ b/drape/symbols_texture.cpp @@ -113,6 +113,11 @@ Texture::ResourceType SymbolsTexture::SymbolInfo::GetType() const return Symbol; } +SymbolsTexture::SymbolsTexture(string const & skinPathName) +{ + Load(skinPathName); +} + void SymbolsTexture::Load(string const & skinPathName) { vector<unsigned char> rawData; @@ -154,31 +159,31 @@ void SymbolsTexture::Load(string const & skinPathName) unsigned char * data = stbi_png_load_from_memory(&rawData[0], rawData.size(), &w, &h, &bpp, 0); if (width == w && height == h) - Create(width, height, RGBA8, MakeStackRefPointer<void>(data)); + Create(width, height, RGBA8, make_ref<void>(data)); else Fail(); stbi_image_free(data); } -RefPointer<Texture::ResourceInfo> SymbolsTexture::FindResource(Texture::Key const & key, bool & newResource) +ref_ptr<Texture::ResourceInfo> SymbolsTexture::FindResource(Texture::Key const & key, bool & newResource) { newResource = false; if (key.GetType() != Texture::Symbol) - return RefPointer<ResourceInfo>(); + return ref_ptr<ResourceInfo>(); string const & symbolName = static_cast<SymbolKey const &>(key).GetSymbolName(); TSymDefinition::iterator it = m_definition.find(symbolName); ASSERT(it != m_definition.end(), ()); - return MakeStackRefPointer<ResourceInfo>(&it->second); + return make_ref<ResourceInfo>(&it->second); } void SymbolsTexture::Fail() { m_definition.clear(); int32_t alfaTexture = 0; - Create(1, 1, RGBA8, MakeStackRefPointer(&alfaTexture)); + Create(1, 1, RGBA8, make_ref(&alfaTexture)); } } // namespace dp diff --git a/drape/symbols_texture.hpp b/drape/symbols_texture.hpp index d622861ccc..2f43c65bd2 100644 --- a/drape/symbols_texture.hpp +++ b/drape/symbols_texture.hpp @@ -29,13 +29,14 @@ public: virtual ResourceType GetType() const; }; - void Load(string const & skinPathName); - RefPointer<ResourceInfo> FindResource(Key const & key, bool & newResource); + SymbolsTexture(string const & skinPathName); + + ref_ptr<ResourceInfo> FindResource(Key const & key, bool & newResource); private: void Fail(); + void Load(string const & skinPathName); -private: typedef map<string, SymbolInfo> TSymDefinition; mutable TSymDefinition m_definition; diff --git a/drape/texture.cpp b/drape/texture.cpp index 6e05267ce0..9db789864a 100644 --- a/drape/texture.cpp +++ b/drape/texture.cpp @@ -42,10 +42,10 @@ Texture::~Texture() void Texture::Create(uint32_t width, uint32_t height, TextureFormat format) { - Create(width, height, format, MakeStackRefPointer<void>(NULL)); + Create(width, height, format, make_ref<void>(NULL)); } -void Texture::Create(uint32_t width, uint32_t height, TextureFormat format, RefPointer<void> data) +void Texture::Create(uint32_t width, uint32_t height, TextureFormat format, ref_ptr<void> data) { m_format = format; m_width = width; @@ -63,7 +63,7 @@ void Texture::Create(uint32_t width, uint32_t height, TextureFormat format, RefP glConst pixelType; UnpackFormat(format, layout, pixelType); - GLFunctions::glTexImage2D(m_width, m_height, layout, pixelType, data.GetRaw()); + GLFunctions::glTexImage2D(m_width, m_height, layout, pixelType, static_cast<void*>(data)); SetFilterParams(gl_const::GLLinear, gl_const::GLLinear); SetWrapMode(gl_const::GLClampToEdge, gl_const::GLClampToEdge); @@ -98,7 +98,7 @@ void Texture::SetWrapMode(glConst sMode, glConst tMode) } void Texture::UploadData(uint32_t x, uint32_t y, uint32_t width, uint32_t height, - TextureFormat format, RefPointer<void> data) + TextureFormat format, ref_ptr<void> data) { ASSERT_ID; ASSERT(format == m_format, ()); @@ -107,7 +107,7 @@ void Texture::UploadData(uint32_t x, uint32_t y, uint32_t width, uint32_t height UnpackFormat(format, layout, pixelType); - GLFunctions::glTexSubImage2D(x, y, width, height, layout, pixelType, data.GetRaw()); + GLFunctions::glTexSubImage2D(x, y, width, height, layout, pixelType, static_cast<void*>(data)); } TextureFormat Texture::GetFormat() const diff --git a/drape/texture.hpp b/drape/texture.hpp index 25a5f9c43d..4bac27856c 100644 --- a/drape/texture.hpp +++ b/drape/texture.hpp @@ -48,14 +48,14 @@ public: virtual ~Texture(); void Create(uint32_t width, uint32_t height, TextureFormat format); - void Create(uint32_t width, uint32_t height, TextureFormat format, RefPointer<void> data); + void Create(uint32_t width, uint32_t height, TextureFormat format, ref_ptr<void> data); void SetFilterParams(glConst minFilter, glConst magFilter); void SetWrapMode(glConst sMode, glConst tMode); void UploadData(uint32_t x, uint32_t y, uint32_t width, uint32_t height, TextureFormat format, - RefPointer<void> data); + ref_ptr<void> data); - virtual RefPointer<ResourceInfo> FindResource(Key const & key, bool & newResource) = 0; + virtual ref_ptr<ResourceInfo> FindResource(Key const & key, bool & newResource) = 0; virtual void UpdateState() {} TextureFormat GetFormat() const; diff --git a/drape/texture_manager.cpp b/drape/texture_manager.cpp index 1ecc377eb9..31b80402d1 100644 --- a/drape/texture_manager.cpp +++ b/drape/texture_manager.cpp @@ -47,17 +47,22 @@ TextureManager::TextureManager() m_nothingToUpload.test_and_set(); } +TextureManager::BaseRegion::BaseRegion() + : m_info(make_ref<Texture::ResourceInfo>(nullptr)) + , m_texture(make_ref<Texture>(nullptr)) +{} + bool TextureManager::BaseRegion::IsValid() const { - return !m_info.IsNull() && !m_texture.IsNull(); + return m_info != nullptr && m_texture != nullptr; } -void TextureManager::BaseRegion::SetResourceInfo(RefPointer<Texture::ResourceInfo> info) +void TextureManager::BaseRegion::SetResourceInfo(ref_ptr<Texture::ResourceInfo> info) { m_info = info; } -void TextureManager::BaseRegion::SetTexture(RefPointer<Texture> texture) +void TextureManager::BaseRegion::SetTexture(ref_ptr<Texture> texture) { m_texture = texture; } @@ -88,41 +93,53 @@ TextureManager::GlyphRegion::GlyphRegion() float TextureManager::GlyphRegion::GetOffsetX() const { ASSERT(m_info->GetType() == Texture::Glyph, ()); - GlyphInfo const * info = static_cast<GlyphInfo const *>(m_info.GetRaw()); + GlyphInfo const * info = static_cast<GlyphInfo const *>(m_info); return info->GetMetrics().m_xOffset; } float TextureManager::GlyphRegion::GetOffsetY() const { ASSERT(m_info->GetType() == Texture::Glyph, ()); - GlyphInfo const * info = static_cast<GlyphInfo const *>(m_info.GetRaw()); + GlyphInfo const * info = static_cast<GlyphInfo const *>(m_info); return info->GetMetrics().m_yOffset; } float TextureManager::GlyphRegion::GetAdvanceX() const { ASSERT(m_info->GetType() == Texture::Glyph, ()); - GlyphInfo const * info = static_cast<GlyphInfo const *>(m_info.GetRaw()); + GlyphInfo const * info = static_cast<GlyphInfo const *>(m_info); return info->GetMetrics().m_xAdvance; } float TextureManager::GlyphRegion::GetAdvanceY() const { ASSERT(m_info->GetType() == Texture::Glyph, ()); - GlyphInfo const * info = static_cast<GlyphInfo const *>(m_info.GetRaw()); + GlyphInfo const * info = static_cast<GlyphInfo const *>(m_info); return info->GetMetrics().m_yAdvance; } uint32_t TextureManager::StippleRegion::GetMaskPixelLength() const { ASSERT(m_info->GetType() == Texture::StipplePen, ()); - return static_cast<StipplePenResourceInfo const *>(m_info.GetRaw())->GetMaskPixelLength(); + return static_cast<StipplePenResourceInfo const *>(m_info)->GetMaskPixelLength(); } uint32_t TextureManager::StippleRegion::GetPatternPixelLength() const { ASSERT(m_info->GetType() == Texture::StipplePen, ()); - return static_cast<StipplePenResourceInfo const *>(m_info.GetRaw())->GetPatternPixelLength(); + return static_cast<StipplePenResourceInfo const *>(m_info)->GetPatternPixelLength(); +} + +void TextureManager::Release() +{ + m_glyphGroups.clear(); + m_hybridGlyphGroups.clear(); + + m_symbolTexture.reset(); + m_stipplePenTexture.reset(); + m_colorTexture.reset(); + + m_glyphTextures.clear(); } void TextureManager::UpdateDynamicTextures() @@ -137,15 +154,19 @@ void TextureManager::UpdateDynamicTextures() UpdateGlyphTextures(m_hybridGlyphGroups); } -MasterPointer<Texture> TextureManager::AllocateGlyphTexture() const +ref_ptr<Texture> TextureManager::AllocateGlyphTexture() { - return MasterPointer<Texture>(new FontTexture(m2::PointU(m_maxTextureSize, m_maxTextureSize), m_glyphManager.GetRefPointer())); + drape_ptr<Texture> tex = make_unique_dp<FontTexture>(m2::PointU(m_maxTextureSize, m_maxTextureSize), + make_ref<GlyphManager>(m_glyphManager)); + ref_ptr<Texture> result = make_ref<Texture>(tex); + m_glyphTextures.push_back(move(tex)); + return result; } -void TextureManager::GetRegionBase(RefPointer<Texture> tex, TextureManager::BaseRegion & region, Texture::Key const & key) +void TextureManager::GetRegionBase(ref_ptr<Texture> tex, TextureManager::BaseRegion & region, Texture::Key const & key) { bool isNew = false; - region.SetResourceInfo(tex->FindResource(key, isNew)); + region.SetResourceInfo(tex != nullptr ? tex->FindResource(key, isNew) : nullptr); region.SetTexture(tex); ASSERT(region.IsValid(), ()); if (isNew) @@ -266,14 +287,12 @@ size_t TextureManager::FindHybridGlyphsGroup(TMultilineText const & text) void TextureManager::Init(Params const & params) { GLFunctions::glPixelStore(gl_const::GLUnpackAlignment, 1); - SymbolsTexture * symbols = new SymbolsTexture(); - symbols->Load(my::JoinFoldersToPath(string("resources-") + params.m_resPrefix, "symbols")); - m_symbolTexture.Reset(symbols); + m_symbolTexture = move(make_unique_dp<SymbolsTexture>(my::JoinFoldersToPath(string("resources-") + params.m_resPrefix, "symbols"))); - m_stipplePenTexture.Reset(new StipplePenTexture(m2::PointU(STIPPLE_TEXTURE_SIZE, STIPPLE_TEXTURE_SIZE))); - m_colorTexture.Reset(new ColorTexture(m2::PointU(COLOR_TEXTURE_SIZE, COLOR_TEXTURE_SIZE))); + m_stipplePenTexture = move(make_unique_dp<StipplePenTexture>(m2::PointU(STIPPLE_TEXTURE_SIZE, STIPPLE_TEXTURE_SIZE))); + m_colorTexture = move(make_unique_dp<ColorTexture>(m2::PointU(COLOR_TEXTURE_SIZE, COLOR_TEXTURE_SIZE))); - m_glyphManager.Reset(new GlyphManager(params.m_glyphMngParams)); + m_glyphManager = move(make_unique_dp<GlyphManager>(params.m_glyphMngParams)); m_maxTextureSize = min(2048, GLFunctions::glGetInteger(gl_const::GLMaxTextureSize)); uint32_t const textureSquare = m_maxTextureSize * m_maxTextureSize; @@ -300,36 +319,19 @@ void TextureManager::Init(Params const & params) }); } -void TextureManager::Release() -{ - m_symbolTexture.Destroy(); - m_stipplePenTexture.Destroy(); - m_colorTexture.Destroy(); - - DeleteRange(m_glyphGroups, [](GlyphGroup & g) - { - g.m_texture.Destroy(); - }); - - DeleteRange(m_hybridGlyphGroups, [](HybridGlyphGroup & g) - { - g.m_texture.Destroy(); - }); -} - void TextureManager::GetSymbolRegion(string const & symbolName, SymbolRegion & region) { - GetRegionBase(m_symbolTexture.GetRefPointer(), region, SymbolsTexture::SymbolKey(symbolName)); + GetRegionBase(make_ref<Texture>(m_symbolTexture), region, SymbolsTexture::SymbolKey(symbolName)); } void TextureManager::GetStippleRegion(TStipplePattern const & pen, StippleRegion & region) { - GetRegionBase(m_stipplePenTexture.GetRefPointer(), region, StipplePenKey(pen)); + GetRegionBase(make_ref<Texture>(m_stipplePenTexture), region, StipplePenKey(pen)); } void TextureManager::GetColorRegion(Color const & color, ColorRegion & region) { - GetRegionBase(m_colorTexture.GetRefPointer(), region, ColorKey(color)); + GetRegionBase(make_ref<Texture>(m_colorTexture), region, ColorKey(color)); } void TextureManager::GetGlyphRegions(TMultilineText const & text, TMultilineGlyphsBuffer & buffers) diff --git a/drape/texture_manager.hpp b/drape/texture_manager.hpp index e49ca419e9..3f00c9d668 100644 --- a/drape/texture_manager.hpp +++ b/drape/texture_manager.hpp @@ -20,9 +20,10 @@ public: class BaseRegion { public: - void SetResourceInfo(RefPointer<Texture::ResourceInfo> info); - void SetTexture(RefPointer<Texture> texture); - RefPointer<Texture> GetTexture() const { return m_texture; } + BaseRegion(); + void SetResourceInfo(ref_ptr<Texture::ResourceInfo> info); + void SetTexture(ref_ptr<Texture> texture); + ref_ptr<Texture> GetTexture() const { return m_texture; } bool IsValid() const; m2::PointU GetPixelSize() const; @@ -30,8 +31,8 @@ public: m2::RectF const & GetTexRect() const; protected: - RefPointer<Texture::ResourceInfo> m_info; - RefPointer<Texture> m_texture; + ref_ptr<Texture::ResourceInfo> m_info; + ref_ptr<Texture> m_texture; }; class SymbolRegion : public BaseRegion {}; @@ -69,9 +70,9 @@ public: }; TextureManager(); + void Release(); void Init(Params const & params); - void Release(); void GetSymbolRegion(string const & symbolName, SymbolRegion & region); typedef buffer_vector<uint8_t, 8> TStipplePattern; @@ -93,27 +94,34 @@ public: private: struct GlyphGroup { - GlyphGroup() = default; - GlyphGroup(strings::UniChar const & start, strings::UniChar const & end) - : m_startChar(start), m_endChar(end) {} + GlyphGroup() + : m_startChar(0), m_endChar(0), m_texture(make_ref<Texture>(nullptr)) + {} - strings::UniChar m_startChar = 0; - strings::UniChar m_endChar = 0; + GlyphGroup(strings::UniChar const & start, strings::UniChar const & end) + : m_startChar(start), m_endChar(end), m_texture(make_ref<Texture>(nullptr)) + {} - MasterPointer<Texture> m_texture; + strings::UniChar m_startChar; + strings::UniChar m_endChar; + ref_ptr<Texture> m_texture; }; struct HybridGlyphGroup { + HybridGlyphGroup() + : m_texture(make_ref<Texture>(nullptr)) + {} + unordered_set<strings::UniChar> m_glyphs; - MasterPointer<Texture> m_texture; + ref_ptr<Texture> m_texture; }; uint32_t m_maxTextureSize; uint32_t m_maxGlypsCount; - MasterPointer<Texture> AllocateGlyphTexture() const; - void GetRegionBase(RefPointer<Texture> tex, TextureManager::BaseRegion & region, Texture::Key const & key); + ref_ptr<Texture> AllocateGlyphTexture(); + void GetRegionBase(ref_ptr<Texture> tex, TextureManager::BaseRegion & region, Texture::Key const & key); size_t FindGlyphsGroup(strings::UniChar const & c) const; size_t FindGlyphsGroup(strings::UniString const & text) const; @@ -131,15 +139,14 @@ private: template<typename TGlyphGroup> void FillResultBuffer(strings::UniString const & text, TGlyphGroup & group, TGlyphsBuffer & regions) { - if (group.m_texture.IsNull()) + if (group.m_texture == nullptr) group.m_texture = AllocateGlyphTexture(); - dp::RefPointer<dp::Texture> texture = group.m_texture.GetRefPointer(); regions.reserve(text.size()); for (strings::UniChar const & c : text) { GlyphRegion reg; - GetRegionBase(texture, reg, GlyphKey(c)); + GetRegionBase(group.m_texture, reg, GlyphKey(c)); regions.push_back(reg); } } @@ -185,18 +192,19 @@ private: void UpdateGlyphTextures(TGlyphGroups & groups) { for (auto & g : groups) - if (!g.m_texture.IsNull()) + if (g.m_texture != nullptr) g.m_texture->UpdateState(); } static constexpr size_t GetInvalidGlyphGroup(); private: - MasterPointer<Texture> m_symbolTexture; - MasterPointer<Texture> m_stipplePenTexture; - MasterPointer<Texture> m_colorTexture; + drape_ptr<Texture> m_symbolTexture; + drape_ptr<Texture> m_stipplePenTexture; + drape_ptr<Texture> m_colorTexture; + list<drape_ptr<Texture>> m_glyphTextures; - MasterPointer<GlyphManager> m_glyphManager; + drape_ptr<GlyphManager> m_glyphManager; buffer_vector<GlyphGroup, 64> m_glyphGroups; buffer_vector<HybridGlyphGroup, 4> m_hybridGlyphGroups; diff --git a/drape/texture_of_colors.cpp b/drape/texture_of_colors.cpp index c1a99077e7..3b508a6408 100644 --- a/drape/texture_of_colors.cpp +++ b/drape/texture_of_colors.cpp @@ -20,7 +20,7 @@ ColorPalette::ColorPalette(m2::PointU const & canvasSize) , m_cursor(m2::PointU::Zero()) {} -RefPointer<Texture::ResourceInfo> ColorPalette::MapResource(ColorKey const & key, bool & newResource) +ref_ptr<Texture::ResourceInfo> ColorPalette::MapResource(ColorKey const & key, bool & newResource) { TPalette::iterator itm = m_palette.find(key.m_color); newResource = itm == m_palette.end(); @@ -53,10 +53,10 @@ RefPointer<Texture::ResourceInfo> ColorPalette::MapResource(ColorKey const & key ASSERT(res.second, ()); itm = res.first; } - return MakeStackRefPointer<Texture::ResourceInfo>(&itm->second); + return make_ref<Texture::ResourceInfo>(&itm->second); } -void ColorPalette::UploadResources(RefPointer<Texture> texture) +void ColorPalette::UploadResources(ref_ptr<Texture> texture) { ASSERT(texture->GetFormat() == dp::RGBA8, ()); if (m_pendingNodes.empty()) @@ -144,7 +144,7 @@ void ColorPalette::UploadResources(RefPointer<Texture> texture) pointer = SharedBufferManager::GetRawPointer(buffer); texture->UploadData(uploadRect.minX(), uploadRect.minY(), uploadRect.SizeX(), uploadRect.SizeY(), - dp::RGBA8, dp::MakeStackRefPointer<void>(pointer)); + dp::RGBA8, make_ref<void>(pointer)); } } diff --git a/drape/texture_of_colors.hpp b/drape/texture_of_colors.hpp index 7e130bbc1b..f7733978d8 100644 --- a/drape/texture_of_colors.hpp +++ b/drape/texture_of_colors.hpp @@ -31,8 +31,8 @@ class ColorPalette public: ColorPalette(m2::PointU const & canvasSize); - RefPointer<Texture::ResourceInfo> MapResource(ColorKey const & key, bool & newResource); - void UploadResources(RefPointer<Texture> texture); + ref_ptr<Texture::ResourceInfo> MapResource(ColorKey const & key, bool & newResource); + void UploadResources(ref_ptr<Texture> texture); glConst GetMinFilter() const; glConst GetMagFilter() const; @@ -71,7 +71,7 @@ public: params.m_minFilter = gl_const::GLNearest; params.m_magFilter = gl_const::GLNearest; - TBase::Init(MakeStackRefPointer(&m_pallete), params); + TBase::Init(make_ref(&m_pallete), params); } ~ColorTexture() { TBase::Reset(); } diff --git a/drape/uniform_value.cpp b/drape/uniform_value.cpp index 9baeacb3a6..3d6d9e8243 100644 --- a/drape/uniform_value.cpp +++ b/drape/uniform_value.cpp @@ -230,7 +230,7 @@ void UniformValue::SetMatrix4x4Value(float const * matrixValue) memcpy(CastMemory<float>(), matrixValue, 4 * 4 * sizeof(float)); } -void UniformValue::Apply(RefPointer<GpuProgram> program) const +void UniformValue::Apply(ref_ptr<GpuProgram> program) const { ASSERT(program->HasUniform(m_name, GetCorrespondingGLType(), 1), ("Failed to find uniform", m_name, GetCorrespondingGLType(), 1)); diff --git a/drape/uniform_value.hpp b/drape/uniform_value.hpp index 16503637c4..ed26fc676b 100644 --- a/drape/uniform_value.hpp +++ b/drape/uniform_value.hpp @@ -48,7 +48,7 @@ public: void SetMatrix4x4Value(float const * matrixValue); - void Apply(RefPointer<GpuProgram> program) const; + void Apply(ref_ptr<GpuProgram> program) const; bool operator<(UniformValue const & other) const { diff --git a/drape/vertex_array_buffer.cpp b/drape/vertex_array_buffer.cpp index f062960908..3a0e30cc18 100644 --- a/drape/vertex_array_buffer.cpp +++ b/drape/vertex_array_buffer.cpp @@ -13,14 +13,14 @@ VertexArrayBuffer::VertexArrayBuffer(uint32_t indexBufferSize, uint32_t dataBuff , m_dataBufferSize(dataBufferSize) , m_program() { - m_indexBuffer.Reset(new IndexBuffer(indexBufferSize)); + m_indexBuffer = make_unique_dp<IndexBuffer>(indexBufferSize); } VertexArrayBuffer::~VertexArrayBuffer() { - m_indexBuffer.Destroy(); - DeleteRange(m_staticBuffers, MasterPointerDeleter()); - DeleteRange(m_dynamicBuffers, MasterPointerDeleter()); + m_indexBuffer.reset(); + m_staticBuffers.clear(); + m_dynamicBuffers.clear(); if (m_VAO != 0) { @@ -41,7 +41,7 @@ void VertexArrayBuffer::Preflush() for(auto & buffer : m_dynamicBuffers) buffer.second->MoveToGPU(GPUBuffer::ElementBuffer); - ASSERT(!m_indexBuffer.IsNull(), ()); + ASSERT(m_indexBuffer != nullptr, ()); m_indexBuffer->MoveToGPU(GPUBuffer::IndexBuffer); GLFunctions::glBindBuffer(0, gl_const::GLElementArrayBuffer); @@ -57,7 +57,7 @@ void VertexArrayBuffer::RenderRange(IndicesRange const & range) { if (!(m_staticBuffers.empty() && m_dynamicBuffers.empty()) && GetIndexCount() > 0) { - ASSERT(!m_program.IsNull(), ("Somebody not call Build. It's very bad. Very very bad")); + ASSERT(m_program != nullptr, ("Somebody not call Build. It's very bad. Very very bad")); /// if OES_vertex_array_object is supported than all bindings already saved in VAO /// and we need only bind VAO. In Bind method have ASSERT("bind already called") if (GLExtensionsList::Instance().IsSupported(GLExtensionsList::VertexArrayObject)) @@ -66,14 +66,14 @@ void VertexArrayBuffer::RenderRange(IndicesRange const & range) BindStaticBuffers(); BindDynamicBuffers(); - GetIndexBuffer().Bind(); + GetIndexBuffer()->Bind(); GLFunctions::glDrawElements(range.m_idxCount, range.m_idxStart); } } -void VertexArrayBuffer::Build(RefPointer<GpuProgram> program) +void VertexArrayBuffer::Build(ref_ptr<GpuProgram> program) { - ASSERT(m_VAO == 0 && m_program.IsNull(), ("No-no-no! You can't rebuild VertexArrayBuffer")); + ASSERT(m_VAO == 0 && m_program == nullptr, ("No-no-no! You can't rebuild VertexArrayBuffer")); m_program = program; /// if OES_vertex_array_object not supported, than buffers will be bind on each Render call if (!GLExtensionsList::Instance().IsSupported(GLExtensionsList::VertexArrayObject)) @@ -89,7 +89,7 @@ void VertexArrayBuffer::Build(RefPointer<GpuProgram> program) void VertexArrayBuffer::UploadData(BindingInfo const & bindingInfo, void const * data, uint16_t count) { - RefPointer<DataBuffer> buffer; + ref_ptr<DataBuffer> buffer; if (!bindingInfo.IsDynamic()) buffer = GetOrCreateStaticBuffer(bindingInfo); else @@ -98,24 +98,24 @@ void VertexArrayBuffer::UploadData(BindingInfo const & bindingInfo, void const * buffer->GetBuffer()->UploadData(data, count); } -RefPointer<DataBuffer> VertexArrayBuffer::GetOrCreateDynamicBuffer(BindingInfo const & bindingInfo) +ref_ptr<DataBuffer> VertexArrayBuffer::GetOrCreateDynamicBuffer(BindingInfo const & bindingInfo) { return GetOrCreateBuffer(bindingInfo, true); } -RefPointer<DataBuffer> VertexArrayBuffer::GetDynamicBuffer(BindingInfo const & bindingInfo) const +ref_ptr<DataBuffer> VertexArrayBuffer::GetDynamicBuffer(BindingInfo const & bindingInfo) const { return GetBuffer(bindingInfo, true); } -RefPointer<DataBuffer> VertexArrayBuffer::GetOrCreateStaticBuffer(BindingInfo const & bindingInfo) +ref_ptr<DataBuffer> VertexArrayBuffer::GetOrCreateStaticBuffer(BindingInfo const & bindingInfo) { return GetOrCreateBuffer(bindingInfo, false); } -RefPointer<DataBuffer> VertexArrayBuffer::GetBuffer(BindingInfo const & bindingInfo, bool isDynamic) const +ref_ptr<DataBuffer> VertexArrayBuffer::GetBuffer(BindingInfo const & bindingInfo, bool isDynamic) const { - TBuffersMap const * buffers = NULL; + TBuffersMap const * buffers = nullptr; if (isDynamic) buffers = &m_dynamicBuffers; else @@ -123,14 +123,14 @@ RefPointer<DataBuffer> VertexArrayBuffer::GetBuffer(BindingInfo const & bindingI TBuffersMap::const_iterator it = buffers->find(bindingInfo); if (it == buffers->end()) - return RefPointer<DataBuffer>(); + return make_ref<DataBuffer>(nullptr); - return it->second.GetRefPointer(); + return make_ref<DataBuffer>(it->second); } -RefPointer<DataBuffer> VertexArrayBuffer::GetOrCreateBuffer(BindingInfo const & bindingInfo, bool isDynamic) +ref_ptr<DataBuffer> VertexArrayBuffer::GetOrCreateBuffer(BindingInfo const & bindingInfo, bool isDynamic) { - TBuffersMap * buffers = NULL; + TBuffersMap * buffers = nullptr; if (isDynamic) buffers = &m_dynamicBuffers; else @@ -139,17 +139,18 @@ RefPointer<DataBuffer> VertexArrayBuffer::GetOrCreateBuffer(BindingInfo const & TBuffersMap::iterator it = buffers->find(bindingInfo); if (it == buffers->end()) { - MasterPointer<DataBuffer> & buffer = (*buffers)[bindingInfo]; - buffer.Reset(new DataBuffer(bindingInfo.GetElementSize(), m_dataBufferSize)); - return buffer.GetRefPointer(); + drape_ptr<DataBuffer> dataBuffer = make_unique_dp<DataBuffer>(bindingInfo.GetElementSize(), m_dataBufferSize); + ref_ptr<DataBuffer> result = make_ref<DataBuffer>(dataBuffer); + (*buffers).insert(make_pair(bindingInfo, move(dataBuffer))); + return result; } - return it->second.GetRefPointer(); + return make_ref<DataBuffer>(it->second); } uint16_t VertexArrayBuffer::GetAvailableIndexCount() const { - return GetIndexBuffer().GetAvailableSize(); + return GetIndexBuffer()->GetAvailableSize(); } uint16_t VertexArrayBuffer::GetAvailableVertexCount() const @@ -189,7 +190,7 @@ uint16_t VertexArrayBuffer::GetDynamicBufferOffset(BindingInfo const & bindingIn uint16_t VertexArrayBuffer::GetIndexCount() const { - return GetIndexBuffer().GetCurrentSize(); + return GetIndexBuffer()->GetCurrentSize(); } bool VertexArrayBuffer::IsFilled() const @@ -199,20 +200,20 @@ bool VertexArrayBuffer::IsFilled() const void VertexArrayBuffer::UploadIndexes(uint16_t const * data, uint16_t count) { - ASSERT(count <= GetIndexBuffer().GetAvailableSize(), ()); - GetIndexBuffer().UploadData(data, count); + ASSERT(count <= GetIndexBuffer()->GetAvailableSize(), ()); + GetIndexBuffer()->UploadData(data, count); } -void VertexArrayBuffer::ApplyMutation(RefPointer<IndexBufferMutator> indexMutator, - RefPointer<AttributeBufferMutator> attrMutator) +void VertexArrayBuffer::ApplyMutation(ref_ptr<IndexBufferMutator> indexMutator, + ref_ptr<AttributeBufferMutator> attrMutator) { - if (!indexMutator.IsNull()) + if (indexMutator != nullptr) { - ASSERT(!m_indexBuffer.IsNull(), ()); + ASSERT(m_indexBuffer != nullptr, ()); m_indexBuffer->UpdateData(indexMutator->GetIndexes(), indexMutator->GetIndexCount()); } - if (attrMutator.IsNull()) + if (attrMutator == nullptr) return; typedef AttributeBufferMutator::TMutateData TMutateData; @@ -220,8 +221,8 @@ void VertexArrayBuffer::ApplyMutation(RefPointer<IndexBufferMutator> indexMutato TMutateData const & data = attrMutator->GetMutateData(); for (TMutateData::const_iterator it = data.begin(); it != data.end(); ++it) { - RefPointer<DataBuffer> buffer = GetDynamicBuffer(it->first); - ASSERT(!buffer.IsNull(), ()); + ref_ptr<DataBuffer> buffer = GetDynamicBuffer(it->first); + ASSERT(buffer != nullptr, ()); DataBufferMapper mapper(buffer); TMutateNodes const & nodes = it->second; @@ -229,7 +230,7 @@ void VertexArrayBuffer::ApplyMutation(RefPointer<IndexBufferMutator> indexMutato { MutateNode const & node = nodes[i]; ASSERT_GREATER(node.m_region.m_count, 0, ()); - mapper.UpdateData(node.m_data.GetRaw(), node.m_region.m_offset, node.m_region.m_count); + mapper.UpdateData(node.m_data, node.m_region.m_offset, node.m_region.m_count); } } } @@ -256,7 +257,7 @@ void VertexArrayBuffer::BindBuffers(TBuffersMap const & buffers) const for (; it != buffers.end(); ++it) { BindingInfo const & binding = it->first; - RefPointer<DataBuffer> buffer = it->second.GetRefPointer(); + ref_ptr<DataBuffer> buffer = make_ref<DataBuffer>(it->second); buffer->GetBuffer()->Bind(); for (uint16_t i = 0; i < binding.GetCount(); ++i) @@ -275,16 +276,10 @@ void VertexArrayBuffer::BindBuffers(TBuffersMap const & buffers) const } } -DataBufferBase & VertexArrayBuffer::GetIndexBuffer() +ref_ptr<DataBufferBase> VertexArrayBuffer::GetIndexBuffer() const { - ASSERT(!m_indexBuffer.IsNull(), ()); - return *(m_indexBuffer->GetBuffer().GetRaw()); -} - -DataBufferBase const & VertexArrayBuffer::GetIndexBuffer() const -{ - ASSERT(!m_indexBuffer.IsNull(), ()); - return *(m_indexBuffer->GetBuffer().GetRaw()); + ASSERT(m_indexBuffer != nullptr, ()); + return m_indexBuffer->GetBuffer(); } } // namespace dp diff --git a/drape/vertex_array_buffer.hpp b/drape/vertex_array_buffer.hpp index c398a0845b..b1e18a537d 100644 --- a/drape/vertex_array_buffer.hpp +++ b/drape/vertex_array_buffer.hpp @@ -31,7 +31,7 @@ struct IndicesRange class VertexArrayBuffer { - typedef map<BindingInfo, MasterPointer<DataBuffer> > TBuffersMap; + typedef map<BindingInfo, drape_ptr<DataBuffer> > TBuffersMap; public: VertexArrayBuffer(uint32_t indexBufferSize, uint32_t dataBufferSize); ~VertexArrayBuffer(); @@ -45,7 +45,7 @@ public: /// by this reason Build/Bind and Render must be called only on Frontendrendere thread void Render(); void RenderRange(IndicesRange const & range); - void Build(RefPointer<GpuProgram> program); + void Build(ref_ptr<GpuProgram> program); ///@} uint16_t GetAvailableVertexCount() const; @@ -58,23 +58,22 @@ public: void UploadData(BindingInfo const & bindingInfo, void const * data, uint16_t count); void UploadIndexes(uint16_t const * data, uint16_t count); - void ApplyMutation(RefPointer<IndexBufferMutator> indexMutator, - RefPointer<AttributeBufferMutator> attrMutator); + void ApplyMutation(ref_ptr<IndexBufferMutator> indexMutator, + ref_ptr<AttributeBufferMutator> attrMutator); private: - RefPointer<DataBuffer> GetOrCreateStaticBuffer(BindingInfo const & bindingInfo); - RefPointer<DataBuffer> GetOrCreateDynamicBuffer(BindingInfo const & bindingInfo); - RefPointer<DataBuffer> GetDynamicBuffer(BindingInfo const & bindingInfo) const; + ref_ptr<DataBuffer> GetOrCreateStaticBuffer(BindingInfo const & bindingInfo); + ref_ptr<DataBuffer> GetOrCreateDynamicBuffer(BindingInfo const & bindingInfo); + ref_ptr<DataBuffer> GetDynamicBuffer(BindingInfo const & bindingInfo) const; - RefPointer<DataBuffer> GetOrCreateBuffer(BindingInfo const & bindingInfo, bool isDynamic); - RefPointer<DataBuffer> GetBuffer(BindingInfo const & bindingInfo, bool isDynamic) const; + ref_ptr<DataBuffer> GetOrCreateBuffer(BindingInfo const & bindingInfo, bool isDynamic); + ref_ptr<DataBuffer> GetBuffer(BindingInfo const & bindingInfo, bool isDynamic) const; void Bind() const; void BindStaticBuffers() const; void BindDynamicBuffers() const; void BindBuffers(TBuffersMap const & buffers) const; - DataBufferBase & GetIndexBuffer(); - DataBufferBase const & GetIndexBuffer() const; + ref_ptr<DataBufferBase> GetIndexBuffer() const; private: /// m_VAO - VertexArrayObject name/identificator @@ -82,10 +81,10 @@ private: TBuffersMap m_staticBuffers; TBuffersMap m_dynamicBuffers; - MasterPointer<IndexBuffer> m_indexBuffer; + drape_ptr<IndexBuffer> m_indexBuffer; uint32_t m_dataBufferSize; - RefPointer<GpuProgram> m_program; + ref_ptr<GpuProgram> m_program; }; } // namespace dp |