Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(518)

Side by Side Diff: third_party/WebKit/Source/core/dom/ArrayBufferViewHelpers.h

Issue 2815793002: [SharedArrayBuffer] Add "AllowShared" extended attribute, used for WebGL (Closed)
Patch Set: merge HEAD Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NotShared_h 5 #ifndef ArrayBufferViewHelpers_h
6 #define NotShared_h 6 #define ArrayBufferViewHelpers_h
7
8 #include <type_traits>
9 #include "core/dom/DOMArrayBufferView.h"
10 #include "platform/heap/Handle.h"
11 #include "platform/wtf/TypeTraits.h"
12
13 namespace blink {
7 14
8 // A wrapper template type that is used to ensure that a TypedArray is not 15 // A wrapper template type that is used to ensure that a TypedArray is not
9 // backed by a SharedArrayBuffer. 16 // backed by a SharedArrayBuffer.
10 // 17 //
11 // Typically this is used as an annotation on C++ functions that are called by 18 // Typically this is used as an annotation on C++ functions that are called by
12 // the bindings layer, e.g.: 19 // the bindings layer, e.g.:
13 // 20 //
14 // void Foo(NotShared<DOMUint32Array> param) { 21 // void Foo(NotShared<DOMUint32Array> param) {
15 // DOMUint32Array* array = param.View(); 22 // DOMUint32Array* array = param.View();
16 // ... 23 // ...
17 // } 24 // }
18
19 #include "platform/heap/Handle.h"
20
21 namespace blink {
22
23 template <typename T> 25 template <typename T>
24 class NotShared { 26 class NotShared {
27 static_assert(WTF::IsSubclass<typename std::remove_const<T>::type,
28 DOMArrayBufferView>::value,
29 "NotShared<T> must have T as subclass of DOMArrayBufferView");
25 STACK_ALLOCATED(); 30 STACK_ALLOCATED();
26 31
27 public: 32 public:
28 using TypedArrayType = T; 33 using TypedArrayType = T;
29 34
30 NotShared() {} 35 NotShared() {}
31 36
32 explicit NotShared(T* typedArray) : typed_array_(typedArray) { 37 explicit NotShared(T* typedArray) : typed_array_(typedArray) {
33 DCHECK(!(typedArray && typedArray->View()->IsShared())); 38 DCHECK(!(typedArray && typedArray->View()->IsShared()));
34 } 39 }
(...skipping 21 matching lines...) Expand all
56 private: 61 private:
57 // Must use an untraced member here since this object may be constructed on a 62 // Must use an untraced member here since this object may be constructed on a
58 // thread without a ThreadState (e.g. an Audio worklet). It is safe in that 63 // thread without a ThreadState (e.g. an Audio worklet). It is safe in that
59 // case because the pointed-to ArrayBuffer is being kept alive another way 64 // case because the pointed-to ArrayBuffer is being kept alive another way
60 // (e.g. CrossThreadPersistent). 65 // (e.g. CrossThreadPersistent).
61 // 66 //
62 // TODO(binji): update to using Member, see crbug.com/710295. 67 // TODO(binji): update to using Member, see crbug.com/710295.
63 UntracedMember<T> typed_array_; 68 UntracedMember<T> typed_array_;
64 }; 69 };
65 70
71 // A wrapper template type that specifies that a TypedArray may be backed by a
72 // SharedArrayBuffer.
73 //
74 // Typically this is used as an annotation on C++ functions that are called by
75 // the bindings layer, e.g.:
76 //
77 // void Foo(MaybeShared<DOMUint32Array> param) {
78 // DOMUint32Array* array = param.View();
79 // ...
80 // }
81 template <typename T>
82 class MaybeShared {
83 static_assert(WTF::IsSubclass<typename std::remove_const<T>::type,
84 DOMArrayBufferView>::value,
85 "MaybeShared<T> must have T as subclass of DOMArrayBufferView");
86 STACK_ALLOCATED();
87
88 public:
89 using TypedArrayType = T;
90
91 MaybeShared() {}
92
93 explicit MaybeShared(T* typedArray) : typed_array_(typedArray) {}
94 MaybeShared(const MaybeShared& other) = default;
95 template <typename U>
96 MaybeShared(const MaybeShared<U>& other) : typed_array_(other.View()) {}
97 template <typename U>
98 MaybeShared(const Member<U>& other) {
99 typed_array_ = other.Get();
100 }
101
102 MaybeShared& operator=(const MaybeShared& other) = default;
103 template <typename U>
104 MaybeShared& operator=(const MaybeShared<U>& other) {
105 typed_array_ = other.View();
106 return *this;
107 }
108
109 T* View() const { return typed_array_.Get(); }
110
111 bool operator!() const { return !typed_array_; }
112 explicit operator bool() const { return !!typed_array_; }
113
114 private:
115 Member<T> typed_array_;
116 };
117
66 } // namespace blink 118 } // namespace blink
67 119
68 #endif // NotShared_h 120 #endif // ArrayBufferViewHelpers_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698