Title: [199071] trunk/Source/WebCore
- Revision
- 199071
- Author
- commit-qu...@webkit.org
- Date
- 2016-04-05 13:24:01 -0700 (Tue, 05 Apr 2016)
Log Message
Avoid context save/restore in GraphicsContext::drawNativeImage
https://bugs.webkit.org/show_bug.cgi?id=156173
Patch by Said Abou-Hallawa <sabouhall...@apple.com> on 2016-04-05
Reviewed by Simon Fraser.
CG save/restore is a costly operation. Try to avoid it, if possible, in
GraphicsContext::drawNativeImage. If no clipping is involved, don't save/
save/restore the GraphicsContext.
* platform/graphics/cg/GraphicsContextCG.cpp:
(WebCore::GraphicsContext::drawNativeImage):
* platform/graphics/cg/GraphicsContextCG.h:
(WebCore::CGContextStateSaver::didSave):
* platform/spi/cg/CoreGraphicsSPI.h:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (199070 => 199071)
--- trunk/Source/WebCore/ChangeLog 2016-04-05 20:05:02 UTC (rev 199070)
+++ trunk/Source/WebCore/ChangeLog 2016-04-05 20:24:01 UTC (rev 199071)
@@ -1,3 +1,20 @@
+2016-04-05 Said Abou-Hallawa <sabouhall...@apple.com>
+
+ Avoid context save/restore in GraphicsContext::drawNativeImage
+ https://bugs.webkit.org/show_bug.cgi?id=156173
+
+ Reviewed by Simon Fraser.
+
+ CG save/restore is a costly operation. Try to avoid it, if possible, in
+ GraphicsContext::drawNativeImage. If no clipping is involved, don't save/
+ save/restore the GraphicsContext.
+
+ * platform/graphics/cg/GraphicsContextCG.cpp:
+ (WebCore::GraphicsContext::drawNativeImage):
+ * platform/graphics/cg/GraphicsContextCG.h:
+ (WebCore::CGContextStateSaver::didSave):
+ * platform/spi/cg/CoreGraphicsSPI.h:
+
2016-04-05 Simon Fraser <simon.fra...@apple.com>
Add a "notifyutil" callback for dumping the RenderLayer tree, and move the registration to Page code
Modified: trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp (199070 => 199071)
--- trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp 2016-04-05 20:05:02 UTC (rev 199070)
+++ trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp 2016-04-05 20:24:01 UTC (rev 199071)
@@ -179,13 +179,9 @@
return;
CGContextRef context = platformContext();
- CGContextStateSaver stateSaver(context);
-
-#if PLATFORM(IOS)
- // Anti-aliasing is on by default on the iPhone. Need to turn it off when drawing images.
- CGContextSetShouldAntialias(context, false);
-#endif
-
+ CGAffineTransform transform = CGContextGetCTM(context);
+ CGContextStateSaver stateSaver(context, false);
+
bool shouldUseSubimage = false;
// If the source rect is a subportion of the image, then we compute an inflated destination rect that will hold the entire image
@@ -229,8 +225,10 @@
adjustedDestRect.setSize(FloatSize(imageSize.width() / xScale, imageSize.height() / yScale));
}
- if (!destRect.contains(adjustedDestRect))
+ if (!destRect.contains(adjustedDestRect)) {
+ stateSaver.save();
CGContextClipToRect(context, destRect);
+ }
}
// If the image is only partially loaded, then shrink the destination rect that we're drawing into accordingly.
@@ -238,6 +236,10 @@
adjustedDestRect.setHeight(adjustedDestRect.height() * currHeight / imageSize.height());
#if PLATFORM(IOS)
+ bool wasAntialiased = CGContextGetShouldAntialias(context);
+ // Anti-aliasing is on by default on the iPhone. Need to turn it off when drawing images.
+ CGContextSetShouldAntialias(context, false);
+
// Align to pixel boundaries
adjustedDestRect = roundToDevicePixels(adjustedDestRect);
#endif
@@ -263,6 +265,13 @@
// Draw the image.
CGContextDrawImage(context, adjustedDestRect, subImage.get());
+
+ if (!stateSaver.didSave()) {
+ CGContextSetCTM(context, transform);
+#if PLATFORM(IOS)
+ CGContextSetShouldAntialias(context, wasAntialiased);
+#endif
+ }
}
static void drawPatternCallback(void* info, CGContextRef context)
Modified: trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.h (199070 => 199071)
--- trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.h 2016-04-05 20:05:02 UTC (rev 199070)
+++ trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.h 2016-04-05 20:24:01 UTC (rev 199071)
@@ -85,6 +85,11 @@
m_saveAndRestore = false;
}
+ bool didSave() const
+ {
+ return m_saveAndRestore;
+ }
+
private:
CGContextRef m_context;
bool m_saveAndRestore;
Modified: trunk/Source/WebCore/platform/spi/cg/CoreGraphicsSPI.h (199070 => 199071)
--- trunk/Source/WebCore/platform/spi/cg/CoreGraphicsSPI.h 2016-04-05 20:05:02 UTC (rev 199070)
+++ trunk/Source/WebCore/platform/spi/cg/CoreGraphicsSPI.h 2016-04-05 20:24:01 UTC (rev 199071)
@@ -143,6 +143,7 @@
CGColorRef CGContextGetFillColorAsColor(CGContextRef);
CGFloat CGContextGetLineWidth(CGContextRef);
bool CGContextGetShouldSmoothFonts(CGContextRef);
+bool CGContextGetShouldAntialias(CGContextRef);
void CGContextSetBaseCTM(CGContextRef, CGAffineTransform);
void CGContextSetCTM(CGContextRef, CGAffineTransform);
void CGContextSetCompositeOperation(CGContextRef, CGCompositeOperation);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes