dawn_node: Add binding/GPUTexture.cpp

Bug: dawn:1123
Change-Id: I2858cc2b86aa9189a92a2f4a9f0988a9f7b36953
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/64909
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
Ben Clayton 2021-09-28 13:58:00 +00:00 committed by Dawn LUCI CQ
parent ca9bc676aa
commit 05944b0f97
2 changed files with 69 additions and 0 deletions

View File

@ -49,6 +49,7 @@ add_library(dawn_node_binding STATIC
"GPUShaderModule.h"
"GPUSupportedLimits.cpp"
"GPUSupportedLimits.h"
"GPUTexture.cpp"
"GPUTexture.h"
"GPUTextureView.cpp"
"GPUTextureView.h"

View File

@ -0,0 +1,68 @@
// 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/GPUTexture.h"
#include "src/dawn_node/binding/Converter.h"
#include "src/dawn_node/binding/Errors.h"
#include "src/dawn_node/binding/GPUTextureView.h"
#include "src/dawn_node/utils/Debug.h"
namespace wgpu { namespace binding {
////////////////////////////////////////////////////////////////////////////////
// wgpu::bindings::GPUTexture
////////////////////////////////////////////////////////////////////////////////
GPUTexture::GPUTexture(wgpu::Texture texture) : texture_(std::move(texture)) {
}
interop::Interface<interop::GPUTextureView> GPUTexture::createView(
Napi::Env env,
std::optional<interop::GPUTextureViewDescriptor> descriptor) {
if (!texture_) {
Errors::OperationError(env).ThrowAsJavaScriptException();
return {};
}
if (descriptor.has_value()) {
wgpu::TextureViewDescriptor desc{};
Converter conv(env);
if (!conv(desc.baseMipLevel, descriptor->baseMipLevel) ||
!conv(desc.mipLevelCount, descriptor->mipLevelCount) ||
!conv(desc.baseArrayLayer, descriptor->baseArrayLayer) ||
!conv(desc.arrayLayerCount, descriptor->arrayLayerCount) ||
!conv(desc.format, descriptor->format) ||
!conv(desc.dimension, descriptor->dimension) ||
!conv(desc.aspect, descriptor->aspect)) {
return {};
}
return interop::GPUTextureView::Create<GPUTextureView>(env, texture_.CreateView(&desc));
}
return interop::GPUTextureView::Create<GPUTextureView>(env, texture_.CreateView());
}
void GPUTexture::destroy(Napi::Env) {
texture_.Destroy();
}
std::optional<std::string> GPUTexture::getLabel(Napi::Env) {
UNIMPLEMENTED();
}
void GPUTexture::setLabel(Napi::Env, std::optional<std::string> value) {
UNIMPLEMENTED();
}
}} // namespace wgpu::binding