Home | History | Annotate | Download | only in core
      1 /*
      2  * Copyright 2014 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 SkBitmapCache_DEFINED
      9 #define SkBitmapCache_DEFINED
     10 
     11 #include "SkScalar.h"
     12 #include "SkBitmap.h"
     13 
     14 class SkResourceCache;
     15 class SkMipMap;
     16 
     17 class SkBitmapCache {
     18 public:
     19     /**
     20      * Use this allocator for bitmaps, so they can use ashmem when available.
     21      * Returns NULL if the ResourceCache has not been initialized with a DiscardableFactory.
     22      */
     23     static SkBitmap::Allocator* GetAllocator();
     24 
     25     /**
     26      *  Search based on the src bitmap and inverse scales in X and Y. If found, returns true and
     27      *  result will be set to the matching bitmap with its pixels already locked.
     28      */
     29     static bool Find(const SkBitmap& src, SkScalar invScaleX, SkScalar invScaleY, SkBitmap* result,
     30                      SkResourceCache* localCache = NULL);
     31 
     32     /*
     33      *  result must be marked isImmutable()
     34      */
     35     static void Add(const SkBitmap& src, SkScalar invScaleX, SkScalar invScaleY,
     36             const SkBitmap& result, SkResourceCache* localCache = NULL);
     37 
     38     /**
     39      *  Search based on the bitmap's genID and subset. If found, returns true and
     40      *  result will be set to the matching bitmap with its pixels already locked.
     41      */
     42     static bool Find(uint32_t genID, const SkIRect& subset, SkBitmap* result,
     43                      SkResourceCache* localCache = NULL);
     44 
     45     /**
     46      * The width and the height of the provided subset must be the same as the result bitmap ones.
     47      * result must be marked isImmutable()
     48      */
     49     static bool Add(uint32_t genID, const SkIRect& subset, const SkBitmap& result,
     50                     SkResourceCache* localCache = NULL);
     51 };
     52 
     53 class SkMipMapCache {
     54 public:
     55     static const SkMipMap* FindAndRef(const SkBitmap& src);
     56     static void Add(const SkBitmap& src, const SkMipMap* result);
     57 };
     58 
     59 #endif
     60