Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(189)

Side by Side Diff: include/core/SkImageGenerator.h

Issue 1291803002: Extend SkImageGenerator to support natively generated GrTextures (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gyp/core.gypi ('k') | include/core/SkImageInfo.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkImageGenerator_DEFINED 8 #ifndef SkImageGenerator_DEFINED
9 #define SkImageGenerator_DEFINED 9 #define SkImageGenerator_DEFINED
10 10
11 #include "SkColor.h" 11 #include "SkColor.h"
12 #include "SkImageInfo.h" 12 #include "SkImageInfo.h"
13 13
14 class GrContext;
14 class SkBitmap; 15 class SkBitmap;
15 class SkData; 16 class SkData;
17 class GrTexture;
16 class SkImageGenerator; 18 class SkImageGenerator;
17 class SkMatrix; 19 class SkMatrix;
18 class SkPaint; 20 class SkPaint;
19 class SkPicture; 21 class SkPicture;
20 22
21 /** 23 /**
22 * Takes ownership of SkImageGenerator. If this method fails for 24 * Takes ownership of SkImageGenerator. If this method fails for
23 * whatever reason, it will return false and immediatetely delete 25 * whatever reason, it will return false and immediatetely delete
24 * the generator. If it succeeds, it will modify destination 26 * the generator. If it succeeds, it will modify destination
25 * bitmap. 27 * bitmap.
(...skipping 23 matching lines...) Expand all
49 * SkDiscardablePixelRef) to decode and re-decode an image as needed. 51 * SkDiscardablePixelRef) to decode and re-decode an image as needed.
50 */ 52 */
51 class SK_API SkImageGenerator : public SkNoncopyable { 53 class SK_API SkImageGenerator : public SkNoncopyable {
52 public: 54 public:
53 /** 55 /**
54 * The PixelRef which takes ownership of this SkImageGenerator 56 * The PixelRef which takes ownership of this SkImageGenerator
55 * will call the image generator's destructor. 57 * will call the image generator's destructor.
56 */ 58 */
57 virtual ~SkImageGenerator() { } 59 virtual ~SkImageGenerator() { }
58 60
61 uint32_t uniqueID() const { return fUniqueID; }
62
59 /** 63 /**
60 * Return a ref to the encoded (i.e. compressed) representation, 64 * Return a ref to the encoded (i.e. compressed) representation,
61 * of this data. 65 * of this data.
62 * 66 *
63 * If non-NULL is returned, the caller is responsible for calling 67 * If non-NULL is returned, the caller is responsible for calling
64 * unref() on the data when it is finished. 68 * unref() on the data when it is finished.
65 */ 69 */
66 SkData* refEncodedData() { return this->onRefEncodedData(); } 70 SkData* refEncodedData() { return this->onRefEncodedData(); }
67 71
68 /** 72 /**
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 * entries only. Having only partial planes/rowBytes information is not sup ported. 120 * entries only. Having only partial planes/rowBytes information is not sup ported.
117 * 121 *
118 * If all planes and rowBytes entries are non NULL or non 0, then it should copy the 122 * If all planes and rowBytes entries are non NULL or non 0, then it should copy the
119 * associated YUV data into those planes of memory supplied by the caller. It should validate 123 * associated YUV data into those planes of memory supplied by the caller. It should validate
120 * that the sizes match what it expected. If the sizes do not match, it sho uld return false. 124 * that the sizes match what it expected. If the sizes do not match, it sho uld return false.
121 */ 125 */
122 bool getYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], 126 bool getYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3],
123 SkYUVColorSpace* colorSpace); 127 SkYUVColorSpace* colorSpace);
124 128
125 /** 129 /**
130 * If the generator can natively/efficiently return its pixels as a GPU ima ge (backed by a
131 * texture) this will return that image. If not, this will return NULL.
132 *
133 * Regarding the GrContext parameter:
134 *
135 * The caller may pass NULL for the context. In that case the generator may assume that its
136 * internal context is current. If it has no internal context, then it shou ld just return
137 * null.
138 *
139 * If the caller passes a non-null context, then the generator should only succeed if:
140 * - it has no intrinsic context, and will use the caller's
141 * - its internal context is the same
142 * - it can somehow convert its texture into one that is valid for the prov ided context.
143 *
144 * Regarding the SkImageUsageType parameter:
145 *
146 * If the context (the provided one or the generator's intrinsic one) deter mines that to
147 * support the specified usage, it must return a different sized texture (f rom the generator's
148 * native size) it may, so the caller must inspect the texture's width/heig ht
149 * (unless kUntiled_SkImageUsedType was specified).
150 */
151 GrTexture* generateTexture(GrContext*, SkImageUsageType);
152
153 /**
126 * If the default image decoder system can interpret the specified (encoded ) data, then 154 * If the default image decoder system can interpret the specified (encoded ) data, then
127 * this returns a new ImageGenerator for it. Otherwise this returns NULL. E ither way 155 * this returns a new ImageGenerator for it. Otherwise this returns NULL. E ither way
128 * the caller is still responsible for managing their ownership of the data . 156 * the caller is still responsible for managing their ownership of the data .
129 */ 157 */
130 static SkImageGenerator* NewFromEncoded(SkData*); 158 static SkImageGenerator* NewFromEncoded(SkData*);
131 159
132 /** Return a new image generator backed by the specified picture. If the si ze is empty or 160 /** Return a new image generator backed by the specified picture. If the si ze is empty or
133 * the picture is NULL, this returns NULL. 161 * the picture is NULL, this returns NULL.
134 * The optional matrix and paint arguments are passed to drawPicture() at r asterization 162 * The optional matrix and paint arguments are passed to drawPicture() at r asterization
135 * time. 163 * time.
136 */ 164 */
137 static SkImageGenerator* NewFromPicture(const SkISize&, const SkPicture*, co nst SkMatrix*, 165 static SkImageGenerator* NewFromPicture(const SkISize&, const SkPicture*, co nst SkMatrix*,
138 const SkPaint*); 166 const SkPaint*);
139 167
140 protected: 168 protected:
141 SkImageGenerator(const SkImageInfo& info) : fInfo(info) {} 169 SkImageGenerator(const SkImageInfo& info);
142 170
143 virtual SkData* onRefEncodedData(); 171 virtual SkData* onRefEncodedData();
144 172
145 virtual bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBy tes, 173 virtual bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBy tes,
146 SkPMColor ctable[], int* ctableCount); 174 SkPMColor ctable[], int* ctableCount);
147 virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy tes[3]); 175 virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy tes[3]);
148 virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy tes[3], 176 virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy tes[3],
149 SkYUVColorSpace* colorSpace); 177 SkYUVColorSpace* colorSpace);
150 178
179 virtual GrTexture* onGenerateTexture(GrContext*, SkImageUsageType) { return nullptr; }
180
151 private: 181 private:
152 const SkImageInfo fInfo; 182 const SkImageInfo fInfo;
183 const uint32_t fUniqueID;
153 184
154 // This is our default impl, which may be different on different platforms. 185 // This is our default impl, which may be different on different platforms.
155 // It is called from NewFromEncoded() after it has checked for any runtime f actory. 186 // It is called from NewFromEncoded() after it has checked for any runtime f actory.
156 // The SkData will never be NULL, as that will have been checked by NewFromE ncoded. 187 // The SkData will never be NULL, as that will have been checked by NewFromE ncoded.
157 static SkImageGenerator* NewFromEncodedImpl(SkData*); 188 static SkImageGenerator* NewFromEncodedImpl(SkData*);
158 }; 189 };
159 190
160 #endif // SkImageGenerator_DEFINED 191 #endif // SkImageGenerator_DEFINED
OLDNEW
« no previous file with comments | « gyp/core.gypi ('k') | include/core/SkImageInfo.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698