00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef SkMask_DEFINED
00018 #define SkMask_DEFINED
00019
00020 #include "SkRect.h"
00021
00026 struct SkMask {
00027 enum Format {
00028 kBW_Format,
00029 kA8_Format,
00030 k3D_Format,
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 kHorizontalLCD_Format,
00048 kVerticalLCD_Format,
00049 };
00050
00051 enum {
00052 kCountMaskFormats = kVerticalLCD_Format + 1
00053 };
00054
00055 uint8_t* fImage;
00056 SkIRect fBounds;
00057 uint32_t fRowBytes;
00058 Format fFormat;
00059
00062 bool isEmpty() const { return fBounds.isEmpty(); }
00063
00068 size_t computeImageSize() const;
00069
00074 size_t computeTotalImageSize() const;
00075
00080 uint8_t* getAddr1(int x, int y) const {
00081 SkASSERT(fFormat == kBW_Format);
00082 SkASSERT(fBounds.contains(x, y));
00083 SkASSERT(fImage != NULL);
00084 return fImage + ((x - fBounds.fLeft) >> 3) + (y - fBounds.fTop) * fRowBytes;
00085 }
00086
00091 uint8_t* getAddr(int x, int y) const {
00092 SkASSERT(fFormat != kBW_Format);
00093 SkASSERT(fBounds.contains(x, y));
00094 SkASSERT(fImage != NULL);
00095 return fImage + x - fBounds.fLeft + (y - fBounds.fTop) * fRowBytes;
00096 }
00097
00101 const uint32_t* getAddrLCD(int x, int y) const {
00102 SkASSERT(fFormat == kHorizontalLCD_Format || fFormat == kVerticalLCD_Format);
00103 SkASSERT(fImage != NULL);
00104
00105 return reinterpret_cast<const uint32_t*>(fImage + SkAlign4(fRowBytes * fBounds.height())) +
00106 x - fBounds.fLeft + (y - fBounds.fTop) * rowWordsLCD();
00107 }
00108
00112 unsigned rowWordsLCD() const {
00113 SkASSERT(fFormat == kHorizontalLCD_Format || fFormat == kVerticalLCD_Format);
00114 if (fFormat == kHorizontalLCD_Format)
00115 return fBounds.width() + 2;
00116 else
00117 return fBounds.width();
00118 }
00119
00120 static uint8_t* AllocImage(size_t bytes);
00121 static void FreeImage(void* image);
00122
00123 enum CreateMode {
00124 kJustComputeBounds_CreateMode,
00125 kJustRenderImage_CreateMode,
00126 kComputeBoundsAndRenderImage_CreateMode
00127 };
00128
00129 static bool FormatIsLCD(Format fm) {
00130 return kHorizontalLCD_Format == fm || kVerticalLCD_Format == fm;
00131 }
00132 };
00133
00134 #endif
00135