| 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 |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 HeapAllocator will be used. | 340 HeapAllocator will be used. |
| 341 @param ctable ColorTable (or null) to use with the pixels that will | 341 @param ctable ColorTable (or null) to use with the pixels that will |
| 342 be allocated. Only used if config == Index8_Config. | 342 be allocated. Only used if config == Index8_Config. |
| 343 If it is non-null and the config is not Index8, it will | 343 If it is non-null and the config is not Index8, it will |
| 344 be ignored. | 344 be ignored. |
| 345 @return true if the allocation succeeds. If not the pixelref field of | 345 @return true if the allocation succeeds. If not the pixelref field of |
| 346 the bitmap will be unchanged. | 346 the bitmap will be unchanged. |
| 347 */ | 347 */ |
| 348 bool allocPixels(Allocator* allocator, SkColorTable* ctable); | 348 bool allocPixels(Allocator* allocator, SkColorTable* ctable); |
| 349 | 349 |
| 350 /** Return the current pixelref object, if any | 350 /** |
| 351 */ | 351 * Return the current pixelref object or NULL if there is none. This does |
| 352 * not affect the refcount of the pixelref. |
| 353 */ |
| 352 SkPixelRef* pixelRef() const { return fPixelRef; } | 354 SkPixelRef* pixelRef() const { return fPixelRef; } |
| 353 /** Return the offset into the pixelref, if any. Will return 0 if there is | 355 |
| 354 no pixelref installed. | 356 /** |
| 355 */ | 357 * A bitmap can reference a subset of a pixelref's pixels. That means the |
| 356 size_t pixelRefOffset() const { return fPixelRefOffset; } | 358 * bitmap's width/height can be <= the dimensions of the pixelref. The |
| 357 /** Assign a pixelref and optional offset. Pixelrefs are reference counted, | 359 * pixelref origin is the x,y location within the pixelref's pixels for |
| 358 so the existing one (if any) will be unref'd and the new one will be | 360 * the bitmap's top/left corner. To be valid the following must be true: |
| 359 ref'd. | 361 * |
| 360 */ | 362 * origin_x + bitmap_width <= pixelref_width |
| 361 SkPixelRef* setPixelRef(SkPixelRef* pr, size_t offset = 0); | 363 * origin_y + bitmap_height <= pixelref_height |
| 364 * |
| 365 * pixelRefOrigin() returns this origin, or (0,0) if there is no pixelRef. |
| 366 */ |
| 367 SkIPoint pixelRefOrigin() const { return fPixelRefOrigin; } |
| 368 |
| 369 /** |
| 370 * Assign a pixelref and origin to the bitmap. Pixelrefs are reference, |
| 371 * so the existing one (if any) will be unref'd and the new one will be |
| 372 * ref'd. (x,y) specify the offset within the pixelref's pixels for the |
| 373 * top/left corner of the bitmap. For a bitmap that encompases the entire |
| 374 * pixels of the pixelref, these will be (0,0). |
| 375 */ |
| 376 SkPixelRef* setPixelRef(SkPixelRef* pr, int dx, int dy); |
| 377 |
| 378 SkPixelRef* setPixelRef(SkPixelRef* pr, const SkIPoint& origin) { |
| 379 return this->setPixelRef(pr, origin.fX, origin.fY); |
| 380 } |
| 381 |
| 382 SkPixelRef* setPixelRef(SkPixelRef* pr) { |
| 383 return this->setPixelRef(pr, 0, 0); |
| 384 } |
| 362 | 385 |
| 363 /** Call this to ensure that the bitmap points to the current pixel address | 386 /** Call this to ensure that the bitmap points to the current pixel address |
| 364 in the pixelref. Balance it with a call to unlockPixels(). These calls | 387 in the pixelref. Balance it with a call to unlockPixels(). These calls |
| 365 are harmless if there is no pixelref. | 388 are harmless if there is no pixelref. |
| 366 */ | 389 */ |
| 367 void lockPixels() const; | 390 void lockPixels() const; |
| 368 /** When you are finished access the pixel memory, call this to balance a | 391 /** When you are finished access the pixel memory, call this to balance a |
| 369 previous call to lockPixels(). This allows pixelrefs that implement | 392 previous call to lockPixels(). This allows pixelrefs that implement |
| 370 cached/deferred image decoding to know when there are active clients of | 393 cached/deferred image decoding to know when there are active clients of |
| 371 a given image. | 394 a given image. |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 int fHeight; | 681 int fHeight; |
| 659 }; | 682 }; |
| 660 | 683 |
| 661 SkDEVCODE(void toString(SkString* str) const;) | 684 SkDEVCODE(void toString(SkString* str) const;) |
| 662 | 685 |
| 663 private: | 686 private: |
| 664 struct MipMap; | 687 struct MipMap; |
| 665 mutable MipMap* fMipMap; | 688 mutable MipMap* fMipMap; |
| 666 | 689 |
| 667 mutable SkPixelRef* fPixelRef; | 690 mutable SkPixelRef* fPixelRef; |
| 668 mutable size_t fPixelRefOffset; | |
| 669 mutable int fPixelLockCount; | 691 mutable int fPixelLockCount; |
| 670 // either user-specified (in which case it is not treated as mutable) | 692 // either user-specified (in which case it is not treated as mutable) |
| 671 // or a cache of the returned value from fPixelRef->lockPixels() | 693 // or a cache of the returned value from fPixelRef->lockPixels() |
| 672 mutable void* fPixels; | 694 mutable void* fPixels; |
| 673 mutable SkColorTable* fColorTable; // only meaningful for kIndex8 | 695 mutable SkColorTable* fColorTable; // only meaningful for kIndex8 |
| 674 | 696 |
| 697 SkIPoint fPixelRefOrigin; |
| 698 |
| 675 enum Flags { | 699 enum Flags { |
| 676 kImageIsOpaque_Flag = 0x01, | 700 kImageIsOpaque_Flag = 0x01, |
| 677 kImageIsVolatile_Flag = 0x02, | 701 kImageIsVolatile_Flag = 0x02, |
| 678 kImageIsImmutable_Flag = 0x04, | 702 kImageIsImmutable_Flag = 0x04, |
| 679 #ifdef SK_BUILD_FOR_ANDROID | 703 #ifdef SK_BUILD_FOR_ANDROID |
| 680 /* A hint for the renderer responsible for drawing this bitmap | 704 /* A hint for the renderer responsible for drawing this bitmap |
| 681 * indicating that it should attempt to use mipmaps when this bitmap | 705 * indicating that it should attempt to use mipmaps when this bitmap |
| 682 * is drawn scaled down. | 706 * is drawn scaled down. |
| 683 */ | 707 */ |
| 684 kHasHardwareMipMap_Flag = 0x08, | 708 kHasHardwareMipMap_Flag = 0x08, |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 | 848 |
| 825 inline SkPMColor SkBitmap::getIndex8Color(int x, int y) const { | 849 inline SkPMColor SkBitmap::getIndex8Color(int x, int y) const { |
| 826 SkASSERT(fPixels); | 850 SkASSERT(fPixels); |
| 827 SkASSERT(fConfig == kIndex8_Config); | 851 SkASSERT(fConfig == kIndex8_Config); |
| 828 SkASSERT((unsigned)x < fWidth && (unsigned)y < fHeight); | 852 SkASSERT((unsigned)x < fWidth && (unsigned)y < fHeight); |
| 829 SkASSERT(fColorTable); | 853 SkASSERT(fColorTable); |
| 830 return (*fColorTable)[*((const uint8_t*)fPixels + y * fRowBytes + x)]; | 854 return (*fColorTable)[*((const uint8_t*)fPixels + y * fRowBytes + x)]; |
| 831 } | 855 } |
| 832 | 856 |
| 833 #endif | 857 #endif |
| OLD | NEW |