| 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 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 //#define SK_SUPPORT_LEGACY_BITMAPFLATTEN |
| 28 |
| 27 /** \class SkBitmap | 29 /** \class SkBitmap |
| 28 | 30 |
| 29 The SkBitmap class specifies a raster bitmap. A bitmap has an integer width | 31 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. | 32 and height, and a format (config), and a pointer to the actual pixels. |
| 31 Bitmaps can be drawn into a SkCanvas, but they are also used to specify the | 33 Bitmaps can be drawn into a SkCanvas, but they are also used to specify the |
| 32 target of a SkCanvas' drawing operations. | 34 target of a SkCanvas' drawing operations. |
| 33 A const SkBitmap exposes getAddr(), which lets a caller write its pixels; | 35 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 | 36 the constness is considered to apply to the bitmap's configuration, not |
| 35 its contents. | 37 its contents. |
| 36 */ | 38 */ |
| (...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 @param allocator Allocator used to allocate the pixelref for the dst | 686 @param allocator Allocator used to allocate the pixelref for the dst |
| 685 bitmap. If this is null, the standard HeapAllocator | 687 bitmap. If this is null, the standard HeapAllocator |
| 686 will be used. | 688 will be used. |
| 687 @param offset If not null, it is set to top-left coordinate to position | 689 @param offset If not null, it is set to top-left coordinate to position |
| 688 the returned bitmap so that it visually lines up with the | 690 the returned bitmap so that it visually lines up with the |
| 689 original | 691 original |
| 690 */ | 692 */ |
| 691 bool extractAlpha(SkBitmap* dst, const SkPaint* paint, Allocator* allocator, | 693 bool extractAlpha(SkBitmap* dst, const SkPaint* paint, Allocator* allocator, |
| 692 SkIPoint* offset) const; | 694 SkIPoint* offset) const; |
| 693 | 695 |
| 696 #ifdef SK_SUPPORT_LEGACY_BITMAPFLATTEN |
| 694 /** The following two functions provide the means to both flatten and | 697 /** The following two functions provide the means to both flatten and |
| 695 unflatten the bitmap AND its pixels into the provided buffer. | 698 unflatten the bitmap AND its pixels into the provided buffer. |
| 696 It is recommended that you do not call these functions directly, | 699 It is recommended that you do not call these functions directly, |
| 697 but instead call the write/readBitmap functions on the respective | 700 but instead call the write/readBitmap functions on the respective |
| 698 buffers as they can optimize the recording process and avoid recording | 701 buffers as they can optimize the recording process and avoid recording |
| 699 duplicate bitmaps and pixelRefs. | 702 duplicate bitmaps and pixelRefs. |
| 700 */ | 703 */ |
| 701 void flatten(SkWriteBuffer&) const; | 704 void flatten(SkWriteBuffer&) const; |
| 705 #else |
| 706 private: |
| 707 #endif |
| 702 void unflatten(SkReadBuffer&); | 708 void unflatten(SkReadBuffer&); |
| 709 public: |
| 703 | 710 |
| 704 SkDEBUGCODE(void validate() const;) | 711 SkDEBUGCODE(void validate() const;) |
| 705 | 712 |
| 706 class Allocator : public SkRefCnt { | 713 class Allocator : public SkRefCnt { |
| 707 public: | 714 public: |
| 708 SK_DECLARE_INST_COUNT(Allocator) | 715 SK_DECLARE_INST_COUNT(Allocator) |
| 709 | 716 |
| 710 /** Allocate the pixel memory for the bitmap, given its dimensions and | 717 /** Allocate the pixel memory for the bitmap, given its dimensions and |
| 711 config. Return true on success, where success means either setPixels | 718 config. Return true on success, where success means either setPixels |
| 712 or setPixelRef was called. The pixels need not be locked when this | 719 or setPixelRef was called. The pixels need not be locked when this |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 size_t rowBytes); | 796 size_t rowBytes); |
| 790 static size_t ComputeSafeSize(Config config, | 797 static size_t ComputeSafeSize(Config config, |
| 791 uint32_t width, | 798 uint32_t width, |
| 792 uint32_t height, | 799 uint32_t height, |
| 793 size_t rowBytes); | 800 size_t rowBytes); |
| 794 | 801 |
| 795 /* Unreference any pixelrefs or colortables | 802 /* Unreference any pixelrefs or colortables |
| 796 */ | 803 */ |
| 797 void freePixels(); | 804 void freePixels(); |
| 798 void updatePixelsFromRef() const; | 805 void updatePixelsFromRef() const; |
| 806 |
| 807 static void WriteRawPixels(SkWriteBuffer*, const SkBitmap&); |
| 808 static SkPixelRef* ReadRawPixels(SkReadBuffer*); |
| 799 | 809 |
| 810 friend class SkBitmapSource; // unflatten |
| 811 friend class SkReadBuffer; // unflatten, rawpixels |
| 812 friend class SkWriteBuffer; // rawpixels |
| 800 friend struct SkBitmapProcState; | 813 friend struct SkBitmapProcState; |
| 801 }; | 814 }; |
| 802 | 815 |
| 803 class SkAutoLockPixels : SkNoncopyable { | 816 class SkAutoLockPixels : SkNoncopyable { |
| 804 public: | 817 public: |
| 805 SkAutoLockPixels(const SkBitmap& bm, bool doLock = true) : fBitmap(bm) { | 818 SkAutoLockPixels(const SkBitmap& bm, bool doLock = true) : fBitmap(bm) { |
| 806 fDidLock = doLock; | 819 fDidLock = doLock; |
| 807 if (doLock) { | 820 if (doLock) { |
| 808 bm.lockPixels(); | 821 bm.lockPixels(); |
| 809 } | 822 } |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 907 } | 920 } |
| 908 | 921 |
| 909 /////////////////////////////////////////////////////////////////////////////// | 922 /////////////////////////////////////////////////////////////////////////////// |
| 910 // | 923 // |
| 911 // Helpers until we can fully deprecate SkBitmap::Config | 924 // Helpers until we can fully deprecate SkBitmap::Config |
| 912 // | 925 // |
| 913 extern SkBitmap::Config SkColorTypeToBitmapConfig(SkColorType); | 926 extern SkBitmap::Config SkColorTypeToBitmapConfig(SkColorType); |
| 914 extern SkColorType SkBitmapConfigToColorType(SkBitmap::Config); | 927 extern SkColorType SkBitmapConfigToColorType(SkBitmap::Config); |
| 915 | 928 |
| 916 #endif | 929 #endif |
| OLD | NEW |