OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2010 Apple Inc. All rights reserved. |
3 * Copyright (C) 2010 Google Inc. All rights reserved. | 3 * Copyright (C) 2010 Google Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 GC3Denum format, | 193 GC3Denum format, |
194 GC3Denum type, | 194 GC3Denum type, |
195 bool flipY, | 195 bool flipY, |
196 bool premultiplyAlpha, | 196 bool premultiplyAlpha, |
197 Vector<uint8_t>& data) | 197 Vector<uint8_t>& data) |
198 { | 198 { |
199 if (!imageData) | 199 if (!imageData) |
200 return false; | 200 return false; |
201 int width = imageData->width(); | 201 int width = imageData->width(); |
202 int height = imageData->height(); | 202 int height = imageData->height(); |
203 int dataBytes = width * height * 4; | 203 |
204 data.resize(dataBytes); | 204 unsigned int packedSize; |
| 205 // Output data is tightly packed (alignment == 1). |
| 206 if (computeImageSizeInBytes(format, type, width, height, 1, &packedSize, 0)
!= GraphicsContext3D::NO_ERROR) |
| 207 return false; |
| 208 data.resize(packedSize); |
| 209 |
205 if (!packPixels(imageData->data()->data(), | 210 if (!packPixels(imageData->data()->data(), |
206 SourceFormatRGBA8, | 211 SourceFormatRGBA8, |
207 width, | 212 width, |
208 height, | 213 height, |
209 0, | 214 0, |
210 format, | 215 format, |
211 type, | 216 type, |
212 premultiplyAlpha ? AlphaDoPremultiply : AlphaDoNothing, | 217 premultiplyAlpha ? AlphaDoPremultiply : AlphaDoNothing, |
213 data.data())) | 218 data.data())) |
214 return false; | 219 return false; |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 for (unsigned int i = 0; i < pixelsPerRow; ++i) { | 702 for (unsigned int i = 0; i < pixelsPerRow; ++i) { |
698 destination[0] = 0x0; | 703 destination[0] = 0x0; |
699 destination[1] = 0x0; | 704 destination[1] = 0x0; |
700 destination[2] = 0x0; | 705 destination[2] = 0x0; |
701 destination[3] = convertColor16BigTo8(source[0]); | 706 destination[3] = convertColor16BigTo8(source[0]); |
702 source += 1; | 707 source += 1; |
703 destination += 4; | 708 destination += 4; |
704 } | 709 } |
705 } | 710 } |
706 | 711 |
| 712 void unpackOneRowOfRGBA8ToRGBA32F(const uint8_t* source, float* destination, uns
igned int pixelsPerRow) |
| 713 { |
| 714 const float scaleFactor = 1.0f / 255.0f; |
| 715 for (unsigned int i = 0; i < pixelsPerRow; ++i) { |
| 716 destination[0] = source[0] * scaleFactor; |
| 717 destination[1] = source[1] * scaleFactor; |
| 718 destination[2] = source[2] * scaleFactor; |
| 719 destination[3] = source[3] * scaleFactor; |
| 720 source += 4; |
| 721 destination += 4; |
| 722 } |
| 723 } |
| 724 |
| 725 void unpackOneRowOfBGRA8ToRGBA32F(const uint8_t* source, float* destination, uns
igned int pixelsPerRow) |
| 726 { |
| 727 const float scaleFactor = 1.0f / 255.0f; |
| 728 for (unsigned int i = 0; i < pixelsPerRow; ++i) { |
| 729 destination[0] = source[2] * scaleFactor; |
| 730 destination[1] = source[1] * scaleFactor; |
| 731 destination[2] = source[0] * scaleFactor; |
| 732 destination[3] = source[3] * scaleFactor; |
| 733 source += 4; |
| 734 destination += 4; |
| 735 } |
| 736 } |
| 737 |
707 void unpackOneRowOfRGB32FToRGBA32F(const float* source, float* destination, unsi
gned int pixelsPerRow) | 738 void unpackOneRowOfRGB32FToRGBA32F(const float* source, float* destination, unsi
gned int pixelsPerRow) |
708 { | 739 { |
709 for (unsigned int i = 0; i < pixelsPerRow; ++i) { | 740 for (unsigned int i = 0; i < pixelsPerRow; ++i) { |
710 destination[0] = source[0]; | 741 destination[0] = source[0]; |
711 destination[1] = source[1]; | 742 destination[1] = source[1]; |
712 destination[2] = source[2]; | 743 destination[2] = source[2]; |
713 destination[3] = 1; | 744 destination[3] = 1; |
714 source += 3; | 745 source += 3; |
715 destination += 4; | 746 destination += 4; |
716 } | 747 } |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1055 for (unsigned int i = 0; i < pixelsPerRow; ++i) { | 1086 for (unsigned int i = 0; i < pixelsPerRow; ++i) { |
1056 float scaleFactor = source[3]; | 1087 float scaleFactor = source[3]; |
1057 destination[0] = source[0] * scaleFactor; | 1088 destination[0] = source[0] * scaleFactor; |
1058 destination[1] = source[1] * scaleFactor; | 1089 destination[1] = source[1] * scaleFactor; |
1059 destination[2] = source[2] * scaleFactor; | 1090 destination[2] = source[2] * scaleFactor; |
1060 source += 4; | 1091 source += 4; |
1061 destination += 3; | 1092 destination += 3; |
1062 } | 1093 } |
1063 } | 1094 } |
1064 | 1095 |
| 1096 void packOneRowOfRGBA32FToRGB32FUnmultiply(const float* source, float* destinati
on, unsigned int pixelsPerRow) |
| 1097 { |
| 1098 for (unsigned int i = 0; i < pixelsPerRow; ++i) { |
| 1099 float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f; |
| 1100 destination[0] = source[0] * scaleFactor; |
| 1101 destination[1] = source[1] * scaleFactor; |
| 1102 destination[2] = source[2] * scaleFactor; |
| 1103 source += 4; |
| 1104 destination += 3; |
| 1105 } |
| 1106 } |
| 1107 |
| 1108 // Used only during RGBA8 or BGRA8 -> floating-point uploads. |
| 1109 void packOneRowOfRGBA32FToRGBA32F(const float* source, float* destination, unsig
ned int pixelsPerRow) |
| 1110 { |
| 1111 for (unsigned int i = 0; i < pixelsPerRow; ++i) { |
| 1112 destination[0] = source[0]; |
| 1113 destination[1] = source[1]; |
| 1114 destination[2] = source[2]; |
| 1115 destination[3] = source[3]; |
| 1116 source += 4; |
| 1117 destination += 4; |
| 1118 } |
| 1119 } |
| 1120 |
1065 void packOneRowOfRGBA32FToRGBA32FPremultiply(const float* source, float* destina
tion, unsigned int pixelsPerRow) | 1121 void packOneRowOfRGBA32FToRGBA32FPremultiply(const float* source, float* destina
tion, unsigned int pixelsPerRow) |
1066 { | 1122 { |
1067 for (unsigned int i = 0; i < pixelsPerRow; ++i) { | 1123 for (unsigned int i = 0; i < pixelsPerRow; ++i) { |
1068 float scaleFactor = source[3]; | 1124 float scaleFactor = source[3]; |
1069 destination[0] = source[0] * scaleFactor; | 1125 destination[0] = source[0] * scaleFactor; |
1070 destination[1] = source[1] * scaleFactor; | 1126 destination[1] = source[1] * scaleFactor; |
1071 destination[2] = source[2] * scaleFactor; | 1127 destination[2] = source[2] * scaleFactor; |
1072 destination[3] = source[3]; | 1128 destination[3] = source[3]; |
1073 source += 4; | 1129 source += 4; |
1074 destination += 4; | 1130 destination += 4; |
1075 } | 1131 } |
1076 } | 1132 } |
1077 | 1133 |
| 1134 void packOneRowOfRGBA32FToRGBA32FUnmultiply(const float* source, float* destinat
ion, unsigned int pixelsPerRow) |
| 1135 { |
| 1136 for (unsigned int i = 0; i < pixelsPerRow; ++i) { |
| 1137 float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f; |
| 1138 destination[0] = source[0] * scaleFactor; |
| 1139 destination[1] = source[1] * scaleFactor; |
| 1140 destination[2] = source[2] * scaleFactor; |
| 1141 destination[3] = source[3]; |
| 1142 source += 4; |
| 1143 destination += 4; |
| 1144 } |
| 1145 } |
| 1146 |
1078 void packOneRowOfRGBA32FToA32F(const float* source, float* destination, unsigned
int pixelsPerRow) | 1147 void packOneRowOfRGBA32FToA32F(const float* source, float* destination, unsigned
int pixelsPerRow) |
1079 { | 1148 { |
1080 for (unsigned int i = 0; i < pixelsPerRow; ++i) { | 1149 for (unsigned int i = 0; i < pixelsPerRow; ++i) { |
1081 destination[0] = source[3]; | 1150 destination[0] = source[3]; |
1082 source += 4; | 1151 source += 4; |
1083 destination += 1; | 1152 destination += 1; |
1084 } | 1153 } |
1085 } | 1154 } |
1086 | 1155 |
1087 void packOneRowOfRGBA32FToR32F(const float* source, float* destination, unsigned
int pixelsPerRow) | 1156 void packOneRowOfRGBA32FToR32F(const float* source, float* destination, unsigned
int pixelsPerRow) |
1088 { | 1157 { |
1089 for (unsigned int i = 0; i < pixelsPerRow; ++i) { | 1158 for (unsigned int i = 0; i < pixelsPerRow; ++i) { |
1090 destination[0] = source[0]; | 1159 destination[0] = source[0]; |
1091 source += 4; | 1160 source += 4; |
1092 destination += 1; | 1161 destination += 1; |
1093 } | 1162 } |
1094 } | 1163 } |
1095 | 1164 |
1096 void packOneRowOfRGBA32FToR32FPremultiply(const float* source, float* destinatio
n, unsigned int pixelsPerRow) | 1165 void packOneRowOfRGBA32FToR32FPremultiply(const float* source, float* destinatio
n, unsigned int pixelsPerRow) |
1097 { | 1166 { |
1098 for (unsigned int i = 0; i < pixelsPerRow; ++i) { | 1167 for (unsigned int i = 0; i < pixelsPerRow; ++i) { |
1099 float scaleFactor = source[3]; | 1168 float scaleFactor = source[3]; |
1100 destination[0] = source[0] * scaleFactor; | 1169 destination[0] = source[0] * scaleFactor; |
1101 source += 4; | 1170 source += 4; |
1102 destination += 1; | 1171 destination += 1; |
1103 } | 1172 } |
1104 } | 1173 } |
1105 | 1174 |
| 1175 void packOneRowOfRGBA32FToR32FUnmultiply(const float* source, float* destination
, unsigned int pixelsPerRow) |
| 1176 { |
| 1177 for (unsigned int i = 0; i < pixelsPerRow; ++i) { |
| 1178 float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f; |
| 1179 destination[0] = source[0] * scaleFactor; |
| 1180 source += 4; |
| 1181 destination += 1; |
| 1182 } |
| 1183 } |
1106 | 1184 |
1107 void packOneRowOfRGBA32FToRA32F(const float* source, float* destination, unsigne
d int pixelsPerRow) | 1185 void packOneRowOfRGBA32FToRA32F(const float* source, float* destination, unsigne
d int pixelsPerRow) |
1108 { | 1186 { |
1109 for (unsigned int i = 0; i < pixelsPerRow; ++i) { | 1187 for (unsigned int i = 0; i < pixelsPerRow; ++i) { |
1110 destination[0] = source[0]; | 1188 destination[0] = source[0]; |
1111 destination[1] = source[3]; | 1189 destination[1] = source[3]; |
1112 source += 4; | 1190 source += 4; |
1113 destination += 2; | 1191 destination += 2; |
1114 } | 1192 } |
1115 } | 1193 } |
1116 | 1194 |
1117 void packOneRowOfRGBA32FToRA32FPremultiply(const float* source, float* destinati
on, unsigned int pixelsPerRow) | 1195 void packOneRowOfRGBA32FToRA32FPremultiply(const float* source, float* destinati
on, unsigned int pixelsPerRow) |
1118 { | 1196 { |
1119 for (unsigned int i = 0; i < pixelsPerRow; ++i) { | 1197 for (unsigned int i = 0; i < pixelsPerRow; ++i) { |
1120 float scaleFactor = source[3]; | 1198 float scaleFactor = source[3]; |
1121 destination[0] = source[0] * scaleFactor; | 1199 destination[0] = source[0] * scaleFactor; |
1122 destination[1] = scaleFactor; | 1200 destination[1] = source[3]; |
| 1201 source += 4; |
| 1202 destination += 2; |
| 1203 } |
| 1204 } |
| 1205 |
| 1206 void packOneRowOfRGBA32FToRA32FUnmultiply(const float* source, float* destinatio
n, unsigned int pixelsPerRow) |
| 1207 { |
| 1208 for (unsigned int i = 0; i < pixelsPerRow; ++i) { |
| 1209 float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f; |
| 1210 destination[0] = source[0] * scaleFactor; |
| 1211 destination[1] = source[3]; |
1123 source += 4; | 1212 source += 4; |
1124 destination += 2; | 1213 destination += 2; |
1125 } | 1214 } |
1126 } | 1215 } |
1127 | 1216 |
1128 } // anonymous namespace | 1217 } // anonymous namespace |
1129 | 1218 |
1130 // This is used whenever unpacking is necessary; i.e., the source data | 1219 // This is used whenever unpacking is necessary; i.e., the source data |
1131 // is not in RGBA8/RGBA32F format, or the unpack alignment specifies | 1220 // is not in RGBA8/RGBA32F format, or the unpack alignment specifies |
1132 // that rows are not tightly packed. | 1221 // that rows are not tightly packed. |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1360 GraphicsContext3D::SourceDataFormat sourceDat
aFormat, | 1449 GraphicsContext3D::SourceDataFormat sourceDat
aFormat, |
1361 unsigned int width, | 1450 unsigned int width, |
1362 unsigned int height, | 1451 unsigned int height, |
1363 unsigned int sourceUnpackAlignment, | 1452 unsigned int sourceUnpackAlignment, |
1364 float* destinationData, | 1453 float* destinationData, |
1365 void rowPackingFunc(const float*, float*, uns
igned int), | 1454 void rowPackingFunc(const float*, float*, uns
igned int), |
1366 unsigned int destinationElementsPerPixel) | 1455 unsigned int destinationElementsPerPixel) |
1367 { | 1456 { |
1368 switch (sourceDataFormat) { | 1457 switch (sourceDataFormat) { |
1369 case GraphicsContext3D::SourceFormatRGBA8: { | 1458 case GraphicsContext3D::SourceFormatRGBA8: { |
| 1459 unsigned int sourceElementsPerRow = computeSourceElementsPerRow<uint8_t>
(width, 4, sourceUnpackAlignment); |
| 1460 doUnpackingAndPacking<uint8_t, float, float>(static_cast<const uint8_t*>
(sourceData), unpackOneRowOfRGBA8ToRGBA32F, width, height, sourceElementsPerRow,
destinationData, rowPackingFunc, destinationElementsPerPixel); |
| 1461 break; |
| 1462 } |
| 1463 case GraphicsContext3D::SourceFormatBGRA8: { |
| 1464 unsigned int sourceElementsPerRow = computeSourceElementsPerRow<uint8_t>
(width, 4, sourceUnpackAlignment); |
| 1465 doUnpackingAndPacking<uint8_t, float, float>(static_cast<const uint8_t*>
(sourceData), unpackOneRowOfBGRA8ToRGBA32F, width, height, sourceElementsPerRow,
destinationData, rowPackingFunc, destinationElementsPerPixel); |
| 1466 break; |
| 1467 } |
| 1468 case GraphicsContext3D::SourceFormatRGBA32F: { |
1370 unsigned int sourceElementsPerRow = computeSourceElementsPerRow<float>(w
idth, 4, sourceUnpackAlignment); | 1469 unsigned int sourceElementsPerRow = computeSourceElementsPerRow<float>(w
idth, 4, sourceUnpackAlignment); |
1371 const float* source = static_cast<const float*>(sourceData); | 1470 const float* source = static_cast<const float*>(sourceData); |
1372 const float* endPointer = source + height * sourceElementsPerRow; | 1471 const float* endPointer = source + height * sourceElementsPerRow; |
1373 unsigned int destinationElementsPerRow = width * destinationElementsPerP
ixel; | 1472 unsigned int destinationElementsPerRow = width * destinationElementsPerP
ixel; |
1374 while (source < endPointer) { | 1473 while (source < endPointer) { |
1375 rowPackingFunc(source, destinationData, width); | 1474 rowPackingFunc(source, destinationData, width); |
1376 source += sourceElementsPerRow; | 1475 source += sourceElementsPerRow; |
1377 destinationData += destinationElementsPerRow; | 1476 destinationData += destinationElementsPerRow; |
1378 } | 1477 } |
1379 break; | 1478 break; |
(...skipping 16 matching lines...) Expand all Loading... |
1396 case GraphicsContext3D::SourceFormatA32F: { | 1495 case GraphicsContext3D::SourceFormatA32F: { |
1397 unsigned int sourceElementsPerRow = computeSourceElementsPerRow<float>(w
idth, 1, sourceUnpackAlignment); | 1496 unsigned int sourceElementsPerRow = computeSourceElementsPerRow<float>(w
idth, 1, sourceUnpackAlignment); |
1398 doUnpackingAndPacking<float, float, float>(static_cast<const float*>(sou
rceData), unpackOneRowOfA32FToRGBA32F, width, height, sourceElementsPerRow, dest
inationData, rowPackingFunc, destinationElementsPerPixel); | 1497 doUnpackingAndPacking<float, float, float>(static_cast<const float*>(sou
rceData), unpackOneRowOfA32FToRGBA32F, width, height, sourceElementsPerRow, dest
inationData, rowPackingFunc, destinationElementsPerPixel); |
1399 break; | 1498 break; |
1400 } | 1499 } |
1401 default: | 1500 default: |
1402 ASSERT_NOT_REACHED(); | 1501 ASSERT_NOT_REACHED(); |
1403 } | 1502 } |
1404 } | 1503 } |
1405 | 1504 |
| 1505 |
| 1506 #if !ASSERT_DISABLED |
| 1507 static bool isFloatingPointSource(GraphicsContext3D::SourceDataFormat format) |
| 1508 { |
| 1509 switch (format) { |
| 1510 case GraphicsContext3D::SourceFormatRGBA32F: |
| 1511 case GraphicsContext3D::SourceFormatRGB32F: |
| 1512 case GraphicsContext3D::SourceFormatRA32F: |
| 1513 case GraphicsContext3D::SourceFormatR32F: |
| 1514 case GraphicsContext3D::SourceFormatA32F: |
| 1515 return true; |
| 1516 default: |
| 1517 return false; |
| 1518 } |
| 1519 } |
| 1520 #endif |
| 1521 |
1406 bool GraphicsContext3D::packPixels(const uint8_t* sourceData, | 1522 bool GraphicsContext3D::packPixels(const uint8_t* sourceData, |
1407 GraphicsContext3D::SourceDataFormat sourceDat
aFormat, | 1523 GraphicsContext3D::SourceDataFormat sourceDat
aFormat, |
1408 unsigned int width, | 1524 unsigned int width, |
1409 unsigned int height, | 1525 unsigned int height, |
1410 unsigned int sourceUnpackAlignment, | 1526 unsigned int sourceUnpackAlignment, |
1411 unsigned int destinationFormat, | 1527 unsigned int destinationFormat, |
1412 unsigned int destinationType, | 1528 unsigned int destinationType, |
1413 AlphaOp alphaOp, | 1529 AlphaOp alphaOp, |
1414 void* destinationData) | 1530 void* destinationData) |
1415 { | 1531 { |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1532 doPacking<uint16_t>(sourceData, sourceDataFormat, width, height, sou
rceUnpackAlignment, destination, packOneRowOfRGBA8ToUnsignedShort565Premultiply,
1); | 1648 doPacking<uint16_t>(sourceData, sourceDataFormat, width, height, sou
rceUnpackAlignment, destination, packOneRowOfRGBA8ToUnsignedShort565Premultiply,
1); |
1533 break; | 1649 break; |
1534 case AlphaDoUnmultiply: | 1650 case AlphaDoUnmultiply: |
1535 doPacking<uint16_t>(sourceData, sourceDataFormat, width, height, sou
rceUnpackAlignment, destination, packOneRowOfRGBA8ToUnsignedShort565Unmultiply,
1); | 1651 doPacking<uint16_t>(sourceData, sourceDataFormat, width, height, sou
rceUnpackAlignment, destination, packOneRowOfRGBA8ToUnsignedShort565Unmultiply,
1); |
1536 break; | 1652 break; |
1537 } | 1653 } |
1538 break; | 1654 break; |
1539 } | 1655 } |
1540 case FLOAT: { | 1656 case FLOAT: { |
1541 // OpenGL ES, and therefore WebGL, require that the format and | 1657 // OpenGL ES, and therefore WebGL, require that the format and |
1542 // internalformat be identical, which implies that the source and | 1658 // internalformat be identical. This means that whenever the |
1543 // destination formats will both be floating-point in this branch -- at | 1659 // developer supplies an ArrayBufferView on this code path, |
1544 // least, until WebKit supports floating-point image formats natively. | 1660 // the source data will be in a floating-point format. |
1545 ASSERT(sourceDataFormat == SourceFormatRGBA32F || sourceDataFormat == So
urceFormatRGB32F | 1661 // |
1546 || sourceDataFormat == SourceFormatRA32F || sourceDataFormat == S
ourceFormatR32F | 1662 // The only time the source data will not be floating-point is |
1547 || sourceDataFormat == SourceFormatA32F); | 1663 // when uploading a DOM element or ImageData as a |
1548 // Because WebKit doesn't use floating-point color channels for anything | 1664 // floating-point texture. Only RGBA8 and BGRA8 are handled in |
1549 // internally, there's no chance we have to do a (lossy) unmultiply | 1665 // this case. |
1550 // operation. | 1666 ASSERT(isFloatingPointSource(sourceDataFormat) |
1551 ASSERT(alphaOp == AlphaDoNothing || alphaOp == AlphaDoPremultiply); | 1667 || sourceDataFormat == SourceFormatRGBA8 |
| 1668 || sourceDataFormat == SourceFormatBGRA8); |
| 1669 // When uploading a canvas into a floating-point texture, |
| 1670 // unmultiplication may be necessary. |
| 1671 ASSERT((alphaOp == AlphaDoNothing || alphaOp == AlphaDoPremultiply) |
| 1672 || !isFloatingPointSource(sourceDataFormat)); |
1552 // For the source formats with an even number of channels (RGBA32F, | 1673 // For the source formats with an even number of channels (RGBA32F, |
1553 // RA32F) it is guaranteed that the pixel data is tightly packed because | 1674 // RA32F) it is guaranteed that the pixel data is tightly packed because |
1554 // unpack alignment <= sizeof(float) * number of channels. | 1675 // unpack alignment <= sizeof(float) * number of channels. |
1555 float* destination = static_cast<float*>(destinationData); | 1676 float* destination = static_cast<float*>(destinationData); |
1556 if (alphaOp == AlphaDoNothing | 1677 if (alphaOp == AlphaDoNothing |
1557 && ((sourceDataFormat == SourceFormatRGBA32F && destinationFormat ==
RGBA) | 1678 && ((sourceDataFormat == SourceFormatRGBA32F && destinationFormat ==
RGBA) |
1558 || (sourceDataFormat == SourceFormatRA32F && destinationFormat =
= LUMINANCE_ALPHA))) { | 1679 || (sourceDataFormat == SourceFormatRA32F && destinationFormat =
= LUMINANCE_ALPHA))) { |
1559 // No conversion necessary. | 1680 // No conversion necessary. |
1560 int numChannels = (sourceDataFormat == SourceFormatRGBA32F ? 4 : 2); | 1681 int numChannels = (sourceDataFormat == SourceFormatRGBA32F ? 4 : 2); |
1561 memcpy(destinationData, sourceData, width * height * numChannels * s
izeof(float)); | 1682 memcpy(destinationData, sourceData, width * height * numChannels * s
izeof(float)); |
1562 break; | 1683 break; |
1563 } | 1684 } |
1564 switch (destinationFormat) { | 1685 switch (destinationFormat) { |
1565 case RGB: | 1686 case RGB: |
1566 switch (alphaOp) { | 1687 switch (alphaOp) { |
1567 case AlphaDoNothing: | 1688 case AlphaDoNothing: |
1568 doFloatingPointPacking(sourceData, sourceDataFormat, width, heig
ht, sourceUnpackAlignment, destination, packOneRowOfRGBA32FToRGB32F, 3); | 1689 doFloatingPointPacking(sourceData, sourceDataFormat, width, heig
ht, sourceUnpackAlignment, destination, packOneRowOfRGBA32FToRGB32F, 3); |
1569 break; | 1690 break; |
1570 case AlphaDoPremultiply: | 1691 case AlphaDoPremultiply: |
1571 doFloatingPointPacking(sourceData, sourceDataFormat, width, heig
ht, sourceUnpackAlignment, destination, packOneRowOfRGBA32FToRGB32FPremultiply,
3); | 1692 doFloatingPointPacking(sourceData, sourceDataFormat, width, heig
ht, sourceUnpackAlignment, destination, packOneRowOfRGBA32FToRGB32FPremultiply,
3); |
1572 break; | 1693 break; |
1573 default: | 1694 case AlphaDoUnmultiply: |
1574 ASSERT_NOT_REACHED(); | 1695 doFloatingPointPacking(sourceData, sourceDataFormat, width, heig
ht, sourceUnpackAlignment, destination, packOneRowOfRGBA32FToRGB32FUnmultiply, 3
); |
| 1696 break; |
1575 } | 1697 } |
1576 break; | 1698 break; |
1577 case RGBA: | 1699 case RGBA: |
1578 // AlphaDoNothing is handled above with fast path. | 1700 // AlphaDoNothing for RGBA32F -> RGBA is handled above with fast pat
h. |
1579 ASSERT(alphaOp == AlphaDoPremultiply); | 1701 ASSERT(alphaOp != AlphaDoNothing || sourceDataFormat != SourceFormat
RGBA32F); |
1580 doFloatingPointPacking(sourceData, sourceDataFormat, width, height,
sourceUnpackAlignment, destination, packOneRowOfRGBA32FToRGBA32FPremultiply, 4); | 1702 switch (alphaOp) { |
| 1703 case AlphaDoNothing: |
| 1704 doFloatingPointPacking(sourceData, sourceDataFormat, width, heig
ht, sourceUnpackAlignment, destination, packOneRowOfRGBA32FToRGBA32F, 4); |
| 1705 break; |
| 1706 case AlphaDoPremultiply: |
| 1707 doFloatingPointPacking(sourceData, sourceDataFormat, width, heig
ht, sourceUnpackAlignment, destination, packOneRowOfRGBA32FToRGBA32FPremultiply,
4); |
| 1708 break; |
| 1709 case AlphaDoUnmultiply: |
| 1710 doFloatingPointPacking(sourceData, sourceDataFormat, width, heig
ht, sourceUnpackAlignment, destination, packOneRowOfRGBA32FToRGBA32FUnmultiply,
4); |
| 1711 break; |
| 1712 } |
1581 break; | 1713 break; |
1582 case ALPHA: | 1714 case ALPHA: |
1583 // From the desktop OpenGL conversion rules (OpenGL 2.1 | 1715 // From the desktop OpenGL conversion rules (OpenGL 2.1 |
1584 // specification, Table 3.15), the alpha channel is chosen | 1716 // specification, Table 3.15), the alpha channel is chosen |
1585 // from the RGBA data. | 1717 // from the RGBA data. |
1586 doFloatingPointPacking(sourceData, sourceDataFormat, width, height,
sourceUnpackAlignment, destination, packOneRowOfRGBA32FToA32F, 1); | 1718 doFloatingPointPacking(sourceData, sourceDataFormat, width, height,
sourceUnpackAlignment, destination, packOneRowOfRGBA32FToA32F, 1); |
1587 break; | 1719 break; |
1588 case LUMINANCE: | 1720 case LUMINANCE: |
1589 // From the desktop OpenGL conversion rules (OpenGL 2.1 | 1721 // From the desktop OpenGL conversion rules (OpenGL 2.1 |
1590 // specification, Table 3.15), the red channel is chosen | 1722 // specification, Table 3.15), the red channel is chosen |
1591 // from the RGBA data. | 1723 // from the RGBA data. |
1592 switch (alphaOp) { | 1724 switch (alphaOp) { |
1593 case AlphaDoNothing: | 1725 case AlphaDoNothing: |
1594 doFloatingPointPacking(sourceData, sourceDataFormat, width, heig
ht, sourceUnpackAlignment, destination, packOneRowOfRGBA32FToR32F, 1); | 1726 doFloatingPointPacking(sourceData, sourceDataFormat, width, heig
ht, sourceUnpackAlignment, destination, packOneRowOfRGBA32FToR32F, 1); |
1595 break; | 1727 break; |
1596 case AlphaDoPremultiply: | 1728 case AlphaDoPremultiply: |
1597 doFloatingPointPacking(sourceData, sourceDataFormat, width, heig
ht, sourceUnpackAlignment, destination, packOneRowOfRGBA32FToR32FPremultiply, 1)
; | 1729 doFloatingPointPacking(sourceData, sourceDataFormat, width, heig
ht, sourceUnpackAlignment, destination, packOneRowOfRGBA32FToR32FPremultiply, 1)
; |
1598 break; | 1730 break; |
1599 default: | 1731 case AlphaDoUnmultiply: |
1600 ASSERT_NOT_REACHED(); | 1732 doFloatingPointPacking(sourceData, sourceDataFormat, width, heig
ht, sourceUnpackAlignment, destination, packOneRowOfRGBA32FToR32FUnmultiply, 1); |
| 1733 break; |
1601 } | 1734 } |
1602 break; | 1735 break; |
1603 case LUMINANCE_ALPHA: | 1736 case LUMINANCE_ALPHA: |
1604 // From the desktop OpenGL conversion rules (OpenGL 2.1 | 1737 // From the desktop OpenGL conversion rules (OpenGL 2.1 |
1605 // specification, Table 3.15), the red and alpha channels | 1738 // specification, Table 3.15), the red and alpha channels |
1606 // are chosen from the RGBA data. | 1739 // are chosen from the RGBA data. |
1607 switch (alphaOp) { | 1740 switch (alphaOp) { |
1608 case AlphaDoNothing: | 1741 case AlphaDoNothing: |
1609 doFloatingPointPacking(sourceData, sourceDataFormat, width, heig
ht, sourceUnpackAlignment, destination, packOneRowOfRGBA32FToRA32F, 2); | 1742 doFloatingPointPacking(sourceData, sourceDataFormat, width, heig
ht, sourceUnpackAlignment, destination, packOneRowOfRGBA32FToRA32F, 2); |
1610 break; | 1743 break; |
1611 case AlphaDoPremultiply: | 1744 case AlphaDoPremultiply: |
1612 doFloatingPointPacking(sourceData, sourceDataFormat, width, heig
ht, sourceUnpackAlignment, destination, packOneRowOfRGBA32FToRA32FPremultiply, 2
); | 1745 doFloatingPointPacking(sourceData, sourceDataFormat, width, heig
ht, sourceUnpackAlignment, destination, packOneRowOfRGBA32FToRA32FPremultiply, 2
); |
1613 break; | 1746 break; |
1614 default: | 1747 case AlphaDoUnmultiply: |
1615 ASSERT_NOT_REACHED(); | 1748 doFloatingPointPacking(sourceData, sourceDataFormat, width, heig
ht, sourceUnpackAlignment, destination, packOneRowOfRGBA32FToRA32FUnmultiply, 2)
; |
| 1749 break; |
1616 } | 1750 } |
1617 break; | 1751 break; |
1618 } | 1752 } |
1619 break; | 1753 break; |
1620 } | 1754 } |
1621 } | 1755 } |
1622 return true; | 1756 return true; |
1623 } | 1757 } |
1624 | 1758 |
1625 } // namespace WebCore | 1759 } // namespace WebCore |
1626 | 1760 |
1627 #endif // ENABLE(WEBGL) | 1761 #endif // ENABLE(WEBGL) |
OLD | NEW |