blob: 181c85812aa86ae8e14fb7d66b54af5c700b59ce [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
17class SkBitmapCache {
18public:
reed680fb9e2014-08-26 09:08:04 -070019 /**
piotaixr81591462014-09-02 11:27:11 -070020 * 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.
reed14b6aba2014-08-29 10:25:26 -070022 */
23 static SkBitmap::Allocator* GetAllocator();
24
25 /**
reed680fb9e2014-08-26 09:08:04 -070026 * 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 */
reed30ad5302014-09-16 10:39:55 -070029 static bool Find(const SkBitmap& src, SkScalar invScaleX, SkScalar invScaleY, SkBitmap* result,
30 SkResourceCache* localCache = NULL);
piotaixr81591462014-09-02 11:27:11 -070031
reed14b6aba2014-08-29 10:25:26 -070032 /*
33 * result must be marked isImmutable()
34 */
reed680fb9e2014-08-26 09:08:04 -070035 static void Add(const SkBitmap& src, SkScalar invScaleX, SkScalar invScaleY,
reed30ad5302014-09-16 10:39:55 -070036 const SkBitmap& result, SkResourceCache* localCache = NULL);
reed04617132014-08-21 09:46:49 -070037
reed680fb9e2014-08-26 09:08:04 -070038 /**
piotaixr42b0dfe2014-09-03 11:33:13 -070039 * 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 */
reed30ad5302014-09-16 10:39:55 -070042 static bool Find(uint32_t genID, const SkIRect& subset, SkBitmap* result,
43 SkResourceCache* localCache = NULL);
piotaixr42b0dfe2014-09-03 11:33:13 -070044
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 */
reed30ad5302014-09-16 10:39:55 -070049 static bool Add(uint32_t genID, const SkIRect& subset, const SkBitmap& result,
50 SkResourceCache* localCache = NULL);
reed04617132014-08-21 09:46:49 -070051};
52
53class SkMipMapCache {
54public:
reed680fb9e2014-08-26 09:08:04 -070055 static const SkMipMap* FindAndRef(const SkBitmap& src);
56 static void Add(const SkBitmap& src, const SkMipMap* result);
reed04617132014-08-21 09:46:49 -070057};
58
59#endif