Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file | 5 * found in the LICENSE file |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef SkSpecialImage_DEFINED | 8 #ifndef SkSpecialImage_DEFINED |
| 9 #define SkSpecialImage_DEFINED | 9 #define SkSpecialImage_DEFINED |
| 10 | 10 |
| 11 #include "SkNextID.h" | |
| 11 #include "SkRefCnt.h" | 12 #include "SkRefCnt.h" |
| 12 | 13 |
| 14 // remove these two when internal_getProxy goes away | |
| 15 #include "SkImageFilter.h" | |
| 16 #include "SkDevice.h" | |
| 17 | |
| 13 class GrTexture; | 18 class GrTexture; |
| 14 class SkBitmap; | 19 class SkBitmap; |
| 15 class SkCanvas; | 20 class SkCanvas; |
| 16 class SkImage; | 21 class SkImage; |
| 17 struct SkImageInfo; | 22 struct SkImageInfo; |
| 18 class SkPaint; | 23 class SkPaint; |
| 19 class SkSpecialSurface; | 24 class SkSpecialSurface; |
| 20 | 25 |
| 26 enum { | |
| 27 kNeedNewImageUniqueID_SpecialImage = 0 | |
| 28 }; | |
| 29 | |
| 21 /** | 30 /** |
| 22 * This is a restricted form of SkImage solely intended for internal use. It | 31 * This is a restricted form of SkImage solely intended for internal use. It |
| 23 * differs from SkImage in that: | 32 * differs from SkImage in that: |
| 24 * - it can only be backed by raster or gpu (no generators) | 33 * - it can only be backed by raster or gpu (no generators) |
| 25 * - it can be backed by a GrTexture larger than its nominal bounds | 34 * - it can be backed by a GrTexture larger than its nominal bounds |
| 26 * - it can't be drawn tiled | 35 * - it can't be drawn tiled |
| 27 * - it can't be drawn with MIPMAPs | 36 * - it can't be drawn with MIPMAPs |
| 28 * It is similar to SkImage in that it abstracts how the pixels are stored/repre sented. | 37 * It is similar to SkImage in that it abstracts how the pixels are stored/repre sented. |
| 29 * | 38 * |
| 30 * Note: the contents of the backing storage outside of the subset rect are unde fined. | 39 * Note: the contents of the backing storage outside of the subset rect are unde fined. |
| 31 */ | 40 */ |
| 32 class SkSpecialImage : public SkRefCnt { | 41 class SkSpecialImage : public SkRefCnt { |
| 33 public: | 42 public: |
| 34 int width() const { return fSubset.width(); } | 43 int width() const { return fSubset.width(); } |
| 35 int height() const { return fSubset.height(); } | 44 int height() const { return fSubset.height(); } |
| 45 uint32_t uniqueID() const { return fUniqueID; } | |
| 46 virtual bool isOpaque() const { return false; } | |
| 47 virtual size_t getSize() const = 0; | |
| 36 | 48 |
| 37 /** | 49 /** |
| 38 * Draw this SpecialImage into the canvas. | 50 * Draw this SpecialImage into the canvas. |
| 39 */ | 51 */ |
| 40 void draw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) const; | 52 void draw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) const; |
| 41 | 53 |
| 42 static SkSpecialImage* NewFromImage(const SkIRect& subset, const SkImage*); | 54 static SkSpecialImage* NewFromImage(const SkIRect& subset, const SkImage*); |
| 43 static SkSpecialImage* NewFromRaster(const SkIRect& subset, const SkBitmap&) ; | 55 static SkSpecialImage* NewFromRaster(const SkIRect& subset, const SkBitmap&) ; |
| 44 static SkSpecialImage* NewFromGpu(const SkIRect& subset, GrTexture*); | 56 static SkSpecialImage* NewFromGpu(const SkIRect& subset, |
| 57 uint32_t uniqueID, | |
|
Stephen White
2016/02/17 17:00:02
Out of curiosity, are we going to need this unique
robertphillips
2016/02/17 19:10:28
I believe it will go away when there are only SkIm
| |
| 58 GrTexture*, | |
| 59 SkAlphaType at = kPremul_SkAlphaType); | |
| 45 | 60 |
| 46 /** | 61 /** |
| 47 * Create a new surface with a backend that is compatible with this image. | 62 * Create a new surface with a backend that is compatible with this image. |
| 48 */ | 63 */ |
| 49 SkSpecialSurface* newSurface(const SkImageInfo&) const; | 64 SkSpecialSurface* newSurface(const SkImageInfo&) const; |
| 50 | 65 |
| 66 // These three internal methods will go away | |
| 67 bool internal_getBM(SkBitmap* result); | |
| 68 static SkSpecialImage* internal_fromBM(const SkBitmap&); | |
| 69 SkImageFilter::Proxy* internal_getProxy(); | |
| 70 | |
| 51 protected: | 71 protected: |
| 52 SkSpecialImage(const SkIRect& subset) : fSubset(subset) { } | 72 SkSpecialImage(const SkIRect& subset, uint32_t uniqueID) |
| 73 : fSubset(subset) | |
| 74 , fUniqueID(kNeedNewImageUniqueID_SpecialImage == uniqueID ? SkNextID::I mageID() | |
| 75 : uniqueID) | |
| 76 , fProxy(nullptr) { | |
| 77 } | |
| 78 ~SkSpecialImage() override { | |
| 79 delete fProxy; | |
| 80 } | |
| 53 | 81 |
| 54 // The following 3 are for testing and shouldn't be used. | 82 // The following 3 are for testing and shouldn't be used. |
| 55 friend class TestingSpecialImageAccess; | 83 friend class TestingSpecialImageAccess; |
| 56 friend class TestingSpecialSurfaceAccess; | 84 friend class TestingSpecialSurfaceAccess; |
| 57 const SkIRect& subset() const { return fSubset; } | 85 const SkIRect& subset() const { return fSubset; } |
| 58 | 86 |
| 59 /** | 87 /** |
| 60 * If the SpecialImage is backed by cpu pixels, return the const address | 88 * If the SpecialImage is backed by cpu pixels, return the const address |
| 61 * of those pixels and, if not null, return the ImageInfo and rowBytes. | 89 * of those pixels and, if not null, return the ImageInfo and rowBytes. |
| 62 * The returned address is only valid while the image object is in scope. | 90 * The returned address is only valid while the image object is in scope. |
| 63 * | 91 * |
| 64 * The returned ImageInfo represents the backing memory. Use 'subset' | 92 * The returned ImageInfo represents the backing memory. Use 'subset' |
| 65 * to get the active portion's dimensions. | 93 * to get the active portion's dimensions. |
| 66 * | 94 * |
| 67 * On failure, return false and ignore the pixmap parameter. | 95 * On failure, return false and ignore the pixmap parameter. |
| 68 */ | 96 */ |
| 69 bool peekPixels(SkPixmap*) const; | 97 bool peekPixels(SkPixmap*) const; |
| 70 | 98 |
| 71 /** | 99 /** |
| 72 * If the SpecialImage is backed by a gpu texture, return that texture. | 100 * If the SpecialImage is backed by a gpu texture, return that texture. |
| 73 * The active portion of the texture can be retrieved via 'subset'. | 101 * The active portion of the texture can be retrieved via 'subset'. |
| 74 */ | 102 */ |
| 75 GrTexture* peekTexture() const; | 103 GrTexture* peekTexture() const; |
| 76 | 104 |
| 77 private: | 105 private: |
| 78 const SkIRect fSubset; | 106 const SkIRect fSubset; |
| 107 const uint32_t fUniqueID; | |
| 108 | |
| 109 // TODO: remove these two ASAP | |
| 110 SkImageFilter::Proxy* fProxy; | |
| 111 SkAutoTUnref<SkBaseDevice> fDevice; | |
| 79 | 112 |
| 80 typedef SkRefCnt INHERITED; | 113 typedef SkRefCnt INHERITED; |
| 81 }; | 114 }; |
| 82 | 115 |
| 83 #endif | 116 #endif |
| 84 | 117 |
| OLD | NEW |