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