CompilationInfo.cpp (1691B)
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #include "CompilationInfo.h" 7 8 #include "CompilationMessage.h" 9 #include "ShaderModule.h" 10 #include "mozilla/dom/WebGPUBinding.h" 11 12 namespace mozilla::webgpu { 13 14 GPU_IMPL_CYCLE_COLLECTION(CompilationInfo, mParent, mMessages) 15 GPU_IMPL_JS_WRAP(CompilationInfo) 16 17 CompilationInfo::CompilationInfo(Device* const aParent) : ChildOf(aParent) {} 18 19 CompilationInfo::~CompilationInfo() = default; 20 21 void CompilationInfo::SetMessages( 22 nsTArray<mozilla::webgpu::WebGPUCompilationMessage>& aMessages) { 23 for (auto& msg : aMessages) { 24 auto messageType = dom::GPUCompilationMessageType::Error; 25 switch (msg.messageType) { 26 case WebGPUCompilationMessageType::Error: 27 messageType = dom::GPUCompilationMessageType::Error; 28 break; 29 case WebGPUCompilationMessageType::Warning: 30 messageType = dom::GPUCompilationMessageType::Warning; 31 break; 32 case WebGPUCompilationMessageType::Info: 33 messageType = dom::GPUCompilationMessageType::Info; 34 break; 35 } 36 mMessages.AppendElement(MakeAndAddRef<mozilla::webgpu::CompilationMessage>( 37 mParent, messageType, msg.lineNum, msg.linePos, msg.offset, msg.length, 38 std::move(msg.message))); 39 } 40 } 41 42 void CompilationInfo::GetMessages( 43 nsTArray<RefPtr<mozilla::webgpu::CompilationMessage>>& aMessages) { 44 for (auto& msg : mMessages) { 45 aMessages.AppendElement(msg); 46 } 47 } 48 49 } // namespace mozilla::webgpu