From ad04eb49f5d3f324e6b85411c776d7466c1fef92 Mon Sep 17 00:00:00 2001 From: "halcanary@google.com" Date: Thu, 21 Nov 2013 15:32:08 +0000 Subject: Add SkImageGenerator Interface - Add SkDiscardablePixelRef class that uses SkDiscardableMemory and a SkImageGenerator. - Add SkDecodingImageGenerator class as an example of a SkImageGenerator. - Add DecodingImageGenerator unit test. - Add SkBasicDiscardableMemory implmentation for unit tests only. R=reed@google.com, scroggo@google.com Review URL: https://codereview.chromium.org/74793011 git-svn-id: http://skia.googlecode.com/svn/trunk@12341 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/images/SkDecodingImageGenerator.cpp | 52 +++++++++++++++++++++++++++++++++ src/images/SkDecodingImageGenerator.h | 45 ++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 src/images/SkDecodingImageGenerator.cpp create mode 100644 src/images/SkDecodingImageGenerator.h (limited to 'src/images') diff --git a/src/images/SkDecodingImageGenerator.cpp b/src/images/SkDecodingImageGenerator.cpp new file mode 100644 index 0000000000..65fa6fd561 --- /dev/null +++ b/src/images/SkDecodingImageGenerator.cpp @@ -0,0 +1,52 @@ +/* + * 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 "SkDecodingImageGenerator.h" + +#include "SkBitmapFactory.h" +#include "SkData.h" +#include "SkDiscardablePixelRef.h" +#include "SkImageDecoder.h" + +SkDecodingImageGenerator::SkDecodingImageGenerator(SkData* data) + : fData(data) { + SkASSERT(fData != NULL); + fData->ref(); +} + +SkDecodingImageGenerator::~SkDecodingImageGenerator() { + fData->unref(); +} + +SkData* SkDecodingImageGenerator::refEncodedData() { + fData->ref(); + return fData; +} + +bool SkDecodingImageGenerator::getInfo(SkImageInfo* info) { + SkASSERT(info != NULL); + return SkImageDecoder::DecodeMemoryToTarget(fData->data(), + fData->size(), + info, NULL); +} + +bool SkDecodingImageGenerator::getPixels(const SkImageInfo& info, + void* pixels, + size_t rowBytes) { + SkASSERT(pixels != NULL); + SkBitmapFactory::Target target = {pixels, rowBytes}; + SkImageInfo tmpInfo = info; + return SkImageDecoder::DecodeMemoryToTarget(fData->data(), + fData->size(), + &tmpInfo, &target); +} +bool SkDecodingImageGenerator::Install(SkData* data, SkBitmap* dst) { + SkASSERT(data != NULL); + SkASSERT(dst != NULL); + SkImageGenerator* gen(SkNEW_ARGS(SkDecodingImageGenerator, (data))); + return SkDiscardablePixelRef::Install(gen, dst); +} diff --git a/src/images/SkDecodingImageGenerator.h b/src/images/SkDecodingImageGenerator.h new file mode 100644 index 0000000000..682aeb619c --- /dev/null +++ b/src/images/SkDecodingImageGenerator.h @@ -0,0 +1,45 @@ +/* + * Copyright 2013 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkDecodingImageGenerator_DEFINED +#define SkDecodingImageGenerator_DEFINED + +#include "SkImageGenerator.h" + +class SkBitmap; + +/** + * Calls into SkImageDecoder::DecodeMemoryToTarget to implement a + * SkImageGenerator + */ +class SkDecodingImageGenerator : public SkImageGenerator { +public: + /* + * The constructor will take a reference to the SkData. The + * destructor will unref() it. + */ + SkDecodingImageGenerator(SkData* data); + virtual ~SkDecodingImageGenerator(); + + virtual SkData* refEncodedData() SK_OVERRIDE; + + virtual bool getInfo(SkImageInfo* info) SK_OVERRIDE; + + virtual bool getPixels(const SkImageInfo& info, + void* pixels, + size_t rowBytes) SK_OVERRIDE; + + /** + * Install the SkData into the destination bitmap, using a new + * SkDiscardablePixelRef and a new SkDecodingImageGenerator. + */ + static bool Install(SkData* data, SkBitmap* destination); + +private: + SkData* fData; +}; +#endif // SkDecodingImageGenerator_DEFINED -- cgit v1.2.3