Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(464)

Side by Side Diff: include/core/SkBitmap.h

Issue 310283004: remove SkBitmap::allocConfigPixels and update dox (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: remove unused function Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gm/gmmain.cpp ('k') | src/core/SkBitmap.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 struct SkMask; 17 struct SkMask;
18 struct SkIRect; 18 struct SkIRect;
19 struct SkRect; 19 struct SkRect;
20 class SkPaint; 20 class SkPaint;
21 class SkPixelRef; 21 class SkPixelRef;
22 class SkPixelRefFactory; 22 class SkPixelRefFactory;
23 class SkRegion; 23 class SkRegion;
24 class SkString; 24 class SkString;
25 class GrTexture; 25 class GrTexture;
26 26
27 /** \class SkBitmap 27 /** \class SkBitmap
28 28
29 The SkBitmap class specifies a raster bitmap. A bitmap has an integer width 29 The SkBitmap class specifies a raster bitmap. A bitmap has an integer width
30 and height, and a format (config), and a pointer to the actual pixels. 30 and height, and a format (colortype), and a pointer to the actual pixels.
31 Bitmaps can be drawn into a SkCanvas, but they are also used to specify the 31 Bitmaps can be drawn into a SkCanvas, but they are also used to specify the
32 target of a SkCanvas' drawing operations. 32 target of a SkCanvas' drawing operations.
33 A const SkBitmap exposes getAddr(), which lets a caller write its pixels; 33 A const SkBitmap exposes getAddr(), which lets a caller write its pixels;
34 the constness is considered to apply to the bitmap's configuration, not 34 the constness is considered to apply to the bitmap's configuration, not
35 its contents. 35 its contents.
36 */ 36 */
37 class SK_API SkBitmap { 37 class SK_API SkBitmap {
38 public: 38 public:
39 class SK_API Allocator; 39 class SK_API Allocator;
40 40
41 enum Config { 41 enum Config {
42 kNo_Config, //!< bitmap has not been configured 42 kNo_Config, //!< bitmap has not been configured
43 kA8_Config, //!< 8-bits per pixel, with only alpha specified (0 is transparent, 0xFF is opaque) 43 kA8_Config, //!< 8-bits per pixel, with only alpha specified (0 is transparent, 0xFF is opaque)
44 kIndex8_Config, //!< 8-bits per pixel, using SkColorTable to specify the colors 44 kIndex8_Config, //!< 8-bits per pixel, using SkColorTable to specify the colors
45 kRGB_565_Config, //!< 16-bits per pixel, (see SkColorPriv.h for packi ng) 45 kRGB_565_Config, //!< 16-bits per pixel, (see SkColorPriv.h for packi ng)
46 kARGB_4444_Config, //!< 16-bits per pixel, (see SkColorPriv.h for packi ng) 46 kARGB_4444_Config, //!< 16-bits per pixel, (see SkColorPriv.h for packi ng)
47 kARGB_8888_Config, //!< 32-bits per pixel, (see SkColorPriv.h for packi ng) 47 kARGB_8888_Config, //!< 32-bits per pixel, (see SkColorPriv.h for packi ng)
48 }; 48 };
49 49
50 // do not add this to the Config enum, otherwise the compiler will let us 50 // do not add this to the Config enum, otherwise the compiler will let us
51 // pass this as a valid parameter for Config. 51 // pass this as a valid parameter for Config.
52 enum { 52 enum {
53 kConfigCount = kARGB_8888_Config + 1 53 kConfigCount = kARGB_8888_Config + 1
54 }; 54 };
55 55
56 /** Return the config for the bitmap. */
57 Config config() const;
scroggo 2014/06/05 16:59:34 Should we deprecate this one too?
58
59 SK_ATTR_DEPRECATED("use config()")
60 Config getConfig() const { return this->config(); }
scroggo 2014/06/05 16:59:34 Does Chrome still use this version? I removed Andr
61
56 /** 62 /**
57 * Default construct creates a bitmap with zero width and height, and no pi xels. 63 * Default construct creates a bitmap with zero width and height, and no pi xels.
58 * Its config is set to kNo_Config. 64 * Its colortype is set to kUnknown_SkColorType.
59 */ 65 */
60 SkBitmap(); 66 SkBitmap();
61 67
62 /** 68 /**
63 * Copy the settings from the src into this bitmap. If the src has pixels 69 * Copy the settings from the src into this bitmap. If the src has pixels
64 * allocated, they will be shared, not copied, so that the two bitmaps will 70 * allocated, they will be shared, not copied, so that the two bitmaps will
65 * reference the same memory for the pixels. If a deep copy is needed, 71 * reference the same memory for the pixels. If a deep copy is needed,
66 * where the new bitmap has its own separate copy of the pixels, use 72 * where the new bitmap has its own separate copy of the pixels, use
67 * deepCopyTo(). 73 * deepCopyTo().
68 */ 74 */
(...skipping 25 matching lines...) Expand all
94 if (kUnknown_SkColorType == this->colorType()) { 100 if (kUnknown_SkColorType == this->colorType()) {
95 return false; 101 return false;
96 } 102 }
97 if (info) { 103 if (info) {
98 *info = this->info(); 104 *info = this->info();
99 } 105 }
100 return true; 106 return true;
101 } 107 }
102 #endif 108 #endif
103 109
104 /** Return the number of bytes per pixel based on the config. If the config 110 /**
105 does not have at least 1 byte per (e.g. kA1_Config) then 0 is returned. 111 * Return the number of bytes per pixel based on the colortype. If the colo rtype is
112 * kUnknown_SkColorType, then 0 is returned.
106 */ 113 */
107 int bytesPerPixel() const { return fInfo.bytesPerPixel(); } 114 int bytesPerPixel() const { return fInfo.bytesPerPixel(); }
108 115
109 /** Return the rowbytes expressed as a number of pixels (like width and 116 /**
110 height). Note, for 1-byte per pixel configs like kA8_Config, this will 117 * Return the rowbytes expressed as a number of pixels (like width and heig ht).
111 return the same as rowBytes(). Is undefined for configs that are less 118 * If the colortype is kUnknown_SkColorType, then 0 is returned.
112 than 1-byte per pixel (e.g. kA1_Config)
113 */ 119 */
114 int rowBytesAsPixels() const { 120 int rowBytesAsPixels() const {
115 return fRowBytes >> this->shiftPerPixel(); 121 return fRowBytes >> this->shiftPerPixel();
116 } 122 }
117 123
118 /** Return the shift amount per pixel (i.e. 0 for 1-byte per pixel, 1 for 124 /**
119 2-bytes per pixel configs, 2 for 4-bytes per pixel configs). Return 0 125 * Return the shift amount per pixel (i.e. 0 for 1-byte per pixel, 1 for 2- bytes per pixel
120 for configs that are not at least 1-byte per pixel (e.g. kA1_Config 126 * colortypes, 2 for 4-bytes per pixel colortypes). Return 0 for kUnknown_S kColorType.
121 or kNo_Config)
122 */ 127 */
123 int shiftPerPixel() const { return this->bytesPerPixel() >> 1; } 128 int shiftPerPixel() const { return this->bytesPerPixel() >> 1; }
124 129
125 /////////////////////////////////////////////////////////////////////////// 130 ///////////////////////////////////////////////////////////////////////////
126 131
127 /** Return true iff the bitmap has empty dimensions. 132 /** Return true iff the bitmap has empty dimensions.
128 * Hey! Before you use this, see if you really want to know drawsNothing() instead. 133 * Hey! Before you use this, see if you really want to know drawsNothing() instead.
129 */ 134 */
130 bool empty() const { return fInfo.isEmpty(); } 135 bool empty() const { return fInfo.isEmpty(); }
131 136
132 /** Return true iff the bitmap has no pixelref. Note: this can return true e ven if the 137 /** Return true iff the bitmap has no pixelref. Note: this can return true e ven if the
133 * dimensions of the bitmap are > 0 (see empty()). 138 * dimensions of the bitmap are > 0 (see empty()).
134 * Hey! Before you use this, see if you really want to know drawsNothing() instead. 139 * Hey! Before you use this, see if you really want to know drawsNothing() instead.
135 */ 140 */
136 bool isNull() const { return NULL == fPixelRef; } 141 bool isNull() const { return NULL == fPixelRef; }
137 142
138 /** Return true iff drawing this bitmap has no effect. 143 /** Return true iff drawing this bitmap has no effect.
139 */ 144 */
140 bool drawsNothing() const { return this->empty() || this->isNull(); } 145 bool drawsNothing() const { return this->empty() || this->isNull(); }
141 146
142 /** Return the config for the bitmap. */
143 Config config() const;
144
145 SK_ATTR_DEPRECATED("use config()")
146 Config getConfig() const { return this->config(); }
147
148 /** Return the number of bytes between subsequent rows of the bitmap. */ 147 /** Return the number of bytes between subsequent rows of the bitmap. */
149 size_t rowBytes() const { return fRowBytes; } 148 size_t rowBytes() const { return fRowBytes; }
150 149
151 /** 150 /**
152 * Set the bitmap's alphaType, returning true on success. If false is 151 * Set the bitmap's alphaType, returning true on success. If false is
153 * returned, then the specified new alphaType is incompatible with the 152 * returned, then the specified new alphaType is incompatible with the
154 * Config, and the current alphaType is unchanged. 153 * colortype, and the current alphaType is unchanged.
155 * 154 *
156 * Note: this changes the alphatype for the underlying pixels, which means 155 * Note: this changes the alphatype for the underlying pixels, which means
157 * that all bitmaps that might be sharing (subsets of) the pixels will 156 * that all bitmaps that might be sharing (subsets of) the pixels will
158 * be affected. 157 * be affected.
159 */ 158 */
160 bool setAlphaType(SkAlphaType); 159 bool setAlphaType(SkAlphaType);
161 160
162 /** Return the address of the pixels for this SkBitmap. 161 /** Return the address of the pixels for this SkBitmap.
163 */ 162 */
164 void* getPixels() const { return fPixels; } 163 void* getPixels() const { return fPixels; }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 improve performance by avoiding unnecessary overhead and resource 220 improve performance by avoiding unnecessary overhead and resource
222 consumption on the device. 221 consumption on the device.
223 */ 222 */
224 void setIsVolatile(bool); 223 void setIsVolatile(bool);
225 224
226 /** Reset the bitmap to its initial state (see default constructor). If we a re a (shared) 225 /** Reset the bitmap to its initial state (see default constructor). If we a re a (shared)
227 owner of the pixels, that ownership is decremented. 226 owner of the pixels, that ownership is decremented.
228 */ 227 */
229 void reset(); 228 void reset();
230 229
230 #ifdef SK_SUPPORT_LEGACY_COMPUTE_CONFIG_SIZE
scroggo 2014/06/05 16:59:34 This needs to be defined in skia_for_android_frame
231 /** Given a config and a width, this computes the optimal rowBytes value. Th is is called automatically 231 /** Given a config and a width, this computes the optimal rowBytes value. Th is is called automatically
232 if you pass 0 for rowBytes to setConfig(). 232 if you pass 0 for rowBytes to setConfig().
233 */ 233 */
234 static size_t ComputeRowBytes(Config c, int width); 234 static size_t ComputeRowBytes(Config c, int width);
235 235
236 /** Return the bytes-per-pixel for the specified config. If the config is 236 /** Return the bytes-per-pixel for the specified config. If the config is
237 not at least 1-byte per pixel, return 0, including for kNo_Config. 237 not at least 1-byte per pixel, return 0, including for kNo_Config.
238 */ 238 */
239 static int ComputeBytesPerPixel(Config c); 239 static int ComputeBytesPerPixel(Config c);
240 240
241 /** Return the shift-per-pixel for the specified config. If the config is 241 /** Return the shift-per-pixel for the specified config. If the config is
242 not at least 1-byte per pixel, return 0, including for kNo_Config. 242 not at least 1-byte per pixel, return 0, including for kNo_Config.
243 */ 243 */
244 static int ComputeShiftPerPixel(Config c) { 244 static int ComputeShiftPerPixel(Config c) {
245 return ComputeBytesPerPixel(c) >> 1; 245 return ComputeBytesPerPixel(c) >> 1;
246 } 246 }
247 247
248 static int64_t ComputeSize64(Config, int width, int height); 248 static int64_t ComputeSize64(Config, int width, int height);
249 static size_t ComputeSize(Config, int width, int height); 249 static size_t ComputeSize(Config, int width, int height);
250 #endif
250 251
251 /** 252 /**
252 * This will brute-force return true if all of the pixels in the bitmap 253 * This will brute-force return true if all of the pixels in the bitmap
253 * are opaque. If it fails to read the pixels, or encounters an error, 254 * are opaque. If it fails to read the pixels, or encounters an error,
254 * it will return false. 255 * it will return false.
255 * 256 *
256 * Since this can be an expensive operation, the bitmap stores a flag for 257 * Since this can be an expensive operation, the bitmap stores a flag for
257 * this (isOpaque). Only call this if you need to compute this value from 258 * this (isOpaque). Only call this if you need to compute this value from
258 * "unknown" pixels. 259 * "unknown" pixels.
259 */ 260 */
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 /** 296 /**
296 * Allocate a pixelref to match the specified image info, using the default 297 * Allocate a pixelref to match the specified image info, using the default
297 * allocator. 298 * allocator.
298 * On success, the bitmap's pixels will be "locked", and return true. 299 * On success, the bitmap's pixels will be "locked", and return true.
299 * On failure, the bitmap will be set to empty and return false. 300 * On failure, the bitmap will be set to empty and return false.
300 */ 301 */
301 bool allocPixels(const SkImageInfo& info) { 302 bool allocPixels(const SkImageInfo& info) {
302 return this->allocPixels(info, NULL, NULL); 303 return this->allocPixels(info, NULL, NULL);
303 } 304 }
304 305
305 /**
306 * Legacy helper function, which creates an SkImageInfo from the specified
307 * config and then calls allocPixels(info).
308 */
309 bool allocConfigPixels(Config, int width, int height, bool isOpaque = false) ;
310
311 bool allocN32Pixels(int width, int height, bool isOpaque = false) { 306 bool allocN32Pixels(int width, int height, bool isOpaque = false) {
312 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); 307 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
313 if (isOpaque) { 308 if (isOpaque) {
314 info.fAlphaType = kOpaque_SkAlphaType; 309 info.fAlphaType = kOpaque_SkAlphaType;
315 } 310 }
316 return this->allocPixels(info); 311 return this->allocPixels(info);
317 } 312 }
318 313
319 /** 314 /**
320 * Install a pixelref that wraps the specified pixels and rowBytes, and 315 * Install a pixelref that wraps the specified pixels and rowBytes, and
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 @param dstSize Size of destination buffer. Must be large enough to hold 372 @param dstSize Size of destination buffer. Must be large enough to hold
378 pixels using indicated stride. 373 pixels using indicated stride.
379 @param dstRowBytes Width of each line in the buffer. If 0, uses 374 @param dstRowBytes Width of each line in the buffer. If 0, uses
380 bitmap's internal stride. 375 bitmap's internal stride.
381 @param preserveDstPad Must we preserve padding in the dst 376 @param preserveDstPad Must we preserve padding in the dst
382 */ 377 */
383 bool copyPixelsTo(void* const dst, size_t dstSize, size_t dstRowBytes = 0, 378 bool copyPixelsTo(void* const dst, size_t dstSize, size_t dstRowBytes = 0,
384 bool preserveDstPad = false) const; 379 bool preserveDstPad = false) const;
385 380
386 /** Use the standard HeapAllocator to create the pixelref that manages the 381 /** Use the standard HeapAllocator to create the pixelref that manages the
387 pixel memory. It will be sized based on the current width/height/config. 382 pixel memory. It will be sized based on the current ImageInfo.
388 If this is called multiple times, a new pixelref object will be created 383 If this is called multiple times, a new pixelref object will be created
389 each time. 384 each time.
390 385
391 If the bitmap retains a reference to the colortable (assuming it is 386 If the bitmap retains a reference to the colortable (assuming it is
392 not null) it will take care of incrementing the reference count. 387 not null) it will take care of incrementing the reference count.
393 388
394 @param ctable ColorTable (or null) to use with the pixels that will 389 @param ctable ColorTable (or null) to use with the pixels that will
395 be allocated. Only used if config == Index8_Config 390 be allocated. Only used if colortype == kIndex_8_SkColor Type
396 @return true if the allocation succeeds. If not the pixelref field of 391 @return true if the allocation succeeds. If not the pixelref field of
397 the bitmap will be unchanged. 392 the bitmap will be unchanged.
398 */ 393 */
399 bool allocPixels(SkColorTable* ctable = NULL) { 394 bool allocPixels(SkColorTable* ctable = NULL) {
400 return this->allocPixels(NULL, ctable); 395 return this->allocPixels(NULL, ctable);
401 } 396 }
402 397
403 /** Use the specified Allocator to create the pixelref that manages the 398 /** Use the specified Allocator to create the pixelref that manages the
404 pixel memory. It will be sized based on the current width/height/config. 399 pixel memory. It will be sized based on the current ImageInfo.
405 If this is called multiple times, a new pixelref object will be created 400 If this is called multiple times, a new pixelref object will be created
406 each time. 401 each time.
407 402
408 If the bitmap retains a reference to the colortable (assuming it is 403 If the bitmap retains a reference to the colortable (assuming it is
409 not null) it will take care of incrementing the reference count. 404 not null) it will take care of incrementing the reference count.
410 405
411 @param allocator The Allocator to use to create a pixelref that can 406 @param allocator The Allocator to use to create a pixelref that can
412 manage the pixel memory for the current 407 manage the pixel memory for the current ImageInfo.
413 width/height/config. If allocator is NULL, the standard 408 If allocator is NULL, the standard HeapAllocator will b e used.
414 HeapAllocator will be used.
415 @param ctable ColorTable (or null) to use with the pixels that will 409 @param ctable ColorTable (or null) to use with the pixels that will
416 be allocated. Only used if config == Index8_Config. 410 be allocated. Only used if colortype == kIndex_8_SkColor Type.
417 If it is non-null and the config is not Index8, it will 411 If it is non-null and the colortype is not indexed, it w ill
418 be ignored. 412 be ignored.
419 @return true if the allocation succeeds. If not the pixelref field of 413 @return true if the allocation succeeds. If not the pixelref field of
420 the bitmap will be unchanged. 414 the bitmap will be unchanged.
421 */ 415 */
422 bool allocPixels(Allocator* allocator, SkColorTable* ctable); 416 bool allocPixels(Allocator* allocator, SkColorTable* ctable);
423 417
424 /** 418 /**
425 * Return the current pixelref object or NULL if there is none. This does 419 * Return the current pixelref object or NULL if there is none. This does
426 * not affect the refcount of the pixelref. 420 * not affect the refcount of the pixelref.
427 */ 421 */
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 465
472 /** 466 /**
473 * Some bitmaps can return a copy of their pixels for lockPixels(), but 467 * Some bitmaps can return a copy of their pixels for lockPixels(), but
474 * that copy, if modified, will not be pushed back. These bitmaps should 468 * that copy, if modified, will not be pushed back. These bitmaps should
475 * not be used as targets for a raster device/canvas (since all pixels 469 * not be used as targets for a raster device/canvas (since all pixels
476 * modifications will be lost when unlockPixels() is called.) 470 * modifications will be lost when unlockPixels() is called.)
477 */ 471 */
478 bool lockPixelsAreWritable() const; 472 bool lockPixelsAreWritable() const;
479 473
480 /** Call this to be sure that the bitmap is valid enough to be drawn (i.e. 474 /** Call this to be sure that the bitmap is valid enough to be drawn (i.e.
481 it has non-null pixels, and if required by its config, it has a 475 it has non-null pixels, and if required by its colortype, it has a
482 non-null colortable. Returns true if all of the above are met. 476 non-null colortable. Returns true if all of the above are met.
483 */ 477 */
484 bool readyToDraw() const { 478 bool readyToDraw() const {
485 return this->getPixels() != NULL && 479 return this->getPixels() != NULL &&
486 (this->colorType() != kIndex_8_SkColorType || NULL != fColorTable ); 480 (this->colorType() != kIndex_8_SkColorType || NULL != fColorTable );
487 } 481 }
488 482
489 /** Returns the pixelRef's texture, or NULL 483 /** Returns the pixelRef's texture, or NULL
490 */ 484 */
491 GrTexture* getTexture() const; 485 GrTexture* getTexture() const;
(...skipping 13 matching lines...) Expand all
505 uint32_t getGenerationID() const; 499 uint32_t getGenerationID() const;
506 500
507 /** Call this if you have changed the contents of the pixels. This will in- 501 /** Call this if you have changed the contents of the pixels. This will in-
508 turn cause a different generation ID value to be returned from 502 turn cause a different generation ID value to be returned from
509 getGenerationID(). 503 getGenerationID().
510 */ 504 */
511 void notifyPixelsChanged() const; 505 void notifyPixelsChanged() const;
512 506
513 /** 507 /**
514 * Fill the entire bitmap with the specified color. 508 * Fill the entire bitmap with the specified color.
515 * If the bitmap's config does not support alpha (e.g. 565) then the alpha 509 * If the bitmap's colortype does not support alpha (e.g. 565) then the alp ha
516 * 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 suppo rts
517 * alpha (e.g. A1 or A8) then the color's r,g,b components are ignored. 511 * alpha (e.g. A1 or A8) then the color's r,g,b components are ignored.
518 */ 512 */
519 void eraseColor(SkColor c) const { 513 void eraseColor(SkColor c) const {
520 this->eraseARGB(SkColorGetA(c), SkColorGetR(c), SkColorGetG(c), 514 this->eraseARGB(SkColorGetA(c), SkColorGetR(c), SkColorGetG(c),
521 SkColorGetB(c)); 515 SkColorGetB(c));
522 } 516 }
523 517
524 /** 518 /**
525 * Fill the entire bitmap with the specified color. 519 * Fill the entire bitmap with the specified color.
526 * If the bitmap's config does not support alpha (e.g. 565) then the alpha 520 * If the bitmap's colortype does not support alpha (e.g. 565) then the alp ha
527 * of the color is ignored (treated as opaque). If the config only supports 521 * of the color is ignored (treated as opaque). If the colortype only suppo rts
528 * alpha (e.g. A1 or A8) then the color's r,g,b components are ignored. 522 * alpha (e.g. A1 or A8) then the color's r,g,b components are ignored.
529 */ 523 */
530 void eraseARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b) const; 524 void eraseARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b) const;
531 525
532 SK_ATTR_DEPRECATED("use eraseARGB or eraseColor") 526 SK_ATTR_DEPRECATED("use eraseARGB or eraseColor")
533 void eraseRGB(U8CPU r, U8CPU g, U8CPU b) const { 527 void eraseRGB(U8CPU r, U8CPU g, U8CPU b) const {
534 this->eraseARGB(0xFF, r, g, b); 528 this->eraseARGB(0xFF, r, g, b);
535 } 529 }
536 530
537 /** 531 /**
538 * Fill the specified area of this bitmap with the specified color. 532 * Fill the specified area of this bitmap with the specified color.
539 * If the bitmap's config does not support alpha (e.g. 565) then the alpha 533 * If the bitmap's colortype does not support alpha (e.g. 565) then the alp ha
540 * of the color is ignored (treated as opaque). If the config only supports 534 * of the color is ignored (treated as opaque). If the colortype only suppo rts
541 * alpha (e.g. A1 or A8) then the color's r,g,b components are ignored. 535 * alpha (e.g. A1 or A8) then the color's r,g,b components are ignored.
542 */ 536 */
543 void eraseArea(const SkIRect& area, SkColor c) const; 537 void eraseArea(const SkIRect& area, SkColor c) const;
544 538
545 /** Scroll (a subset of) the contents of this bitmap by dx/dy. If there are 539 /** Scroll (a subset of) the contents of this bitmap by dx/dy. If there are
546 no pixels allocated (i.e. getPixels() returns null) the method will 540 no pixels allocated (i.e. getPixels() returns null) the method will
547 still update the inval region (if present). If the bitmap is immutable, 541 still update the inval region (if present). If the bitmap is immutable,
548 do nothing and return false. 542 do nothing and return false.
549 543
550 @param subset The subset of the bitmap to scroll/move. To scroll the 544 @param subset The subset of the bitmap to scroll/move. To scroll the
551 entire contents, specify [0, 0, width, height] or just 545 entire contents, specify [0, 0, width, height] or just
552 pass null. 546 pass null.
553 @param dx The amount to scroll in X 547 @param dx The amount to scroll in X
554 @param dy The amount to scroll in Y 548 @param dy The amount to scroll in Y
555 @param inval Optional (may be null). Returns the area of the bitmap that 549 @param inval Optional (may be null). Returns the area of the bitmap that
556 was scrolled away. E.g. if dx = dy = 0, then inval would 550 was scrolled away. E.g. if dx = dy = 0, then inval would
557 be set to empty. If dx >= width or dy >= height, then 551 be set to empty. If dx >= width or dy >= height, then
558 inval would be set to the entire bounds of the bitmap. 552 inval would be set to the entire bounds of the bitmap.
559 @return true if the scroll was doable. Will return false if the bitmap 553 @return true if the scroll was doable. Will return false if the colortyp e is kUnkown or
560 uses an unsupported config for scrolling (only kA8, 554 if the bitmap is immutable.
561 kIndex8, kRGB_565, kARGB_4444, kARGB_8888 are supported).
562 If no pixels are present (i.e. getPixels() returns false) 555 If no pixels are present (i.e. getPixels() returns false)
563 inval will still be updated, and true will be returned. 556 inval will still be updated, and true will be returned.
564 */ 557 */
565 bool scrollRect(const SkIRect* subset, int dx, int dy, 558 bool scrollRect(const SkIRect* subset, int dx, int dy,
566 SkRegion* inval = NULL) const; 559 SkRegion* inval = NULL) const;
567 560
568 /** 561 /**
569 * Return the SkColor of the specified pixel. In most cases this will 562 * Return the SkColor of the specified pixel. In most cases this will
570 * require un-premultiplying the color. Alpha only configs (A1 and A8) 563 * require un-premultiplying the color. Alpha only colortypes (e.g. kAlpha _8_SkColorType)
571 * return black with the appropriate alpha set. The value is undefined 564 * return black with the appropriate alpha set. The value is undefined
572 * for kNone_Config or if x or y are out of bounds, or if the bitmap 565 * for kUnknown_SkColorType or if x or y are out of bounds, or if the bitma p
573 * does not have any pixels (or has not be locked with lockPixels()). 566 * does not have any pixels (or has not be locked with lockPixels()).
574 */ 567 */
575 SkColor getColor(int x, int y) const; 568 SkColor getColor(int x, int y) const;
576 569
577 /** Returns the address of the specified pixel. This performs a runtime 570 /** Returns the address of the specified pixel. This performs a runtime
578 check to know the size of the pixels, and will return the same answer 571 check to know the size of the pixels, and will return the same answer
579 as the corresponding size-specific method (e.g. getAddr16). Since the 572 as the corresponding size-specific method (e.g. getAddr16). Since the
580 check happens at runtime, it is much slower than using a size-specific 573 check happens at runtime, it is much slower than using a size-specific
581 version. Unlike the size-specific methods, this routine also checks if 574 version. Unlike the size-specific methods, this routine also checks if
582 getPixels() returns null, and returns that. The size-specific routines 575 getPixels() returns null, and returns that. The size-specific routines
583 perform a debugging assert that getPixels() is not null, but they do 576 perform a debugging assert that getPixels() is not null, but they do
584 not do any runtime checks. 577 not do any runtime checks.
585 */ 578 */
586 void* getAddr(int x, int y) const; 579 void* getAddr(int x, int y) const;
587 580
588 /** Returns the address of the pixel specified by x,y for 32bit pixels. 581 /** Returns the address of the pixel specified by x,y for 32bit pixels.
589 * In debug build, this asserts that the pixels are allocated and locked, 582 * In debug build, this asserts that the pixels are allocated and locked,
590 * and that the config is 32-bit, however none of these checks are performe d 583 * and that the colortype is 32-bit, however none of these checks are perfo rmed
591 * in the release build. 584 * in the release build.
592 */ 585 */
593 inline uint32_t* getAddr32(int x, int y) const; 586 inline uint32_t* getAddr32(int x, int y) const;
594 587
595 /** Returns the address of the pixel specified by x,y for 16bit pixels. 588 /** Returns the address of the pixel specified by x,y for 16bit pixels.
596 * In debug build, this asserts that the pixels are allocated and locked, 589 * In debug build, this asserts that the pixels are allocated and locked,
597 * and that the config is 16-bit, however none of these checks are performe d 590 * and that the colortype is 16-bit, however none of these checks are perfo rmed
598 * in the release build. 591 * in the release build.
599 */ 592 */
600 inline uint16_t* getAddr16(int x, int y) const; 593 inline uint16_t* getAddr16(int x, int y) const;
601 594
602 /** Returns the address of the pixel specified by x,y for 8bit pixels. 595 /** Returns the address of the pixel specified by x,y for 8bit pixels.
603 * In debug build, this asserts that the pixels are allocated and locked, 596 * In debug build, this asserts that the pixels are allocated and locked,
604 * and that the config is 8-bit, however none of these checks are performed 597 * and that the colortype is 8-bit, however none of these checks are perfor med
605 * in the release build. 598 * in the release build.
606 */ 599 */
607 inline uint8_t* getAddr8(int x, int y) const; 600 inline uint8_t* getAddr8(int x, int y) const;
608 601
609 /** Returns the color corresponding to the pixel specified by x,y for 602 /** Returns the color corresponding to the pixel specified by x,y for
610 * colortable based bitmaps. 603 * colortable based bitmaps.
611 * In debug build, this asserts that the pixels are allocated and locked, 604 * In debug build, this asserts that the pixels are allocated and locked,
612 * that the config is kIndex8, and that the colortable is allocated, 605 * that the colortype is indexed, and that the colortable is allocated,
613 * however none of these checks are performed in the release build. 606 * however none of these checks are performed in the release build.
614 */ 607 */
615 inline SkPMColor getIndex8Color(int x, int y) const; 608 inline SkPMColor getIndex8Color(int x, int y) const;
616 609
617 /** Set dst to be a setset of this bitmap. If possible, it will share the 610 /** Set dst to be a setset of this bitmap. If possible, it will share the
618 pixel memory, and just point into a subset of it. However, if the config 611 pixel memory, and just point into a subset of it. However, if the colort ype
619 does not support this, a local copy will be made and associated with 612 does not support this, a local copy will be made and associated with
620 the dst bitmap. If the subset rectangle, intersected with the bitmap's 613 the dst bitmap. If the subset rectangle, intersected with the bitmap's
621 dimensions is empty, or if there is an unsupported config, false will be 614 dimensions is empty, or if there is an unsupported colortype, false will be
622 returned and dst will be untouched. 615 returned and dst will be untouched.
623 @param dst The bitmap that will be set to a subset of this bitmap 616 @param dst The bitmap that will be set to a subset of this bitmap
624 @param subset The rectangle of pixels in this bitmap that dst will 617 @param subset The rectangle of pixels in this bitmap that dst will
625 reference. 618 reference.
626 @return true if the subset copy was successfully made. 619 @return true if the subset copy was successfully made.
627 */ 620 */
628 bool extractSubset(SkBitmap* dst, const SkIRect& subset) const; 621 bool extractSubset(SkBitmap* dst, const SkIRect& subset) const;
629 622
630 /** Makes a deep copy of this bitmap, respecting the requested colorType, 623 /** Makes a deep copy of this bitmap, respecting the requested colorType,
631 * and allocating the dst pixels on the cpu. 624 * and allocating the dst pixels on the cpu.
632 * Returns false if either there is an error (i.e. the src does not have 625 * Returns false if either there is an error (i.e. the src does not have
633 * pixels) or the request cannot be satisfied (e.g. the src has per-pixel 626 * pixels) or the request cannot be satisfied (e.g. the src has per-pixel
634 * alpha, and the requested config does not support alpha). 627 * alpha, and the requested colortype does not support alpha).
635 * @param dst The bitmap to be sized and allocated 628 * @param dst The bitmap to be sized and allocated
636 * @param ct The desired colorType for dst 629 * @param ct The desired colorType for dst
637 * @param allocator Allocator used to allocate the pixelref for the dst 630 * @param allocator Allocator used to allocate the pixelref for the dst
638 * bitmap. If this is null, the standard HeapAllocator 631 * bitmap. If this is null, the standard HeapAllocator
639 * will be used. 632 * will be used.
640 * @return true if the copy was made. 633 * @return true if the copy was made.
641 */ 634 */
642 bool copyTo(SkBitmap* dst, SkColorType ct, Allocator* = NULL) const; 635 bool copyTo(SkBitmap* dst, SkColorType ct, Allocator* = NULL) const;
643 636
644 bool copyTo(SkBitmap* dst, Allocator* allocator = NULL) const { 637 bool copyTo(SkBitmap* dst, Allocator* allocator = NULL) const {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 bool extractAlpha(SkBitmap* dst, const SkPaint* paint, Allocator* allocator, 691 bool extractAlpha(SkBitmap* dst, const SkPaint* paint, Allocator* allocator,
699 SkIPoint* offset) const; 692 SkIPoint* offset) const;
700 693
701 SkDEBUGCODE(void validate() const;) 694 SkDEBUGCODE(void validate() const;)
702 695
703 class Allocator : public SkRefCnt { 696 class Allocator : public SkRefCnt {
704 public: 697 public:
705 SK_DECLARE_INST_COUNT(Allocator) 698 SK_DECLARE_INST_COUNT(Allocator)
706 699
707 /** Allocate the pixel memory for the bitmap, given its dimensions and 700 /** Allocate the pixel memory for the bitmap, given its dimensions and
708 config. Return true on success, where success means either setPixels 701 colortype. Return true on success, where success means either setPix els
709 or setPixelRef was called. The pixels need not be locked when this 702 or setPixelRef was called. The pixels need not be locked when this
710 returns. If the config requires a colortable, it also must be 703 returns. If the colortype requires a colortable, it also must be
711 installed via setColorTable. If false is returned, the bitmap and 704 installed via setColorTable. If false is returned, the bitmap and
712 colortable should be left unchanged. 705 colortable should be left unchanged.
713 */ 706 */
714 virtual bool allocPixelRef(SkBitmap*, SkColorTable*) = 0; 707 virtual bool allocPixelRef(SkBitmap*, SkColorTable*) = 0;
715 private: 708 private:
716 typedef SkRefCnt INHERITED; 709 typedef SkRefCnt INHERITED;
717 }; 710 };
718 711
719 /** Subclass of Allocator that returns a pixelref that allocates its pixel 712 /** Subclass of Allocator that returns a pixelref that allocates its pixel
720 memory from the heap. This is the default Allocator invoked by 713 memory from the heap. This is the default Allocator invoked by
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 }; 764 };
772 765
773 SkImageInfo fInfo; 766 SkImageInfo fInfo;
774 767
775 uint32_t fRowBytes; 768 uint32_t fRowBytes;
776 769
777 uint8_t fFlags; 770 uint8_t fFlags;
778 771
779 void internalErase(const SkIRect&, U8CPU a, U8CPU r, U8CPU g, U8CPU b)const; 772 void internalErase(const SkIRect&, U8CPU a, U8CPU r, U8CPU g, U8CPU b)const;
780 773
781 /* Internal computations for safe size.
782 */
783 static int64_t ComputeSafeSize64(Config config,
784 uint32_t width,
785 uint32_t height,
786 size_t rowBytes);
787 static size_t ComputeSafeSize(Config config,
788 uint32_t width,
789 uint32_t height,
790 size_t rowBytes);
791
792 /* Unreference any pixelrefs or colortables 774 /* Unreference any pixelrefs or colortables
793 */ 775 */
794 void freePixels(); 776 void freePixels();
795 void updatePixelsFromRef() const; 777 void updatePixelsFromRef() const;
796 778
797 void legacyUnflatten(SkReadBuffer&); 779 void legacyUnflatten(SkReadBuffer&);
798 780
799 static void WriteRawPixels(SkWriteBuffer*, const SkBitmap&); 781 static void WriteRawPixels(SkWriteBuffer*, const SkBitmap&);
800 static bool ReadRawPixels(SkReadBuffer*, SkBitmap*); 782 static bool ReadRawPixels(SkReadBuffer*, SkBitmap*);
801 783
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 } 894 }
913 895
914 /////////////////////////////////////////////////////////////////////////////// 896 ///////////////////////////////////////////////////////////////////////////////
915 // 897 //
916 // Helpers until we can fully deprecate SkBitmap::Config 898 // Helpers until we can fully deprecate SkBitmap::Config
917 // 899 //
918 extern SkBitmap::Config SkColorTypeToBitmapConfig(SkColorType); 900 extern SkBitmap::Config SkColorTypeToBitmapConfig(SkColorType);
919 extern SkColorType SkBitmapConfigToColorType(SkBitmap::Config); 901 extern SkColorType SkBitmapConfigToColorType(SkBitmap::Config);
920 902
921 #endif 903 #endif
OLDNEW
« no previous file with comments | « gm/gmmain.cpp ('k') | src/core/SkBitmap.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698