Chromium Code Reviews| Index: src/core/SkSpecialImage.h |
| diff --git a/src/core/SkSpecialImage.h b/src/core/SkSpecialImage.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ec72fcd61eb7a402797cee6859883ed61fc01e5c |
| --- /dev/null |
| +++ b/src/core/SkSpecialImage.h |
| @@ -0,0 +1,80 @@ |
| +/* |
| + * Copyright 2016 Google Inc. |
| + * |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file |
| + */ |
| + |
| +#ifndef SkSpecialImage_DEFINED |
| +#define SkSpecialImage_DEFINED |
| + |
| +#include "SkRefCnt.h" |
| + |
| +class GrTexture; |
| +class SkBitmap; |
| +class SkCanvas; |
| +class SkImage; |
| +struct SkImageInfo; |
| +class SkPaint; |
| +class SkSpecialSurface; |
| + |
| +/** |
| + * This is a restricted form of SkImage solely intended for internal use. It |
| + * differs from SkImage in that: |
| + * - it can only be backed by raster or gpu (no generators) |
| + * - it can be backed by a GrTexture larger than its nominal bounds |
|
bsalomon
2016/01/13 21:39:17
Should we generalize to allow a irect subset rathe
robertphillips
2016/01/14 19:58:55
Done.
|
| + * - it can't be drawn tiled |
|
bsalomon
2016/01/13 21:39:17
Need a restriction on filtering too (no MIPS).
robertphillips
2016/01/14 14:43:59
Done.
|
| + * It is similar to SkImage in that it abstracts how the pixels are stored/represented. |
| + * |
| + * Note: the contents of the backing storage outside of the upper-right width x height |
| + * rect are undefined. |
| + */ |
| +class SkSpecialImage : public SkRefCnt { |
| +public: |
| + int width() const { return fWidth; } |
| + int height() const { return fHeight; } |
| + |
| + /** |
| + * Draw this SpecialImage into the canvas. |
| + */ |
| + void draw(SkCanvas*, int x, int y, const SkPaint*) const; |
| + |
| + /** |
| + * If the SpecialImage is backed by cpu pixels, return the const address |
| + * of those pixels and, if not null, return the ImageInfo and rowBytes. |
| + * The returned address is only valid while the image object is in scope. |
| + * The returned ImageInfo represents the backing memory. Use 'width' & 'height' |
| + * to get the active portion's dimensions. |
| + * |
| + * On failure, returns NULL and the info and rowBytes parameters are |
| + * ignored. |
| + */ |
| + const void* peekPixels(SkImageInfo* info, size_t* rowBytes) const; |
|
reed1
2016/01/14 13:52:55
nit:
bool peekPixels(SkPixmap*) const;
robertphillips
2016/01/14 19:58:55
Done.
|
| + |
| + /** |
| + * If the SpecialImage is backed by a gpu texture, return that texture. |
| + * The active portion of the texture can be retrieved via 'width' & 'height'. |
| + */ |
| + GrTexture* peekTexture() const; |
| + |
| + static SkSpecialImage* New(int width, int height, const SkImage*); |
| + static SkSpecialImage* New(int width, int height, const SkBitmap&); |
|
reed1
2016/01/14 13:52:55
Does this ever copy the pixels from the bitmap?
robertphillips
2016/01/14 19:58:55
No.
|
| + static SkSpecialImage* New(int width, int height, GrTexture*); |
| + |
| + /** |
| + * Create a new surface with a backend that is compatible with this image. |
| + */ |
| + SkSpecialSurface* newSurface(const SkImageInfo&) const; |
| + |
| +protected: |
| + SkSpecialImage(int width, int height) : fWidth(width), fHeight(height) { } |
| + |
| +private: |
| + const int fWidth; |
| + const int fHeight; |
| + |
| + typedef SkRefCnt INHERITED; |
| +}; |
| + |
| +#endif |
| + |