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