2 * Copyright 2015 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef SkBitmapProvider_DEFINED
9 #define SkBitmapProvider_DEFINED
12 #include "SkBitmapCache.h"
14 class SkBitmapProvider {
16 explicit SkBitmapProvider(const SkImage* img, SkColorSpace* dstColorSpace)
18 , fDstColorSpace(dstColorSpace) {
21 SkBitmapProvider(const SkBitmapProvider& other)
22 : fImage(other.fImage)
23 , fDstColorSpace(other.fDstColorSpace)
28 uint32_t getID() const;
29 SkColorSpace* dstColorSpace() const { return fDstColorSpace; }
31 SkImageInfo info() const;
32 bool isVolatile() const;
34 SkBitmapCacheDesc makeCacheDesc(int w, int h) const;
35 SkBitmapCacheDesc makeCacheDesc() const;
36 void notifyAddedToCache() const;
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;
42 bool accessScaledImage(const SkRect& srcRect, const SkMatrix& invMatrix, SkFilterQuality fq,
43 SkBitmap* scaledBitmap, SkRect* adjustedSrcRect,
44 SkFilterQuality* adjustedFilterQuality) const;
47 // Stack-allocated only.
48 void* operator new(size_t) = delete;
49 void* operator new(size_t, void*) = delete;
51 // SkBitmapProvider is always short-lived/stack allocated, and the source image and destination
52 // color space are guaranteed to outlive its scope => we can store raw ptrs to avoid ref churn.
53 const SkImage* fImage;
54 SkColorSpace* fDstColorSpace;