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 27 matching lines...) Expand all Loading... |
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; |
179 | 183 |
180 /** Specify if this bitmap's pixels are all opaque or not. Is only meaningfu
l for configs | 184 /** |
181 that support per-pixel alpha (RGB32, A1, A8). | 185 * DEPRECATED: use setAlpahType() instead. |
182 */ | 186 */ |
183 void setIsOpaque(bool); | 187 void setIsOpaque(bool opaque) { |
| 188 this->setAlphaType(opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); |
| 189 } |
184 | 190 |
185 /** Returns true if the bitmap is volatile (i.e. should not be cached by dev
ices.) | 191 /** Returns true if the bitmap is volatile (i.e. should not be cached by dev
ices.) |
186 */ | 192 */ |
187 bool isVolatile() const; | 193 bool isVolatile() const; |
188 | 194 |
189 /** Specify whether this bitmap is volatile. Bitmaps are not volatile by | 195 /** Specify whether this bitmap is volatile. Bitmaps are not volatile by |
190 default. Temporary bitmaps that are discarded after use should be | 196 default. Temporary bitmaps that are discarded after use should be |
191 marked as volatile. This provides a hint to the device that the bitmap | 197 marked as volatile. This provides a hint to the device that the bitmap |
192 should not be cached. Providing this hint when appropriate can | 198 should not be cached. Providing this hint when appropriate can |
193 improve performance by avoiding unnecessary overhead and resource | 199 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, | 231 * are opaque. If it fails to read the pixels, or encounters an error, |
226 * it will return false. | 232 * it will return false. |
227 * | 233 * |
228 * Since this can be an expensive operation, the bitmap stores a flag for | 234 * 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 | 235 * this (isOpaque, setIsOpaque). Only call this if you need to compute this |
230 * value from "unknown" pixels. | 236 * value from "unknown" pixels. |
231 */ | 237 */ |
232 static bool ComputeIsOpaque(const SkBitmap&); | 238 static bool ComputeIsOpaque(const SkBitmap&); |
233 | 239 |
234 /** | 240 /** |
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 | 241 * Return the bitmap's bounds [0, 0, width, height] as an SkRect |
243 */ | 242 */ |
244 void getBounds(SkRect* bounds) const; | 243 void getBounds(SkRect* bounds) const; |
245 void getBounds(SkIRect* bounds) const; | 244 void getBounds(SkIRect* bounds) const; |
246 | 245 |
247 /** Set the bitmap's config and dimensions. If rowBytes is 0, then | 246 /** Set the bitmap's config and dimensions. If rowBytes is 0, then |
248 ComputeRowBytes() is called to compute the optimal value. This resets | 247 ComputeRowBytes() is called to compute the optimal value. This resets |
249 any pixel/colortable ownership, just like reset(). | 248 any pixel/colortable ownership, just like reset(). |
250 */ | 249 */ |
251 void setConfig(Config, int width, int height, size_t rowBytes = 0); | 250 bool setConfig(Config, int width, int height, size_t rowBytes, SkAlphaType); |
| 251 |
| 252 bool setConfig(Config config, int width, int height, size_t rowBytes = 0) { |
| 253 return this->setConfig(config, width, height, rowBytes, |
| 254 kPremul_SkAlphaType); |
| 255 } |
| 256 |
| 257 |
252 /** Use this to assign a new pixel address for an existing bitmap. This | 258 /** Use this to assign a new pixel address for an existing bitmap. This |
253 will automatically release any pixelref previously installed. Only call | 259 will automatically release any pixelref previously installed. Only call |
254 this if you are handling ownership/lifetime of the pixel memory. | 260 this if you are handling ownership/lifetime of the pixel memory. |
255 | 261 |
256 If the bitmap retains a reference to the colortable (assuming it is | 262 If the bitmap retains a reference to the colortable (assuming it is |
257 not null) it will take care of incrementing the reference count. | 263 not null) it will take care of incrementing the reference count. |
258 | 264 |
259 @param pixels Address for the pixels, managed by the caller. | 265 @param pixels Address for the pixels, managed by the caller. |
260 @param ctable ColorTable (or null) that matches the specified pixels | 266 @param ctable ColorTable (or null) that matches the specified pixels |
261 */ | 267 */ |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 * is drawn scaled down. | 671 * is drawn scaled down. |
666 */ | 672 */ |
667 kHasHardwareMipMap_Flag = 0x08, | 673 kHasHardwareMipMap_Flag = 0x08, |
668 #endif | 674 #endif |
669 }; | 675 }; |
670 | 676 |
671 uint32_t fRowBytes; | 677 uint32_t fRowBytes; |
672 uint32_t fWidth; | 678 uint32_t fWidth; |
673 uint32_t fHeight; | 679 uint32_t fHeight; |
674 uint8_t fConfig; | 680 uint8_t fConfig; |
| 681 uint8_t fAlphaType; |
675 uint8_t fFlags; | 682 uint8_t fFlags; |
676 uint8_t fBytesPerPixel; // based on config | 683 uint8_t fBytesPerPixel; // based on config |
677 | 684 |
678 void internalErase(const SkIRect&, U8CPU a, U8CPU r, U8CPU g, U8CPU b)const; | 685 void internalErase(const SkIRect&, U8CPU a, U8CPU r, U8CPU g, U8CPU b)const; |
679 | 686 |
680 /* Internal computations for safe size. | 687 /* Internal computations for safe size. |
681 */ | 688 */ |
682 static Sk64 ComputeSafeSize64(Config config, | 689 static Sk64 ComputeSafeSize64(Config config, |
683 uint32_t width, | 690 uint32_t width, |
684 uint32_t height, | 691 uint32_t height, |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
811 | 818 |
812 // returns the address of the byte that contains the x coordinate | 819 // returns the address of the byte that contains the x coordinate |
813 inline uint8_t* SkBitmap::getAddr1(int x, int y) const { | 820 inline uint8_t* SkBitmap::getAddr1(int x, int y) const { |
814 SkASSERT(fPixels); | 821 SkASSERT(fPixels); |
815 SkASSERT(fConfig == kA1_Config); | 822 SkASSERT(fConfig == kA1_Config); |
816 SkASSERT((unsigned)x < fWidth && (unsigned)y < fHeight); | 823 SkASSERT((unsigned)x < fWidth && (unsigned)y < fHeight); |
817 return (uint8_t*)fPixels + y * fRowBytes + (x >> 3); | 824 return (uint8_t*)fPixels + y * fRowBytes + (x >> 3); |
818 } | 825 } |
819 | 826 |
820 #endif | 827 #endif |
OLD | NEW |