2012-07-25 14:42:15 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkImage_DEFINED
|
|
|
|
#define SkImage_DEFINED
|
|
|
|
|
2012-07-27 18:02:50 +00:00
|
|
|
#include "SkRefCnt.h"
|
|
|
|
#include "SkScalar.h"
|
|
|
|
|
|
|
|
class SkData;
|
|
|
|
class SkCanvas;
|
|
|
|
class SkPaint;
|
|
|
|
class SkShader;
|
2012-07-31 15:45:27 +00:00
|
|
|
class GrContext;
|
2012-10-31 14:58:16 +00:00
|
|
|
class GrTexture;
|
2012-07-27 18:02:50 +00:00
|
|
|
|
|
|
|
// need for TileMode
|
|
|
|
#include "SkShader.h"
|
2012-07-25 14:42:15 +00:00
|
|
|
|
|
|
|
////// EXPERIMENTAL
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SkImage is an abstraction for drawing a rectagle of pixels, though the
|
|
|
|
* particular type of image could be actually storing its data on the GPU, or
|
|
|
|
* as drawing commands (picture or PDF or otherwise), ready to be played back
|
|
|
|
* into another canvas.
|
|
|
|
*
|
|
|
|
* The content of SkImage is always immutable, though the actual storage may
|
|
|
|
* change, if for example that image can be re-created via encoded data or
|
|
|
|
* other means.
|
|
|
|
*/
|
|
|
|
class SkImage : public SkRefCnt {
|
|
|
|
public:
|
2012-08-28 12:43:54 +00:00
|
|
|
SK_DECLARE_INST_COUNT(SkImage)
|
2012-08-16 14:58:06 +00:00
|
|
|
|
2012-07-25 14:42:15 +00:00
|
|
|
enum ColorType {
|
2012-07-27 18:02:50 +00:00
|
|
|
kAlpha_8_ColorType,
|
2012-07-25 14:42:15 +00:00
|
|
|
kRGB_565_ColorType,
|
|
|
|
kRGBA_8888_ColorType,
|
|
|
|
kBGRA_8888_ColorType,
|
|
|
|
kPMColor_ColorType,
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2012-07-27 18:02:50 +00:00
|
|
|
kLastEnum_ColorType = kPMColor_ColorType
|
2012-07-25 14:42:15 +00:00
|
|
|
};
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2012-07-25 14:42:15 +00:00
|
|
|
enum AlphaType {
|
|
|
|
kIgnore_AlphaType,
|
|
|
|
kOpaque_AlphaType,
|
|
|
|
kPremul_AlphaType,
|
2012-07-27 18:02:50 +00:00
|
|
|
kUnpremul_AlphaType,
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2012-07-27 18:02:50 +00:00
|
|
|
kLastEnum_AlphaType = kUnpremul_AlphaType
|
2012-07-25 14:42:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Info {
|
|
|
|
int fWidth;
|
|
|
|
int fHeight;
|
|
|
|
ColorType fColorType;
|
|
|
|
AlphaType fAlphaType;
|
|
|
|
};
|
|
|
|
|
2012-11-15 02:37:45 +00:00
|
|
|
static SkImage* NewRasterCopy(const Info&, const void* pixels, size_t rowBytes);
|
|
|
|
static SkImage* NewRasterData(const Info&, SkData* pixels, size_t rowBytes);
|
2012-07-25 14:42:15 +00:00
|
|
|
static SkImage* NewEncodedData(SkData*);
|
2012-10-31 14:48:39 +00:00
|
|
|
static SkImage* NewTexture(GrTexture*);
|
2012-07-25 14:42:15 +00:00
|
|
|
|
2012-07-27 18:02:50 +00:00
|
|
|
int width() const { return fWidth; }
|
|
|
|
int height() const { return fHeight; }
|
|
|
|
uint32_t uniqueID() const { return fUniqueID; }
|
|
|
|
|
2012-07-25 14:42:15 +00:00
|
|
|
SkShader* newShaderClamp() const;
|
|
|
|
SkShader* newShader(SkShader::TileMode, SkShader::TileMode) const;
|
2012-07-27 18:02:50 +00:00
|
|
|
|
|
|
|
void draw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SkImage(int width, int height) :
|
|
|
|
fWidth(width),
|
|
|
|
fHeight(height),
|
|
|
|
fUniqueID(NextUniqueID()) {
|
|
|
|
|
|
|
|
SkASSERT(width >= 0);
|
|
|
|
SkASSERT(height >= 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const int fWidth;
|
|
|
|
const int fHeight;
|
|
|
|
const uint32_t fUniqueID;
|
|
|
|
|
|
|
|
static uint32_t NextUniqueID();
|
2012-08-30 14:38:00 +00:00
|
|
|
|
2012-08-28 12:48:35 +00:00
|
|
|
typedef SkRefCnt INHERITED;
|
2012-07-25 14:42:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|