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 {
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;

View File

@ -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<WGPUTextureFormat>(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 = {};

View File

@ -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);
}