• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "SkImage.h"
12 #include "SkBitmapCache.h"
13 
14 class SkBitmapProvider {
15 public:
SkBitmapProvider(const SkImage * img)16     explicit SkBitmapProvider(const SkImage* img)
17         : fImage(img) {
18         SkASSERT(img);
19     }
SkBitmapProvider(const SkBitmapProvider & other)20     SkBitmapProvider(const SkBitmapProvider& other)
21         : fImage(other.fImage)
22     {}
23 
24     SkBitmapCacheDesc makeCacheDesc() const;
25     void notifyAddedToCache() const;
26 
27     // Only call this if you're sure you need the bits, since it maybe expensive
28     // ... cause a decode and cache, or gpu-readback
29     bool asBitmap(SkBitmap*) const;
30 
31 private:
32     // Stack-allocated only.
33     void* operator new(size_t) = delete;
34     void* operator new(size_t, void*) = delete;
35 
36     // SkBitmapProvider is always short-lived/stack allocated, and the source image is guaranteed
37     // to outlive its scope => we can store a raw ptr to avoid ref churn.
38     const SkImage* fImage;
39 };
40 
41 #endif
42