SkImagePriv.h revision cae54f1f211e3c293ef9afb968067d06ca0ea23d
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 14extern SkBitmap::Config SkImageInfoToBitmapConfig(const SkImageInfo&); 15 16// Call this if you explicitly want to use/share this pixelRef in the image 17extern SkImage* SkNewImageFromPixelRef(const SkImageInfo&, SkPixelRef*, 18 size_t rowBytes); 19 20/** 21 * Examines the bitmap to decide if it can share the existing pixelRef, or 22 * if it needs to make a deep-copy of the pixels. The bitmap's pixelref will 23 * be shared if either the bitmap is marked as immutable, or canSharePixelRef 24 * is true. 25 * 26 * If the bitmap's config cannot be converted into a corresponding 27 * SkImageInfo, or the bitmap's pixels cannot be accessed, this will return 28 * NULL. 29 */ 30extern SkImage* SkNewImageFromBitmap(const SkBitmap&, bool canSharePixelRef); 31 32static inline size_t SkImageMinRowBytes(const SkImageInfo& info) { 33 return SkAlign4(info.minRowBytes()); 34} 35 36// Given an image created from SkNewImageFromBitmap, return its pixelref. This 37// may be called to see if the surface and the image share the same pixelref, 38// in which case the surface may need to perform a copy-on-write. 39extern SkPixelRef* SkBitmapImageGetPixelRef(SkImage* rasterImage); 40 41// Given an image created with NewTexture, return its GrTexture. This 42// may be called to see if the surface and the image share the same GrTexture, 43// in which case the surface may need to perform a copy-on-write. 44extern GrTexture* SkTextureImageGetTexture(SkImage* textureImage); 45 46// Update the texture wrapped by an image created with NewTexture. This 47// is called when a surface and image share the same GrTexture and the 48// surface needs to perform a copy-on-write 49extern void SkTextureImageSetTexture(SkImage* image, GrTexture* texture); 50 51#endif 52