Changeset 170925 in webkit
- Timestamp:
- Jul 9, 2014 12:31:33 PM (10 years ago)
- Location:
- trunk/Source
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r170924 r170925 1 2014-07-09 Tim Horton <timothy_horton@apple.com> 2 3 Use IOSurface ViewSnapshots everywhere on Mac, remove JPEG encoding path 4 https://bugs.webkit.org/show_bug.cgi?id=134773 5 6 Reviewed by Anders Carlsson. 7 8 * WebCore.exp.in: 9 * platform/graphics/cocoa/IOSurface.h: 10 * platform/graphics/cocoa/IOSurface.mm: 11 (IOSurface::createFromImage): 12 Move make-an-IOSurface-from-a-CGImageRef into WebCore::IOSurface. 13 1 14 2014-07-09 Enrica Casucci <enrica@apple.com> 2 15 -
trunk/Source/WebCore/WebCore.exp.in
r170891 r170925 1480 1480 __ZN7WebCore9HTMLNames9titleAttrE 1481 1481 __ZN7WebCore9HTMLNames9valueAttrE 1482 __ZN7WebCore9IOSurface15createFromImageEP7CGImage 1482 1483 __ZN7WebCore9InlineBox14adjustPositionEff 1483 1484 __ZN7WebCore9InlineBox14dirtyLineBoxesEv -
trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.h
r169370 r170925 41 41 static PassRefPtr<IOSurface> createFromMachPort(mach_port_t, ColorSpace); 42 42 static PassRefPtr<IOSurface> createFromSurface(IOSurfaceRef, ColorSpace); 43 static PassRefPtr<IOSurface> createFromImage(CGImageRef); 43 44 44 45 static IntSize maximumSize(); -
trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.mm
r169370 r170925 71 71 } 72 72 73 PassRefPtr<IOSurface> IOSurface::createFromImage(CGImageRef image) 74 { 75 size_t width = CGImageGetWidth(image); 76 size_t height = CGImageGetHeight(image); 77 78 RefPtr<IOSurface> surface = IOSurface::create(IntSize(width, height), ColorSpaceDeviceRGB); 79 auto surfaceContext = surface->ensurePlatformContext(); 80 CGContextDrawImage(surfaceContext, CGRectMake(0, 0, width, height), image); 81 CGContextFlush(surfaceContext); 82 83 return surface.release(); 84 } 85 73 86 IOSurface::IOSurface(IntSize size, ColorSpace colorSpace) 74 87 : m_colorSpace(colorSpace) -
trunk/Source/WebKit2/ChangeLog
r170923 r170925 1 2014-07-09 Tim Horton <timothy_horton@apple.com> 2 3 Use IOSurface ViewSnapshots everywhere on Mac, remove JPEG encoding path 4 https://bugs.webkit.org/show_bug.cgi?id=134773 5 6 Reviewed by Anders Carlsson. 7 8 * UIProcess/API/mac/WKView.mm: 9 (-[WKView _takeViewSnapshot]): 10 * UIProcess/mac/ViewSnapshotStore.h: 11 * UIProcess/mac/ViewSnapshotStore.mm: 12 (WebKit::ViewSnapshotStore::ViewSnapshotStore): 13 (WebKit::ViewSnapshotStore::~ViewSnapshotStore): 14 (WebKit::ViewSnapshotStore::recordSnapshot): 15 (WebKit::ViewSnapshot::clearImage): 16 (WebKit::ViewSnapshot::asLayerContents): 17 (WebKit::createIOSurfaceFromImage): Deleted. 18 (WebKit::compressImageAsJPEG): Deleted. 19 (WebKit::ViewSnapshotStore::reduceSnapshotMemoryCost): Deleted. 20 (WebKit::ViewSnapshotStore::didCompressSnapshot): Deleted. 21 Remove all ViewSnapshot(Store) code related to JPEG-encoded snapshots. 22 Remove the "image" member on ViewSnapshot; Mac will always start out with an IOSurface instead. 23 Adopt WebCore::IOSurface::createFromImage to make that happen. 24 Add a comment noting that if a snapshot comes back empty, we should throw it away completely. 25 1 26 2014-07-09 Anders Carlsson <andersca@apple.com> 2 27 -
trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm
r170774 r170925 3142 3142 auto croppedSnapshotImage = adoptCF(CGImageCreateWithImageInRect(windowSnapshotImage.get(), NSRectToCGRect([window convertRectToBacking:croppedImageRect]))); 3143 3143 3144 snapshot.image = croppedSnapshotImage.get(); 3144 snapshot.surface = IOSurface::createFromImage(croppedSnapshotImage.get()); 3145 snapshot.surface->setIsVolatile(true); 3145 3146 3146 3147 IntSize imageSize(CGImageGetWidth(croppedSnapshotImage.get()), CGImageGetHeight(croppedSnapshotImage.get())); -
trunk/Source/WebKit2/UIProcess/mac/ViewSnapshotStore.h
r170335 r170925 38 38 OBJC_CLASS CAContext; 39 39 40 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090 41 #define USE_JPEG_VIEW_SNAPSHOTS false 40 #if PLATFORM(MAC) 42 41 #define USE_IOSURFACE_VIEW_SNAPSHOTS true 43 42 #define USE_RENDER_SERVER_VIEW_SNAPSHOTS false 44 #elif PLATFORM(MAC)45 // Mountain Lion and before do not support IOSurface purgeability.46 #define USE_JPEG_VIEW_SNAPSHOTS true47 #define USE_IOSURFACE_VIEW_SNAPSHOTS false48 #define USE_RENDER_SERVER_VIEW_SNAPSHOTS false49 43 #else 50 #define USE_JPEG_VIEW_SNAPSHOTS false51 44 #define USE_IOSURFACE_VIEW_SNAPSHOTS false 52 45 #define USE_RENDER_SERVER_VIEW_SNAPSHOTS true … … 59 52 60 53 struct ViewSnapshot { 61 #if USE_ JPEG_VIEW_SNAPSHOTS || USE_IOSURFACE_VIEW_SNAPSHOTS54 #if USE_IOSURFACE_VIEW_SNAPSHOTS 62 55 RefPtr<WebCore::IOSurface> surface; 63 RetainPtr<CGImageRef> image;64 56 #endif 65 57 #if USE_RENDER_SERVER_VIEW_SNAPSHOTS … … 102 94 void pruneSnapshots(WebPageProxy&); 103 95 void removeSnapshotImage(ViewSnapshot&); 104 void reduceSnapshotMemoryCost(const String& uuid);105 106 #if USE_JPEG_VIEW_SNAPSHOTS107 void didCompressSnapshot(const String& uuid, RetainPtr<CGImageRef> newImage, size_t newImageSize);108 dispatch_queue_t m_compressionQueue;109 #endif110 96 111 97 HashMap<String, ViewSnapshot> m_snapshotMap; -
trunk/Source/WebKit2/UIProcess/mac/ViewSnapshotStore.mm
r168689 r170925 41 41 #if USE_IOSURFACE_VIEW_SNAPSHOTS 42 42 static const size_t maximumSnapshotCacheSize = 400 * (1024 * 1024); 43 #elif USE_ JPEG_VIEW_SNAPSHOTS || USE_RENDER_SERVER_VIEW_SNAPSHOTS44 // Because non-IOSurfacesnapshots are not purgeable, we should keep fewer around.43 #elif USE_RENDER_SERVER_VIEW_SNAPSHOTS 44 // Because render server snapshots are not purgeable, we should keep fewer around. 45 45 static const size_t maximumSnapshotCacheSize = 50 * (1024 * 1024); 46 46 #endif … … 52 52 , m_snapshotCacheSize(0) 53 53 { 54 #if USE_JPEG_VIEW_SNAPSHOTS55 m_compressionQueue = dispatch_queue_create("com.apple.WebKit.ViewSnapshotStore.CompressionQueue", nullptr);56 #endif57 54 } 58 55 59 56 ViewSnapshotStore::~ViewSnapshotStore() 60 57 { 61 #if USE_JPEG_VIEW_SNAPSHOTS62 dispatch_release(m_compressionQueue);63 #endif64 58 discardSnapshots(); 65 59 } … … 186 180 m_snapshotMap.add(item->snapshotUUID(), snapshot); 187 181 m_snapshotCacheSize += snapshot.imageSizeInBytes; 188 189 reduceSnapshotMemoryCost(item->snapshotUUID());190 182 } 191 183 … … 208 200 } 209 201 210 #if USE_IOSURFACE_VIEW_SNAPSHOTS211 static RefPtr<IOSurface> createIOSurfaceFromImage(CGImageRef image)212 {213 size_t width = CGImageGetWidth(image);214 size_t height = CGImageGetHeight(image);215 216 RefPtr<IOSurface> surface = IOSurface::create(IntSize(width, height), ColorSpaceDeviceRGB);217 RetainPtr<CGContextRef> surfaceContext = surface->ensurePlatformContext();218 CGContextDrawImage(surfaceContext.get(), CGRectMake(0, 0, width, height), image);219 CGContextFlush(surfaceContext.get());220 221 surface->setIsVolatile(true);222 223 return surface;224 }225 #endif226 227 #if USE_JPEG_VIEW_SNAPSHOTS228 static std::pair<RetainPtr<CGImageRef>, size_t> compressImageAsJPEG(CGImageRef image)229 {230 RetainPtr<NSData> compressedData = adoptNS([[NSMutableData alloc] init]);231 RetainPtr<CGImageDestinationRef> destination = adoptCF(CGImageDestinationCreateWithData((CFMutableDataRef)compressedData.get(), kUTTypeJPEG, 1, 0));232 233 RetainPtr<NSDictionary> options = @{234 (NSString*)kCGImageDestinationLossyCompressionQuality: @0.9235 };236 237 CGImageDestinationAddImage(destination.get(), image, (CFDictionaryRef)options.get());238 CGImageDestinationFinalize(destination.get());239 240 RetainPtr<CGImageSourceRef> imageSourceRef = adoptCF(CGImageSourceCreateWithData((CFDataRef)compressedData.get(), 0));241 RetainPtr<CGImageRef> compressedSnapshot = adoptCF(CGImageSourceCreateImageAtIndex(imageSourceRef.get(), 0, 0));242 243 return std::make_pair(compressedSnapshot, [compressedData length]);244 }245 #endif246 247 void ViewSnapshotStore::reduceSnapshotMemoryCost(const String& uuid)248 {249 const auto& snapshotIterator = m_snapshotMap.find(uuid);250 if (snapshotIterator == m_snapshotMap.end())251 return;252 ViewSnapshot& snapshot = snapshotIterator->value;253 if (!snapshot.hasImage())254 return;255 256 #if USE_IOSURFACE_VIEW_SNAPSHOTS257 snapshot.surface = createIOSurfaceFromImage(snapshot.image.get());258 snapshot.image = nullptr;259 #elif USE_JPEG_VIEW_SNAPSHOTS260 RetainPtr<CGImageRef> originalImage = snapshot.image.get();261 dispatch_async(m_compressionQueue, [uuid, originalImage] {262 auto imageAndBytes = compressImageAsJPEG(originalImage.get());263 dispatch_async(dispatch_get_main_queue(), [uuid, imageAndBytes] {264 ViewSnapshotStore::shared().didCompressSnapshot(uuid, imageAndBytes.first, imageAndBytes.second);265 });266 });267 #endif268 }269 270 #if USE_JPEG_VIEW_SNAPSHOTS271 void ViewSnapshotStore::didCompressSnapshot(const String& uuid, RetainPtr<CGImageRef> newImage, size_t newImageSize)272 {273 const auto& snapshotIterator = m_snapshotMap.find(uuid);274 if (snapshotIterator == m_snapshotMap.end())275 return;276 ViewSnapshot& snapshot = snapshotIterator->value;277 278 size_t originalImageSize = snapshot.imageSizeInBytes;279 if (!newImage || newImageSize > originalImageSize)280 return;281 snapshot.image = newImage;282 snapshot.imageSizeInBytes = newImageSize;283 m_snapshotCacheSize += newImageSize;284 m_snapshotCacheSize -= originalImageSize;285 }286 #endif287 288 202 bool ViewSnapshot::hasImage() const 289 203 { … … 295 209 #if USE_IOSURFACE_VIEW_SNAPSHOTS 296 210 surface = nullptr; 297 #endif 298 #if USE_IOSURFACE_VIEW_SNAPSHOTS || USE_JPEG_VIEW_SNAPSHOTS 299 image = nullptr; 300 #endif 301 #if USE_RENDER_SERVER_VIEW_SNAPSHOTS 211 #elif USE_RENDER_SERVER_VIEW_SNAPSHOTS 302 212 if (slotID) 303 213 [ViewSnapshotStore::snapshottingContext() deleteSlot:slotID]; … … 310 220 { 311 221 #if USE_IOSURFACE_VIEW_SNAPSHOTS 312 if (surface) { 313 if (surface->setIsVolatile(false) != IOSurface::SurfaceState::Valid) 314 return nullptr; 315 316 return (id)surface->surface(); 317 } 318 #endif 319 #if USE_IOSURFACE_VIEW_SNAPSHOTS || USE_JPEG_VIEW_SNAPSHOTS 320 return (id)image.get(); 321 #endif 322 #if USE_RENDER_SERVER_VIEW_SNAPSHOTS 222 if (!surface) 223 return nullptr; 224 225 // FIXME: This should destroy the surface and inform the ViewSnapshotStore to reduce m_snapshotCacheSize. 226 if (surface->setIsVolatile(false) != IOSurface::SurfaceState::Valid) 227 return nullptr; 228 229 return (id)surface->surface(); 230 #elif USE_RENDER_SERVER_VIEW_SNAPSHOTS 323 231 return [CAContext objectForSlot:slotID]; 324 232 #endif
Note: See TracChangeset
for help on using the changeset viewer.