OLD | NEW |
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 #include "core/html/Float32ImageData.h" | 5 #include "core/html/Float32ImageData.h" |
6 | 6 |
7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
8 #include "bindings/core/v8/V8Float32Array.h" | 8 #include "bindings/core/v8/V8Float32Array.h" |
9 #include "core/dom/ExceptionCode.h" | 9 #include "core/dom/ExceptionCode.h" |
10 #include "core/frame/ImageBitmap.h" | 10 #include "core/frame/ImageBitmap.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 Float32ImageData* Float32ImageData::create(const IntSize& size) { | 46 Float32ImageData* Float32ImageData::create(const IntSize& size) { |
47 if (!Float32ImageData::validateConstructorArguments(kParamSize, &size)) | 47 if (!Float32ImageData::validateConstructorArguments(kParamSize, &size)) |
48 return nullptr; | 48 return nullptr; |
49 DOMFloat32Array* dataArray = | 49 DOMFloat32Array* dataArray = |
50 Float32ImageData::allocateAndValidateFloat32Array(4 * size.width() * | 50 Float32ImageData::allocateAndValidateFloat32Array(4 * size.width() * |
51 size.height()); | 51 size.height()); |
52 return dataArray ? new Float32ImageData(size, dataArray) : nullptr; | 52 return dataArray ? new Float32ImageData(size, dataArray) : nullptr; |
53 } | 53 } |
54 | 54 |
55 Float32ImageData* Float32ImageData::create(const IntSize& size, | 55 Float32ImageData* Float32ImageData::create( |
56 DOMFloat32Array* dataArray) { | 56 const IntSize& size, |
| 57 const MaybeShared<DOMFloat32Array>& maybeShared) { |
| 58 if (!ImageData::validateDataArgumentIsNotShared(maybeShared, nullptr)) |
| 59 return nullptr; |
| 60 DOMFloat32Array* data = maybeShared.viewNotShared(); |
57 if (!Float32ImageData::validateConstructorArguments(kParamSize | kParamData, | 61 if (!Float32ImageData::validateConstructorArguments(kParamSize | kParamData, |
58 &size, 0, 0, dataArray)) | 62 &size, 0, 0, data)) |
59 return nullptr; | 63 return nullptr; |
60 return new Float32ImageData(size, dataArray); | 64 return new Float32ImageData(size, data); |
61 } | 65 } |
62 | 66 |
63 Float32ImageData* Float32ImageData::create(unsigned width, | 67 Float32ImageData* Float32ImageData::create(unsigned width, |
64 unsigned height, | 68 unsigned height, |
65 ExceptionState& exceptionState) { | 69 ExceptionState& exceptionState) { |
66 if (!Float32ImageData::validateConstructorArguments( | 70 if (!Float32ImageData::validateConstructorArguments( |
67 kParamWidth | kParamHeight, nullptr, width, height, nullptr, nullptr, | 71 kParamWidth | kParamHeight, nullptr, width, height, nullptr, nullptr, |
68 &exceptionState)) | 72 &exceptionState)) |
69 return nullptr; | 73 return nullptr; |
70 DOMFloat32Array* dataArray = | 74 DOMFloat32Array* dataArray = |
71 Float32ImageData::allocateAndValidateFloat32Array(4 * width * height, | 75 Float32ImageData::allocateAndValidateFloat32Array(4 * width * height, |
72 &exceptionState); | 76 &exceptionState); |
73 return dataArray ? new Float32ImageData(IntSize(width, height), dataArray) | 77 return dataArray ? new Float32ImageData(IntSize(width, height), dataArray) |
74 : nullptr; | 78 : nullptr; |
75 } | 79 } |
76 | 80 |
77 Float32ImageData* Float32ImageData::create(DOMFloat32Array* data, | 81 Float32ImageData* Float32ImageData::create( |
78 unsigned width, | 82 const MaybeShared<DOMFloat32Array>& maybeShared, |
79 ExceptionState& exceptionState) { | 83 unsigned width, |
| 84 ExceptionState& exceptionState) { |
| 85 if (!ImageData::validateDataArgumentIsNotShared(maybeShared, &exceptionState)) |
| 86 return nullptr; |
| 87 DOMFloat32Array* data = maybeShared.viewNotShared(); |
80 if (!Float32ImageData::validateConstructorArguments(kParamData | kParamWidth, | 88 if (!Float32ImageData::validateConstructorArguments(kParamData | kParamWidth, |
81 nullptr, width, 0, data, | 89 nullptr, width, 0, data, |
82 nullptr, &exceptionState)) | 90 nullptr, &exceptionState)) |
83 return nullptr; | 91 return nullptr; |
84 unsigned height = data->length() / (width * 4); | 92 unsigned height = data->length() / (width * 4); |
85 return new Float32ImageData(IntSize(width, height), data); | 93 return new Float32ImageData(IntSize(width, height), data); |
86 } | 94 } |
87 | 95 |
88 Float32ImageData* Float32ImageData::create(DOMFloat32Array* data, | 96 Float32ImageData* Float32ImageData::create( |
89 unsigned width, | 97 const MaybeShared<DOMFloat32Array>& maybeShared, |
90 unsigned height, | 98 unsigned width, |
91 ExceptionState& exceptionState) { | 99 unsigned height, |
| 100 ExceptionState& exceptionState) { |
| 101 if (!ImageData::validateDataArgumentIsNotShared(maybeShared, nullptr)) |
| 102 return nullptr; |
| 103 DOMFloat32Array* data = maybeShared.viewNotShared(); |
92 if (!Float32ImageData::validateConstructorArguments( | 104 if (!Float32ImageData::validateConstructorArguments( |
93 kParamData | kParamWidth | kParamHeight, nullptr, width, height, data, | 105 kParamData | kParamWidth | kParamHeight, nullptr, width, height, data, |
94 nullptr, &exceptionState)) | 106 nullptr, &exceptionState)) |
95 return nullptr; | 107 return nullptr; |
96 return new Float32ImageData(IntSize(width, height), data); | 108 return new Float32ImageData(IntSize(width, height), data); |
97 } | 109 } |
98 | 110 |
99 Float32ImageData* Float32ImageData::create(unsigned width, | 111 Float32ImageData* Float32ImageData::create(unsigned width, |
100 unsigned height, | 112 unsigned height, |
101 String colorSpace, | 113 String colorSpace, |
102 ExceptionState& exceptionState) { | 114 ExceptionState& exceptionState) { |
103 if (!Float32ImageData::validateConstructorArguments( | 115 if (!Float32ImageData::validateConstructorArguments( |
104 kParamWidth | kParamHeight | kParamColorSpace, nullptr, width, height, | 116 kParamWidth | kParamHeight | kParamColorSpace, nullptr, width, height, |
105 nullptr, &colorSpace, &exceptionState)) | 117 nullptr, &colorSpace, &exceptionState)) |
106 return nullptr; | 118 return nullptr; |
107 | 119 |
108 DOMFloat32Array* dataArray = | 120 DOMFloat32Array* dataArray = |
109 Float32ImageData::allocateAndValidateFloat32Array(4 * width * height, | 121 Float32ImageData::allocateAndValidateFloat32Array(4 * width * height, |
110 &exceptionState); | 122 &exceptionState); |
111 return dataArray ? new Float32ImageData(IntSize(width, height), dataArray, | 123 return dataArray ? new Float32ImageData(IntSize(width, height), dataArray, |
112 colorSpace) | 124 colorSpace) |
113 : nullptr; | 125 : nullptr; |
114 } | 126 } |
115 | 127 |
116 Float32ImageData* Float32ImageData::create(DOMFloat32Array* data, | 128 Float32ImageData* Float32ImageData::create( |
117 unsigned width, | 129 const MaybeShared<DOMFloat32Array>& maybeShared, |
118 String colorSpace, | 130 unsigned width, |
119 ExceptionState& exceptionState) { | 131 String colorSpace, |
| 132 ExceptionState& exceptionState) { |
| 133 if (!ImageData::validateDataArgumentIsNotShared(maybeShared, nullptr)) |
| 134 return nullptr; |
| 135 DOMFloat32Array* data = maybeShared.viewNotShared(); |
120 if (!Float32ImageData::validateConstructorArguments( | 136 if (!Float32ImageData::validateConstructorArguments( |
121 kParamData | kParamWidth | kParamColorSpace, nullptr, width, 0, data, | 137 kParamData | kParamWidth | kParamColorSpace, nullptr, width, 0, data, |
122 &colorSpace, &exceptionState)) | 138 &colorSpace, &exceptionState)) |
123 return nullptr; | 139 return nullptr; |
124 unsigned height = data->length() / (width * 4); | 140 unsigned height = data->length() / (width * 4); |
125 return new Float32ImageData(IntSize(width, height), data, colorSpace); | 141 return new Float32ImageData(IntSize(width, height), data, colorSpace); |
126 } | 142 } |
127 | 143 |
128 Float32ImageData* Float32ImageData::create(DOMFloat32Array* data, | 144 Float32ImageData* Float32ImageData::create( |
129 unsigned width, | 145 const MaybeShared<DOMFloat32Array>& maybeShared, |
130 unsigned height, | 146 unsigned width, |
131 String colorSpace, | 147 unsigned height, |
132 ExceptionState& exceptionState) { | 148 String colorSpace, |
| 149 ExceptionState& exceptionState) { |
| 150 if (!ImageData::validateDataArgumentIsNotShared(maybeShared, nullptr)) |
| 151 return nullptr; |
| 152 DOMFloat32Array* data = maybeShared.viewNotShared(); |
133 if (!Float32ImageData::validateConstructorArguments( | 153 if (!Float32ImageData::validateConstructorArguments( |
134 kParamData | kParamWidth | kParamHeight | kParamColorSpace, nullptr, | 154 kParamData | kParamWidth | kParamHeight | kParamColorSpace, nullptr, |
135 width, height, data, &colorSpace, &exceptionState)) | 155 width, height, data, &colorSpace, &exceptionState)) |
136 return nullptr; | 156 return nullptr; |
137 return new Float32ImageData(IntSize(width, height), data, colorSpace); | 157 return new Float32ImageData(IntSize(width, height), data, colorSpace); |
138 } | 158 } |
139 | 159 |
140 v8::Local<v8::Object> Float32ImageData::associateWithWrapper( | 160 v8::Local<v8::Object> Float32ImageData::associateWithWrapper( |
141 v8::Isolate* isolate, | 161 v8::Isolate* isolate, |
142 const WrapperTypeInfo* wrapperType, | 162 const WrapperTypeInfo* wrapperType, |
(...skipping 21 matching lines...) Expand all Loading... |
164 : m_size(size), | 184 : m_size(size), |
165 m_colorSpace(ImageData::getImageDataColorSpace(colorSpaceName)), | 185 m_colorSpace(ImageData::getImageDataColorSpace(colorSpaceName)), |
166 m_data(dataArray) { | 186 m_data(dataArray) { |
167 DCHECK_GE(size.width(), 0); | 187 DCHECK_GE(size.width(), 0); |
168 DCHECK_GE(size.height(), 0); | 188 DCHECK_GE(size.height(), 0); |
169 SECURITY_CHECK(static_cast<unsigned>(size.width() * size.height() * 4) <= | 189 SECURITY_CHECK(static_cast<unsigned>(size.width() * size.height() * 4) <= |
170 m_data->length()); | 190 m_data->length()); |
171 } | 191 } |
172 | 192 |
173 } // namespace blink | 193 } // namespace blink |
OLD | NEW |