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

Side by Side Diff: Source/platform/graphics/gpu/WebGLImageConversion.cpp

Issue 1190423002: Upgrade WebGLImageConversion to ES3: Part II. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 for (unsigned i = 0; i < pixelsPerRow; ++i) { 529 for (unsigned i = 0; i < pixelsPerRow; ++i) {
530 destination[0] = source[0]; 530 destination[0] = source[0];
531 destination[1] = source[0]; 531 destination[1] = source[0];
532 destination[2] = source[0]; 532 destination[2] = source[0];
533 destination[3] = source[1]; 533 destination[3] = source[1];
534 source += 2; 534 source += 2;
535 destination += 4; 535 destination += 4;
536 } 536 }
537 } 537 }
538 538
539 template<> void unpack<WebGLImageConversion::DataFormatRGBA2_10_10_10, uint32_t, uint16_t>(const uint32_t* source, uint16_t* destination, unsigned pixelsPerRow)
540 {
541 // FIXME: Implement this.
542 ASSERT_NOT_REACHED();
543 }
544
539 //---------------------------------------------------------------------- 545 //----------------------------------------------------------------------
540 // Pixel packing routines. 546 // Pixel packing routines.
541 // 547 //
542 548
543 template<int format, int alphaOp, typename SourceType, typename DstType> 549 template<int format, int alphaOp, typename SourceType, typename DstType>
544 void pack(const SourceType*, DstType*, unsigned) 550 void pack(const SourceType*, DstType*, unsigned)
545 { 551 {
546 ASSERT_NOT_REACHED(); 552 ASSERT_NOT_REACHED();
547 } 553 }
548 554
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * s caleFactor); 663 uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * s caleFactor);
658 uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * s caleFactor); 664 uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * s caleFactor);
659 destination[0] = sourceR; 665 destination[0] = sourceR;
660 destination[1] = sourceG; 666 destination[1] = sourceG;
661 destination[2] = sourceB; 667 destination[2] = sourceB;
662 source += 4; 668 source += 4;
663 destination += 3; 669 destination += 3;
664 } 670 }
665 } 671 }
666 672
667
668 template<> void pack<WebGLImageConversion::DataFormatRGBA8, WebGLImageConversion ::AlphaDoNothing, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
669 {
670 memcpy(destination, source, pixelsPerRow * 4);
671 }
672
673 template<> void pack<WebGLImageConversion::DataFormatRGBA8, WebGLImageConversion ::AlphaDoPremultiply, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destinat ion, unsigned pixelsPerRow) 673 template<> void pack<WebGLImageConversion::DataFormatRGBA8, WebGLImageConversion ::AlphaDoPremultiply, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destinat ion, unsigned pixelsPerRow)
674 { 674 {
675 for (unsigned i = 0; i < pixelsPerRow; ++i) { 675 for (unsigned i = 0; i < pixelsPerRow; ++i) {
676 float scaleFactor = source[3] / 255.0f; 676 float scaleFactor = source[3] / 255.0f;
677 uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * s caleFactor); 677 uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * s caleFactor);
678 uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * s caleFactor); 678 uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * s caleFactor);
679 uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * s caleFactor); 679 uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * s caleFactor);
680 destination[0] = sourceR; 680 destination[0] = sourceR;
681 destination[1] = sourceG; 681 destination[1] = sourceG;
682 destination[2] = sourceB; 682 destination[2] = sourceB;
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 for (unsigned i = 0; i < pixelsPerRow; ++i) { 872 for (unsigned i = 0; i < pixelsPerRow; ++i) {
873 float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f; 873 float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f;
874 destination[0] = source[0] * scaleFactor; 874 destination[0] = source[0] * scaleFactor;
875 destination[1] = source[1] * scaleFactor; 875 destination[1] = source[1] * scaleFactor;
876 destination[2] = source[2] * scaleFactor; 876 destination[2] = source[2] * scaleFactor;
877 source += 4; 877 source += 4;
878 destination += 3; 878 destination += 3;
879 } 879 }
880 } 880 }
881 881
882 // Used only during RGBA8 or BGRA8 -> floating-point uploads.
883 template<> void pack<WebGLImageConversion::DataFormatRGBA32F, WebGLImageConversi on::AlphaDoNothing, float, float>(const float* source, float* destination, unsig ned pixelsPerRow)
884 {
885 memcpy(destination, source, pixelsPerRow * 4 * sizeof(float));
886 }
887
888 template<> void pack<WebGLImageConversion::DataFormatRGBA32F, WebGLImageConversi on::AlphaDoPremultiply, float, float>(const float* source, float* destination, u nsigned pixelsPerRow) 882 template<> void pack<WebGLImageConversion::DataFormatRGBA32F, WebGLImageConversi on::AlphaDoPremultiply, float, float>(const float* source, float* destination, u nsigned pixelsPerRow)
889 { 883 {
890 for (unsigned i = 0; i < pixelsPerRow; ++i) { 884 for (unsigned i = 0; i < pixelsPerRow; ++i) {
891 float scaleFactor = source[3]; 885 float scaleFactor = source[3];
892 destination[0] = source[0] * scaleFactor; 886 destination[0] = source[0] * scaleFactor;
893 destination[1] = source[1] * scaleFactor; 887 destination[1] = source[1] * scaleFactor;
894 destination[2] = source[2] * scaleFactor; 888 destination[2] = source[2] * scaleFactor;
895 destination[3] = source[3]; 889 destination[3] = source[3];
896 source += 4; 890 source += 4;
897 destination += 4; 891 destination += 4;
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
1117 1111
1118 template<> void pack<WebGLImageConversion::DataFormatA16F, WebGLImageConversion: :AlphaDoNothing, float, uint16_t>(const float* source, uint16_t* destination, un signed pixelsPerRow) 1112 template<> void pack<WebGLImageConversion::DataFormatA16F, WebGLImageConversion: :AlphaDoNothing, float, uint16_t>(const float* source, uint16_t* destination, un signed pixelsPerRow)
1119 { 1113 {
1120 for (unsigned i = 0; i < pixelsPerRow; ++i) { 1114 for (unsigned i = 0; i < pixelsPerRow; ++i) {
1121 destination[0] = convertFloatToHalfFloat(source[3]); 1115 destination[0] = convertFloatToHalfFloat(source[3]);
1122 source += 4; 1116 source += 4;
1123 destination += 1; 1117 destination += 1;
1124 } 1118 }
1125 } 1119 }
1126 1120
1121 template<> void pack<WebGLImageConversion::DataFormatRGBA8_S, WebGLImageConversi on::AlphaDoPremultiply, int8_t, int8_t>(const int8_t* source, int8_t* destinatio n, unsigned pixelsPerRow)
1122 {
1123 // FIXME: Implement this.
1124 ASSERT_NOT_REACHED();
1125 }
1126
1127 // FIXME: this routine is lossy and must be removed.
1128 template<> void pack<WebGLImageConversion::DataFormatRGBA8_S, WebGLImageConversi on::AlphaDoUnmultiply, int8_t, int8_t>(const int8_t* source, int8_t* destination , unsigned pixelsPerRow)
Ken Russell (switch to Gerrit) 2015/06/20 02:42:23 The only situation where un-multiplication is need
Zhenyao Mo 2015/06/23 19:12:00 Agree. Will revise in a followup.
1129 {
1130 // FIXME: Implement this.
1131 ASSERT_NOT_REACHED();
1132 }
1133
1134 template<> void pack<WebGLImageConversion::DataFormatRGBA16, WebGLImageConversio n::AlphaDoPremultiply, uint16_t, uint16_t>(const uint16_t* source, uint16_t* des tination, unsigned pixelsPerRow)
1135 {
1136 // FIXME: Implement this.
1137 ASSERT_NOT_REACHED();
1138 }
1139
1140 // FIXME: this routine is lossy and must be removed.
1141 template<> void pack<WebGLImageConversion::DataFormatRGBA16, WebGLImageConversio n::AlphaDoUnmultiply, uint16_t, uint16_t>(const uint16_t* source, uint16_t* dest ination, unsigned pixelsPerRow)
1142 {
1143 // FIXME: Implement this.
1144 ASSERT_NOT_REACHED();
1145 }
1146
1147 template<> void pack<WebGLImageConversion::DataFormatRGBA16_S, WebGLImageConvers ion::AlphaDoPremultiply, int16_t, int16_t>(const int16_t* source, int16_t* desti nation, unsigned pixelsPerRow)
1148 {
1149 // FIXME: Implement this.
1150 ASSERT_NOT_REACHED();
1151 }
1152
1153 // FIXME: this routine is lossy and must be removed.
1154 template<> void pack<WebGLImageConversion::DataFormatRGBA16_S, WebGLImageConvers ion::AlphaDoUnmultiply, int16_t, int16_t>(const int16_t* source, int16_t* destin ation, unsigned pixelsPerRow)
1155 {
1156 // FIXME: Implement this.
1157 ASSERT_NOT_REACHED();
1158 }
1159
1160 template<> void pack<WebGLImageConversion::DataFormatRGBA32, WebGLImageConversio n::AlphaDoPremultiply, uint32_t, uint32_t>(const uint32_t* source, uint32_t* des tination, unsigned pixelsPerRow)
1161 {
1162 // FIXME: Implement this.
1163 ASSERT_NOT_REACHED();
1164 }
1165
1166 // FIXME: this routine is lossy and must be removed.
1167 template<> void pack<WebGLImageConversion::DataFormatRGBA32, WebGLImageConversio n::AlphaDoUnmultiply, uint32_t, uint32_t>(const uint32_t* source, uint32_t* dest ination, unsigned pixelsPerRow)
1168 {
1169 // FIXME: Implement this.
1170 ASSERT_NOT_REACHED();
1171 }
1172
1173 template<> void pack<WebGLImageConversion::DataFormatRGBA32_S, WebGLImageConvers ion::AlphaDoPremultiply, int32_t, int32_t>(const int32_t* source, int32_t* desti nation, unsigned pixelsPerRow)
1174 {
1175 // FIXME: Implement this.
1176 ASSERT_NOT_REACHED();
1177 }
1178
1179 // FIXME: this routine is lossy and must be removed.
1180 template<> void pack<WebGLImageConversion::DataFormatRGBA32_S, WebGLImageConvers ion::AlphaDoUnmultiply, int32_t, int32_t>(const int32_t* source, int32_t* destin ation, unsigned pixelsPerRow)
1181 {
1182 // FIXME: Implement this.
1183 ASSERT_NOT_REACHED();
1184 }
1185
1186 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)
1187 {
1188 // FIXME: Implement this.
1189 ASSERT_NOT_REACHED();
1190 }
1191
1192 // FIXME: this routine is lossy and must be removed.
1193 template<> void pack<WebGLImageConversion::DataFormatRGBA2_10_10_10, WebGLImageC onversion::AlphaDoUnmultiply, uint16_t, uint32_t>(const uint16_t* source, uint32 _t* destination, unsigned pixelsPerRow)
1194 {
1195 // FIXME: Implement this.
1196 ASSERT_NOT_REACHED();
1197 }
1198
1199 template<> void pack<WebGLImageConversion::DataFormatRGB10F11F11F, WebGLImageCon version::AlphaDoNothing, float, uint32_t>(const float* source, uint32_t* destina tion, unsigned pixelsPerRow)
1200 {
1201 // FIXME: Implement this.
1202 ASSERT_NOT_REACHED();
1203 }
1204
1205 template<> void pack<WebGLImageConversion::DataFormatRGB10F11F11F, WebGLImageCon version::AlphaDoPremultiply, float, uint32_t>(const float* source, uint32_t* des tination, unsigned pixelsPerRow)
1206 {
1207 // FIXME: Implement this.
1208 ASSERT_NOT_REACHED();
1209 }
1210
1211 // FIXME: this routine is lossy and must be removed.
1212 template<> void pack<WebGLImageConversion::DataFormatRGB10F11F11F, WebGLImageCon version::AlphaDoUnmultiply, float, uint32_t>(const float* source, uint32_t* dest ination, unsigned pixelsPerRow)
1213 {
1214 // FIXME: Implement this.
1215 ASSERT_NOT_REACHED();
1216 }
1217
1218 template<> void pack<WebGLImageConversion::DataFormatRG8, WebGLImageConversion:: AlphaDoNothing, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, u nsigned pixelsPerRow)
1219 {
1220 // FIXME: Implement this.
1221 ASSERT_NOT_REACHED();
1222 }
1223
1224 template<> void pack<WebGLImageConversion::DataFormatRG8, WebGLImageConversion:: AlphaDoPremultiply, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destinatio n, unsigned pixelsPerRow)
1225 {
1226 // FIXME: Implement this.
1227 ASSERT_NOT_REACHED();
1228 }
1229
1230 // FIXME: this routine is lossy and must be removed.
1231 template<> void pack<WebGLImageConversion::DataFormatRG8, WebGLImageConversion:: AlphaDoUnmultiply, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination , unsigned pixelsPerRow)
1232 {
1233 // FIXME: Implement this.
1234 ASSERT_NOT_REACHED();
1235 }
1236
1237 template<> void pack<WebGLImageConversion::DataFormatRG16F, WebGLImageConversion ::AlphaDoNothing, float, uint16_t>(const float* source, uint16_t* destination, u nsigned pixelsPerRow)
1238 {
1239 // FIXME: Implement this.
1240 ASSERT_NOT_REACHED();
1241 }
1242
1243 template<> void pack<WebGLImageConversion::DataFormatRG16F, WebGLImageConversion ::AlphaDoPremultiply, float, uint16_t>(const float* source, uint16_t* destinatio n, unsigned pixelsPerRow)
1244 {
1245 // FIXME: Implement this.
1246 ASSERT_NOT_REACHED();
1247 }
1248
1249 // FIXME: this routine is lossy and must be removed.
1250 template<> void pack<WebGLImageConversion::DataFormatRG16F, WebGLImageConversion ::AlphaDoUnmultiply, float, uint16_t>(const float* source, uint16_t* destination , unsigned pixelsPerRow)
1251 {
1252 // FIXME: Implement this.
1253 ASSERT_NOT_REACHED();
1254 }
1255
1256 template<> void pack<WebGLImageConversion::DataFormatRG32F, WebGLImageConversion ::AlphaDoNothing, float, float>(const float* source, float* destination, unsigne d pixelsPerRow)
1257 {
1258 // FIXME: Implement this.
1259 ASSERT_NOT_REACHED();
1260 }
1261
1262 template<> void pack<WebGLImageConversion::DataFormatRG32F, WebGLImageConversion ::AlphaDoPremultiply, float, float>(const float* source, float* destination, uns igned pixelsPerRow)
1263 {
1264 // FIXME: Implement this.
1265 ASSERT_NOT_REACHED();
1266 }
1267
1268 // FIXME: this routine is lossy and must be removed.
1269 template<> void pack<WebGLImageConversion::DataFormatRG32F, WebGLImageConversion ::AlphaDoUnmultiply, float, float>(const float* source, float* destination, unsi gned pixelsPerRow)
1270 {
1271 // FIXME: Implement this.
1272 ASSERT_NOT_REACHED();
1273 }
1274
1127 bool HasAlpha(int format) 1275 bool HasAlpha(int format)
1128 { 1276 {
1129 return format == WebGLImageConversion::DataFormatA8 1277 return format == WebGLImageConversion::DataFormatA8
1130 || format == WebGLImageConversion::DataFormatA16F 1278 || format == WebGLImageConversion::DataFormatA16F
1131 || format == WebGLImageConversion::DataFormatA32F 1279 || format == WebGLImageConversion::DataFormatA32F
1132 || format == WebGLImageConversion::DataFormatRA8 1280 || format == WebGLImageConversion::DataFormatRA8
1133 || format == WebGLImageConversion::DataFormatAR8 1281 || format == WebGLImageConversion::DataFormatAR8
1134 || format == WebGLImageConversion::DataFormatRA16F 1282 || format == WebGLImageConversion::DataFormatRA16F
1135 || format == WebGLImageConversion::DataFormatRA32F 1283 || format == WebGLImageConversion::DataFormatRA32F
1136 || format == WebGLImageConversion::DataFormatRGBA8 1284 || format == WebGLImageConversion::DataFormatRGBA8
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
1496 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatRA8) 1644 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatRA8)
1497 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatRA32F ) 1645 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatRA32F )
1498 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatRGBA8 ) 1646 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatRGBA8 )
1499 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatARGB8 ) 1647 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatARGB8 )
1500 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatABGR8 ) 1648 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatABGR8 )
1501 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatAR8) 1649 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatAR8)
1502 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatBGRA8 ) 1650 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatBGRA8 )
1503 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatRGBA5 551) 1651 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatRGBA5 551)
1504 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatRGBA4 444) 1652 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatRGBA4 444)
1505 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatRGBA3 2F) 1653 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatRGBA3 2F)
1654 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatRGBA2 _10_10_10)
1506 default: 1655 default:
1507 ASSERT_NOT_REACHED(); 1656 ASSERT_NOT_REACHED();
1508 } 1657 }
1509 #undef FORMATCONVERTER_CASE_SRCFORMAT 1658 #undef FORMATCONVERTER_CASE_SRCFORMAT
1510 } 1659 }
1511 1660
1512 template<WebGLImageConversion::DataFormat SrcFormat> 1661 template<WebGLImageConversion::DataFormat SrcFormat>
1513 void FormatConverter::convert(WebGLImageConversion::DataFormat dstFormat, WebGLI mageConversion::AlphaOp alphaOp) 1662 void FormatConverter::convert(WebGLImageConversion::DataFormat dstFormat, WebGLI mageConversion::AlphaOp alphaOp)
1514 { 1663 {
1515 #define FORMATCONVERTER_CASE_DSTFORMAT(DstFormat) \ 1664 #define FORMATCONVERTER_CASE_DSTFORMAT(DstFormat) \
(...skipping 12 matching lines...) Expand all
1528 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRA32F ) 1677 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRA32F )
1529 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGB8) 1678 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGB8)
1530 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGB56 5) 1679 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGB56 5)
1531 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGB16 F) 1680 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGB16 F)
1532 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGB32 F) 1681 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGB32 F)
1533 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGBA8 ) 1682 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGBA8 )
1534 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGBA5 551) 1683 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGBA5 551)
1535 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGBA4 444) 1684 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGBA4 444)
1536 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGBA1 6F) 1685 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGBA1 6F)
1537 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGBA3 2F) 1686 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGBA3 2F)
1687 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGBA8 _S)
1688 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGBA1 6)
1689 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGBA1 6_S)
1690 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGBA3 2)
1691 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGBA3 2_S)
1692 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGBA2 _10_10_10)
1693 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRGB10 F11F11F)
1694 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRG8)
1695 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRG16F )
1696 FORMATCONVERTER_CASE_DSTFORMAT(WebGLImageConversion::DataFormatRG32F )
1538 default: 1697 default:
1539 ASSERT_NOT_REACHED(); 1698 ASSERT_NOT_REACHED();
1540 } 1699 }
1541 1700
1542 #undef FORMATCONVERTER_CASE_DSTFORMAT 1701 #undef FORMATCONVERTER_CASE_DSTFORMAT
1543 } 1702 }
1544 1703
1545 template<WebGLImageConversion::DataFormat SrcFormat, WebGLImageConversion::DataF ormat DstFormat> 1704 template<WebGLImageConversion::DataFormat SrcFormat, WebGLImageConversion::DataF ormat DstFormat>
1546 void FormatConverter::convert(WebGLImageConversion::AlphaOp alphaOp) 1705 void FormatConverter::convert(WebGLImageConversion::AlphaOp alphaOp)
1547 { 1706 {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1589 return; 1748 return;
1590 } 1749 }
1591 1750
1592 typedef typename DataTypeForFormat<SrcFormat>::Type SrcType; 1751 typedef typename DataTypeForFormat<SrcFormat>::Type SrcType;
1593 typedef typename DataTypeForFormat<DstFormat>::Type DstType; 1752 typedef typename DataTypeForFormat<DstFormat>::Type DstType;
1594 const int IntermFormat = IntermediateFormat<DstFormat>::Value; 1753 const int IntermFormat = IntermediateFormat<DstFormat>::Value;
1595 typedef typename DataTypeForFormat<IntermFormat>::Type IntermType; 1754 typedef typename DataTypeForFormat<IntermFormat>::Type IntermType;
1596 const ptrdiff_t srcStrideInElements = m_srcStride / sizeof(SrcType); 1755 const ptrdiff_t srcStrideInElements = m_srcStride / sizeof(SrcType);
1597 const ptrdiff_t dstStrideInElements = m_dstStride / sizeof(DstType); 1756 const ptrdiff_t dstStrideInElements = m_dstStride / sizeof(DstType);
1598 const bool trivialUnpack = SrcFormat == IntermFormat; 1757 const bool trivialUnpack = SrcFormat == IntermFormat;
1599 const bool trivialPack = DstFormat == IntermFormat && alphaOp == WebGLImageC onversion::AlphaDoNothing && m_dstStride > 0; 1758 const bool trivialPack = DstFormat == IntermFormat && alphaOp == WebGLImageC onversion::AlphaDoNothing;
1600 ASSERT(!trivialUnpack || !trivialPack); 1759 ASSERT(!trivialUnpack || !trivialPack);
1601 1760
1602 const SrcType *srcRowStart = static_cast<const SrcType*>(m_srcStart); 1761 const SrcType *srcRowStart = static_cast<const SrcType*>(m_srcStart);
1603 DstType* dstRowStart = static_cast<DstType*>(m_dstStart); 1762 DstType* dstRowStart = static_cast<DstType*>(m_dstStart);
1604 if (trivialUnpack) { 1763 if (trivialUnpack) {
1605 for (size_t i = 0; i < m_height; ++i) { 1764 for (size_t i = 0; i < m_height; ++i) {
1606 pack<DstFormat, alphaOp>(srcRowStart, dstRowStart, m_width); 1765 pack<DstFormat, alphaOp>(srcRowStart, dstRowStart, m_width);
1607 srcRowStart += srcStrideInElements; 1766 srcRowStart += srcStrideInElements;
1608 dstRowStart += dstStrideInElements; 1767 dstRowStart += dstStrideInElements;
1609 } 1768 }
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
1991 void* destinationData, 2150 void* destinationData,
1992 bool flipY) 2151 bool flipY)
1993 { 2152 {
1994 int validSrc = width * TexelBytesForFormat(sourceDataFormat); 2153 int validSrc = width * TexelBytesForFormat(sourceDataFormat);
1995 int remainder = sourceUnpackAlignment ? (validSrc % sourceUnpackAlignment) : 0; 2154 int remainder = sourceUnpackAlignment ? (validSrc % sourceUnpackAlignment) : 0;
1996 int srcStride = remainder ? (validSrc + sourceUnpackAlignment - remainder) : validSrc; 2155 int srcStride = remainder ? (validSrc + sourceUnpackAlignment - remainder) : validSrc;
1997 2156
1998 DataFormat dstDataFormat = getDataFormat(destinationFormat, destinationType) ; 2157 DataFormat dstDataFormat = getDataFormat(destinationFormat, destinationType) ;
1999 int dstStride = width * TexelBytesForFormat(dstDataFormat); 2158 int dstStride = width * TexelBytesForFormat(dstDataFormat);
2000 if (flipY) { 2159 if (flipY) {
2001 destinationData = static_cast<uint8_t*>(destinationData) + dstStride*(he ight - 1); 2160 destinationData = static_cast<uint8_t*>(destinationData) + dstStride * ( height - 1);
2002 dstStride = -dstStride; 2161 dstStride = -dstStride;
2003 } 2162 }
2004 if (!HasAlpha(sourceDataFormat) || !HasColor(sourceDataFormat) || !HasColor( dstDataFormat)) 2163 if (!HasAlpha(sourceDataFormat) || !HasColor(sourceDataFormat) || !HasColor( dstDataFormat))
2005 alphaOp = AlphaDoNothing; 2164 alphaOp = AlphaDoNothing;
2006 2165
2007 if (sourceDataFormat == dstDataFormat && alphaOp == AlphaDoNothing) { 2166 if (sourceDataFormat == dstDataFormat && alphaOp == AlphaDoNothing) {
2008 const uint8_t* ptr = sourceData; 2167 const uint8_t* ptr = sourceData;
2009 const uint8_t* ptrEnd = sourceData + srcStride * height; 2168 const uint8_t* ptrEnd = sourceData + srcStride * height;
2010 unsigned rowSize = (dstStride > 0) ? dstStride: -dstStride; 2169 unsigned rowSize = (dstStride > 0) ? dstStride: -dstStride;
2011 uint8_t* dst = static_cast<uint8_t*>(destinationData); 2170 uint8_t* dst = static_cast<uint8_t*>(destinationData);
2012 while (ptr < ptrEnd) { 2171 while (ptr < ptrEnd) {
2013 memcpy(dst, ptr, rowSize); 2172 memcpy(dst, ptr, rowSize);
2014 ptr += srcStride; 2173 ptr += srcStride;
2015 dst += dstStride; 2174 dst += dstStride;
2016 } 2175 }
2017 return true; 2176 return true;
2018 } 2177 }
2019 2178
2020 FormatConverter converter(width, height, sourceData, destinationData, srcStr ide, dstStride); 2179 FormatConverter converter(width, height, sourceData, destinationData, srcStr ide, dstStride);
2021 converter.convert(sourceDataFormat, dstDataFormat, alphaOp); 2180 converter.convert(sourceDataFormat, dstDataFormat, alphaOp);
2022 if (!converter.Success()) 2181 if (!converter.Success())
2023 return false; 2182 return false;
2024 return true; 2183 return true;
2025 } 2184 }
2026 2185
2027 } // namespace blink 2186 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698