reed@google.com | bba65d9 | 2012-07-25 14:42:15 +0000 | [diff] [blame] | 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 | |
reed@google.com | f6627b7 | 2012-07-27 18:02:50 +0000 | [diff] [blame] | 11 | #include "SkRefCnt.h" |
| 12 | #include "SkScalar.h" |
| 13 | |
| 14 | class SkData; |
| 15 | class SkCanvas; |
| 16 | class SkPaint; |
| 17 | class SkShader; |
reed@google.com | 5d4ba88 | 2012-07-31 15:45:27 +0000 | [diff] [blame] | 18 | class GrContext; |
robertphillips@google.com | 72ba668 | 2012-10-31 14:58:16 +0000 | [diff] [blame] | 19 | class GrTexture; |
reed@google.com | f6627b7 | 2012-07-27 18:02:50 +0000 | [diff] [blame] | 20 | |
| 21 | // need for TileMode |
| 22 | #include "SkShader.h" |
reed@google.com | bba65d9 | 2012-07-25 14:42:15 +0000 | [diff] [blame] | 23 | |
| 24 | ////// EXPERIMENTAL |
| 25 | |
reed@google.com | bba65d9 | 2012-07-25 14:42:15 +0000 | [diff] [blame] | 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: |
reed@google.com | fd875e8 | 2012-08-28 12:43:54 +0000 | [diff] [blame] | 38 | SK_DECLARE_INST_COUNT(SkImage) |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 39 | |
reed@google.com | bba65d9 | 2012-07-25 14:42:15 +0000 | [diff] [blame] | 40 | enum ColorType { |
reed@google.com | f6627b7 | 2012-07-27 18:02:50 +0000 | [diff] [blame] | 41 | kAlpha_8_ColorType, |
reed@google.com | bba65d9 | 2012-07-25 14:42:15 +0000 | [diff] [blame] | 42 | kRGB_565_ColorType, |
| 43 | kRGBA_8888_ColorType, |
| 44 | kBGRA_8888_ColorType, |
| 45 | kPMColor_ColorType, |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 46 | |
reed@google.com | f6627b7 | 2012-07-27 18:02:50 +0000 | [diff] [blame] | 47 | kLastEnum_ColorType = kPMColor_ColorType |
reed@google.com | bba65d9 | 2012-07-25 14:42:15 +0000 | [diff] [blame] | 48 | }; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 49 | |
reed@google.com | bba65d9 | 2012-07-25 14:42:15 +0000 | [diff] [blame] | 50 | enum AlphaType { |
| 51 | kIgnore_AlphaType, |
| 52 | kOpaque_AlphaType, |
| 53 | kPremul_AlphaType, |
reed@google.com | f6627b7 | 2012-07-27 18:02:50 +0000 | [diff] [blame] | 54 | kUnpremul_AlphaType, |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 55 | |
reed@google.com | f6627b7 | 2012-07-27 18:02:50 +0000 | [diff] [blame] | 56 | kLastEnum_AlphaType = kUnpremul_AlphaType |
reed@google.com | bba65d9 | 2012-07-25 14:42:15 +0000 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | struct Info { |
| 60 | int fWidth; |
| 61 | int fHeight; |
| 62 | ColorType fColorType; |
| 63 | AlphaType fAlphaType; |
reed@google.com | bba65d9 | 2012-07-25 14:42:15 +0000 | [diff] [blame] | 64 | }; |
| 65 | |
mike@reedtribe.org | b947625 | 2012-11-15 02:37:45 +0000 | [diff] [blame^] | 66 | static SkImage* NewRasterCopy(const Info&, const void* pixels, size_t rowBytes); |
| 67 | static SkImage* NewRasterData(const Info&, SkData* pixels, size_t rowBytes); |
reed@google.com | bba65d9 | 2012-07-25 14:42:15 +0000 | [diff] [blame] | 68 | static SkImage* NewEncodedData(SkData*); |
robertphillips@google.com | 97b6b07 | 2012-10-31 14:48:39 +0000 | [diff] [blame] | 69 | static SkImage* NewTexture(GrTexture*); |
reed@google.com | bba65d9 | 2012-07-25 14:42:15 +0000 | [diff] [blame] | 70 | |
reed@google.com | f6627b7 | 2012-07-27 18:02:50 +0000 | [diff] [blame] | 71 | int width() const { return fWidth; } |
| 72 | int height() const { return fHeight; } |
| 73 | uint32_t uniqueID() const { return fUniqueID; } |
| 74 | |
reed@google.com | bba65d9 | 2012-07-25 14:42:15 +0000 | [diff] [blame] | 75 | SkShader* newShaderClamp() const; |
| 76 | SkShader* newShader(SkShader::TileMode, SkShader::TileMode) const; |
reed@google.com | f6627b7 | 2012-07-27 18:02:50 +0000 | [diff] [blame] | 77 | |
| 78 | void draw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*); |
| 79 | |
| 80 | protected: |
| 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(); |
skia.committer@gmail.com | a27096b | 2012-08-30 14:38:00 +0000 | [diff] [blame] | 96 | |
reed@google.com | 7edfb49 | 2012-08-28 12:48:35 +0000 | [diff] [blame] | 97 | typedef SkRefCnt INHERITED; |
reed@google.com | bba65d9 | 2012-07-25 14:42:15 +0000 | [diff] [blame] | 98 | }; |
| 99 | |
reed@google.com | bba65d9 | 2012-07-25 14:42:15 +0000 | [diff] [blame] | 100 | #endif |