18a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/* 2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2006 The Android Open Source Project 38a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * 4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file. 68a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 78a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifndef SkBitmap_DEFINED 98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define SkBitmap_DEFINED 108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkColor.h" 1264a0ec36555352ec31aa7c5a7630a5d042b010badjsollen@google.com#include "SkColorTable.h" 133443fd88862e25199973c2e98075d2e12ef21be0reed@google.com#include "SkImageInfo.h" 148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkPoint.h" 158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkRefCnt.h" 168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 17dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.orgstruct SkMask; 188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstruct SkIRect; 19fb2d3c69816253ab7d2df576718c252ae1158c65reed@google.comstruct SkRect; 208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkPaint; 218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkPixelRef; 229ebcac54635cde63110d73ad7c43d70772e7872freed@google.comclass SkPixelRefFactory; 238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkRegion; 2476f9e938df0b5826fd4c80b854ceafaf385cfbe1robertphillips@google.comclass SkString; 25b8d00db075b5ea09e353508a26ef5ced50722a6ccommit-bot@chromium.orgclass GrTexture; 26ce4e53a2347040a3c145768c193a7a7958c0d4ecreed@android.com 278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** \class SkBitmap 288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com The SkBitmap class specifies a raster bitmap. A bitmap has an integer width 30ddd014e65264e3f18b2d4305dd2fbc81549f5180reed and height, and a format (colortype), and a pointer to the actual pixels. 314b33d28eb369622964d22d5cc4a6e3f0eb11a14ctomhudson@google.com Bitmaps can be drawn into a SkCanvas, but they are also used to specify the 324b33d28eb369622964d22d5cc4a6e3f0eb11a14ctomhudson@google.com target of a SkCanvas' drawing operations. 334b33d28eb369622964d22d5cc4a6e3f0eb11a14ctomhudson@google.com A const SkBitmap exposes getAddr(), which lets a caller write its pixels; 344b33d28eb369622964d22d5cc4a6e3f0eb11a14ctomhudson@google.com the constness is considered to apply to the bitmap's configuration, not 354b33d28eb369622964d22d5cc4a6e3f0eb11a14ctomhudson@google.com its contents. 368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/ 377ffb1b21abcc7bbed5a0fc711f6dd7b9dbb4f577ctguil@chromium.orgclass SK_API SkBitmap { 388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 39eddb02c82d6e35a05f84798b23aac48a446c1aa6commit-bot@chromium.org class SK_API Allocator; 408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 415dd510f1d277a31752a4c6046c4e42385605a393reed@google.com /** 425dd510f1d277a31752a4c6046c4e42385605a393reed@google.com * Default construct creates a bitmap with zero width and height, and no pixels. 43ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * Its colortype is set to kUnknown_SkColorType. 445dd510f1d277a31752a4c6046c4e42385605a393reed@google.com */ 458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBitmap(); 465dd510f1d277a31752a4c6046c4e42385605a393reed@google.com 475dd510f1d277a31752a4c6046c4e42385605a393reed@google.com /** 485dd510f1d277a31752a4c6046c4e42385605a393reed@google.com * Copy the settings from the src into this bitmap. If the src has pixels 495dd510f1d277a31752a4c6046c4e42385605a393reed@google.com * allocated, they will be shared, not copied, so that the two bitmaps will 505dd510f1d277a31752a4c6046c4e42385605a393reed@google.com * reference the same memory for the pixels. If a deep copy is needed, 515dd510f1d277a31752a4c6046c4e42385605a393reed@google.com * where the new bitmap has its own separate copy of the pixels, use 525dd510f1d277a31752a4c6046c4e42385605a393reed@google.com * deepCopyTo(). 535dd510f1d277a31752a4c6046c4e42385605a393reed@google.com */ 548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBitmap(const SkBitmap& src); 555dd510f1d277a31752a4c6046c4e42385605a393reed@google.com 568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ~SkBitmap(); 578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Copies the src bitmap into this bitmap. Ownership of the src bitmap's pixels remains 598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com with the src bitmap. 608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBitmap& operator=(const SkBitmap& src); 628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Swap the fields of the two bitmaps. This routine is guaranteed to never fail or throw. 638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // This method is not exported to java. 658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void swap(SkBitmap& other); 66f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 6761e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org /////////////////////////////////////////////////////////////////////////// 6861e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org 6961e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org const SkImageInfo& info() const { return fInfo; } 7061e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org 71e5ea500d4714a7d84de2bf913e81be3b65d2de68reed int width() const { return fInfo.width(); } 72e5ea500d4714a7d84de2bf913e81be3b65d2de68reed int height() const { return fInfo.height(); } 73e5ea500d4714a7d84de2bf913e81be3b65d2de68reed SkColorType colorType() const { return fInfo.colorType(); } 74e5ea500d4714a7d84de2bf913e81be3b65d2de68reed SkAlphaType alphaType() const { return fInfo.alphaType(); } 75fa1e8a7cefd71f7b75f0b85f8eefe111814dd86fjvanverth SkColorProfileType profileType() const { return fInfo.profileType(); } 7661e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org 77ddd014e65264e3f18b2d4305dd2fbc81549f5180reed /** 78ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * Return the number of bytes per pixel based on the colortype. If the colortype is 79ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * kUnknown_SkColorType, then 0 is returned. 8061e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org */ 8161e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org int bytesPerPixel() const { return fInfo.bytesPerPixel(); } 8261e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org 83ddd014e65264e3f18b2d4305dd2fbc81549f5180reed /** 84ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * Return the rowbytes expressed as a number of pixels (like width and height). 85ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * If the colortype is kUnknown_SkColorType, then 0 is returned. 8661e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org */ 8761e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org int rowBytesAsPixels() const { 8861e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org return fRowBytes >> this->shiftPerPixel(); 8961e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org } 9061e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org 91ddd014e65264e3f18b2d4305dd2fbc81549f5180reed /** 92ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * Return the shift amount per pixel (i.e. 0 for 1-byte per pixel, 1 for 2-bytes per pixel 93ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * colortypes, 2 for 4-bytes per pixel colortypes). Return 0 for kUnknown_SkColorType. 9461e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org */ 9561e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org int shiftPerPixel() const { return this->bytesPerPixel() >> 1; } 9661e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org 9761e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org /////////////////////////////////////////////////////////////////////////// 9861e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org 998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return true iff the bitmap has empty dimensions. 10050b393a768c0311b3210f723325fd27bf161136bcommit-bot@chromium.org * Hey! Before you use this, see if you really want to know drawsNothing() instead. 10150b393a768c0311b3210f723325fd27bf161136bcommit-bot@chromium.org */ 10261e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org bool empty() const { return fInfo.isEmpty(); } 103f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 104c84b8335ee4fd864c30a4703afc643cf4b5010d9djsollen@google.com /** Return true iff the bitmap has no pixelref. Note: this can return true even if the 10550b393a768c0311b3210f723325fd27bf161136bcommit-bot@chromium.org * dimensions of the bitmap are > 0 (see empty()). 10650b393a768c0311b3210f723325fd27bf161136bcommit-bot@chromium.org * Hey! Before you use this, see if you really want to know drawsNothing() instead. 10750b393a768c0311b3210f723325fd27bf161136bcommit-bot@chromium.org */ 108c84b8335ee4fd864c30a4703afc643cf4b5010d9djsollen@google.com bool isNull() const { return NULL == fPixelRef; } 1098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11050b393a768c0311b3210f723325fd27bf161136bcommit-bot@chromium.org /** Return true iff drawing this bitmap has no effect. 11150b393a768c0311b3210f723325fd27bf161136bcommit-bot@chromium.org */ 11250b393a768c0311b3210f723325fd27bf161136bcommit-bot@chromium.org bool drawsNothing() const { return this->empty() || this->isNull(); } 11350b393a768c0311b3210f723325fd27bf161136bcommit-bot@chromium.org 1144469938e92d779dff05e745559e67907bbf21e78reed@google.com /** Return the number of bytes between subsequent rows of the bitmap. */ 1150ba4bf427acbd7707d04192a98c77ef194a0f25ascroggo@google.com size_t rowBytes() const { return fRowBytes; } 116f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 117383a697692cf46951fd451f6f4c3d03634a6a1cbreed@google.com /** 118383a697692cf46951fd451f6f4c3d03634a6a1cbreed@google.com * Set the bitmap's alphaType, returning true on success. If false is 119383a697692cf46951fd451f6f4c3d03634a6a1cbreed@google.com * returned, then the specified new alphaType is incompatible with the 120ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * colortype, and the current alphaType is unchanged. 1210e8d0d6cdc2e02946b099006d0a47e60764905e5commit-bot@chromium.org * 1220e8d0d6cdc2e02946b099006d0a47e60764905e5commit-bot@chromium.org * Note: this changes the alphatype for the underlying pixels, which means 1230e8d0d6cdc2e02946b099006d0a47e60764905e5commit-bot@chromium.org * that all bitmaps that might be sharing (subsets of) the pixels will 124c1587f94a77eaafe257a6ecf504364d40362c66areed@google.com * be affected. 125383a697692cf46951fd451f6f4c3d03634a6a1cbreed@google.com */ 126383a697692cf46951fd451f6f4c3d03634a6a1cbreed@google.com bool setAlphaType(SkAlphaType); 127383a697692cf46951fd451f6f4c3d03634a6a1cbreed@google.com 1288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the address of the pixels for this SkBitmap. 1298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void* getPixels() const { return fPixels; } 1318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the byte size of the pixels, based on the height and rowBytes. 1338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Note this truncates the result to 32bits. Call getSize64() to detect 1348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if the real size exceeds 32bits. 1358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 136e5ea500d4714a7d84de2bf913e81be3b65d2de68reed size_t getSize() const { return fInfo.height() * fRowBytes; } 137f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 13886bff1f008308267c4ff75456b202a9cf60c6193wjmaclean@chromium.org /** Return the number of bytes from the pointer returned by getPixels() 13986bff1f008308267c4ff75456b202a9cf60c6193wjmaclean@chromium.org to the end of the allocated space in the buffer. Required in 140d27fe34d1eb7640bb17062aa8529283e297de18eepoger@google.com cases where extractSubset has been called. 14186bff1f008308267c4ff75456b202a9cf60c6193wjmaclean@chromium.org */ 14261e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org size_t getSafeSize() const { return fInfo.getSafeSize(fRowBytes); } 14386bff1f008308267c4ff75456b202a9cf60c6193wjmaclean@chromium.org 14457212f9469c8056bab3c85243dbb904e386eab95reed@google.com /** 14557212f9469c8056bab3c85243dbb904e386eab95reed@google.com * Return the full size of the bitmap, in bytes. 14657212f9469c8056bab3c85243dbb904e386eab95reed@google.com */ 14757212f9469c8056bab3c85243dbb904e386eab95reed@google.com int64_t computeSize64() const { 148e5ea500d4714a7d84de2bf913e81be3b65d2de68reed return sk_64_mul(fInfo.height(), fRowBytes); 14957212f9469c8056bab3c85243dbb904e386eab95reed@google.com } 15057212f9469c8056bab3c85243dbb904e386eab95reed@google.com 15157212f9469c8056bab3c85243dbb904e386eab95reed@google.com /** 15257212f9469c8056bab3c85243dbb904e386eab95reed@google.com * Return the number of bytes from the pointer returned by getPixels() 15357212f9469c8056bab3c85243dbb904e386eab95reed@google.com * to the end of the allocated space in the buffer. This may be smaller 15457212f9469c8056bab3c85243dbb904e386eab95reed@google.com * than computeSize64() if there is any rowbytes padding beyond the width. 15557212f9469c8056bab3c85243dbb904e386eab95reed@google.com */ 15657212f9469c8056bab3c85243dbb904e386eab95reed@google.com int64_t computeSafeSize64() const { 15761e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org return fInfo.getSafeSize64(fRowBytes); 15857212f9469c8056bab3c85243dbb904e386eab95reed@google.com } 15957212f9469c8056bab3c85243dbb904e386eab95reed@google.com 160b052129a4121c1e3f051e374541a93d3d7a98064junov@chromium.org /** Returns true if this bitmap is marked as immutable, meaning that the 161b052129a4121c1e3f051e374541a93d3d7a98064junov@chromium.org contents of its pixels will not change for the lifetime of the bitmap. 162b052129a4121c1e3f051e374541a93d3d7a98064junov@chromium.org */ 163b052129a4121c1e3f051e374541a93d3d7a98064junov@chromium.org bool isImmutable() const; 164b052129a4121c1e3f051e374541a93d3d7a98064junov@chromium.org 165b052129a4121c1e3f051e374541a93d3d7a98064junov@chromium.org /** Marks this bitmap as immutable, meaning that the contents of its 166b052129a4121c1e3f051e374541a93d3d7a98064junov@chromium.org pixels will not change for the lifetime of the bitmap and of the 167fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com underlying pixelref. This state can be set, but it cannot be 168b052129a4121c1e3f051e374541a93d3d7a98064junov@chromium.org cleared once it is set. This state propagates to all other bitmaps 169b052129a4121c1e3f051e374541a93d3d7a98064junov@chromium.org that share the same pixelref. 170b052129a4121c1e3f051e374541a93d3d7a98064junov@chromium.org */ 171b052129a4121c1e3f051e374541a93d3d7a98064junov@chromium.org void setImmutable(); 172b052129a4121c1e3f051e374541a93d3d7a98064junov@chromium.org 1738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns true if the bitmap is opaque (has no translucent/transparent pixels). 1748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 175383a697692cf46951fd451f6f4c3d03634a6a1cbreed@google.com bool isOpaque() const { 176383a697692cf46951fd451f6f4c3d03634a6a1cbreed@google.com return SkAlphaTypeIsOpaque(this->alphaType()); 177383a697692cf46951fd451f6f4c3d03634a6a1cbreed@google.com } 1784ee7ae5dcfe2055cfcfc21bf2cec1d790330eb4ajunov@google.com 1794ee7ae5dcfe2055cfcfc21bf2cec1d790330eb4ajunov@google.com /** Returns true if the bitmap is volatile (i.e. should not be cached by devices.) 1804ee7ae5dcfe2055cfcfc21bf2cec1d790330eb4ajunov@google.com */ 1814ee7ae5dcfe2055cfcfc21bf2cec1d790330eb4ajunov@google.com bool isVolatile() const; 1824ee7ae5dcfe2055cfcfc21bf2cec1d790330eb4ajunov@google.com 183fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com /** Specify whether this bitmap is volatile. Bitmaps are not volatile by 1844ee7ae5dcfe2055cfcfc21bf2cec1d790330eb4ajunov@google.com default. Temporary bitmaps that are discarded after use should be 1854ee7ae5dcfe2055cfcfc21bf2cec1d790330eb4ajunov@google.com marked as volatile. This provides a hint to the device that the bitmap 186fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com should not be cached. Providing this hint when appropriate can 187fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com improve performance by avoiding unnecessary overhead and resource 1884ee7ae5dcfe2055cfcfc21bf2cec1d790330eb4ajunov@google.com consumption on the device. 1894ee7ae5dcfe2055cfcfc21bf2cec1d790330eb4ajunov@google.com */ 1904ee7ae5dcfe2055cfcfc21bf2cec1d790330eb4ajunov@google.com void setIsVolatile(bool); 1914ee7ae5dcfe2055cfcfc21bf2cec1d790330eb4ajunov@google.com 1928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Reset the bitmap to its initial state (see default constructor). If we are a (shared) 1938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com owner of the pixels, that ownership is decremented. 1948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void reset(); 1968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 19786b2e43a33c486a0b150aa14fadf7af8323a11f5reed@google.com /** 1982a7579d11796866b0026755ab52597d09f4509ccreed@google.com * This will brute-force return true if all of the pixels in the bitmap 1992a7579d11796866b0026755ab52597d09f4509ccreed@google.com * are opaque. If it fails to read the pixels, or encounters an error, 2002a7579d11796866b0026755ab52597d09f4509ccreed@google.com * it will return false. 2012a7579d11796866b0026755ab52597d09f4509ccreed@google.com * 2022a7579d11796866b0026755ab52597d09f4509ccreed@google.com * Since this can be an expensive operation, the bitmap stores a flag for 20321a0b10d7c28e2ca123ddbe32fd8388687b3ef2ccommit-bot@chromium.org * this (isOpaque). Only call this if you need to compute this value from 20421a0b10d7c28e2ca123ddbe32fd8388687b3ef2ccommit-bot@chromium.org * "unknown" pixels. 2052a7579d11796866b0026755ab52597d09f4509ccreed@google.com */ 2062a7579d11796866b0026755ab52597d09f4509ccreed@google.com static bool ComputeIsOpaque(const SkBitmap&); 2072a7579d11796866b0026755ab52597d09f4509ccreed@google.com 2082a7579d11796866b0026755ab52597d09f4509ccreed@google.com /** 20986b2e43a33c486a0b150aa14fadf7af8323a11f5reed@google.com * Return the bitmap's bounds [0, 0, width, height] as an SkRect 21086b2e43a33c486a0b150aa14fadf7af8323a11f5reed@google.com */ 21186b2e43a33c486a0b150aa14fadf7af8323a11f5reed@google.com void getBounds(SkRect* bounds) const; 21280e1459c32f5f3acbc688ae4f0e046aa283e8c3areed@google.com void getBounds(SkIRect* bounds) const; 21386b2e43a33c486a0b150aa14fadf7af8323a11f5reed@google.com 214f622a6c8fd176acf9944de8df00d7f0bb56b67d3halcanary SkIRect bounds() const { return fInfo.bounds(); } 215f622a6c8fd176acf9944de8df00d7f0bb56b67d3halcanary SkISize dimensions() const { return fInfo.dimensions(); } 216f622a6c8fd176acf9944de8df00d7f0bb56b67d3halcanary 217a3264e53ee3f3c5d6a2c813df7e44b5b96d207f2commit-bot@chromium.org bool setInfo(const SkImageInfo&, size_t rowBytes = 0); 218a3264e53ee3f3c5d6a2c813df7e44b5b96d207f2commit-bot@chromium.org 2199230ea29718bcf1a92a89a1a518fb896bbbe00cfreed@google.com /** 220bae704b050491a8a98c67cb23eaccb10852d2bd5reed * Allocate the bitmap's pixels to match the requested image info. If the Factory 2219ebcac54635cde63110d73ad7c43d70772e7872freed@google.com * is non-null, call it to allcoate the pixelref. If the ImageInfo requires 2229ebcac54635cde63110d73ad7c43d70772e7872freed@google.com * a colortable, then ColorTable must be non-null, and will be ref'd. 2239ebcac54635cde63110d73ad7c43d70772e7872freed@google.com * On failure, the bitmap will be set to empty and return false. 2249ebcac54635cde63110d73ad7c43d70772e7872freed@google.com */ 225848250415eddc54075f7eb8795e8db79e749c6abreed bool SK_WARN_UNUSED_RESULT tryAllocPixels(const SkImageInfo&, SkPixelRefFactory*, SkColorTable*); 226848250415eddc54075f7eb8795e8db79e749c6abreed 22768331cd92a6dd09fb7b70a93b1e3cbe22916ef67reed void allocPixels(const SkImageInfo& info, SkPixelRefFactory* factory, SkColorTable* ctable) { 228848250415eddc54075f7eb8795e8db79e749c6abreed if (!this->tryAllocPixels(info, factory, ctable)) { 22968331cd92a6dd09fb7b70a93b1e3cbe22916ef67reed sk_throw(); 230848250415eddc54075f7eb8795e8db79e749c6abreed } 231848250415eddc54075f7eb8795e8db79e749c6abreed } 232d2ac07b64b7d46e81d00d389781f9f83810f0095skia.committer@gmail.com 2339ebcac54635cde63110d73ad7c43d70772e7872freed@google.com /** 234bae704b050491a8a98c67cb23eaccb10852d2bd5reed * Allocate the bitmap's pixels to match the requested image info and 235bae704b050491a8a98c67cb23eaccb10852d2bd5reed * rowBytes. If the request cannot be met (e.g. the info is invalid or 236bae704b050491a8a98c67cb23eaccb10852d2bd5reed * the requested rowBytes are not compatible with the info 237bae704b050491a8a98c67cb23eaccb10852d2bd5reed * (e.g. rowBytes < info.minRowBytes() or rowBytes is not aligned with 238bae704b050491a8a98c67cb23eaccb10852d2bd5reed * the pixel size specified by info.colorType()) then false is returned 239bae704b050491a8a98c67cb23eaccb10852d2bd5reed * and the bitmap is set to empty. 240bae704b050491a8a98c67cb23eaccb10852d2bd5reed */ 241848250415eddc54075f7eb8795e8db79e749c6abreed bool SK_WARN_UNUSED_RESULT tryAllocPixels(const SkImageInfo& info, size_t rowBytes); 242bae704b050491a8a98c67cb23eaccb10852d2bd5reed 24368331cd92a6dd09fb7b70a93b1e3cbe22916ef67reed void allocPixels(const SkImageInfo& info, size_t rowBytes) { 244848250415eddc54075f7eb8795e8db79e749c6abreed if (!this->tryAllocPixels(info, rowBytes)) { 24568331cd92a6dd09fb7b70a93b1e3cbe22916ef67reed sk_throw(); 246848250415eddc54075f7eb8795e8db79e749c6abreed } 247848250415eddc54075f7eb8795e8db79e749c6abreed } 248848250415eddc54075f7eb8795e8db79e749c6abreed 249848250415eddc54075f7eb8795e8db79e749c6abreed bool SK_WARN_UNUSED_RESULT tryAllocPixels(const SkImageInfo& info) { 250848250415eddc54075f7eb8795e8db79e749c6abreed return this->tryAllocPixels(info, info.minRowBytes()); 251848250415eddc54075f7eb8795e8db79e749c6abreed } 252848250415eddc54075f7eb8795e8db79e749c6abreed 25368331cd92a6dd09fb7b70a93b1e3cbe22916ef67reed void allocPixels(const SkImageInfo& info) { 25468331cd92a6dd09fb7b70a93b1e3cbe22916ef67reed this->allocPixels(info, info.minRowBytes()); 2559ebcac54635cde63110d73ad7c43d70772e7872freed@google.com } 256d2ac07b64b7d46e81d00d389781f9f83810f0095skia.committer@gmail.com 257848250415eddc54075f7eb8795e8db79e749c6abreed bool SK_WARN_UNUSED_RESULT tryAllocN32Pixels(int width, int height, bool isOpaque = false) { 258e5ea500d4714a7d84de2bf913e81be3b65d2de68reed SkImageInfo info = SkImageInfo::MakeN32(width, height, 259e5ea500d4714a7d84de2bf913e81be3b65d2de68reed isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); 260848250415eddc54075f7eb8795e8db79e749c6abreed return this->tryAllocPixels(info); 261848250415eddc54075f7eb8795e8db79e749c6abreed } 262775b8199a214af57c3ea7969e9d456f5f3eb137fmtklein 26368331cd92a6dd09fb7b70a93b1e3cbe22916ef67reed void allocN32Pixels(int width, int height, bool isOpaque = false) { 264e5ea500d4714a7d84de2bf913e81be3b65d2de68reed SkImageInfo info = SkImageInfo::MakeN32(width, height, 265e5ea500d4714a7d84de2bf913e81be3b65d2de68reed isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); 26668331cd92a6dd09fb7b70a93b1e3cbe22916ef67reed this->allocPixels(info); 267eb9a46cbbb475e862a084aa2224ec18d4ac5e95breed@google.com } 268775b8199a214af57c3ea7969e9d456f5f3eb137fmtklein 269eb9a46cbbb475e862a084aa2224ec18d4ac5e95breed@google.com /** 2709ebcac54635cde63110d73ad7c43d70772e7872freed@google.com * Install a pixelref that wraps the specified pixels and rowBytes, and 2719ebcac54635cde63110d73ad7c43d70772e7872freed@google.com * optional ReleaseProc and context. When the pixels are no longer 27200f8d6c75d22ce8f95f932c5b101354b196fa0dfcommit-bot@chromium.org * referenced, if releaseProc is not null, it will be called with the 2739ebcac54635cde63110d73ad7c43d70772e7872freed@google.com * pixels and context as parameters. 2749ebcac54635cde63110d73ad7c43d70772e7872freed@google.com * On failure, the bitmap will be set to empty and return false. 2759ebcac54635cde63110d73ad7c43d70772e7872freed@google.com */ 27600f8d6c75d22ce8f95f932c5b101354b196fa0dfcommit-bot@chromium.org bool installPixels(const SkImageInfo&, void* pixels, size_t rowBytes, SkColorTable*, 27700f8d6c75d22ce8f95f932c5b101354b196fa0dfcommit-bot@chromium.org void (*releaseProc)(void* addr, void* context), void* context); 27800f8d6c75d22ce8f95f932c5b101354b196fa0dfcommit-bot@chromium.org 279dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org /** 280dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org * Call installPixels with no ReleaseProc specified. This means that the 281dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org * caller must ensure that the specified pixels are valid for the lifetime 282dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org * of the created bitmap (and its pixelRef). 283dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org */ 284dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org bool installPixels(const SkImageInfo& info, void* pixels, size_t rowBytes) { 28500f8d6c75d22ce8f95f932c5b101354b196fa0dfcommit-bot@chromium.org return this->installPixels(info, pixels, rowBytes, NULL, NULL, NULL); 286dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org } 287dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org 288dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org /** 289dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org * Calls installPixels() with the value in the SkMask. The caller must 290dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org * ensure that the specified mask pixels are valid for the lifetime 291dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org * of the created bitmap (and its pixelRef). 292dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org */ 293dac522589e9395b4654a1a708f1bd971f37f95a5commit-bot@chromium.org bool installMaskPixels(const SkMask&); 294d2ac07b64b7d46e81d00d389781f9f83810f0095skia.committer@gmail.com 2958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Use this to assign a new pixel address for an existing bitmap. This 2968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com will automatically release any pixelref previously installed. Only call 2978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this if you are handling ownership/lifetime of the pixel memory. 298f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 2998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com If the bitmap retains a reference to the colortable (assuming it is 3008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com not null) it will take care of incrementing the reference count. 3018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param pixels Address for the pixels, managed by the caller. 3038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param ctable ColorTable (or null) that matches the specified pixels 3048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setPixels(void* p, SkColorTable* ctable = NULL); 3068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 30786bff1f008308267c4ff75456b202a9cf60c6193wjmaclean@chromium.org /** Copies the bitmap's pixels to the location pointed at by dst and returns 30886bff1f008308267c4ff75456b202a9cf60c6193wjmaclean@chromium.org true if possible, returns false otherwise. 30986bff1f008308267c4ff75456b202a9cf60c6193wjmaclean@chromium.org 310c69809745e6496564639e42ef998ad39adf7dfb8bsalomon@google.com In the case when the dstRowBytes matches the bitmap's rowBytes, the copy 311c69809745e6496564639e42ef998ad39adf7dfb8bsalomon@google.com may be made faster by copying over the dst's per-row padding (for all 312c69809745e6496564639e42ef998ad39adf7dfb8bsalomon@google.com rows but the last). By setting preserveDstPad to true the caller can 313c69809745e6496564639e42ef998ad39adf7dfb8bsalomon@google.com disable this optimization and ensure that pixels in the padding are not 314c69809745e6496564639e42ef998ad39adf7dfb8bsalomon@google.com overwritten. 31586bff1f008308267c4ff75456b202a9cf60c6193wjmaclean@chromium.org 31686bff1f008308267c4ff75456b202a9cf60c6193wjmaclean@chromium.org Always returns false for RLE formats. 31786bff1f008308267c4ff75456b202a9cf60c6193wjmaclean@chromium.org 31886bff1f008308267c4ff75456b202a9cf60c6193wjmaclean@chromium.org @param dst Location of destination buffer. 31986bff1f008308267c4ff75456b202a9cf60c6193wjmaclean@chromium.org @param dstSize Size of destination buffer. Must be large enough to hold 32086bff1f008308267c4ff75456b202a9cf60c6193wjmaclean@chromium.org pixels using indicated stride. 3210ba4bf427acbd7707d04192a98c77ef194a0f25ascroggo@google.com @param dstRowBytes Width of each line in the buffer. If 0, uses 32286bff1f008308267c4ff75456b202a9cf60c6193wjmaclean@chromium.org bitmap's internal stride. 323c69809745e6496564639e42ef998ad39adf7dfb8bsalomon@google.com @param preserveDstPad Must we preserve padding in the dst 32486bff1f008308267c4ff75456b202a9cf60c6193wjmaclean@chromium.org */ 3250ba4bf427acbd7707d04192a98c77ef194a0f25ascroggo@google.com bool copyPixelsTo(void* const dst, size_t dstSize, size_t dstRowBytes = 0, 3260ba4bf427acbd7707d04192a98c77ef194a0f25ascroggo@google.com bool preserveDstPad = false) const; 32786bff1f008308267c4ff75456b202a9cf60c6193wjmaclean@chromium.org 3288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Use the standard HeapAllocator to create the pixelref that manages the 329ddd014e65264e3f18b2d4305dd2fbc81549f5180reed pixel memory. It will be sized based on the current ImageInfo. 3308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com If this is called multiple times, a new pixelref object will be created 3318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com each time. 332f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 3338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com If the bitmap retains a reference to the colortable (assuming it is 3348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com not null) it will take care of incrementing the reference count. 3358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param ctable ColorTable (or null) to use with the pixels that will 337ddd014e65264e3f18b2d4305dd2fbc81549f5180reed be allocated. Only used if colortype == kIndex_8_SkColorType 3388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return true if the allocation succeeds. If not the pixelref field of 3398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the bitmap will be unchanged. 3408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 341848250415eddc54075f7eb8795e8db79e749c6abreed bool SK_WARN_UNUSED_RESULT tryAllocPixels(SkColorTable* ctable = NULL) { 342848250415eddc54075f7eb8795e8db79e749c6abreed return this->tryAllocPixels(NULL, ctable); 343848250415eddc54075f7eb8795e8db79e749c6abreed } 344848250415eddc54075f7eb8795e8db79e749c6abreed 34568331cd92a6dd09fb7b70a93b1e3cbe22916ef67reed void allocPixels(SkColorTable* ctable = NULL) { 34668331cd92a6dd09fb7b70a93b1e3cbe22916ef67reed this->allocPixels(NULL, ctable); 3478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 348f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 3498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Use the specified Allocator to create the pixelref that manages the 350ddd014e65264e3f18b2d4305dd2fbc81549f5180reed pixel memory. It will be sized based on the current ImageInfo. 3518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com If this is called multiple times, a new pixelref object will be created 3528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com each time. 353f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 3548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com If the bitmap retains a reference to the colortable (assuming it is 3558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com not null) it will take care of incrementing the reference count. 356f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 3578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param allocator The Allocator to use to create a pixelref that can 358ddd014e65264e3f18b2d4305dd2fbc81549f5180reed manage the pixel memory for the current ImageInfo. 359ddd014e65264e3f18b2d4305dd2fbc81549f5180reed If allocator is NULL, the standard HeapAllocator will be used. 3608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param ctable ColorTable (or null) to use with the pixels that will 361ddd014e65264e3f18b2d4305dd2fbc81549f5180reed be allocated. Only used if colortype == kIndex_8_SkColorType. 362ddd014e65264e3f18b2d4305dd2fbc81549f5180reed If it is non-null and the colortype is not indexed, it will 3638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com be ignored. 3648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return true if the allocation succeeds. If not the pixelref field of 3658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the bitmap will be unchanged. 3668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 367848250415eddc54075f7eb8795e8db79e749c6abreed bool SK_WARN_UNUSED_RESULT tryAllocPixels(Allocator* allocator, SkColorTable* ctable); 368848250415eddc54075f7eb8795e8db79e749c6abreed 36968331cd92a6dd09fb7b70a93b1e3cbe22916ef67reed void allocPixels(Allocator* allocator, SkColorTable* ctable) { 370848250415eddc54075f7eb8795e8db79e749c6abreed if (!this->tryAllocPixels(allocator, ctable)) { 37168331cd92a6dd09fb7b70a93b1e3cbe22916ef67reed sk_throw(); 372848250415eddc54075f7eb8795e8db79e749c6abreed } 373848250415eddc54075f7eb8795e8db79e749c6abreed } 374f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 375672588b684d484dce6ae251e9e163e4a46924322reed@google.com /** 376672588b684d484dce6ae251e9e163e4a46924322reed@google.com * Return the current pixelref object or NULL if there is none. This does 377672588b684d484dce6ae251e9e163e4a46924322reed@google.com * not affect the refcount of the pixelref. 378672588b684d484dce6ae251e9e163e4a46924322reed@google.com */ 3798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPixelRef* pixelRef() const { return fPixelRef; } 380672588b684d484dce6ae251e9e163e4a46924322reed@google.com 381672588b684d484dce6ae251e9e163e4a46924322reed@google.com /** 382672588b684d484dce6ae251e9e163e4a46924322reed@google.com * A bitmap can reference a subset of a pixelref's pixels. That means the 383672588b684d484dce6ae251e9e163e4a46924322reed@google.com * bitmap's width/height can be <= the dimensions of the pixelref. The 384672588b684d484dce6ae251e9e163e4a46924322reed@google.com * pixelref origin is the x,y location within the pixelref's pixels for 385672588b684d484dce6ae251e9e163e4a46924322reed@google.com * the bitmap's top/left corner. To be valid the following must be true: 386672588b684d484dce6ae251e9e163e4a46924322reed@google.com * 387672588b684d484dce6ae251e9e163e4a46924322reed@google.com * origin_x + bitmap_width <= pixelref_width 388672588b684d484dce6ae251e9e163e4a46924322reed@google.com * origin_y + bitmap_height <= pixelref_height 389672588b684d484dce6ae251e9e163e4a46924322reed@google.com * 390672588b684d484dce6ae251e9e163e4a46924322reed@google.com * pixelRefOrigin() returns this origin, or (0,0) if there is no pixelRef. 391672588b684d484dce6ae251e9e163e4a46924322reed@google.com */ 392672588b684d484dce6ae251e9e163e4a46924322reed@google.com SkIPoint pixelRefOrigin() const { return fPixelRefOrigin; } 393672588b684d484dce6ae251e9e163e4a46924322reed@google.com 394672588b684d484dce6ae251e9e163e4a46924322reed@google.com /** 395672588b684d484dce6ae251e9e163e4a46924322reed@google.com * Assign a pixelref and origin to the bitmap. Pixelrefs are reference, 396672588b684d484dce6ae251e9e163e4a46924322reed@google.com * so the existing one (if any) will be unref'd and the new one will be 397672588b684d484dce6ae251e9e163e4a46924322reed@google.com * ref'd. (x,y) specify the offset within the pixelref's pixels for the 398672588b684d484dce6ae251e9e163e4a46924322reed@google.com * top/left corner of the bitmap. For a bitmap that encompases the entire 399672588b684d484dce6ae251e9e163e4a46924322reed@google.com * pixels of the pixelref, these will be (0,0). 400672588b684d484dce6ae251e9e163e4a46924322reed@google.com */ 401672588b684d484dce6ae251e9e163e4a46924322reed@google.com SkPixelRef* setPixelRef(SkPixelRef* pr, int dx, int dy); 402672588b684d484dce6ae251e9e163e4a46924322reed@google.com 403672588b684d484dce6ae251e9e163e4a46924322reed@google.com SkPixelRef* setPixelRef(SkPixelRef* pr, const SkIPoint& origin) { 404672588b684d484dce6ae251e9e163e4a46924322reed@google.com return this->setPixelRef(pr, origin.fX, origin.fY); 405672588b684d484dce6ae251e9e163e4a46924322reed@google.com } 4061ae9111f33db7640ce87d55156c1b6d491237db2skia.committer@gmail.com 407672588b684d484dce6ae251e9e163e4a46924322reed@google.com SkPixelRef* setPixelRef(SkPixelRef* pr) { 408672588b684d484dce6ae251e9e163e4a46924322reed@google.com return this->setPixelRef(pr, 0, 0); 409672588b684d484dce6ae251e9e163e4a46924322reed@google.com } 410f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 4118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Call this to ensure that the bitmap points to the current pixel address 4128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com in the pixelref. Balance it with a call to unlockPixels(). These calls 4138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com are harmless if there is no pixelref. 4148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void lockPixels() const; 4168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** When you are finished access the pixel memory, call this to balance a 4178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com previous call to lockPixels(). This allows pixelrefs that implement 4188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com cached/deferred image decoding to know when there are active clients of 4198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com a given image. 4208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void unlockPixels() const; 422f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 4239c49bc3e643c435677727c1c0904c4a7cb7a6907reed@google.com /** 4249c49bc3e643c435677727c1c0904c4a7cb7a6907reed@google.com * Some bitmaps can return a copy of their pixels for lockPixels(), but 4259c49bc3e643c435677727c1c0904c4a7cb7a6907reed@google.com * that copy, if modified, will not be pushed back. These bitmaps should 4269c49bc3e643c435677727c1c0904c4a7cb7a6907reed@google.com * not be used as targets for a raster device/canvas (since all pixels 4279c49bc3e643c435677727c1c0904c4a7cb7a6907reed@google.com * modifications will be lost when unlockPixels() is called.) 4289c49bc3e643c435677727c1c0904c4a7cb7a6907reed@google.com */ 4299c49bc3e643c435677727c1c0904c4a7cb7a6907reed@google.com bool lockPixelsAreWritable() const; 4309c49bc3e643c435677727c1c0904c4a7cb7a6907reed@google.com 4318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Call this to be sure that the bitmap is valid enough to be drawn (i.e. 432ddd014e65264e3f18b2d4305dd2fbc81549f5180reed it has non-null pixels, and if required by its colortype, it has a 4338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com non-null colortable. Returns true if all of the above are met. 4348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool readyToDraw() const { 4368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return this->getPixels() != NULL && 43749f085dddff10473b6ebf832a974288300224e60bsalomon (this->colorType() != kIndex_8_SkColorType || fColorTable); 4388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 440ce4e53a2347040a3c145768c193a7a7958c0d4ecreed@android.com /** Returns the pixelRef's texture, or NULL 441ce4e53a2347040a3c145768c193a7a7958c0d4ecreed@android.com */ 442b8d00db075b5ea09e353508a26ef5ced50722a6ccommit-bot@chromium.org GrTexture* getTexture() const; 443ce4e53a2347040a3c145768c193a7a7958c0d4ecreed@android.com 44461e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org /** Return the bitmap's colortable, if it uses one (i.e. colorType is 44561e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org Index_8) and the pixels are locked. 446665b2cca88e25b821a69c9ce8a4fd7f551532012scroggo@google.com Otherwise returns NULL. Does not affect the colortable's 4478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com reference count. 4488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkColorTable* getColorTable() const { return fColorTable; } 4508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns a non-zero, unique value corresponding to the pixels in our 452c84b8335ee4fd864c30a4703afc643cf4b5010d9djsollen@google.com pixelref. Each time the pixels are changed (and notifyPixelsChanged 453c84b8335ee4fd864c30a4703afc643cf4b5010d9djsollen@google.com is called), a different generation ID will be returned. Finally, if 45458edea89627d347010cadc26ce3c092a9265a8eescroggo there is no pixelRef then zero is returned. 4558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint32_t getGenerationID() const; 457f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 4588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Call this if you have changed the contents of the pixels. This will in- 4598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com turn cause a different generation ID value to be returned from 4608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com getGenerationID(). 4618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void notifyPixelsChanged() const; 4638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 46460d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com /** 46560d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com * Fill the entire bitmap with the specified color. 466ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * If the bitmap's colortype does not support alpha (e.g. 565) then the alpha 467ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * of the color is ignored (treated as opaque). If the colortype only supports 46860d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com * alpha (e.g. A1 or A8) then the color's r,g,b components are ignored. 46960d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com */ 4708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void eraseColor(SkColor c) const { 4718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->eraseARGB(SkColorGetA(c), SkColorGetR(c), SkColorGetG(c), 4728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkColorGetB(c)); 4738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 474f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 47560d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com /** 47660d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com * Fill the entire bitmap with the specified color. 477ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * If the bitmap's colortype does not support alpha (e.g. 565) then the alpha 478ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * of the color is ignored (treated as opaque). If the colortype only supports 47960d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com * alpha (e.g. A1 or A8) then the color's r,g,b components are ignored. 48060d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com */ 48160d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com void eraseARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b) const; 48260d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com 4834469938e92d779dff05e745559e67907bbf21e78reed@google.com SK_ATTR_DEPRECATED("use eraseARGB or eraseColor") 48460d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com void eraseRGB(U8CPU r, U8CPU g, U8CPU b) const { 48560d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com this->eraseARGB(0xFF, r, g, b); 48660d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com } 48760d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com 48860d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com /** 48960d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com * Fill the specified area of this bitmap with the specified color. 490ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * If the bitmap's colortype does not support alpha (e.g. 565) then the alpha 491ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * of the color is ignored (treated as opaque). If the colortype only supports 49260d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com * alpha (e.g. A1 or A8) then the color's r,g,b components are ignored. 49360d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com */ 49460d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com void eraseArea(const SkIRect& area, SkColor c) const; 49560d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com 4968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Scroll (a subset of) the contents of this bitmap by dx/dy. If there are 4978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com no pixels allocated (i.e. getPixels() returns null) the method will 4986a9368d41154890b6c316fdae704bf56ca4c70ccscroggo@google.com still update the inval region (if present). If the bitmap is immutable, 4996a9368d41154890b6c316fdae704bf56ca4c70ccscroggo@google.com do nothing and return false. 5008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param subset The subset of the bitmap to scroll/move. To scroll the 5028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com entire contents, specify [0, 0, width, height] or just 5038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pass null. 5048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dx The amount to scroll in X 5058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dy The amount to scroll in Y 5068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param inval Optional (may be null). Returns the area of the bitmap that 5078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com was scrolled away. E.g. if dx = dy = 0, then inval would 5088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com be set to empty. If dx >= width or dy >= height, then 5098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com inval would be set to the entire bounds of the bitmap. 510ddd014e65264e3f18b2d4305dd2fbc81549f5180reed @return true if the scroll was doable. Will return false if the colortype is kUnkown or 511ddd014e65264e3f18b2d4305dd2fbc81549f5180reed if the bitmap is immutable. 5128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com If no pixels are present (i.e. getPixels() returns false) 5138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com inval will still be updated, and true will be returned. 5148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 5158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool scrollRect(const SkIRect* subset, int dx, int dy, 5168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRegion* inval = NULL) const; 5178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5183b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com /** 5193b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com * Return the SkColor of the specified pixel. In most cases this will 520ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * require un-premultiplying the color. Alpha only colortypes (e.g. kAlpha_8_SkColorType) 5213b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com * return black with the appropriate alpha set. The value is undefined 522ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * for kUnknown_SkColorType or if x or y are out of bounds, or if the bitmap 5233b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com * does not have any pixels (or has not be locked with lockPixels()). 5243b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com */ 5253b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com SkColor getColor(int x, int y) const; 526fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 5278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns the address of the specified pixel. This performs a runtime 5288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com check to know the size of the pixels, and will return the same answer 5298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com as the corresponding size-specific method (e.g. getAddr16). Since the 5308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com check happens at runtime, it is much slower than using a size-specific 5318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com version. Unlike the size-specific methods, this routine also checks if 5328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com getPixels() returns null, and returns that. The size-specific routines 5338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com perform a debugging assert that getPixels() is not null, but they do 5348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com not do any runtime checks. 5358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 5368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void* getAddr(int x, int y) const; 5378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns the address of the pixel specified by x,y for 32bit pixels. 5393b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com * In debug build, this asserts that the pixels are allocated and locked, 540ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * and that the colortype is 32-bit, however none of these checks are performed 5413b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com * in the release build. 5423b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com */ 5438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com inline uint32_t* getAddr32(int x, int y) const; 5443b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com 5458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns the address of the pixel specified by x,y for 16bit pixels. 5463b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com * In debug build, this asserts that the pixels are allocated and locked, 547ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * and that the colortype is 16-bit, however none of these checks are performed 5483b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com * in the release build. 5493b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com */ 5508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com inline uint16_t* getAddr16(int x, int y) const; 5513b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com 5528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns the address of the pixel specified by x,y for 8bit pixels. 5533b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com * In debug build, this asserts that the pixels are allocated and locked, 554ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * and that the colortype is 8-bit, however none of these checks are performed 5553b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com * in the release build. 5563b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com */ 5578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com inline uint8_t* getAddr8(int x, int y) const; 5583b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com 5598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns the color corresponding to the pixel specified by x,y for 5603b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com * colortable based bitmaps. 5613b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com * In debug build, this asserts that the pixels are allocated and locked, 562ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * that the colortype is indexed, and that the colortable is allocated, 5633b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com * however none of these checks are performed in the release build. 5643b521d05335a1bf76be3456feb9dbfba0a51b339reed@google.com */ 5658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com inline SkPMColor getIndex8Color(int x, int y) const; 5668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5679ef2d8382f5238cc54d211e3cc228def7a93b133epoger@google.com /** Set dst to be a setset of this bitmap. If possible, it will share the 568ddd014e65264e3f18b2d4305dd2fbc81549f5180reed pixel memory, and just point into a subset of it. However, if the colortype 5698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com does not support this, a local copy will be made and associated with 5708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the dst bitmap. If the subset rectangle, intersected with the bitmap's 571ddd014e65264e3f18b2d4305dd2fbc81549f5180reed dimensions is empty, or if there is an unsupported colortype, false will be 5728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com returned and dst will be untouched. 5738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dst The bitmap that will be set to a subset of this bitmap 5748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param subset The rectangle of pixels in this bitmap that dst will 5758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com reference. 5768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return true if the subset copy was successfully made. 5778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 5788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool extractSubset(SkBitmap* dst, const SkIRect& subset) const; 5798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5808a2ad3cae710f05cca57e48dd1732d575dba2dc7commit-bot@chromium.org /** Makes a deep copy of this bitmap, respecting the requested colorType, 581ef843cdcd1be858fe55cc99ff134ffbd080c9a51senorblanco@chromium.org * and allocating the dst pixels on the cpu. 582ef843cdcd1be858fe55cc99ff134ffbd080c9a51senorblanco@chromium.org * Returns false if either there is an error (i.e. the src does not have 583ef843cdcd1be858fe55cc99ff134ffbd080c9a51senorblanco@chromium.org * pixels) or the request cannot be satisfied (e.g. the src has per-pixel 584ddd014e65264e3f18b2d4305dd2fbc81549f5180reed * alpha, and the requested colortype does not support alpha). 585ef843cdcd1be858fe55cc99ff134ffbd080c9a51senorblanco@chromium.org * @param dst The bitmap to be sized and allocated 5868a2ad3cae710f05cca57e48dd1732d575dba2dc7commit-bot@chromium.org * @param ct The desired colorType for dst 587ef843cdcd1be858fe55cc99ff134ffbd080c9a51senorblanco@chromium.org * @param allocator Allocator used to allocate the pixelref for the dst 588ef843cdcd1be858fe55cc99ff134ffbd080c9a51senorblanco@chromium.org * bitmap. If this is null, the standard HeapAllocator 589ef843cdcd1be858fe55cc99ff134ffbd080c9a51senorblanco@chromium.org * will be used. 5908a2ad3cae710f05cca57e48dd1732d575dba2dc7commit-bot@chromium.org * @return true if the copy was made. 591ef843cdcd1be858fe55cc99ff134ffbd080c9a51senorblanco@chromium.org */ 5928a2ad3cae710f05cca57e48dd1732d575dba2dc7commit-bot@chromium.org bool copyTo(SkBitmap* dst, SkColorType ct, Allocator* = NULL) const; 5938a2ad3cae710f05cca57e48dd1732d575dba2dc7commit-bot@chromium.org 5948a2ad3cae710f05cca57e48dd1732d575dba2dc7commit-bot@chromium.org bool copyTo(SkBitmap* dst, Allocator* allocator = NULL) const { 5958a2ad3cae710f05cca57e48dd1732d575dba2dc7commit-bot@chromium.org return this->copyTo(dst, this->colorType(), allocator); 5968a2ad3cae710f05cca57e48dd1732d575dba2dc7commit-bot@chromium.org } 5978a2ad3cae710f05cca57e48dd1732d575dba2dc7commit-bot@chromium.org 5988a2ad3cae710f05cca57e48dd1732d575dba2dc7commit-bot@chromium.org /** 599b184f7f52b2a94e95aee326a3ca37110d2e43336reed * Copy the bitmap's pixels into the specified buffer (pixels + rowBytes), 600b184f7f52b2a94e95aee326a3ca37110d2e43336reed * converting them into the requested format (SkImageInfo). The src pixels are read 601b184f7f52b2a94e95aee326a3ca37110d2e43336reed * starting at the specified (srcX,srcY) offset, relative to the top-left corner. 602b184f7f52b2a94e95aee326a3ca37110d2e43336reed * 603b184f7f52b2a94e95aee326a3ca37110d2e43336reed * The specified ImageInfo and (srcX,srcY) offset specifies a source rectangle 604b184f7f52b2a94e95aee326a3ca37110d2e43336reed * 605b184f7f52b2a94e95aee326a3ca37110d2e43336reed * srcR.setXYWH(srcX, srcY, dstInfo.width(), dstInfo.height()); 606b184f7f52b2a94e95aee326a3ca37110d2e43336reed * 607b184f7f52b2a94e95aee326a3ca37110d2e43336reed * srcR is intersected with the bounds of the bitmap. If this intersection is not empty, 608b184f7f52b2a94e95aee326a3ca37110d2e43336reed * then we have two sets of pixels (of equal size). Replace the dst pixels with the 609b184f7f52b2a94e95aee326a3ca37110d2e43336reed * corresponding src pixels, performing any colortype/alphatype transformations needed 610b184f7f52b2a94e95aee326a3ca37110d2e43336reed * (in the case where the src and dst have different colortypes or alphatypes). 611b184f7f52b2a94e95aee326a3ca37110d2e43336reed * 612b184f7f52b2a94e95aee326a3ca37110d2e43336reed * This call can fail, returning false, for several reasons: 613b184f7f52b2a94e95aee326a3ca37110d2e43336reed * - If srcR does not intersect the bitmap bounds. 614b184f7f52b2a94e95aee326a3ca37110d2e43336reed * - If the requested colortype/alphatype cannot be converted from the src's types. 615b184f7f52b2a94e95aee326a3ca37110d2e43336reed * - If the src pixels are not available. 616b184f7f52b2a94e95aee326a3ca37110d2e43336reed */ 617b184f7f52b2a94e95aee326a3ca37110d2e43336reed bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, 618b184f7f52b2a94e95aee326a3ca37110d2e43336reed int srcX, int srcY) const; 619b184f7f52b2a94e95aee326a3ca37110d2e43336reed 620b184f7f52b2a94e95aee326a3ca37110d2e43336reed /** 6218a2ad3cae710f05cca57e48dd1732d575dba2dc7commit-bot@chromium.org * Returns true if this bitmap's pixels can be converted into the requested 6228a2ad3cae710f05cca57e48dd1732d575dba2dc7commit-bot@chromium.org * colorType, such that copyTo() could succeed. 6238a2ad3cae710f05cca57e48dd1732d575dba2dc7commit-bot@chromium.org */ 6248a2ad3cae710f05cca57e48dd1732d575dba2dc7commit-bot@chromium.org bool canCopyTo(SkColorType colorType) const; 62589bb83abb420c126b02fcdd4047fd6574e9b73fcreed@android.com 6266285f4f7662853336b788d6ee3e177c396f7fb01commit-bot@chromium.org /** Makes a deep copy of this bitmap, keeping the copied pixels 6276285f4f7662853336b788d6ee3e177c396f7fb01commit-bot@chromium.org * in the same domain as the source: If the src pixels are allocated for 6286285f4f7662853336b788d6ee3e177c396f7fb01commit-bot@chromium.org * the cpu, then so will the dst. If the src pixels are allocated on the 6296285f4f7662853336b788d6ee3e177c396f7fb01commit-bot@chromium.org * gpu (typically as a texture), the it will do the same for the dst. 6306285f4f7662853336b788d6ee3e177c396f7fb01commit-bot@chromium.org * If the request cannot be fulfilled, returns false and dst is unmodified. 6316285f4f7662853336b788d6ee3e177c396f7fb01commit-bot@chromium.org */ 6326285f4f7662853336b788d6ee3e177c396f7fb01commit-bot@chromium.org bool deepCopyTo(SkBitmap* dst) const; 633ef843cdcd1be858fe55cc99ff134ffbd080c9a51senorblanco@chromium.org 6344bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com#ifdef SK_BUILD_FOR_ANDROID 6354bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com bool hasHardwareMipMap() const { 6364bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com return (fFlags & kHasHardwareMipMap_Flag) != 0; 6374bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com } 6384bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com 6394bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com void setHasHardwareMipMap(bool hasHardwareMipMap) { 6404bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com if (hasHardwareMipMap) { 6414bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com fFlags |= kHasHardwareMipMap_Flag; 6424bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com } else { 6434bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com fFlags &= ~kHasHardwareMipMap_Flag; 6444bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com } 6454bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com } 6464bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com#endif 6474bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com 648cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com bool extractAlpha(SkBitmap* dst) const { 649cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com return this->extractAlpha(dst, NULL, NULL, NULL); 6508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 6518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 652cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com bool extractAlpha(SkBitmap* dst, const SkPaint* paint, 65357f4969724a1dd88c8d9ae35a863e6cf621181d5djsollen@google.com SkIPoint* offset) const { 654cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com return this->extractAlpha(dst, paint, NULL, offset); 65557f4969724a1dd88c8d9ae35a863e6cf621181d5djsollen@google.com } 65657f4969724a1dd88c8d9ae35a863e6cf621181d5djsollen@google.com 657cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com /** Set dst to contain alpha layer of this bitmap. If destination bitmap 658cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com fails to be initialized, e.g. because allocator can't allocate pixels 659cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com for it, dst will not be modified and false will be returned. 660cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 661cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com @param dst The bitmap to be filled with alpha layer 662cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com @param paint The paint to draw with 663cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com @param allocator Allocator used to allocate the pixelref for the dst 664cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com bitmap. If this is null, the standard HeapAllocator 665cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com will be used. 666cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com @param offset If not null, it is set to top-left coordinate to position 667cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com the returned bitmap so that it visually lines up with the 668cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com original 669cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com */ 670cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com bool extractAlpha(SkBitmap* dst, const SkPaint* paint, Allocator* allocator, 6718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIPoint* offset) const; 672f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 6738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDEBUGCODE(void validate() const;) 6748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com class Allocator : public SkRefCnt { 6768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com public: 67715e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com SK_DECLARE_INST_COUNT(Allocator) 67815e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com 6798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Allocate the pixel memory for the bitmap, given its dimensions and 680ddd014e65264e3f18b2d4305dd2fbc81549f5180reed colortype. Return true on success, where success means either setPixels 6818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com or setPixelRef was called. The pixels need not be locked when this 682ddd014e65264e3f18b2d4305dd2fbc81549f5180reed returns. If the colortype requires a colortable, it also must be 6838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com installed via setColorTable. If false is returned, the bitmap and 6848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com colortable should be left unchanged. 6858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 6868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual bool allocPixelRef(SkBitmap*, SkColorTable*) = 0; 68715e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com private: 68815e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com typedef SkRefCnt INHERITED; 6898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 6908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Subclass of Allocator that returns a pixelref that allocates its pixel 6928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com memory from the heap. This is the default Allocator invoked by 6938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com allocPixels(). 6948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 6958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com class HeapAllocator : public Allocator { 6968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com public: 69736352bf5e38f45a70ee4f4fc132a38048d38206dmtklein bool allocPixelRef(SkBitmap*, SkColorTable*) override; 6988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 6998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com class RLEPixels { 7018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com public: 7028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com RLEPixels(int width, int height); 7038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual ~RLEPixels(); 704f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 7058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint8_t* packedAtY(int y) const { 7068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT((unsigned)y < (unsigned)fHeight); 7078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return fYPtrs[y]; 7088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 709f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 7108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // called by subclasses during creation 7118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setPackedAtY(int y, uint8_t* addr) { 7128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT((unsigned)y < (unsigned)fHeight); 7138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fYPtrs[y] = addr; 7148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 715f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 7168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com private: 7178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint8_t** fYPtrs; 7188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int fHeight; 7198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 720f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 7210f10f7bf1fb43ca6346dc220a076773b1f19a367commit-bot@chromium.org SK_TO_STRING_NONVIRT() 72276f9e938df0b5826fd4c80b854ceafaf385cfbe1robertphillips@google.com 7238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 7248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mutable SkPixelRef* fPixelRef; 7258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mutable int fPixelLockCount; 7265f62ed74342e44cb1b9671ffdac47c6a81416136reed@google.com // These are just caches from the locked pixelref 7278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mutable void* fPixels; 7288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mutable SkColorTable* fColorTable; // only meaningful for kIndex8 7298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 730672588b684d484dce6ae251e9e163e4a46924322reed@google.com SkIPoint fPixelRefOrigin; 731672588b684d484dce6ae251e9e163e4a46924322reed@google.com 7328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com enum Flags { 733b052129a4121c1e3f051e374541a93d3d7a98064junov@chromium.org kImageIsVolatile_Flag = 0x02, 7344bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com#ifdef SK_BUILD_FOR_ANDROID 7354bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com /* A hint for the renderer responsible for drawing this bitmap 7364bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com * indicating that it should attempt to use mipmaps when this bitmap 7374bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com * is drawn scaled down. 7384bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com */ 7394bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com kHasHardwareMipMap_Flag = 0x08, 7404bd2bdbf04f21237337616aa931e34d7c8991edcdjsollen@google.com#endif 7418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 7428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 74361e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org SkImageInfo fInfo; 74461e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org 745e5f48243bdbed2662be7a31be0888abc273b09e8scroggo@google.com uint32_t fRowBytes; 74661e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org 7478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint8_t fFlags; 7488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 74960d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com void internalErase(const SkIRect&, U8CPU a, U8CPU r, U8CPU g, U8CPU b)const; 75060d3235ab42bd1d32a070695ee30d6e3ec2fa222reed@google.com 7518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /* Unreference any pixelrefs or colortables 7528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 7538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void freePixels(); 7548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void updatePixelsFromRef() const; 7553c134a97ed128ca95345e13619512df0f42e95f8skia.committer@gmail.com 756968edcafa61442dc4f7f8ed8f89523d0f353e9fbcommit-bot@chromium.org static void WriteRawPixels(SkWriteBuffer*, const SkBitmap&); 757968edcafa61442dc4f7f8ed8f89523d0f353e9fbcommit-bot@chromium.org static bool ReadRawPixels(SkReadBuffer*, SkBitmap*); 758f9ab99aaade8c451c0e9309b4c61a448373019e3weita@google.com 759968edcafa61442dc4f7f8ed8f89523d0f353e9fbcommit-bot@chromium.org friend class SkBitmapSource; // unflatten 760968edcafa61442dc4f7f8ed8f89523d0f353e9fbcommit-bot@chromium.org friend class SkReadBuffer; // unflatten, rawpixels 761968edcafa61442dc4f7f8ed8f89523d0f353e9fbcommit-bot@chromium.org friend class SkWriteBuffer; // rawpixels 7624a551d49cf44397a99c73787f63409568cf85009reed@google.com friend struct SkBitmapProcState; 7638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 7648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 765e3beb6bd7de7fa211681abbb0be58e80b19885e0commit-bot@chromium.orgclass SkAutoLockPixels : SkNoncopyable { 7668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 7679c49bc3e643c435677727c1c0904c4a7cb7a6907reed@google.com SkAutoLockPixels(const SkBitmap& bm, bool doLock = true) : fBitmap(bm) { 7689c49bc3e643c435677727c1c0904c4a7cb7a6907reed@google.com fDidLock = doLock; 7699c49bc3e643c435677727c1c0904c4a7cb7a6907reed@google.com if (doLock) { 7709c49bc3e643c435677727c1c0904c4a7cb7a6907reed@google.com bm.lockPixels(); 7719c49bc3e643c435677727c1c0904c4a7cb7a6907reed@google.com } 7728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ~SkAutoLockPixels() { 7749c49bc3e643c435677727c1c0904c4a7cb7a6907reed@google.com if (fDidLock) { 7759c49bc3e643c435677727c1c0904c4a7cb7a6907reed@google.com fBitmap.unlockPixels(); 7769c49bc3e643c435677727c1c0904c4a7cb7a6907reed@google.com } 7778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 7808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkBitmap& fBitmap; 7819c49bc3e643c435677727c1c0904c4a7cb7a6907reed@google.com bool fDidLock; 7828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 7830f6dc21e324a0829ed7f4ff4c4238f75f62683b5mtklein@google.com//TODO(mtklein): uncomment when 71713004 lands and Chromium's fixed. 7840f6dc21e324a0829ed7f4ff4c4238f75f62683b5mtklein@google.com//#define SkAutoLockPixels(...) SK_REQUIRE_LOCAL_VAR(SkAutoLockPixels) 7858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/////////////////////////////////////////////////////////////////////////////// 7878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.cominline uint32_t* SkBitmap::getAddr32(int x, int y) const { 7898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(fPixels); 79069e64637925d51f746560b2da21c4b0a10eed48areed@google.com SkASSERT(4 == this->bytesPerPixel()); 79161e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org SkASSERT((unsigned)x < (unsigned)this->width() && (unsigned)y < (unsigned)this->height()); 7928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return (uint32_t*)((char*)fPixels + y * fRowBytes + (x << 2)); 7938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 7948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.cominline uint16_t* SkBitmap::getAddr16(int x, int y) const { 7968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(fPixels); 79769e64637925d51f746560b2da21c4b0a10eed48areed@google.com SkASSERT(2 == this->bytesPerPixel()); 79861e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org SkASSERT((unsigned)x < (unsigned)this->width() && (unsigned)y < (unsigned)this->height()); 7998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return (uint16_t*)((char*)fPixels + y * fRowBytes + (x << 1)); 8008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 8018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.cominline uint8_t* SkBitmap::getAddr8(int x, int y) const { 8038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(fPixels); 80469e64637925d51f746560b2da21c4b0a10eed48areed@google.com SkASSERT(1 == this->bytesPerPixel()); 80561e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org SkASSERT((unsigned)x < (unsigned)this->width() && (unsigned)y < (unsigned)this->height()); 8068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return (uint8_t*)fPixels + y * fRowBytes + x; 8078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 8088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.cominline SkPMColor SkBitmap::getIndex8Color(int x, int y) const { 8108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(fPixels); 81169e64637925d51f746560b2da21c4b0a10eed48areed@google.com SkASSERT(kIndex_8_SkColorType == this->colorType()); 81261e96cd44624c9faceb625519c1b29775b161f45commit-bot@chromium.org SkASSERT((unsigned)x < (unsigned)this->width() && (unsigned)y < (unsigned)this->height()); 8138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(fColorTable); 8148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return (*fColorTable)[*((const uint8_t*)fPixels + y * fRowBytes + x)]; 8158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 8168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 818