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 |
kkinnunen | 73953e7 | 2015-02-23 22:12:12 -0800 | [diff] [blame] | 15 | extern SkImage* SkNewImageFromPixelRef(const SkImageInfo&, SkPixelRef*, |
| 16 | const SkIPoint& pixelRefOrigin, |
| 17 | size_t rowBytes, |
reed | 4af267b | 2014-11-21 08:46:37 -0800 | [diff] [blame] | 18 | const SkSurfaceProps*); |
reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 19 | |
| 20 | /** |
| 21 | * Examines the bitmap to decide if it can share the existing pixelRef, or |
fmalita | 9a5d1ab | 2015-07-27 10:27:28 -0700 | [diff] [blame^] | 22 | * if it needs to make a deep-copy of the pixels. |
| 23 | * |
| 24 | * The bitmap's pixelref will be shared if either the bitmap is marked as |
| 25 | * immutable, or forceSharePixelRef is true. Shared pixel refs are also |
| 26 | * locked when kLocked_SharedPixelRefMode is specified. |
| 27 | * |
| 28 | * Passing kLocked_SharedPixelRefMode allows the image's peekPixels() method |
| 29 | * to succeed, but it will force any lazy decodes/generators to execute if |
| 30 | * they exist on the pixelref. |
reed@google.com | 97af1a6 | 2012-08-28 12:19:02 +0000 | [diff] [blame] | 31 | * |
reed | 5617900 | 2015-07-07 06:11:19 -0700 | [diff] [blame] | 32 | * It is illegal to call this with a texture-backed bitmap. |
| 33 | * |
commit-bot@chromium.org | a3264e5 | 2014-05-30 13:26:10 +0000 | [diff] [blame] | 34 | * If the bitmap's colortype cannot be converted into a corresponding |
reed@google.com | 2bd8b81 | 2013-11-01 13:46:54 +0000 | [diff] [blame] | 35 | * SkImageInfo, or the bitmap's pixels cannot be accessed, this will return |
reed@google.com | 97af1a6 | 2012-08-28 12:19:02 +0000 | [diff] [blame] | 36 | * NULL. |
reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 37 | */ |
fmalita | 9a5d1ab | 2015-07-27 10:27:28 -0700 | [diff] [blame^] | 38 | enum SharedPixelRefMode { |
| 39 | kLocked_SharedPixelRefMode, |
| 40 | kUnlocked_SharedPixelRefMode |
| 41 | }; |
reed | 5617900 | 2015-07-07 06:11:19 -0700 | [diff] [blame] | 42 | extern SkImage* SkNewImageFromRasterBitmap(const SkBitmap&, bool forceSharePixelRef, |
fmalita | 9a5d1ab | 2015-07-27 10:27:28 -0700 | [diff] [blame^] | 43 | const SkSurfaceProps*, SharedPixelRefMode); |
reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 44 | |
reed@google.com | 2bd8b81 | 2013-11-01 13:46:54 +0000 | [diff] [blame] | 45 | static inline size_t SkImageMinRowBytes(const SkImageInfo& info) { |
reed | 759373a | 2015-07-03 21:01:10 -0700 | [diff] [blame] | 46 | size_t minRB = info.minRowBytes(); |
| 47 | if (kIndex_8_SkColorType != info.colorType()) { |
| 48 | minRB = SkAlign4(minRB); |
| 49 | } |
| 50 | return minRB; |
reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 51 | } |
| 52 | |
reed@google.com | 97af1a6 | 2012-08-28 12:19:02 +0000 | [diff] [blame] | 53 | // Given an image created from SkNewImageFromBitmap, return its pixelref. This |
| 54 | // may be called to see if the surface and the image share the same pixelref, |
| 55 | // in which case the surface may need to perform a copy-on-write. |
piotaixr | 6515175 | 2014-10-16 11:58:39 -0700 | [diff] [blame] | 56 | extern const SkPixelRef* SkBitmapImageGetPixelRef(const SkImage* rasterImage); |
reed@google.com | 97af1a6 | 2012-08-28 12:19:02 +0000 | [diff] [blame] | 57 | |
bsalomon | eaaaf0b | 2015-01-23 08:08:04 -0800 | [diff] [blame] | 58 | // When a texture is shared by a surface and an image its budgeted status is that of the |
| 59 | // surface. This function is used when the surface makes a new texture for itself in order |
| 60 | // for the orphaned image to determine whether the original texture counts against the |
| 61 | // budget or not. |
| 62 | extern void SkTextureImageApplyBudgetedDecision(SkImage* textureImage); |
| 63 | |
robertphillips@google.com | 97b6b07 | 2012-10-31 14:48:39 +0000 | [diff] [blame] | 64 | // Update the texture wrapped by an image created with NewTexture. This |
| 65 | // is called when a surface and image share the same GrTexture and the |
| 66 | // surface needs to perform a copy-on-write |
| 67 | extern void SkTextureImageSetTexture(SkImage* image, GrTexture* texture); |
| 68 | |
reed | 5617900 | 2015-07-07 06:11:19 -0700 | [diff] [blame] | 69 | GrTexture* GrDeepCopyTexture(GrTexture* src, bool isBudgeted); |
| 70 | |
reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 71 | #endif |