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 |
| 136 /** |
| 137 * Set the bitmap's alphaType, returning true on success. If false is |
| 138 * returned, then the specified new alphaType is incompatible with the |
| 139 * Config, and the current alphaType is unchanged. |
| 140 */ |
| 141 bool setAlphaType(SkAlphaType); |
| 142 |
133 /** Return the address of the pixels for this SkBitmap. | 143 /** Return the address of the pixels for this SkBitmap. |
134 */ | 144 */ |
135 void* getPixels() const { return fPixels; } | 145 void* getPixels() const { return fPixels; } |
136 | 146 |
137 /** Return the byte size of the pixels, based on the height and rowBytes. | 147 /** 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 | 148 Note this truncates the result to 32bits. Call getSize64() to detect |
139 if the real size exceeds 32bits. | 149 if the real size exceeds 32bits. |
140 */ | 150 */ |
141 size_t getSize() const { return fHeight * fRowBytes; } | 151 size_t getSize() const { return fHeight * fRowBytes; } |
142 | 152 |
(...skipping 25 matching lines...) Expand all Loading... |
168 /** Marks this bitmap as immutable, meaning that the contents of its | 178 /** 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 | 179 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 | 180 underlying pixelref. This state can be set, but it cannot be |
171 cleared once it is set. This state propagates to all other bitmaps | 181 cleared once it is set. This state propagates to all other bitmaps |
172 that share the same pixelref. | 182 that share the same pixelref. |
173 */ | 183 */ |
174 void setImmutable(); | 184 void setImmutable(); |
175 | 185 |
176 /** Returns true if the bitmap is opaque (has no translucent/transparent pix
els). | 186 /** Returns true if the bitmap is opaque (has no translucent/transparent pix
els). |
177 */ | 187 */ |
178 bool isOpaque() const; | 188 bool isOpaque() const { |
| 189 return SkAlphaTypeIsOpaque(this->alphaType()); |
| 190 } |
179 | 191 |
180 /** Specify if this bitmap's pixels are all opaque or not. Is only meaningfu
l for configs | 192 /** |
181 that support per-pixel alpha (RGB32, A1, A8). | 193 * DEPRECATED: use setAlpahType() instead. |
182 */ | 194 */ |
183 void setIsOpaque(bool); | 195 void setIsOpaque(bool opaque) { |
| 196 this->setAlphaType(opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); |
| 197 } |
184 | 198 |
185 /** Returns true if the bitmap is volatile (i.e. should not be cached by dev
ices.) | 199 /** Returns true if the bitmap is volatile (i.e. should not be cached by dev
ices.) |
186 */ | 200 */ |
187 bool isVolatile() const; | 201 bool isVolatile() const; |
188 | 202 |
189 /** Specify whether this bitmap is volatile. Bitmaps are not volatile by | 203 /** Specify whether this bitmap is volatile. Bitmaps are not volatile by |
190 default. Temporary bitmaps that are discarded after use should be | 204 default. Temporary bitmaps that are discarded after use should be |
191 marked as volatile. This provides a hint to the device that the bitmap | 205 marked as volatile. This provides a hint to the device that the bitmap |
192 should not be cached. Providing this hint when appropriate can | 206 should not be cached. Providing this hint when appropriate can |
193 improve performance by avoiding unnecessary overhead and resource | 207 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, | 239 * are opaque. If it fails to read the pixels, or encounters an error, |
226 * it will return false. | 240 * it will return false. |
227 * | 241 * |
228 * Since this can be an expensive operation, the bitmap stores a flag for | 242 * 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 | 243 * this (isOpaque, setIsOpaque). Only call this if you need to compute this |
230 * value from "unknown" pixels. | 244 * value from "unknown" pixels. |
231 */ | 245 */ |
232 static bool ComputeIsOpaque(const SkBitmap&); | 246 static bool ComputeIsOpaque(const SkBitmap&); |
233 | 247 |
234 /** | 248 /** |
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 | 249 * Return the bitmap's bounds [0, 0, width, height] as an SkRect |
243 */ | 250 */ |
244 void getBounds(SkRect* bounds) const; | 251 void getBounds(SkRect* bounds) const; |
245 void getBounds(SkIRect* bounds) const; | 252 void getBounds(SkIRect* bounds) const; |
246 | 253 |
247 /** Set the bitmap's config and dimensions. If rowBytes is 0, then | 254 /** Set the bitmap's config and dimensions. If rowBytes is 0, then |
248 ComputeRowBytes() is called to compute the optimal value. This resets | 255 ComputeRowBytes() is called to compute the optimal value. This resets |
249 any pixel/colortable ownership, just like reset(). | 256 any pixel/colortable ownership, just like reset(). |
250 */ | 257 */ |
251 void setConfig(Config, int width, int height, size_t rowBytes = 0); | 258 bool setConfig(Config, int width, int height, size_t rowBytes, SkAlphaType); |
| 259 |
| 260 bool setConfig(Config config, int width, int height, size_t rowBytes = 0) { |
| 261 return this->setConfig(config, width, height, rowBytes, |
| 262 kPremul_SkAlphaType); |
| 263 } |
| 264 |
| 265 |
252 /** Use this to assign a new pixel address for an existing bitmap. This | 266 /** Use this to assign a new pixel address for an existing bitmap. This |
253 will automatically release any pixelref previously installed. Only call | 267 will automatically release any pixelref previously installed. Only call |
254 this if you are handling ownership/lifetime of the pixel memory. | 268 this if you are handling ownership/lifetime of the pixel memory. |
255 | 269 |
256 If the bitmap retains a reference to the colortable (assuming it is | 270 If the bitmap retains a reference to the colortable (assuming it is |
257 not null) it will take care of incrementing the reference count. | 271 not null) it will take care of incrementing the reference count. |
258 | 272 |
259 @param pixels Address for the pixels, managed by the caller. | 273 @param pixels Address for the pixels, managed by the caller. |
260 @param ctable ColorTable (or null) that matches the specified pixels | 274 @param ctable ColorTable (or null) that matches the specified pixels |
261 */ | 275 */ |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 * is drawn scaled down. | 679 * is drawn scaled down. |
666 */ | 680 */ |
667 kHasHardwareMipMap_Flag = 0x08, | 681 kHasHardwareMipMap_Flag = 0x08, |
668 #endif | 682 #endif |
669 }; | 683 }; |
670 | 684 |
671 uint32_t fRowBytes; | 685 uint32_t fRowBytes; |
672 uint32_t fWidth; | 686 uint32_t fWidth; |
673 uint32_t fHeight; | 687 uint32_t fHeight; |
674 uint8_t fConfig; | 688 uint8_t fConfig; |
| 689 uint8_t fAlphaType; |
675 uint8_t fFlags; | 690 uint8_t fFlags; |
676 uint8_t fBytesPerPixel; // based on config | 691 uint8_t fBytesPerPixel; // based on config |
677 | 692 |
678 void internalErase(const SkIRect&, U8CPU a, U8CPU r, U8CPU g, U8CPU b)const; | 693 void internalErase(const SkIRect&, U8CPU a, U8CPU r, U8CPU g, U8CPU b)const; |
679 | 694 |
680 /* Internal computations for safe size. | 695 /* Internal computations for safe size. |
681 */ | 696 */ |
682 static Sk64 ComputeSafeSize64(Config config, | 697 static Sk64 ComputeSafeSize64(Config config, |
683 uint32_t width, | 698 uint32_t width, |
684 uint32_t height, | 699 uint32_t height, |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
811 | 826 |
812 // returns the address of the byte that contains the x coordinate | 827 // returns the address of the byte that contains the x coordinate |
813 inline uint8_t* SkBitmap::getAddr1(int x, int y) const { | 828 inline uint8_t* SkBitmap::getAddr1(int x, int y) const { |
814 SkASSERT(fPixels); | 829 SkASSERT(fPixels); |
815 SkASSERT(fConfig == kA1_Config); | 830 SkASSERT(fConfig == kA1_Config); |
816 SkASSERT((unsigned)x < fWidth && (unsigned)y < fHeight); | 831 SkASSERT((unsigned)x < fWidth && (unsigned)y < fHeight); |
817 return (uint8_t*)fPixels + y * fRowBytes + (x >> 3); | 832 return (uint8_t*)fPixels + y * fRowBytes + (x >> 3); |
818 } | 833 } |
819 | 834 |
820 #endif | 835 #endif |
OLD | NEW |