| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef SkImagePriv_DEFINED | 8 #ifndef SkImagePriv_DEFINED |
| 9 #define SkImagePriv_DEFINED | 9 #define SkImagePriv_DEFINED |
| 10 | 10 |
| 11 #include "SkImage.h" | 11 #include "SkImage.h" |
| 12 #include "SkSmallAllocator.h" |
| 12 #include "SkSurface.h" | 13 #include "SkSurface.h" |
| 13 | 14 |
| 14 // Call this if you explicitly want to use/share this pixelRef in the image | |
| 15 extern sk_sp<SkImage> SkMakeImageFromPixelRef(const SkImageInfo&, SkPixelRef*, | |
| 16 const SkIPoint& pixelRefOrigin, | |
| 17 size_t rowBytes); | |
| 18 | |
| 19 enum SkCopyPixelsMode { | 15 enum SkCopyPixelsMode { |
| 20 kIfMutable_SkCopyPixelsMode, //!< only copy src pixels if they are marked m
utable | 16 kIfMutable_SkCopyPixelsMode, //!< only copy src pixels if they are marked m
utable |
| 21 kAlways_SkCopyPixelsMode, //!< always copy src pixels (even if they are
marked immutable) | 17 kAlways_SkCopyPixelsMode, //!< always copy src pixels (even if they are
marked immutable) |
| 22 kNever_SkCopyPixelsMode, //!< never copy src pixels (even if they are m
arked mutable) | 18 kNever_SkCopyPixelsMode, //!< never copy src pixels (even if they are m
arked mutable) |
| 23 }; | 19 }; |
| 24 | 20 |
| 21 enum {kSkBlitterContextSize = 3332}; |
| 22 |
| 23 // Commonly used allocator. It currently is only used to allocate up to 3 object
s. The total |
| 24 // bytes requested is calculated using one of our large shaders, its context siz
e plus the size of |
| 25 // an Sk3DBlitter in SkDraw.cpp |
| 26 // Note that some contexts may contain other contexts (e.g. for compose shaders)
, but we've not |
| 27 // yet found a situation where the size below isn't big enough. |
| 28 typedef SkSmallAllocator<3, kSkBlitterContextSize> SkTBlitterAllocator; |
| 29 |
| 30 // If alloc is non-nullptr, it will be used to allocate the returned SkShader, a
nd MUST outlive |
| 31 // the SkShader. |
| 32 sk_sp<SkShader> SkMakeBitmapShader(const SkBitmap& src, SkShader::TileMode, SkSh
ader::TileMode, |
| 33 const SkMatrix* localMatrix, SkCopyPixelsMode
, |
| 34 SkTBlitterAllocator* alloc); |
| 35 |
| 36 // Call this if you explicitly want to use/share this pixelRef in the image |
| 37 extern sk_sp<SkImage> SkMakeImageFromPixelRef(const SkImageInfo&, SkPixelRef*, |
| 38 const SkIPoint& pixelRefOrigin, |
| 39 size_t rowBytes); |
| 40 |
| 25 /** | 41 /** |
| 26 * Examines the bitmap to decide if it can share the existing pixelRef, or | 42 * Examines the bitmap to decide if it can share the existing pixelRef, or |
| 27 * if it needs to make a deep-copy of the pixels. | 43 * if it needs to make a deep-copy of the pixels. |
| 28 * | 44 * |
| 29 * The bitmap's pixelref will be shared if either the bitmap is marked as | 45 * The bitmap's pixelref will be shared if either the bitmap is marked as |
| 30 * immutable, or CopyPixelsMode allows it. Shared pixel refs are also | 46 * immutable, or CopyPixelsMode allows it. Shared pixel refs are also |
| 31 * locked when kLocked_SharedPixelRefMode is specified. | 47 * locked when kLocked_SharedPixelRefMode is specified. |
| 32 * | 48 * |
| 33 * Passing kLocked_SharedPixelRefMode allows the image's peekPixels() method | 49 * Passing kLocked_SharedPixelRefMode allows the image's peekPixels() method |
| 34 * to succeed, but it will force any lazy decodes/generators to execute if | 50 * to succeed, but it will force any lazy decodes/generators to execute if |
| 35 * they exist on the pixelref. | 51 * they exist on the pixelref. |
| 36 * | 52 * |
| 37 * It is illegal to call this with a texture-backed bitmap. | 53 * It is illegal to call this with a texture-backed bitmap. |
| 38 * | 54 * |
| 39 * If the bitmap's colortype cannot be converted into a corresponding | 55 * If the bitmap's colortype cannot be converted into a corresponding |
| 40 * SkImageInfo, or the bitmap's pixels cannot be accessed, this will return | 56 * SkImageInfo, or the bitmap's pixels cannot be accessed, this will return |
| 41 * nullptr. | 57 * nullptr. |
| 42 */ | 58 */ |
| 43 extern sk_sp<SkImage> SkMakeImageFromRasterBitmap(const SkBitmap&, SkCopyPixelsM
ode); | 59 extern sk_sp<SkImage> SkMakeImageFromRasterBitmap(const SkBitmap&, SkCopyPixelsM
ode, |
| 60 SkTBlitterAllocator* = nullptr
); |
| 44 | 61 |
| 45 // Given an image created from SkNewImageFromBitmap, return its pixelref. This | 62 // 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, | 63 // 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. | 64 // in which case the surface may need to perform a copy-on-write. |
| 48 extern const SkPixelRef* SkBitmapImageGetPixelRef(const SkImage* rasterImage); | 65 extern const SkPixelRef* SkBitmapImageGetPixelRef(const SkImage* rasterImage); |
| 49 | 66 |
| 50 // When a texture is shared by a surface and an image its budgeted status is tha
t of the | 67 // When a texture is shared by a surface and an image its budgeted status is tha
t of the |
| 51 // surface. This function is used when the surface makes a new texture for itsel
f in order | 68 // surface. This function is used when the surface makes a new texture for itsel
f in order |
| 52 // for the orphaned image to determine whether the original texture counts again
st the | 69 // for the orphaned image to determine whether the original texture counts again
st the |
| 53 // budget or not. | 70 // budget or not. |
| 54 extern void SkTextureImageApplyBudgetedDecision(SkImage* textureImage); | 71 extern void SkTextureImageApplyBudgetedDecision(SkImage* textureImage); |
| 55 | 72 |
| 56 // Update the texture wrapped by an image created with NewTexture. This | 73 // 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 | 74 // is called when a surface and image share the same GrTexture and the |
| 58 // surface needs to perform a copy-on-write | 75 // surface needs to perform a copy-on-write |
| 59 extern void SkTextureImageSetTexture(SkImage* image, GrTexture* texture); | 76 extern void SkTextureImageSetTexture(SkImage* image, GrTexture* texture); |
| 60 | 77 |
| 61 GrTexture* GrDeepCopyTexture(GrTexture* src, SkBudgeted); | 78 GrTexture* GrDeepCopyTexture(GrTexture* src, SkBudgeted); |
| 62 | 79 |
| 63 #endif | 80 #endif |
| OLD | NEW |