Hal Canary | 7cbf5e3 | 2017-07-12 13:10:23 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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 | #ifndef SkKeyedImage_DEFINED |
| 8 | #define SkKeyedImage_DEFINED |
| 9 | |
| 10 | #include "SkBitmap.h" |
| 11 | #include "SkBitmapKey.h" |
| 12 | #include "SkImage.h" |
| 13 | |
| 14 | /** |
| 15 | This class has all the advantages of SkBitmaps and SkImages. |
| 16 | |
| 17 | The SkImage holds on to encoded data. The SkBitmapKey properly de-dups subsets. |
| 18 | */ |
| 19 | class SkKeyedImage { |
| 20 | public: |
| 21 | SkKeyedImage() {} |
| 22 | SkKeyedImage(sk_sp<SkImage>); |
| 23 | SkKeyedImage(const SkBitmap&); |
| 24 | SkKeyedImage(SkKeyedImage&&) = default; |
| 25 | SkKeyedImage(const SkKeyedImage&) = default; |
| 26 | |
| 27 | SkKeyedImage& operator=(SkKeyedImage&&) = default; |
| 28 | SkKeyedImage& operator=(const SkKeyedImage&) = default; |
| 29 | |
Ben Wagner | 5d1adbf | 2018-05-28 13:35:39 -0400 | [diff] [blame] | 30 | explicit operator bool() const { return fImage != nullptr; } |
Hal Canary | 7cbf5e3 | 2017-07-12 13:10:23 -0400 | [diff] [blame] | 31 | const SkBitmapKey& key() const { return fKey; } |
| 32 | const sk_sp<SkImage>& image() const { return fImage; } |
| 33 | sk_sp<SkImage> release(); |
| 34 | SkKeyedImage subset(SkIRect subset) const; |
| 35 | |
| 36 | private: |
| 37 | sk_sp<SkImage> fImage; |
| 38 | SkBitmapKey fKey = {{0, 0, 0, 0}, 0}; |
| 39 | }; |
Hal Canary | 4f29c20 | 2017-07-18 10:28:31 -0400 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * Given an Image, return the Bitmap Key that corresponds to it. If the Image |
| 43 | * wraps a Bitmap, use that Bitmap's key. |
| 44 | */ |
| 45 | SkBitmapKey SkBitmapKeyFromImage(const SkImage*); |
Hal Canary | 7cbf5e3 | 2017-07-12 13:10:23 -0400 | [diff] [blame] | 46 | #endif // SkKeyedImage_DEFINED |