blob: f4904d4aa461d330bc658e02c63025ea7a968c75 [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
reed013e9e32015-09-15 14:46:27 -070011#include "SkImage.h"
12#include "SkBitmapCache.h"
13
14class SkBitmapProvider {
15public:
Brian Osman61624f02016-12-09 14:51:59 -050016 explicit SkBitmapProvider(const SkImage* img, SkColorSpace* dstColorSpace)
Brian Osman7992da32016-11-18 11:28:24 -050017 : fImage(img)
Brian Osman61624f02016-12-09 14:51:59 -050018 , fDstColorSpace(dstColorSpace) {
Brian Osman7992da32016-11-18 11:28:24 -050019 SkASSERT(img);
20 }
reed013e9e32015-09-15 14:46:27 -070021 SkBitmapProvider(const SkBitmapProvider& other)
Florin Malitae13a69b2016-11-10 11:10:30 -050022 : fImage(other.fImage)
Brian Osman61624f02016-12-09 14:51:59 -050023 , fDstColorSpace(other.fDstColorSpace)
reed013e9e32015-09-15 14:46:27 -070024 {}
25
26 int width() const;
27 int height() const;
28 uint32_t getID() const;
Brian Osman61624f02016-12-09 14:51:59 -050029 SkColorSpace* dstColorSpace() const { return fDstColorSpace; }
reed013e9e32015-09-15 14:46:27 -070030
reed013e9e32015-09-15 14:46:27 -070031 SkImageInfo info() const;
reed09553032015-11-23 12:32:16 -080032 bool isVolatile() const;
reed013e9e32015-09-15 14:46:27 -070033
34 SkBitmapCacheDesc makeCacheDesc(int w, int h) const;
35 SkBitmapCacheDesc makeCacheDesc() const;
36 void notifyAddedToCache() const;
37
38 // Only call this if you're sure you need the bits, since it maybe expensive
39 // ... cause a decode and cache, or gpu-readback
40 bool asBitmap(SkBitmap*) const;
41
42private:
fmalita862a3872016-10-17 07:16:05 -070043 // Stack-allocated only.
44 void* operator new(size_t) = delete;
45 void* operator new(size_t, void*) = delete;
46
Brian Osman61624f02016-12-09 14:51:59 -050047 // SkBitmapProvider is always short-lived/stack allocated, and the source image and destination
48 // color space are guaranteed to outlive its scope => we can store raw ptrs to avoid ref churn.
49 const SkImage* fImage;
50 SkColorSpace* fDstColorSpace;
reed013e9e32015-09-15 14:46:27 -070051};
52
53#endif