Home | History | Annotate | Download | only in core
      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:
     16     explicit SkBitmapProvider(const SkImage* img, SkColorSpace* dstColorSpace)
     17         : fImage(img)
     18         , fDstColorSpace(dstColorSpace) {
     19         SkASSERT(img);
     20     }
     21     SkBitmapProvider(const SkBitmapProvider& other)
     22         : fImage(other.fImage)
     23         , fDstColorSpace(other.fDstColorSpace)
     24     {}
     25 
     26     int width() const;
     27     int height() const;
     28     uint32_t getID() const;
     29     SkColorSpace* dstColorSpace() const { return fDstColorSpace; }
     30 
     31     SkImageInfo info() const;
     32     bool isVolatile() const;
     33 
     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 
     42 private:
     43     // Stack-allocated only.
     44     void* operator new(size_t) = delete;
     45     void* operator new(size_t, void*) = delete;
     46 
     47     // 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;
     51 };
     52 
     53 #endif
     54