| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #ifndef SkBitmap_DEFINED | 10 #ifndef SkBitmap_DEFINED |
| 11 #define SkBitmap_DEFINED | 11 #define SkBitmap_DEFINED |
| 12 | 12 |
| 13 #include "Sk64.h" | 13 #include "Sk64.h" |
| 14 #include "SkAlpha.h" |
| 14 #include "SkColor.h" | 15 #include "SkColor.h" |
| 15 #include "SkColorTable.h" | 16 #include "SkColorTable.h" |
| 16 #include "SkPoint.h" | 17 #include "SkPoint.h" |
| 17 #include "SkRefCnt.h" | 18 #include "SkRefCnt.h" |
| 18 | 19 |
| 19 struct SkIRect; | 20 struct SkIRect; |
| 20 struct SkRect; | 21 struct SkRect; |
| 21 class SkPaint; | 22 class SkPaint; |
| 22 class SkPixelRef; | 23 class SkPixelRef; |
| 23 class SkRegion; | 24 class SkRegion; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 */ | 124 */ |
| 124 int bytesPerPixel() const { return fBytesPerPixel; } | 125 int bytesPerPixel() const { return fBytesPerPixel; } |
| 125 | 126 |
| 126 /** Return the rowbytes expressed as a number of pixels (like width and | 127 /** Return the rowbytes expressed as a number of pixels (like width and |
| 127 height). Note, for 1-byte per pixel configs like kA8_Config, this will | 128 height). Note, for 1-byte per pixel configs like kA8_Config, this will |
| 128 return the same as rowBytes(). Is undefined for configs that are less | 129 return the same as rowBytes(). Is undefined for configs that are less |
| 129 than 1-byte per pixel (e.g. kA1_Config) | 130 than 1-byte per pixel (e.g. kA1_Config) |
| 130 */ | 131 */ |
| 131 int rowBytesAsPixels() const { return fRowBytes >> (fBytesPerPixel >> 1); } | 132 int rowBytesAsPixels() const { return fRowBytes >> (fBytesPerPixel >> 1); } |
| 132 | 133 |
| 134 SkAlphaType alphaType() const { return (SkAlphaType)fAlphaType; } |
| 135 void setAlphaType(SkAlphaType); |
| 136 |
| 133 /** Return the address of the pixels for this SkBitmap. | 137 /** Return the address of the pixels for this SkBitmap. |
| 134 */ | 138 */ |
| 135 void* getPixels() const { return fPixels; } | 139 void* getPixels() const { return fPixels; } |
| 136 | 140 |
| 137 /** Return the byte size of the pixels, based on the height and rowBytes. | 141 /** Return the byte size of the pixels, based on the height and rowBytes. |
| 138 Note this truncates the result to 32bits. Call getSize64() to detect | 142 Note this truncates the result to 32bits. Call getSize64() to detect |
| 139 if the real size exceeds 32bits. | 143 if the real size exceeds 32bits. |
| 140 */ | 144 */ |
| 141 size_t getSize() const { return fHeight * fRowBytes; } | 145 size_t getSize() const { return fHeight * fRowBytes; } |
| 142 | 146 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 168 /** Marks this bitmap as immutable, meaning that the contents of its | 172 /** Marks this bitmap as immutable, meaning that the contents of its |
| 169 pixels will not change for the lifetime of the bitmap and of the | 173 pixels will not change for the lifetime of the bitmap and of the |
| 170 underlying pixelref. This state can be set, but it cannot be | 174 underlying pixelref. This state can be set, but it cannot be |
| 171 cleared once it is set. This state propagates to all other bitmaps | 175 cleared once it is set. This state propagates to all other bitmaps |
| 172 that share the same pixelref. | 176 that share the same pixelref. |
| 173 */ | 177 */ |
| 174 void setImmutable(); | 178 void setImmutable(); |
| 175 | 179 |
| 176 /** Returns true if the bitmap is opaque (has no translucent/transparent pix
els). | 180 /** Returns true if the bitmap is opaque (has no translucent/transparent pix
els). |
| 177 */ | 181 */ |
| 178 bool isOpaque() const; | 182 bool isOpaque() const { |
| 183 return SkAlphaTypeIsOpaque(this->alphaType()); |
| 184 } |
| 179 | 185 |
| 180 /** Specify if this bitmap's pixels are all opaque or not. Is only meaningfu
l for configs | 186 /** |
| 181 that support per-pixel alpha (RGB32, A1, A8). | 187 * DEPRECATED: use setAlpahType() instead. |
| 182 */ | 188 */ |
| 183 void setIsOpaque(bool); | 189 void setIsOpaque(bool opaque) { |
| 190 this->setAlphaType(opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); |
| 191 } |
| 184 | 192 |
| 185 /** Returns true if the bitmap is volatile (i.e. should not be cached by dev
ices.) | 193 /** Returns true if the bitmap is volatile (i.e. should not be cached by dev
ices.) |
| 186 */ | 194 */ |
| 187 bool isVolatile() const; | 195 bool isVolatile() const; |
| 188 | 196 |
| 189 /** Specify whether this bitmap is volatile. Bitmaps are not volatile by | 197 /** Specify whether this bitmap is volatile. Bitmaps are not volatile by |
| 190 default. Temporary bitmaps that are discarded after use should be | 198 default. Temporary bitmaps that are discarded after use should be |
| 191 marked as volatile. This provides a hint to the device that the bitmap | 199 marked as volatile. This provides a hint to the device that the bitmap |
| 192 should not be cached. Providing this hint when appropriate can | 200 should not be cached. Providing this hint when appropriate can |
| 193 improve performance by avoiding unnecessary overhead and resource | 201 improve performance by avoiding unnecessary overhead and resource |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 * are opaque. If it fails to read the pixels, or encounters an error, | 233 * are opaque. If it fails to read the pixels, or encounters an error, |
| 226 * it will return false. | 234 * it will return false. |
| 227 * | 235 * |
| 228 * Since this can be an expensive operation, the bitmap stores a flag for | 236 * Since this can be an expensive operation, the bitmap stores a flag for |
| 229 * this (isOpaque, setIsOpaque). Only call this if you need to compute this | 237 * this (isOpaque, setIsOpaque). Only call this if you need to compute this |
| 230 * value from "unknown" pixels. | 238 * value from "unknown" pixels. |
| 231 */ | 239 */ |
| 232 static bool ComputeIsOpaque(const SkBitmap&); | 240 static bool ComputeIsOpaque(const SkBitmap&); |
| 233 | 241 |
| 234 /** | 242 /** |
| 235 * Calls ComputeIsOpaque, and passes its result to setIsOpaque(). | |
| 236 */ | |
| 237 void computeAndSetOpaquePredicate() { | |
| 238 this->setIsOpaque(ComputeIsOpaque(*this)); | |
| 239 } | |
| 240 | |
| 241 /** | |
| 242 * Return the bitmap's bounds [0, 0, width, height] as an SkRect | 243 * Return the bitmap's bounds [0, 0, width, height] as an SkRect |
| 243 */ | 244 */ |
| 244 void getBounds(SkRect* bounds) const; | 245 void getBounds(SkRect* bounds) const; |
| 245 void getBounds(SkIRect* bounds) const; | 246 void getBounds(SkIRect* bounds) const; |
| 246 | 247 |
| 247 /** Set the bitmap's config and dimensions. If rowBytes is 0, then | 248 /** Set the bitmap's config and dimensions. If rowBytes is 0, then |
| 248 ComputeRowBytes() is called to compute the optimal value. This resets | 249 ComputeRowBytes() is called to compute the optimal value. This resets |
| 249 any pixel/colortable ownership, just like reset(). | 250 any pixel/colortable ownership, just like reset(). |
| 250 */ | 251 */ |
| 251 void setConfig(Config, int width, int height, size_t rowBytes = 0); | 252 bool setConfig(Config, int width, int height, size_t rowBytes, SkAlphaType); |
| 253 |
| 254 bool setConfig(Config config, int width, int height, size_t rowBytes = 0) { |
| 255 return this->setConfig(config, width, height, rowBytes, |
| 256 kPremul_SkAlphaType); |
| 257 } |
| 258 |
| 259 |
| 252 /** Use this to assign a new pixel address for an existing bitmap. This | 260 /** Use this to assign a new pixel address for an existing bitmap. This |
| 253 will automatically release any pixelref previously installed. Only call | 261 will automatically release any pixelref previously installed. Only call |
| 254 this if you are handling ownership/lifetime of the pixel memory. | 262 this if you are handling ownership/lifetime of the pixel memory. |
| 255 | 263 |
| 256 If the bitmap retains a reference to the colortable (assuming it is | 264 If the bitmap retains a reference to the colortable (assuming it is |
| 257 not null) it will take care of incrementing the reference count. | 265 not null) it will take care of incrementing the reference count. |
| 258 | 266 |
| 259 @param pixels Address for the pixels, managed by the caller. | 267 @param pixels Address for the pixels, managed by the caller. |
| 260 @param ctable ColorTable (or null) that matches the specified pixels | 268 @param ctable ColorTable (or null) that matches the specified pixels |
| 261 */ | 269 */ |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 * is drawn scaled down. | 673 * is drawn scaled down. |
| 666 */ | 674 */ |
| 667 kHasHardwareMipMap_Flag = 0x08, | 675 kHasHardwareMipMap_Flag = 0x08, |
| 668 #endif | 676 #endif |
| 669 }; | 677 }; |
| 670 | 678 |
| 671 uint32_t fRowBytes; | 679 uint32_t fRowBytes; |
| 672 uint32_t fWidth; | 680 uint32_t fWidth; |
| 673 uint32_t fHeight; | 681 uint32_t fHeight; |
| 674 uint8_t fConfig; | 682 uint8_t fConfig; |
| 683 uint8_t fAlphaType; |
| 675 uint8_t fFlags; | 684 uint8_t fFlags; |
| 676 uint8_t fBytesPerPixel; // based on config | 685 uint8_t fBytesPerPixel; // based on config |
| 677 | 686 |
| 678 void internalErase(const SkIRect&, U8CPU a, U8CPU r, U8CPU g, U8CPU b)const; | 687 void internalErase(const SkIRect&, U8CPU a, U8CPU r, U8CPU g, U8CPU b)const; |
| 679 | 688 |
| 680 /* Internal computations for safe size. | 689 /* Internal computations for safe size. |
| 681 */ | 690 */ |
| 682 static Sk64 ComputeSafeSize64(Config config, | 691 static Sk64 ComputeSafeSize64(Config config, |
| 683 uint32_t width, | 692 uint32_t width, |
| 684 uint32_t height, | 693 uint32_t height, |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 | 820 |
| 812 // returns the address of the byte that contains the x coordinate | 821 // returns the address of the byte that contains the x coordinate |
| 813 inline uint8_t* SkBitmap::getAddr1(int x, int y) const { | 822 inline uint8_t* SkBitmap::getAddr1(int x, int y) const { |
| 814 SkASSERT(fPixels); | 823 SkASSERT(fPixels); |
| 815 SkASSERT(fConfig == kA1_Config); | 824 SkASSERT(fConfig == kA1_Config); |
| 816 SkASSERT((unsigned)x < fWidth && (unsigned)y < fHeight); | 825 SkASSERT((unsigned)x < fWidth && (unsigned)y < fHeight); |
| 817 return (uint8_t*)fPixels + y * fRowBytes + (x >> 3); | 826 return (uint8_t*)fPixels + y * fRowBytes + (x >> 3); |
| 818 } | 827 } |
| 819 | 828 |
| 820 #endif | 829 #endif |
| OLD | NEW |