Renames C++ object Release function to MoveToCHandle.

Bug: dawn:1639
Change-Id: If4aaeefbb629cbef4302bbb430e09d740f057d8f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/132273
Reviewed-by: Austin Eng <enga@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Loko Kung <lokokung@google.com>
This commit is contained in:
Loko Kung 2023-05-10 23:48:22 +00:00 committed by Dawn LUCI CQ
parent b8233deafe
commit 0214a30479
3 changed files with 13 additions and 7 deletions

View File

@ -136,11 +136,17 @@ namespace {{metadata.namespace}} {
CType Get() const { CType Get() const {
return mHandle; return mHandle;
} }
// TODO(dawn:1639) Deprecate Release after uses have been removed.
CType Release() { CType Release() {
CType result = mHandle; CType result = mHandle;
mHandle = 0; mHandle = 0;
return result; return result;
} }
CType MoveToCHandle() {
CType result = mHandle;
mHandle = 0;
return result;
}
static Derived Acquire(CType handle) { static Derived Acquire(CType handle) {
Derived result; Derived result;
result.mHandle = handle; result.mHandle = handle;

View File

@ -26,9 +26,9 @@ WGPURenderPipeline pipeline;
WGPUTextureFormat swapChainFormat; WGPUTextureFormat swapChainFormat;
void init() { void init() {
device = CreateCppDawnDevice().Release(); device = CreateCppDawnDevice().MoveToCHandle();
queue = wgpuDeviceGetQueue(device); queue = wgpuDeviceGetQueue(device);
swapchain = GetSwapChain().Release(); swapchain = GetSwapChain().MoveToCHandle();
swapChainFormat = static_cast<WGPUTextureFormat>(GetPreferredSwapChainTextureFormat()); swapChainFormat = static_cast<WGPUTextureFormat>(GetPreferredSwapChainTextureFormat());
const char* vs = R"( const char* vs = R"(
@ -42,13 +42,13 @@ void init() {
); );
return vec4f(pos[VertexIndex], 0.0, 1.0); 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"( const char* fs = R"(
@fragment fn main() -> @location(0) vec4f { @fragment fn main() -> @location(0) vec4f {
return vec4f(1.0, 0.0, 0.0, 1.0); 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 = {}; WGPURenderPipelineDescriptor descriptor = {};

View File

@ -65,14 +65,14 @@ TEST(ObjectBase, Get) {
ASSERT_EQ(1, refcount); ASSERT_EQ(1, refcount);
} }
// Test that Release consumes the C++ object into a C object and doesn't release // Test that MoveToCHandle consumes the C++ object into a C object and doesn't release
TEST(ObjectBase, Release) { TEST(ObjectBase, MoveToCHandle) {
int refcount = 1; int refcount = 1;
{ {
Object obj(&refcount); Object obj(&refcount);
ASSERT_EQ(2, refcount); ASSERT_EQ(2, refcount);
ASSERT_EQ(&refcount, obj.Release()); ASSERT_EQ(&refcount, obj.MoveToCHandle());
ASSERT_EQ(nullptr, obj.Get()); ASSERT_EQ(nullptr, obj.Get());
ASSERT_EQ(2, refcount); ASSERT_EQ(2, refcount);
} }