Skia
2DGraphicsLibrary
 All Classes Namespaces 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 "SkImage.h"
14 #include "SkImageInfo.h"
15 #include "SkYUVSizeInfo.h"
16 
17 class GrContext;
19 class GrTextureProxy;
20 class GrSamplerParams;
21 class SkBitmap;
22 class SkData;
23 class SkMatrix;
24 class SkPaint;
25 class SkPicture;
26 
27 class SK_API SkImageGenerator : public SkNoncopyable {
28 public:
33  virtual ~SkImageGenerator() { }
34 
35  uint32_t uniqueID() const { return fUniqueID; }
36 
45  return this->onRefEncodedData();
46  }
47 
51  const SkImageInfo& getInfo() const { return fInfo; }
52 
57  bool isValid(GrContext* context) const {
58  return this->onIsValid(context);
59  }
60 
85  struct Options {
86  Options()
87  : fBehavior(SkTransferFunctionBehavior::kIgnore)
88  {}
89 
90  SkTransferFunctionBehavior fBehavior;
91  };
92  bool getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, const Options* options);
93 
97  bool getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes);
98 
107  bool queryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const;
108 
119  bool getYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]);
120 
121 #if SK_SUPPORT_GPU
122 
144  sk_sp<GrTextureProxy> generateTexture(GrContext*, const SkImageInfo& info,
145  const SkIPoint& origin);
146 #endif
147 
153  static std::unique_ptr<SkImageGenerator> MakeFromEncoded(sk_sp<SkData>);
154 
160  static std::unique_ptr<SkImageGenerator> MakeFromPicture(const SkISize&, sk_sp<SkPicture>,
161  const SkMatrix*, const SkPaint*,
162  SkImage::BitDepth,
164 
165 protected:
166  enum {
167  kNeedNewImageUniqueID = 0
168  };
169 
170  SkImageGenerator(const SkImageInfo& info, uint32_t uniqueId = kNeedNewImageUniqueID);
171 
172  virtual SkData* onRefEncodedData() { return nullptr; }
173  virtual bool onGetPixels(const SkImageInfo&, void*, size_t, const Options&) { return false; }
174  virtual bool onIsValid(GrContext*) const { return true; }
175  virtual bool onQueryYUV8(SkYUVSizeInfo*, SkYUVColorSpace*) const { return false; }
176  virtual bool onGetYUV8Planes(const SkYUVSizeInfo&, void*[3] /*planes*/) { return false; }
177 
178 #if SK_SUPPORT_GPU
179  enum class TexGenType {
180  kNone, //image generator does not implement onGenerateTexture
181  kCheap, //onGenerateTexture is implemented and it is fast (does not render offscreen)
182  kExpensive, //onGenerateTexture is implemented and it is relatively slow
183  };
184 
185  virtual TexGenType onCanGenerateTexture() const { return TexGenType::kNone; }
186  virtual sk_sp<GrTextureProxy> onGenerateTexture(GrContext*, const SkImageInfo&,
187  const SkIPoint&); // returns nullptr
188 #endif
189 
190 private:
191  const SkImageInfo fInfo;
192  const uint32_t fUniqueID;
193 
194  friend class SkImage_Lazy;
195 
196  // This is our default impl, which may be different on different platforms.
197  // It is called from NewFromEncoded() after it has checked for any runtime factory.
198  // The SkData will never be NULL, as that will have been checked by NewFromEncoded.
199  static std::unique_ptr<SkImageGenerator> MakeFromEncodedImpl(sk_sp<SkData>);
200 };
201 
202 #endif // SkImageGenerator_DEFINED
Describe an image's dimensions and pixel type.
Definition: SkImageInfo.h:181
Definition: SkImageGenerator.h:27
Represents the filtering and tile modes used to access a texture.
Definition: GrSamplerParams.h:17
The SkMatrix class holds a 3x3 matrix for transforming coordinates.
Definition: SkMatrix.h:28
The SkPaint class holds the style and color information about how to draw geometries, text and bitmaps.
Definition: SkPaint.h:45
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
The SkBitmap class specifies a raster bitmap.
Definition: SkBitmap.h:37
Shared pointer class to wrap classes that support a ref()/unref() interface.
Definition: SkRefCnt.h:246
Definition: SkYUVSizeInfo.h:13
Definition: GrContext.h:47
Definition: SkSize.h:13
const SkImageInfo & getInfo() const
Return the ImageInfo associated with this generator.
Definition: SkImageGenerator.h:51
bool isValid(GrContext *context) const
Can this generator be used to produce images that will be drawable to the specified context (or to CP...
Definition: SkImageGenerator.h:57
SkData * refEncodedData()
Return a ref to the encoded (i.e.
Definition: SkImageGenerator.h:44
virtual ~SkImageGenerator()
The PixelRef which takes ownership of this SkImageGenerator will call the image generator's destructo...
Definition: SkImageGenerator.h:33
Decode into the given pixels, a block of memory of size at least (info.fHeight - 1) * rowBytes + (inf...
Definition: SkImageGenerator.h:85
SkIPoint holds two 32 bit integer coordinates.
Definition: SkPoint.h:40
Types and macros for colors.
Can be used to perform actions related to the generating GrContext in a thread safe manner...
Definition: GrContext.h:361