Fix APIGetInstance() didn't increase external ref.

InstanceBase has two seperate ref counts: external & internal.
When we return it to the external user, we need to increase external
ref count as well.

Bug: chromium:1429835
Change-Id: I4b585d04149180418bd620e6e4d86522e033b64e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/126080
Commit-Queue: Quyen Le <lehoangquyen@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
Le Hoang Quyen 2023-04-03 10:04:42 +00:00 committed by Dawn LUCI CQ
parent 04cfa59882
commit 44afd7112f
2 changed files with 18 additions and 1 deletions

View File

@ -86,7 +86,7 @@ MaybeError AdapterBase::Initialize() {
InstanceBase* AdapterBase::APIGetInstance() const { InstanceBase* AdapterBase::APIGetInstance() const {
auto instance = GetInstance(); auto instance = GetInstance();
ASSERT(instance != nullptr); ASSERT(instance != nullptr);
instance->Reference(); instance->APIReference();
return instance; return instance;
} }

View File

@ -335,4 +335,21 @@ TEST_F(AdapterCreationTest, PreferLowPower) {
} }
} }
// Test that GetInstance() returns the correct Instance.
TEST_F(AdapterCreationTest, GetInstance) {
wgpu::RequestAdapterOptions options = {};
MockCallback<WGPURequestAdapterCallback> cb;
WGPUAdapter cAdapter = nullptr;
EXPECT_CALL(cb, Call(WGPURequestAdapterStatus_Success, _, nullptr, this))
.WillOnce(SaveArg<1>(&cAdapter));
instance.RequestAdapter(&options, cb.Callback(), cb.MakeUserdata(this));
wgpu::Adapter adapter = wgpu::Adapter::Acquire(cAdapter);
EXPECT_EQ(adapter != nullptr, anyAdapterAvailable);
EXPECT_EQ(adapter.GetInstance().Get(), instance.Get());
}
} // anonymous namespace } // anonymous namespace