#include "third_party/blink/renderer/modules/ml/webnn/ml_buffer.h"
#include "base/types/expected.h"
#include "base/types/expected_macros.h"
#include "services/webnn/public/cpp/ml_buffer_usage.h"
#include "services/webnn/public/cpp/operand_descriptor.h"
#include "services/webnn/public/mojom/webnn_buffer.mojom-blink.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_ml_buffer_descriptor.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/modules/ml/ml_context.h"
#include "third_party/blink/renderer/modules/ml/webnn/ml_error.h"
#include "third_party/blink/renderer/modules/ml/webnn/ml_graph_utils.h"
namespace blink {
MLBuffer::MLBuffer(
ExecutionContext* execution_context,
MLContext* context,
webnn::OperandDescriptor descriptor,
webnn::MLBufferUsage usage,
webnn::mojom::blink::CreateBufferSuccessPtr create_buffer_success,
base::PassKey<MLContext> )
: … { … }
MLBuffer::~MLBuffer() = default;
void MLBuffer::Trace(Visitor* visitor) const { … }
V8MLOperandDataType MLBuffer::dataType() const { … }
Vector<uint32_t> MLBuffer::shape() const { … }
uint32_t MLBuffer::usage() const { … }
void MLBuffer::destroy() { … }
const webnn::OperandDescriptor& MLBuffer::Descriptor() const { … }
webnn::OperandDataType MLBuffer::DataType() const { … }
const std::vector<uint32_t>& MLBuffer::Shape() const { … }
const webnn::MLBufferUsage& MLBuffer::Usage() const { … }
uint64_t MLBuffer::PackedByteLength() const { … }
ScriptPromise<DOMArrayBuffer> MLBuffer::ReadBufferImpl(
ScriptState* script_state,
ExceptionState& exception_state) { … }
ScriptPromise<IDLUndefined> MLBuffer::ReadBufferImpl(
ScriptState* script_state,
DOMArrayBufferBase* dst_data,
ExceptionState& exception_state) { … }
ScriptPromise<IDLUndefined> MLBuffer::ReadBufferImpl(
ScriptState* script_state,
DOMArrayBufferView* dst_data,
ExceptionState& exception_state) { … }
void MLBuffer::OnDidReadBuffer(
ScriptPromiseResolver<DOMArrayBuffer>* resolver,
webnn::mojom::blink::ReadBufferResultPtr result) { … }
void MLBuffer::OnDidReadBufferByob(
ScriptPromiseResolver<IDLUndefined>* resolver,
DOMArrayBufferBase* dst_data,
webnn::mojom::blink::ReadBufferResultPtr result) { … }
void MLBuffer::OnDidReadBufferByobView(
ScriptPromiseResolver<IDLUndefined>* resolver,
DOMArrayBufferView* dst_data,
webnn::mojom::blink::ReadBufferResultPtr result) { … }
void MLBuffer::WriteBufferImpl(base::span<const uint8_t> src_data,
ExceptionState& exception_state) { … }
void MLBuffer::OnConnectionError() { … }
}