Changeset 70706 in webkit
- Timestamp:
- Oct 27, 2010 2:09:18 PM (13 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r70705 r70706 1 2010-10-27 Zhenyao Mo <zmo@google.com> 2 3 Reviewed by Kenneth Russell. 4 5 refactor the nested large switch statements in GraphicsContext3DCG.cpp:getImageData() 6 https://bugs.webkit.org/show_bug.cgi?id=47027 7 8 * platform/graphics/GraphicsContext3D.cpp: 9 (WebCore::doPacking): ASSERT false if undefined format is passed in. 10 * platform/graphics/GraphicsContext3D.h: Add kSourceFormatUndefined enum. 11 * platform/graphics/cg/GraphicsContext3DCG.cpp: 12 (WebCore::getSourceDataFormat): Decide source data format from componentsPerPixel, alpha format, bitsPerComponet, etc. 13 (WebCore::GraphicsContext3D::getImageData): Refactor the code to use getSourceDataFormat and remove nested switches. 14 1 15 2010-10-27 Patrick Gansterer <paroga@webkit.org> 2 16 -
trunk/WebCore/platform/graphics/GraphicsContext3D.cpp
r70073 r70706 946 946 break; 947 947 } 948 default: 949 ASSERT(false); 948 950 } 949 951 } -
trunk/WebCore/platform/graphics/GraphicsContext3D.h
r70073 r70706 541 541 // by non-member functions. 542 542 enum SourceDataFormat { 543 kSourceFormatRGBA8 ,543 kSourceFormatRGBA8 = 0, 544 544 kSourceFormatRGBA16Little, 545 545 kSourceFormatRGBA16Big, … … 567 567 kSourceFormatA8, 568 568 kSourceFormatA16Little, 569 kSourceFormatA16Big 569 kSourceFormatA16Big, 570 kSourceFormatNumFormats 570 571 }; 571 572 -
trunk/WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp
r70073 r70706 42 42 namespace WebCore { 43 43 44 enum SourceDataFormatBase { 45 SourceFormatBaseR = 0, 46 SourceFormatBaseA, 47 SourceFormatBaseRA, 48 SourceFormatBaseAR, 49 SourceFormatBaseRGB, 50 SourceFormatBaseRGBA, 51 SourceFormatBaseARGB, 52 SourceFormatBaseNumFormats 53 }; 54 55 enum AlphaFormat { 56 AlphaFormatNone = 0, 57 AlphaFormatFirst, 58 AlphaFormatLast, 59 AlphaFormatNumFormats 60 }; 61 62 // This returns kSourceFormatNumFormats if the combination of input parameters is unsupported. 63 static GraphicsContext3D::SourceDataFormat getSourceDataFormat(unsigned int componentsPerPixel, AlphaFormat alphaFormat, bool is16BitFormat, bool bigEndian) 64 { 65 const static SourceDataFormatBase formatTableBase[4][AlphaFormatNumFormats] = { // componentsPerPixel x AlphaFormat 66 // AlphaFormatNone AlphaFormatFirst AlphaFormatLast 67 { SourceFormatBaseR, SourceFormatBaseA, SourceFormatBaseA }, // 1 componentsPerPixel 68 { SourceFormatBaseNumFormats, SourceFormatBaseAR, SourceFormatBaseRA }, // 2 componentsPerPixel 69 { SourceFormatBaseRGB, SourceFormatBaseNumFormats, SourceFormatBaseNumFormats }, // 3 componentsPerPixel 70 { SourceFormatBaseNumFormats, SourceFormatBaseARGB, SourceFormatBaseRGBA } // 4 componentsPerPixel 71 }; 72 const static GraphicsContext3D::SourceDataFormat formatTable[SourceFormatBaseNumFormats][3] = { // SourceDataFormatBase x bitsPerComponentAndEndian 73 // 8bits 16bits, little endian 16bits, big endian 74 { GraphicsContext3D::kSourceFormatR8, GraphicsContext3D::kSourceFormatR16Little, GraphicsContext3D::kSourceFormatR16Big }, 75 { GraphicsContext3D::kSourceFormatA8, GraphicsContext3D::kSourceFormatA16Little, GraphicsContext3D::kSourceFormatA16Big }, 76 { GraphicsContext3D::kSourceFormatRA8, GraphicsContext3D::kSourceFormatRA16Little, GraphicsContext3D::kSourceFormatRA16Big }, 77 { GraphicsContext3D::kSourceFormatAR8, GraphicsContext3D::kSourceFormatAR16Little, GraphicsContext3D::kSourceFormatAR16Big }, 78 { GraphicsContext3D::kSourceFormatRGB8, GraphicsContext3D::kSourceFormatRGB16Little, GraphicsContext3D::kSourceFormatRGB16Big }, 79 { GraphicsContext3D::kSourceFormatRGBA8, GraphicsContext3D::kSourceFormatRGBA16Little, GraphicsContext3D::kSourceFormatRGBA16Big }, 80 { GraphicsContext3D::kSourceFormatARGB8, GraphicsContext3D::kSourceFormatARGB16Little, GraphicsContext3D::kSourceFormatARGB16Big } 81 }; 82 83 ASSERT(componentsPerPixel <= 4 && componentsPerPixel > 0); 84 SourceDataFormatBase formatBase = formatTableBase[componentsPerPixel - 1][alphaFormat]; 85 if (formatBase == SourceFormatBaseNumFormats) 86 return GraphicsContext3D::kSourceFormatNumFormats; 87 if (!is16BitFormat) 88 return formatTable[formatBase][0]; 89 if (!bigEndian) 90 return formatTable[formatBase][1]; 91 return formatTable[formatBase][2]; 92 } 93 44 94 bool GraphicsContext3D::getImageData(Image* image, 45 95 unsigned int format, … … 63 113 if (!cgImage) 64 114 return false; 115 65 116 size_t width = CGImageGetWidth(cgImage); 66 117 size_t height = CGImageGetHeight(cgImage); … … 74 125 return false; 75 126 size_t componentsPerPixel = bitsPerPixel / bitsPerComponent; 127 76 128 bool srcByteOrder16Big = false; 77 129 if (bitsPerComponent == 16) { … … 94 146 } 95 147 } 96 SourceDataFormat srcDataFormat = kSourceFormatRGBA8; 148 97 149 AlphaOp neededAlphaOp = kAlphaDoNothing; 150 AlphaFormat alphaFormat = AlphaFormatNone; 98 151 switch (CGImageGetAlphaInfo(cgImage)) { 99 152 case kCGImageAlphaPremultipliedFirst: … … 104 157 if (!premultiplyAlpha) 105 158 neededAlphaOp = kAlphaDoUnmultiply; 106 switch (componentsPerPixel) { 107 case 2: 108 if (bitsPerComponent == 8) 109 srcDataFormat = kSourceFormatAR8; 110 else 111 srcDataFormat = srcByteOrder16Big ? kSourceFormatAR16Big : kSourceFormatAR16Little; 112 break; 113 case 4: 114 if (bitsPerComponent == 8) 115 srcDataFormat = kSourceFormatARGB8; 116 else 117 srcDataFormat = srcByteOrder16Big ? kSourceFormatARGB16Big : kSourceFormatARGB16Little; 118 break; 119 default: 120 return false; 121 } 159 alphaFormat = AlphaFormatFirst; 122 160 break; 123 161 case kCGImageAlphaFirst: … … 125 163 if (premultiplyAlpha) 126 164 neededAlphaOp = kAlphaDoPremultiply; 127 switch (componentsPerPixel) { 128 case 1: 129 if (bitsPerComponent == 8) 130 srcDataFormat = kSourceFormatA8; 131 else 132 srcDataFormat = srcByteOrder16Big ? kSourceFormatA16Big : kSourceFormatA16Little; 133 break; 134 case 2: 135 if (bitsPerComponent == 8) 136 srcDataFormat = kSourceFormatAR8; 137 else 138 srcDataFormat = srcByteOrder16Big ? kSourceFormatAR16Big : kSourceFormatAR16Little; 139 break; 140 case 4: 141 if (bitsPerComponent == 8) 142 srcDataFormat = kSourceFormatARGB8; 143 else 144 srcDataFormat = srcByteOrder16Big ? kSourceFormatARGB16Big : kSourceFormatARGB16Little; 145 break; 146 default: 147 return false; 148 } 165 alphaFormat = AlphaFormatFirst; 149 166 break; 150 167 case kCGImageAlphaNoneSkipFirst: 151 168 // This path is only accessible for MacOS earlier than 10.6.4. 152 switch (componentsPerPixel) { 153 case 2: 154 if (bitsPerComponent == 8) 155 srcDataFormat = kSourceFormatAR8; 156 else 157 srcDataFormat = srcByteOrder16Big ? kSourceFormatAR16Big : kSourceFormatAR16Little; 158 break; 159 case 4: 160 if (bitsPerComponent == 8) 161 srcDataFormat = kSourceFormatARGB8; 162 else 163 srcDataFormat = srcByteOrder16Big ? kSourceFormatARGB16Big : kSourceFormatARGB16Little; 164 break; 165 default: 166 return false; 167 } 169 alphaFormat = AlphaFormatFirst; 168 170 break; 169 171 case kCGImageAlphaPremultipliedLast: … … 173 175 if (!premultiplyAlpha) 174 176 neededAlphaOp = kAlphaDoUnmultiply; 175 switch (componentsPerPixel) { 176 case 2: 177 if (bitsPerComponent == 8) 178 srcDataFormat = kSourceFormatRA8; 179 else 180 srcDataFormat = srcByteOrder16Big ? kSourceFormatRA16Big : kSourceFormatRA16Little; 181 break; 182 case 4: 183 if (bitsPerComponent == 8) 184 srcDataFormat = kSourceFormatRGBA8; 185 else 186 srcDataFormat = srcByteOrder16Big ? kSourceFormatRGBA16Big : kSourceFormatRGBA16Little; 187 break; 188 default: 189 return false; 190 } 177 alphaFormat = AlphaFormatLast; 191 178 break; 192 179 case kCGImageAlphaLast: 193 180 if (premultiplyAlpha) 194 181 neededAlphaOp = kAlphaDoPremultiply; 195 switch (componentsPerPixel) { 196 case 1: 197 if (bitsPerComponent == 8) 198 srcDataFormat = kSourceFormatA8; 199 else 200 srcDataFormat = srcByteOrder16Big ? kSourceFormatA16Big : kSourceFormatA16Little; 201 break; 202 case 2: 203 if (bitsPerComponent == 8) 204 srcDataFormat = kSourceFormatRA8; 205 else 206 srcDataFormat = srcByteOrder16Big ? kSourceFormatRA16Big : kSourceFormatRA16Little; 207 break; 208 case 4: 209 if (bitsPerComponent == 8) 210 srcDataFormat = kSourceFormatRGBA8; 211 else 212 srcDataFormat = srcByteOrder16Big ? kSourceFormatRGBA16Big : kSourceFormatRGBA16Little; 213 break; 214 default: 215 return false; 216 } 182 alphaFormat = AlphaFormatLast; 217 183 break; 218 184 case kCGImageAlphaNoneSkipLast: 219 switch (componentsPerPixel) { 220 case 2: 221 if (bitsPerComponent == 8) 222 srcDataFormat = kSourceFormatRA8; 223 else 224 srcDataFormat = srcByteOrder16Big ? kSourceFormatRA16Big : kSourceFormatRA16Little; 225 break; 226 case 4: 227 if (bitsPerComponent == 8) 228 srcDataFormat = kSourceFormatRGBA8; 229 else 230 srcDataFormat = srcByteOrder16Big ? kSourceFormatRGBA16Big : kSourceFormatRGBA16Little; 231 break; 232 default: 233 return false; 234 } 185 alphaFormat = AlphaFormatLast; 235 186 break; 236 187 case kCGImageAlphaNone: 237 switch (componentsPerPixel) { 238 case 1: 239 if (bitsPerComponent == 8) 240 srcDataFormat = kSourceFormatR8; 241 else 242 srcDataFormat = srcByteOrder16Big ? kSourceFormatR16Big : kSourceFormatR16Little; 243 break; 244 case 3: 245 if (bitsPerComponent == 8) 246 srcDataFormat = kSourceFormatRGB8; 247 else 248 srcDataFormat = srcByteOrder16Big ? kSourceFormatRGB16Big : kSourceFormatRGB16Little; 249 break; 250 default: 251 return false; 252 } 188 alphaFormat = AlphaFormatNone; 253 189 break; 254 190 default: 255 191 return false; 256 192 } 193 SourceDataFormat srcDataFormat = getSourceDataFormat(componentsPerPixel, alphaFormat, bitsPerComponent == 16, srcByteOrder16Big); 194 if (srcDataFormat == kSourceFormatNumFormats) 195 return false; 196 257 197 RetainPtr<CFDataRef> pixelData; 258 198 pixelData.adoptCF(CGDataProviderCopyData(CGImageGetDataProvider(cgImage)));
Note: See TracChangeset
for help on using the changeset viewer.