OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkBitmap_DEFINED | 8 #ifndef SkBitmap_DEFINED |
9 #define SkBitmap_DEFINED | 9 #define SkBitmap_DEFINED |
10 | 10 |
11 #include "SkColor.h" | 11 #include "SkColor.h" |
12 #include "SkColorTable.h" | 12 #include "SkColorTable.h" |
13 #include "SkImageInfo.h" | 13 #include "SkImageInfo.h" |
14 #include "SkPoint.h" | 14 #include "SkPoint.h" |
15 #include "SkRefCnt.h" | 15 #include "SkRefCnt.h" |
16 | 16 |
| 17 #define SK_SUPPORT_LEGACY_BITMAPCONFIG |
| 18 //#define SK_SUPPORT_LEGACY_BITMAP_COMPUTESIZE |
| 19 |
17 struct SkIRect; | 20 struct SkIRect; |
18 struct SkRect; | 21 struct SkRect; |
19 class SkPaint; | 22 class SkPaint; |
20 class SkPixelRef; | 23 class SkPixelRef; |
21 class SkPixelRefFactory; | 24 class SkPixelRefFactory; |
22 class SkRegion; | 25 class SkRegion; |
23 class SkString; | 26 class SkString; |
24 | 27 |
25 class GrTexture; | 28 class GrTexture; |
26 | 29 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 84 |
82 /////////////////////////////////////////////////////////////////////////// | 85 /////////////////////////////////////////////////////////////////////////// |
83 | 86 |
84 const SkImageInfo& info() const { return fInfo; } | 87 const SkImageInfo& info() const { return fInfo; } |
85 | 88 |
86 int width() const { return fInfo.fWidth; } | 89 int width() const { return fInfo.fWidth; } |
87 int height() const { return fInfo.fHeight; } | 90 int height() const { return fInfo.fHeight; } |
88 SkColorType colorType() const { return fInfo.fColorType; } | 91 SkColorType colorType() const { return fInfo.fColorType; } |
89 SkAlphaType alphaType() const { return fInfo.fAlphaType; } | 92 SkAlphaType alphaType() const { return fInfo.fAlphaType; } |
90 | 93 |
91 /** Return the number of bytes per pixel based on the config. If the config | 94 /** |
92 does not have at least 1 byte per (e.g. kA1_Config) then 0 is returned. | 95 * Return the number of bytes per pixel based on the colorType. |
93 */ | 96 */ |
94 int bytesPerPixel() const { return fInfo.bytesPerPixel(); } | 97 int bytesPerPixel() const { return fInfo.bytesPerPixel(); } |
95 | 98 |
96 /** Return the rowbytes expressed as a number of pixels (like width and | 99 /** |
97 height). Note, for 1-byte per pixel configs like kA8_Config, this will | 100 * Return the rowbytes expressed as a number of pixels (like width and |
98 return the same as rowBytes(). Is undefined for configs that are less | 101 * height). |
99 than 1-byte per pixel (e.g. kA1_Config) | |
100 */ | 102 */ |
101 int rowBytesAsPixels() const { | 103 int rowBytesAsPixels() const { |
102 return fRowBytes >> this->shiftPerPixel(); | 104 return fRowBytes >> this->shiftPerPixel(); |
103 } | 105 } |
104 | 106 |
105 /** Return the shift amount per pixel (i.e. 0 for 1-byte per pixel, 1 for | 107 /** |
106 2-bytes per pixel configs, 2 for 4-bytes per pixel configs). Return 0 | 108 * Return the shift amount per pixel (i.e. 0 for 1-byte per pixel, 1 for |
107 for configs that are not at least 1-byte per pixel (e.g. kA1_Config | 109 * 2-bytes per pixel configs, 2 for 4-bytes per pixel configs). |
108 or kNo_Config) | |
109 */ | 110 */ |
110 int shiftPerPixel() const { return this->bytesPerPixel() >> 1; } | 111 int shiftPerPixel() const { return this->bytesPerPixel() >> 1; } |
111 | 112 |
112 /////////////////////////////////////////////////////////////////////////// | 113 /////////////////////////////////////////////////////////////////////////// |
113 | 114 |
114 /** Return true iff the bitmap has empty dimensions. | 115 /** Return true iff the bitmap has empty dimensions. |
115 * Hey! Before you use this, see if you really want to know drawsNothing()
instead. | 116 * Hey! Before you use this, see if you really want to know drawsNothing()
instead. |
116 */ | 117 */ |
117 bool empty() const { return fInfo.isEmpty(); } | 118 bool empty() const { return fInfo.isEmpty(); } |
118 | 119 |
119 /** Return true iff the bitmap has no pixelref. Note: this can return true e
ven if the | 120 /** Return true iff the bitmap has no pixelref. Note: this can return true e
ven if the |
120 * dimensions of the bitmap are > 0 (see empty()). | 121 * dimensions of the bitmap are > 0 (see empty()). |
121 * Hey! Before you use this, see if you really want to know drawsNothing()
instead. | 122 * Hey! Before you use this, see if you really want to know drawsNothing()
instead. |
122 */ | 123 */ |
123 bool isNull() const { return NULL == fPixelRef; } | 124 bool isNull() const { return NULL == fPixelRef; } |
124 | 125 |
125 /** Return true iff drawing this bitmap has no effect. | 126 /** Return true iff drawing this bitmap has no effect. |
126 */ | 127 */ |
127 bool drawsNothing() const { return this->empty() || this->isNull(); } | 128 bool drawsNothing() const { return this->empty() || this->isNull(); } |
128 | 129 |
129 /** Return the config for the bitmap. */ | 130 //#ifdef SK_SUPPORT_LEGACY_BITMAPCONFIG |
| 131 SK_ATTR_DEPRECATED("use colorType()") |
130 Config config() const; | 132 Config config() const; |
131 | 133 |
132 SK_ATTR_DEPRECATED("use config()") | 134 SK_ATTR_DEPRECATED("use colorType()") |
133 Config getConfig() const { return this->config(); } | 135 Config getConfig() const { return this->config(); } |
| 136 //#endif |
134 | 137 |
135 /** Return the number of bytes between subsequent rows of the bitmap. */ | 138 /** Return the number of bytes between subsequent rows of the bitmap. */ |
136 size_t rowBytes() const { return fRowBytes; } | 139 size_t rowBytes() const { return fRowBytes; } |
137 | 140 |
138 /** | 141 /** |
139 * Set the bitmap's alphaType, returning true on success. If false is | 142 * Set the bitmap's alphaType, returning true on success. If false is |
140 * returned, then the specified new alphaType is incompatible with the | 143 * returned, then the specified new alphaType is incompatible with the |
141 * Config, and the current alphaType is unchanged. | 144 * ColorType, and the current alphaType is unchanged. |
142 * | 145 * |
143 * Note: this changes the alphatype for the underlying pixels, which means | 146 * Note: this changes the alphatype for the underlying pixels, which means |
144 * that all bitmaps that might be sharing (subsets of) the pixels will | 147 * that all bitmaps that might be sharing (subsets of) the pixels will |
145 * be affected. | 148 * be affected. |
146 */ | 149 */ |
147 bool setAlphaType(SkAlphaType); | 150 bool setAlphaType(SkAlphaType); |
148 | 151 |
149 /** Return the address of the pixels for this SkBitmap. | 152 /** Return the address of the pixels for this SkBitmap. |
150 */ | 153 */ |
151 void* getPixels() const { return fPixels; } | 154 void* getPixels() const { return fPixels; } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 improve performance by avoiding unnecessary overhead and resource | 211 improve performance by avoiding unnecessary overhead and resource |
209 consumption on the device. | 212 consumption on the device. |
210 */ | 213 */ |
211 void setIsVolatile(bool); | 214 void setIsVolatile(bool); |
212 | 215 |
213 /** Reset the bitmap to its initial state (see default constructor). If we a
re a (shared) | 216 /** Reset the bitmap to its initial state (see default constructor). If we a
re a (shared) |
214 owner of the pixels, that ownership is decremented. | 217 owner of the pixels, that ownership is decremented. |
215 */ | 218 */ |
216 void reset(); | 219 void reset(); |
217 | 220 |
218 /** Given a config and a width, this computes the optimal rowBytes value. Th
is is called automatically | 221 #ifdef SK_SUPPORT_LEGACY_BITMAP_COMPUTESIZE |
219 if you pass 0 for rowBytes to setConfig(). | 222 /** |
220 */ | 223 * Given a config and a width, this computes the optimal rowBytes value. |
| 224 * This is called automatically if you pass 0 for rowBytes to setConfig(). |
| 225 */ |
221 static size_t ComputeRowBytes(Config c, int width); | 226 static size_t ComputeRowBytes(Config c, int width); |
222 | 227 |
223 /** Return the bytes-per-pixel for the specified config. If the config is | 228 /** Return the bytes-per-pixel for the specified config. If the config is |
224 not at least 1-byte per pixel, return 0, including for kNo_Config. | 229 not at least 1-byte per pixel, return 0, including for kNo_Config. |
225 */ | 230 */ |
226 static int ComputeBytesPerPixel(Config c); | 231 static int ComputeBytesPerPixel(Config c); |
227 | 232 |
228 /** Return the shift-per-pixel for the specified config. If the config is | 233 /** Return the shift-per-pixel for the specified config. If the config is |
229 not at least 1-byte per pixel, return 0, including for kNo_Config. | 234 not at least 1-byte per pixel, return 0, including for kNo_Config. |
230 */ | 235 */ |
231 static int ComputeShiftPerPixel(Config c) { | 236 static int ComputeShiftPerPixel(Config c) { |
232 return ComputeBytesPerPixel(c) >> 1; | 237 return ComputeBytesPerPixel(c) >> 1; |
233 } | 238 } |
234 | 239 |
235 static int64_t ComputeSize64(Config, int width, int height); | 240 static int64_t ComputeSize64(Config, int width, int height); |
236 static size_t ComputeSize(Config, int width, int height); | 241 static size_t ComputeSize(Config, int width, int height); |
| 242 #endif |
237 | 243 |
238 /** | 244 /** |
239 * This will brute-force return true if all of the pixels in the bitmap | 245 * This will brute-force return true if all of the pixels in the bitmap |
240 * are opaque. If it fails to read the pixels, or encounters an error, | 246 * are opaque. If it fails to read the pixels, or encounters an error, |
241 * it will return false. | 247 * it will return false. |
242 * | 248 * |
243 * Since this can be an expensive operation, the bitmap stores a flag for | 249 * Since this can be an expensive operation, the bitmap stores a flag for |
244 * this (isOpaque). Only call this if you need to compute this value from | 250 * this (isOpaque). Only call this if you need to compute this value from |
245 * "unknown" pixels. | 251 * "unknown" pixels. |
246 */ | 252 */ |
247 static bool ComputeIsOpaque(const SkBitmap&); | 253 static bool ComputeIsOpaque(const SkBitmap&); |
248 | 254 |
249 /** | 255 /** |
250 * Return the bitmap's bounds [0, 0, width, height] as an SkRect | 256 * Return the bitmap's bounds [0, 0, width, height] as an SkRect |
251 */ | 257 */ |
252 void getBounds(SkRect* bounds) const; | 258 void getBounds(SkRect* bounds) const; |
253 void getBounds(SkIRect* bounds) const; | 259 void getBounds(SkIRect* bounds) const; |
254 | 260 |
| 261 #ifdef SK_SUPPORT_LEGACY_BITMAPCONFIG |
255 /** Set the bitmap's config and dimensions. If rowBytes is 0, then | 262 /** Set the bitmap's config and dimensions. If rowBytes is 0, then |
256 ComputeRowBytes() is called to compute the optimal value. This resets | 263 ComputeRowBytes() is called to compute the optimal value. This resets |
257 any pixel/colortable ownership, just like reset(). | 264 any pixel/colortable ownership, just like reset(). |
258 */ | 265 */ |
259 bool setConfig(Config, int width, int height, size_t rowBytes, SkAlphaType); | 266 bool setConfig(Config, int width, int height, size_t rowBytes, SkAlphaType); |
260 | 267 |
261 bool setConfig(Config config, int width, int height, size_t rowBytes = 0) { | 268 bool setConfig(Config config, int width, int height, size_t rowBytes = 0) { |
262 return this->setConfig(config, width, height, rowBytes, | 269 return this->setConfig(config, width, height, rowBytes, |
263 kPremul_SkAlphaType); | 270 kPremul_SkAlphaType); |
264 } | 271 } |
| 272 #endif |
265 | 273 |
266 bool setConfig(const SkImageInfo& info, size_t rowBytes = 0); | 274 bool setConfig(const SkImageInfo& info, size_t rowBytes = 0); |
267 | 275 |
268 /** | 276 /** |
269 * Allocate a pixelref to match the specified image info. If the Factory | 277 * Allocate a pixelref to match the specified image info. If the Factory |
270 * is non-null, call it to allcoate the pixelref. If the ImageInfo requires | 278 * is non-null, call it to allcoate the pixelref. If the ImageInfo requires |
271 * a colortable, then ColorTable must be non-null, and will be ref'd. | 279 * a colortable, then ColorTable must be non-null, and will be ref'd. |
272 * On failure, the bitmap will be set to empty and return false. | 280 * On failure, the bitmap will be set to empty and return false. |
273 */ | 281 */ |
274 bool allocPixels(const SkImageInfo&, SkPixelRefFactory*, SkColorTable*); | 282 bool allocPixels(const SkImageInfo&, SkPixelRefFactory*, SkColorTable*); |
275 | 283 |
276 /** | 284 /** |
277 * Allocate a pixelref to match the specified image info, using the default | 285 * Allocate a pixelref to match the specified image info, using the default |
278 * allocator. | 286 * allocator. |
279 * On success, the bitmap's pixels will be "locked", and return true. | 287 * On success, the bitmap's pixels will be "locked", and return true. |
280 * On failure, the bitmap will be set to empty and return false. | 288 * On failure, the bitmap will be set to empty and return false. |
281 */ | 289 */ |
282 bool allocPixels(const SkImageInfo& info) { | 290 bool allocPixels(const SkImageInfo& info) { |
283 return this->allocPixels(info, NULL, NULL); | 291 return this->allocPixels(info, NULL, NULL); |
284 } | 292 } |
285 | 293 |
| 294 #ifdef SK_SUPPORT_LEGACY_BITMAPCONFIG |
286 /** | 295 /** |
287 * Legacy helper function, which creates an SkImageInfo from the specified | 296 * Legacy helper function, which creates an SkImageInfo from the specified |
288 * config and then calls allocPixels(info). | 297 * config and then calls allocPixels(info). |
289 */ | 298 */ |
290 bool allocConfigPixels(Config, int width, int height, bool isOpaque = false)
; | 299 bool allocConfigPixels(Config, int width, int height, bool isOpaque = false)
; |
| 300 #endif |
291 | 301 |
292 bool allocN32Pixels(int width, int height, bool isOpaque = false) { | 302 bool allocN32Pixels(int width, int height, bool isOpaque = false) { |
293 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); | 303 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
294 if (isOpaque) { | 304 if (isOpaque) { |
295 info.fAlphaType = kOpaque_SkAlphaType; | 305 info.fAlphaType = kOpaque_SkAlphaType; |
296 } | 306 } |
297 return this->allocPixels(info); | 307 return this->allocPixels(info); |
298 } | 308 } |
299 | 309 |
300 /** | 310 /** |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 @param dstSize Size of destination buffer. Must be large enough to hold | 359 @param dstSize Size of destination buffer. Must be large enough to hold |
350 pixels using indicated stride. | 360 pixels using indicated stride. |
351 @param dstRowBytes Width of each line in the buffer. If 0, uses | 361 @param dstRowBytes Width of each line in the buffer. If 0, uses |
352 bitmap's internal stride. | 362 bitmap's internal stride. |
353 @param preserveDstPad Must we preserve padding in the dst | 363 @param preserveDstPad Must we preserve padding in the dst |
354 */ | 364 */ |
355 bool copyPixelsTo(void* const dst, size_t dstSize, size_t dstRowBytes = 0, | 365 bool copyPixelsTo(void* const dst, size_t dstSize, size_t dstRowBytes = 0, |
356 bool preserveDstPad = false) const; | 366 bool preserveDstPad = false) const; |
357 | 367 |
358 /** Use the standard HeapAllocator to create the pixelref that manages the | 368 /** Use the standard HeapAllocator to create the pixelref that manages the |
359 pixel memory. It will be sized based on the current width/height/config. | 369 pixel memory. It will be sized based on the current ImageInfo. |
360 If this is called multiple times, a new pixelref object will be created | 370 If this is called multiple times, a new pixelref object will be created |
361 each time. | 371 each time. |
362 | 372 |
363 If the bitmap retains a reference to the colortable (assuming it is | 373 If the bitmap retains a reference to the colortable (assuming it is |
364 not null) it will take care of incrementing the reference count. | 374 not null) it will take care of incrementing the reference count. |
365 | 375 |
366 @param ctable ColorTable (or null) to use with the pixels that will | 376 @param ctable ColorTable (or null) to use with the pixels that will |
367 be allocated. Only used if config == Index8_Config | 377 be allocated. Only used if ColorType == Index_8 |
368 @return true if the allocation succeeds. If not the pixelref field of | 378 @return true if the allocation succeeds. If not the pixelref field of |
369 the bitmap will be unchanged. | 379 the bitmap will be unchanged. |
370 */ | 380 */ |
371 bool allocPixels(SkColorTable* ctable = NULL) { | 381 bool allocPixels(SkColorTable* ctable = NULL) { |
372 return this->allocPixels(NULL, ctable); | 382 return this->allocPixels(NULL, ctable); |
373 } | 383 } |
374 | 384 |
375 /** Use the specified Allocator to create the pixelref that manages the | 385 /** Use the specified Allocator to create the pixelref that manages the |
376 pixel memory. It will be sized based on the current width/height/config. | 386 pixel memory. It will be sized based on the current ImageInfo. |
377 If this is called multiple times, a new pixelref object will be created | 387 If this is called multiple times, a new pixelref object will be created |
378 each time. | 388 each time. |
379 | 389 |
380 If the bitmap retains a reference to the colortable (assuming it is | 390 If the bitmap retains a reference to the colortable (assuming it is |
381 not null) it will take care of incrementing the reference count. | 391 not null) it will take care of incrementing the reference count. |
382 | 392 |
383 @param allocator The Allocator to use to create a pixelref that can | 393 @param allocator The Allocator to use to create a pixelref that can |
384 manage the pixel memory for the current | 394 manage the pixel memory for the current ImageInfo. |
385 width/height/config. If allocator is NULL, the standard | 395 If allocator is NULL, the standard HeapAllocator will |
386 HeapAllocator will be used. | 396 be used. |
387 @param ctable ColorTable (or null) to use with the pixels that will | 397 @param ctable ColorTable (or null) to use with the pixels that will |
388 be allocated. Only used if config == Index8_Config. | 398 be allocated. Only used if ColorType == Index_8. |
389 If it is non-null and the config is not Index8, it will | 399 If it is non-null and the colorType is not Index_8, it |
390 be ignored. | 400 will be ignored. |
391 @return true if the allocation succeeds. If not the pixelref field of | 401 @return true if the allocation succeeds. If not the pixelref field of |
392 the bitmap will be unchanged. | 402 the bitmap will be unchanged. |
393 */ | 403 */ |
394 bool allocPixels(Allocator* allocator, SkColorTable* ctable); | 404 bool allocPixels(Allocator* allocator, SkColorTable* ctable); |
395 | 405 |
396 /** | 406 /** |
397 * Return the current pixelref object or NULL if there is none. This does | 407 * Return the current pixelref object or NULL if there is none. This does |
398 * not affect the refcount of the pixelref. | 408 * not affect the refcount of the pixelref. |
399 */ | 409 */ |
400 SkPixelRef* pixelRef() const { return fPixelRef; } | 410 SkPixelRef* pixelRef() const { return fPixelRef; } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 | 453 |
444 /** | 454 /** |
445 * Some bitmaps can return a copy of their pixels for lockPixels(), but | 455 * Some bitmaps can return a copy of their pixels for lockPixels(), but |
446 * that copy, if modified, will not be pushed back. These bitmaps should | 456 * that copy, if modified, will not be pushed back. These bitmaps should |
447 * not be used as targets for a raster device/canvas (since all pixels | 457 * not be used as targets for a raster device/canvas (since all pixels |
448 * modifications will be lost when unlockPixels() is called.) | 458 * modifications will be lost when unlockPixels() is called.) |
449 */ | 459 */ |
450 bool lockPixelsAreWritable() const; | 460 bool lockPixelsAreWritable() const; |
451 | 461 |
452 /** Call this to be sure that the bitmap is valid enough to be drawn (i.e. | 462 /** Call this to be sure that the bitmap is valid enough to be drawn (i.e. |
453 it has non-null pixels, and if required by its config, it has a | 463 it has non-null pixels, and if required by its colorType, it has a |
454 non-null colortable. Returns true if all of the above are met. | 464 non-null colortable. Returns true if all of the above are met. |
455 */ | 465 */ |
456 bool readyToDraw() const { | 466 bool readyToDraw() const { |
457 return this->getPixels() != NULL && | 467 return NULL != this->getPixels() && |
458 (this->config() != kIndex8_Config || NULL != fColorTable); | 468 (this->colorType() != kIndex_8_SkColorType || |
| 469 NULL != fColorTable); |
459 } | 470 } |
460 | 471 |
461 /** Returns the pixelRef's texture, or NULL | 472 /** Returns the pixelRef's texture, or NULL |
462 */ | 473 */ |
463 GrTexture* getTexture() const; | 474 GrTexture* getTexture() const; |
464 | 475 |
465 /** Return the bitmap's colortable, if it uses one (i.e. colorType is | 476 /** Return the bitmap's colortable, if it uses one (i.e. colorType is |
466 Index_8) and the pixels are locked. | 477 Index_8) and the pixels are locked. |
467 Otherwise returns NULL. Does not affect the colortable's | 478 Otherwise returns NULL. Does not affect the colortable's |
468 reference count. | 479 reference count. |
469 */ | 480 */ |
470 SkColorTable* getColorTable() const { return fColorTable; } | 481 SkColorTable* getColorTable() const { return fColorTable; } |
471 | 482 |
472 /** Returns a non-zero, unique value corresponding to the pixels in our | 483 /** Returns a non-zero, unique value corresponding to the pixels in our |
473 pixelref. Each time the pixels are changed (and notifyPixelsChanged | 484 pixelref. Each time the pixels are changed (and notifyPixelsChanged |
474 is called), a different generation ID will be returned. Finally, if | 485 is called), a different generation ID will be returned. Finally, if |
475 their is no pixelRef then zero is returned. | 486 their is no pixelRef then zero is returned. |
476 */ | 487 */ |
477 uint32_t getGenerationID() const; | 488 uint32_t getGenerationID() const; |
478 | 489 |
479 /** Call this if you have changed the contents of the pixels. This will in- | 490 /** Call this if you have changed the contents of the pixels. This will in- |
480 turn cause a different generation ID value to be returned from | 491 turn cause a different generation ID value to be returned from |
481 getGenerationID(). | 492 getGenerationID(). |
482 */ | 493 */ |
483 void notifyPixelsChanged() const; | 494 void notifyPixelsChanged() const; |
484 | 495 |
485 /** | 496 /** |
486 * Fill the entire bitmap with the specified color. | 497 * Fill the entire bitmap with the specified color. |
487 * If the bitmap's config does not support alpha (e.g. 565) then the alpha | 498 * If the ColorType does not support alpha (e.g. 565) then the alpha |
488 * of the color is ignored (treated as opaque). If the config only supports | 499 * of the color is ignored (treated as opaque). If the config only supports |
489 * alpha (e.g. A1 or A8) then the color's r,g,b components are ignored. | 500 * alpha (e.g. Alpha_8) then the color's r,g,b components are ignored. |
490 */ | 501 */ |
491 void eraseColor(SkColor c) const { | 502 void eraseColor(SkColor c) const { |
492 this->eraseARGB(SkColorGetA(c), SkColorGetR(c), SkColorGetG(c), | 503 this->eraseARGB(SkColorGetA(c), SkColorGetR(c), SkColorGetG(c), |
493 SkColorGetB(c)); | 504 SkColorGetB(c)); |
494 } | 505 } |
495 | 506 |
496 /** | 507 /** |
497 * Fill the entire bitmap with the specified color. | 508 * Fill the entire bitmap with the specified color. |
498 * If the bitmap's config does not support alpha (e.g. 565) then the alpha | 509 * If the ColorType does not support alpha (e.g. 565) then the alpha |
499 * of the color is ignored (treated as opaque). If the config only supports | 510 * of the color is ignored (treated as opaque). If the ColorType only |
500 * alpha (e.g. A1 or A8) then the color's r,g,b components are ignored. | 511 * supports alpha (e.g. Alpha_8) then the r,g,b components are ignored. |
501 */ | 512 */ |
502 void eraseARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b) const; | 513 void eraseARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b) const; |
503 | 514 |
504 SK_ATTR_DEPRECATED("use eraseARGB or eraseColor") | 515 SK_ATTR_DEPRECATED("use eraseARGB or eraseColor") |
505 void eraseRGB(U8CPU r, U8CPU g, U8CPU b) const { | 516 void eraseRGB(U8CPU r, U8CPU g, U8CPU b) const { |
506 this->eraseARGB(0xFF, r, g, b); | 517 this->eraseARGB(0xFF, r, g, b); |
507 } | 518 } |
508 | 519 |
509 /** | 520 /** |
510 * Fill the specified area of this bitmap with the specified color. | 521 * Fill the specified area of this bitmap with the specified color. |
511 * If the bitmap's config does not support alpha (e.g. 565) then the alpha | 522 * If the ColorType does not support alpha (e.g. 565) then the alpha |
512 * of the color is ignored (treated as opaque). If the config only supports | 523 * of the color is ignored (treated as opaque). If the ColorType only |
513 * alpha (e.g. A1 or A8) then the color's r,g,b components are ignored. | 524 * supports alpha (e.g. Alpha_8) then the r,g,b components are ignored. |
514 */ | 525 */ |
515 void eraseArea(const SkIRect& area, SkColor c) const; | 526 void eraseArea(const SkIRect& area, SkColor c) const; |
516 | 527 |
517 /** Scroll (a subset of) the contents of this bitmap by dx/dy. If there are | 528 /** Scroll (a subset of) the contents of this bitmap by dx/dy. If there are |
518 no pixels allocated (i.e. getPixels() returns null) the method will | 529 no pixels allocated (i.e. getPixels() returns null) the method will |
519 still update the inval region (if present). If the bitmap is immutable, | 530 still update the inval region (if present). If the bitmap is immutable, |
520 do nothing and return false. | 531 do nothing and return false. |
521 | 532 |
522 @param subset The subset of the bitmap to scroll/move. To scroll the | 533 @param subset The subset of the bitmap to scroll/move. To scroll the |
523 entire contents, specify [0, 0, width, height] or just | 534 entire contents, specify [0, 0, width, height] or just |
524 pass null. | 535 pass null. |
525 @param dx The amount to scroll in X | 536 @param dx The amount to scroll in X |
526 @param dy The amount to scroll in Y | 537 @param dy The amount to scroll in Y |
527 @param inval Optional (may be null). Returns the area of the bitmap that | 538 @param inval Optional (may be null). Returns the area of the bitmap that |
528 was scrolled away. E.g. if dx = dy = 0, then inval would | 539 was scrolled away. E.g. if dx = dy = 0, then inval would |
529 be set to empty. If dx >= width or dy >= height, then | 540 be set to empty. If dx >= width or dy >= height, then |
530 inval would be set to the entire bounds of the bitmap. | 541 inval would be set to the entire bounds of the bitmap. |
531 @return true if the scroll was doable. Will return false if the bitmap | 542 @return true if the scroll was doable. Will return false on failure. |
532 uses an unsupported config for scrolling (only kA8, | |
533 kIndex8, kRGB_565, kARGB_4444, kARGB_8888 are supported). | |
534 If no pixels are present (i.e. getPixels() returns false) | 543 If no pixels are present (i.e. getPixels() returns false) |
535 inval will still be updated, and true will be returned. | 544 inval will still be updated, and true will be returned. |
536 */ | 545 */ |
537 bool scrollRect(const SkIRect* subset, int dx, int dy, | 546 bool scrollRect(const SkIRect* subset, int dx, int dy, |
538 SkRegion* inval = NULL) const; | 547 SkRegion* inval = NULL) const; |
539 | 548 |
540 /** | 549 /** |
541 * Return the SkColor of the specified pixel. In most cases this will | 550 * Return the SkColor of the specified pixel. In most cases this will |
542 * require un-premultiplying the color. Alpha only configs (A1 and A8) | 551 * require un-premultiplying the color. Alpha only ColorType (Alpha_8) |
543 * return black with the appropriate alpha set. The value is undefined | 552 * return black with the appropriate alpha set. The value is undefined |
544 * for kNone_Config or if x or y are out of bounds, or if the bitmap | 553 * for kUnknown_ColorType or if x or y are out of bounds, or if the bitmap |
545 * does not have any pixels (or has not be locked with lockPixels()). | 554 * does not have any pixels (or has not be locked with lockPixels()). |
546 */ | 555 */ |
547 SkColor getColor(int x, int y) const; | 556 SkColor getColor(int x, int y) const; |
548 | 557 |
549 /** Returns the address of the specified pixel. This performs a runtime | 558 /** Returns the address of the specified pixel. This performs a runtime |
550 check to know the size of the pixels, and will return the same answer | 559 check to know the size of the pixels, and will return the same answer |
551 as the corresponding size-specific method (e.g. getAddr16). Since the | 560 as the corresponding size-specific method (e.g. getAddr16). Since the |
552 check happens at runtime, it is much slower than using a size-specific | 561 check happens at runtime, it is much slower than using a size-specific |
553 version. Unlike the size-specific methods, this routine also checks if | 562 version. Unlike the size-specific methods, this routine also checks if |
554 getPixels() returns null, and returns that. The size-specific routines | 563 getPixels() returns null, and returns that. The size-specific routines |
555 perform a debugging assert that getPixels() is not null, but they do | 564 perform a debugging assert that getPixels() is not null, but they do |
556 not do any runtime checks. | 565 not do any runtime checks. |
557 */ | 566 */ |
558 void* getAddr(int x, int y) const; | 567 void* getAddr(int x, int y) const; |
559 | 568 |
560 /** Returns the address of the pixel specified by x,y for 32bit pixels. | 569 /** Returns the address of the pixel specified by x,y for 32bit pixels. |
561 * In debug build, this asserts that the pixels are allocated and locked, | 570 * In debug build, this asserts that the pixels are allocated and locked, |
562 * and that the config is 32-bit, however none of these checks are performe
d | 571 * and that the ColorType is 32-bit, however none of these checks are |
563 * in the release build. | 572 * performed in the release build. |
564 */ | 573 */ |
565 inline uint32_t* getAddr32(int x, int y) const; | 574 inline uint32_t* getAddr32(int x, int y) const; |
566 | 575 |
567 /** Returns the address of the pixel specified by x,y for 16bit pixels. | 576 /** Returns the address of the pixel specified by x,y for 16bit pixels. |
568 * In debug build, this asserts that the pixels are allocated and locked, | 577 * In debug build, this asserts that the pixels are allocated and locked, |
569 * and that the config is 16-bit, however none of these checks are performe
d | 578 * and that the ColorType is 16-bit, however none of these checks are |
570 * in the release build. | 579 * performed in the release build. |
571 */ | 580 */ |
572 inline uint16_t* getAddr16(int x, int y) const; | 581 inline uint16_t* getAddr16(int x, int y) const; |
573 | 582 |
574 /** Returns the address of the pixel specified by x,y for 8bit pixels. | 583 /** Returns the address of the pixel specified by x,y for 8bit pixels. |
575 * In debug build, this asserts that the pixels are allocated and locked, | 584 * In debug build, this asserts that the pixels are allocated and locked, |
576 * and that the config is 8-bit, however none of these checks are performed | 585 * and that the ColorType is 8-bit, however none of these checks are |
577 * in the release build. | 586 * performed in the release build. |
578 */ | 587 */ |
579 inline uint8_t* getAddr8(int x, int y) const; | 588 inline uint8_t* getAddr8(int x, int y) const; |
580 | 589 |
581 /** Returns the color corresponding to the pixel specified by x,y for | 590 /** Returns the color corresponding to the pixel specified by x,y for |
582 * colortable based bitmaps. | 591 * colortable based bitmaps. |
583 * In debug build, this asserts that the pixels are allocated and locked, | 592 * In debug build, this asserts that the pixels are allocated and locked, |
584 * that the config is kIndex8, and that the colortable is allocated, | 593 * that the ColorType is Index_8, and that the colortable is allocated, |
585 * however none of these checks are performed in the release build. | 594 * however none of these checks are performed in the release build. |
586 */ | 595 */ |
587 inline SkPMColor getIndex8Color(int x, int y) const; | 596 inline SkPMColor getIndex8Color(int x, int y) const; |
588 | 597 |
589 /** Set dst to be a setset of this bitmap. If possible, it will share the | 598 /** Set dst to be a setset of this bitmap. If possible, it will share the |
590 pixel memory, and just point into a subset of it. However, if the config | 599 pixel memory, and just point into a subset of it. If this is not |
591 does not support this, a local copy will be made and associated with | 600 supported, a local copy will be made and associated with |
592 the dst bitmap. If the subset rectangle, intersected with the bitmap's | 601 the dst bitmap. If the subset rectangle, intersected with the bitmap's |
593 dimensions is empty, or if there is an unsupported config, false will be | 602 dimensions is empty, or if there is an unsupported colorType, false will |
594 returned and dst will be untouched. | 603 be returned and dst will be untouched. |
595 @param dst The bitmap that will be set to a subset of this bitmap | 604 @param dst The bitmap that will be set to a subset of this bitmap |
596 @param subset The rectangle of pixels in this bitmap that dst will | 605 @param subset The rectangle of pixels in this bitmap that dst will |
597 reference. | 606 reference. |
598 @return true if the subset copy was successfully made. | 607 @return true if the subset copy was successfully made. |
599 */ | 608 */ |
600 bool extractSubset(SkBitmap* dst, const SkIRect& subset) const; | 609 bool extractSubset(SkBitmap* dst, const SkIRect& subset) const; |
601 | 610 |
| 611 #ifdef SK_SUPPORT_LEGACY_BITMAPCONFIG |
602 /** Makes a deep copy of this bitmap, respecting the requested config, | 612 /** Makes a deep copy of this bitmap, respecting the requested config, |
603 * and allocating the dst pixels on the cpu. | 613 * and allocating the dst pixels on the cpu. |
604 * Returns false if either there is an error (i.e. the src does not have | 614 * Returns false if either there is an error (i.e. the src does not have |
605 * pixels) or the request cannot be satisfied (e.g. the src has per-pixel | 615 * pixels) or the request cannot be satisfied (e.g. the src has per-pixel |
606 * alpha, and the requested config does not support alpha). | 616 * alpha, and the requested config does not support alpha). |
607 * @param dst The bitmap to be sized and allocated | 617 * @param dst The bitmap to be sized and allocated |
608 * @param c The desired config for dst | 618 * @param c The desired config for dst |
609 * @param allocator Allocator used to allocate the pixelref for the dst | 619 * @param allocator Allocator used to allocate the pixelref for the dst |
610 * bitmap. If this is null, the standard HeapAllocator | 620 * bitmap. If this is null, the standard HeapAllocator |
611 * will be used. | 621 * will be used. |
612 * @return true if the copy could be made. | 622 * @return true if the copy could be made. |
613 */ | 623 */ |
614 bool copyTo(SkBitmap* dst, Config c, Allocator* allocator = NULL) const; | 624 bool copyTo(SkBitmap* dst, Config c, Allocator* allocator = NULL) const; |
615 | 625 |
616 /** Makes a deep copy of this bitmap, respecting the requested config, and | 626 /** Makes a deep copy of this bitmap, respecting the requested config, and |
617 * with custom allocation logic that will keep the copied pixels | 627 * with custom allocation logic that will keep the copied pixels |
618 * in the same domain as the source: If the src pixels are allocated for | 628 * in the same domain as the source: If the src pixels are allocated for |
619 * the cpu, then so will the dst. If the src pixels are allocated on the | 629 * the cpu, then so will the dst. If the src pixels are allocated on the |
620 * gpu (typically as a texture), the it will do the same for the dst. | 630 * gpu (typically as a texture), the it will do the same for the dst. |
621 * If the request cannot be fulfilled, returns false and dst is unmodified. | 631 * If the request cannot be fulfilled, returns false and dst is unmodified. |
622 */ | 632 */ |
623 bool deepCopyTo(SkBitmap* dst, Config c) const; | 633 bool deepCopyTo(SkBitmap* dst, Config c) const; |
624 | 634 |
625 /** Returns true if this bitmap can be deep copied into the requested config | 635 /** Returns true if this bitmap can be deep copied into the requested config |
626 by calling copyTo(). | 636 by calling copyTo(). |
627 */ | 637 */ |
628 bool canCopyTo(Config newConfig) const; | 638 bool canCopyTo(Config config) const; |
| 639 #endif |
| 640 /** |
| 641 * Returns true if this bitmap can be deep copied into the requested |
| 642 * colorType by calling copyTo(). |
| 643 */ |
| 644 bool canCopyTo(SkColorType) const; |
629 | 645 |
630 SK_ATTR_DEPRECATED("use setFilterLevel on SkPaint") | 646 SK_ATTR_DEPRECATED("use setFilterLevel on SkPaint") |
631 void buildMipMap(bool forceRebuild = false); | 647 void buildMipMap(bool forceRebuild = false); |
632 | 648 |
633 #ifdef SK_BUILD_FOR_ANDROID | 649 #ifdef SK_BUILD_FOR_ANDROID |
634 bool hasHardwareMipMap() const { | 650 bool hasHardwareMipMap() const { |
635 return (fFlags & kHasHardwareMipMap_Flag) != 0; | 651 return (fFlags & kHasHardwareMipMap_Flag) != 0; |
636 } | 652 } |
637 | 653 |
638 void setHasHardwareMipMap(bool hasHardwareMipMap) { | 654 void setHasHardwareMipMap(bool hasHardwareMipMap) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 */ | 694 */ |
679 void flatten(SkWriteBuffer&) const; | 695 void flatten(SkWriteBuffer&) const; |
680 void unflatten(SkReadBuffer&); | 696 void unflatten(SkReadBuffer&); |
681 | 697 |
682 SkDEBUGCODE(void validate() const;) | 698 SkDEBUGCODE(void validate() const;) |
683 | 699 |
684 class Allocator : public SkRefCnt { | 700 class Allocator : public SkRefCnt { |
685 public: | 701 public: |
686 SK_DECLARE_INST_COUNT(Allocator) | 702 SK_DECLARE_INST_COUNT(Allocator) |
687 | 703 |
688 /** Allocate the pixel memory for the bitmap, given its dimensions and | 704 /** Allocate the pixel memory for the bitmap, given its ImageInfo. |
689 config. Return true on success, where success means either setPixels | 705 Return true on success, where success means either setPixels |
690 or setPixelRef was called. The pixels need not be locked when this | 706 or setPixelRef was called. The pixels need not be locked when this |
691 returns. If the config requires a colortable, it also must be | 707 returns. If the ColorType requires a colortable, it also must be |
692 installed via setColorTable. If false is returned, the bitmap and | 708 installed via setColorTable. If false is returned, the bitmap and |
693 colortable should be left unchanged. | 709 colortable should be left unchanged. |
694 */ | 710 */ |
695 virtual bool allocPixelRef(SkBitmap*, SkColorTable*) = 0; | 711 virtual bool allocPixelRef(SkBitmap*, SkColorTable*) = 0; |
696 private: | 712 private: |
697 typedef SkRefCnt INHERITED; | 713 typedef SkRefCnt INHERITED; |
698 }; | 714 }; |
699 | 715 |
700 /** Subclass of Allocator that returns a pixelref that allocates its pixel | 716 /** Subclass of Allocator that returns a pixelref that allocates its pixel |
701 memory from the heap. This is the default Allocator invoked by | 717 memory from the heap. This is the default Allocator invoked by |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
755 }; | 771 }; |
756 | 772 |
757 SkImageInfo fInfo; | 773 SkImageInfo fInfo; |
758 | 774 |
759 uint32_t fRowBytes; | 775 uint32_t fRowBytes; |
760 | 776 |
761 uint8_t fFlags; | 777 uint8_t fFlags; |
762 | 778 |
763 void internalErase(const SkIRect&, U8CPU a, U8CPU r, U8CPU g, U8CPU b)const; | 779 void internalErase(const SkIRect&, U8CPU a, U8CPU r, U8CPU g, U8CPU b)const; |
764 | 780 |
| 781 #ifdef SK_SUPPORT_LEGACY_BITMAP_COMPUTESIZE |
765 /* Internal computations for safe size. | 782 /* Internal computations for safe size. |
766 */ | 783 */ |
767 static int64_t ComputeSafeSize64(Config config, | 784 static int64_t ComputeSafeSize64(Config config, |
768 uint32_t width, | 785 uint32_t width, |
769 uint32_t height, | 786 uint32_t height, |
770 size_t rowBytes); | 787 size_t rowBytes); |
771 static size_t ComputeSafeSize(Config config, | 788 static size_t ComputeSafeSize(Config config, |
772 uint32_t width, | 789 uint32_t width, |
773 uint32_t height, | 790 uint32_t height, |
774 size_t rowBytes); | 791 size_t rowBytes); |
| 792 #endif |
775 | 793 |
776 /* Unreference any pixelrefs or colortables | 794 /* Unreference any pixelrefs or colortables |
777 */ | 795 */ |
778 void freePixels(); | 796 void freePixels(); |
779 void updatePixelsFromRef() const; | 797 void updatePixelsFromRef() const; |
780 | 798 |
781 static SkFixed ComputeMipLevel(SkFixed sx, SkFixed dy); | 799 static SkFixed ComputeMipLevel(SkFixed sx, SkFixed dy); |
782 | 800 |
783 /** Given scale factors sx, sy, determine the miplevel available in the | 801 /** Given scale factors sx, sy, determine the miplevel available in the |
784 bitmap, and return it (this is the amount to shift matrix iterators | 802 bitmap, and return it (this is the amount to shift matrix iterators |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
863 private: | 881 private: |
864 SkColorTable* fCTable; | 882 SkColorTable* fCTable; |
865 const SkPMColor* fColors; | 883 const SkPMColor* fColors; |
866 }; | 884 }; |
867 #define SkAutoLockColors(...) SK_REQUIRE_LOCAL_VAR(SkAutoLockColors) | 885 #define SkAutoLockColors(...) SK_REQUIRE_LOCAL_VAR(SkAutoLockColors) |
868 | 886 |
869 /////////////////////////////////////////////////////////////////////////////// | 887 /////////////////////////////////////////////////////////////////////////////// |
870 | 888 |
871 inline uint32_t* SkBitmap::getAddr32(int x, int y) const { | 889 inline uint32_t* SkBitmap::getAddr32(int x, int y) const { |
872 SkASSERT(fPixels); | 890 SkASSERT(fPixels); |
873 SkASSERT(this->config() == kARGB_8888_Config); | 891 SkASSERT(4 == this->bytesPerPixel()); |
874 SkASSERT((unsigned)x < (unsigned)this->width() && (unsigned)y < (unsigned)th
is->height()); | 892 SkASSERT((unsigned)x < (unsigned)this->width() && (unsigned)y < (unsigned)th
is->height()); |
875 return (uint32_t*)((char*)fPixels + y * fRowBytes + (x << 2)); | 893 return (uint32_t*)((char*)fPixels + y * fRowBytes + (x << 2)); |
876 } | 894 } |
877 | 895 |
878 inline uint16_t* SkBitmap::getAddr16(int x, int y) const { | 896 inline uint16_t* SkBitmap::getAddr16(int x, int y) const { |
879 SkASSERT(fPixels); | 897 SkASSERT(fPixels); |
880 SkASSERT(this->config() == kRGB_565_Config || this->config() == kARGB_4444_C
onfig); | 898 SkASSERT(2 == this->bytesPerPixel()); |
881 SkASSERT((unsigned)x < (unsigned)this->width() && (unsigned)y < (unsigned)th
is->height()); | 899 SkASSERT((unsigned)x < (unsigned)this->width() && (unsigned)y < (unsigned)th
is->height()); |
882 return (uint16_t*)((char*)fPixels + y * fRowBytes + (x << 1)); | 900 return (uint16_t*)((char*)fPixels + y * fRowBytes + (x << 1)); |
883 } | 901 } |
884 | 902 |
885 inline uint8_t* SkBitmap::getAddr8(int x, int y) const { | 903 inline uint8_t* SkBitmap::getAddr8(int x, int y) const { |
886 SkASSERT(fPixels); | 904 SkASSERT(fPixels); |
887 SkASSERT(this->config() == kA8_Config || this->config() == kIndex8_Config); | 905 SkASSERT(1 == this->bytesPerPixel()); |
888 SkASSERT((unsigned)x < (unsigned)this->width() && (unsigned)y < (unsigned)th
is->height()); | 906 SkASSERT((unsigned)x < (unsigned)this->width() && (unsigned)y < (unsigned)th
is->height()); |
889 return (uint8_t*)fPixels + y * fRowBytes + x; | 907 return (uint8_t*)fPixels + y * fRowBytes + x; |
890 } | 908 } |
891 | 909 |
892 inline SkPMColor SkBitmap::getIndex8Color(int x, int y) const { | 910 inline SkPMColor SkBitmap::getIndex8Color(int x, int y) const { |
893 SkASSERT(fPixels); | 911 SkASSERT(fPixels); |
894 SkASSERT(this->config() == kIndex8_Config); | 912 SkASSERT(kIndex_8_SkColorType == this->colorType()); |
895 SkASSERT((unsigned)x < (unsigned)this->width() && (unsigned)y < (unsigned)th
is->height()); | 913 SkASSERT((unsigned)x < (unsigned)this->width() && (unsigned)y < (unsigned)th
is->height()); |
896 SkASSERT(fColorTable); | 914 SkASSERT(fColorTable); |
897 return (*fColorTable)[*((const uint8_t*)fPixels + y * fRowBytes + x)]; | 915 return (*fColorTable)[*((const uint8_t*)fPixels + y * fRowBytes + x)]; |
898 } | 916 } |
899 | 917 |
| 918 /////////////////////////////////////////////////////////////////////////////// |
| 919 |
| 920 extern SkBitmap::Config SkColorTypeToBitmapConfig(SkColorType); |
| 921 extern SkColorType SkBitmapConfigToColorType(SkBitmap::Config); |
| 922 |
900 #endif | 923 #endif |
OLD | NEW |