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" |
| 12 | |
reed@google.com | 97af1a6 | 2012-08-28 12:19:02 +0000 | [diff] [blame] | 13 | // Call this if you explicitly want to use/share this pixelRef in the image |
reed | 4af267b | 2014-11-21 08:46:37 -0800 | [diff] [blame] | 14 | extern SkImage* SkNewImageFromPixelRef(const SkImageInfo&, SkPixelRef*, size_t rowBytes, |
| 15 | const SkSurfaceProps*); |
reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 16 | |
| 17 | /** |
| 18 | * Examines the bitmap to decide if it can share the existing pixelRef, or |
reed@google.com | 97af1a6 | 2012-08-28 12:19:02 +0000 | [diff] [blame] | 19 | * if it needs to make a deep-copy of the pixels. The bitmap's pixelref will |
| 20 | * be shared if either the bitmap is marked as immutable, or canSharePixelRef |
| 21 | * is true. |
| 22 | * |
commit-bot@chromium.org | a3264e5 | 2014-05-30 13:26:10 +0000 | [diff] [blame] | 23 | * If the bitmap's colortype cannot be converted into a corresponding |
reed@google.com | 2bd8b81 | 2013-11-01 13:46:54 +0000 | [diff] [blame] | 24 | * 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] | 25 | * NULL. |
reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 26 | */ |
reed | 4af267b | 2014-11-21 08:46:37 -0800 | [diff] [blame] | 27 | extern SkImage* SkNewImageFromBitmap(const SkBitmap&, bool canSharePixelRef, const SkSurfaceProps*); |
reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 28 | |
reed@google.com | 2bd8b81 | 2013-11-01 13:46:54 +0000 | [diff] [blame] | 29 | static inline size_t SkImageMinRowBytes(const SkImageInfo& info) { |
reed@google.com | 9230ea2 | 2013-12-09 22:01:03 +0000 | [diff] [blame] | 30 | return SkAlign4(info.minRowBytes()); |
reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 31 | } |
| 32 | |
reed@google.com | 97af1a6 | 2012-08-28 12:19:02 +0000 | [diff] [blame] | 33 | // Given an image created from SkNewImageFromBitmap, return its pixelref. This |
| 34 | // may be called to see if the surface and the image share the same pixelref, |
| 35 | // in which case the surface may need to perform a copy-on-write. |
piotaixr | 6515175 | 2014-10-16 11:58:39 -0700 | [diff] [blame] | 36 | extern const SkPixelRef* SkBitmapImageGetPixelRef(const SkImage* rasterImage); |
reed@google.com | 97af1a6 | 2012-08-28 12:19:02 +0000 | [diff] [blame] | 37 | |
robertphillips@google.com | 97b6b07 | 2012-10-31 14:48:39 +0000 | [diff] [blame] | 38 | // Given an image created with NewTexture, return its GrTexture. This |
| 39 | // may be called to see if the surface and the image share the same GrTexture, |
| 40 | // in which case the surface may need to perform a copy-on-write. |
junov@chromium.org | 45c3db8 | 2013-04-11 17:52:05 +0000 | [diff] [blame] | 41 | extern GrTexture* SkTextureImageGetTexture(SkImage* textureImage); |
robertphillips@google.com | 97b6b07 | 2012-10-31 14:48:39 +0000 | [diff] [blame] | 42 | |
| 43 | // Update the texture wrapped by an image created with NewTexture. This |
| 44 | // is called when a surface and image share the same GrTexture and the |
| 45 | // surface needs to perform a copy-on-write |
| 46 | extern void SkTextureImageSetTexture(SkImage* image, GrTexture* texture); |
| 47 | |
reed | 3f10b9d | 2014-11-21 10:27:53 -0800 | [diff] [blame] | 48 | extern SkImage* SkNewImageFromBitmapTexture(const SkBitmap&, int sampleCountForNewSurfaces); |
reed | 4af267b | 2014-11-21 08:46:37 -0800 | [diff] [blame] | 49 | |
reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 50 | #endif |