SkImagePriv.h revision 1195a28892d37ae9632e81e1bc2407cf644522d2
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 */ 7 8#ifndef SkImagePriv_DEFINED 9#define SkImagePriv_DEFINED 10 11#include "SkBitmap.h" 12#include "SkImage.h" 13 14class SkPicture; 15 16extern SkBitmap::Config SkImageInfoToBitmapConfig(const SkImageInfo&); 17extern SkBitmap::Config SkColorTypeToBitmapConfig(SkColorType); 18extern bool SkBitmapConfigToColorType(SkBitmap::Config, SkColorType* ctOut); 19 20// Call this if you explicitly want to use/share this pixelRef in the image 21extern SkImage* SkNewImageFromPixelRef(const SkImageInfo&, SkPixelRef*, 22 size_t rowBytes); 23 24/** 25 * Examines the bitmap to decide if it can share the existing pixelRef, or 26 * if it needs to make a deep-copy of the pixels. The bitmap's pixelref will 27 * be shared if either the bitmap is marked as immutable, or canSharePixelRef 28 * is true. 29 * 30 * If the bitmap's config cannot be converted into a corresponding 31 * SkImageInfo, or the bitmap's pixels cannot be accessed, this will return 32 * NULL. 33 */ 34extern SkImage* SkNewImageFromBitmap(const SkBitmap&, bool canSharePixelRef); 35 36extern void SkImagePrivDrawPicture(SkCanvas*, SkPicture*, 37 SkScalar x, SkScalar y, const SkPaint*); 38 39extern void SkImagePrivDrawPicture(SkCanvas*, SkPicture*, 40 const SkRect*, const SkRect&, const SkPaint*); 41 42/** 43 * Return an SkImage whose contents are those of the specified picture. Note: 44 * The picture itself is unmodified, and may continue to be used for recording 45 */ 46extern SkImage* SkNewImageFromPicture(const SkPicture*); 47 48static inline size_t SkImageMinRowBytes(const SkImageInfo& info) { 49 return SkAlign4(info.minRowBytes()); 50} 51 52// Given an image created from SkNewImageFromBitmap, return its pixelref. This 53// may be called to see if the surface and the image share the same pixelref, 54// in which case the surface may need to perform a copy-on-write. 55extern SkPixelRef* SkBitmapImageGetPixelRef(SkImage* rasterImage); 56 57// Given an image created with NewPicture, return its SkPicture. 58extern SkPicture* SkPictureImageGetPicture(SkImage* pictureImage); 59 60// Given an image created with NewTexture, return its GrTexture. This 61// may be called to see if the surface and the image share the same GrTexture, 62// in which case the surface may need to perform a copy-on-write. 63extern GrTexture* SkTextureImageGetTexture(SkImage* textureImage); 64 65// Update the texture wrapped by an image created with NewTexture. This 66// is called when a surface and image share the same GrTexture and the 67// surface needs to perform a copy-on-write 68extern void SkTextureImageSetTexture(SkImage* image, GrTexture* texture); 69 70#endif 71