| 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 #ifndef SkLazyCachingPixelRef_DEFINED | 8 #ifndef SkLazyCachingPixelRef_DEFINED |
| 9 #define SkLazyCachingPixelRef_DEFINED | 9 #define SkLazyCachingPixelRef_DEFINED |
| 10 | 10 |
| 11 #include "SkBitmapFactory.h" | |
| 12 #include "SkCachingPixelRef.h" | 11 #include "SkCachingPixelRef.h" |
| 12 #include "SkImageDecoder.h" |
| 13 | 13 |
| 14 class SkData; | 14 class SkData; |
| 15 | 15 |
| 16 /** | 16 /** |
| 17 * PixelRef which defers decoding until SkBitmap::lockPixels() is | 17 * PixelRef which defers decoding until SkBitmap::lockPixels() is |
| 18 * called. Makes use of a supplied decode procedure. Will decode at | 18 * called. Makes use of a supplied decode procedure. Will decode at |
| 19 * the procedure's preferred size. | 19 * the procedure's preferred size. |
| 20 */ | 20 */ |
| 21 class SkLazyCachingPixelRef : public SkCachingPixelRef { | 21 class SkLazyCachingPixelRef : public SkCachingPixelRef { |
| 22 public: | 22 public: |
| 23 typedef bool (*DecodeProc)(const void* data, |
| 24 size_t length, |
| 25 SkImageInfo*, |
| 26 const SkImageDecoder::Target*); |
| 23 /** | 27 /** |
| 24 * @param data Encoded data representing the pixels. NULL is | 28 * @param data Encoded data representing the pixels. NULL is |
| 25 * equivalent to an empty data, and will be passed to | 29 * equivalent to an empty data, and will be passed to |
| 26 * DecodeProc with length zero. | 30 * DecodeProc with length zero. |
| 27 * | 31 * |
| 28 * @param procedure Called to decode the pixels when | 32 * @param procedure Called to decode the pixels when |
| 29 * needed. If NULL, use SkImageDecoder::DecodeMemoryToTarget. | 33 * needed. If NULL, use SkImageDecoder::DecodeMemoryToTarget. |
| 30 */ | 34 */ |
| 31 SkLazyCachingPixelRef(SkData* data, | 35 SkLazyCachingPixelRef(SkData* data, DecodeProc procedure); |
| 32 SkBitmapFactory::DecodeProc procedure); | |
| 33 | 36 |
| 34 virtual ~SkLazyCachingPixelRef(); | 37 virtual ~SkLazyCachingPixelRef(); |
| 35 | 38 |
| 36 virtual SkData* onRefEncodedData() SK_OVERRIDE { return SkSafeRef(fData); } | 39 virtual SkData* onRefEncodedData() SK_OVERRIDE { return SkSafeRef(fData); } |
| 37 | 40 |
| 38 /** | 41 /** |
| 39 * A simplified version of SkBitmapFactory. Installs a new | 42 * A simplified version of SkBitmapFactory. Installs a new |
| 40 * SkLazyCachingPixelRef into the provided bitmap. Will | 43 * SkLazyCachingPixelRef into the provided bitmap. Will |
| 41 * immediately call onDecodeInfo() to configure the bitmap, but | 44 * immediately call onDecodeInfo() to configure the bitmap, but |
| 42 * will defer decoding until the first time the bitmap's pixels | 45 * will defer decoding until the first time the bitmap's pixels |
| 43 * are locked. | 46 * are locked. |
| 44 * | 47 * |
| 45 * @param data Encoded data representing the pixels. NULL is | 48 * @param data Encoded data representing the pixels. NULL is |
| 46 * equivalent to an empty data, and will be passed to | 49 * equivalent to an empty data, and will be passed to |
| 47 * DecodeProc with length zero. | 50 * DecodeProc with length zero. |
| 48 * | 51 * |
| 49 * @param procedure Called to decode the pixels when | 52 * @param procedure Called to decode the pixels when |
| 50 * needed. If NULL, use SkImageDecoder::DecodeMemoryToTarget. | 53 * needed. If NULL, use SkImageDecoder::DecodeMemoryToTarget. |
| 51 * | 54 * |
| 52 * @param destination Bitmap that will be modified on success. | 55 * @param destination Bitmap that will be modified on success. |
| 53 * | 56 * |
| 54 * @returns true on success. | 57 * @returns true on success. |
| 55 */ | 58 */ |
| 56 static bool Install(SkBitmapFactory::DecodeProc procedure, | 59 static bool Install(DecodeProc procedure, |
| 57 SkData* data, | 60 SkData* data, |
| 58 SkBitmap* destination); | 61 SkBitmap* destination); |
| 59 | 62 |
| 60 // No need to flatten this object. When flattening an SkBitmap, | 63 // No need to flatten this object. When flattening an SkBitmap, |
| 61 // SkOrderedWriteBuffer will check the encoded data and write that | 64 // SkOrderedWriteBuffer will check the encoded data and write that |
| 62 // instead. | 65 // instead. |
| 63 // Future implementations of SkFlattenableWriteBuffer will need to | 66 // Future implementations of SkFlattenableWriteBuffer will need to |
| 64 // special case for onRefEncodedData as well. | 67 // special case for onRefEncodedData as well. |
| 65 SK_DECLARE_UNFLATTENABLE_OBJECT() | 68 SK_DECLARE_UNFLATTENABLE_OBJECT() |
| 66 | 69 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 82 * that the caller knows what its asking for (config, | 85 * that the caller knows what its asking for (config, |
| 83 * size). | 86 * size). |
| 84 * | 87 * |
| 85 * @return false if anything goes wrong. | 88 * @return false if anything goes wrong. |
| 86 */ | 89 */ |
| 87 virtual bool onDecodePixels(const SkImageInfo& info, | 90 virtual bool onDecodePixels(const SkImageInfo& info, |
| 88 void* pixels, | 91 void* pixels, |
| 89 size_t rowBytes) SK_OVERRIDE; | 92 size_t rowBytes) SK_OVERRIDE; |
| 90 | 93 |
| 91 private: | 94 private: |
| 92 SkData* fData; | 95 SkData* fData; |
| 93 SkBitmapFactory::DecodeProc fDecodeProc; | 96 DecodeProc fDecodeProc; |
| 94 | 97 |
| 95 typedef SkCachingPixelRef INHERITED; | 98 typedef SkCachingPixelRef INHERITED; |
| 96 }; | 99 }; |
| 97 | 100 |
| 98 #endif // SkLazyCachingPixelRef_DEFINED | 101 #endif // SkLazyCachingPixelRef_DEFINED |
| OLD | NEW |