dawn_node: Add binding/GPUAdapter.cpp

Bug: dawn:1123
Change-Id: I5eee0036acf4db18dd103f863c4f07511a0cee25
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/64917
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
diff --git a/src/dawn_node/binding/CMakeLists.txt b/src/dawn_node/binding/CMakeLists.txt
index 8627199..b45ad6a 100644
--- a/src/dawn_node/binding/CMakeLists.txt
+++ b/src/dawn_node/binding/CMakeLists.txt
@@ -21,6 +21,7 @@
     "Errors.h"
     "GPU.cpp"
     "GPU.h"
+    "GPUAdapter.cpp"
     "GPUAdapter.h"
     "GPUBindGroup.cpp"
     "GPUBindGroup.h"
diff --git a/src/dawn_node/binding/GPUAdapter.cpp b/src/dawn_node/binding/GPUAdapter.cpp
new file mode 100644
index 0000000..0d47304
--- /dev/null
+++ b/src/dawn_node/binding/GPUAdapter.cpp
@@ -0,0 +1,61 @@
+// Copyright 2021 The Dawn Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "src/dawn_node/binding/GPUAdapter.h"
+
+#include "src/dawn_node/binding/GPUDevice.h"
+#include "src/dawn_node/binding/GPUSupportedLimits.h"
+
+namespace wgpu { namespace binding {
+
+    ////////////////////////////////////////////////////////////////////////////////
+    // wgpu::bindings::GPUAdapter
+    // TODO(crbug.com/dawn/1133): This is a stub implementation. Properly implement.
+    ////////////////////////////////////////////////////////////////////////////////
+    GPUAdapter::GPUAdapter(dawn_native::Adapter a) : adapter_(a) {
+    }
+
+    std::string GPUAdapter::getName(Napi::Env) {
+        return "dawn-adapter";
+    }
+
+    interop::Interface<interop::GPUSupportedFeatures> GPUAdapter::getFeatures(Napi::Env env) {
+        class Features : public interop::GPUSupportedFeatures {};
+        return interop::GPUSupportedFeatures::Create<Features>(env);
+    }
+
+    interop::Interface<interop::GPUSupportedLimits> GPUAdapter::getLimits(Napi::Env env) {
+        return interop::GPUSupportedLimits::Create<GPUSupportedLimits>(env);
+    }
+
+    bool GPUAdapter::getIsFallbackAdapter(Napi::Env) {
+        UNIMPLEMENTED();
+    }
+
+    interop::Promise<interop::Interface<interop::GPUDevice>> GPUAdapter::requestDevice(
+        Napi::Env env,
+        std::optional<interop::GPUDeviceDescriptor> descriptor) {
+        dawn_native::DeviceDescriptor desc{};  // TODO(crbug.com/dawn/1133): Fill in.
+        interop::Promise<interop::Interface<interop::GPUDevice>> promise(env);
+
+        auto wgpu_device = adapter_.CreateDevice(&desc);
+        if (wgpu_device) {
+            promise.Resolve(interop::GPUDevice::Create<GPUDevice>(env, env, wgpu_device));
+        } else {
+            Napi::Error::New(env, "failed to create device").ThrowAsJavaScriptException();
+        }
+        return promise;
+    }
+
+}}  // namespace wgpu::binding