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