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/SkData.h"
13 #include "include/core/SkPixmap.h"
14 #include "include/core/SkRefCnt.h"
16 #include "include/private/base/SkAPI.h"
17 
18 #if defined(SK_GRAPHITE)
19 #include "include/core/SkImage.h"
20 #include "include/gpu/graphite/Recorder.h"
21 #endif
22 
23 #include <cstddef>
24 #include <cstdint>
25 
26 class GrRecordingContext;
27 
28 class SK_API SkImageGenerator {
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 
65  bool isProtected() const {
66  return this->onIsProtected();
67  }
68 
91  bool getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes);
92 
93  bool getPixels(const SkPixmap& pm) {
94  return this->getPixels(pm.info(), pm.writable_addr(), pm.rowBytes());
95  }
96 
108  bool queryYUVAInfo(const SkYUVAPixmapInfo::SupportedDataTypes& supportedDataTypes,
109  SkYUVAPixmapInfo* yuvaPixmapInfo) const;
110 
119  bool getYUVAPlanes(const SkYUVAPixmaps& yuvaPixmaps);
120 
121  virtual bool isTextureGenerator() const { return false; }
122 
123 protected:
124  static constexpr int kNeedNewImageUniqueID = 0;
125 
126  SkImageGenerator(const SkImageInfo& info, uint32_t uniqueId = kNeedNewImageUniqueID);
127 
128  virtual sk_sp<SkData> onRefEncodedData() { return nullptr; }
129  struct Options {};
130  virtual bool onGetPixels(const SkImageInfo&, void*, size_t, const Options&) { return false; }
131  virtual bool onIsValid(GrRecordingContext*) const { return true; }
132  virtual bool onIsProtected() const { return false; }
134  SkYUVAPixmapInfo*) const { return false; }
135  virtual bool onGetYUVAPlanes(const SkYUVAPixmaps&) { return false; }
136 
138 
139 private:
140  const uint32_t fUniqueID;
141 
143  SkImageGenerator(const SkImageGenerator&) = delete;
144  SkImageGenerator& operator=(SkImageGenerator&&) = delete;
145  SkImageGenerator& operator=(const SkImageGenerator&) = delete;
146 };
147 
148 #endif // SkImageGenerator_DEFINED
Definition: GrRecordingContext.h:42
Definition: SkImageGenerator.h:28
virtual sk_sp< SkData > onRefEncodedData()
Definition: SkImageGenerator.h:128
virtual bool isTextureGenerator() const
Definition: SkImageGenerator.h:121
bool getYUVAPlanes(const SkYUVAPixmaps &yuvaPixmaps)
Returns true on success and false on failure.
SkImageGenerator(const SkImageInfo &info, uint32_t uniqueId=kNeedNewImageUniqueID)
virtual bool onIsValid(GrRecordingContext *) const
Definition: SkImageGenerator.h:131
const SkImageInfo & getInfo() const
Return the ImageInfo associated with this generator.
Definition: SkImageGenerator.h:52
bool queryYUVAInfo(const SkYUVAPixmapInfo::SupportedDataTypes &supportedDataTypes, SkYUVAPixmapInfo *yuvaPixmapInfo) const
If decoding to YUV is supported, this returns true.
virtual bool onGetYUVAPlanes(const SkYUVAPixmaps &)
Definition: SkImageGenerator.h:135
virtual ~SkImageGenerator()
The PixelRef which takes ownership of this SkImageGenerator will call the image generator's destructo...
Definition: SkImageGenerator.h:34
virtual bool onQueryYUVAInfo(const SkYUVAPixmapInfo::SupportedDataTypes &, SkYUVAPixmapInfo *) const
Definition: SkImageGenerator.h:133
virtual bool onGetPixels(const SkImageInfo &, void *, size_t, const Options &)
Definition: SkImageGenerator.h:130
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
sk_sp< SkData > refEncodedData()
Return a ref to the encoded (i.e.
Definition: SkImageGenerator.h:45
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...
bool getPixels(const SkPixmap &pm)
Definition: SkImageGenerator.h:93
const SkImageInfo fInfo
Definition: SkImageGenerator.h:137
virtual bool onIsProtected() const
Definition: SkImageGenerator.h:132
bool isProtected() const
Will this generator produce protected content.
Definition: SkImageGenerator.h:65
uint32_t uniqueID() const
Definition: SkImageGenerator.h:36
SkPixmap provides a utility to pair SkImageInfo with pixels and row bytes.
Definition: SkPixmap.h:40
size_t rowBytes() const
Returns row bytes, the interval from one pixel row to the next.
Definition: SkPixmap.h:145
void * writable_addr() const
Returns writable base pixel address.
Definition: SkPixmap.h:483
const SkImageInfo & info() const
Returns width, height, SkAlphaType, SkColorType, and SkColorSpace.
Definition: SkPixmap.h:135
Definition: SkYUVAPixmaps.h:51
SkYUVAInfo combined with per-plane SkColorTypes and row bytes.
Definition: SkYUVAPixmaps.h:30
Helper to store SkPixmap planes as described by a SkYUVAPixmapInfo.
Definition: SkYUVAPixmaps.h:172
Definition: SkImageGenerator.h:129
Describes pixel dimensions and encoding.
Definition: SkImageInfo.h:194