blob: b8ebc3aca57f65bdd76e730f22ac1cac4bf21290 [file] [log] [blame]
reed@google.combba65d92012-07-25 14:42:15 +00001/*
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.comf6627b72012-07-27 18:02:50 +000011#include "SkRefCnt.h"
12#include "SkScalar.h"
13
14class SkData;
15class SkCanvas;
16class SkPaint;
17class SkShader;
reed@google.com5d4ba882012-07-31 15:45:27 +000018class GrContext;
robertphillips@google.com72ba6682012-10-31 14:58:16 +000019class GrTexture;
reed@google.comf6627b72012-07-27 18:02:50 +000020
21// need for TileMode
22#include "SkShader.h"
reed@google.combba65d92012-07-25 14:42:15 +000023
24////// EXPERIMENTAL
25
reed@google.combba65d92012-07-25 14:42:15 +000026/**
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 */
36class SkImage : public SkRefCnt {
37public:
reed@google.comfd875e82012-08-28 12:43:54 +000038 SK_DECLARE_INST_COUNT(SkImage)
robertphillips@google.coma22e2112012-08-16 14:58:06 +000039
reed@google.combba65d92012-07-25 14:42:15 +000040 enum ColorType {
reed@google.comf6627b72012-07-27 18:02:50 +000041 kAlpha_8_ColorType,
reed@google.combba65d92012-07-25 14:42:15 +000042 kRGB_565_ColorType,
43 kRGBA_8888_ColorType,
44 kBGRA_8888_ColorType,
45 kPMColor_ColorType,
rmistry@google.comfbfcd562012-08-23 18:09:54 +000046
reed@google.comf6627b72012-07-27 18:02:50 +000047 kLastEnum_ColorType = kPMColor_ColorType
reed@google.combba65d92012-07-25 14:42:15 +000048 };
rmistry@google.comfbfcd562012-08-23 18:09:54 +000049
reed@google.combba65d92012-07-25 14:42:15 +000050 enum AlphaType {
51 kIgnore_AlphaType,
52 kOpaque_AlphaType,
53 kPremul_AlphaType,
reed@google.comf6627b72012-07-27 18:02:50 +000054 kUnpremul_AlphaType,
rmistry@google.comfbfcd562012-08-23 18:09:54 +000055
reed@google.comf6627b72012-07-27 18:02:50 +000056 kLastEnum_AlphaType = kUnpremul_AlphaType
reed@google.combba65d92012-07-25 14:42:15 +000057 };
58
59 struct Info {
60 int fWidth;
61 int fHeight;
62 ColorType fColorType;
63 AlphaType fAlphaType;
reed@google.combba65d92012-07-25 14:42:15 +000064 };
65
mike@reedtribe.orgb9476252012-11-15 02:37:45 +000066 static SkImage* NewRasterCopy(const Info&, const void* pixels, size_t rowBytes);
67 static SkImage* NewRasterData(const Info&, SkData* pixels, size_t rowBytes);
reed@google.combba65d92012-07-25 14:42:15 +000068 static SkImage* NewEncodedData(SkData*);
robertphillips@google.com97b6b072012-10-31 14:48:39 +000069 static SkImage* NewTexture(GrTexture*);
reed@google.combba65d92012-07-25 14:42:15 +000070
reed@google.comf6627b72012-07-27 18:02:50 +000071 int width() const { return fWidth; }
72 int height() const { return fHeight; }
73 uint32_t uniqueID() const { return fUniqueID; }
74
reed@google.combba65d92012-07-25 14:42:15 +000075 SkShader* newShaderClamp() const;
76 SkShader* newShader(SkShader::TileMode, SkShader::TileMode) const;
reed@google.comf6627b72012-07-27 18:02:50 +000077
78 void draw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*);
79
80protected:
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
90private:
91 const int fWidth;
92 const int fHeight;
93 const uint32_t fUniqueID;
94
95 static uint32_t NextUniqueID();
skia.committer@gmail.coma27096b2012-08-30 14:38:00 +000096
reed@google.com7edfb492012-08-28 12:48:35 +000097 typedef SkRefCnt INHERITED;
reed@google.combba65d92012-07-25 14:42:15 +000098};
99
reed@google.combba65d92012-07-25 14:42:15 +0000100#endif