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 | |
29 /** \class SkBitmap | 27 /** \class SkBitmap |
30 | 28 |
31 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 |
32 and height, and a format (config), and a pointer to the actual pixels. | 30 and height, and a format (config), and a pointer to the actual pixels. |
33 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 |
34 target of a SkCanvas' drawing operations. | 32 target of a SkCanvas' drawing operations. |
35 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; |
36 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 |
37 its contents. | 35 its contents. |
38 */ | 36 */ |
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 @param allocator Allocator used to allocate the pixelref for the dst | 679 @param allocator Allocator used to allocate the pixelref for the dst |
682 bitmap. If this is null, the standard HeapAllocator | 680 bitmap. If this is null, the standard HeapAllocator |
683 will be used. | 681 will be used. |
684 @param offset If not null, it is set to top-left coordinate to position | 682 @param offset If not null, it is set to top-left coordinate to position |
685 the returned bitmap so that it visually lines up with the | 683 the returned bitmap so that it visually lines up with the |
686 original | 684 original |
687 */ | 685 */ |
688 bool extractAlpha(SkBitmap* dst, const SkPaint* paint, Allocator* allocator, | 686 bool extractAlpha(SkBitmap* dst, const SkPaint* paint, Allocator* allocator, |
689 SkIPoint* offset) const; | 687 SkIPoint* offset) const; |
690 | 688 |
691 #ifdef SK_SUPPORT_LEGACY_BITMAPFLATTEN | |
692 /** The following two functions provide the means to both flatten and | |
693 unflatten the bitmap AND its pixels into the provided buffer. | |
694 It is recommended that you do not call these functions directly, | |
695 but instead call the write/readBitmap functions on the respective | |
696 buffers as they can optimize the recording process and avoid recording | |
697 duplicate bitmaps and pixelRefs. | |
698 */ | |
699 void flatten(SkWriteBuffer&) const; | |
700 #else | |
701 private: | |
702 #endif | |
703 void unflatten(SkReadBuffer&); | |
704 public: | |
705 | |
706 SkDEBUGCODE(void validate() const;) | 689 SkDEBUGCODE(void validate() const;) |
707 | 690 |
708 class Allocator : public SkRefCnt { | 691 class Allocator : public SkRefCnt { |
709 public: | 692 public: |
710 SK_DECLARE_INST_COUNT(Allocator) | 693 SK_DECLARE_INST_COUNT(Allocator) |
711 | 694 |
712 /** Allocate the pixel memory for the bitmap, given its dimensions and | 695 /** Allocate the pixel memory for the bitmap, given its dimensions and |
713 config. Return true on success, where success means either setPixels | 696 config. Return true on success, where success means either setPixels |
714 or setPixelRef was called. The pixels need not be locked when this | 697 or setPixelRef was called. The pixels need not be locked when this |
715 returns. If the config requires a colortable, it also must be | 698 returns. If the config requires a colortable, it also must be |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 static size_t ComputeSafeSize(Config config, | 775 static size_t ComputeSafeSize(Config config, |
793 uint32_t width, | 776 uint32_t width, |
794 uint32_t height, | 777 uint32_t height, |
795 size_t rowBytes); | 778 size_t rowBytes); |
796 | 779 |
797 /* Unreference any pixelrefs or colortables | 780 /* Unreference any pixelrefs or colortables |
798 */ | 781 */ |
799 void freePixels(); | 782 void freePixels(); |
800 void updatePixelsFromRef() const; | 783 void updatePixelsFromRef() const; |
801 | 784 |
| 785 void legacyUnflatten(SkReadBuffer&); |
| 786 |
802 static void WriteRawPixels(SkWriteBuffer*, const SkBitmap&); | 787 static void WriteRawPixels(SkWriteBuffer*, const SkBitmap&); |
803 static bool ReadRawPixels(SkReadBuffer*, SkBitmap*); | 788 static bool ReadRawPixels(SkReadBuffer*, SkBitmap*); |
804 | 789 |
805 friend class SkBitmapSource; // unflatten | 790 friend class SkBitmapSource; // unflatten |
806 friend class SkReadBuffer; // unflatten, rawpixels | 791 friend class SkReadBuffer; // unflatten, rawpixels |
807 friend class SkWriteBuffer; // rawpixels | 792 friend class SkWriteBuffer; // rawpixels |
808 friend struct SkBitmapProcState; | 793 friend struct SkBitmapProcState; |
809 }; | 794 }; |
810 | 795 |
811 class SkAutoLockPixels : SkNoncopyable { | 796 class SkAutoLockPixels : SkNoncopyable { |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
915 } | 900 } |
916 | 901 |
917 /////////////////////////////////////////////////////////////////////////////// | 902 /////////////////////////////////////////////////////////////////////////////// |
918 // | 903 // |
919 // Helpers until we can fully deprecate SkBitmap::Config | 904 // Helpers until we can fully deprecate SkBitmap::Config |
920 // | 905 // |
921 extern SkBitmap::Config SkColorTypeToBitmapConfig(SkColorType); | 906 extern SkBitmap::Config SkColorTypeToBitmapConfig(SkColorType); |
922 extern SkColorType SkBitmapConfigToColorType(SkBitmap::Config); | 907 extern SkColorType SkBitmapConfigToColorType(SkBitmap::Config); |
923 | 908 |
924 #endif | 909 #endif |
OLD | NEW |