2 * Copyright 2012 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef SkImage_DEFINED
9 #define SkImage_DEFINED
11 #include "SkImageInfo.h"
12 #include "SkImageEncoder.h"
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.
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
36 class SK_API SkImage : public SkRefCnt {
38 SK_DECLARE_INST_COUNT(SkImage)
40 typedef SkImageInfo Info;
42 static SkImage* NewRasterCopy(const Info&, const void* pixels, size_t rowBytes);
43 static SkImage* NewRasterData(const Info&, SkData* pixels, size_t rowBytes);
44 static SkImage* NewEncodedData(SkData*);
47 * GrTexture is a more logical parameter for this factory, but its
48 * interactions with scratch cache still has issues, so for now we take
49 * SkBitmap instead. This will be changed in the future. skbug.com/1449
51 static SkImage* NewTexture(const SkBitmap&);
53 int width() const { return fWidth; }
54 int height() const { return fHeight; }
55 uint32_t uniqueID() const { return fUniqueID; }
58 * Return the GrTexture that stores the image pixels. Calling getTexture
59 * does not affect the reference count of the GrTexture object.
60 * Will return NULL if the image does not use a texture.
62 GrTexture* getTexture();
64 SkShader* newShaderClamp() const;
65 SkShader* newShader(SkShader::TileMode, SkShader::TileMode) const;
67 void draw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*);
70 * Draw the image, cropped to the src rect, to the dst rect of a canvas.
71 * If src is larger than the bounds of the image, the rest of the image is
72 * filled with transparent black pixels.
74 * See SkCanvas::drawBitmapRectToRect for similar behavior.
76 void draw(SkCanvas*, const SkRect* src, const SkRect& dst, const SkPaint*);
79 * Encode the image's pixels and return the result as a new SkData, which
80 * the caller must manage (i.e. call unref() when they are done).
82 * If the image type cannot be encoded, or the requested encoder type is
83 * not supported, this will return NULL.
85 SkData* encode(SkImageEncoder::Type t = SkImageEncoder::kPNG_Type,
86 int quality = 80) const;
89 SkImage(int width, int height) :
92 fUniqueID(NextUniqueID()) {
95 SkASSERT(height >= 0);
101 const uint32_t fUniqueID;
103 static uint32_t NextUniqueID();
105 typedef SkRefCnt INHERITED;