Changeset 84172 in webkit
- Timestamp:
- Apr 18, 2011 12:58:23 PM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r84170 r84172 1 2011-04-14 Matthew Delaney <mdelaney@apple.com> 2 3 Reviewed by Simon Fraser. 4 5 [CG] Use vImage (un)premultiplyImageData functions for get/putImageData with IOSurfaces 6 https://bugs.webkit.org/show_bug.cgi?id=58088 7 8 * platform/graphics/cg/ImageBufferDataCG.cpp: 9 (WebCore::convertScanline): un/premultiplies and converts a scanline of image data from/to BGRA to/from RGBA 10 (WebCore::unpremultitplyScanline): 11 (WebCore::premultitplyScanline): 12 (WebCore::ImageBufferData::getData): 13 (WebCore::ImageBufferData::putData): 14 1 15 2011-04-18 Jeff Miller <jeffm@apple.com> 2 16 -
trunk/Source/WebCore/platform/graphics/cg/ImageBufferDataCG.cpp
r83786 r84172 35 35 #if USE(IOSURFACE_CANVAS_BACKING_STORE) 36 36 #include <IOSurface/IOSurface.h> 37 #include <dispatch/dispatch.h> 38 #endif 39 40 #if USE(ACCELERATE) 41 struct ScanlineData { 42 vImagePixelCount scanlineWidth; 43 unsigned char* srcData; 44 size_t srcRowBytes; 45 unsigned char* destData; 46 size_t destRowBytes; 47 }; 37 48 #endif 38 49 … … 55 66 return result; 56 67 } 57 #endif 68 69 #if USE(IOSURFACE_CANVAS_BACKING_STORE) 70 static void convertScanline(void* data, size_t tileNumber, bool premultiply) 71 { 72 ScanlineData* scanlineData = static_cast<ScanlineData*>(data); 73 74 vImage_Buffer src; 75 src.data = scanlineData->srcData + tileNumber * scanlineData->srcRowBytes; 76 src.height = 1; 77 src.width = scanlineData->scanlineWidth; 78 src.rowBytes = scanlineData->srcRowBytes; 79 80 vImage_Buffer dest; 81 dest.data = scanlineData->destData + tileNumber * scanlineData->destRowBytes; 82 dest.height = 1; 83 dest.width = scanlineData->scanlineWidth; 84 dest.rowBytes = scanlineData->destRowBytes; 85 86 if (premultiply) { 87 if (kvImageNoError != vImagePremultiplyData_RGBA8888(&src, &dest, kvImageDoNotTile)) 88 return; 89 } else { 90 if (kvImageNoError != vImageUnpremultiplyData_RGBA8888(&src, &dest, kvImageDoNotTile)) 91 return; 92 } 93 94 // Swap channels 1 and 3, to convert BGRA<->RGBA. IOSurfaces is BGRA, ImageData expects RGBA. 95 const uint8_t map[4] = { 2, 1, 0, 3 }; 96 vImagePermuteChannels_ARGB8888(&dest, &dest, map, kvImageDoNotTile); 97 } 98 99 static void unpremultitplyScanline(void* data, size_t tileNumber) 100 { 101 convertScanline(data, tileNumber, false); 102 } 103 104 static void premultitplyScanline(void* data, size_t tileNumber) 105 { 106 convertScanline(data, tileNumber, true); 107 } 108 #endif // USE(IOSURFACE_CANVAS_BACKING_STORE) 109 #endif // USE(ACCELERATE) 58 110 59 111 PassRefPtr<ByteArray> ImageBufferData::getData(const IntRect& rect, const IntSize& size, bool accelerateRendering, bool unmultiplied) const … … 139 191 srcBytesPerRow = IOSurfaceGetBytesPerRow(surface); 140 192 srcRows = (unsigned char*)(IOSurfaceGetBaseAddress(surface)) + originy * srcBytesPerRow + originx * 4; 141 193 194 #if USE(ACCELERATE) 195 if (unmultiplied) { 196 ScanlineData scanlineData; 197 scanlineData.scanlineWidth = width; 198 scanlineData.srcData = srcRows; 199 scanlineData.srcRowBytes = srcBytesPerRow; 200 scanlineData.destData = destRows; 201 scanlineData.destRowBytes = destBytesPerRow; 202 203 dispatch_apply_f(height, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), &scanlineData, unpremultitplyScanline); 204 } else { 205 vImage_Buffer src; 206 src.height = height; 207 src.width = width; 208 src.rowBytes = srcBytesPerRow; 209 src.data = srcRows; 210 211 vImage_Buffer dest; 212 dest.height = height; 213 dest.width = width; 214 dest.rowBytes = destBytesPerRow; 215 dest.data = destRows; 216 217 // Swap pixel channels from BGRA to RGBA. 218 const uint8_t map[4] = { 2, 1, 0, 3 }; 219 vImagePermuteChannels_ARGB8888(&src, &dest, map, kvImageNoFlags); 220 } 221 #else 142 222 for (int y = 0; y < height; ++y) { 143 223 for (int x = 0; x < width; x++) { … … 159 239 destRows += destBytesPerRow; 160 240 } 241 #endif // USE(ACCELERATE) 161 242 IOSurfaceUnlock(surface, kIOSurfaceLockReadOnly, 0); 162 243 #else 163 244 ASSERT_NOT_REACHED(); 164 #endif 245 #endif // USE(IOSURFACE_CANVAS_BACKING_STORE) 165 246 } 166 247 … … 247 328 destBytesPerRow = IOSurfaceGetBytesPerRow(surface); 248 329 destRows = (unsigned char*)(IOSurfaceGetBaseAddress(surface)) + desty * destBytesPerRow + destx * 4; 249 330 331 #if USE(ACCELERATE) 332 if (unmultiplied) { 333 ScanlineData scanlineData; 334 scanlineData.scanlineWidth = width; 335 scanlineData.srcData = srcRows; 336 scanlineData.srcRowBytes = srcBytesPerRow; 337 scanlineData.destData = destRows; 338 scanlineData.destRowBytes = destBytesPerRow; 339 340 dispatch_apply_f(height, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), &scanlineData, premultitplyScanline); 341 } else { 342 vImage_Buffer src; 343 src.height = height; 344 src.width = width; 345 src.rowBytes = srcBytesPerRow; 346 src.data = srcRows; 347 348 vImage_Buffer dest; 349 dest.height = height; 350 dest.width = width; 351 dest.rowBytes = destBytesPerRow; 352 dest.data = destRows; 353 354 // Swap pixel channels from RGBA to BGRA. 355 const uint8_t map[4] = { 2, 1, 0, 3 }; 356 vImagePermuteChannels_ARGB8888(&src, &dest, map, kvImageNoFlags); 357 } 358 #else 250 359 for (int y = 0; y < height; ++y) { 251 360 for (int x = 0; x < width; x++) { … … 267 376 srcRows += srcBytesPerRow; 268 377 } 378 #endif // USE(ACCELERATE) 379 269 380 IOSurfaceUnlock(surface, 0, 0); 270 381 #else 271 382 ASSERT_NOT_REACHED(); 272 #endif 383 #endif // USE(IOSURFACE_CANVAS_BACKING_STORE) 273 384 } 274 385 }
Note: See TracChangeset
for help on using the changeset viewer.