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