Bumping manifests a=b2g-bump
[gecko.git] / gfx / gl / HeapCopyOfStackArray.h
blobe6dbb2a1fe251155fe97a2cd7b4e20c3632e9812
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* vim: set ts=8 sts=4 et sw=4 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef HEAPCOPYOFSTACKARRAY_H_
8 #define HEAPCOPYOFSTACKARRAY_H_
10 #include "mozilla/Attributes.h"
11 #include "mozilla/Scoped.h"
13 #include <string.h>
15 namespace mozilla {
17 // Takes a stack array and copies it into a heap buffer.
18 // Useful to retain the convenience of declaring static arrays, while
19 // avoiding passing stack pointers to the GL (see bug 1005658).
21 template <typename ElemType>
22 class HeapCopyOfStackArray
24 public:
25 template<size_t N>
26 HeapCopyOfStackArray(ElemType (&array)[N])
27 : mArrayLength(N)
28 , mArrayData(new ElemType[N])
30 memcpy(mArrayData, &array[0], N * sizeof(ElemType));
33 ElemType* Data() const { return mArrayData; }
34 size_t ArrayLength() const { return mArrayLength; }
35 size_t ByteLength() const { return mArrayLength * sizeof(ElemType); }
37 private:
38 HeapCopyOfStackArray() = delete;
39 HeapCopyOfStackArray(const HeapCopyOfStackArray&) = delete;
41 const size_t mArrayLength;
42 ScopedDeletePtr<ElemType> const mArrayData;
47 #endif // HEAPCOPYOFSTACKARRAY_H_