blob: f399ab538e9ea05d125ab1b21ec387640d69ffc3 [file] [log] [blame]
halcanary@google.comad04eb42013-11-21 15:32:08 +00001/*
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.comedd370f2013-12-10 21:11:12 +000013class SkBitmap;
halcanary@google.comad04eb42013-11-21 15:32:08 +000014class SkData;
halcanary@google.comedd370f2013-12-10 21:11:12 +000015class 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.com3d50ea12014-01-02 13:15:13 +000023 * If generator is NULL, will safely return false.
24 *
halcanary@google.comedd370f2013-12-10 21:11:12 +000025 * 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.comedd370f2013-12-10 21:11:12 +000033 * @return true iff successful.
34 */
commit-bot@chromium.org2d970b52014-05-27 14:14:22 +000035SK_API bool SkInstallDiscardablePixelRef(SkImageGenerator*, SkBitmap* destination);
halcanary@google.comedd370f2013-12-10 21:11:12 +000036
halcanary@google.comad04eb42013-11-21 15:32:08 +000037
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.comedd370f2013-12-10 21:11:12 +000042class SK_API SkImageGenerator {
halcanary@google.comad04eb42013-11-21 15:32:08 +000043public:
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.org924205a2014-05-28 16:16:08 +000057 virtual SkData* refEncodedData() { return NULL; }
halcanary@google.comad04eb42013-11-21 15:32:08 +000058
59 /**
60 * Return some information about the image, allowing the owner of
61 * this object to allocate pixels.
62 *
commit-bot@chromium.orgdd597992013-12-02 22:32:54 +000063 * Repeated calls to this function should give the same results,
64 * allowing the PixelRef to be immutable.
65 *
halcanary@google.comad04eb42013-11-21 15:32:08 +000066 * @return false if anything goes wrong.
67 */
commit-bot@chromium.org924205a2014-05-28 16:16:08 +000068 virtual bool getInfo(SkImageInfo* info) = 0;
halcanary@google.comad04eb42013-11-21 15:32:08 +000069
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.orgdd597992013-12-02 22:32:54 +000075 * Repeated calls to this function should give the same results,
76 * allowing the PixelRef to be immutable.
77 *
halcanary@google.comad04eb42013-11-21 15:32:08 +000078 * @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.org924205a2014-05-28 16:16:08 +000089 virtual bool getPixels(const SkImageInfo& info,
90 void* pixels,
91 size_t rowBytes) = 0;
halcanary@google.comad04eb42013-11-21 15:32:08 +000092};
93
94#endif // SkImageGenerator_DEFINED