blob: 9901c0fc1a054ed9af43dfc77b22d1bed2eac1e3 [file] [log] [blame]
reed013e9e32015-09-15 14:46:27 -07001/*
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
15class SkBitmapProvider {
16public:
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;
reed09553032015-11-23 12:32:16 -080030 bool isVolatile() const;
reed013e9e32015-09-15 14:46:27 -070031
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
40private:
41 SkBitmap fBitmap;
42 SkAutoTUnref<const SkImage> fImage;
43};
44
45#endif