SkBitmapCache.h revision f7834221ac5342a3446b9b299398ea3ff7976946
1a05814398202c4147a5e3f28474830ec0a9a0a90Jay Srinivasan/* 2f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson * Copyright 2014 Google Inc. 3f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson * 4f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson * Use of this source code is governed by a BSD-style license that can be 5f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson * found in the LICENSE file. 6f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson */ 7f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson 80c3ba249abb1dc60f5ebabccf84ff13206440b83Bill Richardson#ifndef SkBitmapCache_DEFINED 90c3ba249abb1dc60f5ebabccf84ff13206440b83Bill Richardson#define SkBitmapCache_DEFINED 10f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson 114cb5497984642b8cbd592c14cb1912a787b2d4d7Bill Richardson#include "SkScalar.h" 124cb5497984642b8cbd592c14cb1912a787b2d4d7Bill Richardson#include "SkBitmap.h" 13f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson 14f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardsonclass SkResourceCache; 15f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardsonclass SkMipMap; 16f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson 17f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardsonuint64_t SkMakeResourceCacheSharedIDForBitmap(uint32_t bitmapGenID); 18f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson 19f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardsonvoid SkNotifyBitmapGenIDIsStale(uint32_t bitmapGenID); 20f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson 21f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardsonclass SkBitmapCache { 22f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardsonpublic: 23f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson /** 24f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson * Use this allocator for bitmaps, so they can use ashmem when available. 25f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson * Returns NULL if the ResourceCache has not been initialized with a DiscardableFactory. 26f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson */ 27f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson static SkBitmap::Allocator* GetAllocator(); 28f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson 29f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson /** 30f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson * Search based on the src bitmap and inverse scales in X and Y. If found, returns true and 31f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson * result will be set to the matching bitmap with its pixels already locked. 32f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson */ 33f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson static bool Find(const SkBitmap& src, SkScalar invScaleX, SkScalar invScaleY, SkBitmap* result, 34f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson SkResourceCache* localCache = NULL); 35f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson 36a05814398202c4147a5e3f28474830ec0a9a0a90Jay Srinivasan /* 37a05814398202c4147a5e3f28474830ec0a9a0a90Jay Srinivasan * result must be marked isImmutable() 38a05814398202c4147a5e3f28474830ec0a9a0a90Jay Srinivasan */ 39f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson static void Add(const SkBitmap& src, SkScalar invScaleX, SkScalar invScaleY, 40f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson const SkBitmap& result, SkResourceCache* localCache = NULL); 41f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson 42f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson /** 43f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson * Search based on the bitmap's genID and subset. If found, returns true and 44f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson * result will be set to the matching bitmap with its pixels already locked. 45f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson */ 46f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson static bool Find(uint32_t genID, const SkIRect& subset, SkBitmap* result, 47f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson SkResourceCache* localCache = NULL); 48f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson 49f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson /** 50a05814398202c4147a5e3f28474830ec0a9a0a90Jay Srinivasan * The width and the height of the provided subset must be the same as the result bitmap ones. 51f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson * result must be marked isImmutable() 52f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson */ 53f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson static bool Add(SkPixelRef*, const SkIRect& subset, const SkBitmap& result, 54f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson SkResourceCache* localCache = NULL); 55f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson}; 56f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson 57f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardsonclass SkMipMapCache { 58a05814398202c4147a5e3f28474830ec0a9a0a90Jay Srinivasanpublic: 59a05814398202c4147a5e3f28474830ec0a9a0a90Jay Srinivasan static const SkMipMap* FindAndRef(const SkBitmap& src, SkResourceCache* localCache = NULL); 60f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson static const SkMipMap* AddAndRef(const SkBitmap& src, SkResourceCache* localCache = NULL); 61f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson}; 62f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson 63f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson#endif 64f1372d9109d638fbb1a177a89ebaf64e7ee0637eBill Richardson