blob: de50aabe1e4d7eb28e0cd1149a6cdd4d724fcdba [file] [log] [blame]
reed04617132014-08-21 09:46:49 -07001/*
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
reed680fb9e2014-08-26 09:08:04 -070011#include "SkScalar.h"
reed14b6aba2014-08-29 10:25:26 -070012#include "SkBitmap.h"
reed680fb9e2014-08-26 09:08:04 -070013
reed30ad5302014-09-16 10:39:55 -070014class SkResourceCache;
reed680fb9e2014-08-26 09:08:04 -070015class SkMipMap;
reed04617132014-08-21 09:46:49 -070016
reed7eeba252015-02-24 13:54:23 -080017uint64_t SkMakeResourceCacheSharedIDForBitmap(uint32_t bitmapGenID);
18
19void SkNotifyBitmapGenIDIsStale(uint32_t bitmapGenID);
20
reed04617132014-08-21 09:46:49 -070021class SkBitmapCache {
22public:
reed680fb9e2014-08-26 09:08:04 -070023 /**
piotaixr81591462014-09-02 11:27:11 -070024 * 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.
reed14b6aba2014-08-29 10:25:26 -070026 */
27 static SkBitmap::Allocator* GetAllocator();
28
29 /**
reed680fb9e2014-08-26 09:08:04 -070030 * 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 */
reed30ad5302014-09-16 10:39:55 -070033 static bool Find(const SkBitmap& src, SkScalar invScaleX, SkScalar invScaleY, SkBitmap* result,
34 SkResourceCache* localCache = NULL);
piotaixr81591462014-09-02 11:27:11 -070035
reed14b6aba2014-08-29 10:25:26 -070036 /*
37 * result must be marked isImmutable()
38 */
reed680fb9e2014-08-26 09:08:04 -070039 static void Add(const SkBitmap& src, SkScalar invScaleX, SkScalar invScaleY,
reed30ad5302014-09-16 10:39:55 -070040 const SkBitmap& result, SkResourceCache* localCache = NULL);
reed04617132014-08-21 09:46:49 -070041
reed680fb9e2014-08-26 09:08:04 -070042 /**
piotaixr42b0dfe2014-09-03 11:33:13 -070043 * 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 */
reed30ad5302014-09-16 10:39:55 -070046 static bool Find(uint32_t genID, const SkIRect& subset, SkBitmap* result,
47 SkResourceCache* localCache = NULL);
piotaixr42b0dfe2014-09-03 11:33:13 -070048
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 */
reed83787d02015-02-25 07:17:11 -080053 static bool Add(SkPixelRef*, const SkIRect& subset, const SkBitmap& result,
reed30ad5302014-09-16 10:39:55 -070054 SkResourceCache* localCache = NULL);
reed04617132014-08-21 09:46:49 -070055};
56
57class SkMipMapCache {
58public:
reed9d93c2e2014-10-08 05:17:12 -070059 static const SkMipMap* FindAndRef(const SkBitmap& src, SkResourceCache* localCache = NULL);
60 static const SkMipMap* AddAndRef(const SkBitmap& src, SkResourceCache* localCache = NULL);
reed04617132014-08-21 09:46:49 -070061};
62
63#endif