Skia
2DGraphicsLibrary
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SkImageGenerator.h
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 "SkBitmap.h"
12 #include "SkColor.h"
13 #include "SkImageInfo.h"
14 #include "SkYUVSizeInfo.h"
15 
16 class GrContext;
17 class GrTexture;
18 class GrTextureParams;
19 class SkBitmap;
20 class SkData;
21 class SkImageGenerator;
22 class SkMatrix;
23 class SkPaint;
24 class SkPicture;
25 
26 #ifdef SK_SUPPORT_LEGACY_REFENCODEDDATA_NOCTX
27  #define SK_REFENCODEDDATA_CTXPARAM
28 #else
29  #define SK_REFENCODEDDATA_CTXPARAM GrContext* ctx
30 #endif
31 
50 SK_API bool SkDEPRECATED_InstallDiscardablePixelRef(SkImageGenerator*, SkBitmap* destination);
51 
56 SK_API bool SkDEPRECATED_InstallDiscardablePixelRef(SkData* encoded, SkBitmap* destination);
57 
62 class SK_API SkImageGenerator : public SkNoncopyable {
63 public:
68  virtual ~SkImageGenerator() { }
69 
70  uint32_t uniqueID() const { return fUniqueID; }
71 
81  SkData* refEncodedData(GrContext* ctx = nullptr) {
82 #ifdef SK_SUPPORT_LEGACY_REFENCODEDDATA_NOCTX
83  return this->onRefEncodedData();
84 #else
85  return this->onRefEncodedData(ctx);
86 #endif
87  }
88 
92  const SkImageInfo& getInfo() const { return fInfo; }
93 
123  bool getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
124  SkPMColor ctable[], int* ctableCount);
125 
130  bool getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes);
131 
140  bool queryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const;
141 
152  bool getYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]);
153 
176  GrTexture* generateTexture(GrContext*, const SkIRect* subset = nullptr);
177 
178  struct SupportedSizes {
179  SkISize fSizes[2];
180  };
181 
191  bool computeScaledDimensions(SkScalar scale, SupportedSizes*);
192 
212  bool generateScaledPixels(const SkISize& scaledSize, const SkIPoint& subsetOrigin,
213  const SkPixmap& subsetPixels);
214 
215  bool generateScaledPixels(const SkPixmap& scaledPixels) {
216  return this->generateScaledPixels(SkISize::Make(scaledPixels.width(),
217  scaledPixels.height()),
218  SkIPoint::Make(0, 0), scaledPixels);
219  }
220 
226  static SkImageGenerator* NewFromEncoded(SkData*);
227 
233  static SkImageGenerator* NewFromPicture(const SkISize&, const SkPicture*, const SkMatrix*,
234  const SkPaint*);
235 
236  bool tryGenerateBitmap(SkBitmap* bm) {
237  return this->tryGenerateBitmap(bm, nullptr, nullptr);
238  }
239  bool tryGenerateBitmap(SkBitmap* bm, const SkImageInfo& info, SkBitmap::Allocator* allocator) {
240  return this->tryGenerateBitmap(bm, &info, allocator);
241  }
242  void generateBitmap(SkBitmap* bm) {
243  if (!this->tryGenerateBitmap(bm, nullptr, nullptr)) {
244  sk_throw();
245  }
246  }
247  void generateBitmap(SkBitmap* bm, const SkImageInfo& info) {
248  if (!this->tryGenerateBitmap(bm, &info, nullptr)) {
249  sk_throw();
250  }
251  }
252 
253 protected:
254  enum {
255  kNeedNewImageUniqueID = 0
256  };
257 
258  SkImageGenerator(const SkImageInfo& info, uint32_t uniqueId = kNeedNewImageUniqueID);
259 
260  virtual SkData* onRefEncodedData(SK_REFENCODEDDATA_CTXPARAM);
261 
262  virtual bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
263  SkPMColor ctable[], int* ctableCount);
264 
265  virtual bool onQueryYUV8(SkYUVSizeInfo*, SkYUVColorSpace*) const {
266  return false;
267  }
268  virtual bool onGetYUV8Planes(const SkYUVSizeInfo&, void*[3] /*planes*/) {
269  return false;
270  }
271 
272  virtual GrTexture* onGenerateTexture(GrContext*, const SkIRect*) {
273  return nullptr;
274  }
275 
276  virtual bool onComputeScaledDimensions(SkScalar, SupportedSizes*) {
277  return false;
278  }
279  virtual bool onGenerateScaledPixels(const SkISize&, const SkIPoint&, const SkPixmap&) {
280  return false;
281  }
282 
283  bool tryGenerateBitmap(SkBitmap* bm, const SkImageInfo* optionalInfo, SkBitmap::Allocator*);
284 
285 private:
286  const SkImageInfo fInfo;
287  const uint32_t fUniqueID;
288 
289  // This is our default impl, which may be different on different platforms.
290  // It is called from NewFromEncoded() after it has checked for any runtime factory.
291  // The SkData will never be NULL, as that will have been checked by NewFromEncoded.
292  static SkImageGenerator* NewFromEncodedImpl(SkData*);
293 };
294 
295 #endif // SkImageGenerator_DEFINED
Describe an image's dimensions and pixel type.
Definition: SkImageInfo.h:181
Definition: SkBitmap.h:703
SkData * refEncodedData(GrContext *ctx=nullptr)
Return a ref to the encoded (i.e.
Definition: SkImageGenerator.h:81
An interface that allows a purgeable PixelRef (such as a SkDiscardablePixelRef) to decode and re-deco...
Definition: SkImageGenerator.h:62
Pairs SkImageInfo with actual pixels and rowbytes.
Definition: SkPixmap.h:23
Represents the filtering and tile modes used to access a texture.
Definition: GrTextureParams.h:17
The SkMatrix class holds a 3x3 matrix for transforming coordinates.
Definition: SkMatrix.h:26
The SkPaint class holds the style and color information about how to draw geometries, text and bitmaps.
Definition: SkPaint.h:46
An SkPicture records drawing commands made to a canvas to be played back at a later time...
Definition: SkPicture.h:38
SkData holds an immutable data buffer.
Definition: SkData.h:22
Definition: SkImageGenerator.h:178
The SkBitmap class specifies a raster bitmap.
Definition: SkBitmap.h:41
Definition: SkYUVSizeInfo.h:11
Definition: GrContext.h:48
uint32_t SkPMColor
32 bit ARGB color value, premultiplied.
Definition: SkColor.h:147
const SkImageInfo & getInfo() const
Return the ImageInfo associated with this generator.
Definition: SkImageGenerator.h:92
virtual ~SkImageGenerator()
The PixelRef which takes ownership of this SkImageGenerator will call the image generator's destructo...
Definition: SkImageGenerator.h:68
SkIRect holds four 32 bit integer coordinates for a rectangle.
Definition: SkRect.h:20
Definition: GrTexture.h:19
SkIPoint holds two 32 bit integer coordinates.
Definition: SkPoint.h:40
Types and macros for colors.