skia2/tools/LazyDecodeBitmap.cpp
kjlubick 1de415f2c3 Revert of Make SkPicture/SkImageGenerator default to SkCodec (patchset #7 id:120001 of https://codereview.chromium.org/1671193002/ )
Reason for revert:
Breaks Ubuntu and Mac CMAKE

Original issue's description:
> Make SkPicture/SkImageGenerator default to SkCodec
>
> Remove reference to SkImageDecoder from SkPicture. Make the default
> InstallPixelRefProc passed to CreateFromStream use
> SkImageGenerator::NewFromEncoded instead.
>
> Make SkImageGenerator::NewFromEncoded create an SkCodecImageGenerator.
> Remove the old version that used SkImageDecoder.
>
> Remove all versions of lazy_decode_bitmap/LazyDecodeBitmap. The default
> now behaves lazily.
>
> Update all clients to use the default.
>
> Move SkImageDecoderGenerator into KtxTest.cpp, and use it directly.
>
> BUG=skia:4691
> BUG=skia:4290
> GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1671193002
>
> Committed: https://skia.googlesource.com/skia/+/026388a01864c74208ad57d1ba4f711602d101c6

TBR=msarett@google.com,reed@google.com,scroggo@google.com
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:4691

Review URL: https://codereview.chromium.org/1685963004
2016-02-10 11:25:07 -08:00

45 lines
1.5 KiB
C++

/*
* Copyright 2013 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "LazyDecodeBitmap.h"
#include "SkData.h"
#include "SkDiscardableMemoryPool.h"
#include "SkImageGeneratorPriv.h"
#include "SkForceLinking.h"
#include "SkCommandLineFlags.h"
__SK_FORCE_IMAGE_DECODER_LINKING;
DEFINE_bool(useVolatileCache, false, "Use a volatile cache for deferred image decoding pixels. "
"Only meaningful if --deferImageDecoding is set to true and the platform has an "
"implementation.");
// Fits SkPicture::InstallPixelRefProc call signature.
// Used in SkPictureData::CreateFromStream
bool sk_tools::LazyDecodeBitmap(const void* src, size_t length, SkBitmap* dst) {
SkAutoDataUnref data(SkData::NewWithCopy(src, length));
if (nullptr == data.get()) {
return false;
}
SkAutoTDelete<SkImageGenerator> gen(SkImageGenerator::NewFromEncoded(data));
if (nullptr == gen.get()) {
return false;
}
const SkImageInfo info = gen->getInfo();
SkDiscardableMemory::Factory* pool = nullptr;
if ((!FLAGS_useVolatileCache) || (info.width() * info.height() < 32 * 1024)) {
// how to do switching with SkDiscardableMemory.
pool = SkGetGlobalDiscardableMemoryPool();
// Only meaningful if platform has a default discardable
// memory implementation that differs from the global DM pool.
}
return SkDEPRECATED_InstallDiscardablePixelRef(gen.detach(), nullptr, dst, pool);
}