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 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 | 264 |
265 SK_ALLOCPIXELS_RETURN_TYPE allocPixels(const SkImageInfo& info) { | 265 SK_ALLOCPIXELS_RETURN_TYPE allocPixels(const SkImageInfo& info) { |
266 return this->allocPixels(info, info.minRowBytes()); | 266 return this->allocPixels(info, info.minRowBytes()); |
267 } | 267 } |
268 | 268 |
269 bool SK_WARN_UNUSED_RESULT tryAllocN32Pixels(int width, int height, bool isO
paque = false) { | 269 bool SK_WARN_UNUSED_RESULT tryAllocN32Pixels(int width, int height, bool isO
paque = false) { |
270 SkImageInfo info = SkImageInfo::MakeN32(width, height, | 270 SkImageInfo info = SkImageInfo::MakeN32(width, height, |
271 isOpaque ? kOpaque_SkAlphaType : kPr
emul_SkAlphaType); | 271 isOpaque ? kOpaque_SkAlphaType : kPr
emul_SkAlphaType); |
272 return this->tryAllocPixels(info); | 272 return this->tryAllocPixels(info); |
273 } | 273 } |
274 | 274 |
275 SK_ALLOCPIXELS_RETURN_TYPE allocN32Pixels(int width, int height, bool isOpaq
ue = false) { | 275 SK_ALLOCPIXELS_RETURN_TYPE allocN32Pixels(int width, int height, bool isOpaq
ue = false) { |
276 SkImageInfo info = SkImageInfo::MakeN32(width, height, | 276 SkImageInfo info = SkImageInfo::MakeN32(width, height, |
277 isOpaque ? kOpaque_SkAlphaType : kPr
emul_SkAlphaType); | 277 isOpaque ? kOpaque_SkAlphaType : kPr
emul_SkAlphaType); |
278 return this->allocPixels(info); | 278 return this->allocPixels(info); |
279 } | 279 } |
280 | 280 |
281 /** | 281 /** |
282 * Install a pixelref that wraps the specified pixels and rowBytes, and | 282 * Install a pixelref that wraps the specified pixels and rowBytes, and |
283 * optional ReleaseProc and context. When the pixels are no longer | 283 * optional ReleaseProc and context. When the pixels are no longer |
284 * referenced, if releaseProc is not null, it will be called with the | 284 * referenced, if releaseProc is not null, it will be called with the |
285 * pixels and context as parameters. | 285 * pixels and context as parameters. |
286 * On failure, the bitmap will be set to empty and return false. | 286 * On failure, the bitmap will be set to empty and return false. |
287 */ | 287 */ |
288 bool installPixels(const SkImageInfo&, void* pixels, size_t rowBytes, SkColo
rTable*, | 288 bool installPixels(const SkImageInfo&, void* pixels, size_t rowBytes, SkColo
rTable*, |
289 void (*releaseProc)(void* addr, void* context), void* con
text); | 289 void (*releaseProc)(void* addr, void* context), void* con
text); |
290 | 290 |
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
791 } | 791 } |
792 } | 792 } |
793 | 793 |
794 private: | 794 private: |
795 const SkBitmap& fBitmap; | 795 const SkBitmap& fBitmap; |
796 bool fDidLock; | 796 bool fDidLock; |
797 }; | 797 }; |
798 //TODO(mtklein): uncomment when 71713004 lands and Chromium's fixed. | 798 //TODO(mtklein): uncomment when 71713004 lands and Chromium's fixed. |
799 //#define SkAutoLockPixels(...) SK_REQUIRE_LOCAL_VAR(SkAutoLockPixels) | 799 //#define SkAutoLockPixels(...) SK_REQUIRE_LOCAL_VAR(SkAutoLockPixels) |
800 | 800 |
801 /** Helper class that performs the lock/unlockColors calls on a colortable. | |
802 The destructor will call unlockColors(false) if it has a bitmap's colortable | |
803 */ | |
804 class SkAutoLockColors : SkNoncopyable { | |
805 public: | |
806 /** Initialize with no bitmap. Call lockColors(bitmap) to lock bitmap's | |
807 colortable | |
808 */ | |
809 SkAutoLockColors() : fCTable(NULL), fColors(NULL) {} | |
810 /** Initialize with bitmap, locking its colortable if present | |
811 */ | |
812 explicit SkAutoLockColors(const SkBitmap& bm) { | |
813 fCTable = bm.getColorTable(); | |
814 fColors = fCTable ? fCTable->lockColors() : NULL; | |
815 } | |
816 /** Initialize with a colortable (may be null) | |
817 */ | |
818 explicit SkAutoLockColors(SkColorTable* ctable) { | |
819 fCTable = ctable; | |
820 fColors = ctable ? ctable->lockColors() : NULL; | |
821 } | |
822 ~SkAutoLockColors() { | |
823 if (fCTable) { | |
824 fCTable->unlockColors(); | |
825 } | |
826 } | |
827 | |
828 /** Return the currently locked colors, or NULL if no bitmap's colortable | |
829 is currently locked. | |
830 */ | |
831 const SkPMColor* colors() const { return fColors; } | |
832 | |
833 /** Locks the table and returns is colors (assuming ctable is not null) and | |
834 unlocks the previous table if one was present | |
835 */ | |
836 const SkPMColor* lockColors(SkColorTable* ctable) { | |
837 if (fCTable) { | |
838 fCTable->unlockColors(); | |
839 } | |
840 fCTable = ctable; | |
841 fColors = ctable ? ctable->lockColors() : NULL; | |
842 return fColors; | |
843 } | |
844 | |
845 const SkPMColor* lockColors(const SkBitmap& bm) { | |
846 return this->lockColors(bm.getColorTable()); | |
847 } | |
848 | |
849 private: | |
850 SkColorTable* fCTable; | |
851 const SkPMColor* fColors; | |
852 }; | |
853 #define SkAutoLockColors(...) SK_REQUIRE_LOCAL_VAR(SkAutoLockColors) | |
854 | |
855 /////////////////////////////////////////////////////////////////////////////// | 801 /////////////////////////////////////////////////////////////////////////////// |
856 | 802 |
857 inline uint32_t* SkBitmap::getAddr32(int x, int y) const { | 803 inline uint32_t* SkBitmap::getAddr32(int x, int y) const { |
858 SkASSERT(fPixels); | 804 SkASSERT(fPixels); |
859 SkASSERT(4 == this->bytesPerPixel()); | 805 SkASSERT(4 == this->bytesPerPixel()); |
860 SkASSERT((unsigned)x < (unsigned)this->width() && (unsigned)y < (unsigned)th
is->height()); | 806 SkASSERT((unsigned)x < (unsigned)this->width() && (unsigned)y < (unsigned)th
is->height()); |
861 return (uint32_t*)((char*)fPixels + y * fRowBytes + (x << 2)); | 807 return (uint32_t*)((char*)fPixels + y * fRowBytes + (x << 2)); |
862 } | 808 } |
863 | 809 |
864 inline uint16_t* SkBitmap::getAddr16(int x, int y) const { | 810 inline uint16_t* SkBitmap::getAddr16(int x, int y) const { |
(...skipping 12 matching lines...) Expand all Loading... |
877 | 823 |
878 inline SkPMColor SkBitmap::getIndex8Color(int x, int y) const { | 824 inline SkPMColor SkBitmap::getIndex8Color(int x, int y) const { |
879 SkASSERT(fPixels); | 825 SkASSERT(fPixels); |
880 SkASSERT(kIndex_8_SkColorType == this->colorType()); | 826 SkASSERT(kIndex_8_SkColorType == this->colorType()); |
881 SkASSERT((unsigned)x < (unsigned)this->width() && (unsigned)y < (unsigned)th
is->height()); | 827 SkASSERT((unsigned)x < (unsigned)this->width() && (unsigned)y < (unsigned)th
is->height()); |
882 SkASSERT(fColorTable); | 828 SkASSERT(fColorTable); |
883 return (*fColorTable)[*((const uint8_t*)fPixels + y * fRowBytes + x)]; | 829 return (*fColorTable)[*((const uint8_t*)fPixels + y * fRowBytes + x)]; |
884 } | 830 } |
885 | 831 |
886 #endif | 832 #endif |
OLD | NEW |