Changeset 73925 in webkit
- Timestamp:
- Dec 13, 2010 10:13:13 AM (13 years ago)
- Location:
- trunk
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r73923 r73925 1 2010-12-09 Matthew Delaney <mdelaney@apple.com> 2 3 Reviewed by Simon Fraser. 4 5 Adopt new CG API for canvas 6 https://bugs.webkit.org/show_bug.cgi?id=50591 7 8 No new tests. All current layout tests are sufficient. 9 10 * html/HTMLCanvasElement.cpp: Add in accelerateRendering flag for imagebuffer creation. 11 * html/canvas/CanvasRenderingContext2D.cpp: 12 (WebCore::CanvasRenderingContext2D::isAccelerated): Always return true if using CA on new platforms. 13 (WebCore::CanvasRenderingContext2D::drawTextInternal): Use accelerateRendering for imagebuffer. 14 * platform/graphics/ImageBuffer.h: 15 (WebCore::ImageBuffer::create): Plumb through new flag. 16 * platform/graphics/cairo/ImageBufferCairo.cpp: Update method sig. 17 * platform/graphics/cg/ImageBufferCG.cpp: Switch off of accelerateRendering flag for new accelerated paths. 18 * platform/graphics/cg/ImageBufferData.h: Add in surface ref 19 * platform/graphics/haiku/ImageBufferHaiku.cpp: Update method sig. 20 * platform/graphics/qt/ImageBufferQt.cpp: ^^ 21 * platform/graphics/skia/ImageBufferSkia.cpp: ^^ 22 * platform/graphics/wince/ImageBufferWinCE.cpp: ^^ 23 * platform/graphics/wx/ImageBufferWx.cpp: ^^ 24 * platform/mac/WebCoreSystemInterface.h: Add new method sigs 25 * platform/mac/WebCoreSystemInterface.mm: ^^ 26 * rendering/RenderLayerBacking.cpp: 27 * rendering/RenderLayerCompositor.cpp: Set acceleratesDrawing for canvas backings. 28 1 29 2010-12-13 Benjamin Kalman <kalman@chromium.org> 2 30 -
trunk/WebCore/WebCore.exp.in
r73886 r73925 1257 1257 #if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD) 1258 1258 _wkCreateCTTypesetterWithUniCharProviderAndOptions 1259 _wkIOSurfaceContextCreate 1260 _wkIOSurfaceContextCreateImage 1259 1261 #endif 1260 1262 -
trunk/WebCore/WebCore.xcodeproj/project.pbxproj
r73914 r73925 690 690 20D629271253690B00081543 /* InspectorInstrumentation.h in Headers */ = {isa = PBXBuildFile; fileRef = 20D629251253690B00081543 /* InspectorInstrumentation.h */; }; 691 691 228C284510D82500009D0D0E /* ScriptWrappable.h in Headers */ = {isa = PBXBuildFile; fileRef = 228C284410D82500009D0D0E /* ScriptWrappable.h */; settings = {ATTRIBUTES = (Private, ); }; }; 692 2298CCE712AD8BCA00C42E51 /* IOSurface.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2298CCE612AD8BCA00C42E51 /* IOSurface.framework */; }; 692 693 24F54EAC101FE914000AE741 /* ApplicationCacheHost.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 24F54EAA101FE914000AE741 /* ApplicationCacheHost.cpp */; }; 693 694 24F54EAD101FE914000AE741 /* ApplicationCacheHost.h in Headers */ = {isa = PBXBuildFile; fileRef = 24F54EAB101FE914000AE741 /* ApplicationCacheHost.h */; settings = {ATTRIBUTES = (); }; }; … … 6973 6974 20D629251253690B00081543 /* InspectorInstrumentation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorInstrumentation.h; sourceTree = "<group>"; }; 6974 6975 228C284410D82500009D0D0E /* ScriptWrappable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptWrappable.h; sourceTree = "<group>"; }; 6976 2298CCE612AD8BCA00C42E51 /* IOSurface.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOSurface.framework; path = /System/Library/Frameworks/IOSurface.framework; sourceTree = "<absolute>"; }; 6975 6977 2442BBF81194C9D300D49469 /* HashChangeEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HashChangeEvent.h; sourceTree = "<group>"; }; 6976 6978 24F54EAA101FE914000AE741 /* ApplicationCacheHost.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ApplicationCacheHost.cpp; sourceTree = "<group>"; }; … … 12230 12232 FD2DBF1412B048A300ED98C6 /* AudioUnit.framework in Frameworks */, 12231 12233 FD2DBF1512B048A300ED98C6 /* CoreAudio.framework in Frameworks */, 12234 2298CCE712AD8BCA00C42E51 /* IOSurface.framework in Frameworks */, 12232 12235 ); 12233 12236 runOnlyForDeploymentPostprocessing = 0; … … 12326 12329 F5C2869502846DCD018635CA /* Cocoa.framework */, 12327 12330 1AB33DA412551E320024457A /* IOKit.framework */, 12331 2298CCE612AD8BCA00C42E51 /* IOSurface.framework */, 12328 12332 F8216299029F4FB501000131 /* JavaScriptCore.framework */, 12329 12333 93F1D31A0558CC5C00821BC0 /* libicucore.dylib */, -
trunk/WebCore/html/HTMLCanvasElement.cpp
r73744 r73925 373 373 return; 374 374 375 #if defined(USE_IOSURFACE) 376 m_imageBuffer = ImageBuffer::create(size, ColorSpaceDeviceRGB, Accelerated); 377 #else 375 378 m_imageBuffer = ImageBuffer::create(size); 379 #endif 376 380 // The convertLogicalToDevice MaxCanvasArea check should prevent common cases 377 381 // where ImageBuffer::create() returns 0, however we could still be low on memory. -
trunk/WebCore/html/canvas/CanvasRenderingContext2D.cpp
r73284 r73925 145 145 bool CanvasRenderingContext2D::isAccelerated() const 146 146 { 147 #if ENABLE(ACCELERATED_2D_CANVAS) 147 #if PLATFORM(MAC) && PLATFORM(CA) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD) 148 return true; 149 #elif ENABLE(ACCELERATED_2D_CANVAS) 148 150 return m_context3D; 149 151 #else … … 1820 1822 IntRect maskRect = enclosingIntRect(textRect); 1821 1823 1824 #if defined(USE_IOSURFACE) 1825 OwnPtr<ImageBuffer> maskImage = ImageBuffer::create(maskRect.size(), ColorSpaceDeviceRGB, Accelerated); 1826 #else 1822 1827 OwnPtr<ImageBuffer> maskImage = ImageBuffer::create(maskRect.size()); 1828 #endif 1823 1829 1824 1830 GraphicsContext* maskImageContext = maskImage->context(); -
trunk/WebCore/platform/graphics/ImageBuffer.h
r70143 r73925 40 40 #include <wtf/PassRefPtr.h> 41 41 42 #if (PLATFORM(MAC) && PLATFORM(CA) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)) 43 #define USE_IOSURFACE 1 44 #endif 45 42 46 namespace WebCore { 43 47 … … 52 56 }; 53 57 58 enum RenderingMode { 59 Unaccelerated, 60 Accelerated 61 }; 62 54 63 class ImageBuffer : public Noncopyable { 55 64 public: 56 65 // Will return a null pointer on allocation failure. 57 static PassOwnPtr<ImageBuffer> create(const IntSize& size, ColorSpace colorSpace = ColorSpaceDeviceRGB )66 static PassOwnPtr<ImageBuffer> create(const IntSize& size, ColorSpace colorSpace = ColorSpaceDeviceRGB, RenderingMode renderingMode = Unaccelerated) 58 67 { 59 68 bool success = false; 60 OwnPtr<ImageBuffer> buf(new ImageBuffer(size, colorSpace, success));69 OwnPtr<ImageBuffer> buf(new ImageBuffer(size, colorSpace, renderingMode == Accelerated, success)); 61 70 if (success) 62 71 return buf.release(); … … 105 114 106 115 IntSize m_size; 116 bool m_accelerateRendering; 107 117 OwnPtr<GraphicsContext> m_context; 108 118 … … 114 124 // This constructor will place its success into the given out-variable 115 125 // so that create() knows when it should return failure. 116 ImageBuffer(const IntSize&, ColorSpace colorSpace, bool & success);126 ImageBuffer(const IntSize&, ColorSpace colorSpace, bool accelerateRendering, bool& success); 117 127 }; 118 128 -
trunk/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp
r70143 r73925 70 70 } 71 71 72 ImageBuffer::ImageBuffer(const IntSize& size, ColorSpace, bool & success)72 ImageBuffer::ImageBuffer(const IntSize& size, ColorSpace, bool, bool& success) 73 73 : m_data(size) 74 74 , m_size(size) -
trunk/WebCore/platform/graphics/cg/ImageBufferCG.cpp
r73853 r73925 43 43 #include <math.h> 44 44 45 #if defined(USE_IOSURFACE) 46 #include <IOSurface/IOSurface.h> 47 #endif 48 49 #if PLATFORM(MAC) || PLATFORM(CHROMIUM) 50 #include "WebCoreSystemInterface.h" 51 #endif 52 45 53 using namespace std; 46 54 47 55 namespace WebCore { 56 57 #if defined(USE_IOSURFACE) 58 static RetainPtr<IOSurfaceRef> createIOSurface(const IntSize& size) 59 { 60 unsigned pixelFormat = 'BGRA'; 61 unsigned bytesPerElement = 4; 62 int width = size.width(); 63 int height = size.height(); 64 65 unsigned long bytesPerRow = IOSurfaceAlignProperty(kIOSurfaceBytesPerRow, size.width() * bytesPerElement); 66 if (!bytesPerRow || bytesPerRow != (size.width() * bytesPerElement)) 67 return 0; 68 69 unsigned long allocSize = IOSurfaceAlignProperty(kIOSurfaceAllocSize, size.height() * bytesPerRow); 70 if (!allocSize || allocSize != (size.height() * bytesPerRow)) 71 return 0; 72 73 const void *keys[6]; 74 const void *values[6]; 75 keys[0] = kIOSurfaceWidth; 76 values[0] = CFNumberCreate(0, kCFNumberIntType, &width); 77 keys[1] = kIOSurfaceHeight; 78 values[1] = CFNumberCreate(0, kCFNumberIntType, &height); 79 keys[2] = kIOSurfacePixelFormat; 80 values[2] = CFNumberCreate(0, kCFNumberIntType, &pixelFormat); 81 keys[3] = kIOSurfaceBytesPerElement; 82 values[3] = CFNumberCreate(0, kCFNumberIntType, &bytesPerElement); 83 keys[4] = kIOSurfaceBytesPerRow; 84 values[4] = CFNumberCreate(0, kCFNumberLongType, &bytesPerRow); 85 keys[5] = kIOSurfaceAllocSize; 86 values[5] = CFNumberCreate(0, kCFNumberLongType, &allocSize); 87 88 RetainPtr<CFDictionaryRef> dict(AdoptCF, CFDictionaryCreate(0, keys, values, 6, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); 89 for (unsigned i = 0; i < 6; i++) 90 CFRelease(values[i]); 91 92 return RetainPtr<IOSurfaceRef>(AdoptCF, IOSurfaceCreate(dict.get())); 93 } 94 #endif 48 95 49 96 static void releaseImageData(void*, const void* data, size_t) … … 54 101 ImageBufferData::ImageBufferData(const IntSize&) 55 102 : m_data(0) 56 { 57 } 58 59 ImageBuffer::ImageBuffer(const IntSize& size, ColorSpace imageColorSpace, bool& success) 103 #if defined(USE_IOSURFACE) 104 , m_surface(0) 105 #endif 106 { 107 } 108 109 ImageBuffer::ImageBuffer(const IntSize& size, ColorSpace imageColorSpace, bool accelerateRendering, bool& success) 60 110 : m_data(size) 61 111 , m_size(size) 112 , m_accelerateRendering(accelerateRendering) 62 113 { 63 114 success = false; // Make early return mean failure. … … 66 117 67 118 unsigned bytesPerRow = size.width(); 68 69 // Protect against overflow 70 if (bytesPerRow > 0x3FFFFFFF) 119 if (bytesPerRow > 0x3FFFFFFF) // Protect against overflow 71 120 return; 72 121 bytesPerRow *= 4; 73 122 m_data.m_bytesPerRow = bytesPerRow; 74 75 123 size_t dataSize = size.height() * bytesPerRow; 76 if (!tryFastCalloc(size.height(), bytesPerRow).getValue(m_data.m_data)) 77 return; 78 79 ASSERT((reinterpret_cast<size_t>(m_data.m_data) & 2) == 0); 80 81 switch(imageColorSpace) { 124 125 switch (imageColorSpace) { 82 126 case ColorSpaceDeviceRGB: 83 127 m_data.m_colorSpace = deviceRGBColorSpaceRef(); … … 91 135 } 92 136 93 m_data.m_bitmapInfo = kCGImageAlphaPremultipliedLast; 94 RetainPtr<CGContextRef> cgContext(AdoptCF, CGBitmapContextCreate(m_data.m_data, size.width(), size.height(), 8, bytesPerRow, 95 m_data.m_colorSpace, m_data.m_bitmapInfo)); 137 RetainPtr<CGContextRef> cgContext; 138 if (!m_accelerateRendering) { 139 if (!tryFastCalloc(size.height(), bytesPerRow).getValue(m_data.m_data)) 140 return; 141 ASSERT(!(reinterpret_cast<size_t>(m_data.m_data) & 2)); 142 143 m_data.m_bitmapInfo = kCGImageAlphaPremultipliedLast; 144 cgContext.adoptCF(CGBitmapContextCreate(m_data.m_data, size.width(), size.height(), 8, bytesPerRow, m_data.m_colorSpace, m_data.m_bitmapInfo)); 145 // Create a live image that wraps the data. 146 m_data.m_dataProvider.adoptCF(CGDataProviderCreateWithData(0, m_data.m_data, dataSize, releaseImageData)); 147 } else { 148 #if defined(USE_IOSURFACE) 149 m_data.m_surface = createIOSurface(size); 150 cgContext.adoptCF(wkIOSurfaceContextCreate(m_data.m_surface.get(), size.width(), size.height(), m_data.m_colorSpace)); 151 #else 152 m_accelerateRendering = false; // Force to false on older platforms 153 #endif 154 } 155 96 156 if (!cgContext) 97 157 return; … … 101 161 m_context->translate(0, -size.height()); 102 162 success = true; 103 104 // Create a live image that wraps the data.105 m_data.m_dataProvider.adoptCF(CGDataProviderCreateWithData(0, m_data.m_data, dataSize, releaseImageData));106 163 } 107 164 … … 123 180 { 124 181 // BitmapImage will release the passed in CGImage on destruction 125 return BitmapImage::create(CGBitmapContextCreateImage(context()->platformContext())); 182 CGImageRef ctxImage = 0; 183 if (!m_accelerateRendering) 184 ctxImage = CGBitmapContextCreateImage(context()->platformContext()); 185 #if defined(USE_IOSURFACE) 186 else 187 ctxImage = wkIOSurfaceContextCreateImage(context()->platformContext()); 188 #endif 189 return BitmapImage::create(ctxImage); 126 190 } 127 191 … … 135 199 CompositeOperator op, bool useLowQualityScale) 136 200 { 137 if (destContext == context()) { 138 // We're drawing into our own buffer. In order for this to work, we need to copy the source buffer first. 201 if (!m_accelerateRendering) { 202 if (destContext == context()) { 203 // We're drawing into our own buffer. In order for this to work, we need to copy the source buffer first. 204 RefPtr<Image> copy = copyImage(); 205 destContext->drawImage(copy.get(), ColorSpaceDeviceRGB, destRect, srcRect, op, useLowQualityScale); 206 } else { 207 RefPtr<Image> imageForRendering = BitmapImage::create(cgImage(m_size, m_data)); 208 destContext->drawImage(imageForRendering.get(), styleColorSpace, destRect, srcRect, op, useLowQualityScale); 209 } 210 } else { 139 211 RefPtr<Image> copy = copyImage(); 140 destContext->drawImage(copy.get(), ColorSpaceDeviceRGB, destRect, srcRect, op, useLowQualityScale); 141 } else { 142 RefPtr<Image> imageForRendering = BitmapImage::create(cgImage(m_size, m_data)); 143 destContext->drawImage(imageForRendering.get(), styleColorSpace, destRect, srcRect, op, useLowQualityScale); 212 ColorSpace colorSpace = (destContext == context()) ? ColorSpaceDeviceRGB : styleColorSpace; 213 destContext->drawImage(copy.get(), colorSpace, destRect, srcRect, op, useLowQualityScale); 144 214 } 145 215 } … … 148 218 const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator op, const FloatRect& destRect) 149 219 { 150 if (destContext == context()) { 151 // We're drawing into our own buffer. In order for this to work, we need to copy the source buffer first. 220 if (!m_accelerateRendering) { 221 if (destContext == context()) { 222 // We're drawing into our own buffer. In order for this to work, we need to copy the source buffer first. 223 RefPtr<Image> copy = copyImage(); 224 copy->drawPattern(destContext, srcRect, patternTransform, phase, styleColorSpace, op, destRect); 225 } else { 226 RefPtr<Image> imageForRendering = BitmapImage::create(cgImage(m_size, m_data)); 227 imageForRendering->drawPattern(destContext, srcRect, patternTransform, phase, styleColorSpace, op, destRect); 228 } 229 } else { 152 230 RefPtr<Image> copy = copyImage(); 153 231 copy->drawPattern(destContext, srcRect, patternTransform, phase, styleColorSpace, op, destRect); 154 } else {155 RefPtr<Image> imageForRendering = BitmapImage::create(cgImage(m_size, m_data));156 imageForRendering->drawPattern(destContext, srcRect, patternTransform, phase, styleColorSpace, op, destRect);157 232 } 158 233 } … … 160 235 void ImageBuffer::clip(GraphicsContext* context, const FloatRect& rect) const 161 236 { 162 RetainPtr<CGImageRef> image(AdoptCF, cgImage(m_size, m_data));163 164 237 CGContextRef platformContext = context->platformContext(); 238 RetainPtr<CGImageRef> image; 239 if (!m_accelerateRendering) 240 image.adoptCF(cgImage(m_size, m_data)); 241 #if defined(USE_IOSURFACE) 242 else 243 image.adoptCF(wkIOSurfaceContextCreateImage(platformContext)); 244 #endif 165 245 CGContextTranslateCTM(platformContext, rect.x(), rect.y() + rect.height()); 166 246 CGContextScaleCTM(platformContext, 1, -1); … … 171 251 172 252 template <Multiply multiplied> 173 PassRefPtr<ImageData> getImageData(const IntRect& rect, const ImageBufferData& imageData, const IntSize& size )253 PassRefPtr<ImageData> getImageData(const IntRect& rect, const ImageBufferData& imageData, const IntSize& size, bool accelerateRendering) 174 254 { 175 255 PassRefPtr<ImageData> result = ImageData::create(rect.width(), rect.height()); … … 200 280 endy = size.height(); 201 281 int numRows = endy - originy; 202 203 unsigned srcBytesPerRow = 4 * size.width(); 282 204 283 unsigned destBytesPerRow = 4 * rect.width(); 205 206 // ::create ensures that all ImageBuffers have valid data, so we don't need to check it here.207 unsigned char* srcRows = reinterpret_cast<unsigned char*>(imageData.m_data) + originy * srcBytesPerRow + originx * 4;208 284 unsigned char* destRows = data + desty * destBytesPerRow + destx * 4; 209 for (int y = 0; y < numRows; ++y) { 210 for (int x = 0; x < numColumns; x++) { 211 int basex = x * 4; 212 unsigned char alpha = srcRows[basex + 3]; 213 if (multiplied == Unmultiplied && alpha) { 214 destRows[basex] = (srcRows[basex] * 255) / alpha; 215 destRows[basex + 1] = (srcRows[basex + 1] * 255) / alpha; 216 destRows[basex + 2] = (srcRows[basex + 2] * 255) / alpha; 217 destRows[basex + 3] = alpha; 218 } else 219 reinterpret_cast<uint32_t*>(destRows + basex)[0] = reinterpret_cast<uint32_t*>(srcRows + basex)[0]; 285 286 unsigned srcBytesPerRow; 287 unsigned char* srcRows; 288 289 if (!accelerateRendering) { 290 srcBytesPerRow = 4 * size.width(); 291 srcRows = reinterpret_cast<unsigned char*>(imageData.m_data) + originy * srcBytesPerRow + originx * 4; 292 293 for (int y = 0; y < numRows; ++y) { 294 for (int x = 0; x < numColumns; x++) { 295 int basex = x * 4; 296 unsigned char alpha = srcRows[basex + 3]; 297 if (multiplied == Unmultiplied && alpha) { 298 destRows[basex] = (srcRows[basex] * 255) / alpha; 299 destRows[basex + 1] = (srcRows[basex + 1] * 255) / alpha; 300 destRows[basex + 2] = (srcRows[basex + 2] * 255) / alpha; 301 destRows[basex + 3] = alpha; 302 } else 303 reinterpret_cast<uint32_t*>(destRows + basex)[0] = reinterpret_cast<uint32_t*>(srcRows + basex)[0]; 304 } 305 srcRows += srcBytesPerRow; 306 destRows += destBytesPerRow; 220 307 } 221 srcRows += srcBytesPerRow; 222 destRows += destBytesPerRow; 223 } 308 } else { 309 #if defined(USE_IOSURFACE) 310 IOSurfaceRef surface = imageData.m_surface.get(); 311 IOSurfaceLock(surface, kIOSurfaceLockReadOnly, 0); 312 srcBytesPerRow = IOSurfaceGetBytesPerRow(surface); 313 srcRows = (unsigned char*)(IOSurfaceGetBaseAddress(surface)) + originy * srcBytesPerRow + originx * 4; 314 315 for (int y = 0; y < numRows; ++y) { 316 for (int x = 0; x < numColumns; x++) { 317 int basex = x * 4; 318 unsigned char alpha = srcRows[basex + 3]; 319 if (multiplied == Unmultiplied && alpha) { 320 destRows[basex] = (srcRows[basex + 2] * 255) / alpha; 321 destRows[basex + 1] = (srcRows[basex + 1] * 255) / alpha; 322 destRows[basex + 2] = (srcRows[basex] * 255) / alpha; 323 destRows[basex + 3] = alpha; 324 } else { 325 destRows[basex] = srcRows[basex + 2]; 326 destRows[basex + 1] = srcRows[basex + 1]; 327 destRows[basex + 2] = srcRows[basex]; 328 destRows[basex + 3] = alpha; 329 } 330 } 331 srcRows += srcBytesPerRow; 332 destRows += destBytesPerRow; 333 } 334 IOSurfaceUnlock(surface, kIOSurfaceLockReadOnly, 0); 335 #else 336 ASSERT_NOT_REACHED(); 337 #endif 338 } 339 224 340 return result; 225 341 } … … 227 343 PassRefPtr<ImageData> ImageBuffer::getUnmultipliedImageData(const IntRect& rect) const 228 344 { 229 return getImageData<Unmultiplied>(rect, m_data, m_size); 345 if (m_accelerateRendering) 346 CGContextFlush(context()->platformContext()); 347 return getImageData<Unmultiplied>(rect, m_data, m_size, m_accelerateRendering); 230 348 } 231 349 232 350 PassRefPtr<ImageData> ImageBuffer::getPremultipliedImageData(const IntRect& rect) const 233 351 { 234 return getImageData<Premultiplied>(rect, m_data, m_size); 352 if (m_accelerateRendering) 353 CGContextFlush(context()->platformContext()); 354 return getImageData<Premultiplied>(rect, m_data, m_size, m_accelerateRendering); 235 355 } 236 356 237 357 template <Multiply multiplied> 238 void putImageData(ImageData*& source, const IntRect& sourceRect, const IntPoint& destPoint, ImageBufferData& imageData, const IntSize& size )358 void putImageData(ImageData*& source, const IntRect& sourceRect, const IntPoint& destPoint, ImageBufferData& imageData, const IntSize& size, bool accelerateRendering) 239 359 { 240 360 ASSERT(sourceRect.width() > 0); … … 265 385 266 386 unsigned srcBytesPerRow = 4 * source->width(); 267 unsigned destBytesPerRow = 4 * size.width();268 269 387 unsigned char* srcRows = source->data()->data()->data() + originy * srcBytesPerRow + originx * 4; 270 unsigned char* destRows = reinterpret_cast<unsigned char*>(imageData.m_data) + desty * destBytesPerRow + destx * 4; 271 for (int y = 0; y < numRows; ++y) { 272 for (int x = 0; x < numColumns; x++) { 273 int basex = x * 4; 274 unsigned char alpha = srcRows[basex + 3]; 275 if (multiplied == Unmultiplied && alpha != 255) { 276 destRows[basex] = (srcRows[basex] * alpha + 254) / 255; 277 destRows[basex + 1] = (srcRows[basex + 1] * alpha + 254) / 255; 278 destRows[basex + 2] = (srcRows[basex + 2] * alpha + 254) / 255; 279 destRows[basex + 3] = alpha; 280 } else 281 reinterpret_cast<uint32_t*>(destRows + basex)[0] = reinterpret_cast<uint32_t*>(srcRows + basex)[0]; 388 unsigned destBytesPerRow; 389 unsigned char* destRows; 390 391 if (!accelerateRendering) { 392 destBytesPerRow = 4 * size.width(); 393 destRows = reinterpret_cast<unsigned char*>(imageData.m_data) + desty * destBytesPerRow + destx * 4; 394 for (int y = 0; y < numRows; ++y) { 395 for (int x = 0; x < numColumns; x++) { 396 int basex = x * 4; 397 unsigned char alpha = srcRows[basex + 3]; 398 if (multiplied == Unmultiplied && alpha != 255) { 399 destRows[basex] = (srcRows[basex] * alpha + 254) / 255; 400 destRows[basex + 1] = (srcRows[basex + 1] * alpha + 254) / 255; 401 destRows[basex + 2] = (srcRows[basex + 2] * alpha + 254) / 255; 402 destRows[basex + 3] = alpha; 403 } else 404 reinterpret_cast<uint32_t*>(destRows + basex)[0] = reinterpret_cast<uint32_t*>(srcRows + basex)[0]; 405 } 406 destRows += destBytesPerRow; 407 srcRows += srcBytesPerRow; 282 408 } 283 destRows += destBytesPerRow; 284 srcRows += srcBytesPerRow; 409 } else { 410 #if defined(USE_IOSURFACE) 411 IOSurfaceRef surface = imageData.m_surface.get(); 412 IOSurfaceLock(surface, 0, 0); 413 destBytesPerRow = IOSurfaceGetBytesPerRow(surface); 414 destRows = (unsigned char*)(IOSurfaceGetBaseAddress(surface)) + desty * destBytesPerRow + destx * 4; 415 416 for (int y = 0; y < numRows; ++y) { 417 for (int x = 0; x < numColumns; x++) { 418 int basex = x * 4; 419 unsigned char alpha = srcRows[basex + 3]; 420 if (multiplied == Unmultiplied && alpha != 255) { 421 destRows[basex] = (srcRows[basex + 2] * alpha + 254) / 255; 422 destRows[basex + 1] = (srcRows[basex + 1] * alpha + 254) / 255; 423 destRows[basex + 2] = (srcRows[basex] * alpha + 254) / 255; 424 destRows[basex + 3] = alpha; 425 } else { 426 destRows[basex] = srcRows[basex + 2]; 427 destRows[basex + 1] = srcRows[basex + 1]; 428 destRows[basex + 2] = srcRows[basex]; 429 destRows[basex + 3] = alpha; 430 } 431 } 432 destRows += destBytesPerRow; 433 srcRows += srcBytesPerRow; 434 } 435 IOSurfaceUnlock(surface, 0, 0); 436 #else 437 ASSERT_NOT_REACHED(); 438 #endif 285 439 } 286 440 } … … 288 442 void ImageBuffer::putUnmultipliedImageData(ImageData* source, const IntRect& sourceRect, const IntPoint& destPoint) 289 443 { 290 putImageData<Unmultiplied>(source, sourceRect, destPoint, m_data, m_size); 444 if (m_accelerateRendering) 445 CGContextFlush(context()->platformContext()); 446 putImageData<Unmultiplied>(source, sourceRect, destPoint, m_data, m_size, m_accelerateRendering); 291 447 } 292 448 293 449 void ImageBuffer::putPremultipliedImageData(ImageData* source, const IntRect& sourceRect, const IntPoint& destPoint) 294 450 { 295 putImageData<Premultiplied>(source, sourceRect, destPoint, m_data, m_size); 451 if (m_accelerateRendering) 452 CGContextFlush(context()->platformContext()); 453 putImageData<Premultiplied>(source, sourceRect, destPoint, m_data, m_size, m_accelerateRendering); 296 454 } 297 455 … … 333 491 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); 334 492 335 RetainPtr<CGImageRef> image(AdoptCF, CGBitmapContextCreateImage(context()->platformContext())); 493 RetainPtr<CGImageRef> image; 494 if (!m_accelerateRendering) 495 image.adoptCF(CGBitmapContextCreateImage(context()->platformContext())); 496 #if defined(USE_IOSURFACE) 497 else 498 image.adoptCF(wkIOSurfaceContextCreateImage(context()->platformContext())); 499 #endif 500 336 501 if (!image) 337 502 return "data:,"; … … 365 530 return makeString("data:", mimeType, ";base64,", out); 366 531 } 367 368 532 } // namespace WebCore -
trunk/WebCore/platform/graphics/cg/ImageBufferData.h
r70143 r73925 31 31 #include <wtf/RetainPtr.h> 32 32 33 typedef struct __IOSurface *IOSurfaceRef; 33 34 typedef struct CGColorSpace *CGColorSpaceRef; 34 35 typedef struct CGDataProvider *CGDataProviderRef; … … 49 50 unsigned m_bytesPerRow; 50 51 CGColorSpaceRef m_colorSpace; 52 RetainPtr<IOSurfaceRef> m_surface; 51 53 }; 52 54 -
trunk/WebCore/platform/graphics/haiku/ImageBufferHaiku.cpp
r73853 r73925 67 67 } 68 68 69 ImageBuffer::ImageBuffer(const IntSize& size, ImageColorSpace imageColorSpace, bool & success)69 ImageBuffer::ImageBuffer(const IntSize& size, ImageColorSpace imageColorSpace, bool, bool& success) 70 70 : m_data(size) 71 71 , m_size(size) -
trunk/WebCore/platform/graphics/qt/ImageBufferQt.cpp
r70424 r73925 81 81 } 82 82 83 ImageBuffer::ImageBuffer(const IntSize& size, ColorSpace, bool & success)83 ImageBuffer::ImageBuffer(const IntSize& size, ColorSpace, bool, bool& success) 84 84 : m_data(size) 85 85 , m_size(size) -
trunk/WebCore/platform/graphics/skia/ImageBufferSkia.cpp
r73853 r73925 63 63 } 64 64 65 ImageBuffer::ImageBuffer(const IntSize& size, ColorSpace, bool & success)65 ImageBuffer::ImageBuffer(const IntSize& size, ColorSpace, bool, bool& success) 66 66 : m_data(size) 67 67 , m_size(size) -
trunk/WebCore/platform/graphics/wince/ImageBufferWinCE.cpp
r70397 r73925 73 73 } 74 74 75 ImageBuffer::ImageBuffer(const IntSize& size, ColorSpace colorSpace, bool & success)75 ImageBuffer::ImageBuffer(const IntSize& size, ColorSpace colorSpace, bool, bool& success) 76 76 : m_data(size) 77 77 , m_size(size) -
trunk/WebCore/platform/graphics/wx/ImageBufferWx.cpp
r73051 r73925 38 38 } 39 39 40 ImageBuffer::ImageBuffer(const IntSize&, ColorSpace imageColorSpace, bool & success) :40 ImageBuffer::ImageBuffer(const IntSize&, ColorSpace imageColorSpace, bool, bool& success) : 41 41 m_data(IntSize()) 42 42 { -
trunk/WebCore/platform/mac/WebCoreSystemInterface.h
r71590 r73925 29 29 #include <ApplicationServices/ApplicationServices.h> 30 30 #include <objc/objc.h> 31 32 #if PLATFORM(MAC) && PLATFORM(CA) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD) 33 #include <IOSurface/IOSurface.h> 34 #endif 31 35 32 36 typedef struct _NSRange NSRange; … … 180 184 #if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD) 181 185 extern CTTypesetterRef (*wkCreateCTTypesetterWithUniCharProviderAndOptions)(const UniChar* (*provide)(CFIndex stringIndex, CFIndex* charCount, CFDictionaryRef* attributes, void*), void (*dispose)(const UniChar* chars, void*), void*, CFDictionaryRef options); 186 187 extern CGContextRef (*wkIOSurfaceContextCreate)(IOSurfaceRef surface, unsigned width, unsigned height, CGColorSpaceRef colorSpace); 188 extern CGImageRef (*wkIOSurfaceContextCreateImage)(CGContextRef context); 182 189 #endif 183 190 -
trunk/WebCore/platform/mac/WebCoreSystemInterface.mm
r71590 r73925 123 123 #if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD) 124 124 CTTypesetterRef (*wkCreateCTTypesetterWithUniCharProviderAndOptions)(const UniChar* (*provide)(CFIndex stringIndex, CFIndex* charCount, CFDictionaryRef* attributes, void*), void (*dispose)(const UniChar* chars, void*), void*, CFDictionaryRef options); 125 126 CGContextRef (*wkIOSurfaceContextCreate)(IOSurfaceRef surface, unsigned width, unsigned height, CGColorSpaceRef colorSpace); 127 CGImageRef (*wkIOSurfaceContextCreateImage)(CGContextRef context); 125 128 #endif -
trunk/WebCore/rendering/RenderLayerBacking.cpp
r72954 r73925 768 768 return hasBoxDecorationsOrBackground(renderer()); 769 769 #endif 770 #if ENABLE(3D_CANVAS) || ENABLE(ACCELERATED_2D_CANVAS) 770 #if PLATFORM(MAC) && PLATFORM(CA) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD) 771 #elif ENABLE(3D_CANVAS) || ENABLE(ACCELERATED_2D_CANVAS) 771 772 if (isAcceleratedCanvas(renderer())) 772 773 return hasBoxDecorationsOrBackground(renderer()); -
trunk/WebCore/rendering/RenderLayerCompositor.cpp
r72954 r73925 298 298 299 299 layer->ensureBacking(); 300 301 #if PLATFORM(MAC) && PLATFORM(CA) 302 if (layer->renderer()->isCanvas()) { 303 HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(layer->renderer()->node()); 304 if (canvas->renderingContext() && canvas->renderingContext()->isAccelerated()) 305 layer->backing()->graphicsLayer()->setAcceleratesDrawing(true); 306 } 307 #endif 300 308 layerChanged = true; 301 309 } -
trunk/WebKit/mac/ChangeLog
r73886 r73925 1 2010-12-09 Matthew Delaney <mdelaney@apple.com> 2 3 Reviewed by Simon Fraser. 4 5 Adopt new CG API for canvas 6 https://bugs.webkit.org/show_bug.cgi?id=50591 7 8 * WebCoreSupport/WebSystemInterface.mm: 9 1 10 2010-10-28 MORITA Hajime <morrita@google.com> 2 11 -
trunk/WebKit/mac/WebCoreSupport/WebSystemInterface.mm
r71590 r73925 122 122 #if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD) 123 123 INIT(CreateCTTypesetterWithUniCharProviderAndOptions); 124 INIT(IOSurfaceContextCreate); 125 INIT(IOSurfaceContextCreateImage); 124 126 #endif 125 127
Note: See TracChangeset
for help on using the changeset viewer.