halcanary@google.com | ad04eb4 | 2013-11-21 15:32:08 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef SkImageGenerator_DEFINED |
| 9 | #define SkImageGenerator_DEFINED |
| 10 | |
| 11 | #include "SkImageInfo.h" |
| 12 | |
halcanary@google.com | edd370f | 2013-12-10 21:11:12 +0000 | [diff] [blame] | 13 | class SkBitmap; |
halcanary@google.com | ad04eb4 | 2013-11-21 15:32:08 +0000 | [diff] [blame] | 14 | class SkData; |
halcanary@google.com | edd370f | 2013-12-10 21:11:12 +0000 | [diff] [blame] | 15 | class SkImageGenerator; |
| 16 | |
| 17 | /** |
| 18 | * Takes ownership of SkImageGenerator. If this method fails for |
| 19 | * whatever reason, it will return false and immediatetely delete |
| 20 | * the generator. If it succeeds, it will modify destination |
| 21 | * bitmap. |
| 22 | * |
halcanary@google.com | 3d50ea1 | 2014-01-02 13:15:13 +0000 | [diff] [blame] | 23 | * If generator is NULL, will safely return false. |
| 24 | * |
halcanary@google.com | edd370f | 2013-12-10 21:11:12 +0000 | [diff] [blame] | 25 | * If this fails or when the SkDiscardablePixelRef that is |
| 26 | * installed into destination is destroyed, it will call |
| 27 | * SkDELETE() on the generator. Therefore, generator should be |
| 28 | * allocated with SkNEW() or SkNEW_ARGS(). |
| 29 | * |
| 30 | * @param destination Upon success, this bitmap will be |
| 31 | * configured and have a pixelref installed. |
| 32 | * |
halcanary@google.com | edd370f | 2013-12-10 21:11:12 +0000 | [diff] [blame] | 33 | * @return true iff successful. |
| 34 | */ |
commit-bot@chromium.org | 2d970b5 | 2014-05-27 14:14:22 +0000 | [diff] [blame] | 35 | SK_API bool SkInstallDiscardablePixelRef(SkImageGenerator*, SkBitmap* destination); |
halcanary@google.com | edd370f | 2013-12-10 21:11:12 +0000 | [diff] [blame] | 36 | |
halcanary@google.com | ad04eb4 | 2013-11-21 15:32:08 +0000 | [diff] [blame] | 37 | |
| 38 | /** |
| 39 | * An interface that allows a purgeable PixelRef (such as a |
| 40 | * SkDiscardablePixelRef) to decode and re-decode an image as needed. |
| 41 | */ |
halcanary@google.com | edd370f | 2013-12-10 21:11:12 +0000 | [diff] [blame] | 42 | class SK_API SkImageGenerator { |
halcanary@google.com | ad04eb4 | 2013-11-21 15:32:08 +0000 | [diff] [blame] | 43 | public: |
| 44 | /** |
| 45 | * The PixelRef which takes ownership of this SkImageGenerator |
| 46 | * will call the image generator's destructor. |
| 47 | */ |
| 48 | virtual ~SkImageGenerator() { } |
| 49 | |
| 50 | /** |
| 51 | * Return a ref to the encoded (i.e. compressed) representation, |
| 52 | * of this data. |
| 53 | * |
| 54 | * If non-NULL is returned, the caller is responsible for calling |
| 55 | * unref() on the data when it is finished. |
| 56 | */ |
commit-bot@chromium.org | 924205a | 2014-05-28 16:16:08 +0000 | [diff] [blame^] | 57 | virtual SkData* refEncodedData() { return NULL; } |
halcanary@google.com | ad04eb4 | 2013-11-21 15:32:08 +0000 | [diff] [blame] | 58 | |
| 59 | /** |
| 60 | * Return some information about the image, allowing the owner of |
| 61 | * this object to allocate pixels. |
| 62 | * |
commit-bot@chromium.org | dd59799 | 2013-12-02 22:32:54 +0000 | [diff] [blame] | 63 | * Repeated calls to this function should give the same results, |
| 64 | * allowing the PixelRef to be immutable. |
| 65 | * |
halcanary@google.com | ad04eb4 | 2013-11-21 15:32:08 +0000 | [diff] [blame] | 66 | * @return false if anything goes wrong. |
| 67 | */ |
commit-bot@chromium.org | 924205a | 2014-05-28 16:16:08 +0000 | [diff] [blame^] | 68 | virtual bool getInfo(SkImageInfo* info) = 0; |
halcanary@google.com | ad04eb4 | 2013-11-21 15:32:08 +0000 | [diff] [blame] | 69 | |
| 70 | /** |
| 71 | * Decode into the given pixels, a block of memory of size at |
| 72 | * least (info.fHeight - 1) * rowBytes + (info.fWidth * |
| 73 | * bytesPerPixel) |
| 74 | * |
commit-bot@chromium.org | dd59799 | 2013-12-02 22:32:54 +0000 | [diff] [blame] | 75 | * Repeated calls to this function should give the same results, |
| 76 | * allowing the PixelRef to be immutable. |
| 77 | * |
halcanary@google.com | ad04eb4 | 2013-11-21 15:32:08 +0000 | [diff] [blame] | 78 | * @param info A description of the format (config, size) |
| 79 | * expected by the caller. This can simply be identical |
| 80 | * to the info returned by getInfo(). |
| 81 | * |
| 82 | * This contract also allows the caller to specify |
| 83 | * different output-configs, which the implementation can |
| 84 | * decide to support or not. |
| 85 | * |
| 86 | * @return false if anything goes wrong or if the image info is |
| 87 | * unsupported. |
| 88 | */ |
commit-bot@chromium.org | 924205a | 2014-05-28 16:16:08 +0000 | [diff] [blame^] | 89 | virtual bool getPixels(const SkImageInfo& info, |
| 90 | void* pixels, |
| 91 | size_t rowBytes) = 0; |
halcanary@google.com | ad04eb4 | 2013-11-21 15:32:08 +0000 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | #endif // SkImageGenerator_DEFINED |