Add a WebCore logging channel for images
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 16 May 2016 21:36:15 +0000 (21:36 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 16 May 2016 21:36:15 +0000 (21:36 +0000)
https://bugs.webkit.org/show_bug.cgi?id=157752

Reviewed by Zalan Bujtas.

Create an Images log channel, and log various things related to decoding and drawing
images.

* platform/Logging.h:
* platform/graphics/BitmapImage.cpp:
(WebCore::BitmapImage::destroyDecodedDataIfNecessary):
(WebCore::BitmapImage::cacheFrame):
(WebCore::BitmapImage::startAnimation):
* platform/graphics/cg/GraphicsContextCG.cpp:
(WebCore::GraphicsContext::drawNativeImage):
* platform/graphics/cg/ImageDecoderCG.cpp:
(WebCore::ImageDecoder::createFrameImageAtIndex):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@200967 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/Logging.h
Source/WebCore/platform/graphics/BitmapImage.cpp
Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp
Source/WebCore/platform/graphics/cg/ImageDecoderCG.cpp

index 16b09fc..f32f03a 100644 (file)
@@ -1,3 +1,23 @@
+2016-05-16  Simon Fraser  <simon.fraser@apple.com>
+
+        Add a WebCore logging channel for images
+        https://bugs.webkit.org/show_bug.cgi?id=157752
+
+        Reviewed by Zalan Bujtas.
+
+        Create an Images log channel, and log various things related to decoding and drawing
+        images.
+
+        * platform/Logging.h:
+        * platform/graphics/BitmapImage.cpp:
+        (WebCore::BitmapImage::destroyDecodedDataIfNecessary):
+        (WebCore::BitmapImage::cacheFrame):
+        (WebCore::BitmapImage::startAnimation):
+        * platform/graphics/cg/GraphicsContextCG.cpp:
+        (WebCore::GraphicsContext::drawNativeImage):
+        * platform/graphics/cg/ImageDecoderCG.cpp:
+        (WebCore::ImageDecoder::createFrameImageAtIndex):
+
 2016-05-12  Ada Chan  <adachan@apple.com>
 
         Don't execute JavaScript within HTMLMediaElement::stop()
index 3859de1..8223ee5 100644 (file)
@@ -59,6 +59,7 @@ namespace WebCore {
     M(Gamepad) \
     M(History) \
     M(IconDatabase) \
+    M(Images) \
     M(IndexedDB) \
     M(Layout) \
     M(Loading) \
index 71526c3..77b321f 100644 (file)
@@ -32,6 +32,7 @@
 #include "ImageBuffer.h"
 #include "ImageObserver.h"
 #include "IntRect.h"
+#include "Logging.h"
 #include "MIMETypeRegistry.h"
 #include "TextStream.h"
 #include "Timer.h"
@@ -158,8 +159,10 @@ void BitmapImage::destroyDecodedDataIfNecessary(bool destroyAll)
     for (size_t i = 0; i < m_frames.size(); ++i)
         allFrameBytes += m_frames[i].m_frameBytes;
 
-    if (allFrameBytes > largeAnimationCutoff)
+    if (allFrameBytes > largeAnimationCutoff) {
+        LOG(Images, "BitmapImage %p destroyDecodedDataIfNecessary destryingData: allFrameBytes=%u cutoff=%u", this, allFrameBytes, largeAnimationCutoff);
         destroyDecodedData(destroyAll);
+    }
 }
 
 void BitmapImage::destroyMetadataAndNotify(unsigned frameBytesCleared, ClearedSource clearedSource)
@@ -206,6 +209,8 @@ void BitmapImage::cacheFrame(size_t index, SubsamplingLevel subsamplingLevel, Im
     m_frames[index].m_hasAlpha = m_source.frameHasAlphaAtIndex(index);
     m_frames[index].m_frameBytes = m_source.frameBytesAtIndex(index, subsamplingLevel);
 
+    LOG(Images, "BitmapImage %p cacheFrame %lu (%s%u bytes, complete %d)", this, index, frameCaching == CacheMetadataOnly ? "metadata only, " : "", m_frames[index].m_frameBytes, m_frames[index].m_isComplete);
+
     if (m_frames[index].m_image) {
         int deltaBytes = safeCast<int>(m_frames[index].m_frameBytes);
         m_decodedSize += deltaBytes;
@@ -549,6 +554,11 @@ void BitmapImage::startAnimation(CatchUpAnimation catchUpIfNecessary)
     // See if we've also passed the time for frames after that to start, in
     // case we need to skip some frames entirely. Remember not to advance
     // to an incomplete frame.
+
+#if !LOG_DISABLED
+    size_t startCatchupFrameIndex = nextFrame;
+#endif
+    
     for (size_t frameAfterNext = (nextFrame + 1) % frameCount(); frameIsCompleteAtIndex(frameAfterNext); frameAfterNext = (nextFrame + 1) % frameCount()) {
         // Should we skip the next frame?
         double frameAfterNextStartTime = m_desiredFrameStartTime + frameDurationAtIndex(nextFrame);
@@ -560,12 +570,15 @@ void BitmapImage::startAnimation(CatchUpAnimation catchUpIfNecessary)
         if (!internalAdvanceAnimation(SkippingFramesToCatchUp)) {
             m_animationFinishedWhenCatchingUp = true;
             startTimer(0);
+            LOG(Images, "BitmapImage %p startAnimation catching up from frame %lu, ended", this, startCatchupFrameIndex);
             return;
         }
         m_desiredFrameStartTime = frameAfterNextStartTime;
         nextFrame = frameAfterNext;
     }
 
+    LOG(Images, "BitmapImage %p startAnimation catching up jumped from from frame %lu to %d", this, startCatchupFrameIndex, (int)nextFrame - 1);
+
     // Draw the next frame as soon as possible. Note that m_desiredFrameStartTime
     // may be in the past, meaning the next time through this function we'll
     // kick off the next advancement sooner than this frame's duration would suggest.
index b599e34..9ecec52 100644 (file)
 #include "GraphicsContextPlatformPrivateCG.h"
 #include "ImageBuffer.h"
 #include "ImageOrientation.h"
+#include "Logging.h"
 #include "Path.h"
 #include "Pattern.h"
 #include "ShadowBlur.h"
 #include "SubimageCacheWithTimer.h"
+#include "TextStream.h"
 #include "Timer.h"
 #include "URL.h"
+#include <wtf/CurrentTime.h>
 #include <wtf/MathExtras.h>
 #include <wtf/RetainPtr.h>
 
@@ -172,6 +175,9 @@ void GraphicsContext::drawNativeImage(const RetainPtr<CGImageRef>& image, const
         return;
     }
 
+#if !LOG_DISABLED
+    double startTime = currentTime();
+#endif
     RetainPtr<CGImageRef> subImage(image);
 
     float currHeight = orientation.usesWidthAsHeight() ? CGImageGetWidth(subImage.get()) : CGImageGetHeight(subImage.get());
@@ -272,6 +278,8 @@ void GraphicsContext::drawNativeImage(const RetainPtr<CGImageRef>& image, const
         CGContextSetShouldAntialias(context, wasAntialiased);
 #endif
     }
+
+    LOG_WITH_STREAM(Images, stream << "GraphicsContext::drawNativeImage " << image.get() << " size " << imageSize << " into " << destRect << " took " << 1000.0 * (currentTime() - startTime) << "ms");
 }
 
 static void drawPatternCallback(void* info, CGContextRef context)
index 25259da..3d7774c 100644 (file)
@@ -31,6 +31,7 @@
 #include "ImageOrientation.h"
 #include "IntPoint.h"
 #include "IntSize.h"
+#include "Logging.h"
 #include "SharedBuffer.h"
 #include <wtf/NeverDestroyed.h>
 
@@ -339,6 +340,8 @@ unsigned ImageDecoder::frameBytesAtIndex(size_t index, SubsamplingLevel subsampl
 
 NativeImagePtr ImageDecoder::createFrameImageAtIndex(size_t index, SubsamplingLevel subsamplingLevel) const
 {
+    LOG(Images, "ImageDecoder %p createFrameImageAtIndex %lu", this, index);
+
     RetainPtr<CGImageRef> image = adoptCF(CGImageSourceCreateImageAtIndex(m_nativeDecoder.get(), index, imageSourceOptions(subsamplingLevel).get()));
     
 #if PLATFORM(IOS)