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

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

Issue 1778393002: add Make variations to return SkImage by sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: roll in fmalitas comments Created 4 years, 9 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 | « no previous file | include/core/SkShader.h » ('j') | src/image/SkImage.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 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 SkImage_DEFINED 8 #ifndef SkImage_DEFINED
9 #define SkImage_DEFINED 9 #define SkImage_DEFINED
10 10
11 #include "SkFilterQuality.h" 11 #include "SkFilterQuality.h"
12 #include "SkImageInfo.h" 12 #include "SkImageInfo.h"
13 #include "SkImageEncoder.h" 13 #include "SkImageEncoder.h"
14 #include "SkRefCnt.h" 14 #include "SkRefCnt.h"
15 #include "SkScalar.h" 15 #include "SkScalar.h"
16 #include "SkShader.h" 16 #include "SkShader.h"
17 17
18 class SkData; 18 class SkData;
19 class SkCanvas; 19 class SkCanvas;
20 class SkColorTable; 20 class SkColorTable;
21 class SkImageGenerator; 21 class SkImageGenerator;
22 class SkPaint; 22 class SkPaint;
23 class SkPicture; 23 class SkPicture;
24 class SkPixelSerializer; 24 class SkPixelSerializer;
25 class SkString; 25 class SkString;
26 class SkSurface; 26 class SkSurface;
27 class GrContext; 27 class GrContext;
28 class GrTexture; 28 class GrTexture;
29 29
30 #define SK_SUPPORT_LEGACY_IMAGEFACTORY
31
30 /** 32 /**
31 * SkImage is an abstraction for drawing a rectagle of pixels, though the 33 * SkImage is an abstraction for drawing a rectagle of pixels, though the
32 * particular type of image could be actually storing its data on the GPU, or 34 * particular type of image could be actually storing its data on the GPU, or
33 * as drawing commands (picture or PDF or otherwise), ready to be played back 35 * as drawing commands (picture or PDF or otherwise), ready to be played back
34 * into another canvas. 36 * into another canvas.
35 * 37 *
36 * The content of SkImage is always immutable, though the actual storage may 38 * The content of SkImage is always immutable, though the actual storage may
37 * change, if for example that image can be re-created via encoded data or 39 * change, if for example that image can be re-created via encoded data or
38 * other means. 40 * other means.
39 * 41 *
40 * SkImage always has a non-zero dimensions. If there is a request to create a new image, either 42 * SkImage always has a non-zero dimensions. If there is a request to create a new image, either
41 * directly or via SkSurface, and either of the requested dimensions are zero, then NULL will be 43 * directly or via SkSurface, and either of the requested dimensions are zero, then NULL will be
42 * returned. 44 * returned.
43 */ 45 */
44 class SK_API SkImage : public SkRefCnt { 46 class SK_API SkImage : public SkRefCnt {
45 public: 47 public:
46 typedef SkImageInfo Info; 48 typedef SkImageInfo Info;
47 typedef void* ReleaseContext; 49 typedef void* ReleaseContext;
48 50
49 static SkImage* NewRasterCopy(const Info&, const void* pixels, size_t rowByt es, 51 static sk_sp<SkImage> MakeRasterCopy(const SkPixmap&);
50 SkColorTable* ctable = NULL); 52 static sk_sp<SkImage> MakeRasterData(const Info&, sk_sp<SkData> pixels, size _t rowBytes);
51 static SkImage* NewRasterData(const Info&, SkData* pixels, size_t rowBytes);
52 53
53 typedef void (*RasterReleaseProc)(const void* pixels, ReleaseContext); 54 typedef void (*RasterReleaseProc)(const void* pixels, ReleaseContext);
54 55
55 /** 56 /**
56 * Return a new Image referencing the specified pixels. These must remain v alid and unchanged 57 * Return a new Image referencing the specified pixels. These must remain v alid and unchanged
57 * until the specified release-proc is called, indicating that Skia no long er has a reference 58 * until the specified release-proc is called, indicating that Skia no long er has a reference
58 * to the pixels. 59 * to the pixels.
59 * 60 *
60 * Returns NULL if the requested Info is unsupported. 61 * Returns NULL if the requested pixmap info is unsupported.
61 */ 62 */
62 static SkImage* NewFromRaster(const Info&, const void* pixels, size_t rowByt es, 63 static sk_sp<SkImage> MakeFromRaster(const SkPixmap&, RasterReleaseProc, Rel easeContext);
63 RasterReleaseProc, ReleaseContext);
64 64
65 /** 65 /**
66 * Construct a new image from the specified bitmap. If the bitmap is marked immutable, and 66 * Construct a new image from the specified bitmap. If the bitmap is marked immutable, and
67 * its pixel memory is shareable, it may be shared instead of copied. 67 * its pixel memory is shareable, it may be shared instead of copied.
68 */ 68 */
69 static SkImage* NewFromBitmap(const SkBitmap&); 69 static sk_sp<SkImage> MakeFromBitmap(const SkBitmap&);
70 70
71 /** 71 /**
72 * Construct a new SkImage based on the given ImageGenerator. 72 * Construct a new SkImage based on the given ImageGenerator. Returns NULL on error.
73 * This function will always take ownership of the passed 73 * This function will always take ownership of the passed generator.
74 * ImageGenerator. Returns NULL on error.
75 * 74 *
76 * If a subset is specified, it must be contained within the generator's bo unds. 75 * If a subset is specified, it must be contained within the generator's bo unds.
77 */ 76 */
78 static SkImage* NewFromGenerator(SkImageGenerator*, const SkIRect* subset = NULL); 77 static sk_sp<SkImage> MakeFromGenerator(SkImageGenerator*, const SkIRect* su bset = NULL);
79 78
80 /** 79 /**
81 * Construct a new SkImage based on the specified encoded data. Returns NUL L on failure, 80 * Construct a new SkImage based on the specified encoded data. Returns NUL L on failure,
82 * which can mean that the format of the encoded data was not recognized/su pported. 81 * which can mean that the format of the encoded data was not recognized/su pported.
83 * 82 *
84 * If a subset is specified, it must be contained within the encoded data's bounds. 83 * If a subset is specified, it must be contained within the encoded data's bounds.
85 *
86 * Regardless of success or failure, the caller is responsible for managing their ownership
87 * of the data.
88 */ 84 */
89 static SkImage* NewFromEncoded(SkData* encoded, const SkIRect* subset = NULL ); 85 static sk_sp<SkImage> MakeFromEncoded(sk_sp<SkData> encoded, const SkIRect* subset = NULL);
90 86
91 /** 87 /**
92 * Create a new image from the specified descriptor. Note - the caller is r esponsible for 88 * Create a new image from the specified descriptor. Note - the caller is r esponsible for
93 * managing the lifetime of the underlying platform texture. 89 * managing the lifetime of the underlying platform texture.
94 * 90 *
95 * Will return NULL if the specified descriptor is unsupported. 91 * Will return NULL if the specified descriptor is unsupported.
96 */ 92 */
97 static SkImage* NewFromTexture(GrContext* ctx, const GrBackendTextureDesc& d esc) { 93 static sk_sp<SkImage> MakeFromTexture(GrContext* ctx, const GrBackendTexture Desc& desc) {
98 return NewFromTexture(ctx, desc, kPremul_SkAlphaType, NULL, NULL); 94 return MakeFromTexture(ctx, desc, kPremul_SkAlphaType, NULL, NULL);
99 } 95 }
100 96
101 static SkImage* NewFromTexture(GrContext* ctx, const GrBackendTextureDesc& d e, SkAlphaType at) { 97 static sk_sp<SkImage> MakeFromTexture(GrContext* ctx, const GrBackendTexture Desc& de,
102 return NewFromTexture(ctx, de, at, NULL, NULL); 98 SkAlphaType at) {
99 return MakeFromTexture(ctx, de, at, NULL, NULL);
103 } 100 }
104 101
105 typedef void (*TextureReleaseProc)(ReleaseContext); 102 typedef void (*TextureReleaseProc)(ReleaseContext);
106 103
107 /** 104 /**
108 * Create a new image from the specified descriptor. The underlying platfor m texture must stay 105 * Create a new image from the specified descriptor. The underlying platfor m texture must stay
109 * valid and unaltered until the specified release-proc is invoked, indicat ing that Skia 106 * valid and unaltered until the specified release-proc is invoked, indicat ing that Skia
110 * no longer is holding a reference to it. 107 * no longer is holding a reference to it.
111 * 108 *
112 * Will return NULL if the specified descriptor is unsupported. 109 * Will return NULL if the specified descriptor is unsupported.
113 */ 110 */
114 static SkImage* NewFromTexture(GrContext*, const GrBackendTextureDesc&, SkAl phaType, 111 static sk_sp<SkImage> MakeFromTexture(GrContext*, const GrBackendTextureDesc &, SkAlphaType,
115 TextureReleaseProc, ReleaseContext); 112 TextureReleaseProc, ReleaseContext);
116 113
117 /** 114 /**
118 * Create a new image from the specified descriptor. Note - Skia will delet e or recycle the 115 * Create a new image from the specified descriptor. Note - Skia will delet e or recycle the
119 * texture when the image is released. 116 * texture when the image is released.
120 * 117 *
121 * Will return NULL if the specified descriptor is unsupported. 118 * Will return NULL if the specified descriptor is unsupported.
122 */ 119 */
123 static SkImage* NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc &, 120 static sk_sp<SkImage> MakeFromAdoptedTexture(GrContext*, const GrBackendText ureDesc&,
124 SkAlphaType = kPremul_SkAlphaType); 121 SkAlphaType = kPremul_SkAlphaTy pe);
125 122
126 /** 123 /**
127 * Create a new image by copying the pixels from the specified descriptor. No reference is 124 * Create a new image by copying the pixels from the specified descriptor. No reference is
128 * kept to the original platform texture. 125 * kept to the original platform texture.
129 * 126 *
130 * Will return NULL if the specified descriptor is unsupported. 127 * Will return NULL if the specified descriptor is unsupported.
131 */ 128 */
132 static SkImage* NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, 129 static sk_sp<SkImage> MakeFromTextureCopy(GrContext*, const GrBackendTexture Desc&,
133 SkAlphaType = kPremul_SkAlphaType); 130 SkAlphaType = kPremul_SkAlphaType) ;
134 131
135 /** 132 /**
136 * Create a new image by copying the pixels from the specified y, u, v text ures. The data 133 * Create a new image by copying the pixels from the specified y, u, v text ures. The data
137 * from the textures is immediately ingested into the image and the texture s can be modified or 134 * from the textures is immediately ingested into the image and the texture s can be modified or
138 * deleted after the function returns. The image will have the dimensions o f the y texture. 135 * deleted after the function returns. The image will have the dimensions o f the y texture.
139 */ 136 */
140 static SkImage* NewFromYUVTexturesCopy(GrContext*, SkYUVColorSpace, 137 static sk_sp<SkImage> MakeFromYUVTexturesCopy(GrContext*, SkYUVColorSpace,
141 const GrBackendObject yuvTextureHandl es[3], 138 const GrBackendObject yuvTextu reHandles[3],
142 const SkISize yuvSizes[3], 139 const SkISize yuvSizes[3],
143 GrSurfaceOrigin); 140 GrSurfaceOrigin);
144 141
145 static SkImage* NewFromPicture(const SkPicture*, const SkISize& dimensions, 142 static sk_sp<SkImage> MakeFromPicture(sk_sp<SkPicture>, const SkISize& dimen sions,
146 const SkMatrix*, const SkPaint*); 143 const SkMatrix*, const SkPaint*);
147 144
148 static SkImage* NewTextureFromPixmap(GrContext*, const SkPixmap&, SkBudgeted budgeted); 145 static sk_sp<SkImage> MakeTextureFromPixmap(GrContext*, const SkPixmap&, SkB udgeted budgeted);
149 146
150 //////////////////////////////////////////////////////////////////////////// /////////////////// 147 //////////////////////////////////////////////////////////////////////////// ///////////////////
151 148
152 int width() const { return fWidth; } 149 int width() const { return fWidth; }
153 int height() const { return fHeight; } 150 int height() const { return fHeight; }
154 SkISize dimensions() const { return SkISize::Make(fWidth, fHeight); } 151 SkISize dimensions() const { return SkISize::Make(fWidth, fHeight); }
155 SkIRect bounds() const { return SkIRect::MakeWH(fWidth, fHeight); } 152 SkIRect bounds() const { return SkIRect::MakeWH(fWidth, fHeight); }
156 uint32_t uniqueID() const { return fUniqueID; } 153 uint32_t uniqueID() const { return fUniqueID; }
157 virtual bool isOpaque() const { return false; } 154 virtual bool isOpaque() const { return false; }
158 155
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 305
309 const char* toString(SkString*) const; 306 const char* toString(SkString*) const;
310 307
311 /** 308 /**
312 * Return a new image that is a subset of this image. The underlying implem entation may 309 * Return a new image that is a subset of this image. The underlying implem entation may
313 * share the pixels, or it may make a copy. 310 * share the pixels, or it may make a copy.
314 * 311 *
315 * If subset does not intersect the bounds of this image, or the copy/share cannot be made, 312 * If subset does not intersect the bounds of this image, or the copy/share cannot be made,
316 * NULL will be returned. 313 * NULL will be returned.
317 */ 314 */
318 SkImage* newSubset(const SkIRect& subset) const; 315 sk_sp<SkImage> makeSubset(const SkIRect& subset) const;
319 316
320 /** 317 /**
321 * Ensures that an image is backed by a texture (when GrContext is non-null ). If no 318 * Ensures that an image is backed by a texture (when GrContext is non-null ). If no
322 * transformation is required, the returned image may be the same as this i mage. If the this 319 * transformation is required, the returned image may be the same as this i mage. If the this
323 * image is from a different GrContext, this will fail. 320 * image is from a different GrContext, this will fail.
324 */ 321 */
325 SkImage* newTextureImage(GrContext*) const; 322 sk_sp<SkImage> makeTextureImage(GrContext*) const;
326 323
327 // Helper functions to convert to SkBitmap 324 // Helper functions to convert to SkBitmap
328 325
329 enum LegacyBitmapMode { 326 enum LegacyBitmapMode {
330 kRO_LegacyBitmapMode, 327 kRO_LegacyBitmapMode,
331 kRW_LegacyBitmapMode, 328 kRW_LegacyBitmapMode,
332 }; 329 };
333 330
334 /** 331 /**
335 * Attempt to create a bitmap with the same pixels as the image. The result will always be 332 * Attempt to create a bitmap with the same pixels as the image. The result will always be
336 * a raster-backed bitmap (texture-backed bitmaps are DEPRECATED, and not s upported here). 333 * a raster-backed bitmap (texture-backed bitmaps are DEPRECATED, and not s upported here).
337 * 334 *
338 * If the mode is kRO (read-only), the resulting bitmap will be marked as i mmutable. 335 * If the mode is kRO (read-only), the resulting bitmap will be marked as i mmutable.
339 * 336 *
340 * On succcess, returns true. On failure, returns false and the bitmap para meter will be reset 337 * On succcess, returns true. On failure, returns false and the bitmap para meter will be reset
341 * to empty. 338 * to empty.
342 */ 339 */
343 bool asLegacyBitmap(SkBitmap*, LegacyBitmapMode) const; 340 bool asLegacyBitmap(SkBitmap*, LegacyBitmapMode) const;
344 341
345 /** 342 /**
346 * Returns true if the image is backed by an image-generator or other src t hat creates 343 * Returns true if the image is backed by an image-generator or other src t hat creates
347 * (and caches) its pixels / texture on-demand. 344 * (and caches) its pixels / texture on-demand.
348 */ 345 */
349 bool isLazyGenerated() const; 346 bool isLazyGenerated() const;
350 347
348
349 #ifdef SK_SUPPORT_LEGACY_IMAGEFACTORY
350 static SkImage* NewRasterCopy(const Info&, const void* pixels, size_t rowByt es,
351 SkColorTable* ctable = nullptr);
352 static SkImage* NewRasterData(const Info&, SkData* pixels, size_t rowBytes);
353 static SkImage* NewFromRaster(const Info&, const void* pixels, size_t rowByt es,
354 RasterReleaseProc, ReleaseContext);
355 static SkImage* NewFromBitmap(const SkBitmap&);
356 static SkImage* NewFromGenerator(SkImageGenerator*, const SkIRect* subset = NULL);
357 static SkImage* NewFromEncoded(SkData* encoded, const SkIRect* subset = NULL );
358 static SkImage* NewFromTexture(GrContext* ctx, const GrBackendTextureDesc& d esc) {
359 return NewFromTexture(ctx, desc, kPremul_SkAlphaType, NULL, NULL);
360 }
361
362 static SkImage* NewFromTexture(GrContext* ctx, const GrBackendTextureDesc& d e, SkAlphaType at) {
363 return NewFromTexture(ctx, de, at, NULL, NULL);
364 }
365 static SkImage* NewFromTexture(GrContext*, const GrBackendTextureDesc&, SkAl phaType,
366 TextureReleaseProc, ReleaseContext);
367 static SkImage* NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc &,
368 SkAlphaType = kPremul_SkAlphaType);
369 static SkImage* NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&,
370 SkAlphaType = kPremul_SkAlphaType);
371 static SkImage* NewFromYUVTexturesCopy(GrContext*, SkYUVColorSpace,
372 const GrBackendObject yuvTextureHandl es[3],
373 const SkISize yuvSizes[3],
374 GrSurfaceOrigin);
375 static SkImage* NewFromPicture(const SkPicture*, const SkISize& dimensions,
376 const SkMatrix*, const SkPaint*);
377 static SkImage* NewTextureFromPixmap(GrContext*, const SkPixmap&, SkBudgeted budgeted);
378
379 SkImage* newSubset(const SkIRect& subset) const { return this->makeSubset(su bset).release(); }
380 SkImage* newTextureImage(GrContext* ctx) const { return this->makeTextureIma ge(ctx).release(); }
381 #endif
382
351 protected: 383 protected:
352 SkImage(int width, int height, uint32_t uniqueID); 384 SkImage(int width, int height, uint32_t uniqueID);
353 385
354 private: 386 private:
355 const int fWidth; 387 const int fWidth;
356 const int fHeight; 388 const int fHeight;
357 const uint32_t fUniqueID; 389 const uint32_t fUniqueID;
358 390
359 typedef SkRefCnt INHERITED; 391 typedef SkRefCnt INHERITED;
360 }; 392 };
361 393
362 #endif 394 #endif
OLDNEW
« no previous file with comments | « no previous file | include/core/SkShader.h » ('j') | src/image/SkImage.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698