Commit 8031abcb authored by hclam@chromium.org's avatar hclam@chromium.org

Enable Skia discardable memory path on Android

With this change Android will stop using the old discardable memory path
and will use Skia's implementation of discardable memory and caching.

Tested on Android with ChromeShell.

BUG=169282

Review URL: https://codereview.chromium.org/303033004

git-svn-id: svn://svn.chromium.org/blink/trunk@175166 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent ff2c4137
...@@ -36,16 +36,12 @@ namespace WebCore { ...@@ -36,16 +36,12 @@ namespace WebCore {
namespace { namespace {
// URI label for a lazily decoded SkPixelRef.
const char labelLazyDecoded[] = "lazy";
// URI label for SkDiscardablePixelRef. // URI label for SkDiscardablePixelRef.
const char labelDiscardable[] = "discardable"; const char labelDiscardable[] = "discardable";
} // namespace } // namespace
bool DeferredImageDecoder::s_enabled = false; bool DeferredImageDecoder::s_enabled = false;
bool DeferredImageDecoder::s_skiaDiscardableMemoryEnabled = false;
DeferredImageDecoder::DeferredImageDecoder(PassOwnPtr<ImageDecoder> actualDecoder) DeferredImageDecoder::DeferredImageDecoder(PassOwnPtr<ImageDecoder> actualDecoder)
: m_allDataReceived(false) : m_allDataReceived(false)
...@@ -77,21 +73,14 @@ bool DeferredImageDecoder::isLazyDecoded(const SkBitmap& bitmap) ...@@ -77,21 +73,14 @@ bool DeferredImageDecoder::isLazyDecoded(const SkBitmap& bitmap)
{ {
return bitmap.pixelRef() return bitmap.pixelRef()
&& bitmap.pixelRef()->getURI() && bitmap.pixelRef()->getURI()
&& (!memcmp(bitmap.pixelRef()->getURI(), labelLazyDecoded, sizeof(labelLazyDecoded)) && !memcmp(bitmap.pixelRef()->getURI(), labelDiscardable, sizeof(labelDiscardable));
|| !memcmp(bitmap.pixelRef()->getURI(), labelDiscardable, sizeof(labelDiscardable)));
} }
void DeferredImageDecoder::setEnabled(bool enabled) void DeferredImageDecoder::setEnabled(bool enabled)
{ {
s_enabled = enabled; s_enabled = enabled;
#if !OS(ANDROID)
// FIXME: This code is temporary to enable discardable memory for
// non-Android platforms. In the future all platforms will be
// the same and we can remove this code.
s_skiaDiscardableMemoryEnabled = enabled;
if (enabled) if (enabled)
ImageDecodingStore::setImageCachingEnabled(false); ImageDecodingStore::setImageCachingEnabled(false);
#endif
} }
bool DeferredImageDecoder::enabled() bool DeferredImageDecoder::enabled()
...@@ -273,18 +262,8 @@ void DeferredImageDecoder::prepareLazyDecodedFrames() ...@@ -273,18 +262,8 @@ 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. // Creates a SkBitmap that is backed by SkDiscardablePixelRef.
SkBitmap DeferredImageDecoder::createSkiaDiscardableBitmap(size_t index) SkBitmap DeferredImageDecoder::createBitmap(size_t index)
{ {
IntSize decodedSize = m_actualDecoder->decodedSize(); IntSize decodedSize = m_actualDecoder->decodedSize();
ASSERT(decodedSize.width() > 0); ASSERT(decodedSize.width() > 0);
...@@ -293,7 +272,11 @@ SkBitmap DeferredImageDecoder::createSkiaDiscardableBitmap(size_t index) ...@@ -293,7 +272,11 @@ SkBitmap DeferredImageDecoder::createSkiaDiscardableBitmap(size_t index)
SkImageInfo info; SkImageInfo info;
info.fWidth = decodedSize.width(); info.fWidth = decodedSize.width();
info.fHeight = decodedSize.height(); info.fHeight = decodedSize.height();
#if SK_B32_SHIFT // Little-endian RGBA pixels. (Android)
info.fColorType = kRGBA_8888_SkColorType;
#else
info.fColorType = kBGRA_8888_SkColorType; info.fColorType = kBGRA_8888_SkColorType;
#endif
info.fAlphaType = kPremul_SkAlphaType; info.fAlphaType = kPremul_SkAlphaType;
SkBitmap bitmap; SkBitmap bitmap;
...@@ -305,34 +288,6 @@ SkBitmap DeferredImageDecoder::createSkiaDiscardableBitmap(size_t index) ...@@ -305,34 +288,6 @@ SkBitmap DeferredImageDecoder::createSkiaDiscardableBitmap(size_t index)
return bitmap; return bitmap;
} }
SkBitmap DeferredImageDecoder::createLazyDecodingBitmap(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 = kPMColor_SkColorType;
info.fAlphaType = kPremul_SkAlphaType;
// Creates a lazily decoded SkPixelRef that references the entire image without scaling.
SkBitmap bitmap;
bitmap.setConfig(info);
bitmap.setPixelRef(new LazyDecodingPixelRef(info, m_frameGenerator, index))->unref();
// Use the URI to identify this as a lazily decoded SkPixelRef of type LazyDecodingPixelRef.
// FIXME: It would be more useful to give the actual image URI.
bitmap.pixelRef()->setURI(labelLazyDecoded);
// Inform the bitmap that we will never change the pixels. This is a performance hint
// subsystems that may try to cache this bitmap (e.g. pictures, pipes, gpu, pdf, etc.)
bitmap.setImmutable();
return bitmap;
}
bool DeferredImageDecoder::hotSpot(IntPoint& hotSpot) const bool DeferredImageDecoder::hotSpot(IntPoint& hotSpot) const
{ {
// TODO: Implement. // TODO: Implement.
......
...@@ -81,8 +81,6 @@ private: ...@@ -81,8 +81,6 @@ private:
explicit DeferredImageDecoder(PassOwnPtr<ImageDecoder> actualDecoder); explicit DeferredImageDecoder(PassOwnPtr<ImageDecoder> actualDecoder);
void prepareLazyDecodedFrames(); void prepareLazyDecodedFrames();
SkBitmap createBitmap(size_t index); SkBitmap createBitmap(size_t index);
SkBitmap createSkiaDiscardableBitmap(size_t index);
SkBitmap createLazyDecodingBitmap(size_t index);
void activateLazyDecoding(); void activateLazyDecoding();
RefPtr<SharedBuffer> m_data; RefPtr<SharedBuffer> m_data;
...@@ -101,7 +99,6 @@ private: ...@@ -101,7 +99,6 @@ private:
RefPtr<ImageFrameGenerator> m_frameGenerator; RefPtr<ImageFrameGenerator> m_frameGenerator;
static bool s_enabled; static bool s_enabled;
static bool s_skiaDiscardableMemoryEnabled;
}; };
} // namespace WebCore } // namespace WebCore
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment