OpenSubdiv: Refactor, use C++ allocation for internal classes

Only use OBJECT_GUARDED_{NEW. DELETE} for structures which are part of
public C-API (and hence can not have new/delete operators overloaded).

Could try being brave and override new/delete from under C++ ifdef.
This commit is contained in:
Sergey Sharybin 2020-05-19 09:42:05 +02:00
parent c81a5f58f8
commit 57aae2a355
6 changed files with 42 additions and 4 deletions

View File

@ -50,6 +50,9 @@ if(WITH_OPENSUBDIV)
)
list(APPEND SRC
# Base.
internal/base/memory.h
# Device.
internal/device/device_context_cuda.cc
internal/device/device_context_cuda.h

View File

@ -0,0 +1,28 @@
// Copyright 2020 Blender Foundation. All rights reserved.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#ifndef OPENSUBDIV_BASE_MEMORY_H_
#define OPENSUBDIV_BASE_MEMORY_H_
#include "MEM_guardedalloc.h"
namespace blender {
namespace opensubdiv {
} // namespace opensubdiv
} // namespace blender
#endif // OPENSUBDIV_BASE_MEMORY_H_

View File

@ -858,7 +858,7 @@ OpenSubdiv_EvaluatorInternal *openSubdiv_createEvaluatorInternal(
OpenSubdiv::Far::PatchMap *patch_map = new PatchMap(*patch_table);
// Wrap everything we need into an object which we control from our side.
OpenSubdiv_EvaluatorInternal *evaluator_descr;
evaluator_descr = OBJECT_GUARDED_NEW(OpenSubdiv_EvaluatorInternal);
evaluator_descr = new OpenSubdiv_EvaluatorInternal();
evaluator_descr->eval_output = new blender::opensubdiv::CpuEvalOutputAPI(eval_output, patch_map);
evaluator_descr->patch_map = patch_map;
evaluator_descr->patch_table = patch_table;
@ -873,5 +873,5 @@ OpenSubdiv_EvaluatorInternal *openSubdiv_createEvaluatorInternal(
void openSubdiv_deleteEvaluatorInternal(OpenSubdiv_EvaluatorInternal *evaluator)
{
OBJECT_GUARDED_DELETE(evaluator, OpenSubdiv_EvaluatorInternal);
delete evaluator;
}

View File

@ -26,6 +26,8 @@
#include <opensubdiv/far/patchMap.h>
#include <opensubdiv/far/patchTable.h>
#include "internal/base/memory.h"
struct OpenSubdiv_PatchCoord;
struct OpenSubdiv_TopologyRefiner;
@ -144,6 +146,8 @@ struct OpenSubdiv_EvaluatorInternal {
blender::opensubdiv::CpuEvalOutputAPI *eval_output;
const OpenSubdiv::Far::PatchMap *patch_map;
const OpenSubdiv::Far::PatchTable *patch_table;
MEM_CXX_CLASS_ALLOC_FUNCS("OpenSubdiv_EvaluatorInternal");
};
OpenSubdiv_EvaluatorInternal *openSubdiv_createEvaluatorInternal(

View File

@ -230,7 +230,7 @@ void assignFunctionPointers(OpenSubdiv_TopologyRefiner *topology_refiner)
OpenSubdiv_TopologyRefiner *allocateTopologyRefiner()
{
OpenSubdiv_TopologyRefiner *topology_refiner = OBJECT_GUARDED_NEW(OpenSubdiv_TopologyRefiner);
topology_refiner->impl = OBJECT_GUARDED_NEW(OpenSubdiv_TopologyRefinerImpl);
topology_refiner->impl = new OpenSubdiv_TopologyRefinerImpl();
assignFunctionPointers(topology_refiner);
return topology_refiner;
}
@ -256,7 +256,7 @@ OpenSubdiv_TopologyRefiner *openSubdiv_createTopologyRefinerFromConverter(
void openSubdiv_deleteTopologyRefiner(OpenSubdiv_TopologyRefiner *topology_refiner)
{
OBJECT_GUARDED_DELETE(topology_refiner->impl, OpenSubdiv_TopologyRefinerImpl);
delete topology_refiner->impl;
OBJECT_GUARDED_DELETE(topology_refiner, OpenSubdiv_TopologyRefiner);
}

View File

@ -25,6 +25,7 @@
#include <opensubdiv/far/topologyRefiner.h>
#include "internal/base/memory.h"
#include "opensubdiv_topology_refiner_capi.h"
namespace blender {
@ -45,6 +46,8 @@ class TopologyRefinerImpl {
// Ideally, we would also support refining topology without re-importing it
// from external world, but that is for later.
OpenSubdiv_TopologyRefinerSettings settings;
MEM_CXX_CLASS_ALLOC_FUNCS("TopologyRefinerImpl");
};
} // namespace opensubdiv