skia2/tools/gpu/dawn/DawnTestContext.h
Stephen White 64c8b811b5 Dawn: fix memory corruption in DawnTestContext.
Move the dawn_native::Instance ownership from DawnTestContextImpl to
DawnTestContext (its parent class), which owns the wgpu::Device.

dawn_native::Instance must outlive any wgpu::Devices created from it.

Bug: skia: 10311
Change-Id: Iedc4ed94f03b61d5e43cd5c93eb68e24bc4474e1
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/293852
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Stephen White <senorblanco@chromium.org>
2020-06-03 18:40:49 +00:00

46 lines
994 B
C++

/*
* Copyright 2019 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef DawnTestContext_DEFINED
#define DawnTestContext_DEFINED
#include "tools/gpu/TestContext.h"
#include <dawn_native/DawnNative.h>
#ifdef SK_DAWN
namespace sk_gpu_test {
class DawnTestContext : public TestContext {
public:
virtual GrBackend backend() override { return GrBackendApi::kDawn; }
const wgpu::Device& getDevice() {
return fDevice;
}
protected:
DawnTestContext(std::unique_ptr<dawn_native::Instance> instance, const wgpu::Device& device)
: fInstance(std::move(instance)), fDevice(device) {}
std::unique_ptr<dawn_native::Instance> fInstance;
wgpu::Device fDevice;
private:
typedef TestContext INHERITED;
};
/**
* Creates Dawn context object bound to the Dawn library.
*/
DawnTestContext* CreatePlatformDawnTestContext(DawnTestContext*);
} // namespace sk_gpu_test
#endif
#endif