| 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 "include/core/SkData.h" |
| 12 |
#include "include/core/SkImageInfo.h" |
| 13 |
#include "include/core/SkPixmap.h" |
| 14 |
#include "include/core/SkRefCnt.h" |
| 15 |
#include "include/core/SkYUVAPixmaps.h" |
| 16 |
#include "include/private/base/SkAPI.h" |
| 17 |
|
| 18 |
#include <cstddef> |
| 19 |
#include <cstdint> |
| 20 |
|
| 21 |
class SkRecorder; |
| 22 |
|
| 23 |
class SK_API SkImageGenerator { |
| 24 |
public: |
| 25 |
/** |
| 26 |
* The PixelRef which takes ownership of this SkImageGenerator |
| 27 |
* will call the image generator's destructor. |
| 28 |
*/ |
| 29 |
virtual ~SkImageGenerator() { } |
| 30 |
|
| 31 |
uint32_t uniqueID() const { return fUniqueID; } |
| 32 |
|
| 33 |
/** |
| 34 |
* Return a ref to the encoded (i.e. compressed) representation |
| 35 |
* of this data. |
| 36 |
* |
| 37 |
* If non-NULL is returned, the caller is responsible for calling |
| 38 |
* unref() on the data when it is finished. |
| 39 |
*/ |
| 40 |
sk_sp<const SkData> refEncodedData() { return this->onRefEncodedData(); } |
| 41 |
|
| 42 |
/** |
| 43 |
* Return the ImageInfo associated with this generator. |
| 44 |
*/ |
| 45 |
const SkImageInfo& getInfo() const { return fInfo; } |
| 46 |
|
| 47 |
/** |
| 48 |
* Can this generator be used to produce images that will be drawable to the specified context |
| 49 |
* (or to CPU, if context is nullptr)? |
| 50 |
*/ |
| 51 |
bool isValid(SkRecorder* recorder) const { return this->onIsValid(recorder); } |
| 52 |
|
| 53 |
/** |
| 54 |
* Will this generator produce protected content |
| 55 |
*/ |
| 56 |
bool isProtected() const { |
| 57 |
return this->onIsProtected(); |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* Decode into the given pixels, a block of memory of size at |
| 62 |
* least (info.fHeight - 1) * rowBytes + (info.fWidth * |
| 63 |
* bytesPerPixel) |
| 64 |
* |
| 65 |
* Repeated calls to this function should give the same results, |
| 66 |
* allowing the PixelRef to be immutable. |
| 67 |
* |
| 68 |
* @param info A description of the format |
| 69 |
* expected by the caller. This can simply be identical |
| 70 |
* to the info returned by getInfo(). |
| 71 |
* |
| 72 |
* This contract also allows the caller to specify |
| 73 |
* different output-configs, which the implementation can |
| 74 |
* decide to support or not. |
| 75 |
* |
| 76 |
* A size that does not match getInfo() implies a request |
| 77 |
* to scale. If the generator cannot perform this scale, |
| 78 |
* it will return false. |
| 79 |
* |
| 80 |
* @return true on success. |
| 81 |
*/ |
| 82 |
bool getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes); |
| 83 |
|
| 84 |
bool getPixels(const SkPixmap& pm) { |
| 85 |
return this->getPixels(pm.info(), pm.writable_addr(), pm.rowBytes()); |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* If decoding to YUV is supported, this returns true. Otherwise, this |
| 90 |
* returns false and the caller will ignore output parameter yuvaPixmapInfo. |
| 91 |
* |
| 92 |
* @param supportedDataTypes Indicates the data type/planar config combinations that are |
| 93 |
* supported by the caller. If the generator supports decoding to |
| 94 |
* YUV(A), but not as a type in supportedDataTypes, this method |
| 95 |
* returns false. |
| 96 |
* @param yuvaPixmapInfo Output parameter that specifies the planar configuration, subsampling, |
| 97 |
* orientation, chroma siting, plane color types, and row bytes. |
| 98 |
*/ |
| 99 |
bool queryYUVAInfo(const SkYUVAPixmapInfo::SupportedDataTypes& supportedDataTypes, |
| 100 |
SkYUVAPixmapInfo* yuvaPixmapInfo) const; |
| 101 |
|
| 102 |
/** |
| 103 |
* Returns true on success and false on failure. |
| 104 |
* This always attempts to perform a full decode. To get the planar |
| 105 |
* configuration without decoding use queryYUVAInfo(). |
| 106 |
* |
| 107 |
* @param yuvaPixmaps Contains preallocated pixmaps configured according to a successful call |
| 108 |
* to queryYUVAInfo(). |
| 109 |
*/ |
| 110 |
bool getYUVAPlanes(const SkYUVAPixmaps& yuvaPixmaps); |
| 111 |
|
| 112 |
virtual bool isTextureGenerator() const { return false; } |
| 113 |
|
| 114 |
protected: |
| 115 |
static constexpr int kNeedNewImageUniqueID = 0; |
| 116 |
|
| 117 |
SkImageGenerator(const SkImageInfo& info, uint32_t uniqueId = kNeedNewImageUniqueID); |
| 118 |
|
| 119 |
virtual sk_sp<const SkData> onRefEncodedData() { return nullptr; } |
| 120 |
|
| 121 |
struct Options {}; |
| 122 |
virtual bool onGetPixels(const SkImageInfo&, void*, size_t, const Options&) { return false; } |
| 123 |
virtual bool onIsValid(SkRecorder*) const { return true; } |
| 124 |
virtual bool onIsProtected() const { return false; } |
| 125 |
virtual bool onQueryYUVAInfo(const SkYUVAPixmapInfo::SupportedDataTypes&, |
| 126 |
SkYUVAPixmapInfo*) const { return false; } |
| 127 |
virtual bool onGetYUVAPlanes(const SkYUVAPixmaps&) { return false; } |
| 128 |
|
| 129 |
const SkImageInfo fInfo; |
| 130 |
|
| 131 |
private: |
| 132 |
const uint32_t fUniqueID; |
| 133 |
|
| 134 |
SkImageGenerator(SkImageGenerator&&) = delete; |
| 135 |
SkImageGenerator(const SkImageGenerator&) = delete; |
| 136 |
SkImageGenerator& operator=(SkImageGenerator&&) = delete; |
| 137 |
SkImageGenerator& operator=(const SkImageGenerator&) = delete; |
| 138 |
}; |
| 139 |
|
| 140 |
#endif // SkImageGenerator_DEFINED |