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
160a657bbc2c6fc9daf699942e023050536d5ec95fDerek Sollenbergerextern SkBitmap::Config SkImageInfoToBitmapConfig(const SkImageInfo&);
1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// Call this if you explicitly want to use/share this pixelRef in the image
190a657bbc2c6fc9daf699942e023050536d5ec95fDerek Sollenbergerextern SkImage* SkNewImageFromPixelRef(const SkImageInfo&, SkPixelRef*,
2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                                       size_t rowBytes);
2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/**
2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *  Examines the bitmap to decide if it can share the existing pixelRef, or
2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *  if it needs to make a deep-copy of the pixels. The bitmap's pixelref will
2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *  be shared if either the bitmap is marked as immutable, or canSharePixelRef
2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *  is true.
2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *
2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *  If the bitmap's config cannot be converted into a corresponding
290a657bbc2c6fc9daf699942e023050536d5ec95fDerek Sollenberger *  SkImageInfo, or the bitmap's pixels cannot be accessed, this will return
3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *  NULL.
3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */
3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruextern SkImage* SkNewImageFromBitmap(const SkBitmap&, bool canSharePixelRef);
3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruextern void SkImagePrivDrawPicture(SkCanvas*, SkPicture*,
3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                                   SkScalar x, SkScalar y, const SkPaint*);
3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
3758190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenbergerextern void SkImagePrivDrawPicture(SkCanvas*, SkPicture*,
3858190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger                                   const SkRect*, const SkRect&, const SkPaint*);
3958190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger
4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/**
4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *  Return an SkImage whose contents are those of the specified picture. Note:
4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *  The picture itself is unmodified, and may continue to be used for recording
4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */
4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruextern SkImage* SkNewImageFromPicture(const SkPicture*);
4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
460a657bbc2c6fc9daf699942e023050536d5ec95fDerek Sollenbergerstatic inline size_t SkImageMinRowBytes(const SkImageInfo& info) {
47910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger    return SkAlign4(info.minRowBytes());
4880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
5080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// Given an image created from SkNewImageFromBitmap, return its pixelref. This
5180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// may be called to see if the surface and the image share the same pixelref,
5280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// in which case the surface may need to perform a copy-on-write.
5380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruextern SkPixelRef* SkBitmapImageGetPixelRef(SkImage* rasterImage);
5480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
557839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger// Given an image created with NewPicture, return its SkPicture.
567839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenbergerextern SkPicture* SkPictureImageGetPicture(SkImage* pictureImage);
577839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger
58363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger// Given an image created with NewTexture, return its GrTexture. This
59363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger// may be called to see if the surface and the image share the same GrTexture,
60363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger// in which case the surface may need to perform a copy-on-write.
617839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenbergerextern GrTexture* SkTextureImageGetTexture(SkImage* textureImage);
62363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger
63363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger// Update the texture wrapped by an image created with NewTexture. This
64363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger// is called when a surface and image share the same GrTexture and the
65363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger// surface needs to perform a copy-on-write
66363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenbergerextern void SkTextureImageSetTexture(SkImage* image, GrTexture* texture);
67363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger
6880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif
69