summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/typed_arrays/typed_flexible_array_buffer_view.h
blob: 5eac3e790858a72e2cc81c3754211c8ed9476ba0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_TYPED_ARRAYS_TYPED_FLEXIBLE_ARRAY_BUFFER_VIEW_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_TYPED_ARRAYS_TYPED_FLEXIBLE_ARRAY_BUFFER_VIEW_H_

#include "base/macros.h"
#include "third_party/blink/renderer/core/typed_arrays/flexible_array_buffer_view.h"

namespace blink {

template <typename ValueType, bool clamped = false>
class TypedFlexibleArrayBufferView final : public FlexibleArrayBufferView {
  STACK_ALLOCATED();

 public:
  TypedFlexibleArrayBufferView() = default;
  TypedFlexibleArrayBufferView(const TypedFlexibleArrayBufferView&) = default;
  TypedFlexibleArrayBufferView(TypedFlexibleArrayBufferView&&) = default;
  TypedFlexibleArrayBufferView(v8::Local<v8::ArrayBufferView> array_buffer_view)
      : FlexibleArrayBufferView(array_buffer_view) {}
  ~TypedFlexibleArrayBufferView() = default;

  ValueType* DataMaybeOnStack() const {
    return static_cast<ValueType*>(BaseAddressMaybeOnStack());
  }

  size_t length() const {
    DCHECK_EQ(ByteLength() % sizeof(ValueType), 0u);
    return ByteLength() / sizeof(ValueType);
  }
};

using FlexibleInt8Array = TypedFlexibleArrayBufferView<int8_t>;
using FlexibleInt16Array = TypedFlexibleArrayBufferView<int16_t>;
using FlexibleInt32Array = TypedFlexibleArrayBufferView<int32_t>;
using FlexibleUint8Array = TypedFlexibleArrayBufferView<uint8_t>;
using FlexibleUint8ClampedArray = TypedFlexibleArrayBufferView<uint8_t, true>;
using FlexibleUint16Array = TypedFlexibleArrayBufferView<uint16_t>;
using FlexibleUint32Array = TypedFlexibleArrayBufferView<uint32_t>;
using FlexibleBigInt64Array = TypedFlexibleArrayBufferView<int64_t>;
using FlexibleBigUint64Array = TypedFlexibleArrayBufferView<uint64_t>;
using FlexibleFloat32Array = TypedFlexibleArrayBufferView<float>;
using FlexibleFloat64Array = TypedFlexibleArrayBufferView<double>;

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_TYPED_ARRAYS_TYPED_FLEXIBLE_ARRAY_BUFFER_VIEW_H_