diff --git a/generator/templates/api_cpp.h b/generator/templates/api_cpp.h index 2bd475eeb2..54bf66d8ea 100644 --- a/generator/templates/api_cpp.h +++ b/generator/templates/api_cpp.h @@ -136,11 +136,17 @@ namespace {{metadata.namespace}} { CType Get() const { return mHandle; } + // TODO(dawn:1639) Deprecate Release after uses have been removed. CType Release() { CType result = mHandle; mHandle = 0; return result; } + CType MoveToCHandle() { + CType result = mHandle; + mHandle = 0; + return result; + } static Derived Acquire(CType handle) { Derived result; result.mHandle = handle; diff --git a/src/dawn/samples/CHelloTriangle.cpp b/src/dawn/samples/CHelloTriangle.cpp index c3b6ab367c..59451ca734 100644 --- a/src/dawn/samples/CHelloTriangle.cpp +++ b/src/dawn/samples/CHelloTriangle.cpp @@ -26,9 +26,9 @@ WGPURenderPipeline pipeline; WGPUTextureFormat swapChainFormat; void init() { - device = CreateCppDawnDevice().Release(); + device = CreateCppDawnDevice().MoveToCHandle(); queue = wgpuDeviceGetQueue(device); - swapchain = GetSwapChain().Release(); + swapchain = GetSwapChain().MoveToCHandle(); swapChainFormat = static_cast(GetPreferredSwapChainTextureFormat()); const char* vs = R"( @@ -42,13 +42,13 @@ void init() { ); return vec4f(pos[VertexIndex], 0.0, 1.0); })"; - WGPUShaderModule vsModule = utils::CreateShaderModule(device, vs).Release(); + WGPUShaderModule vsModule = utils::CreateShaderModule(device, vs).MoveToCHandle(); const char* fs = R"( @fragment fn main() -> @location(0) vec4f { return vec4f(1.0, 0.0, 0.0, 1.0); })"; - WGPUShaderModule fsModule = utils::CreateShaderModule(device, fs).Release(); + WGPUShaderModule fsModule = utils::CreateShaderModule(device, fs).MoveToCHandle(); { WGPURenderPipelineDescriptor descriptor = {}; diff --git a/src/dawn/tests/unittests/ObjectBaseTests.cpp b/src/dawn/tests/unittests/ObjectBaseTests.cpp index 56abe74fa6..c60f4aee69 100644 --- a/src/dawn/tests/unittests/ObjectBaseTests.cpp +++ b/src/dawn/tests/unittests/ObjectBaseTests.cpp @@ -65,14 +65,14 @@ TEST(ObjectBase, Get) { ASSERT_EQ(1, refcount); } -// Test that Release consumes the C++ object into a C object and doesn't release -TEST(ObjectBase, Release) { +// Test that MoveToCHandle consumes the C++ object into a C object and doesn't release +TEST(ObjectBase, MoveToCHandle) { int refcount = 1; { Object obj(&refcount); ASSERT_EQ(2, refcount); - ASSERT_EQ(&refcount, obj.Release()); + ASSERT_EQ(&refcount, obj.MoveToCHandle()); ASSERT_EQ(nullptr, obj.Get()); ASSERT_EQ(2, refcount); }