00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef SkShader_DEFINED
00018 #define SkShader_DEFINED
00019
00020 #include "SkBitmap.h"
00021 #include "SkFlattenable.h"
00022 #include "SkMask.h"
00023 #include "SkMatrix.h"
00024 #include "SkPaint.h"
00025
00026 class SkPath;
00027
00035 class SkShader : public SkFlattenable {
00036 public:
00037 SkShader();
00038 virtual ~SkShader();
00039
00044 bool getLocalMatrix(SkMatrix* localM) const;
00048 void setLocalMatrix(const SkMatrix& localM);
00051 void resetLocalMatrix();
00052
00053 enum TileMode {
00054 kClamp_TileMode,
00055 kRepeat_TileMode,
00056 kMirror_TileMode,
00057
00058 kTileModeCount
00059 };
00060
00061
00062
00063 enum Flags {
00065 kOpaqueAlpha_Flag = 0x01,
00066
00068 kHasSpan16_Flag = 0x02,
00069
00075 kIntrinsicly16_Flag = 0x04,
00076
00082 kConstInY32_Flag = 0x08,
00083
00089 kConstInY16_Flag = 0x10
00090 };
00091
00098 virtual uint32_t getFlags() { return 0; }
00099
00103 virtual uint8_t getSpan16Alpha() const { return fPaintAlpha; }
00104
00110 virtual bool setContext(const SkBitmap& device, const SkPaint& paint,
00111 const SkMatrix& matrix);
00112
00117 virtual void shadeSpan(int x, int y, SkPMColor[], int count) = 0;
00121 virtual void shadeSpan16(int x, int y, uint16_t[], int count);
00126 virtual void shadeSpanAlpha(int x, int y, uint8_t alpha[], int count);
00127
00131 bool canCallShadeSpan16() {
00132 return SkShader::CanCallShadeSpan16(this->getFlags());
00133 }
00134
00137 static bool CanCallShadeSpan16(uint32_t flags) {
00138 return (flags & kHasSpan16_Flag) != 0;
00139 }
00140
00145 virtual void beginSession();
00146 virtual void endSession();
00147
00152 virtual bool asABitmap(SkBitmap* outTexture, SkMatrix* outMatrix,
00153 TileMode xy[2]);
00154
00156
00157
00164 static SkShader* CreateBitmapShader(const SkBitmap& src,
00165 TileMode tmx, TileMode tmy);
00166
00167 virtual void flatten(SkFlattenableWriteBuffer& );
00168 protected:
00169 enum MatrixClass {
00170 kLinear_MatrixClass,
00171 kFixedStepInX_MatrixClass,
00172 kPerspective_MatrixClass
00173 };
00174 static MatrixClass ComputeMatrixClass(const SkMatrix&);
00175
00176
00177 uint8_t getPaintAlpha() const { return fPaintAlpha; }
00178 SkBitmap::Config getDeviceConfig() const { return (SkBitmap::Config)fDeviceConfig; }
00179 const SkMatrix& getTotalInverse() const { return fTotalInverse; }
00180 MatrixClass getInverseClass() const { return (MatrixClass)fTotalInverseClass; }
00181
00182 SkShader(SkFlattenableReadBuffer& );
00183 private:
00184 SkMatrix* fLocalMatrix;
00185 SkMatrix fTotalInverse;
00186 uint8_t fPaintAlpha;
00187 uint8_t fDeviceConfig;
00188 uint8_t fTotalInverseClass;
00189 SkDEBUGCODE(SkBool8 fInSession;)
00190
00191 static SkShader* CreateBitmapShader(const SkBitmap& src,
00192 TileMode, TileMode,
00193 void* storage, size_t storageSize);
00194 friend class SkAutoBitmapShaderInstall;
00195 typedef SkFlattenable INHERITED;
00196 };
00197
00198 #endif
00199