reed@google.com | 58b21ec | 2012-07-30 18:20:12 +0000 | [diff] [blame] | 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 | */ |
reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 7 | |
| 8 | #ifndef SkImagePriv_DEFINED |
| 9 | #define SkImagePriv_DEFINED |
| 10 | |
reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 11 | #include "SkImage.h" |
bsalomon | eaaaf0b | 2015-01-23 08:08:04 -0800 | [diff] [blame] | 12 | #include "SkSurface.h" |
reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 13 | |
reed@google.com | 97af1a6 | 2012-08-28 12:19:02 +0000 | [diff] [blame] | 14 | // Call this if you explicitly want to use/share this pixelRef in the image |
reed | 7fb4f8b | 2016-03-11 04:33:52 -0800 | [diff] [blame] | 15 | extern sk_sp<SkImage> SkMakeImageFromPixelRef(const SkImageInfo&, SkPixelRef*, |
| 16 | const SkIPoint& pixelRefOrigin, |
| 17 | size_t rowBytes); |
reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 18 | |
reed | 1ec04d9 | 2016-08-05 12:07:41 -0700 | [diff] [blame^] | 19 | enum SkCopyPixelsMode { |
| 20 | kIfMutable_SkCopyPixelsMode, //!< only copy src pixels if they are marked mutable |
| 21 | kAlways_SkCopyPixelsMode, //!< always copy src pixels (even if they are marked immutable) |
| 22 | kNever_SkCopyPixelsMode, //!< never copy src pixels (even if they are marked mutable) |
| 23 | }; |
| 24 | |
reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 25 | /** |
| 26 | * Examines the bitmap to decide if it can share the existing pixelRef, or |
fmalita | 9a5d1ab | 2015-07-27 10:27:28 -0700 | [diff] [blame] | 27 | * if it needs to make a deep-copy of the pixels. |
| 28 | * |
| 29 | * The bitmap's pixelref will be shared if either the bitmap is marked as |
reed | 1ec04d9 | 2016-08-05 12:07:41 -0700 | [diff] [blame^] | 30 | * immutable, or CopyPixelsMode allows it. Shared pixel refs are also |
fmalita | 9a5d1ab | 2015-07-27 10:27:28 -0700 | [diff] [blame] | 31 | * locked when kLocked_SharedPixelRefMode is specified. |
| 32 | * |
| 33 | * Passing kLocked_SharedPixelRefMode allows the image's peekPixels() method |
| 34 | * to succeed, but it will force any lazy decodes/generators to execute if |
| 35 | * they exist on the pixelref. |
reed@google.com | 97af1a6 | 2012-08-28 12:19:02 +0000 | [diff] [blame] | 36 | * |
reed | 5617900 | 2015-07-07 06:11:19 -0700 | [diff] [blame] | 37 | * It is illegal to call this with a texture-backed bitmap. |
| 38 | * |
commit-bot@chromium.org | a3264e5 | 2014-05-30 13:26:10 +0000 | [diff] [blame] | 39 | * If the bitmap's colortype cannot be converted into a corresponding |
reed@google.com | 2bd8b81 | 2013-11-01 13:46:54 +0000 | [diff] [blame] | 40 | * SkImageInfo, or the bitmap's pixels cannot be accessed, this will return |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 41 | * nullptr. |
reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 42 | */ |
reed | 1ec04d9 | 2016-08-05 12:07:41 -0700 | [diff] [blame^] | 43 | extern sk_sp<SkImage> SkMakeImageFromRasterBitmap(const SkBitmap&, SkCopyPixelsMode); |
reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 44 | |
reed@google.com | 97af1a6 | 2012-08-28 12:19:02 +0000 | [diff] [blame] | 45 | // Given an image created from SkNewImageFromBitmap, return its pixelref. This |
| 46 | // may be called to see if the surface and the image share the same pixelref, |
| 47 | // in which case the surface may need to perform a copy-on-write. |
piotaixr | 6515175 | 2014-10-16 11:58:39 -0700 | [diff] [blame] | 48 | extern const SkPixelRef* SkBitmapImageGetPixelRef(const SkImage* rasterImage); |
reed@google.com | 97af1a6 | 2012-08-28 12:19:02 +0000 | [diff] [blame] | 49 | |
bsalomon | eaaaf0b | 2015-01-23 08:08:04 -0800 | [diff] [blame] | 50 | // When a texture is shared by a surface and an image its budgeted status is that of the |
| 51 | // surface. This function is used when the surface makes a new texture for itself in order |
| 52 | // for the orphaned image to determine whether the original texture counts against the |
| 53 | // budget or not. |
| 54 | extern void SkTextureImageApplyBudgetedDecision(SkImage* textureImage); |
| 55 | |
robertphillips@google.com | 97b6b07 | 2012-10-31 14:48:39 +0000 | [diff] [blame] | 56 | // Update the texture wrapped by an image created with NewTexture. This |
| 57 | // is called when a surface and image share the same GrTexture and the |
| 58 | // surface needs to perform a copy-on-write |
| 59 | extern void SkTextureImageSetTexture(SkImage* image, GrTexture* texture); |
| 60 | |
bsalomon | 5ec26ae | 2016-02-25 08:33:02 -0800 | [diff] [blame] | 61 | GrTexture* GrDeepCopyTexture(GrTexture* src, SkBudgeted); |
reed | 5617900 | 2015-07-07 06:11:19 -0700 | [diff] [blame] | 62 | |
reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 63 | #endif |