OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 kParamHeight = 1 << 2, | 57 kParamHeight = 1 << 2, |
58 kParamData = 1 << 3, | 58 kParamData = 1 << 3, |
59 }; | 59 }; |
60 | 60 |
61 enum ImageDataStorageFormat { | 61 enum ImageDataStorageFormat { |
62 kUint8ClampedArrayStorageFormat, | 62 kUint8ClampedArrayStorageFormat, |
63 kUint16ArrayStorageFormat, | 63 kUint16ArrayStorageFormat, |
64 kFloat32ArrayStorageFormat, | 64 kFloat32ArrayStorageFormat, |
65 }; | 65 }; |
66 | 66 |
| 67 enum StorageFormatSource { |
| 68 kStorageFormatFromColorSettings, |
| 69 kStorageFormatFromBufferType, |
| 70 }; |
| 71 |
67 constexpr const char* kUint8ClampedArrayStorageFormatName = "uint8"; | 72 constexpr const char* kUint8ClampedArrayStorageFormatName = "uint8"; |
68 constexpr const char* kUint16ArrayStorageFormatName = "uint16"; | 73 constexpr const char* kUint16ArrayStorageFormatName = "uint16"; |
69 constexpr const char* kFloat32ArrayStorageFormatName = "float32"; | 74 constexpr const char* kFloat32ArrayStorageFormatName = "float32"; |
70 | 75 |
71 class CORE_EXPORT ImageData final : public GarbageCollectedFinalized<ImageData>, | 76 class CORE_EXPORT ImageData final : public GarbageCollectedFinalized<ImageData>, |
72 public ScriptWrappable, | 77 public ScriptWrappable, |
73 public ImageBitmapSource { | 78 public ImageBitmapSource { |
74 DEFINE_WRAPPERTYPEINFO(); | 79 DEFINE_WRAPPERTYPEINFO(); |
75 | 80 |
76 public: | 81 public: |
77 static ImageData* create(const IntSize&, | 82 static ImageData* create(const IntSize&); |
78 const ImageDataColorSettings* = nullptr); | 83 static ImageData* create(const IntSize&, DOMUint8ClampedArray*); |
79 static ImageData* create(const IntSize&, | |
80 DOMArrayBufferView*, | |
81 const ImageDataColorSettings* = nullptr); | |
82 | 84 |
83 static ImageData* create(unsigned width, unsigned height, ExceptionState&); | 85 static ImageData* create(unsigned width, unsigned height, ExceptionState&); |
84 static ImageData* create(DOMUint8ClampedArray*, | 86 static ImageData* create(DOMUint8ClampedArray*, |
85 unsigned width, | 87 unsigned width, |
86 ExceptionState&); | 88 ExceptionState&); |
87 static ImageData* create(DOMUint8ClampedArray*, | 89 static ImageData* create(DOMUint8ClampedArray*, |
88 unsigned width, | 90 unsigned width, |
89 unsigned height, | 91 unsigned height, |
90 ExceptionState&); | 92 ExceptionState&); |
91 | 93 |
| 94 static ImageData* createForTest(const IntSize&); |
| 95 |
92 ImageData* createImageData(unsigned width, | 96 ImageData* createImageData(unsigned width, |
93 unsigned height, | 97 unsigned height, |
94 const ImageDataColorSettings&, | 98 const ImageDataColorSettings&, |
95 ExceptionState&); | 99 ExceptionState&); |
96 ImageData* createImageData(ImageDataArray&, | 100 ImageData* createImageData(ImageDataArray&, |
97 unsigned width, | 101 unsigned width, |
98 unsigned height, | 102 unsigned height, |
99 ImageDataColorSettings&, | 103 const ImageDataColorSettings&, |
100 ExceptionState&); | 104 ExceptionState&); |
101 | 105 |
102 static ImageData* createForTest(const IntSize&); | 106 static ImageDataStorageFormat getImageDataStorageFormat(const String&); |
103 static ImageData* createForTest(const IntSize&, | |
104 DOMArrayBufferView*, | |
105 const ImageDataColorSettings* = nullptr); | |
106 static sk_sp<SkColorSpace> getSkColorSpaceForTest(const CanvasColorSpace&, | |
107 const CanvasPixelFormat&); | |
108 | |
109 static CanvasColorSpace canvasColorSpace(const String&); | |
110 static String canvasColorSpaceName(const CanvasColorSpace&); | |
111 static ImageDataStorageFormat imageDataStorageFormat(const String&); | |
112 static unsigned storageFormatDataSize(const String&); | |
113 static DOMArrayBufferView* | |
114 convertPixelsFromCanvasPixelFormatToImageDataStorageFormat( | |
115 WTF::ArrayBufferContents&, | |
116 CanvasPixelFormat, | |
117 ImageDataStorageFormat); | |
118 | 107 |
119 IntSize size() const { return m_size; } | 108 IntSize size() const { return m_size; } |
120 int width() const { return m_size.width(); } | 109 int width() const { return m_size.width(); } |
121 int height() const { return m_size.height(); } | 110 int height() const { return m_size.height(); } |
122 | 111 |
123 DOMUint8ClampedArray* data(); | 112 DOMUint8ClampedArray* data(); |
124 const DOMUint8ClampedArray* data() const; | 113 const DOMUint8ClampedArray* data() const; |
125 ImageDataArray& dataUnion() { return m_dataUnion; } | 114 ImageDataArray& dataUnion() { return m_dataUnion; } |
126 const ImageDataArray& dataUnion() const { return m_dataUnion; } | 115 const ImageDataArray& dataUnion() const { return m_dataUnion; } |
127 void dataUnion(ImageDataArray& result) { result = m_dataUnion; }; | 116 void dataUnion(ImageDataArray& result) { result = m_dataUnion; }; |
128 const ImageDataColorSettings& colorSettings() const { | 117 const ImageDataColorSettings& colorSettings() const { |
129 return m_colorSettings; | 118 return m_colorSettings; |
130 } | 119 } |
131 void colorSettings(ImageDataColorSettings& result) { | 120 void colorSettings(ImageDataColorSettings& result) { |
132 result = m_colorSettings; | 121 result = m_colorSettings; |
133 }; | 122 }; |
134 | 123 |
135 sk_sp<SkColorSpace> skColorSpace(); | 124 sk_sp<SkColorSpace> getSkColorSpace(); |
136 bool imageDataInCanvasColorSettings(const CanvasColorSpace&, | |
137 const CanvasPixelFormat&, | |
138 std::unique_ptr<uint8_t[]>&); | |
139 | 125 |
140 // ImageBitmapSource implementation | 126 // ImageBitmapSource implementation |
141 IntSize bitmapSourceSize() const override { return m_size; } | 127 IntSize bitmapSourceSize() const override { return m_size; } |
142 ScriptPromise createImageBitmap(ScriptState*, | 128 ScriptPromise createImageBitmap(ScriptState*, |
143 EventTarget&, | 129 EventTarget&, |
144 Optional<IntRect> cropRect, | 130 Optional<IntRect> cropRect, |
145 const ImageBitmapOptions&, | 131 const ImageBitmapOptions&, |
146 ExceptionState&) override; | 132 ExceptionState&) override; |
147 | 133 |
148 void trace(Visitor*); | 134 void trace(Visitor*); |
149 | 135 |
150 WARN_UNUSED_RESULT v8::Local<v8::Object> associateWithWrapper( | 136 WARN_UNUSED_RESULT v8::Local<v8::Object> associateWithWrapper( |
151 v8::Isolate*, | 137 v8::Isolate*, |
152 const WrapperTypeInfo*, | 138 const WrapperTypeInfo*, |
153 v8::Local<v8::Object> wrapper) override; | 139 v8::Local<v8::Object> wrapper) override; |
154 | 140 |
155 static bool validateConstructorArguments( | 141 static bool validateConstructorArguments(const unsigned&, |
156 const unsigned&, | 142 const IntSize* = nullptr, |
157 const IntSize* = nullptr, | 143 const unsigned& = 0, |
158 const unsigned& = 0, | 144 const unsigned& = 0, |
159 const unsigned& = 0, | 145 const DOMArrayBufferView* = nullptr, |
160 const DOMArrayBufferView* = nullptr, | 146 ExceptionState* = nullptr); |
161 const ImageDataColorSettings* = nullptr, | |
162 ExceptionState* = nullptr); | |
163 | 147 |
164 private: | 148 private: |
165 ImageData(const IntSize&, | 149 ImageData(const IntSize&, |
166 DOMArrayBufferView*, | 150 DOMArrayBufferView*, |
167 const ImageDataColorSettings* = nullptr); | 151 const ImageDataColorSettings* = nullptr, |
| 152 StorageFormatSource = kStorageFormatFromColorSettings); |
168 | 153 |
169 IntSize m_size; | 154 IntSize m_size; |
170 ImageDataColorSettings m_colorSettings; | 155 ImageDataColorSettings m_colorSettings; |
171 ImageDataArray m_dataUnion; | 156 ImageDataArray m_dataUnion; |
172 Member<DOMUint8ClampedArray> m_data; | 157 Member<DOMUint8ClampedArray> m_data; |
173 Member<DOMUint16Array> m_dataU16; | 158 Member<DOMUint16Array> m_dataU16; |
174 Member<DOMFloat32Array> m_dataF32; | 159 Member<DOMFloat32Array> m_dataF32; |
175 | 160 |
176 static DOMArrayBufferView* allocateAndValidateDataArray( | 161 static DOMArrayBufferView* allocateAndValidateDataArray( |
177 const unsigned&, | 162 const unsigned&, |
178 ImageDataStorageFormat, | 163 ImageDataStorageFormat, |
179 ExceptionState* = nullptr); | 164 ExceptionState* = nullptr); |
180 | |
181 static DOMUint8ClampedArray* allocateAndValidateUint8ClampedArray( | |
182 const unsigned&, | |
183 ExceptionState* = nullptr); | |
184 | |
185 static DOMUint16Array* allocateAndValidateUint16Array( | |
186 const unsigned&, | |
187 ExceptionState* = nullptr); | |
188 | |
189 static DOMFloat32Array* allocateAndValidateFloat32Array( | |
190 const unsigned&, | |
191 ExceptionState* = nullptr); | |
192 | |
193 static DOMFloat32Array* convertFloat16ArrayToFloat32Array(const uint16_t*, | |
194 unsigned); | |
195 | |
196 static sk_sp<SkColorSpace> getSkColorSpace(const CanvasColorSpace&, | |
197 const CanvasPixelFormat&); | |
198 }; | 165 }; |
199 | 166 |
200 } // namespace blink | 167 } // namespace blink |
201 | 168 |
202 #endif // ImageData_h | 169 #endif // ImageData_h |
OLD | NEW |