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