OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "config.h" | 5 #include "config.h" |
6 #include "platform/graphics/gpu/WebGLImageConversion.h" | 6 #include "platform/graphics/gpu/WebGLImageConversion.h" |
7 | 7 |
8 #include "platform/CheckedInt.h" | 8 #include "platform/CheckedInt.h" |
9 #include "platform/graphics/ImageObserver.h" | 9 #include "platform/graphics/ImageObserver.h" |
10 #include "platform/graphics/cpu/arm/WebGLImageConversionNEON.h" | 10 #include "platform/graphics/cpu/arm/WebGLImageConversionNEON.h" |
11 #include "platform/graphics/cpu/x86/WebGLImageConversionSSE.h" | 11 #include "platform/graphics/cpu/x86/WebGLImageConversionSSE.h" |
12 #include "platform/image-decoders/ImageDecoder.h" | 12 #include "platform/image-decoders/ImageDecoder.h" |
13 #include "wtf/OwnPtr.h" | 13 #include "wtf/OwnPtr.h" |
14 #include "wtf/PassOwnPtr.h" | 14 #include "wtf/PassOwnPtr.h" |
15 | 15 |
16 namespace blink { | 16 namespace blink { |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
| 20 const float maxInt8Value = INT8_MAX; |
| 21 const float maxUInt8Value = UINT8_MAX; |
| 22 const float maxInt16Value = INT16_MAX; |
| 23 const float maxUInt16Value = UINT16_MAX; |
| 24 const double maxInt32Value = INT32_MAX; |
| 25 const double maxUInt32Value = UINT32_MAX; |
| 26 |
| 27 int8_t ClampMin(int8_t value) |
| 28 { |
| 29 const static int8_t minInt8Value = INT8_MIN + 1; |
| 30 return value < minInt8Value ? minInt8Value : value; |
| 31 } |
| 32 |
| 33 int16_t ClampMin(int16_t value) |
| 34 { |
| 35 const static int16_t minInt16Value = INT16_MIN + 1; |
| 36 return value < minInt16Value ? minInt16Value : value; |
| 37 } |
| 38 |
| 39 int32_t ClampMin(int32_t value) |
| 40 { |
| 41 const static int32_t minInt32Value = INT32_MIN + 1; |
| 42 return value < minInt32Value ? minInt32Value : value; |
| 43 } |
| 44 |
20 WebGLImageConversion::DataFormat getDataFormat(GLenum destinationFormat, GLenum
destinationType) | 45 WebGLImageConversion::DataFormat getDataFormat(GLenum destinationFormat, GLenum
destinationType) |
21 { | 46 { |
22 WebGLImageConversion::DataFormat dstFormat = WebGLImageConversion::DataForma
tRGBA8; | 47 WebGLImageConversion::DataFormat dstFormat = WebGLImageConversion::DataForma
tRGBA8; |
23 switch (destinationType) { | 48 switch (destinationType) { |
24 case GL_BYTE: | 49 case GL_BYTE: |
25 switch (destinationFormat) { | 50 switch (destinationFormat) { |
26 case GL_RED: | 51 case GL_RED: |
27 case GL_RED_INTEGER: | 52 case GL_RED_INTEGER: |
28 dstFormat = WebGLImageConversion::DataFormatR8_S; | 53 dstFormat = WebGLImageConversion::DataFormatR8_S; |
29 break; | 54 break; |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 for (unsigned i = 0; i < pixelsPerRow; ++i) { | 559 for (unsigned i = 0; i < pixelsPerRow; ++i) { |
535 destination[0] = source[0]; | 560 destination[0] = source[0]; |
536 destination[1] = source[0]; | 561 destination[1] = source[0]; |
537 destination[2] = source[0]; | 562 destination[2] = source[0]; |
538 destination[3] = source[1]; | 563 destination[3] = source[1]; |
539 source += 2; | 564 source += 2; |
540 destination += 4; | 565 destination += 4; |
541 } | 566 } |
542 } | 567 } |
543 | 568 |
544 template<> void unpack<WebGLImageConversion::DataFormatRGBA2_10_10_10, uint32_t,
uint16_t>(const uint32_t* source, uint16_t* destination, unsigned pixelsPerRow) | 569 template<> void unpack<WebGLImageConversion::DataFormatRGBA2_10_10_10, uint32_t,
float>(const uint32_t* source, float* destination, unsigned pixelsPerRow) |
545 { | 570 { |
546 // FIXME: Implement this. | 571 static const float rgbScaleFactor = 1.0f / 1023.0f; |
547 ASSERT_NOT_REACHED(); | 572 static const float alphaScaleFactor = 1.0f / 3.0f; |
| 573 for (unsigned i = 0; i < pixelsPerRow; ++i) { |
| 574 uint32_t packedValue = source[0]; |
| 575 destination[0] = static_cast<float>(packedValue & 0x3FF) * rgbScaleFacto
r; |
| 576 destination[1] = static_cast<float>((packedValue >> 10) & 0x3FF) * rgbSc
aleFactor; |
| 577 destination[2] = static_cast<float>((packedValue >> 20) & 0x3FF) * rgbSc
aleFactor; |
| 578 destination[3] = static_cast<float>(packedValue >> 30) * alphaScaleFacto
r; |
| 579 source += 1; |
| 580 destination += 4; |
| 581 } |
548 } | 582 } |
549 | 583 |
550 //---------------------------------------------------------------------- | 584 //---------------------------------------------------------------------- |
551 // Pixel packing routines. | 585 // Pixel packing routines. |
552 // | 586 // |
553 | 587 |
554 template<int format, int alphaOp, typename SourceType, typename DstType> | 588 template<int format, int alphaOp, typename SourceType, typename DstType> |
555 void pack(const SourceType*, DstType*, unsigned) | 589 void pack(const SourceType*, DstType*, unsigned) |
556 { | 590 { |
557 ASSERT_NOT_REACHED(); | 591 ASSERT_NOT_REACHED(); |
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1125 { | 1159 { |
1126 for (unsigned i = 0; i < pixelsPerRow; ++i) { | 1160 for (unsigned i = 0; i < pixelsPerRow; ++i) { |
1127 destination[0] = convertFloatToHalfFloat(source[3]); | 1161 destination[0] = convertFloatToHalfFloat(source[3]); |
1128 source += 4; | 1162 source += 4; |
1129 destination += 1; | 1163 destination += 1; |
1130 } | 1164 } |
1131 } | 1165 } |
1132 | 1166 |
1133 template<> void pack<WebGLImageConversion::DataFormatRGBA8_S, WebGLImageConversi
on::AlphaDoPremultiply, int8_t, int8_t>(const int8_t* source, int8_t* destinatio
n, unsigned pixelsPerRow) | 1167 template<> void pack<WebGLImageConversion::DataFormatRGBA8_S, WebGLImageConversi
on::AlphaDoPremultiply, int8_t, int8_t>(const int8_t* source, int8_t* destinatio
n, unsigned pixelsPerRow) |
1134 { | 1168 { |
1135 // FIXME: Implement this. | 1169 for (unsigned i = 0; i < pixelsPerRow; ++i) { |
1136 ASSERT_NOT_REACHED(); | 1170 destination[3] = ClampMin(source[3]); |
1137 } | 1171 float scaleFactor = static_cast<float>(destination[3]) / maxInt8Value; |
1138 | 1172 destination[0] = static_cast<int8_t>(static_cast<float>(ClampMin(source[
0])) * scaleFactor); |
1139 // FIXME: this routine is lossy and must be removed. | 1173 destination[1] = static_cast<int8_t>(static_cast<float>(ClampMin(source[
1])) * scaleFactor); |
1140 template<> void pack<WebGLImageConversion::DataFormatRGBA8_S, WebGLImageConversi
on::AlphaDoUnmultiply, int8_t, int8_t>(const int8_t* source, int8_t* destination
, unsigned pixelsPerRow) | 1174 destination[2] = static_cast<int8_t>(static_cast<float>(ClampMin(source[
2])) * scaleFactor); |
1141 { | 1175 source += 4; |
1142 // FIXME: Implement this. | 1176 destination += 4; |
1143 ASSERT_NOT_REACHED(); | 1177 } |
1144 } | 1178 } |
1145 | 1179 |
1146 template<> void pack<WebGLImageConversion::DataFormatRGBA16, WebGLImageConversio
n::AlphaDoPremultiply, uint16_t, uint16_t>(const uint16_t* source, uint16_t* des
tination, unsigned pixelsPerRow) | 1180 template<> void pack<WebGLImageConversion::DataFormatRGBA16, WebGLImageConversio
n::AlphaDoPremultiply, uint16_t, uint16_t>(const uint16_t* source, uint16_t* des
tination, unsigned pixelsPerRow) |
1147 { | 1181 { |
1148 // FIXME: Implement this. | 1182 for (unsigned i = 0; i < pixelsPerRow; ++i) { |
1149 ASSERT_NOT_REACHED(); | 1183 float scaleFactor = static_cast<float>(source[3]) / maxUInt16Value; |
1150 } | 1184 destination[0] = static_cast<uint16_t>(static_cast<float>(source[0]) * s
caleFactor); |
1151 | 1185 destination[1] = static_cast<uint16_t>(static_cast<float>(source[1]) * s
caleFactor); |
1152 // FIXME: this routine is lossy and must be removed. | 1186 destination[2] = static_cast<uint16_t>(static_cast<float>(source[2]) * s
caleFactor); |
1153 template<> void pack<WebGLImageConversion::DataFormatRGBA16, WebGLImageConversio
n::AlphaDoUnmultiply, uint16_t, uint16_t>(const uint16_t* source, uint16_t* dest
ination, unsigned pixelsPerRow) | 1187 destination[3] = source[3]; |
1154 { | 1188 source += 4; |
1155 // FIXME: Implement this. | 1189 destination += 4; |
1156 ASSERT_NOT_REACHED(); | 1190 } |
1157 } | 1191 } |
1158 | 1192 |
1159 template<> void pack<WebGLImageConversion::DataFormatRGBA16_S, WebGLImageConvers
ion::AlphaDoPremultiply, int16_t, int16_t>(const int16_t* source, int16_t* desti
nation, unsigned pixelsPerRow) | 1193 template<> void pack<WebGLImageConversion::DataFormatRGBA16_S, WebGLImageConvers
ion::AlphaDoPremultiply, int16_t, int16_t>(const int16_t* source, int16_t* desti
nation, unsigned pixelsPerRow) |
1160 { | 1194 { |
1161 // FIXME: Implement this. | 1195 for (unsigned i = 0; i < pixelsPerRow; ++i) { |
1162 ASSERT_NOT_REACHED(); | 1196 destination[3] = ClampMin(source[3]); |
1163 } | 1197 float scaleFactor = static_cast<float>(destination[3]) / maxInt16Value; |
1164 | 1198 destination[0] = static_cast<int16_t>(static_cast<float>(ClampMin(source
[0])) * scaleFactor); |
1165 // FIXME: this routine is lossy and must be removed. | 1199 destination[1] = static_cast<int16_t>(static_cast<float>(ClampMin(source
[1])) * scaleFactor); |
1166 template<> void pack<WebGLImageConversion::DataFormatRGBA16_S, WebGLImageConvers
ion::AlphaDoUnmultiply, int16_t, int16_t>(const int16_t* source, int16_t* destin
ation, unsigned pixelsPerRow) | 1200 destination[2] = static_cast<int16_t>(static_cast<float>(ClampMin(source
[2])) * scaleFactor); |
1167 { | 1201 source += 4; |
1168 // FIXME: Implement this. | 1202 destination += 4; |
1169 ASSERT_NOT_REACHED(); | 1203 } |
1170 } | 1204 } |
1171 | 1205 |
1172 template<> void pack<WebGLImageConversion::DataFormatRGBA32, WebGLImageConversio
n::AlphaDoPremultiply, uint32_t, uint32_t>(const uint32_t* source, uint32_t* des
tination, unsigned pixelsPerRow) | 1206 template<> void pack<WebGLImageConversion::DataFormatRGBA32, WebGLImageConversio
n::AlphaDoPremultiply, uint32_t, uint32_t>(const uint32_t* source, uint32_t* des
tination, unsigned pixelsPerRow) |
1173 { | 1207 { |
1174 // FIXME: Implement this. | 1208 for (unsigned i = 0; i < pixelsPerRow; ++i) { |
1175 ASSERT_NOT_REACHED(); | 1209 double scaleFactor = static_cast<double>(source[3]) / maxUInt32Value; |
1176 } | 1210 destination[0] = static_cast<uint32_t>(static_cast<double>(source[0]) *
scaleFactor); |
1177 | 1211 destination[1] = static_cast<uint32_t>(static_cast<double>(source[1]) *
scaleFactor); |
1178 // FIXME: this routine is lossy and must be removed. | 1212 destination[2] = static_cast<uint32_t>(static_cast<double>(source[2]) *
scaleFactor); |
1179 template<> void pack<WebGLImageConversion::DataFormatRGBA32, WebGLImageConversio
n::AlphaDoUnmultiply, uint32_t, uint32_t>(const uint32_t* source, uint32_t* dest
ination, unsigned pixelsPerRow) | 1213 destination[3] = source[3]; |
1180 { | 1214 source += 4; |
1181 // FIXME: Implement this. | 1215 destination += 4; |
1182 ASSERT_NOT_REACHED(); | 1216 } |
1183 } | 1217 } |
1184 | 1218 |
1185 template<> void pack<WebGLImageConversion::DataFormatRGBA32_S, WebGLImageConvers
ion::AlphaDoPremultiply, int32_t, int32_t>(const int32_t* source, int32_t* desti
nation, unsigned pixelsPerRow) | 1219 template<> void pack<WebGLImageConversion::DataFormatRGBA32_S, WebGLImageConvers
ion::AlphaDoPremultiply, int32_t, int32_t>(const int32_t* source, int32_t* desti
nation, unsigned pixelsPerRow) |
1186 { | 1220 { |
1187 // FIXME: Implement this. | 1221 for (unsigned i = 0; i < pixelsPerRow; ++i) { |
1188 ASSERT_NOT_REACHED(); | 1222 destination[3] = ClampMin(source[3]); |
| 1223 double scaleFactor = static_cast<double>(destination[3]) / maxInt32Value
; |
| 1224 destination[0] = static_cast<int32_t>(static_cast<double>(ClampMin(sourc
e[0])) * scaleFactor); |
| 1225 destination[1] = static_cast<int32_t>(static_cast<double>(ClampMin(sourc
e[1])) * scaleFactor); |
| 1226 destination[2] = static_cast<int32_t>(static_cast<double>(ClampMin(sourc
e[2])) * scaleFactor); |
| 1227 source += 4; |
| 1228 destination += 4; |
| 1229 } |
1189 } | 1230 } |
1190 | 1231 |
1191 // FIXME: this routine is lossy and must be removed. | 1232 template<> void pack<WebGLImageConversion::DataFormatRGBA2_10_10_10, WebGLImageC
onversion::AlphaDoPremultiply, float, uint32_t>(const float* source, uint32_t* d
estination, unsigned pixelsPerRow) |
1192 template<> void pack<WebGLImageConversion::DataFormatRGBA32_S, WebGLImageConvers
ion::AlphaDoUnmultiply, int32_t, int32_t>(const int32_t* source, int32_t* destin
ation, unsigned pixelsPerRow) | |
1193 { | 1233 { |
1194 // FIXME: Implement this. | 1234 for (unsigned i = 0; i < pixelsPerRow; ++i) { |
1195 ASSERT_NOT_REACHED(); | 1235 uint32_t r = static_cast<uint32_t>(source[0] * source[3] * 1023.0f); |
1196 } | 1236 uint32_t g = static_cast<uint32_t>(source[1] * source[3] * 1023.0f); |
1197 | 1237 uint32_t b = static_cast<uint32_t>(source[2] * source[3] * 1023.0f); |
1198 template<> void pack<WebGLImageConversion::DataFormatRGBA2_10_10_10, WebGLImageC
onversion::AlphaDoPremultiply, uint16_t, uint32_t>(const uint16_t* source, uint3
2_t* destination, unsigned pixelsPerRow) | 1238 uint32_t a = static_cast<uint32_t>(source[3] * 3.0f); |
1199 { | 1239 destination[0] = (a << 30) | (b << 20) | (g << 10) | r; |
1200 // FIXME: Implement this. | 1240 source += 4; |
1201 ASSERT_NOT_REACHED(); | 1241 destination += 1; |
1202 } | 1242 } |
1203 | |
1204 // FIXME: this routine is lossy and must be removed. | |
1205 template<> void pack<WebGLImageConversion::DataFormatRGBA2_10_10_10, WebGLImageC
onversion::AlphaDoUnmultiply, uint16_t, uint32_t>(const uint16_t* source, uint32
_t* destination, unsigned pixelsPerRow) | |
1206 { | |
1207 // FIXME: Implement this. | |
1208 ASSERT_NOT_REACHED(); | |
1209 } | |
1210 | |
1211 template<> void pack<WebGLImageConversion::DataFormatRGB10F11F11F, WebGLImageCon
version::AlphaDoNothing, float, uint32_t>(const float* source, uint32_t* destina
tion, unsigned pixelsPerRow) | |
1212 { | |
1213 // FIXME: Implement this. | |
1214 ASSERT_NOT_REACHED(); | |
1215 } | |
1216 | |
1217 template<> void pack<WebGLImageConversion::DataFormatRGB10F11F11F, WebGLImageCon
version::AlphaDoPremultiply, float, uint32_t>(const float* source, uint32_t* des
tination, unsigned pixelsPerRow) | |
1218 { | |
1219 // FIXME: Implement this. | |
1220 ASSERT_NOT_REACHED(); | |
1221 } | |
1222 | |
1223 // FIXME: this routine is lossy and must be removed. | |
1224 template<> void pack<WebGLImageConversion::DataFormatRGB10F11F11F, WebGLImageCon
version::AlphaDoUnmultiply, float, uint32_t>(const float* source, uint32_t* dest
ination, unsigned pixelsPerRow) | |
1225 { | |
1226 // FIXME: Implement this. | |
1227 ASSERT_NOT_REACHED(); | |
1228 } | 1243 } |
1229 | 1244 |
1230 template<> void pack<WebGLImageConversion::DataFormatRG8, WebGLImageConversion::
AlphaDoNothing, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, u
nsigned pixelsPerRow) | 1245 template<> void pack<WebGLImageConversion::DataFormatRG8, WebGLImageConversion::
AlphaDoNothing, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, u
nsigned pixelsPerRow) |
1231 { | 1246 { |
1232 // FIXME: Implement this. | 1247 for (unsigned i = 0; i < pixelsPerRow; ++i) { |
1233 ASSERT_NOT_REACHED(); | 1248 destination[0] = source[0]; |
| 1249 destination[1] = source[1]; |
| 1250 source += 4; |
| 1251 destination += 2; |
| 1252 } |
1234 } | 1253 } |
1235 | 1254 |
1236 template<> void pack<WebGLImageConversion::DataFormatRG8, WebGLImageConversion::
AlphaDoPremultiply, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destinatio
n, unsigned pixelsPerRow) | 1255 template<> void pack<WebGLImageConversion::DataFormatRG8, WebGLImageConversion::
AlphaDoPremultiply, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destinatio
n, unsigned pixelsPerRow) |
1237 { | 1256 { |
1238 // FIXME: Implement this. | 1257 for (unsigned i = 0; i < pixelsPerRow; ++i) { |
1239 ASSERT_NOT_REACHED(); | 1258 float scaleFactor = static_cast<float>(source[3]) / maxUInt8Value; |
| 1259 destination[0] = static_cast<uint8_t>(static_cast<float>(source[0]) * sc
aleFactor); |
| 1260 destination[1] = static_cast<uint8_t>(static_cast<float>(source[1]) * sc
aleFactor); |
| 1261 source += 4; |
| 1262 destination += 2; |
| 1263 } |
1240 } | 1264 } |
1241 | 1265 |
1242 // FIXME: this routine is lossy and must be removed. | 1266 // FIXME: this routine is lossy and must be removed. |
1243 template<> void pack<WebGLImageConversion::DataFormatRG8, WebGLImageConversion::
AlphaDoUnmultiply, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination
, unsigned pixelsPerRow) | 1267 template<> void pack<WebGLImageConversion::DataFormatRG8, WebGLImageConversion::
AlphaDoUnmultiply, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination
, unsigned pixelsPerRow) |
1244 { | 1268 { |
1245 // FIXME: Implement this. | 1269 for (unsigned i = 0; i < pixelsPerRow; ++i) { |
1246 ASSERT_NOT_REACHED(); | 1270 float scaleFactor = source[3] ? maxUInt8Value / static_cast<float>(sourc
e[3]) : 1.0f; |
| 1271 destination[0] = static_cast<uint8_t>(static_cast<float>(source[0]) * sc
aleFactor); |
| 1272 destination[1] = static_cast<uint8_t>(static_cast<float>(source[1]) * sc
aleFactor); |
| 1273 source += 4; |
| 1274 destination += 2; |
| 1275 } |
1247 } | 1276 } |
1248 | 1277 |
1249 template<> void pack<WebGLImageConversion::DataFormatRG16F, WebGLImageConversion
::AlphaDoNothing, float, uint16_t>(const float* source, uint16_t* destination, u
nsigned pixelsPerRow) | 1278 template<> void pack<WebGLImageConversion::DataFormatRG16F, WebGLImageConversion
::AlphaDoNothing, float, uint16_t>(const float* source, uint16_t* destination, u
nsigned pixelsPerRow) |
1250 { | 1279 { |
1251 // FIXME: Implement this. | 1280 for (unsigned i = 0; i < pixelsPerRow; ++i) { |
1252 ASSERT_NOT_REACHED(); | 1281 destination[0] = convertFloatToHalfFloat(source[0]); |
| 1282 destination[1] = convertFloatToHalfFloat(source[1]); |
| 1283 source += 4; |
| 1284 destination += 2; |
| 1285 } |
| 1286 |
1253 } | 1287 } |
1254 | 1288 |
1255 template<> void pack<WebGLImageConversion::DataFormatRG16F, WebGLImageConversion
::AlphaDoPremultiply, float, uint16_t>(const float* source, uint16_t* destinatio
n, unsigned pixelsPerRow) | 1289 template<> void pack<WebGLImageConversion::DataFormatRG16F, WebGLImageConversion
::AlphaDoPremultiply, float, uint16_t>(const float* source, uint16_t* destinatio
n, unsigned pixelsPerRow) |
1256 { | 1290 { |
1257 // FIXME: Implement this. | 1291 for (unsigned i = 0; i < pixelsPerRow; ++i) { |
1258 ASSERT_NOT_REACHED(); | 1292 float scaleFactor = source[3]; |
| 1293 destination[0] = convertFloatToHalfFloat(source[0] * scaleFactor); |
| 1294 destination[1] = convertFloatToHalfFloat(source[1] * scaleFactor); |
| 1295 source += 4; |
| 1296 destination += 2; |
| 1297 } |
1259 } | 1298 } |
1260 | 1299 |
1261 // FIXME: this routine is lossy and must be removed. | 1300 // FIXME: this routine is lossy and must be removed. |
1262 template<> void pack<WebGLImageConversion::DataFormatRG16F, WebGLImageConversion
::AlphaDoUnmultiply, float, uint16_t>(const float* source, uint16_t* destination
, unsigned pixelsPerRow) | 1301 template<> void pack<WebGLImageConversion::DataFormatRG16F, WebGLImageConversion
::AlphaDoUnmultiply, float, uint16_t>(const float* source, uint16_t* destination
, unsigned pixelsPerRow) |
1263 { | 1302 { |
1264 // FIXME: Implement this. | 1303 for (unsigned i = 0; i < pixelsPerRow; ++i) { |
1265 ASSERT_NOT_REACHED(); | 1304 float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f; |
| 1305 destination[0] = convertFloatToHalfFloat(source[0] * scaleFactor); |
| 1306 destination[1] = convertFloatToHalfFloat(source[1] * scaleFactor); |
| 1307 source += 4; |
| 1308 destination += 2; |
| 1309 } |
1266 } | 1310 } |
1267 | 1311 |
1268 template<> void pack<WebGLImageConversion::DataFormatRG32F, WebGLImageConversion
::AlphaDoNothing, float, float>(const float* source, float* destination, unsigne
d pixelsPerRow) | 1312 template<> void pack<WebGLImageConversion::DataFormatRG32F, WebGLImageConversion
::AlphaDoNothing, float, float>(const float* source, float* destination, unsigne
d pixelsPerRow) |
1269 { | 1313 { |
1270 // FIXME: Implement this. | 1314 for (unsigned i = 0; i < pixelsPerRow; ++i) { |
1271 ASSERT_NOT_REACHED(); | 1315 destination[0] = source[0]; |
| 1316 destination[1] = source[1]; |
| 1317 source += 4; |
| 1318 destination += 2; |
| 1319 } |
1272 } | 1320 } |
1273 | 1321 |
1274 template<> void pack<WebGLImageConversion::DataFormatRG32F, WebGLImageConversion
::AlphaDoPremultiply, float, float>(const float* source, float* destination, uns
igned pixelsPerRow) | 1322 template<> void pack<WebGLImageConversion::DataFormatRG32F, WebGLImageConversion
::AlphaDoPremultiply, float, float>(const float* source, float* destination, uns
igned pixelsPerRow) |
1275 { | 1323 { |
1276 // FIXME: Implement this. | 1324 for (unsigned i = 0; i < pixelsPerRow; ++i) { |
1277 ASSERT_NOT_REACHED(); | 1325 float scaleFactor = source[3]; |
| 1326 destination[0] = source[0] * scaleFactor; |
| 1327 destination[1] = source[1] * scaleFactor; |
| 1328 source += 4; |
| 1329 destination += 2; |
| 1330 } |
1278 } | 1331 } |
1279 | 1332 |
1280 // FIXME: this routine is lossy and must be removed. | 1333 // FIXME: this routine is lossy and must be removed. |
1281 template<> void pack<WebGLImageConversion::DataFormatRG32F, WebGLImageConversion
::AlphaDoUnmultiply, float, float>(const float* source, float* destination, unsi
gned pixelsPerRow) | 1334 template<> void pack<WebGLImageConversion::DataFormatRG32F, WebGLImageConversion
::AlphaDoUnmultiply, float, float>(const float* source, float* destination, unsi
gned pixelsPerRow) |
1282 { | 1335 { |
1283 // FIXME: Implement this. | 1336 for (unsigned i = 0; i < pixelsPerRow; ++i) { |
1284 ASSERT_NOT_REACHED(); | 1337 float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f; |
| 1338 destination[0] = source[0] * scaleFactor; |
| 1339 destination[1] = source[1] * scaleFactor; |
| 1340 source += 4; |
| 1341 destination += 2; |
| 1342 } |
1285 } | 1343 } |
1286 | 1344 |
1287 bool HasAlpha(int format) | 1345 bool HasAlpha(int format) |
1288 { | 1346 { |
1289 return format == WebGLImageConversion::DataFormatA8 | 1347 return format == WebGLImageConversion::DataFormatA8 |
1290 || format == WebGLImageConversion::DataFormatA16F | 1348 || format == WebGLImageConversion::DataFormatA16F |
1291 || format == WebGLImageConversion::DataFormatA32F | 1349 || format == WebGLImageConversion::DataFormatA32F |
1292 || format == WebGLImageConversion::DataFormatRA8 | 1350 || format == WebGLImageConversion::DataFormatRA8 |
1293 || format == WebGLImageConversion::DataFormatAR8 | 1351 || format == WebGLImageConversion::DataFormatAR8 |
1294 || format == WebGLImageConversion::DataFormatRA16F | 1352 || format == WebGLImageConversion::DataFormatRA16F |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1521 template<int Format> | 1579 template<int Format> |
1522 struct DataTypeForFormat<Format, false, false, false, false, false, false, false
, false, false, true> { | 1580 struct DataTypeForFormat<Format, false, false, false, false, false, false, false
, false, false, true> { |
1523 typedef uint32_t Type; | 1581 typedef uint32_t Type; |
1524 }; | 1582 }; |
1525 | 1583 |
1526 template<int Format> | 1584 template<int Format> |
1527 struct UsesFloatIntermediateFormat { | 1585 struct UsesFloatIntermediateFormat { |
1528 static const bool Value = | 1586 static const bool Value = |
1529 IsFloatFormat<Format>::Value | 1587 IsFloatFormat<Format>::Value |
1530 || IsHalfFloatFormat<Format>::Value | 1588 || IsHalfFloatFormat<Format>::Value |
| 1589 || Format == WebGLImageConversion::DataFormatRGBA2_10_10_10 |
1531 || Format == WebGLImageConversion::DataFormatRGB10F11F11F | 1590 || Format == WebGLImageConversion::DataFormatRGB10F11F11F |
1532 || Format == WebGLImageConversion::DataFormatRGB5999; | 1591 || Format == WebGLImageConversion::DataFormatRGB5999; |
1533 }; | 1592 }; |
1534 | 1593 |
1535 template<int Format> | 1594 template<int Format> |
1536 struct IntermediateFormat { | 1595 struct IntermediateFormat { |
1537 static const int Value = | 1596 static const int Value = |
1538 UsesFloatIntermediateFormat<Format>::Value ? WebGLImageConversion::DataF
ormatRGBA32F | 1597 UsesFloatIntermediateFormat<Format>::Value ? WebGLImageConversion::DataF
ormatRGBA32F |
1539 : IsInt32Format<Format>::Value ? WebGLImageConversion::DataFormatRGBA32_
S | 1598 : IsInt32Format<Format>::Value ? WebGLImageConversion::DataFormatRGBA32_
S |
1540 : IsUInt32Format<Format>::Value ? WebGLImageConversion::DataFormatRGBA32 | 1599 : IsUInt32Format<Format>::Value ? WebGLImageConversion::DataFormatRGBA32 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1572 case WebGLImageConversion::DataFormatARGB8: | 1631 case WebGLImageConversion::DataFormatARGB8: |
1573 case WebGLImageConversion::DataFormatABGR8: | 1632 case WebGLImageConversion::DataFormatABGR8: |
1574 case WebGLImageConversion::DataFormatBGRA8: | 1633 case WebGLImageConversion::DataFormatBGRA8: |
1575 case WebGLImageConversion::DataFormatR32: | 1634 case WebGLImageConversion::DataFormatR32: |
1576 case WebGLImageConversion::DataFormatR32_S: | 1635 case WebGLImageConversion::DataFormatR32_S: |
1577 case WebGLImageConversion::DataFormatR32F: | 1636 case WebGLImageConversion::DataFormatR32F: |
1578 case WebGLImageConversion::DataFormatA32F: | 1637 case WebGLImageConversion::DataFormatA32F: |
1579 case WebGLImageConversion::DataFormatRA16F: | 1638 case WebGLImageConversion::DataFormatRA16F: |
1580 case WebGLImageConversion::DataFormatRGBA2_10_10_10: | 1639 case WebGLImageConversion::DataFormatRGBA2_10_10_10: |
1581 case WebGLImageConversion::DataFormatRGB10F11F11F: | 1640 case WebGLImageConversion::DataFormatRGB10F11F11F: |
| 1641 case WebGLImageConversion::DataFormatRGB5999: |
1582 case WebGLImageConversion::DataFormatRG16: | 1642 case WebGLImageConversion::DataFormatRG16: |
1583 case WebGLImageConversion::DataFormatRG16_S: | 1643 case WebGLImageConversion::DataFormatRG16_S: |
1584 case WebGLImageConversion::DataFormatRG16F: | 1644 case WebGLImageConversion::DataFormatRG16F: |
1585 case WebGLImageConversion::DataFormatD32: | 1645 case WebGLImageConversion::DataFormatD32: |
1586 case WebGLImageConversion::DataFormatD32F: | 1646 case WebGLImageConversion::DataFormatD32F: |
1587 case WebGLImageConversion::DataFormatDS24_8: | 1647 case WebGLImageConversion::DataFormatDS24_8: |
1588 return 4; | 1648 return 4; |
1589 case WebGLImageConversion::DataFormatRGB16: | 1649 case WebGLImageConversion::DataFormatRGB16: |
1590 case WebGLImageConversion::DataFormatRGB16_S: | 1650 case WebGLImageConversion::DataFormatRGB16_S: |
1591 case WebGLImageConversion::DataFormatRGB16F: | 1651 case WebGLImageConversion::DataFormatRGB16F: |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1695 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGBA5
551) | 1755 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGBA5
551) |
1696 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGBA4
444) | 1756 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGBA4
444) |
1697 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGBA1
6F) | 1757 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGBA1
6F) |
1698 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGBA3
2F) | 1758 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGBA3
2F) |
1699 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGBA8
_S) | 1759 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGBA8
_S) |
1700 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGBA1
6) | 1760 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGBA1
6) |
1701 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGBA1
6_S) | 1761 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGBA1
6_S) |
1702 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGBA3
2) | 1762 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGBA3
2) |
1703 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGBA3
2_S) | 1763 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGBA3
2_S) |
1704 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGBA2
_10_10_10) | 1764 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGBA2
_10_10_10) |
1705 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGB10
F11F11F) | |
1706 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRG8) | 1765 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRG8) |
1707 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRG16F
) | 1766 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRG16F
) |
1708 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRG32F
) | 1767 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRG32F
) |
1709 default: | 1768 default: |
1710 ASSERT_NOT_REACHED(); | 1769 ASSERT_NOT_REACHED(); |
1711 } | 1770 } |
1712 | 1771 |
1713 #undef FORMATCONVERTER_CASE_DSTFORMAT | 1772 #undef FORMATCONVERTER_CASE_DSTFORMAT |
1714 } | 1773 } |
1715 | 1774 |
1716 template<WebGLImageConversion::DataFormat SrcFormat, WebGLImageConversion::DataF
ormat DstFormat> | 1775 template<WebGLImageConversion::DataFormat SrcFormat, WebGLImageConversion::DataF
ormat DstFormat> |
1717 void FormatConverter::convert(WebGLImageConversion::AlphaOp alphaOp) | 1776 void FormatConverter::convert(WebGLImageConversion::AlphaOp alphaOp) |
1718 { | 1777 { |
1719 #define FORMATCONVERTER_CASE_ALPHAOP(alphaOp) \ | 1778 #define FORMATCONVERTER_CASE_ALPHAOP(alphaOp) \ |
1720 case alphaOp: \ | 1779 case alphaOp: \ |
1721 return convert<SrcFormat, DstFormat, alphaOp>(); | 1780 return convert<SrcFormat, DstFormat, alphaOp>(); |
1722 | 1781 |
1723 switch (alphaOp) { | 1782 switch (alphaOp) { |
1724 FORMATCONVERTER_CASE_ALPHAOP(WebGLImageConversion::AlphaDoNothing) | 1783 FORMATCONVERTER_CASE_ALPHAOP(WebGLImageConversion::AlphaDoNothing) |
1725 FORMATCONVERTER_CASE_ALPHAOP(WebGLImageConversion::AlphaDoPremultipl
y) | 1784 FORMATCONVERTER_CASE_ALPHAOP(WebGLImageConversion::AlphaDoPremultipl
y) |
1726 FORMATCONVERTER_CASE_ALPHAOP(WebGLImageConversion::AlphaDoUnmultiply
) | 1785 FORMATCONVERTER_CASE_ALPHAOP(WebGLImageConversion::AlphaDoUnmultiply
) |
1727 default: | 1786 default: |
1728 ASSERT_NOT_REACHED(); | 1787 ASSERT_NOT_REACHED(); |
1729 } | 1788 } |
1730 #undef FORMATCONVERTER_CASE_ALPHAOP | 1789 #undef FORMATCONVERTER_CASE_ALPHAOP |
1731 } | 1790 } |
1732 | 1791 |
| 1792 template<int Format> |
| 1793 struct SupportsConversionFromDomElements { |
| 1794 static const bool Value = |
| 1795 Format == WebGLImageConversion::DataFormatRGBA8 |
| 1796 || Format == WebGLImageConversion::DataFormatRGB8 |
| 1797 || Format == WebGLImageConversion::DataFormatRG8 |
| 1798 || Format == WebGLImageConversion::DataFormatRA8 |
| 1799 || Format == WebGLImageConversion::DataFormatR8 |
| 1800 || Format == WebGLImageConversion::DataFormatRGBA32F |
| 1801 || Format == WebGLImageConversion::DataFormatRGB32F |
| 1802 || Format == WebGLImageConversion::DataFormatRG32F |
| 1803 || Format == WebGLImageConversion::DataFormatRA32F |
| 1804 || Format == WebGLImageConversion::DataFormatR32F |
| 1805 || Format == WebGLImageConversion::DataFormatRGBA16F |
| 1806 || Format == WebGLImageConversion::DataFormatRGB16F |
| 1807 || Format == WebGLImageConversion::DataFormatRG16F |
| 1808 || Format == WebGLImageConversion::DataFormatRA16F |
| 1809 || Format == WebGLImageConversion::DataFormatR16F |
| 1810 || Format == WebGLImageConversion::DataFormatRGBA5551 |
| 1811 || Format == WebGLImageConversion::DataFormatRGBA4444 |
| 1812 || Format == WebGLImageConversion::DataFormatRGB565; |
| 1813 }; |
| 1814 |
1733 template<WebGLImageConversion::DataFormat SrcFormat, WebGLImageConversion::DataF
ormat DstFormat, WebGLImageConversion::AlphaOp alphaOp> | 1815 template<WebGLImageConversion::DataFormat SrcFormat, WebGLImageConversion::DataF
ormat DstFormat, WebGLImageConversion::AlphaOp alphaOp> |
1734 void FormatConverter::convert() | 1816 void FormatConverter::convert() |
1735 { | 1817 { |
1736 // Many instantiations of this template function will never be entered, so w
e try | 1818 // Many instantiations of this template function will never be entered, so w
e try |
1737 // to return immediately in these cases to avoid the compiler to generate us
eless code. | 1819 // to return immediately in these cases to avoid the compiler to generate us
eless code. |
1738 if (SrcFormat == DstFormat && alphaOp == WebGLImageConversion::AlphaDoNothin
g) { | 1820 if (SrcFormat == DstFormat && alphaOp == WebGLImageConversion::AlphaDoNothin
g) { |
1739 ASSERT_NOT_REACHED(); | 1821 ASSERT_NOT_REACHED(); |
1740 return; | 1822 return; |
1741 } | 1823 } |
1742 if (!IsFloatFormat<DstFormat>::Value && IsFloatFormat<SrcFormat>::Value) { | 1824 if (!IsFloatFormat<DstFormat>::Value && IsFloatFormat<SrcFormat>::Value) { |
1743 ASSERT_NOT_REACHED(); | 1825 ASSERT_NOT_REACHED(); |
1744 return; | 1826 return; |
1745 } | 1827 } |
1746 | 1828 |
1747 // Only textures uploaded from DOM elements or ImageData can allow DstFormat
!= SrcFormat. | 1829 // Only textures uploaded from DOM elements or ImageData can allow DstFormat
!= SrcFormat. |
1748 const bool srcFormatComesFromDOMElementOrImageData = WebGLImageConversion::s
rcFormatComeFromDOMElementOrImageData(SrcFormat); | 1830 const bool srcFormatComesFromDOMElementOrImageData = WebGLImageConversion::s
rcFormatComeFromDOMElementOrImageData(SrcFormat); |
1749 if (!srcFormatComesFromDOMElementOrImageData && SrcFormat != DstFormat) { | 1831 if (!srcFormatComesFromDOMElementOrImageData && SrcFormat != DstFormat) { |
1750 ASSERT_NOT_REACHED(); | 1832 ASSERT_NOT_REACHED(); |
1751 return; | 1833 return; |
1752 } | 1834 } |
1753 // Likewise, only textures uploaded from DOM elements or ImageData can possi
bly have to be unpremultiplied. | 1835 // Likewise, only textures uploaded from DOM elements or ImageData can possi
bly have to be unpremultiplied. |
1754 if (!srcFormatComesFromDOMElementOrImageData && alphaOp == WebGLImageConvers
ion::AlphaDoUnmultiply) { | 1836 if (!srcFormatComesFromDOMElementOrImageData && alphaOp == WebGLImageConvers
ion::AlphaDoUnmultiply) { |
1755 ASSERT_NOT_REACHED(); | 1837 ASSERT_NOT_REACHED(); |
1756 return; | 1838 return; |
1757 } | 1839 } |
| 1840 if (srcFormatComesFromDOMElementOrImageData && alphaOp == WebGLImageConversi
on::AlphaDoUnmultiply && !SupportsConversionFromDomElements<DstFormat>::Value) { |
| 1841 ASSERT_NOT_REACHED(); |
| 1842 return; |
| 1843 } |
1758 if ((!HasAlpha(SrcFormat) || !HasColor(SrcFormat) || !HasColor(DstFormat)) &
& alphaOp != WebGLImageConversion::AlphaDoNothing) { | 1844 if ((!HasAlpha(SrcFormat) || !HasColor(SrcFormat) || !HasColor(DstFormat)) &
& alphaOp != WebGLImageConversion::AlphaDoNothing) { |
1759 ASSERT_NOT_REACHED(); | 1845 ASSERT_NOT_REACHED(); |
1760 return; | 1846 return; |
1761 } | 1847 } |
| 1848 // If converting DOM element data to UNSIGNED_INT_5_9_9_9_REV or UNSIGNED_IN
T_10F_11F_11F_REV, |
| 1849 // we should always switch to FLOAT instead to avoid unpack/pack to these tw
o types. |
| 1850 if (srcFormatComesFromDOMElementOrImageData && SrcFormat != DstFormat |
| 1851 && (DstFormat == WebGLImageConversion::DataFormatRGB5999 || DstFormat ==
WebGLImageConversion::DataFormatRGB10F11F11F)) { |
| 1852 ASSERT_NOT_REACHED(); |
| 1853 return; |
| 1854 } |
1762 | 1855 |
1763 typedef typename DataTypeForFormat<SrcFormat>::Type SrcType; | 1856 typedef typename DataTypeForFormat<SrcFormat>::Type SrcType; |
1764 typedef typename DataTypeForFormat<DstFormat>::Type DstType; | 1857 typedef typename DataTypeForFormat<DstFormat>::Type DstType; |
1765 const int IntermFormat = IntermediateFormat<DstFormat>::Value; | 1858 const int IntermFormat = IntermediateFormat<DstFormat>::Value; |
1766 typedef typename DataTypeForFormat<IntermFormat>::Type IntermType; | 1859 typedef typename DataTypeForFormat<IntermFormat>::Type IntermType; |
1767 const ptrdiff_t srcStrideInElements = m_srcStride / sizeof(SrcType); | 1860 const ptrdiff_t srcStrideInElements = m_srcStride / sizeof(SrcType); |
1768 const ptrdiff_t dstStrideInElements = m_dstStride / sizeof(DstType); | 1861 const ptrdiff_t dstStrideInElements = m_dstStride / sizeof(DstType); |
1769 const bool trivialUnpack = SrcFormat == IntermFormat; | 1862 const bool trivialUnpack = SrcFormat == IntermFormat; |
1770 const bool trivialPack = DstFormat == IntermFormat && alphaOp == WebGLImageC
onversion::AlphaDoNothing; | 1863 const bool trivialPack = DstFormat == IntermFormat && alphaOp == WebGLImageC
onversion::AlphaDoNothing; |
1771 ASSERT(!trivialUnpack || !trivialPack); | 1864 ASSERT(!trivialUnpack || !trivialPack); |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2189 } | 2282 } |
2190 | 2283 |
2191 FormatConverter converter(width, height, sourceData, destinationData, srcStr
ide, dstStride); | 2284 FormatConverter converter(width, height, sourceData, destinationData, srcStr
ide, dstStride); |
2192 converter.convert(sourceDataFormat, dstDataFormat, alphaOp); | 2285 converter.convert(sourceDataFormat, dstDataFormat, alphaOp); |
2193 if (!converter.Success()) | 2286 if (!converter.Success()) |
2194 return false; | 2287 return false; |
2195 return true; | 2288 return true; |
2196 } | 2289 } |
2197 | 2290 |
2198 } // namespace blink | 2291 } // namespace blink |
OLD | NEW |