SkImage.h 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026
  1. /*
  2. * Copyright 2012 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. /* Generated by tools/bookmaker from include/core/SkImage.h and docs/SkImage_Reference.bmh
  8. on 2018-09-18 07:26:44. Additional documentation and examples can be found at:
  9. https://skia.org/user/api/SkImage_Reference
  10. You may edit either file directly. Structural changes to public interfaces require
  11. editing both files. After editing docs/SkImage_Reference.bmh, run:
  12. bookmaker -b docs -i include/core/SkImage.h -p
  13. to create an updated version of this file.
  14. */
  15. #ifndef SkImage_DEFINED
  16. #define SkImage_DEFINED
  17. #include "GrTypes.h"
  18. #include "SkFilterQuality.h"
  19. #include "SkImageInfo.h"
  20. #include "SkImageEncoder.h"
  21. #include "SkRefCnt.h"
  22. #include "SkScalar.h"
  23. #include "SkShader.h"
  24. #if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26
  25. #include <android/hardware_buffer.h>
  26. #endif
  27. class SkData;
  28. class SkCanvas;
  29. class SkImageFilter;
  30. class SkImageGenerator;
  31. class SkPaint;
  32. class SkPicture;
  33. class SkString;
  34. class SkSurface;
  35. class GrBackendTexture;
  36. class GrContext;
  37. class GrContextThreadSafeProxy;
  38. class GrTexture;
  39. struct SkYUVAIndex;
  40. /** \class SkImage
  41. SkImage describes a two dimensional array of pixels to draw. The pixels may be
  42. decoded in a raster bitmap, encoded in a SkPicture or compressed data stream,
  43. or located in GPU memory as a GPU texture.
  44. SkImage cannot be modified after it is created. SkImage may allocate additional
  45. storage as needed; for instance, an encoded SkImage may decode when drawn.
  46. SkImage width and height are greater than zero. Creating an SkImage with zero width
  47. or height returns SkImage equal to nullptr.
  48. SkImage may be created from SkBitmap, SkPixmap, SkSurface, SkPicture, encoded streams,
  49. GPU texture, YUV_ColorSpace data, or hardware buffer. Encoded streams supported
  50. include BMP, GIF, HEIF, ICO, JPEG, PNG, WBMP, WebP. Supported encoding details
  51. vary with platform.
  52. */
  53. class SK_API SkImage : public SkRefCnt {
  54. public:
  55. /** Caller data passed to RasterReleaseProc; may be nullptr.
  56. */
  57. typedef void* ReleaseContext;
  58. /** Creates SkImage from SkPixmap and copy of pixels. Since pixels are copied, SkPixmap
  59. pixels may be modified or deleted without affecting SkImage.
  60. SkImage is returned if SkPixmap is valid. Valid SkPixmap parameters include:
  61. dimensions are greater than zero;
  62. each dimension fits in 29 bits;
  63. SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType;
  64. row bytes are large enough to hold one row of pixels;
  65. pixel address is not nullptr.
  66. @param pixmap SkImageInfo, pixel address, and row bytes
  67. @return copy of SkPixmap pixels, or nullptr
  68. */
  69. static sk_sp<SkImage> MakeRasterCopy(const SkPixmap& pixmap);
  70. /** Creates SkImage from SkImageInfo, sharing pixels.
  71. SkImage is returned if SkImageInfo is valid. Valid SkImageInfo parameters include:
  72. dimensions are greater than zero;
  73. each dimension fits in 29 bits;
  74. SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType;
  75. rowBytes are large enough to hold one row of pixels;
  76. pixels is not nullptr, and contains enough data for SkImage.
  77. @param info contains width, height, SkAlphaType, SkColorType, SkColorSpace
  78. @param pixels address or pixel storage
  79. @param rowBytes size of pixel row or larger
  80. @return SkImage sharing pixels, or nullptr
  81. */
  82. static sk_sp<SkImage> MakeRasterData(const SkImageInfo& info, sk_sp<SkData> pixels,
  83. size_t rowBytes);
  84. /** Function called when SkImage no longer shares pixels. ReleaseContext is
  85. provided by caller when SkImage is created, and may be nullptr.
  86. */
  87. typedef void (*RasterReleaseProc)(const void* pixels, ReleaseContext);
  88. /** Creates SkImage from pixmap, sharing SkPixmap pixels. Pixels must remain valid and
  89. unchanged until rasterReleaseProc is called. rasterReleaseProc is passed
  90. releaseContext when SkImage is deleted or no longer refers to pixmap pixels.
  91. Pass nullptr for rasterReleaseProc to share SkPixmap without requiring a callback
  92. when SkImage is released. Pass nullptr for releaseContext if rasterReleaseProc
  93. does not require state.
  94. SkImage is returned if pixmap is valid. Valid SkPixmap parameters include:
  95. dimensions are greater than zero;
  96. each dimension fits in 29 bits;
  97. SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType;
  98. row bytes are large enough to hold one row of pixels;
  99. pixel address is not nullptr.
  100. @param pixmap SkImageInfo, pixel address, and row bytes
  101. @param rasterReleaseProc function called when pixels can be released; or nullptr
  102. @param releaseContext state passed to rasterReleaseProc; or nullptr
  103. @return SkImage sharing pixmap
  104. */
  105. static sk_sp<SkImage> MakeFromRaster(const SkPixmap& pixmap,
  106. RasterReleaseProc rasterReleaseProc,
  107. ReleaseContext releaseContext);
  108. /** Creates SkImage from bitmap, sharing or copying bitmap pixels. If the bitmap
  109. is marked immutable, and its pixel memory is shareable, it may be shared
  110. instead of copied.
  111. SkImage is returned if bitmap is valid. Valid SkBitmap parameters include:
  112. dimensions are greater than zero;
  113. each dimension fits in 29 bits;
  114. SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType;
  115. row bytes are large enough to hold one row of pixels;
  116. pixel address is not nullptr.
  117. @param bitmap SkImageInfo, row bytes, and pixels
  118. @return created SkImage, or nullptr
  119. */
  120. static sk_sp<SkImage> MakeFromBitmap(const SkBitmap& bitmap);
  121. /** Creates SkImage from data returned by imageGenerator. Generated data is owned by SkImage and
  122. may not be shared or accessed.
  123. subset allows selecting a portion of the full image. Pass nullptr to select the entire
  124. image; otherwise, subset must be contained by image bounds.
  125. SkImage is returned if generator data is valid. Valid data parameters vary by type of data
  126. and platform.
  127. imageGenerator may wrap SkPicture data, codec data, or custom data.
  128. @param imageGenerator stock or custom routines to retrieve SkImage
  129. @param subset bounds of returned SkImage; may be nullptr
  130. @return created SkImage, or nullptr
  131. */
  132. static sk_sp<SkImage> MakeFromGenerator(std::unique_ptr<SkImageGenerator> imageGenerator,
  133. const SkIRect* subset = nullptr);
  134. /** Creates SkImage from encoded data.
  135. subset allows selecting a portion of the full image. Pass nullptr to select the entire
  136. image; otherwise, subset must be contained by image bounds.
  137. SkImage is returned if format of the encoded data is recognized and supported.
  138. Recognized formats vary by platform.
  139. @param encoded data of SkImage to decode
  140. @param subset bounds of returned SkImage; may be nullptr
  141. @return created SkImage, or nullptr
  142. */
  143. static sk_sp<SkImage> MakeFromEncoded(sk_sp<SkData> encoded, const SkIRect* subset = nullptr);
  144. /** User function called when supplied texture may be deleted.
  145. */
  146. typedef void (*TextureReleaseProc)(ReleaseContext releaseContext);
  147. /** Creates SkImage from GPU texture associated with context. Caller is responsible for
  148. managing the lifetime of GPU texture.
  149. SkImage is returned if format of backendTexture is recognized and supported.
  150. Recognized formats vary by GPU back-end.
  151. @param context GPU context
  152. @param backendTexture texture residing on GPU
  153. @param origin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin
  154. @param colorType one of:
  155. kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType,
  156. kARGB_4444_SkColorType, kRGBA_8888_SkColorType,
  157. kRGB_888x_SkColorType, kBGRA_8888_SkColorType,
  158. kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType,
  159. kGray_8_SkColorType, kRGBA_F16_SkColorType
  160. @param alphaType one of:
  161. kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType,
  162. kUnpremul_SkAlphaType
  163. @param colorSpace range of colors; may be nullptr
  164. @return created SkImage, or nullptr
  165. */
  166. static sk_sp<SkImage> MakeFromTexture(GrContext* context,
  167. const GrBackendTexture& backendTexture,
  168. GrSurfaceOrigin origin,
  169. SkColorType colorType,
  170. SkAlphaType alphaType,
  171. sk_sp<SkColorSpace> colorSpace) {
  172. return MakeFromTexture(context, backendTexture, origin, colorType, alphaType, colorSpace,
  173. nullptr, nullptr);
  174. }
  175. /** Creates SkImage from GPU texture associated with context. GPU texture must stay
  176. valid and unchanged until textureReleaseProc is called. textureReleaseProc is
  177. passed releaseContext when SkImage is deleted or no longer refers to texture.
  178. SkImage is returned if format of backendTexture is recognized and supported.
  179. Recognized formats vary by GPU back-end.
  180. @param context GPU context
  181. @param backendTexture texture residing on GPU
  182. @param origin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin
  183. @param colorType one of:
  184. kUnknown_SkColorType, kAlpha_8_SkColorType,
  185. kRGB_565_SkColorType, kARGB_4444_SkColorType,
  186. kRGBA_8888_SkColorType, kRGB_888x_SkColorType,
  187. kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType,
  188. kRGB_101010x_SkColorType, kGray_8_SkColorType,
  189. kRGBA_F16_SkColorType
  190. @param alphaType one of:
  191. kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType,
  192. kUnpremul_SkAlphaType
  193. @param colorSpace range of colors; may be nullptr
  194. @param textureReleaseProc function called when texture can be released
  195. @param releaseContext state passed to textureReleaseProc
  196. @return created SkImage, or nullptr
  197. */
  198. static sk_sp<SkImage> MakeFromTexture(GrContext* context,
  199. const GrBackendTexture& backendTexture,
  200. GrSurfaceOrigin origin,
  201. SkColorType colorType,
  202. SkAlphaType alphaType,
  203. sk_sp<SkColorSpace> colorSpace,
  204. TextureReleaseProc textureReleaseProc,
  205. ReleaseContext releaseContext);
  206. /** Creates SkImage from encoded data. SkImage is uploaded to GPU back-end using context.
  207. Created SkImage is available to other GPU contexts, and is available across thread
  208. boundaries. All contexts must be in the same GPU share group, or otherwise
  209. share resources.
  210. When SkImage is no longer referenced, context releases texture memory
  211. asynchronously.
  212. GrBackendTexture decoded from data is uploaded to match SkSurface created with
  213. dstColorSpace. SkColorSpace of SkImage is determined by encoded data.
  214. SkImage is returned if format of data is recognized and supported, and if context
  215. supports moving resources. Recognized formats vary by platform and GPU back-end.
  216. SkImage is returned using MakeFromEncoded() if context is nullptr or does not support
  217. moving resources between contexts.
  218. @param context GPU context
  219. @param data SkImage to decode
  220. @param buildMips create SkImage as mip map if true
  221. @param dstColorSpace range of colors of matching SkSurface on GPU
  222. @param limitToMaxTextureSize downscale image to GPU maximum texture size, if necessary
  223. @return created SkImage, or nullptr
  224. */
  225. static sk_sp<SkImage> MakeCrossContextFromEncoded(GrContext* context, sk_sp<SkData> data,
  226. bool buildMips, SkColorSpace* dstColorSpace,
  227. bool limitToMaxTextureSize = false);
  228. /** Creates SkImage from pixmap. SkImage is uploaded to GPU back-end using context.
  229. Created SkImage is available to other GPU contexts, and is available across thread
  230. boundaries. All contexts must be in the same GPU share group, or otherwise
  231. share resources.
  232. When SkImage is no longer referenced, context releases texture memory
  233. asynchronously.
  234. GrBackendTexture created from pixmap is uploaded to match SkSurface created with
  235. dstColorSpace. SkColorSpace of SkImage is determined by pixmap.colorSpace().
  236. SkImage is returned referring to GPU back-end if context is not nullptr,
  237. format of data is recognized and supported, and if context supports moving
  238. resources between contexts. Otherwise, pixmap pixel data is copied and SkImage
  239. as returned in raster format if possible; nullptr may be returned.
  240. Recognized GPU formats vary by platform and GPU back-end.
  241. @param context GPU context
  242. @param pixmap SkImageInfo, pixel address, and row bytes
  243. @param buildMips create SkImage as mip map if true
  244. @param dstColorSpace range of colors of matching SkSurface on GPU
  245. @param limitToMaxTextureSize downscale image to GPU maximum texture size, if necessary
  246. @return created SkImage, or nullptr
  247. */
  248. static sk_sp<SkImage> MakeCrossContextFromPixmap(GrContext* context, const SkPixmap& pixmap,
  249. bool buildMips, SkColorSpace* dstColorSpace,
  250. bool limitToMaxTextureSize = false);
  251. /** Creates SkImage from backendTexture associated with context. backendTexture and
  252. returned SkImage are managed internally, and are released when no longer needed.
  253. SkImage is returned if format of backendTexture is recognized and supported.
  254. Recognized formats vary by GPU back-end.
  255. @param context GPU context
  256. @param backendTexture texture residing on GPU
  257. @param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin
  258. @param colorType one of:
  259. kUnknown_SkColorType, kAlpha_8_SkColorType,
  260. kRGB_565_SkColorType, kARGB_4444_SkColorType,
  261. kRGBA_8888_SkColorType, kRGB_888x_SkColorType,
  262. kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType,
  263. kRGB_101010x_SkColorType, kGray_8_SkColorType,
  264. kRGBA_F16_SkColorType
  265. @param alphaType one of:
  266. kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType,
  267. kUnpremul_SkAlphaType
  268. @param colorSpace range of colors; may be nullptr
  269. @return created SkImage, or nullptr
  270. */
  271. static sk_sp<SkImage> MakeFromAdoptedTexture(GrContext* context,
  272. const GrBackendTexture& backendTexture,
  273. GrSurfaceOrigin surfaceOrigin,
  274. SkColorType colorType,
  275. SkAlphaType alphaType = kPremul_SkAlphaType,
  276. sk_sp<SkColorSpace> colorSpace = nullptr);
  277. /** Creates an SkImage by flattening the specified YUVA planes into a single, interleaved RGBA
  278. image.
  279. @param context GPU context
  280. @param yuvColorSpace How the YUV values are converted to RGB. One of:
  281. kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace,
  282. kRec709_SkYUVColorSpace
  283. @param yuvaTextures array of (up to four) YUVA textures on GPU which contain the,
  284. possibly interleaved, YUVA planes
  285. @param yuvaIndices array indicating which texture in yuvaTextures, and channel
  286. in that texture, maps to each component of YUVA.
  287. @param imageSize size of the resulting image
  288. @param imageOrigin origin of the resulting image. One of: kBottomLeft_GrSurfaceOrigin,
  289. kTopLeft_GrSurfaceOrigin
  290. @param imageColorSpace range of colors of the resulting image; may be nullptr
  291. @return created SkImage, or nullptr
  292. */
  293. static sk_sp<SkImage> MakeFromYUVATexturesCopy(GrContext* context,
  294. SkYUVColorSpace yuvColorSpace,
  295. const GrBackendTexture yuvaTextures[],
  296. const SkYUVAIndex yuvaIndices[4],
  297. SkISize imageSize,
  298. GrSurfaceOrigin imageOrigin,
  299. sk_sp<SkColorSpace> imageColorSpace = nullptr);
  300. /** Creates an SkImage by flattening the specified YUVA planes into a single, interleaved RGBA
  301. image. 'backendTexture' is used to store the result of the flattening.
  302. @param context GPU context
  303. @param yuvColorSpace How the YUV values are converted to RGB. One of:
  304. kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace,
  305. kRec709_SkYUVColorSpace
  306. @param yuvaTextures array of (up to four) YUVA textures on GPU which contain the,
  307. possibly interleaved, YUVA planes
  308. @param yuvaIndices array indicating which texture in yuvaTextures, and channel
  309. in that texture, maps to each component of YUVA.
  310. @param imageSize size of the resulting image
  311. @param imageOrigin origin of the resulting image. One of: kBottomLeft_GrSurfaceOrigin,
  312. kTopLeft_GrSurfaceOrigin
  313. @param backendTexture the resource that stores the final pixels
  314. @param imageColorSpace range of colors of the resulting image; may be nullptr
  315. @return created SkImage, or nullptr
  316. */
  317. static sk_sp<SkImage> MakeFromYUVATexturesCopyWithExternalBackend(
  318. GrContext* context,
  319. SkYUVColorSpace yuvColorSpace,
  320. const GrBackendTexture yuvaTextures[],
  321. const SkYUVAIndex yuvaIndices[4],
  322. SkISize imageSize,
  323. GrSurfaceOrigin imageOrigin,
  324. const GrBackendTexture& backendTexture,
  325. sk_sp<SkColorSpace> imageColorSpace = nullptr);
  326. /** Creates an SkImage by storing the specified YUVA planes into an image, to be rendered
  327. via multitexturing.
  328. @param context GPU context
  329. @param yuvColorSpace How the YUV values are converted to RGB. One of:
  330. kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace,
  331. kRec709_SkYUVColorSpace
  332. @param yuvaTextures array of (up to four) YUVA textures on GPU which contain the,
  333. possibly interleaved, YUVA planes
  334. @param yuvaIndices array indicating which texture in yuvaTextures, and channel
  335. in that texture, maps to each component of YUVA.
  336. @param imageSize size of the resulting image
  337. @param imageOrigin origin of the resulting image. One of: kBottomLeft_GrSurfaceOrigin,
  338. kTopLeft_GrSurfaceOrigin
  339. @param imageColorSpace range of colors of the resulting image; may be nullptr
  340. @return created SkImage, or nullptr
  341. */
  342. static sk_sp<SkImage> MakeFromYUVATextures(GrContext* context,
  343. SkYUVColorSpace yuvColorSpace,
  344. const GrBackendTexture yuvaTextures[],
  345. const SkYUVAIndex yuvaIndices[4],
  346. SkISize imageSize,
  347. GrSurfaceOrigin imageOrigin,
  348. sk_sp<SkColorSpace> imageColorSpace = nullptr);
  349. /** Creates SkImage from pixmap array representing YUVA data.
  350. SkImage is uploaded to GPU back-end using context.
  351. Each GrBackendTexture created from yuvaPixmaps array is uploaded to match SkSurface
  352. using SkColorSpace of SkPixmap. SkColorSpace of SkImage is determined by imageColorSpace.
  353. SkImage is returned referring to GPU back-end if context is not nullptr and
  354. format of data is recognized and supported. Otherwise, nullptr is returned.
  355. Recognized GPU formats vary by platform and GPU back-end.
  356. @param context GPU context
  357. @param yuvColorSpace How the YUV values are converted to RGB. One of:
  358. kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace,
  359. kRec709_SkYUVColorSpace
  360. @param yuvaPixmaps array of (up to four) SkPixmap which contain the,
  361. possibly interleaved, YUVA planes
  362. @param yuvaIndices array indicating which pixmap in yuvaPixmaps, and channel
  363. in that pixmap, maps to each component of YUVA.
  364. @param imageSize size of the resulting image
  365. @param imageOrigin origin of the resulting image. One of:
  366. kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin
  367. @param buildMips create internal YUVA textures as mip map if true
  368. @param limitToMaxTextureSize downscale image to GPU maximum texture size, if necessary
  369. @param imageColorSpace range of colors of the resulting image; may be nullptr
  370. @return created SkImage, or nullptr
  371. */
  372. static sk_sp<SkImage> MakeFromYUVAPixmaps(
  373. GrContext* context, SkYUVColorSpace yuvColorSpace, const SkPixmap yuvaPixmaps[],
  374. const SkYUVAIndex yuvaIndices[4], SkISize imageSize, GrSurfaceOrigin imageOrigin,
  375. bool buildMips, bool limitToMaxTextureSize = false,
  376. sk_sp<SkColorSpace> imageColorSpace = nullptr);
  377. /** To be deprecated.
  378. */
  379. static sk_sp<SkImage> MakeFromYUVTexturesCopy(GrContext* context, SkYUVColorSpace yuvColorSpace,
  380. const GrBackendTexture yuvTextures[3],
  381. GrSurfaceOrigin imageOrigin,
  382. sk_sp<SkColorSpace> imageColorSpace = nullptr);
  383. /** To be deprecated.
  384. */
  385. static sk_sp<SkImage> MakeFromYUVTexturesCopyWithExternalBackend(
  386. GrContext* context, SkYUVColorSpace yuvColorSpace,
  387. const GrBackendTexture yuvTextures[3], GrSurfaceOrigin imageOrigin,
  388. const GrBackendTexture& backendTexture, sk_sp<SkColorSpace> imageColorSpace = nullptr);
  389. /** Creates SkImage from copy of nv12Textures, an array of textures on GPU.
  390. nv12Textures[0] contains pixels for YUV component y plane.
  391. nv12Textures[1] contains pixels for YUV component u plane,
  392. followed by pixels for YUV component v plane.
  393. Returned SkImage has the dimensions nv12Textures[2].
  394. yuvColorSpace describes how YUV colors convert to RGB colors.
  395. @param context GPU context
  396. @param yuvColorSpace one of: kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace,
  397. kRec709_SkYUVColorSpace
  398. @param nv12Textures array of YUV textures on GPU
  399. @param imageOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin
  400. @param imageColorSpace range of colors; may be nullptr
  401. @return created SkImage, or nullptr
  402. */
  403. static sk_sp<SkImage> MakeFromNV12TexturesCopy(GrContext* context,
  404. SkYUVColorSpace yuvColorSpace,
  405. const GrBackendTexture nv12Textures[2],
  406. GrSurfaceOrigin imageOrigin,
  407. sk_sp<SkColorSpace> imageColorSpace = nullptr);
  408. /** Creates SkImage from copy of nv12Textures, an array of textures on GPU.
  409. nv12Textures[0] contains pixels for YUV component y plane.
  410. nv12Textures[1] contains pixels for YUV component u plane,
  411. followed by pixels for YUV component v plane.
  412. Returned SkImage has the dimensions nv12Textures[2] and stores pixels in backendTexture.
  413. yuvColorSpace describes how YUV colors convert to RGB colors.
  414. @param context GPU context
  415. @param yuvColorSpace one of: kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace,
  416. kRec709_SkYUVColorSpace
  417. @param nv12Textures array of YUV textures on GPU
  418. @param imageOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin
  419. @param backendTexture the resource that stores the final pixels
  420. @param imageColorSpace range of colors; may be nullptr
  421. @return created SkImage, or nullptr
  422. */
  423. static sk_sp<SkImage> MakeFromNV12TexturesCopyWithExternalBackend(
  424. GrContext* context,
  425. SkYUVColorSpace yuvColorSpace,
  426. const GrBackendTexture nv12Textures[2],
  427. GrSurfaceOrigin imageOrigin,
  428. const GrBackendTexture& backendTexture,
  429. sk_sp<SkColorSpace> imageColorSpace = nullptr);
  430. enum class BitDepth {
  431. kU8, //!< uses 8-bit unsigned int per color component
  432. kF16, //!< uses 16-bit float per color component
  433. };
  434. /** Creates SkImage from picture. Returned SkImage width and height are set by dimensions.
  435. SkImage draws picture with matrix and paint, set to bitDepth and colorSpace.
  436. If matrix is nullptr, draws with identity SkMatrix. If paint is nullptr, draws
  437. with default SkPaint. colorSpace may be nullptr.
  438. @param picture stream of drawing commands
  439. @param dimensions width and height
  440. @param matrix SkMatrix to rotate, scale, translate, and so on; may be nullptr
  441. @param paint SkPaint to apply transparency, filtering, and so on; may be nullptr
  442. @param bitDepth 8-bit integer or 16-bit float: per component
  443. @param colorSpace range of colors; may be nullptr
  444. @return created SkImage, or nullptr
  445. */
  446. static sk_sp<SkImage> MakeFromPicture(sk_sp<SkPicture> picture, const SkISize& dimensions,
  447. const SkMatrix* matrix, const SkPaint* paint,
  448. BitDepth bitDepth,
  449. sk_sp<SkColorSpace> colorSpace);
  450. #if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26
  451. /** (See Skia bug 7447)
  452. Creates SkImage from Android hardware buffer.
  453. Returned SkImage takes a reference on the buffer.
  454. Only available on Android, when __ANDROID_API__ is defined to be 26 or greater.
  455. @param hardwareBuffer AHardwareBuffer Android hardware buffer
  456. @param alphaType one of:
  457. kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType,
  458. kUnpremul_SkAlphaType
  459. @param colorSpace range of colors; may be nullptr
  460. @param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin
  461. @return created SkImage, or nullptr
  462. */
  463. static sk_sp<SkImage> MakeFromAHardwareBuffer(
  464. AHardwareBuffer* hardwareBuffer,
  465. SkAlphaType alphaType = kPremul_SkAlphaType,
  466. sk_sp<SkColorSpace> colorSpace = nullptr,
  467. GrSurfaceOrigin surfaceOrigin = kTopLeft_GrSurfaceOrigin);
  468. #endif
  469. /** Returns pixel count in each row.
  470. @return pixel width in SkImage
  471. */
  472. int width() const { return fWidth; }
  473. /** Returns pixel row count.
  474. @return pixel height in SkImage
  475. */
  476. int height() const { return fHeight; }
  477. /** Returns SkISize { width(), height() }.
  478. @return integral size of width() and height()
  479. */
  480. SkISize dimensions() const { return SkISize::Make(fWidth, fHeight); }
  481. /** Returns SkIRect { 0, 0, width(), height() }.
  482. @return integral rectangle from origin to width() and height()
  483. */
  484. SkIRect bounds() const { return SkIRect::MakeWH(fWidth, fHeight); }
  485. /** Returns value unique to image. SkImage contents cannot change after SkImage is
  486. created. Any operation to create a new SkImage will receive generate a new
  487. unique number.
  488. @return unique identifier
  489. */
  490. uint32_t uniqueID() const { return fUniqueID; }
  491. /** Returns SkAlphaType, one of:
  492. kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType,
  493. kUnpremul_SkAlphaType.
  494. SkAlphaType returned was a parameter to an SkImage constructor,
  495. or was parsed from encoded data.
  496. @return SkAlphaType in SkImage
  497. */
  498. SkAlphaType alphaType() const;
  499. /** Returns SkColorType if known; otherwise, returns kUnknown_SkColorType.
  500. @return SkColorType of SkImage
  501. */
  502. SkColorType colorType() const;
  503. /** Returns SkColorSpace, the range of colors, associated with SkImage. The
  504. reference count of SkColorSpace is unchanged. The returned SkColorSpace is
  505. immutable.
  506. SkColorSpace returned was passed to an SkImage constructor,
  507. or was parsed from encoded data. SkColorSpace returned may be ignored when SkImage
  508. is drawn, depending on the capabilities of the SkSurface receiving the drawing.
  509. @return SkColorSpace in SkImage, or nullptr
  510. */
  511. SkColorSpace* colorSpace() const;
  512. /** Returns a smart pointer to SkColorSpace, the range of colors, associated with
  513. SkImage. The smart pointer tracks the number of objects sharing this
  514. SkColorSpace reference so the memory is released when the owners destruct.
  515. The returned SkColorSpace is immutable.
  516. SkColorSpace returned was passed to an SkImage constructor,
  517. or was parsed from encoded data. SkColorSpace returned may be ignored when SkImage
  518. is drawn, depending on the capabilities of the SkSurface receiving the drawing.
  519. @return SkColorSpace in SkImage, or nullptr, wrapped in a smart pointer
  520. */
  521. sk_sp<SkColorSpace> refColorSpace() const;
  522. /** Returns true if SkImage pixels represent transparency only. If true, each pixel
  523. is packed in 8 bits as defined by kAlpha_8_SkColorType.
  524. @return true if pixels represent a transparency mask
  525. */
  526. bool isAlphaOnly() const;
  527. /** Returns true if pixels ignore their alpha value and are treated as fully opaque.
  528. @return true if SkAlphaType is kOpaque_SkAlphaType
  529. */
  530. bool isOpaque() const { return SkAlphaTypeIsOpaque(this->alphaType()); }
  531. /** Creates SkShader from SkImage. SkShader dimensions are taken from SkImage. SkShader uses
  532. SkShader::TileMode rules to fill drawn area outside SkImage. localMatrix permits
  533. transforming SkImage before SkCanvas matrix is applied.
  534. @param tileMode1 tiling on x-axis, one of: SkShader::kClamp_TileMode,
  535. SkShader::kRepeat_TileMode, SkShader::kMirror_TileMode
  536. @param tileMode2 tiling on y-axis, one of: SkShader::kClamp_TileMode,
  537. SkShader::kRepeat_TileMode, SkShader::kMirror_TileMode
  538. @param localMatrix SkImage transformation, or nullptr
  539. @return SkShader containing SkImage
  540. */
  541. sk_sp<SkShader> makeShader(SkShader::TileMode tileMode1, SkShader::TileMode tileMode2,
  542. const SkMatrix* localMatrix = nullptr) const;
  543. /** Creates SkShader from SkImage. SkShader dimensions are taken from SkImage. SkShader uses
  544. SkShader::kClamp_TileMode to fill drawn area outside SkImage. localMatrix permits
  545. transforming SkImage before SkCanvas matrix is applied.
  546. @param localMatrix SkImage transformation, or nullptr
  547. @return SkShader containing SkImage
  548. */
  549. sk_sp<SkShader> makeShader(const SkMatrix* localMatrix = nullptr) const {
  550. return this->makeShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, localMatrix);
  551. }
  552. /** Copies SkImage pixel address, row bytes, and SkImageInfo to pixmap, if address
  553. is available, and returns true. If pixel address is not available, return
  554. false and leave pixmap unchanged.
  555. @param pixmap storage for pixel state if pixels are readable; otherwise, ignored
  556. @return true if SkImage has direct access to pixels
  557. */
  558. bool peekPixels(SkPixmap* pixmap) const;
  559. /** Deprecated.
  560. */
  561. GrTexture* getTexture() const;
  562. /** Returns true the contents of SkImage was created on or uploaded to GPU memory,
  563. and is available as a GPU texture.
  564. @return true if SkImage is a GPU texture
  565. */
  566. bool isTextureBacked() const;
  567. /** Returns true if SkImage can be drawn on either raster surface or GPU surface.
  568. If context is nullptr, tests if SkImage draws on raster surface;
  569. otherwise, tests if SkImage draws on GPU surface associated with context.
  570. SkImage backed by GPU texture may become invalid if associated GrContext is
  571. invalid. lazy image may be invalid and may not draw to raster surface or
  572. GPU surface or both.
  573. @param context GPU context
  574. @return true if SkImage can be drawn
  575. */
  576. bool isValid(GrContext* context) const;
  577. /** Retrieves the back-end texture. If SkImage has no back-end texture, an invalid
  578. object is returned. Call GrBackendTexture::isValid to determine if the result
  579. is valid.
  580. If flushPendingGrContextIO is true, completes deferred I/O operations.
  581. If origin in not nullptr, copies location of content drawn into SkImage.
  582. @param flushPendingGrContextIO flag to flush outstanding requests
  583. @param origin storage for one of: kTopLeft_GrSurfaceOrigin,
  584. kBottomLeft_GrSurfaceOrigin; or nullptr
  585. @return back-end API texture handle; invalid on failure
  586. */
  587. GrBackendTexture getBackendTexture(bool flushPendingGrContextIO,
  588. GrSurfaceOrigin* origin = nullptr) const;
  589. /** \enum SkImage::CachingHint
  590. CachingHint selects whether Skia may internally cache SkBitmap generated by
  591. decoding SkImage, or by copying SkImage from GPU to CPU. The default behavior
  592. allows caching SkBitmap.
  593. Choose kDisallow_CachingHint if SkImage pixels are to be used only once, or
  594. if SkImage pixels reside in a cache outside of Skia, or to reduce memory pressure.
  595. Choosing kAllow_CachingHint does not ensure that pixels will be cached.
  596. SkImage pixels may not be cached if memory requirements are too large or
  597. pixels are not accessible.
  598. */
  599. enum CachingHint {
  600. kAllow_CachingHint, //!< allows internally caching decoded and copied pixels
  601. kDisallow_CachingHint, //!< disallows internally caching decoded and copied pixels
  602. };
  603. /** Copies SkRect of pixels from SkImage to dstPixels. Copy starts at offset (srcX, srcY),
  604. and does not exceed SkImage (width(), height()).
  605. dstInfo specifies width, height, SkColorType, SkAlphaType, and SkColorSpace of
  606. destination. dstRowBytes specifics the gap from one destination row to the next.
  607. Returns true if pixels are copied. Returns false if:
  608. - dstInfo.addr() equals nullptr
  609. - dstRowBytes is less than dstInfo.minRowBytes()
  610. - SkPixelRef is nullptr
  611. Pixels are copied only if pixel conversion is possible. If SkImage SkColorType is
  612. kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType() must match.
  613. If SkImage SkColorType is kGray_8_SkColorType, dstInfo.colorSpace() must match.
  614. If SkImage SkAlphaType is kOpaque_SkAlphaType, dstInfo.alphaType() must
  615. match. If SkImage SkColorSpace is nullptr, dstInfo.colorSpace() must match. Returns
  616. false if pixel conversion is not possible.
  617. srcX and srcY may be negative to copy only top or left of source. Returns
  618. false if width() or height() is zero or negative.
  619. Returns false if abs(srcX) >= Image width(), or if abs(srcY) >= Image height().
  620. If cachingHint is kAllow_CachingHint, pixels may be retained locally.
  621. If cachingHint is kDisallow_CachingHint, pixels are not added to the local cache.
  622. @param dstInfo destination width, height, SkColorType, SkAlphaType, SkColorSpace
  623. @param dstPixels destination pixel storage
  624. @param dstRowBytes destination row length
  625. @param srcX column index whose absolute value is less than width()
  626. @param srcY row index whose absolute value is less than height()
  627. @param cachingHint one of: kAllow_CachingHint, kDisallow_CachingHint
  628. @return true if pixels are copied to dstPixels
  629. */
  630. bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
  631. int srcX, int srcY, CachingHint cachingHint = kAllow_CachingHint) const;
  632. /** Copies a SkRect of pixels from SkImage to dst. Copy starts at (srcX, srcY), and
  633. does not exceed SkImage (width(), height()).
  634. dst specifies width, height, SkColorType, SkAlphaType, SkColorSpace, pixel storage,
  635. and row bytes of destination. dst.rowBytes() specifics the gap from one destination
  636. row to the next. Returns true if pixels are copied. Returns false if:
  637. - dst pixel storage equals nullptr
  638. - dst.rowBytes is less than SkImageInfo::minRowBytes
  639. - SkPixelRef is nullptr
  640. Pixels are copied only if pixel conversion is possible. If SkImage SkColorType is
  641. kGray_8_SkColorType, or kAlpha_8_SkColorType; dst.colorType() must match.
  642. If SkImage SkColorType is kGray_8_SkColorType, dst.colorSpace() must match.
  643. If SkImage SkAlphaType is kOpaque_SkAlphaType, dst.alphaType() must
  644. match. If SkImage SkColorSpace is nullptr, dst.colorSpace() must match. Returns
  645. false if pixel conversion is not possible.
  646. srcX and srcY may be negative to copy only top or left of source. Returns
  647. false if width() or height() is zero or negative.
  648. Returns false if abs(srcX) >= Image width(), or if abs(srcY) >= Image height().
  649. If cachingHint is kAllow_CachingHint, pixels may be retained locally.
  650. If cachingHint is kDisallow_CachingHint, pixels are not added to the local cache.
  651. @param dst destination SkPixmap: SkImageInfo, pixels, row bytes
  652. @param srcX column index whose absolute value is less than width()
  653. @param srcY row index whose absolute value is less than height()
  654. @param cachingHint one of: kAllow_CachingHint, kDisallow_CachingHint
  655. @return true if pixels are copied to dst
  656. */
  657. bool readPixels(const SkPixmap& dst, int srcX, int srcY,
  658. CachingHint cachingHint = kAllow_CachingHint) const;
  659. /** Copies SkImage to dst, scaling pixels to fit dst.width() and dst.height(), and
  660. converting pixels to match dst.colorType() and dst.alphaType(). Returns true if
  661. pixels are copied. Returns false if dst.addr() is nullptr, or dst.rowBytes() is
  662. less than dst SkImageInfo::minRowBytes.
  663. Pixels are copied only if pixel conversion is possible. If SkImage SkColorType is
  664. kGray_8_SkColorType, or kAlpha_8_SkColorType; dst.colorType() must match.
  665. If SkImage SkColorType is kGray_8_SkColorType, dst.colorSpace() must match.
  666. If SkImage SkAlphaType is kOpaque_SkAlphaType, dst.alphaType() must
  667. match. If SkImage SkColorSpace is nullptr, dst.colorSpace() must match. Returns
  668. false if pixel conversion is not possible.
  669. Scales the image, with filterQuality, to match dst.width() and dst.height().
  670. filterQuality kNone_SkFilterQuality is fastest, typically implemented with
  671. nearest neighbor filter. kLow_SkFilterQuality is typically implemented with
  672. bilerp filter. kMedium_SkFilterQuality is typically implemented with
  673. bilerp filter, and mip-map filter when size is reduced.
  674. kHigh_SkFilterQuality is slowest, typically implemented with bicubic filter.
  675. If cachingHint is kAllow_CachingHint, pixels may be retained locally.
  676. If cachingHint is kDisallow_CachingHint, pixels are not added to the local cache.
  677. @param dst destination SkPixmap: SkImageInfo, pixels, row bytes
  678. @param filterQuality one of: kNone_SkFilterQuality, kLow_SkFilterQuality,
  679. kMedium_SkFilterQuality, kHigh_SkFilterQuality
  680. @param cachingHint one of: kAllow_CachingHint, kDisallow_CachingHint
  681. @return true if pixels are scaled to fit dst
  682. */
  683. bool scalePixels(const SkPixmap& dst, SkFilterQuality filterQuality,
  684. CachingHint cachingHint = kAllow_CachingHint) const;
  685. /** Encodes SkImage pixels, returning result as SkData.
  686. Returns nullptr if encoding fails, or if encodedImageFormat is not supported.
  687. SkImage encoding in a format requires both building with one or more of:
  688. SK_HAS_JPEG_LIBRARY, SK_HAS_PNG_LIBRARY, SK_HAS_WEBP_LIBRARY; and platform support
  689. for the encoded format.
  690. If SK_BUILD_FOR_MAC or SK_BUILD_FOR_IOS is defined, encodedImageFormat can
  691. additionally be one of: SkEncodedImageFormat::kICO, SkEncodedImageFormat::kBMP,
  692. SkEncodedImageFormat::kGIF.
  693. quality is a platform and format specific metric trading off size and encoding
  694. error. When used, quality equaling 100 encodes with the least error. quality may
  695. be ignored by the encoder.
  696. @param encodedImageFormat one of: SkEncodedImageFormat::kJPEG, SkEncodedImageFormat::kPNG,
  697. SkEncodedImageFormat::kWEBP
  698. @param quality encoder specific metric with 100 equaling best
  699. @return encoded SkImage, or nullptr
  700. */
  701. sk_sp<SkData> encodeToData(SkEncodedImageFormat encodedImageFormat, int quality) const;
  702. /** Encodes SkImage pixels, returning result as SkData. Returns existing encoded data
  703. if present; otherwise, SkImage is encoded with SkEncodedImageFormat::kPNG. Skia
  704. must be built with SK_HAS_PNG_LIBRARY to encode SkImage.
  705. Returns nullptr if existing encoded data is missing or invalid, and
  706. encoding fails.
  707. @return encoded SkImage, or nullptr
  708. */
  709. sk_sp<SkData> encodeToData() const;
  710. /** Returns encoded SkImage pixels as SkData, if SkImage was created from supported
  711. encoded stream format. Platform support for formats vary and may require building
  712. with one or more of: SK_HAS_JPEG_LIBRARY, SK_HAS_PNG_LIBRARY, SK_HAS_WEBP_LIBRARY.
  713. Returns nullptr if SkImage contents are not encoded.
  714. @return encoded SkImage, or nullptr
  715. */
  716. sk_sp<SkData> refEncodedData() const;
  717. /** Returns subset of SkImage. subset must be fully contained by SkImage dimensions().
  718. The implementation may share pixels, or may copy them.
  719. Returns nullptr if subset is empty, or subset is not contained by bounds, or
  720. pixels in SkImage could not be read or copied.
  721. @param subset bounds of returned SkImage
  722. @return partial or full SkImage, or nullptr
  723. */
  724. sk_sp<SkImage> makeSubset(const SkIRect& subset) const;
  725. /** Returns SkImage backed by GPU texture associated with context. Returned SkImage is
  726. compatible with SkSurface created with dstColorSpace. The returned SkImage respects
  727. mipMapped setting; if mipMapped equals GrMipMapped::kYes, the backing texture
  728. allocates mip map levels. Returns original SkImage if context
  729. and dstColorSpace match and mipMapped is compatible with backing GPU texture.
  730. Returns nullptr if context is nullptr, or if SkImage was created with another
  731. GrContext.
  732. @param context GPU context
  733. @param dstColorSpace range of colors of matching SkSurface on GPU
  734. @param mipMapped whether created SkImage texture must allocate mip map levels
  735. @return created SkImage, or nullptr
  736. */
  737. sk_sp<SkImage> makeTextureImage(GrContext* context, SkColorSpace* dstColorSpace,
  738. GrMipMapped mipMapped = GrMipMapped::kNo) const;
  739. /** Returns raster image or lazy image. Copies SkImage backed by GPU texture into
  740. CPU memory if needed. Returns original SkImage if decoded in raster bitmap,
  741. or if encoded in a stream.
  742. Returns nullptr if backed by GPU texture and copy fails.
  743. @return raster image, lazy image, or nullptr
  744. */
  745. sk_sp<SkImage> makeNonTextureImage() const;
  746. /** Returns raster image. Copies SkImage backed by GPU texture into CPU memory,
  747. or decodes SkImage from lazy image. Returns original SkImage if decoded in
  748. raster bitmap.
  749. Returns nullptr if copy, decode, or pixel read fails.
  750. @return raster image, or nullptr
  751. */
  752. sk_sp<SkImage> makeRasterImage() const;
  753. /** Creates filtered SkImage. filter processes original SkImage, potentially changing
  754. color, position, and size. subset is the bounds of original SkImage processed
  755. by filter. clipBounds is the expected bounds of the filtered SkImage. outSubset
  756. is required storage for the actual bounds of the filtered SkImage. offset is
  757. required storage for translation of returned SkImage.
  758. Returns nullptr if SkImage could not be created. If nullptr is returned, outSubset
  759. and offset are undefined.
  760. Useful for animation of SkImageFilter that varies size from frame to frame.
  761. Returned SkImage is created larger than required by filter so that GPU texture
  762. can be reused with different sized effects. outSubset describes the valid bounds
  763. of GPU texture returned. offset translates the returned SkImage to keep subsequent
  764. animation frames aligned with respect to each other.
  765. @param filter how SkImage is sampled when transformed
  766. @param subset bounds of SkImage processed by filter
  767. @param clipBounds expected bounds of filtered SkImage
  768. @param outSubset storage for returned SkImage bounds
  769. @param offset storage for returned SkImage translation
  770. @return filtered SkImage, or nullptr
  771. */
  772. sk_sp<SkImage> makeWithFilter(const SkImageFilter* filter, const SkIRect& subset,
  773. const SkIRect& clipBounds, SkIRect* outSubset,
  774. SkIPoint* offset) const;
  775. /** Defines a callback function, taking one parameter of type GrBackendTexture with
  776. no return value. Function is called when back-end texture is to be released.
  777. */
  778. typedef std::function<void(GrBackendTexture)> BackendTextureReleaseProc;
  779. /** Creates a GrBackendTexture from the provided SkImage. Returns true and
  780. stores result in backendTexture and backendTextureReleaseProc if
  781. texture is created; otherwise, returns false and leaves
  782. backendTexture and backendTextureReleaseProc unmodified.
  783. Call backendTextureReleaseProc after deleting backendTexture.
  784. backendTextureReleaseProc cleans up auxiliary data related to returned
  785. backendTexture. The caller must delete returned backendTexture after use.
  786. If SkImage is both texture backed and singly referenced, image is returned in
  787. backendTexture without conversion or making a copy. SkImage is singly referenced
  788. if its was transferred solely using std::move().
  789. If SkImage is not texture backed, returns texture with SkImage contents.
  790. @param context GPU context
  791. @param image SkImage used for texture
  792. @param backendTexture storage for back-end texture
  793. @param backendTextureReleaseProc storage for clean up function
  794. @return true if back-end texture was created
  795. */
  796. static bool MakeBackendTextureFromSkImage(GrContext* context,
  797. sk_sp<SkImage> image,
  798. GrBackendTexture* backendTexture,
  799. BackendTextureReleaseProc* backendTextureReleaseProc);
  800. /** Deprecated.
  801. */
  802. enum LegacyBitmapMode {
  803. kRO_LegacyBitmapMode, //!< returned bitmap is read-only and immutable
  804. };
  805. /** Deprecated.
  806. Creates raster SkBitmap with same pixels as SkImage. If legacyBitmapMode is
  807. kRO_LegacyBitmapMode, returned bitmap is read-only and immutable.
  808. Returns true if SkBitmap is stored in bitmap. Returns false and resets bitmap if
  809. SkBitmap write did not succeed.
  810. @param bitmap storage for legacy SkBitmap
  811. @param legacyBitmapMode bitmap is read-only and immutable
  812. @return true if SkBitmap was created
  813. */
  814. bool asLegacyBitmap(SkBitmap* bitmap,
  815. LegacyBitmapMode legacyBitmapMode = kRO_LegacyBitmapMode) const;
  816. /** Returns true if SkImage is backed by an image-generator or other service that creates
  817. and caches its pixels or texture on-demand.
  818. @return true if SkImage is created as needed
  819. */
  820. bool isLazyGenerated() const;
  821. /** Creates SkImage in target SkColorSpace.
  822. Returns nullptr if SkImage could not be created.
  823. Returns original SkImage if it is in target SkColorSpace.
  824. Otherwise, converts pixels from SkImage SkColorSpace to target SkColorSpace.
  825. If SkImage colorSpace() returns nullptr, SkImage SkColorSpace is assumed to be sRGB.
  826. @param target SkColorSpace describing color range of returned SkImage
  827. @return created SkImage in target SkColorSpace
  828. */
  829. sk_sp<SkImage> makeColorSpace(sk_sp<SkColorSpace> target) const;
  830. private:
  831. SkImage(int width, int height, uint32_t uniqueID);
  832. friend class SkImage_Base;
  833. const int fWidth;
  834. const int fHeight;
  835. const uint32_t fUniqueID;
  836. typedef SkRefCnt INHERITED;
  837. };
  838. #endif