1 /* 2 * Copyright 2012 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef SkImage_DEFINED 9 #define SkImage_DEFINED 10 11 #include "SkRefCnt.h" 12 #include "SkScalar.h" 13 14 class SkData; 15 class SkCanvas; 16 class SkPaint; 17 class SkShader; 18 class GrContext; 19 class GrTexture; 20 21 // need for TileMode 22 #include "SkShader.h" 23 24 ////// EXPERIMENTAL 25 26 /** 27 * SkImage is an abstraction for drawing a rectagle of pixels, though the 28 * particular type of image could be actually storing its data on the GPU, or 29 * as drawing commands (picture or PDF or otherwise), ready to be played back 30 * into another canvas. 31 * 32 * The content of SkImage is always immutable, though the actual storage may 33 * change, if for example that image can be re-created via encoded data or 34 * other means. 35 */ 36 class SkImage : public SkRefCnt { 37 public: 38 SK_DECLARE_INST_COUNT(SkImage) 39 40 enum ColorType { 41 kAlpha_8_ColorType, 42 kRGB_565_ColorType, 43 kRGBA_8888_ColorType, 44 kBGRA_8888_ColorType, 45 kPMColor_ColorType, 46 47 kLastEnum_ColorType = kPMColor_ColorType 48 }; 49 50 enum AlphaType { 51 kIgnore_AlphaType, 52 kOpaque_AlphaType, 53 kPremul_AlphaType, 54 kUnpremul_AlphaType, 55 56 kLastEnum_AlphaType = kUnpremul_AlphaType 57 }; 58 59 struct Info { 60 int fWidth; 61 int fHeight; 62 ColorType fColorType; 63 AlphaType fAlphaType; 64 }; 65 66 static SkImage* NewRasterCopy(const Info&, const void* pixels, size_t rowBytes); 67 static SkImage* NewRasterData(const Info&, SkData* pixels, size_t rowBytes); 68 static SkImage* NewEncodedData(SkData*); 69 static SkImage* NewTexture(GrTexture*); 70 width()71 int width() const { return fWidth; } height()72 int height() const { return fHeight; } uniqueID()73 uint32_t uniqueID() const { return fUniqueID; } 74 75 SkShader* newShaderClamp() const; 76 SkShader* newShader(SkShader::TileMode, SkShader::TileMode) const; 77 78 void draw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*); 79 80 protected: SkImage(int width,int height)81 SkImage(int width, int height) : 82 fWidth(width), 83 fHeight(height), 84 fUniqueID(NextUniqueID()) { 85 86 SkASSERT(width >= 0); 87 SkASSERT(height >= 0); 88 } 89 90 private: 91 const int fWidth; 92 const int fHeight; 93 const uint32_t fUniqueID; 94 95 static uint32_t NextUniqueID(); 96 97 typedef SkRefCnt INHERITED; 98 }; 99 100 #endif 101