| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkDecodingImageGenerator.h" | 8 #include "SkDecodingImageGenerator.h" |
| 9 | |
| 10 #include "SkBitmapFactory.h" | |
| 11 #include "SkData.h" | 9 #include "SkData.h" |
| 12 #include "SkDiscardablePixelRef.h" | 10 #include "SkDiscardablePixelRef.h" |
| 13 #include "SkImageDecoder.h" | 11 #include "SkImageDecoder.h" |
| 14 | 12 |
| 15 SkDecodingImageGenerator::SkDecodingImageGenerator(SkData* data) | 13 SkDecodingImageGenerator::SkDecodingImageGenerator(SkData* data) |
| 16 : fData(data) { | 14 : fData(data) { |
| 17 SkASSERT(fData != NULL); | 15 SkASSERT(fData != NULL); |
| 18 fData->ref(); | 16 fData->ref(); |
| 19 } | 17 } |
| 20 | 18 |
| 21 SkDecodingImageGenerator::~SkDecodingImageGenerator() { | 19 SkDecodingImageGenerator::~SkDecodingImageGenerator() { |
| 22 fData->unref(); | 20 fData->unref(); |
| 23 } | 21 } |
| 24 | 22 |
| 25 SkData* SkDecodingImageGenerator::refEncodedData() { | 23 SkData* SkDecodingImageGenerator::refEncodedData() { |
| 24 // This functionality is used in `gm --serialize` |
| 26 fData->ref(); | 25 fData->ref(); |
| 27 return fData; | 26 return fData; |
| 28 } | 27 } |
| 29 | 28 |
| 30 bool SkDecodingImageGenerator::getInfo(SkImageInfo* info) { | 29 bool SkDecodingImageGenerator::getInfo(SkImageInfo* info) { |
| 31 SkASSERT(info != NULL); | 30 SkASSERT(info != NULL); |
| 32 return SkImageDecoder::DecodeMemoryToTarget(fData->data(), | 31 return SkImageDecoder::DecodeMemoryToTarget(fData->data(), |
| 33 fData->size(), | 32 fData->size(), |
| 34 info, NULL); | 33 info, NULL); |
| 35 } | 34 } |
| 36 | 35 |
| 37 bool SkDecodingImageGenerator::getPixels(const SkImageInfo& info, | 36 bool SkDecodingImageGenerator::getPixels(const SkImageInfo& info, |
| 38 void* pixels, | 37 void* pixels, |
| 39 size_t rowBytes) { | 38 size_t rowBytes) { |
| 40 SkASSERT(pixels != NULL); | 39 SkASSERT(pixels != NULL); |
| 41 SkBitmapFactory::Target target = {pixels, rowBytes}; | 40 SkImageDecoder::Target target = {pixels, rowBytes}; |
| 42 SkImageInfo tmpInfo = info; | 41 SkImageInfo tmpInfo = info; |
| 43 return SkImageDecoder::DecodeMemoryToTarget(fData->data(), | 42 return SkImageDecoder::DecodeMemoryToTarget(fData->data(), |
| 44 fData->size(), | 43 fData->size(), |
| 45 &tmpInfo, &target); | 44 &tmpInfo, &target); |
| 46 } | 45 } |
| 47 bool SkDecodingImageGenerator::Install(SkData* data, SkBitmap* dst) { | 46 bool SkDecodingImageGenerator::Install(SkData* data, SkBitmap* dst, |
| 47 SkDiscardableMemory::Factory* factory) { |
| 48 SkASSERT(data != NULL); | 48 SkASSERT(data != NULL); |
| 49 SkASSERT(dst != NULL); | 49 SkASSERT(dst != NULL); |
| 50 SkImageGenerator* gen(SkNEW_ARGS(SkDecodingImageGenerator, (data))); | 50 SkImageGenerator* gen(SkNEW_ARGS(SkDecodingImageGenerator, (data))); |
| 51 return SkDiscardablePixelRef::Install(gen, dst); | 51 return SkDiscardablePixelRef::Install(gen, dst, factory); |
| 52 } | 52 } |
| OLD | NEW |