| 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 "include/core/SkImage.h" |
| 11 |
#include "include/core/SkRefCnt.h" |
| 12 |
#include "src/pdf/SkBitmapKey.h" |
| 13 |
|
| 14 |
class SkBitmap; |
| 15 |
struct SkIRect; |
| 16 |
|
| 17 |
/** |
| 18 |
This class has all the advantages of SkBitmaps and SkImages. |
| 19 |
|
| 20 |
The SkImage holds on to encoded data. The SkBitmapKey properly de-dups subsets. |
| 21 |
*/ |
| 22 |
class SkKeyedImage { |
| 23 |
public: |
| 24 |
SkKeyedImage() {} |
| 25 |
explicit SkKeyedImage(sk_sp<SkImage>); |
| 26 |
explicit SkKeyedImage(const SkBitmap&); |
| 27 |
SkKeyedImage(SkKeyedImage&&) = default; |
| 28 |
SkKeyedImage(const SkKeyedImage&) = default; |
| 29 |
|
| 30 |
SkKeyedImage& operator=(SkKeyedImage&&) = default; |
| 31 |
SkKeyedImage& operator=(const SkKeyedImage&) = default; |
| 32 |
|
| 33 |
explicit operator bool() const { return fImage != nullptr; } |
| 34 |
const SkBitmapKey& key() const { return fKey; } |
| 35 |
const sk_sp<SkImage>& image() const { return fImage; } |
| 36 |
sk_sp<SkImage> release(); |
| 37 |
SkKeyedImage subset(SkIRect subset) const; |
| 38 |
|
| 39 |
private: |
| 40 |
sk_sp<SkImage> fImage; |
| 41 |
SkBitmapKey fKey = {{0, 0, 0, 0}, 0}; |
| 42 |
}; |
| 43 |
|
| 44 |
/** |
| 45 |
* Given an Image, return the Bitmap Key that corresponds to it. If the Image |
| 46 |
* wraps a Bitmap, use that Bitmap's key. |
| 47 |
*/ |
| 48 |
SkBitmapKey SkBitmapKeyFromImage(const SkImage*); |
| 49 |
#endif // SkKeyedImage_DEFINED |