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

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

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

Powered by Google App Engine
This is Rietveld 408576698