Skia
2D Graphics Library
SkImageGenerator.h
Go to the documentation of this file.
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/SkBitmap.h"
12 #include "include/core/SkColor.h"
13 #include "include/core/SkImage.h"
16 
17 class GrRecordingContext;
18 class GrSurfaceProxyView;
19 class GrSamplerState;
20 class SkBitmap;
21 class SkData;
22 class SkMatrix;
23 class SkPaint;
24 class SkPicture;
25 
26 enum class GrImageTexGenPolicy : int;
27 
29 public:
34  virtual ~SkImageGenerator() { }
35 
36  uint32_t uniqueID() const { return fUniqueID; }
37 
46  return this->onRefEncodedData();
47  }
48 
52  const SkImageInfo& getInfo() const { return fInfo; }
53 
58  bool isValid(GrRecordingContext* context) const {
59  return this->onIsValid(context);
60  }
61 
84  bool getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes);
85 
86  bool getPixels(const SkPixmap& pm) {
87  return this->getPixels(pm.info(), pm.writable_addr(), pm.rowBytes());
88  }
89 
101  bool queryYUVAInfo(const SkYUVAPixmapInfo::SupportedDataTypes& supportedDataTypes,
102  SkYUVAPixmapInfo* yuvaPixmapInfo) const;
103 
112  bool getYUVAPlanes(const SkYUVAPixmaps& yuvaPixmaps);
113 
114 #if SK_SUPPORT_GPU
115 
146  GrSurfaceProxyView generateTexture(GrRecordingContext*, const SkImageInfo& info,
147  const SkIPoint& origin, GrMipmapped, GrImageTexGenPolicy);
148 
149 #endif
150 
156  static std::unique_ptr<SkImageGenerator> MakeFromEncoded(sk_sp<SkData>);
157 
163  static std::unique_ptr<SkImageGenerator> MakeFromPicture(const SkISize&, sk_sp<SkPicture>,
164  const SkMatrix*, const SkPaint*,
167 
168 protected:
169  static constexpr int kNeedNewImageUniqueID = 0;
170 
171  SkImageGenerator(const SkImageInfo& info, uint32_t uniqueId = kNeedNewImageUniqueID);
172 
173  virtual sk_sp<SkData> onRefEncodedData() { return nullptr; }
174  struct Options {};
175  virtual bool onGetPixels(const SkImageInfo&, void*, size_t, const Options&) { return false; }
176  virtual bool onIsValid(GrRecordingContext*) const { return true; }
178  SkYUVAPixmapInfo*) const { return false; }
179  virtual bool onGetYUVAPlanes(const SkYUVAPixmaps&) { return false; }
180 #if SK_SUPPORT_GPU
181  // returns nullptr
182  virtual GrSurfaceProxyView onGenerateTexture(GrRecordingContext*, const SkImageInfo&,
183  const SkIPoint&, GrMipmapped, GrImageTexGenPolicy);
184 #endif
185 
186 private:
187  const SkImageInfo fInfo;
188  const uint32_t fUniqueID;
189 
190  friend class SkImage_Lazy;
191 
192  // This is our default impl, which may be different on different platforms.
193  // It is called from NewFromEncoded() after it has checked for any runtime factory.
194  // The SkData will never be NULL, as that will have been checked by NewFromEncoded.
195  static std::unique_ptr<SkImageGenerator> MakeFromEncodedImpl(sk_sp<SkData>);
196 
198  SkImageGenerator(const SkImageGenerator&) = delete;
199  SkImageGenerator& operator=(SkImageGenerator&&) = delete;
200  SkImageGenerator& operator=(const SkImageGenerator&) = delete;
201 };
202 
203 #endif // SkImageGenerator_DEFINED
SkImageGenerator::onGetPixels
virtual bool onGetPixels(const SkImageInfo &, void *, size_t, const Options &)
Definition: SkImageGenerator.h:175
SkImageGenerator::refEncodedData
sk_sp< SkData > refEncodedData()
Return a ref to the encoded (i.e.
Definition: SkImageGenerator.h:45
GrRecordingContext
Definition: GrRecordingContext.h:35
SkImageGenerator::onQueryYUVAInfo
virtual bool onQueryYUVAInfo(const SkYUVAPixmapInfo::SupportedDataTypes &, SkYUVAPixmapInfo *) const
Definition: SkImageGenerator.h:177
SkYUVAPixmaps
Helper to store SkPixmap planes as described by a SkYUVAPixmapInfo.
Definition: SkYUVAPixmaps.h:171
SkImageGenerator
Definition: SkImageGenerator.h:28
SkImageGenerator::isValid
bool isValid(GrRecordingContext *context) const
Can this generator be used to produce images that will be drawable to the specified context (or to CP...
Definition: SkImageGenerator.h:58
SkImageGenerator::onGetYUVAPlanes
virtual bool onGetYUVAPlanes(const SkYUVAPixmaps &)
Definition: SkImageGenerator.h:179
SkImageGenerator::getPixels
bool getPixels(const SkPixmap &pm)
Definition: SkImageGenerator.h:86
SkPixmap::writable_addr
void * writable_addr() const
Returns writable base pixel address.
Definition: SkPixmap.h:455
SkImageGenerator::onIsValid
virtual bool onIsValid(GrRecordingContext *) const
Definition: SkImageGenerator.h:176
SkBitmap.h
SkData
SkData holds an immutable data buffer.
Definition: SkData.h:22
SkImageGenerator::uniqueID
uint32_t uniqueID() const
Definition: SkImageGenerator.h:36
SkYUVAPixmaps.h
SkYUVAPixmapInfo::SupportedDataTypes
Definition: SkYUVAPixmaps.h:47
GrMipmapped
GrMipmapped
Used to say whether a texture has mip levels allocated or not.
Definition: GrTypes.h:169
sk_sp< SkData >
SkPixmap::rowBytes
size_t rowBytes() const
Returns row bytes, the interval from one pixel row to the next.
Definition: SkPixmap.h:136
SkPaint
Definition: SkPaint.h:39
SkYUVAPixmapInfo
SkYUVAInfo combined with per-plane SkColorTypes and row bytes.
Definition: SkYUVAPixmaps.h:26
SK_API
#define SK_API
Definition: SkTypes.h:181
SkImageGenerator::Options
Definition: SkImageGenerator.h:174
SkImage::BitDepth
BitDepth
Definition: SkImage.h:421
SkImageInfo
Definition: SkImageInfo.h:283
SkImageGenerator::MakeFromPicture
static std::unique_ptr< SkImageGenerator > MakeFromPicture(const SkISize &, sk_sp< SkPicture >, const SkMatrix *, const SkPaint *, SkImage::BitDepth, sk_sp< SkColorSpace >)
Return a new image generator backed by the specified picture.
SkISize
Definition: SkSize.h:13
SkPicture
Definition: SkPicture.h:39
SkImageGenerator::~SkImageGenerator
virtual ~SkImageGenerator()
The PixelRef which takes ownership of this SkImageGenerator will call the image generator's destructo...
Definition: SkImageGenerator.h:34
SkImageGenerator::getInfo
const SkImageInfo & getInfo() const
Return the ImageInfo associated with this generator.
Definition: SkImageGenerator.h:52
SkImageGenerator::onRefEncodedData
virtual sk_sp< SkData > onRefEncodedData()
Definition: SkImageGenerator.h:173
SkImage.h
SkPixmap
Definition: SkPixmap.h:31
SkMatrix
Definition: SkMatrix.h:48
SkPixmap::info
const SkImageInfo & info() const
Returns width, height, SkAlphaType, SkColorType, and SkColorSpace.
Definition: SkPixmap.h:126
SkImageGenerator::SkImageGenerator
SkImageGenerator(const SkImageInfo &info, uint32_t uniqueId=kNeedNewImageUniqueID)
SkImageGenerator::getYUVAPlanes
bool getYUVAPlanes(const SkYUVAPixmaps &yuvaPixmaps)
Returns true on success and false on failure.
SkImageGenerator::queryYUVAInfo
bool queryYUVAInfo(const SkYUVAPixmapInfo::SupportedDataTypes &supportedDataTypes, SkYUVAPixmapInfo *yuvaPixmapInfo) const
If decoding to YUV is supported, this returns true.
SkImageGenerator::getPixels
bool getPixels(const SkImageInfo &info, void *pixels, size_t rowBytes)
Decode into the given pixels, a block of memory of size at least (info.fHeight - 1) * rowBytes + (inf...
SkIPoint
Definition: SkPoint.h:25
SkColor.h
SkImageInfo.h
SkBitmap
Definition: SkBitmap.h:50
SkImageGenerator::MakeFromEncoded
static std::unique_ptr< SkImageGenerator > MakeFromEncoded(sk_sp< SkData >)
If the default image decoder system can interpret the specified (encoded) data, then this returns a n...