reed | 013e9e3 | 2015-09-15 14:46:27 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | |
| 8 | #ifndef SkBitmapProvider_DEFINED |
| 9 | #define SkBitmapProvider_DEFINED |
| 10 | |
| 11 | #include "SkBitmap.h" |
| 12 | #include "SkImage.h" |
| 13 | #include "SkBitmapCache.h" |
| 14 | |
| 15 | class SkBitmapProvider { |
| 16 | public: |
| 17 | explicit SkBitmapProvider(const SkBitmap& bm) : fBitmap(bm) {} |
| 18 | explicit SkBitmapProvider(const SkImage* img) : fImage(SkSafeRef(img)) {} |
| 19 | SkBitmapProvider(const SkBitmapProvider& other) |
| 20 | : fBitmap(other.fBitmap) |
| 21 | , fImage(SkSafeRef(other.fImage.get())) |
| 22 | {} |
| 23 | |
| 24 | int width() const; |
| 25 | int height() const; |
| 26 | uint32_t getID() const; |
| 27 | |
| 28 | bool validForDrawing() const; |
| 29 | SkImageInfo info() const; |
reed | 0955303 | 2015-11-23 12:32:16 -0800 | [diff] [blame] | 30 | bool isVolatile() const; |
reed | 013e9e3 | 2015-09-15 14:46:27 -0700 | [diff] [blame] | 31 | |
| 32 | SkBitmapCacheDesc makeCacheDesc(int w, int h) const; |
| 33 | SkBitmapCacheDesc makeCacheDesc() const; |
| 34 | void notifyAddedToCache() const; |
| 35 | |
| 36 | // Only call this if you're sure you need the bits, since it maybe expensive |
| 37 | // ... cause a decode and cache, or gpu-readback |
| 38 | bool asBitmap(SkBitmap*) const; |
| 39 | |
| 40 | private: |
| 41 | SkBitmap fBitmap; |
| 42 | SkAutoTUnref<const SkImage> fImage; |
| 43 | }; |
| 44 | |
| 45 | #endif |