Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Unified Diff: Source/platform/graphics/DeferredImageDecoder.cpp

Issue 105773003: Teach Skia to use discardable memory (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: merged and discardable Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/platform/graphics/DeferredImageDecoder.h ('k') | Source/platform/graphics/ImageFrameGenerator.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/graphics/DeferredImageDecoder.cpp
diff --git a/Source/platform/graphics/DeferredImageDecoder.cpp b/Source/platform/graphics/DeferredImageDecoder.cpp
index 795ade041e30a4c8ec8f75eb7a9d4580cd97d5d1..17567e564e6fb6b0a40842c866dacb7bd4bd4cca 100644
--- a/Source/platform/graphics/DeferredImageDecoder.cpp
+++ b/Source/platform/graphics/DeferredImageDecoder.cpp
@@ -26,8 +26,9 @@
#include "config.h"
#include "platform/graphics/DeferredImageDecoder.h"
+#include "platform/graphics/DecodingImageGenerator.h"
#include "platform/graphics/LazyDecodingPixelRef.h"
-
+#include "third_party/skia/include/core/SkImageInfo.h"
#include "wtf/PassOwnPtr.h"
namespace WebCore {
@@ -37,9 +38,13 @@ namespace {
// URI label for a lazily decoded SkPixelRef.
const char labelLazyDecoded[] = "lazy";
+// URI label for SkDiscardablePixelRef.
+const char labelDiscardable[] = "discardable";
+
} // namespace
bool DeferredImageDecoder::s_enabled = false;
+bool DeferredImageDecoder::s_skiaDiscardableMemoryEnabled = false;
reveman 2013/12/12 16:57:11 Can we just make this true if !defined(OS_ANDROID)
DeferredImageDecoder::DeferredImageDecoder(PassOwnPtr<ImageDecoder> actualDecoder)
: m_allDataReceived(false)
@@ -68,7 +73,8 @@ bool DeferredImageDecoder::isLazyDecoded(const SkBitmap& bitmap)
{
return bitmap.pixelRef()
&& bitmap.pixelRef()->getURI()
- && !memcmp(bitmap.pixelRef()->getURI(), labelLazyDecoded, sizeof(labelLazyDecoded));
+ && (!memcmp(bitmap.pixelRef()->getURI(), labelLazyDecoded, sizeof(labelLazyDecoded))
+ || !memcmp(bitmap.pixelRef()->getURI(), labelDiscardable, sizeof(labelDiscardable)));
}
void DeferredImageDecoder::setEnabled(bool enabled)
@@ -76,6 +82,11 @@ void DeferredImageDecoder::setEnabled(bool enabled)
s_enabled = enabled;
}
+void DeferredImageDecoder::setSkiaDiscardableMemoryEnabled(bool enabled)
+{
+ s_skiaDiscardableMemoryEnabled = enabled;
+}
+
String DeferredImageDecoder::filenameExtension() const
{
return m_actualDecoder ? m_actualDecoder->filenameExtension() : m_filenameExtension;
@@ -208,7 +219,7 @@ void DeferredImageDecoder::prepareLazyDecodedFrames()
m_lazyDecodedFrames.resize(m_actualDecoder->frameCount());
for (size_t i = previousSize; i < m_lazyDecodedFrames.size(); ++i) {
OwnPtr<ImageFrame> frame(adoptPtr(new ImageFrame()));
- frame->setSkBitmap(createLazyDecodingBitmap(i));
+ frame->setSkBitmap(createBitmap(i));
frame->setDuration(m_actualDecoder->frameDurationAtIndex(i));
frame->setStatus(m_actualDecoder->frameIsCompleteAtIndex(i) ? ImageFrame::FrameComplete : ImageFrame::FramePartial);
m_lazyDecodedFrames[i] = frame.release();
@@ -226,6 +237,36 @@ void DeferredImageDecoder::prepareLazyDecodedFrames()
}
}
+// Creates either a SkBitmap backed by SkDiscardablePixelRef or a SkBitmap using the
+// legacy LazyDecodingPixelRef.
+SkBitmap DeferredImageDecoder::createBitmap(size_t index)
+{
+ // This code is temporary until the transition to SkDiscardablePixelRef is complete.
+ if (s_skiaDiscardableMemoryEnabled)
+ return createSkiaDiscardableBitmap(index);
+ return createLazyDecodingBitmap(index);
+}
+
+// Creates a SkBitmap that is backed by SkDiscardablePixelRef.
+SkBitmap DeferredImageDecoder::createSkiaDiscardableBitmap(size_t index)
+{
+ IntSize decodedSize = m_actualDecoder->decodedSize();
+ ASSERT(decodedSize.width() > 0);
+ ASSERT(decodedSize.height() > 0);
+
+ SkImageInfo info;
+ info.fWidth = decodedSize.width();
+ info.fHeight = decodedSize.height();
+ info.fColorType = kBGRA_8888_SkColorType;
+ info.fAlphaType = frameHasAlphaAtIndex(index) ? kPremul_SkAlphaType : kOpaque_SkAlphaType;
+
+ SkBitmap bitmap;
+ bool installed = SkInstallDiscardablePixelRef(new DecodingImageGenerator(m_frameGenerator, info, index), &bitmap);
+ ASSERT_UNUSED(installed, installed);
+ bitmap.pixelRef()->setURI(labelDiscardable);
+ return bitmap;
+}
+
SkBitmap DeferredImageDecoder::createLazyDecodingBitmap(size_t index)
{
IntSize decodedSize = m_actualDecoder->decodedSize();
« no previous file with comments | « Source/platform/graphics/DeferredImageDecoder.h ('k') | Source/platform/graphics/ImageFrameGenerator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698