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 | |
| 11 | #include "SkBitmap.h" |
| 12 | #include "SkImage.h" |
| 13 | |
mike@reedtribe.org | 70e3590 | 2012-07-29 20:38:16 +0000 | [diff] [blame] | 14 | class SkPicture; |
| 15 | |
reed@google.com | 2bd8b81 | 2013-11-01 13:46:54 +0000 | [diff] [blame] | 16 | extern SkBitmap::Config SkImageInfoToBitmapConfig(const SkImageInfo&); |
reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 17 | |
reed@google.com | 97af1a6 | 2012-08-28 12:19:02 +0000 | [diff] [blame] | 18 | // Call this if you explicitly want to use/share this pixelRef in the image |
reed@google.com | 2bd8b81 | 2013-11-01 13:46:54 +0000 | [diff] [blame] | 19 | extern SkImage* SkNewImageFromPixelRef(const SkImageInfo&, SkPixelRef*, |
reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 20 | size_t rowBytes); |
| 21 | |
| 22 | /** |
| 23 | * 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] | 24 | * if it needs to make a deep-copy of the pixels. The bitmap's pixelref will |
| 25 | * be shared if either the bitmap is marked as immutable, or canSharePixelRef |
| 26 | * is true. |
| 27 | * |
| 28 | * If the bitmap's config cannot be converted into a corresponding |
reed@google.com | 2bd8b81 | 2013-11-01 13:46:54 +0000 | [diff] [blame] | 29 | * 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] | 30 | * NULL. |
reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 31 | */ |
reed@google.com | 97af1a6 | 2012-08-28 12:19:02 +0000 | [diff] [blame] | 32 | extern SkImage* SkNewImageFromBitmap(const SkBitmap&, bool canSharePixelRef); |
reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 33 | |
mike@reedtribe.org | 70e3590 | 2012-07-29 20:38:16 +0000 | [diff] [blame] | 34 | extern void SkImagePrivDrawPicture(SkCanvas*, SkPicture*, |
| 35 | SkScalar x, SkScalar y, const SkPaint*); |
reed@google.com | 9ea5a3b | 2012-07-30 21:03:46 +0000 | [diff] [blame] | 36 | |
commit-bot@chromium.org | dfec28d | 2013-07-23 15:52:16 +0000 | [diff] [blame] | 37 | extern void SkImagePrivDrawPicture(SkCanvas*, SkPicture*, |
| 38 | const SkRect*, const SkRect&, const SkPaint*); |
| 39 | |
reed@google.com | 9ea5a3b | 2012-07-30 21:03:46 +0000 | [diff] [blame] | 40 | /** |
| 41 | * Return an SkImage whose contents are those of the specified picture. Note: |
| 42 | * The picture itself is unmodified, and may continue to be used for recording |
| 43 | */ |
| 44 | extern SkImage* SkNewImageFromPicture(const SkPicture*); |
mike@reedtribe.org | 70e3590 | 2012-07-29 20:38:16 +0000 | [diff] [blame] | 45 | |
reed@google.com | 2bd8b81 | 2013-11-01 13:46:54 +0000 | [diff] [blame] | 46 | static inline size_t SkImageMinRowBytes(const SkImageInfo& info) { |
reed@google.com | 9230ea2 | 2013-12-09 22:01:03 +0000 | [diff] [blame^] | 47 | return SkAlign4(info.minRowBytes()); |
reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 48 | } |
| 49 | |
reed@google.com | 97af1a6 | 2012-08-28 12:19:02 +0000 | [diff] [blame] | 50 | // Given an image created from SkNewImageFromBitmap, return its pixelref. This |
| 51 | // may be called to see if the surface and the image share the same pixelref, |
| 52 | // in which case the surface may need to perform a copy-on-write. |
| 53 | extern SkPixelRef* SkBitmapImageGetPixelRef(SkImage* rasterImage); |
| 54 | |
junov@chromium.org | 45c3db8 | 2013-04-11 17:52:05 +0000 | [diff] [blame] | 55 | // Given an image created with NewPicture, return its SkPicture. |
| 56 | extern SkPicture* SkPictureImageGetPicture(SkImage* pictureImage); |
| 57 | |
robertphillips@google.com | 97b6b07 | 2012-10-31 14:48:39 +0000 | [diff] [blame] | 58 | // Given an image created with NewTexture, return its GrTexture. This |
| 59 | // may be called to see if the surface and the image share the same GrTexture, |
| 60 | // 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] | 61 | extern GrTexture* SkTextureImageGetTexture(SkImage* textureImage); |
robertphillips@google.com | 97b6b07 | 2012-10-31 14:48:39 +0000 | [diff] [blame] | 62 | |
| 63 | // Update the texture wrapped by an image created with NewTexture. This |
| 64 | // is called when a surface and image share the same GrTexture and the |
| 65 | // surface needs to perform a copy-on-write |
| 66 | extern void SkTextureImageSetTexture(SkImage* image, GrTexture* texture); |
| 67 | |
reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 68 | #endif |