Commit f2966925 authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[arraybuffer] Remove type-specific typed-array files

The type-specific typed-array files like int16-array.h were unnecessary
and did not add functionality. I replaced them now with a templated
version of the original base class.

R=haraken@chromium.org

Bug: chromium:1008840
Change-Id: I04b2c392af8737162b4251249d7af6ff50eee7bc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1919354Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#716891}
parent 5421614a
......@@ -18,15 +18,8 @@ blink_core_sources("typed_arrays") {
"array_buffer/biguint64_array.h",
"array_buffer/float32_array.h",
"array_buffer/float64_array.h",
"array_buffer/int16_array.h",
"array_buffer/int32_array.h",
"array_buffer/int8_array.h",
"array_buffer/integral_typed_array_base.h",
"array_buffer/typed_array_base.h",
"array_buffer/uint16_array.h",
"array_buffer/uint32_array.h",
"array_buffer/uint8_array.h",
"array_buffer/uint8_clamped_array.h",
"array_buffer_view_helpers.h",
"dom_array_buffer.cc",
"dom_array_buffer.h",
......
/*
* Copyright (C) 2009 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_TYPED_ARRAYS_ARRAY_BUFFER_INT16_ARRAY_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_TYPED_ARRAYS_ARRAY_BUFFER_INT16_ARRAY_H_
#include "third_party/blink/renderer/core/typed_arrays/array_buffer/integral_typed_array_base.h"
namespace blink {
class ArrayBuffer;
class Int16Array final : public IntegralTypedArrayBase<int16_t> {
public:
static inline scoped_refptr<Int16Array> Create(unsigned length);
static inline scoped_refptr<Int16Array> Create(const int16_t* array,
unsigned length);
static inline scoped_refptr<Int16Array> Create(scoped_refptr<ArrayBuffer>,
unsigned byte_offset,
unsigned length);
using TypedArrayBase<int16_t>::Set;
using IntegralTypedArrayBase<int16_t>::Set;
ViewType GetType() const override { return kTypeInt16; }
private:
inline Int16Array(scoped_refptr<ArrayBuffer>,
unsigned byte_offset,
unsigned length);
// Make constructor visible to superclass.
friend class TypedArrayBase<int16_t>;
};
scoped_refptr<Int16Array> Int16Array::Create(unsigned length) {
return TypedArrayBase<int16_t>::Create<Int16Array>(length);
}
scoped_refptr<Int16Array> Int16Array::Create(const int16_t* array,
unsigned length) {
return TypedArrayBase<int16_t>::Create<Int16Array>(array, length);
}
scoped_refptr<Int16Array> Int16Array::Create(scoped_refptr<ArrayBuffer> buffer,
unsigned byte_offset,
unsigned length) {
return TypedArrayBase<int16_t>::Create<Int16Array>(std::move(buffer),
byte_offset, length);
}
Int16Array::Int16Array(scoped_refptr<ArrayBuffer> buffer,
unsigned byte_offset,
unsigned length)
: IntegralTypedArrayBase<int16_t>(std::move(buffer), byte_offset, length) {}
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_TYPED_ARRAYS_ARRAY_BUFFER_INT16_ARRAY_H_
/*
* Copyright (C) 2009 Apple Inc. All rights reserved.
* Copyright (C) 2009 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_TYPED_ARRAYS_ARRAY_BUFFER_INT32_ARRAY_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_TYPED_ARRAYS_ARRAY_BUFFER_INT32_ARRAY_H_
#include "third_party/blink/renderer/core/typed_arrays/array_buffer/integral_typed_array_base.h"
namespace blink {
class Int32Array final : public IntegralTypedArrayBase<int> {
public:
static inline scoped_refptr<Int32Array> Create(unsigned length);
static inline scoped_refptr<Int32Array> Create(const int* array,
unsigned length);
static inline scoped_refptr<Int32Array> Create(scoped_refptr<ArrayBuffer>,
unsigned byte_offset,
unsigned length);
using TypedArrayBase<int>::Set;
using IntegralTypedArrayBase<int>::Set;
ViewType GetType() const override { return kTypeInt32; }
private:
inline Int32Array(scoped_refptr<ArrayBuffer>,
unsigned byte_offset,
unsigned length);
// Make constructor visible to superclass.
friend class TypedArrayBase<int>;
};
scoped_refptr<Int32Array> Int32Array::Create(unsigned length) {
return TypedArrayBase<int>::Create<Int32Array>(length);
}
scoped_refptr<Int32Array> Int32Array::Create(const int* array,
unsigned length) {
return TypedArrayBase<int>::Create<Int32Array>(array, length);
}
scoped_refptr<Int32Array> Int32Array::Create(scoped_refptr<ArrayBuffer> buffer,
unsigned byte_offset,
unsigned length) {
return TypedArrayBase<int>::Create<Int32Array>(std::move(buffer), byte_offset,
length);
}
Int32Array::Int32Array(scoped_refptr<ArrayBuffer> buffer,
unsigned byte_offset,
unsigned length)
: IntegralTypedArrayBase<int>(std::move(buffer), byte_offset, length) {}
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_TYPED_ARRAYS_ARRAY_BUFFER_INT32_ARRAY_H_
/*
* Copyright (C) 2009 Apple Inc. All rights reserved.
* Copyright (C) 2009 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_TYPED_ARRAYS_ARRAY_BUFFER_INT8_ARRAY_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_TYPED_ARRAYS_ARRAY_BUFFER_INT8_ARRAY_H_
#include "third_party/blink/renderer/core/typed_arrays/array_buffer/integral_typed_array_base.h"
namespace blink {
class ArrayBuffer;
class Int8Array final : public IntegralTypedArrayBase<signed char> {
public:
static inline scoped_refptr<Int8Array> Create(unsigned length);
static inline scoped_refptr<Int8Array> Create(const signed char* array,
unsigned length);
static inline scoped_refptr<Int8Array> Create(scoped_refptr<ArrayBuffer>,
unsigned byte_offset,
unsigned length);
using TypedArrayBase<signed char>::Set;
using IntegralTypedArrayBase<signed char>::Set;
ViewType GetType() const override { return kTypeInt8; }
private:
inline Int8Array(scoped_refptr<ArrayBuffer>,
unsigned byte_offset,
unsigned length);
// Make constructor visible to superclass.
friend class TypedArrayBase<signed char>;
};
scoped_refptr<Int8Array> Int8Array::Create(unsigned length) {
return TypedArrayBase<signed char>::Create<Int8Array>(length);
}
scoped_refptr<Int8Array> Int8Array::Create(const signed char* array,
unsigned length) {
return TypedArrayBase<signed char>::Create<Int8Array>(array, length);
}
scoped_refptr<Int8Array> Int8Array::Create(scoped_refptr<ArrayBuffer> buffer,
unsigned byte_offset,
unsigned length) {
return TypedArrayBase<signed char>::Create<Int8Array>(std::move(buffer),
byte_offset, length);
}
Int8Array::Int8Array(scoped_refptr<ArrayBuffer> buffer,
unsigned byte_offset,
unsigned length)
: IntegralTypedArrayBase<signed char>(std::move(buffer),
byte_offset,
length) {}
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_TYPED_ARRAYS_ARRAY_BUFFER_INT8_ARRAY_H_
......@@ -35,27 +35,111 @@ namespace blink {
// Base class for all WebGL<T>Array types holding integral
// (non-floating-point) values.
template <typename T>
template <typename T, bool clamped = false>
class IntegralTypedArrayBase : public TypedArrayBase<T> {
public:
void Set(unsigned index, double value) {
if (index >= TypedArrayBase<T>::length_)
return;
if (std::isnan(value)) // Clamp NaN to 0
value = 0;
// The double cast is necessary to get the correct wrapping
// for out-of-range values with Int32Array and Uint32Array.
TypedArrayBase<T>::Data()[index] =
static_cast<T>(static_cast<int64_t>(value));
}
static inline scoped_refptr<IntegralTypedArrayBase<T, clamped>> Create(
unsigned length);
static inline scoped_refptr<IntegralTypedArrayBase<T, clamped>> Create(
const T* array,
unsigned length);
static inline scoped_refptr<IntegralTypedArrayBase<T, clamped>>
Create(scoped_refptr<ArrayBuffer>, unsigned byte_offset, unsigned length);
inline void Set(unsigned index, double value);
ArrayBufferView::ViewType GetType() const override;
protected:
IntegralTypedArrayBase(scoped_refptr<ArrayBuffer> buffer,
unsigned byte_offset,
unsigned length)
: TypedArrayBase<T>(std::move(buffer), byte_offset, length) {}
};
template <typename T, bool clamped>
scoped_refptr<IntegralTypedArrayBase<T, clamped>>
IntegralTypedArrayBase<T, clamped>::Create(unsigned length) {
return TypedArrayBase<T>::template Create<IntegralTypedArrayBase<T, clamped>>(
length);
}
template <typename T, bool clamped>
scoped_refptr<IntegralTypedArrayBase<T, clamped>>
IntegralTypedArrayBase<T, clamped>::Create(const T* array, unsigned length) {
return TypedArrayBase<T>::template Create<IntegralTypedArrayBase<T, clamped>>(
array, length);
}
template <typename T, bool clamped>
scoped_refptr<IntegralTypedArrayBase<T, clamped>>
IntegralTypedArrayBase<T, clamped>::Create(scoped_refptr<ArrayBuffer> buffer,
unsigned byte_offset,
unsigned length) {
return TypedArrayBase<T>::template Create<IntegralTypedArrayBase<T, clamped>>(
std::move(buffer), byte_offset, length);
}
template <typename T, bool clamped>
inline void IntegralTypedArrayBase<T, clamped>::Set(unsigned index,
double value) {
if (index >= TypedArrayBase<T>::length_)
return;
if (std::isnan(value)) // Clamp NaN to 0
value = 0;
// The double cast is necessary to get the correct wrapping
// for out-of-range values with Int32Array and Uint32Array.
TypedArrayBase<T>::Data()[index] =
static_cast<T>(static_cast<int64_t>(value));
}
template <>
inline void IntegralTypedArrayBase<uint8_t, true>::Set(unsigned index,
double value) {
if (index >= TypedArrayBase<uint8_t>::length_) {
return;
}
if (std::isnan(value) || value < 0) {
value = 0;
} else if (value > 255) {
value = 255;
}
Data()[index] = static_cast<unsigned char>(lrint(value));
}
template <typename T, bool clamped>
inline ArrayBufferView::ViewType IntegralTypedArrayBase<T, clamped>::GetType()
const {
NOTREACHED();
return ArrayBufferView::kTypeInt16;
}
#define FOREACH_VIEW_TYPE(V) \
V(int8_t, kTypeInt8) \
V(int16_t, kTypeInt16) \
V(int32_t, kTypeInt32) \
V(uint8_t, kTypeUint8) \
V(uint16_t, kTypeUint16) \
V(uint32_t, kTypeUint32)
#define GET_TYPE(c_type, view_type) \
template <> \
inline ArrayBufferView::ViewType \
IntegralTypedArrayBase<c_type, false>::GetType() const { \
return ArrayBufferView::view_type; \
}
FOREACH_VIEW_TYPE(GET_TYPE)
#undef GET_TYPE
#undef FOREACH_VIEW_TYPE
template <>
inline ArrayBufferView::ViewType
IntegralTypedArrayBase<uint8_t, true>::GetType() const {
return ArrayBufferView::kTypeUint8Clamped;
}
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_TYPED_ARRAYS_ARRAY_BUFFER_INTEGRAL_TYPED_ARRAY_BASE_H_
/*
* Copyright (C) 2009 Apple Inc. All rights reserved.
* Copyright (C) 2009 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_TYPED_ARRAYS_ARRAY_BUFFER_UINT16_ARRAY_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_TYPED_ARRAYS_ARRAY_BUFFER_UINT16_ARRAY_H_
#include "third_party/blink/renderer/core/typed_arrays/array_buffer/integral_typed_array_base.h"
namespace blink {
class ArrayBuffer;
class Uint16Array final : public IntegralTypedArrayBase<uint16_t> {
public:
static inline scoped_refptr<Uint16Array> Create(unsigned length);
static inline scoped_refptr<Uint16Array> Create(const uint16_t* array,
unsigned length);
static inline scoped_refptr<Uint16Array> Create(scoped_refptr<ArrayBuffer>,
unsigned byte_offset,
unsigned length);
using TypedArrayBase<uint16_t>::Set;
using IntegralTypedArrayBase<uint16_t>::Set;
ViewType GetType() const override { return kTypeUint16; }
private:
inline Uint16Array(scoped_refptr<ArrayBuffer>,
unsigned byte_offset,
unsigned length);
// Make constructor visible to superclass.
friend class TypedArrayBase<uint16_t>;
};
scoped_refptr<Uint16Array> Uint16Array::Create(unsigned length) {
return TypedArrayBase<uint16_t>::Create<Uint16Array>(length);
}
scoped_refptr<Uint16Array> Uint16Array::Create(const uint16_t* array,
unsigned length) {
return TypedArrayBase<uint16_t>::Create<Uint16Array>(array, length);
}
scoped_refptr<Uint16Array> Uint16Array::Create(
scoped_refptr<ArrayBuffer> buffer,
unsigned byte_offset,
unsigned length) {
return TypedArrayBase<uint16_t>::Create<Uint16Array>(std::move(buffer),
byte_offset, length);
}
Uint16Array::Uint16Array(scoped_refptr<ArrayBuffer> buffer,
unsigned byte_offset,
unsigned length)
: IntegralTypedArrayBase<uint16_t>(std::move(buffer), byte_offset, length) {
}
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_TYPED_ARRAYS_ARRAY_BUFFER_UINT16_ARRAY_H_
/*
* Copyright (C) 2009 Apple Inc. All rights reserved.
* Copyright (C) 2009 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_TYPED_ARRAYS_ARRAY_BUFFER_UINT32_ARRAY_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_TYPED_ARRAYS_ARRAY_BUFFER_UINT32_ARRAY_H_
#include "third_party/blink/renderer/core/typed_arrays/array_buffer/integral_typed_array_base.h"
namespace blink {
class ArrayBuffer;
class Uint32Array final : public IntegralTypedArrayBase<unsigned> {
public:
static inline scoped_refptr<Uint32Array> Create(unsigned length);
static inline scoped_refptr<Uint32Array> Create(const unsigned* array,
unsigned length);
static inline scoped_refptr<Uint32Array> Create(scoped_refptr<ArrayBuffer>,
unsigned byte_offset,
unsigned length);
using TypedArrayBase<unsigned>::Set;
using IntegralTypedArrayBase<unsigned>::Set;
ViewType GetType() const override { return kTypeUint32; }
private:
inline Uint32Array(scoped_refptr<ArrayBuffer>,
unsigned byte_offset,
unsigned length);
// Make constructor visible to superclass.
friend class TypedArrayBase<unsigned>;
};
scoped_refptr<Uint32Array> Uint32Array::Create(unsigned length) {
return TypedArrayBase<unsigned>::Create<Uint32Array>(length);
}
scoped_refptr<Uint32Array> Uint32Array::Create(const unsigned* array,
unsigned length) {
return TypedArrayBase<unsigned>::Create<Uint32Array>(array, length);
}
scoped_refptr<Uint32Array> Uint32Array::Create(
scoped_refptr<ArrayBuffer> buffer,
unsigned byte_offset,
unsigned length) {
return TypedArrayBase<unsigned>::Create<Uint32Array>(std::move(buffer),
byte_offset, length);
}
Uint32Array::Uint32Array(scoped_refptr<ArrayBuffer> buffer,
unsigned byte_offset,
unsigned length)
: IntegralTypedArrayBase<unsigned>(std::move(buffer), byte_offset, length) {
}
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_TYPED_ARRAYS_ARRAY_BUFFER_UINT32_ARRAY_H_
/*
* Copyright (C) 2009 Apple Inc. All rights reserved.
* Copyright (C) 2009 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_TYPED_ARRAYS_ARRAY_BUFFER_UINT8_ARRAY_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_TYPED_ARRAYS_ARRAY_BUFFER_UINT8_ARRAY_H_
#include "third_party/blink/renderer/core/typed_arrays/array_buffer/integral_typed_array_base.h"
namespace blink {
class ArrayBuffer;
class Uint8Array : public IntegralTypedArrayBase<unsigned char> {
public:
static inline scoped_refptr<Uint8Array> Create(unsigned length);
static inline scoped_refptr<Uint8Array> Create(const unsigned char* array,
unsigned length);
static inline scoped_refptr<Uint8Array> Create(scoped_refptr<ArrayBuffer>,
unsigned byte_offset,
unsigned length);
using TypedArrayBase<unsigned char>::Set;
using IntegralTypedArrayBase<unsigned char>::Set;
ViewType GetType() const override { return kTypeUint8; }
protected:
inline Uint8Array(scoped_refptr<ArrayBuffer>,
unsigned byte_offset,
unsigned length);
// Make constructor visible to superclass.
friend class TypedArrayBase<unsigned char>;
};
scoped_refptr<Uint8Array> Uint8Array::Create(unsigned length) {
return TypedArrayBase<unsigned char>::Create<Uint8Array>(length);
}
scoped_refptr<Uint8Array> Uint8Array::Create(const unsigned char* array,
unsigned length) {
return TypedArrayBase<unsigned char>::Create<Uint8Array>(array, length);
}
scoped_refptr<Uint8Array> Uint8Array::Create(scoped_refptr<ArrayBuffer> buffer,
unsigned byte_offset,
unsigned length) {
return TypedArrayBase<unsigned char>::Create<Uint8Array>(std::move(buffer),
byte_offset, length);
}
Uint8Array::Uint8Array(scoped_refptr<ArrayBuffer> buffer,
unsigned byte_offset,
unsigned length)
: IntegralTypedArrayBase<unsigned char>(std::move(buffer),
byte_offset,
length) {}
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_TYPED_ARRAYS_ARRAY_BUFFER_UINT8_ARRAY_H_
/*
* Copyright (C) 2009 Apple Inc. All rights reserved.
* Copyright (C) 2009 Google Inc. All rights reserved.
* Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_TYPED_ARRAYS_ARRAY_BUFFER_UINT8_CLAMPED_ARRAY_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_TYPED_ARRAYS_ARRAY_BUFFER_UINT8_CLAMPED_ARRAY_H_
#include "third_party/blink/renderer/core/typed_arrays/array_buffer/uint8_array.h"
#include "third_party/blink/renderer/platform/wtf/math_extras.h"
namespace blink {
class Uint8ClampedArray final : public Uint8Array {
public:
static inline scoped_refptr<Uint8ClampedArray> Create(unsigned length);
static inline scoped_refptr<Uint8ClampedArray> Create(
const unsigned char* array,
unsigned length);
static inline scoped_refptr<Uint8ClampedArray>
Create(scoped_refptr<ArrayBuffer>, unsigned byte_offset, unsigned length);
using TypedArrayBase<unsigned char>::Set;
inline void Set(unsigned index, double value);
ViewType GetType() const override { return kTypeUint8Clamped; }
private:
inline Uint8ClampedArray(scoped_refptr<ArrayBuffer>,
unsigned byte_offset,
unsigned length);
// Make constructor visible to superclass.
friend class TypedArrayBase<unsigned char>;
};
scoped_refptr<Uint8ClampedArray> Uint8ClampedArray::Create(unsigned length) {
return TypedArrayBase<unsigned char>::Create<Uint8ClampedArray>(length);
}
scoped_refptr<Uint8ClampedArray> Uint8ClampedArray::Create(
const unsigned char* array,
unsigned length) {
return TypedArrayBase<unsigned char>::Create<Uint8ClampedArray>(array,
length);
}
scoped_refptr<Uint8ClampedArray> Uint8ClampedArray::Create(
scoped_refptr<ArrayBuffer> buffer,
unsigned byte_offset,
unsigned length) {
return TypedArrayBase<unsigned char>::Create<Uint8ClampedArray>(
std::move(buffer), byte_offset, length);
}
void Uint8ClampedArray::Set(unsigned index, double value) {
if (index >= length_)
return;
if (std::isnan(value) || value < 0)
value = 0;
else if (value > 255)
value = 255;
Data()[index] = static_cast<unsigned char>(lrint(value));
}
Uint8ClampedArray::Uint8ClampedArray(scoped_refptr<ArrayBuffer> buffer,
unsigned byte_offset,
unsigned length)
: Uint8Array(std::move(buffer), byte_offset, length) {}
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_TYPED_ARRAYS_ARRAY_BUFFER_UINT8_CLAMPED_ARRAY_H_
......@@ -75,14 +75,21 @@ DOMTypedArray<TypedArray, V8TypedArray>::GetWrapperTypeInfo() const {
DOMTypedArray<TypedArray, V8TypedArray>>::Type::GetWrapperTypeInfo();
}
template class CORE_TEMPLATE_EXPORT DOMTypedArray<Int8Array, v8::Int8Array>;
template class CORE_TEMPLATE_EXPORT DOMTypedArray<Int16Array, v8::Int16Array>;
template class CORE_TEMPLATE_EXPORT DOMTypedArray<Int32Array, v8::Int32Array>;
template class CORE_TEMPLATE_EXPORT DOMTypedArray<Uint8Array, v8::Uint8Array>;
template class CORE_TEMPLATE_EXPORT
DOMTypedArray<Uint8ClampedArray, v8::Uint8ClampedArray>;
template class CORE_TEMPLATE_EXPORT DOMTypedArray<Uint16Array, v8::Uint16Array>;
template class CORE_TEMPLATE_EXPORT DOMTypedArray<Uint32Array, v8::Uint32Array>;
DOMTypedArray<IntegralTypedArrayBase<int8_t>, v8::Int8Array>;
template class CORE_TEMPLATE_EXPORT
DOMTypedArray<IntegralTypedArrayBase<int16_t>, v8::Int16Array>;
template class CORE_TEMPLATE_EXPORT
DOMTypedArray<IntegralTypedArrayBase<int32_t>, v8::Int32Array>;
template class CORE_TEMPLATE_EXPORT
DOMTypedArray<IntegralTypedArrayBase<uint8_t>, v8::Uint8Array>;
template class CORE_TEMPLATE_EXPORT
DOMTypedArray<IntegralTypedArrayBase<uint8_t, /*clamped=*/true>,
v8::Uint8ClampedArray>;
template class CORE_TEMPLATE_EXPORT
DOMTypedArray<IntegralTypedArrayBase<uint16_t>, v8::Uint16Array>;
template class CORE_TEMPLATE_EXPORT
DOMTypedArray<IntegralTypedArrayBase<uint32_t>, v8::Uint32Array>;
template class CORE_TEMPLATE_EXPORT
DOMTypedArray<BigInt64Array, v8::BigInt64Array>;
template class CORE_TEMPLATE_EXPORT
......
......@@ -10,13 +10,7 @@
#include "third_party/blink/renderer/core/typed_arrays/array_buffer/biguint64_array.h"
#include "third_party/blink/renderer/core/typed_arrays/array_buffer/float32_array.h"
#include "third_party/blink/renderer/core/typed_arrays/array_buffer/float64_array.h"
#include "third_party/blink/renderer/core/typed_arrays/array_buffer/int16_array.h"
#include "third_party/blink/renderer/core/typed_arrays/array_buffer/int32_array.h"
#include "third_party/blink/renderer/core/typed_arrays/array_buffer/int8_array.h"
#include "third_party/blink/renderer/core/typed_arrays/array_buffer/uint16_array.h"
#include "third_party/blink/renderer/core/typed_arrays/array_buffer/uint32_array.h"
#include "third_party/blink/renderer/core/typed_arrays/array_buffer/uint8_array.h"
#include "third_party/blink/renderer/core/typed_arrays/array_buffer/uint8_clamped_array.h"
#include "third_party/blink/renderer/core/typed_arrays/array_buffer/integral_typed_array_base.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer_view.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_shared_array_buffer.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
......@@ -91,19 +85,20 @@ class DOMTypedArray final : public DOMArrayBufferView {
};
extern template class CORE_EXTERN_TEMPLATE_EXPORT
DOMTypedArray<Int8Array, v8::Int8Array>;
DOMTypedArray<IntegralTypedArrayBase<int8_t>, v8::Int8Array>;
extern template class CORE_EXTERN_TEMPLATE_EXPORT
DOMTypedArray<Int16Array, v8::Int16Array>;
DOMTypedArray<IntegralTypedArrayBase<int16_t>, v8::Int16Array>;
extern template class CORE_EXTERN_TEMPLATE_EXPORT
DOMTypedArray<Int32Array, v8::Int32Array>;
DOMTypedArray<IntegralTypedArrayBase<int32_t>, v8::Int32Array>;
extern template class CORE_EXTERN_TEMPLATE_EXPORT
DOMTypedArray<Uint8Array, v8::Uint8Array>;
DOMTypedArray<IntegralTypedArrayBase<uint8_t>, v8::Uint8Array>;
extern template class CORE_EXTERN_TEMPLATE_EXPORT
DOMTypedArray<Uint8ClampedArray, v8::Uint8ClampedArray>;
DOMTypedArray<IntegralTypedArrayBase<uint8_t, /*clamped=*/true>,
v8::Uint8ClampedArray>;
extern template class CORE_EXTERN_TEMPLATE_EXPORT
DOMTypedArray<Uint16Array, v8::Uint16Array>;
DOMTypedArray<IntegralTypedArrayBase<uint16_t>, v8::Uint16Array>;
extern template class CORE_EXTERN_TEMPLATE_EXPORT
DOMTypedArray<Uint32Array, v8::Uint32Array>;
DOMTypedArray<IntegralTypedArrayBase<uint32_t>, v8::Uint32Array>;
extern template class CORE_EXTERN_TEMPLATE_EXPORT
DOMTypedArray<BigInt64Array, v8::BigInt64Array>;
extern template class CORE_EXTERN_TEMPLATE_EXPORT
......@@ -113,14 +108,21 @@ extern template class CORE_EXTERN_TEMPLATE_EXPORT
extern template class CORE_EXTERN_TEMPLATE_EXPORT
DOMTypedArray<Float64Array, v8::Float64Array>;
typedef DOMTypedArray<Int8Array, v8::Int8Array> DOMInt8Array;
typedef DOMTypedArray<Int16Array, v8::Int16Array> DOMInt16Array;
typedef DOMTypedArray<Int32Array, v8::Int32Array> DOMInt32Array;
typedef DOMTypedArray<Uint8Array, v8::Uint8Array> DOMUint8Array;
typedef DOMTypedArray<Uint8ClampedArray, v8::Uint8ClampedArray>
typedef DOMTypedArray<IntegralTypedArrayBase<int8_t>, v8::Int8Array>
DOMInt8Array;
typedef DOMTypedArray<IntegralTypedArrayBase<int16_t>, v8::Int16Array>
DOMInt16Array;
typedef DOMTypedArray<IntegralTypedArrayBase<int32_t>, v8::Int32Array>
DOMInt32Array;
typedef DOMTypedArray<IntegralTypedArrayBase<uint8_t>, v8::Uint8Array>
DOMUint8Array;
typedef DOMTypedArray<IntegralTypedArrayBase<uint8_t, /*clamped=*/true>,
v8::Uint8ClampedArray>
DOMUint8ClampedArray;
typedef DOMTypedArray<Uint16Array, v8::Uint16Array> DOMUint16Array;
typedef DOMTypedArray<Uint32Array, v8::Uint32Array> DOMUint32Array;
typedef DOMTypedArray<IntegralTypedArrayBase<uint16_t>, v8::Uint16Array>
DOMUint16Array;
typedef DOMTypedArray<IntegralTypedArrayBase<uint32_t>, v8::Uint32Array>
DOMUint32Array;
typedef DOMTypedArray<BigInt64Array, v8::BigInt64Array> DOMBigInt64Array;
typedef DOMTypedArray<BigUint64Array, v8::BigUint64Array> DOMBigUint64Array;
typedef DOMTypedArray<Float32Array, v8::Float32Array> DOMFloat32Array;
......
......@@ -34,8 +34,10 @@ class TypedFlexibleArrayBufferView final : public FlexibleArrayBufferView {
};
using FlexibleFloat32ArrayView = TypedFlexibleArrayBufferView<Float32Array>;
using FlexibleInt32ArrayView = TypedFlexibleArrayBufferView<Int32Array>;
using FlexibleUint32ArrayView = TypedFlexibleArrayBufferView<Uint32Array>;
using FlexibleInt32ArrayView =
TypedFlexibleArrayBufferView<IntegralTypedArrayBase<int32_t>>;
using FlexibleUint32ArrayView =
TypedFlexibleArrayBufferView<IntegralTypedArrayBase<uint32_t>>;
} // namespace blink
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment