180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/* 280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2012 Google Inc. 380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * 480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be 580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file. 680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifndef SkImagePriv_DEFINED 980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define SkImagePriv_DEFINED 1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkBitmap.h" 1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkImage.h" 1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass SkPicture; 1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruextern SkBitmap::Config SkImageInfoToBitmapConfig(const SkImage::Info&, 1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru bool* isOpaque); 1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruextern int SkImageBytesPerPixel(SkImage::ColorType); 2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruextern bool SkBitmapToImageInfo(const SkBitmap&, SkImage::Info*); 2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// Call this if you explicitly want to use/share this pixelRef in the image 2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruextern SkImage* SkNewImageFromPixelRef(const SkImage::Info&, SkPixelRef*, 2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru size_t rowBytes); 2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/** 2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Examines the bitmap to decide if it can share the existing pixelRef, or 2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * if it needs to make a deep-copy of the pixels. The bitmap's pixelref will 3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * be shared if either the bitmap is marked as immutable, or canSharePixelRef 3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * is true. 3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * 3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * If the bitmap's config cannot be converted into a corresponding 3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * SkImage::Info, or the bitmap's pixels cannot be accessed, this will return 3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * NULL. 3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruextern SkImage* SkNewImageFromBitmap(const SkBitmap&, bool canSharePixelRef); 3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruextern void SkImagePrivDrawPicture(SkCanvas*, SkPicture*, 4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkScalar x, SkScalar y, const SkPaint*); 4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 4258190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenbergerextern void SkImagePrivDrawPicture(SkCanvas*, SkPicture*, 4358190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger const SkRect*, const SkRect&, const SkPaint*); 4458190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger 4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/** 4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Return an SkImage whose contents are those of the specified picture. Note: 4780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * The picture itself is unmodified, and may continue to be used for recording 4880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruextern SkImage* SkNewImageFromPicture(const SkPicture*); 5080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 5180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querustatic inline size_t SkImageMinRowBytes(const SkImage::Info& info) { 5280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru size_t rb = info.fWidth * SkImageBytesPerPixel(info.fColorType); 5380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return SkAlign4(rb); 5480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 5580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 5680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// Given an image created from SkNewImageFromBitmap, return its pixelref. This 5780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// may be called to see if the surface and the image share the same pixelref, 5880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// in which case the surface may need to perform a copy-on-write. 5980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruextern SkPixelRef* SkBitmapImageGetPixelRef(SkImage* rasterImage); 6080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 617839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger// Given an image created with NewPicture, return its SkPicture. 627839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenbergerextern SkPicture* SkPictureImageGetPicture(SkImage* pictureImage); 637839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger 64363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger// Given an image created with NewTexture, return its GrTexture. This 65363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger// may be called to see if the surface and the image share the same GrTexture, 66363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger// in which case the surface may need to perform a copy-on-write. 677839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenbergerextern GrTexture* SkTextureImageGetTexture(SkImage* textureImage); 68363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger 69363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger// Update the texture wrapped by an image created with NewTexture. This 70363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger// is called when a surface and image share the same GrTexture and the 71363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger// surface needs to perform a copy-on-write 72363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenbergerextern void SkTextureImageSetTexture(SkImage* image, GrTexture* texture); 73363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger 7480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 75